aboutsummaryrefslogtreecommitdiff
path: root/core/qmpmidiplay.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-04-07 23:39:02 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-04-07 23:39:02 +0800
commit8f8782f43bd838e825f3792b611d27fffa90399b (patch)
tree1fbd96dd7ce061010edacf67f72f0ffb07889edf /core/qmpmidiplay.cpp
parent70fd2d85c1bd6fb8732e680e8fda9d36c317c732 (diff)
downloadQMidiPlayer-8f8782f43bd838e825f3792b611d27fffa90399b.tar.xz
Lunatic Princess.
Diffstat (limited to 'core/qmpmidiplay.cpp')
-rw-r--r--core/qmpmidiplay.cpp54
1 files changed, 48 insertions, 6 deletions
diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp
index 6f69e33..e65a2a1 100644
--- a/core/qmpmidiplay.cpp
+++ b/core/qmpmidiplay.cpp
@@ -1,4 +1,5 @@
#include <cstdio>
+#include <cstring>
#include <chrono>
#include <thread>
#include <fluidsynth.h>
@@ -46,12 +47,18 @@ void CMidiPlayer::processEvent(const SEvent *e)
switch(e->type&0xF0)
{
case 0x80://Note off
- fluid_synth_noteoff(synth,e->type&0x0F,e->p1);
+ if(mappedoutput[e->type&0x0F])
+ mapper->noteOff(mappedoutput[e->type&0x0F]-1,e->type*0x0F,e->p1);
+ else
+ fluid_synth_noteoff(synth,e->type&0x0F,e->p1);
break;
case 0x90://Note on
if((mute>>(e->type&0x0F))&1)break;//muted
if(solo&&!((solo>>(e->type&0x0F))&1))break;
- fluid_synth_noteon(synth,e->type&0x0F,e->p1,e->p2);
+ if(mappedoutput[e->type&0x0F])
+ mapper->noteOn(mappedoutput[e->type&0x0F]-1,e->type*0x0F,e->p1,e->p2);
+ else
+ fluid_synth_noteon(synth,e->type&0x0F,e->p1,e->p2);
break;
case 0xB0://CC
if(e->p1==100)rpnid=e->p2;
@@ -61,13 +68,22 @@ void CMidiPlayer::processEvent(const SEvent *e)
if(rpnid==0)fluid_synth_pitch_wheel_sens(synth,e->type&0x0F,rpnval);
rpnid=rpnval=-1;
}
- fluid_synth_cc(synth,e->type&0x0F,e->p1,e->p2);
+ if(mappedoutput[e->type&0x0F])
+ mapper->ctrlChange(mappedoutput[e->type&0x0F]-1,e->type*0x0F,e->p1,e->p2);
+ else
+ fluid_synth_cc(synth,e->type&0x0F,e->p1,e->p2);
break;
case 0xC0://PC
- fluid_synth_program_change(synth,e->type&0x0F,e->p1);
+ if(mappedoutput[e->type&0x0F])
+ mapper->progChange(mappedoutput[e->type&0x0F]-1,e->type*0x0F,e->p1);
+ else
+ fluid_synth_program_change(synth,e->type&0x0F,e->p1);
break;
case 0xE0://PW
- fluid_synth_pitch_bend(synth,e->type&0x0F,e->p1);
+ if(mappedoutput[e->type&0x0F])
+ mapper->pitchBend(mappedoutput[e->type&0x0F]-1,e->type*0x0F,e->p1);
+ else
+ fluid_synth_pitch_bend(synth,e->type&0x0F,e->p1);
break;
case 0xF0://Meta/SysEx
if((e->type&0x0F)==0x0F)
@@ -94,7 +110,11 @@ void CMidiPlayer::processEvent(const SEvent *e)
if((e->type&0x0F)==0x00||(e->type&0x0F)==07)
{
int io=0;
- if(sendSysEx)fluid_synth_sysex(synth,e->str,e->p1,NULL,&io,NULL,0);
+ if(sendSysEx)
+ {
+ for(int i=0;i<16;++i)if(deviceusage[i])mapper->sysEx(i,e->p1,e->str);
+ fluid_synth_sysex(synth,e->str,e->p1,NULL,&io,NULL,0);
+ }
}
break;
}
@@ -231,6 +251,9 @@ CMidiPlayer::CMidiPlayer(bool singleInst)
{
midiFile=NULL;resumed=false;singleInstance=singleInst;
settings=NULL;synth=NULL;adriver=NULL;waitvoice=true;
+ memset(mappedoutput,0,sizeof(mappedoutput));
+ memset(deviceusage,0,sizeof(deviceusage));
+ mapper=new qmpMidiMapperRtMidi();
#ifdef _WIN32
QueryPerformanceFrequency((LARGE_INTEGER*)&pf);
#endif
@@ -238,6 +261,7 @@ CMidiPlayer::CMidiPlayer(bool singleInst)
CMidiPlayer::~CMidiPlayer()
{
if(singleInstance)fluidDeinitialize();
+ delete mapper;
}
void CMidiPlayer::playerPanic(bool reset)
{
@@ -402,3 +426,21 @@ int CMidiPlayer::getSFCount()
{return synth?fluid_synth_sfcount(synth):0;}
fluid_sfont_t* CMidiPlayer::getSFPtr(int sfid)
{return synth&&sfid<getSFCount()?fluid_synth_get_sfont(synth,sfid):NULL;}
+
+qmpMidiMapperRtMidi* CMidiPlayer::getMidiMapper(){return mapper;}
+void CMidiPlayer::setChannelOutput(int ch,int devid)
+{
+ int origoutput=mappedoutput[ch];
+ int newoutput=0;
+ if(devid>0)
+ {
+ if(!deviceusage[devid-1])deviceiid[devid]=newoutput=mapper->deviceInit(devid-1);
+ ++deviceusage[deviceiid[devid]];
+ }
+ mappedoutput[ch]=devid?deviceiid[devid]+1:0;
+ if(origoutput>0)
+ {
+ --deviceusage[origoutput-1];
+ if(!deviceusage[origoutput-1])mapper->deviceDeinit(origoutput-1);
+ }
+}