From 41d78f3a67e2356008911b07f8cc0d0cdafd7fda Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 18 Apr 2016 23:34:22 +0800 Subject: Use std::vector for the event list. Add panic action. Minor changes on the panic function. --- core/qmpmidiplay.cpp | 21 +++++++++++++-------- core/qmpmidiplay.hpp | 5 +++-- core/qmpmidiread.cpp | 36 ++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 28 deletions(-) (limited to 'core') diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp index 780b8f7..43ae17e 100644 --- a/core/qmpmidiplay.cpp +++ b/core/qmpmidiplay.cpp @@ -287,16 +287,21 @@ CMidiPlayer::~CMidiPlayer() } void CMidiPlayer::playerPanic(bool reset) { - if(reset)for(int i=0;i<16;++i) + for(int i=0;i<16;++i) { - fluid_synth_pitch_bend(synth,i,8192); - fluid_synth_cc(synth,i,7,100); - fluid_synth_cc(synth,i,10,64); - fluid_synth_cc(synth,i,11,127); - if(deviceusage[i])for(int j=0;j<16;++j)mapper->reset(i,j); + if(reset) + { + fluid_synth_pitch_bend(synth,i,8192); + fluid_synth_cc(synth,i,7,100); + fluid_synth_cc(synth,i,10,64); + fluid_synth_cc(synth,i,11,127); + } + fluid_synth_cc(synth,i,64,0); + //all sounds off causes the minus polyphone bug... + fluid_synth_all_notes_off(synth,i); + if(deviceusage[i])for(int j=0;j<16;++j) + reset?mapper->reset(i,j):mapper->panic(i,j); } - //all sounds off causes the minus polyphone bug... - for(int i=0;i<16;++i)fluid_synth_all_notes_off(synth,i); } bool CMidiPlayer::playerLoadFile(const char* fn) { diff --git a/core/qmpmidiplay.hpp b/core/qmpmidiplay.hpp index b0fb387..f2d7a4a 100644 --- a/core/qmpmidiplay.hpp +++ b/core/qmpmidiplay.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "qmpmidimappers.hpp" struct SEvent @@ -29,9 +30,9 @@ class CMidiCallBack class CMidiFile { private: - SEvent *eventList[10000000]; + std::vectoreventList; char *title,*copyright; - uint32_t eventc,std;//standard 0=? 1=GM 2=GM2 3=GS 4=XG + uint32_t std;//standard 0=? 1=GM 2=GM2 3=GS 4=XG uint32_t fmt,trk,divs; FILE *f; int byteread,valid; diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp index fd2e0d9..115b7b3 100644 --- a/core/qmpmidiread.cpp +++ b/core/qmpmidiread.cpp @@ -56,37 +56,37 @@ retry: { case 0x80://Note Off p1=fgetc(f);p2=fgetc(f);byteread+=2; - eventList[eventc++]=new SEvent(curid,curt,type,p1,p2); + eventList.push_back(new SEvent(curid,curt,type,p1,p2)); break; case 0x90://Note On p1=fgetc(f);p2=fgetc(f);byteread+=2; if(p2) { ++notes; - eventList[eventc++]=new SEvent(curid,curt,type,p1,p2); + eventList.push_back(new SEvent(curid,curt,type,p1,p2)); } else - eventList[eventc++]=new SEvent(curid,curt,(type&0x0F)|0x80,p1,p2); + eventList.push_back(new SEvent(curid,curt,(type&0x0F)|0x80,p1,p2)); break; case 0xA0://Note Aftertouch p1=fgetc(f);p2=fgetc(f);byteread+=2; - eventList[eventc++]=new SEvent(curid,curt,type,p1,p2); + eventList.push_back(new SEvent(curid,curt,type,p1,p2)); break; case 0xB0://Controller Change p1=fgetc(f);p2=fgetc(f);byteread+=2; - eventList[eventc++]=new SEvent(curid,curt,type,p1,p2); + eventList.push_back(new SEvent(curid,curt,type,p1,p2)); break; case 0xC0://Patch Change p1=fgetc(f);++byteread; - eventList[eventc++]=new SEvent(curid,curt,type,p1,0); + eventList.push_back(new SEvent(curid,curt,type,p1,0)); break; case 0xD0://Channel Aftertouch p1=fgetc(f);++byteread; - eventList[eventc++]=new SEvent(curid,curt,type,p1,0); + eventList.push_back(new SEvent(curid,curt,type,p1,0)); break; case 0xE0://Pitch wheel p1=fgetc(f);p2=fgetc(f);byteread+=2; - eventList[eventc++]=new SEvent(curid,curt,type,(p1|(p2<<7))&0x3FFF,0); + eventList.push_back(new SEvent(curid,curt,type,(p1|(p2<<7))&0x3FFF,0)); break; case 0xF0: if((type&0x0F)==0x0F)//Meta Event @@ -107,7 +107,7 @@ retry: break; case 0x51://Set Tempo p1=readDW();p1&=0x00FFFFFF; - eventList[eventc++]=new SEvent(curid,curt,type,metatype,p1); + eventList.push_back(new SEvent(curid,curt,type,metatype,p1)); break; case 0x54://SMTPE offset, not handled. fgetc(f);fgetc(f);fgetc(f); @@ -117,12 +117,12 @@ retry: case 0x58://Time signature fgetc(f);++byteread; p1=readDW(); - eventList[eventc++]=new SEvent(curid,curt,type,metatype,p1); + eventList.push_back(new SEvent(curid,curt,type,metatype,p1)); break; case 0x59://Key signature fgetc(f);++byteread; p1=readSW(); - eventList[eventc++]=new SEvent(curid,curt,type,metatype,p1); + eventList.push_back(new SEvent(curid,curt,type,metatype,p1)); break; case 0x01:case 0x02:case 0x03: case 0x04:case 0x05:case 0x06: @@ -134,7 +134,7 @@ retry: { ++byteread;if(str)str[c]=fgetc(f);else fgetc(f); } - if(str)str[c]='\0';eventList[eventc++]=new SEvent(curid,curt,type,metatype,0,str); + if(str)str[c]='\0';eventList.push_back(new SEvent(curid,curt,type,metatype,0,str)); if(str&&metatype==0x03&&!title) { title=new char[len+8]; @@ -159,7 +159,7 @@ retry: for(c=1;c