aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/qmpmidiplay.cpp20
-rw-r--r--core/qmpmidiplay.hpp11
-rw-r--r--core/qmpmidiread.cpp7
3 files changed, 32 insertions, 6 deletions
diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp
index bb2279d..1d32501 100644
--- a/core/qmpmidiplay.cpp
+++ b/core/qmpmidiplay.cpp
@@ -322,9 +322,11 @@ void CMidiPlayer::playerPanic(bool reset)
}
bool CMidiPlayer::playerLoadFile(const char* fn)
{
- midiFile=new CMidiFile(fn,this->eventReaderCB,this->eventReaderCBuserdata);
+ midiFile=new CMidiFile(fn,this);
if(!midiFile->isValid())return false;
divs=midiFile->getDivision();
+ for(int i=0;i<16;++i)if(fileReadFinishCB[i])
+ fileReadFinishCB[i]->callBack(NULL,fileReadFinishCBuserdata[i]);
fileTimer1Pass();
fileTimer2Pass();
return true;
@@ -411,6 +413,7 @@ double CMidiPlayer::getTempo(){return 60./(ctempo/1e6);}
uint32_t CMidiPlayer::getTick(){return ct;}
uint32_t CMidiPlayer::getRawTempo(){return ctempo;}
uint32_t CMidiPlayer::getDivision(){return divs;}
+uint32_t CMidiPlayer::getMaxTick(){return maxtk;}
double CMidiPlayer::getPitchBend(int ch){return((int)pbv[ch]-8192)/8192.*pbr[ch];}
uint32_t CMidiPlayer::getTCpaused(){return tcpaused;}
void CMidiPlayer::setTCpaused(uint32_t ps){tcpaused=ps;}
@@ -580,5 +583,20 @@ int CMidiPlayer::setEventReaderCB(IMidiCallBack *cb,void *userdata)
}
void CMidiPlayer::unsetEventReaderCB(int id)
{eventReaderCB[id]=NULL;eventReaderCBuserdata[id]=NULL;}
+int CMidiPlayer::setFileReadFinishedCB(IMidiCallBack *cb,void *userdata)
+{
+ for(int i=0;i<16;++i)
+ {
+ if(fileReadFinishCB[i]==cb)return i;
+ if(fileReadFinishCB[i]==NULL)
+ {
+ fileReadFinishCB[i]=cb;fileReadFinishCBuserdata[i]=userdata;
+ return i;
+ }
+ }
+ return -1;
+}
+void CMidiPlayer::unsetFileReadFinishedCB(int id)
+{fileReadFinishCB[id]=NULL;fileReadFinishCBuserdata[id]=NULL;}
void CMidiPlayer::discardLastEvent(){midiFile?midiFile->discardLastEvent():(void)0;}
void CMidiPlayer::commitEventChange(SEventCallBackData d){midiFile?midiFile->commitEventChange(d):(void)0;}
diff --git a/core/qmpmidiplay.hpp b/core/qmpmidiplay.hpp
index f7b81af..5b6c5a7 100644
--- a/core/qmpmidiplay.hpp
+++ b/core/qmpmidiplay.hpp
@@ -21,6 +21,7 @@ struct SEvent
if(s){str=new char[strlen(s)+2];strcpy(str,s);}else str=NULL;
}
};
+class CMidiPlayer;
class CMidiFile
{
private:
@@ -44,7 +45,7 @@ class CMidiFile
int chunkReader(int hdrXp);
void dumpEvents();
public:
- CMidiFile(const char* fn,IMidiCallBack** ercb,void** ercbdata);
+ CMidiFile(const char* fn,CMidiPlayer* par);
~CMidiFile();
const SEvent* getEvent(uint32_t id);
uint32_t getEventCount();
@@ -59,9 +60,10 @@ class CMidiFile
};
class CMidiPlayer
{
+ friend class CMidiFile;
private:
CMidiFile *midiFile;
- uint32_t stamps[101];
+ uint32_t stamps[101],maxtk;
uint32_t ccstamps[101][16][135],ccc[16][135];
//0..127:cc 128:pc 129:cp 130:pb 131:tempo 132:ts 133:ks 134:pbr
int32_t rpnid[16],rpnval[16];
@@ -83,8 +85,10 @@ class CMidiPlayer
uint8_t chstate[16],chstatus[16][130];//0..127: cc 128: pc
IMidiCallBack* eventHandlerCB[16];
IMidiCallBack* eventReaderCB[16];
+ IMidiCallBack* fileReadFinishCB[16];
void* eventHandlerCBuserdata[16];
void* eventReaderCBuserdata[16];
+ void* fileReadFinishCBuserdata[16];
void setBit(uint16_t &n,uint16_t bn,uint16_t b);
void processEvent(const SEvent *e);
@@ -129,6 +133,7 @@ class CMidiPlayer
uint32_t getTick();
uint32_t getRawTempo();
uint32_t getDivision();
+ uint32_t getMaxTick();
double getPitchBend(int ch);
const char* getTitle();
const char* getCopyright();
@@ -164,6 +169,8 @@ class CMidiPlayer
void unsetEventHandlerCB(int id);
int setEventReaderCB(IMidiCallBack *cb,void *userdata);
void unsetEventReaderCB(int id);
+ int setFileReadFinishedCB(IMidiCallBack *cb,void *userdata);
+ void unsetFileReadFinishedCB(int id);
void discardLastEvent();
void commitEventChange(SEventCallBackData d);
diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp
index 33a1bd4..58a9786 100644
--- a/core/qmpmidiread.cpp
+++ b/core/qmpmidiread.cpp
@@ -229,11 +229,11 @@ void CMidiFile::dumpEvents()
printf("type %x #%d @%d p1 %d p2 %d\n",eventList[i]->type,
eventList[i]->iid,eventList[i]->time,eventList[i]->p1,eventList[i]->p2);
}
-CMidiFile::CMidiFile(const char* fn,IMidiCallBack **ercb,void **ercbdata)
+CMidiFile::CMidiFile(const char* fn,CMidiPlayer* par)
{
title=copyright=NULL;notes=0;std=0;valid=1;
- memcpy(eventReaderCB,ercb,sizeof(eventReaderCB));
- memcpy(eventReaderCBuserdata,ercbdata,sizeof(eventReaderCBuserdata));
+ memcpy(eventReaderCB,par->eventReaderCB,sizeof(eventReaderCB));
+ memcpy(eventReaderCBuserdata,par->eventReaderCBuserdata,sizeof(eventReaderCBuserdata));
try
{
if(!(f=fopen(fn,"rb")))throw (fprintf(stderr,"E: file %s doesn't exist!\n",fn),2);
@@ -241,6 +241,7 @@ CMidiFile::CMidiFile(const char* fn,IMidiCallBack **ercb,void **ercbdata)
for(uint32_t i=0;i<trk;i+=chunkReader(0));
fclose(f);
std::sort(eventList.begin(),eventList.end(),cmp);
+ par->maxtk=eventList[eventList.size()-1]->time;
}
catch(int){fprintf(stderr,"E: %s is not a supported file.\n",fn);valid=0;}
}