aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--core/qmpmidioutfluid.cpp22
-rw-r--r--core/qmpmidioutrtmidi.cpp10
-rw-r--r--core/qmpmidiplay.cpp101
-rw-r--r--core/qmpmidiplay.hpp40
-rw-r--r--core/qmpmidiread.cpp133
-rw-r--r--include/qmpcorepublic.hpp34
-rw-r--r--midifmt-plugin/midifmtplugin.cpp22
-rw-r--r--midifmt-plugin/midifmtplugin.hpp2
-rw-r--r--qmidiplayer-desktop/qdialskulpturestyle.cpp4
-rw-r--r--qmidiplayer-desktop/qmpchannelswindow.cpp2
-rw-r--r--qmidiplayer-desktop/qmpchannelswindow.hpp4
-rw-r--r--qmidiplayer-desktop/qmpefxwindow.hpp2
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.cpp56
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.hpp14
-rw-r--r--qmidiplayer-desktop/qmpplugin.cpp19
-rw-r--r--qmidiplayer-desktop/qmpsettingswindow.cpp32
-rw-r--r--qmidiplayer-desktop/qmpsettingswindow.hpp2
-rw-r--r--sample-plugin/sampleplugin.cpp2
-rw-r--r--simple-visualization/qmpkeyboardwindow.cpp6
-rw-r--r--simple-visualization/qmpkeyboardwindow.hpp2
-rw-r--r--simple-visualization/simplevisualization.cpp10
-rw-r--r--simple-visualization/simplevisualization.hpp2
-rw-r--r--visualization/extrasmeltutils.cpp12
-rw-r--r--visualization/extrasmeltutils.hpp2
-rw-r--r--visualization/qmpvirtualpiano3d.cpp2
-rw-r--r--visualization/qmpvisualization.cpp52
-rw-r--r--visualization/qmpvisualization.hpp11
28 files changed, 347 insertions, 262 deletions
diff --git a/ChangeLog b/ChangeLog
index 892f273..110602b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-05-25 0.8.7 indev
+Massive code refactor en cours!
+Less complain from compilers:
+ - use nullptr instead of NULL
+ - use types for event fields
+ - explicit type casting added
+Stop saving parameters of meta events in p1/p2 fields of SEvent.
+callback_t now uses std::function, deprecating ICallback.
+
2019-04-22 0.8.7 indev
New development cycle!
Partially reintroduce High DPI handling.
diff --git a/core/qmpmidioutfluid.cpp b/core/qmpmidioutfluid.cpp
index ab0ab9d..bb8f290 100644
--- a/core/qmpmidioutfluid.cpp
+++ b/core/qmpmidioutfluid.cpp
@@ -5,27 +5,27 @@
qmpMidiOutFluid::qmpMidiOutFluid()
{
settings=new_fluid_settings();
- synth=NULL;adriver=NULL;
+ synth=nullptr;adriver=nullptr;
}
qmpMidiOutFluid::~qmpMidiOutFluid()
{
delete_fluid_settings(settings);
- settings=NULL;
+ settings=nullptr;
}
void qmpMidiOutFluid::deviceInit()
{
synth=new_fluid_synth(settings);
if(!synth){fputs("Error creating fluidsynth instance!",stderr);return;}
- fluid_set_log_function(FLUID_DBG,NULL,NULL);
- fluid_set_log_function(FLUID_INFO,NULL,NULL);
- fluid_set_log_function(FLUID_WARN,NULL,NULL);
- fluid_set_log_function(FLUID_ERR,fluid_default_log_function,NULL);
- fluid_set_log_function(FLUID_PANIC,fluid_default_log_function,NULL);
+ fluid_set_log_function(FLUID_DBG,nullptr,nullptr);
+ fluid_set_log_function(FLUID_INFO,nullptr,nullptr);
+ fluid_set_log_function(FLUID_WARN,nullptr,nullptr);
+ fluid_set_log_function(FLUID_ERR,fluid_default_log_function,nullptr);
+ fluid_set_log_function(FLUID_PANIC,fluid_default_log_function,nullptr);
adriver=new_fluid_audio_driver(settings,synth);
if(!adriver)
{
fputs("Error creating fluidsynth audio driver!",stderr);
- delete_fluid_synth(synth);synth=NULL;
+ delete_fluid_synth(synth);synth=nullptr;
return;
}
fluid_synth_set_chorus(synth,3,2.0,0.3,8.0,
@@ -37,7 +37,7 @@ void qmpMidiOutFluid::deviceDeinit(bool freshsettings)
if(!synth||!adriver)return;
delete_fluid_audio_driver(adriver);
delete_fluid_synth(synth);
- synth=NULL;adriver=NULL;
+ synth=nullptr;adriver=nullptr;
if(freshsettings)
{
delete_fluid_settings(settings);
@@ -70,7 +70,7 @@ void qmpMidiOutFluid::basicMessage(uint8_t type,uint8_t p1,uint8_t p2)
void qmpMidiOutFluid::extendedMessage(uint8_t length,const char *data)
{
int rlen=0;
- fluid_synth_sysex(synth,data,length,NULL,&rlen,NULL,0);
+ fluid_synth_sysex(synth,data,length,nullptr,&rlen,nullptr,0);
}
void qmpMidiOutFluid::rpnMessage(uint8_t ch,uint16_t type,uint16_t val)
{
@@ -234,7 +234,7 @@ void qmpFileRendererFluid::renderDeinit()
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);
- player=NULL;synth=NULL;settings=NULL;
+ player=nullptr;synth=nullptr;settings=nullptr;
}
void qmpFileRendererFluid::renderWorker()
{
diff --git a/core/qmpmidioutrtmidi.cpp b/core/qmpmidioutrtmidi.cpp
index 1b897df..2d6d41f 100644
--- a/core/qmpmidioutrtmidi.cpp
+++ b/core/qmpmidioutrtmidi.cpp
@@ -6,13 +6,13 @@
qmpMidiOutRtMidi::qmpMidiOutRtMidi(unsigned _portid)
{
portid=_portid;
- outport=NULL;
+ outport=nullptr;
}
qmpMidiOutRtMidi::~qmpMidiOutRtMidi()
{
if(!outport)return;
if(outport->isPortOpen())outport->closePort();
- delete outport;outport=NULL;
+ delete outport;outport=nullptr;
}
void qmpMidiOutRtMidi::deviceInit()
{
@@ -23,7 +23,7 @@ void qmpMidiOutRtMidi::deviceInit()
catch(RtMidiError &e)
{
printf("Cannot create RtMidi Output instance: %s\n",e.what());
- outport=NULL;
+ outport=nullptr;
}
}
void qmpMidiOutRtMidi::deviceDeinit()
@@ -92,14 +92,14 @@ void qmpMidiOutRtMidi::onUnmapped(uint8_t ch,int refcnt)
if(!refcnt&&outport)outport->closePort();
}
-RtMidiOut* qmpRtMidiManager::dummy=NULL;
+RtMidiOut* qmpRtMidiManager::dummy=nullptr;
void qmpRtMidiManager::createDevices()
{
try{dummy=new RtMidiOut();}
catch(RtMidiError &e)
{
printf("Failed to initialize the dummy device: %s\n",e.what());
- dummy=NULL;return;
+ dummy=nullptr;return;
}
for(unsigned i=0;i<dummy->getPortCount();++i)
devices.push_back(std::make_pair(new qmpMidiOutRtMidi(i),dummy->getPortName(i)));
diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp
index 29f636f..1e0cf8c 100644
--- a/core/qmpmidiplay.cpp
+++ b/core/qmpmidiplay.cpp
@@ -10,15 +10,13 @@
#include <windows.h>
uint64_t pf;
#endif
-//debug purpose
-uint32_t ttick;
-std::chrono::high_resolution_clock::time_point ttime;
-CMidiPlayer* CMidiPlayer::ref=NULL;
+CMidiPlayer* CMidiPlayer::ref=nullptr;
bool CMidiPlayer::processEvent(const SEvent *e)
{
- SEventCallBackData cbd(e->type,e->p1,e->p2,tceptr);
for(int i=0;i<16;++i)if(eventHandlerCB[i])
- eventHandlerCB[i]->callBack(&cbd,eventHandlerCBuserdata[i]);
+ eventHandlerCB[i]->callBack((void*)e,eventHandlerCBuserdata[i]);
+ for(auto i=event_handlers.begin();i!=event_handlers.end();++i)
+ i->second.first((void*)e,i->second.second);
uint8_t ch=e->type&0x0F;
switch(e->type&0xF0)
{
@@ -56,16 +54,28 @@ bool CMidiPlayer::processEvent(const SEvent *e)
switch(e->p1)
{
case 0x51:
- ctempo=e->p2;dpt=ctempo*1000./divs;
+ {
+ ctempo=0;
+#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__)||defined(_WIN32)
+ std::string x(e->str);
+ std::reverse(x.begin(),x.end());
+ memcpy(&ctempo,x.data(),3);
+#else
+ memcpy(&ctempo,e->str.data(),3);
+ ctempo>>=8;
+#endif
+ dpt=ctempo*1000./divs;
ttime=std::chrono::high_resolution_clock::now();
ttick=getTick();
+ }
break;
case 0x58:
- ctsn=e->p2>>24;
- ctsd=1<<((e->p2>>16)&0xFF);
+ ctsn=(uint32_t)e->str[0];
+ ctsd=1<<((uint32_t)e->str[1]);
break;
case 0x59:
- cks=e->p2;
+ if(e->str.length()==2)
+ cks=(e->str[0]<<8u)|e->str[1];
break;
case 0x01:case 0x02:case 0x03:
case 0x04:case 0x05:case 0x06:
@@ -111,14 +121,26 @@ void CMidiPlayer::processEventStub(const SEvent *e)
switch(e->p1)
{
case 0x51:
- ctempo=e->p2;dpt=ctempo*1000./divs;
+ {
+ ctempo=0;
+#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__)||defined(_WIN32)
+ std::string x(e->str);
+ std::reverse(x.begin(),x.end());
+ memcpy(&ctempo,x.data(),3);
+#else
+ memcpy(&ctempo,e->str.data(),3);
+ ctempo>>=8;
+#endif
+ dpt=ctempo*1000./divs;
ccc[0][131]=ctempo;
+ }
break;
case 0x58:
- ccc[0][132]=e->p2;
+ ccc[0][132]=(e->str[0]<<24u)|(e->str[1]<<16u);
break;
case 0x59:
- ccc[0][133]=e->p2;
+ if(e->str.length()>=2)
+ ccc[0][133]=(e->str[0]<<8u)|e->str[1];
break;
}
}
@@ -251,9 +273,10 @@ void CMidiPlayer::fileTimer2Pass()
CMidiPlayer::CMidiPlayer()
{
midiReaders=new CMidiFileReaderCollection();
- resumed=false;midiFile=NULL;internalFluid=new qmpMidiOutFluid();
+ resumed=false;midiFile=nullptr;internalFluid=new qmpMidiOutFluid();
registerMidiOutDevice(internalFluid,"Internal FluidSynth");
waitvoice=true;
+ event_handlers_id=event_read_handlers_id=file_read_finish_hooks_id=0;
memset(eventHandlerCB,0,sizeof(eventHandlerCB));
memset(eventHandlerCBuserdata,0,sizeof(eventHandlerCBuserdata));
memset(eventReaderCB,0,sizeof(eventReaderCB));
@@ -281,7 +304,7 @@ CMidiPlayer::~CMidiPlayer()
{
internalFluid->deviceDeinit();
delete internalFluid;
- internalFluid=NULL;
+ internalFluid=nullptr;
}
if(midiFile)delete midiFile;delete midiReaders;
}
@@ -307,7 +330,9 @@ bool CMidiPlayer::playerLoadFile(const char* fn)
maxtk=std::max(maxtk,i.eventList.back().time);
}
for(int i=0;i<16;++i)if(fileReadFinishCB[i])
- fileReadFinishCB[i]->callBack(NULL,fileReadFinishCBuserdata[i]);
+ fileReadFinishCB[i]->callBack(nullptr,fileReadFinishCBuserdata[i]);
+ for(auto i=file_read_finish_hooks.begin();i!=file_read_finish_hooks.end();++i)
+ i->second.first(nullptr,i->second.second);
eorder.clear();
for(size_t i=0;i<midiFile->tracks.size();++i)
for(size_t j=0;j<midiFile->tracks[i].eventList.size();++j)
@@ -343,7 +368,7 @@ void CMidiPlayer::playerInit()
void CMidiPlayer::playerDeinit()
{
tceptr=0;tcstop=1;tcpaused=0;
- delete midiFile;midiFile=NULL;
+ delete midiFile;midiFile=nullptr;
}
void CMidiPlayer::playerThread()
{
@@ -503,7 +528,7 @@ int CMidiPlayer::setEventHandlerCB(ICallBack *cb,void *userdata)
for(int i=0;i<16;++i)
{
if(eventHandlerCB[i]==cb)return i;
- if(eventHandlerCB[i]==NULL)
+ if(eventHandlerCB[i]==nullptr)
{
eventHandlerCB[i]=cb;eventHandlerCBuserdata[i]=userdata;
return i;
@@ -512,13 +537,13 @@ int CMidiPlayer::setEventHandlerCB(ICallBack *cb,void *userdata)
return -1;
}
void CMidiPlayer::unsetEventHandlerCB(int id)
-{eventHandlerCB[id]=NULL;eventHandlerCBuserdata[id]=NULL;}
+{eventHandlerCB[id]=nullptr;eventHandlerCBuserdata[id]=nullptr;}
int CMidiPlayer::setEventReaderCB(ICallBack *cb,void *userdata)
{
for(int i=0;i<16;++i)
{
if(eventReaderCB[i]==cb)return i;
- if(eventReaderCB[i]==NULL)
+ if(eventReaderCB[i]==nullptr)
{
eventReaderCB[i]=cb;eventReaderCBuserdata[i]=userdata;
return i;
@@ -527,13 +552,13 @@ int CMidiPlayer::setEventReaderCB(ICallBack *cb,void *userdata)
return -1;
}
void CMidiPlayer::unsetEventReaderCB(int id)
-{eventReaderCB[id]=NULL;eventReaderCBuserdata[id]=NULL;}
+{eventReaderCB[id]=nullptr;eventReaderCBuserdata[id]=nullptr;}
int CMidiPlayer::setFileReadFinishedCB(ICallBack *cb,void *userdata)
{
for(int i=0;i<16;++i)
{
if(fileReadFinishCB[i]==cb)return i;
- if(fileReadFinishCB[i]==NULL)
+ if(fileReadFinishCB[i]==nullptr)
{
fileReadFinishCB[i]=cb;fileReadFinishCBuserdata[i]=userdata;
return i;
@@ -542,23 +567,49 @@ int CMidiPlayer::setFileReadFinishedCB(ICallBack *cb,void *userdata)
return -1;
}
void CMidiPlayer::unsetFileReadFinishedCB(int id)
-{fileReadFinishCB[id]=NULL;fileReadFinishCBuserdata[id]=NULL;}
+{fileReadFinishCB[id]=nullptr;fileReadFinishCBuserdata[id]=nullptr;}
+int CMidiPlayer::registerEventHandler(callback_t cb,void *userdata)
+{
+ event_handlers[event_handlers_id++]=std::make_pair(cb,userdata);
+}
+void CMidiPlayer::unregisterEventHandler(int id)
+{
+ event_handlers.find(id)!=event_handlers.end()&&event_handlers.erase(id);
+}
+int CMidiPlayer::registerEventReadHandler(callback_t cb,void *userdata)
+{
+ event_read_handlers[event_read_handlers_id++]=std::make_pair(cb,userdata);
+}
+void CMidiPlayer::unregisterEventReadHandler(int id)
+{
+ event_read_handlers.find(id)!=event_read_handlers.end()&&event_read_handlers.erase(id);
+}
+int CMidiPlayer::registerFileReadFinishHook(callback_t cb,void *userdata)
+{
+ file_read_finish_hooks[file_read_finish_hooks_id++]=std::make_pair(cb,userdata);
+}
+void CMidiPlayer::unregisterFileReadFinishHook(int id)
+{
+ file_read_finish_hooks.find(id)!=file_read_finish_hooks.end()&&file_read_finish_hooks.erase(id);
+}
void CMidiPlayer::registerReader(qmpFileReader *reader,std::string name)
{midiReaders->registerReader(reader,name);}
void CMidiPlayer::unregisterReader(std::string name)
{midiReaders->unregisterReader(name);}
-void CMidiPlayer::callEventReaderCB(SEventCallBackData d)
+void CMidiPlayer::callEventReaderCB(SEvent d)
{
if((d.type&0xF0)==0x90)++notes;
for(int i=0;i<16;++i)if(eventReaderCB[i])
eventReaderCB[i]->callBack(&d,eventReaderCBuserdata[i]);
+ for(auto i=event_read_handlers.begin();i!=event_read_handlers.end();++i)
+ i->second.first(&d,i->second.second);
}
void CMidiPlayer::discardCurrentEvent()
{
if(midiReaders->getCurrentReader())
midiReaders->getCurrentReader()->discardCurrentEvent();
}
-void CMidiPlayer::commitEventChange(SEventCallBackData d)
+void CMidiPlayer::commitEventChange(SEvent d)
{
if(midiReaders->getCurrentReader())
midiReaders->getCurrentReader()->commitEventChange(d);
diff --git a/core/qmpmidiplay.hpp b/core/qmpmidiplay.hpp
index f054238..b94bb08 100644
--- a/core/qmpmidiplay.hpp
+++ b/core/qmpmidiplay.hpp
@@ -3,6 +3,8 @@
#define QMPMIDIPLAY_H
#include <cstring>
#include <cstdlib>
+#include <chrono>
+#include <unordered_map>
#include <utility>
#include <vector>
#define QMP_MAIN
@@ -17,23 +19,24 @@ class CSMFReader:public qmpFileReader
CMidiTrack* curTrack;
uint32_t fmt,trk;
FILE *f;
- int byteread,valid,eventdiscarded;
- uint32_t curt,curid;
+ bool eventdiscarded;
+ uint32_t byteread,curt,curid;
void error(int fatal,const char* format,...);
- uint32_t readSW();
- uint32_t readDW();
- uint32_t readVL();
- int eventReader();
- void trackChunkReader();
- void headerChunkReader();
- int chunkReader(int hdrXp);
+ uint8_t read_u8();
+ uint16_t read_u16();
+ uint32_t read_u32();
+ uint32_t read_varlen();
+ int read_event();
+ void read_track();
+ void read_header();
+ uint32_t read_chunk(int is_header);
public:
CSMFReader();
~CSMFReader();
CMidiFile* readFile(const char* fn);
void discardCurrentEvent();
- void commitEventChange(SEventCallBackData d);
+ void commitEventChange(SEvent d);
};
class CMidiFileReaderCollection{
private:
@@ -70,6 +73,9 @@ class CMidiPlayer
uint32_t tceptr,tcpaused,tcstop,ct;
uint32_t finished,resumed;
uint32_t pbr[16],pbv[16];
+ //playback correction
+ uint32_t ttick;
+ std::chrono::high_resolution_clock::time_point ttime;
struct SMidiDev
{
std::string name;
@@ -84,6 +90,10 @@ class CMidiPlayer
void* eventHandlerCBuserdata[16];
void* eventReaderCBuserdata[16];
void* fileReadFinishCBuserdata[16];
+ std::unordered_map<int,std::pair<callback_t,void*>> event_handlers;
+ std::unordered_map<int,std::pair<callback_t,void*>> event_read_handlers;
+ std::unordered_map<int,std::pair<callback_t,void*>> file_read_finish_hooks;
+ int event_handlers_id,event_read_handlers_id,file_read_finish_hooks_id;
static CMidiPlayer* ref;
SEvent *getEvent(int id);
@@ -152,12 +162,18 @@ class CMidiPlayer
void unsetEventReaderCB(int id);
int setFileReadFinishedCB(ICallBack *cb,void *userdata);
void unsetFileReadFinishedCB(int id);
+ int registerEventHandler(callback_t cb,void *userdata);
+ void unregisterEventHandler(int id);
+ int registerEventReadHandler(callback_t cb,void *userdata);
+ void unregisterEventReadHandler(int id);
+ int registerFileReadFinishHook(callback_t cb,void *userdata);
+ void unregisterFileReadFinishHook(int id);
void registerReader(qmpFileReader* reader,std::string name);
void unregisterReader(std::string name);
- void callEventReaderCB(SEventCallBackData d);
+ void callEventReaderCB(SEvent d);
void discardCurrentEvent();
- void commitEventChange(SEventCallBackData d);
+ void commitEventChange(SEvent d);
static CMidiPlayer* getInstance();
};
diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp
index d5f20ff..7f5bdfc 100644
--- a/core/qmpmidiread.cpp
+++ b/core/qmpmidiread.cpp
@@ -8,10 +8,10 @@
#include <cstdarg>
#include <algorithm>
#include "qmpmidiplay.hpp"
-const char* GM1SysX="\xF0\x7E\x7F\x09\x01\xF7";
-const char* GM2SysX="\xF0\x7E\x7F\x09\x03\xF7";
-const char* GSSysEx="\xF0\x41\x10\x42\x12\x40\x00\x7F\x00\x41\xF7";
-const char* XGSysEx="\xF0\x43\x10\x4C\x00\x00\x7E\x00\xF7";
+static const char* GM1SysX="\xF0\x7E\x7F\x09\x01\xF7";
+static const char* GM2SysX="\xF0\x7E\x7F\x09\x03\xF7";
+static const char* GSSysEx="\xF0\x41\x10\x42\x12\x40\x00\x7F\x00\x41\xF7";
+static const char* XGSysEx="\xF0\x43\x10\x4C\x00\x00\x7E\x00\xF7";
#define assert(x) if(!(x))this->error(false,"assertion failure @ qmpmidiread.cpp:%d",__LINE__)
void CSMFReader::error(int fatal,const char* format,...)
{
@@ -21,34 +21,56 @@ void CSMFReader::error(int fatal,const char* format,...)
if(fatal)throw std::runtime_error(bufr);
else fprintf(stderr,"CSMFReader W: %s.\n",bufr);
}
-uint32_t CSMFReader::readSW()
+uint8_t CSMFReader::read_u8()
{
- uint32_t ret=0;
- for(int i=0;i<2;++i){ret<<=8;ret|=((uint32_t)fgetc(f))&0xFF;}
+ uint8_t ret=0;
+ int t=fgetc(f);
+ if(!~t)error(1,"Unexpected EOF");
+ ret=(uint8_t)t;
return ret;
}
-uint32_t CSMFReader::readDW()
+uint16_t CSMFReader::read_u16()
+{
+ uint16_t ret=0;
+ size_t sz=fread(&ret,2,1,f);
+ if(sz<1)error(1,"Unexpected EOF");
+#if defined(_MSC_VER)&&defined(_WIN32)
+ ret=_byteswap_ushort(ret);
+#elif __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
+ ret=__builtin_bswap16(ret);
+#endif
+ return ret;
+}
+uint32_t CSMFReader::read_u32()
{
uint32_t ret=0;
- for(int i=0;i<4;++i){ret<<=8;ret|=((uint32_t)fgetc(f))&0xFF;}
+ size_t sz=fread(&ret,4,1,f);
+ if(sz<1)error(1,"Unexpected EOF");
+#if defined(_MSC_VER)&&defined(_WIN32)
+ ret=_byteswap_ulong(ret);
+#elif __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
+ ret=__builtin_bswap32(ret);
+#endif
return ret;
}
-uint32_t CSMFReader::readVL()
+uint32_t CSMFReader::read_varlen()
{
- uint32_t ret=0,t,c=0;
+ uint32_t ret=0,c=0;
+ int t;
do
{
t=fgetc(f);
+ if(!~t)error(1,"Unexpected EOF");
if(++c>4)error(1,"Variable length type overflow");
ret<<=7;ret|=(t&0x7F);
}while(t&0x80);
return ret;
}
-int CSMFReader::eventReader()//returns 0 if End of Track encountered
+int CSMFReader::read_event()//returns 0 if End of Track encountered
{
- uint32_t delta=readVL();curt+=delta;
- char type=fgetc(f);uint32_t p1,p2;
- static char lasttype;eventdiscarded=0;
+ uint32_t delta=read_varlen();curt+=delta;
+ uint8_t type=read_u8();uint32_t p1,p2;
+ static uint8_t lasttype;eventdiscarded=false;
if(!(type&0x80)){fseek(f,-1,SEEK_CUR);type=lasttype;}
switch(type&0xF0)
{
@@ -57,19 +79,19 @@ int CSMFReader::eventReader()//returns 0 if End of Track encountered
case 0xA0://Note Aftertouch
case 0xB0://Controller Change
case 0xE0://Pitch wheel
- p1=fgetc(f);p2=fgetc(f);
+ p1=read_u8();p2=read_u8();
curTrack->appendEvent(SEvent(curid,curt,type,p1,p2));
break;
case 0xC0://Patch Change
case 0xD0://Channel Aftertouch
- p1=fgetc(f);
+ p1=read_u8();
curTrack->appendEvent(SEvent(curid,curt,type,p1,0));
break;
case 0xF0:
if((type&0x0F)==0x0F)//Meta Event
{
- char metatype=fgetc(f);
- uint32_t len=readVL();char* str=NULL;
+ uint8_t metatype=read_u8();
+ uint32_t len=read_varlen();char* str=nullptr;
if(len<=1024&&len>0)str=new char[len+8];
if(str)fread(str,1,len,f);else fseek(f,len,SEEK_CUR);
if(str)str[len]='\0';
@@ -83,26 +105,21 @@ int CSMFReader::eventReader()//returns 0 if End of Track encountered
break;
case 0x2F://End of Track
assert(len==0);
- return 0;
- break;
+ return 0;
case 0x51://Set Tempo
assert(len==3);
- p1=((str[0]&0xffu)<<16u)|(str[1]&0xffu)<<8u|(str[2]&0xffu);
- curTrack->appendEvent(SEvent(curid,curt,type,metatype,p1));
+ curTrack->appendEvent(SEvent(curid,curt,type,metatype,0,str));
break;
case 0x54://SMTPE offset, not handled.
assert(len==5);
break;
case 0x58://Time signature
assert(len==4);
- p1=((str[0]&0xffu)<<24u)|(str[1]&0xffu)<<16u|(str[2]&0xffu)<<8u|(str[3]&0xffu);
- curTrack->appendEvent(SEvent(curid,curt,type,metatype,p1));
+ curTrack->appendEvent(SEvent(curid,curt,type,metatype,0,str));
break;
case 0x59://Key signature
assert(len==2);
- if(len>=2)
- p1=(str[0]&0xffu)<<8u|(str[1]&0xffu);else p1=0;
- curTrack->appendEvent(SEvent(curid,curt,type,metatype,p1));
+ curTrack->appendEvent(SEvent(curid,curt,type,metatype,0,str));
break;
case 0x01:case 0x02:case 0x03:
case 0x04:case 0x05:case 0x06:
@@ -125,14 +142,19 @@ int CSMFReader::eventReader()//returns 0 if End of Track encountered
}
else if((type&0x0F)==0x00||(type&0x0F)==0x07)//SysEx
{
- uint32_t len=readVL(),c;char* str=NULL;
+ uint32_t len=read_varlen();char* str=nullptr;
str=new char[len+8];
if((type&0x0F)==0x00)
{
str[0]=0xF0;++len;
- for(c=1;c<len;++c){str[c]=fgetc(f);}
+ size_t sz=fread(str+1,1,len-1,f);
+ if(sz<len-1)error(1,"Unexpected EOF");
+ }
+ else
+ {
+ size_t sz=fread(str,1,len,f);
+ if(sz<len)error(1,"Unexpected EOF");
}
- else for(c=0;c<len;++c){str[c]=fgetc(f);}
curTrack->appendEvent(SEvent(curid,curt,type,len,0,str));
if(!strcmp(str,GM1SysX))ret->std=1;
if(!strcmp(str,GM2SysX))ret->std=2;
@@ -149,17 +171,16 @@ int CSMFReader::eventReader()//returns 0 if End of Track encountered
if(curTrack->eventList.size())
{
SEvent& le=curTrack->eventList.back();
- SEventCallBackData cbd(le.type,le.p1,le.p2,le.time);
- CMidiPlayer::getInstance()->callEventReaderCB(cbd);
+ CMidiPlayer::getInstance()->callEventReaderCB(le);
}
return 1;
}
-void CSMFReader::trackChunkReader()
+void CSMFReader::read_track()
{
ret->tracks.push_back(CMidiTrack());
curTrack=&ret->tracks.back();
- int chnklen=readDW();byteread=ftell(f);curt=0;curid=0;
- while(eventReader());
+ uint32_t chnklen=read_u32();byteread=ftell(f);curt=0;curid=0;
+ while(read_event());
byteread=ftell(f)-byteread;
if(byteread<chnklen)
{
@@ -169,21 +190,21 @@ void CSMFReader::trackChunkReader()
if(byteread>chnklen)
error(1,"Read past end of track");
}
-void CSMFReader::headerChunkReader()
+void CSMFReader::read_header()
{
- int chnklen=readDW();byteread=ftell(f);
+ uint32_t chnklen=read_u32();byteread=ftell(f);
if(chnklen<6)error(1,"Header chunk too short");
if(chnklen>6)error(0,"Header chunk length longer than expected. Ignoring extra bytes");
- fmt=readSW();trk=readSW();ret->divs=readSW();
+ fmt=read_u16();trk=read_u16();ret->divs=read_u16();
if(ret->divs&0x8000)error(1,"SMTPE format is not supported");
for(byteread=ftell(f)-byteread;byteread<chnklen;++byteread){fgetc(f);}
}
-int CSMFReader::chunkReader(int hdrXp)
+uint32_t CSMFReader::read_chunk(int is_header)
{
char hdr[6];
fread(hdr,1,4,f);
if(feof(f))error(1,"Unexpected EOF");
- if(hdrXp)
+ if(is_header)
{
if(!strncmp(hdr,"RIFF",4))
{
@@ -194,37 +215,37 @@ int CSMFReader::chunkReader(int hdrXp)
fread(hdr,1,4,f);
}
if(strncmp(hdr,"MThd",4)){error(1,"Wrong MIDI header.");}
- else return headerChunkReader(),0;
+ else return read_header(),0;
}
else
if(strncmp(hdr,"MTrk",4))
{
error(0,"Wrong track chunk header. Ignoring the whole chunk");
- uint32_t chnklen=readDW();fseek(f,chnklen,SEEK_CUR);return 0;
+ uint32_t chnklen=read_u32();fseek(f,chnklen,SEEK_CUR);return 0;
}
- else return trackChunkReader(),1;
+ else return read_track(),1;
return 0;
}
CSMFReader::CSMFReader()
{
- f=NULL;
+ f=nullptr;
}
CMidiFile* CSMFReader::readFile(const char* fn)
{
ret=new CMidiFile;
- ret->title=ret->copyright=NULL;ret->std=0;ret->valid=1;
+ ret->title=ret->copyright=nullptr;ret->std=0;ret->valid=1;
try
{
if(!(f=fopen(fn,"rb")))
- throw std::runtime_error("File doesn't exist");
- chunkReader(1);
- for(uint32_t i=0;i<trk;i+=chunkReader(0));
- fclose(f);f=NULL;
+ throw std::runtime_error("Can't open file");
+ read_chunk(1);
+ for(uint32_t i=0;i<trk;i+=read_chunk(0));
+ fclose(f);f=nullptr;
}
catch(std::runtime_error& e)
{
fprintf(stderr,"CSMFReader E: %s is not a supported file. Cause: %s.\n",fn,e.what());
- ret->valid=0;if(f)fclose(f);f=NULL;
+ ret->valid=0;if(f)fclose(f);f=nullptr;
}
return ret;
}
@@ -234,10 +255,10 @@ CSMFReader::~CSMFReader()
void CSMFReader::discardCurrentEvent()
{
- if(eventdiscarded)return;eventdiscarded=1;
+ if(eventdiscarded)return;eventdiscarded=true;
curTrack->eventList.pop_back();
}
-void CSMFReader::commitEventChange(SEventCallBackData d)
+void CSMFReader::commitEventChange(SEvent d)
{
curTrack->eventList.back().time=d.time;
curTrack->eventList.back().type=d.type;
@@ -247,7 +268,7 @@ void CSMFReader::commitEventChange(SEventCallBackData d)
CMidiFileReaderCollection::CMidiFileReaderCollection()
{
- readers.clear();currentReader=NULL;
+ readers.clear();currentReader=nullptr;
registerReader(new CSMFReader(),"Default SMF Reader");
}
CMidiFileReaderCollection::~CMidiFileReaderCollection()
@@ -271,7 +292,7 @@ void CMidiFileReaderCollection::unregisterReader(std::string name)
}
CMidiFile* CMidiFileReaderCollection::readFile(const char* fn)
{
- CMidiFile *file=NULL;
+ CMidiFile *file=nullptr;
for(unsigned i=0;i<readers.size();++i)
{
currentReader=readers[i].first;
@@ -280,7 +301,7 @@ CMidiFile* CMidiFileReaderCollection::readFile(const char* fn)
if(t->valid){file=t;break;}
else delete t;
}
- currentReader=NULL;
+ currentReader=nullptr;
return file;
}
qmpFileReader* CMidiFileReaderCollection::getCurrentReader()
diff --git a/include/qmpcorepublic.hpp b/include/qmpcorepublic.hpp
index 0994865..67a39e0 100644
--- a/include/qmpcorepublic.hpp
+++ b/include/qmpcorepublic.hpp
@@ -1,6 +1,7 @@
#ifndef QMPCOREPUBLIC_HPP
#define QMPCOREPUBLIC_HPP
#include <cstdint>
+#include <functional>
#include <vector>
#include <string>
#ifdef _WIN32
@@ -8,15 +9,15 @@
#else
#define EXPORTSYM __attribute__ ((visibility ("default")))
#endif
-#define QMP_PLUGIN_API_REV "1+indev7"
+#define QMP_PLUGIN_API_REV "1+indev8"
//MIDI Event structure
struct SEvent
{
- uint32_t iid,time,p1,p2;
- uint8_t type;
+ uint32_t iid,time;
+ uint8_t type,p1,p2;
std::string str;
SEvent(){time=p1=p2=0;type=0;str="";}
- SEvent(uint32_t _iid,uint32_t _t,char _tp,uint32_t _p1,uint32_t _p2,const char* s=NULL)
+ SEvent(uint32_t _iid,uint32_t _t,uint8_t _tp,uint8_t _p1,uint8_t _p2,const char* s=nullptr)
{
iid=_iid;time=_t;type=_tp;
p1=_p1;p2=_p2;
@@ -24,13 +25,6 @@ struct SEvent
}
friend bool operator <(const SEvent& a,const SEvent& b){return a.time-b.time?a.time<b.time:a.iid<b.iid;}
};
-//This struct is used by event reader callbacks and event handler callbacks
-//as caller data struct
-struct SEventCallBackData
-{
- uint32_t time,type,p1,p2;
- SEventCallBackData(uint32_t _t,uint32_t _p1,uint32_t _p2,uint32_t _tm){type=_t;p1=_p1;p2=_p2;time=_tm;}
-};
//MIDI Track class
class CMidiTrack{
public:
@@ -53,15 +47,16 @@ class CMidiFile{
};
//Generic callback function that can be used for hooking the core.
//"userdata" is set when you register the callback function.
+//Deprecated. Removing in 0.9.x.
class ICallBack
{
public:
ICallBack(){}
- virtual void callBack(void* callerdata,void* userdata)=0;
+ virtual void callBack(const void* callerdata,void* userdata)=0;
virtual ~ICallBack(){}
};
//alternative callback function type
-typedef void (*callback_t)(void*,void*);
+typedef std::function<void(const void*,void*)> callback_t;
//MIDI file reader interface. Use this to implement your file importer.
class qmpFileReader
{
@@ -70,7 +65,7 @@ class qmpFileReader
virtual ~qmpFileReader(){}
virtual CMidiFile* readFile(const char* fn)=0;
virtual void discardCurrentEvent()=0;
- virtual void commitEventChange(SEventCallBackData d)=0;
+ virtual void commitEventChange(SEvent d)=0;
};
//Functionality interface.
class qmpFuncBaseIntf
@@ -138,6 +133,7 @@ class qmpPluginAPI
virtual std::wstring getWTitle();
virtual std::string getChannelPresetString(int ch);
virtual bool isDarkTheme();
+ virtual void* getMainWindow();
//WARNING!!: This function should be called from event reader callbacks only and
//it is somehow dangerous -- other plugins might be unaware of the removal of the
@@ -146,9 +142,9 @@ class qmpPluginAPI
//WARNING!!: This function should be called from event reader callbacks only and
//it is somehow dangerous -- other plugins might be unaware of the event change.
//The design might be modified afterward.
- virtual void commitEventChange(SEventCallBackData d);
+ virtual void commitEventChange(SEvent d);
//This function should be called from a file reader when it has read a new event
- virtual void callEventReaderCB(SEventCallBackData d);
+ virtual void callEventReaderCB(SEvent d);
virtual void setFuncState(std::string name,bool state);
virtual void setFuncEnabled(std::string name,bool enable);
@@ -165,6 +161,12 @@ class qmpPluginAPI
virtual void unregisterEventHandlerIntf(int intfhandle);
virtual int registerFileReadFinishedHandlerIntf(ICallBack* cb,void* userdata);
virtual void unregisterFileReadFinishedHandlerIntf(int intfhandle);
+ virtual int registerEventHandler(callback_t cb,void *userdata);
+ virtual void unregisterEventHandler(int id);
+ virtual int registerEventReadHandler(callback_t cb,void *userdata);
+ virtual void unregisterEventReadHandler(int id);
+ virtual int registerFileReadFinishHook(callback_t cb,void *userdata);
+ virtual void unregisterFileReadFinishHook(int id);
virtual void registerFileReader(qmpFileReader* reader,std::string name);
virtual void unregisterFileReader(std::string name);
diff --git a/midifmt-plugin/midifmtplugin.cpp b/midifmt-plugin/midifmtplugin.cpp
index 1882fe4..fa9936d 100644
--- a/midifmt-plugin/midifmtplugin.cpp
+++ b/midifmt-plugin/midifmtplugin.cpp
@@ -2,7 +2,7 @@
#include <algorithm>
#include <stdexcept>
#include "midifmtplugin.hpp"
-qmpPluginAPI* qmpMidiFmtPlugin::api=NULL;
+qmpPluginAPI* qmpMidiFmtPlugin::api=nullptr;
uint32_t CMidiStreamReader::readDWLE()
{
@@ -43,12 +43,18 @@ bool CMidiStreamReader::midsBodyReader()
uint32_t e=readDWLE();
SEvent ev;
if(e>>24==1)//set tempo
- ev=SEvent(curid,cts,0xFF,0x51,e&0x00FFFFFF);
+ {
+ char s[3]={'\0'};
+ for(int i=0;i<3;++i)
+ s[i]=(e>>(8*(2-i)))&0xff;
+ ev=SEvent(curid,cts,0xFF,0x51,0);
+ ev.str=std::string(s,3);
+ }
else if(e>>24==0)//midishortmsg
ev=SEvent(curid,cts,e&0xFF,(e>>8)&0xFF,(e>>16)&0xFF);
else return false;
ret->tracks.back().appendEvent(ev);eventdiscarded=0;
- qmpMidiFmtPlugin::api->callEventReaderCB(SEventCallBackData(ev.type,ev.p1,ev.p2,ev.time));
+ qmpMidiFmtPlugin::api->callEventReaderCB(ev);
if(eventdiscarded)ret->tracks.back().eventList.pop_back();
++curid;
}
@@ -58,7 +64,7 @@ bool CMidiStreamReader::midsBodyReader()
CMidiFile* CMidiStreamReader::readFile(const char *fn)
{
ret=new CMidiFile;
- ret->title=ret->copyright=NULL;ret->std=0;ret->valid=1;
+ ret->title=ret->copyright=nullptr;ret->std=0;ret->valid=1;
ret->tracks.push_back(CMidiTrack());
try
{
@@ -68,7 +74,7 @@ CMidiFile* CMidiStreamReader::readFile(const char *fn)
}catch(std::runtime_error& e)
{
fprintf(stderr,"CMidiStreamReader E: %s is not a supported file. Cause: %s.\n",fn,e.what());
- ret->valid=0;if(f)fclose(f);f=NULL;
+ ret->valid=0;if(f)fclose(f);f=nullptr;
}
return ret;
}
@@ -76,7 +82,7 @@ void CMidiStreamReader::discardCurrentEvent()
{
eventdiscarded=1;
}
-void CMidiStreamReader::commitEventChange(SEventCallBackData d)
+void CMidiStreamReader::commitEventChange(SEvent d)
{
ret->tracks.back().eventList.back().time=d.time;
ret->tracks.back().eventList.back().type=d.type;
@@ -85,7 +91,7 @@ void CMidiStreamReader::commitEventChange(SEventCallBackData d)
}
CMidiStreamReader::CMidiStreamReader()
{
- ret=NULL;f=NULL;
+ ret=nullptr;f=nullptr;
}
CMidiStreamReader::~CMidiStreamReader()
{
@@ -94,7 +100,7 @@ CMidiStreamReader::~CMidiStreamReader()
qmpMidiFmtPlugin::qmpMidiFmtPlugin(qmpPluginAPI *_api)
{api=_api;}
qmpMidiFmtPlugin::~qmpMidiFmtPlugin()
-{api=NULL;}
+{api=nullptr;}
void qmpMidiFmtPlugin::init()
{
api->registerFileReader(mdsreader=new CMidiStreamReader,"MIDS reader");
diff --git a/midifmt-plugin/midifmtplugin.hpp b/midifmt-plugin/midifmtplugin.hpp
index 05c96ea..038a2a7 100644
--- a/midifmt-plugin/midifmtplugin.hpp
+++ b/midifmt-plugin/midifmtplugin.hpp
@@ -18,7 +18,7 @@ class CMidiStreamReader:public qmpFileReader
~CMidiStreamReader();
CMidiFile* readFile(const char *fn);
void discardCurrentEvent();
- void commitEventChange(SEventCallBackData d);
+ void commitEventChange(SEvent d);
};
class qmpMidiFmtPlugin:public qmpPluginIntf
diff --git a/qmidiplayer-desktop/qdialskulpturestyle.cpp b/qmidiplayer-desktop/qdialskulpturestyle.cpp
index ba9e03f..33c80de 100644
--- a/qmidiplayer-desktop/qdialskulpturestyle.cpp
+++ b/qmidiplayer-desktop/qdialskulpturestyle.cpp
@@ -386,12 +386,12 @@ QDialSkulptureStyle::drawComplexControl( ComplexControl cc,
}
const QStyleOptionSlider *option = qstyleoption_cast<const QStyleOptionSlider *>(optc);
- if (option == NULL)
+ if (option == nullptr)
return;
int d = qMin(option->rect.width() & ~1, option->rect.height() & ~1);
QStyleOptionSlider opt = *option;
- const QAbstractSlider *slider = NULL;
+ const QAbstractSlider *slider = nullptr;
// always highlight knob if pressed (even if mouse is not over knob)
if ((option->state & QStyle::State_HasFocus) && (slider = qobject_cast<const QAbstractSlider *>(widget))) {
if (slider->isSliderDown()) {
diff --git a/qmidiplayer-desktop/qmpchannelswindow.cpp b/qmidiplayer-desktop/qmpchannelswindow.cpp
index 3b54069..1800aa5 100644
--- a/qmidiplayer-desktop/qmpchannelswindow.cpp
+++ b/qmidiplayer-desktop/qmpchannelswindow.cpp
@@ -15,7 +15,7 @@ qmpChannelsWindow::qmpChannelsWindow(QWidget *parent) :
ceditw=new qmpChannelEditor(this);
cha=new QIcon(":/img/ledon.svg");chi=new QIcon(":/img/ledoff.svg");
cb=new qmpCWNoteOnCB();fused=callbacksc=cbcnt=0;
- qmpMainWindow::getInstance()->getPlayer()->setEventHandlerCB(cb,NULL);
+ qmpMainWindow::getInstance()->getPlayer()->setEventHandlerCB(cb,nullptr);
connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity()));
std::vector<std::string> devs=qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices();
size_t devc=devs.size();
diff --git a/qmidiplayer-desktop/qmpchannelswindow.hpp b/qmidiplayer-desktop/qmpchannelswindow.hpp
index cb7b791..36cba3c 100644
--- a/qmidiplayer-desktop/qmpchannelswindow.hpp
+++ b/qmidiplayer-desktop/qmpchannelswindow.hpp
@@ -52,8 +52,8 @@ class qmpCWNoteOnCB:public QObject,public ICallBack
{
Q_OBJECT
public:
- void callBack(void* callerdata,void*)
- {if(((((SEventCallBackData*)callerdata)->type)&0xF0)==0x90)emit onNoteOn();}
+ void callBack(const void* callerdata,void*)
+ {if(((((const SEvent*)callerdata)->type)&0xF0)==0x90)emit onNoteOn();}
signals:
void onNoteOn();
};
diff --git a/qmidiplayer-desktop/qmpefxwindow.hpp b/qmidiplayer-desktop/qmpefxwindow.hpp
index 8b5319d..bacda1d 100644
--- a/qmidiplayer-desktop/qmpefxwindow.hpp
+++ b/qmidiplayer-desktop/qmpefxwindow.hpp
@@ -34,7 +34,7 @@ class qmpEfxWindow:public QWidget
~qmpEfxWindow();
void closeEvent(QCloseEvent *event);
void showEvent(QShowEvent *event);
- void sendEfxChange(void *_fs=NULL);
+ void sendEfxChange(void *_fs=nullptr);
private slots:
void on_dRoom_valueChanged();
diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp
index baebe4f..5f9dfba 100644
--- a/qmidiplayer-desktop/qmpmainwindow.cpp
+++ b/qmidiplayer-desktop/qmpmainwindow.cpp
@@ -26,7 +26,7 @@ char* wcsto8bit(const wchar_t* s)
#endif
#define UPDATE_INTERVAL 66
-qmpMainWindow* qmpMainWindow::ref=NULL;
+qmpMainWindow* qmpMainWindow::ref=nullptr;
qmpMainWindow::qmpMainWindow(QWidget *parent) :
QMainWindow(parent),
@@ -39,7 +39,7 @@ qmpMainWindow::qmpMainWindow(QWidget *parent) :
setButtonHeight(ui->pbPrev,36);setButtonHeight(ui->pbSettings,36);setButtonHeight(ui->pbStop,36);
playing=false;stopped=true;dragging=false;fin=false;
settingsw=new qmpSettingsWindow(this);pmgr=new qmpPluginManager();
- player=NULL;timer=NULL;fluidrenderer=NULL;
+ player=nullptr;timer=nullptr;fluidrenderer=nullptr;
}
qmpMainWindow::~qmpMainWindow()
@@ -56,15 +56,15 @@ qmpMainWindow::~qmpMainWindow()
rtmididev->deleteDevices();
delete pmgr;if(player)delete player;
if(timer)delete timer;
- delete helpw;helpw=NULL;
- delete efxw;efxw=NULL;
- delete chnlw;chnlw=NULL;
- delete plistw;plistw=NULL;
- delete infow;infow=NULL;
- delete settingsw;settingsw=NULL;
- delete panicf;panicf=NULL;
- delete renderf;renderf=NULL;
- delete reloadsynf;reloadsynf=NULL;
+ delete helpw;helpw=nullptr;
+ delete efxw;efxw=nullptr;
+ delete chnlw;chnlw=nullptr;
+ delete plistw;plistw=nullptr;
+ delete infow;infow=nullptr;
+ delete settingsw;settingsw=nullptr;
+ delete panicf;panicf=nullptr;
+ delete renderf;renderf=nullptr;
+ delete reloadsynf;reloadsynf=nullptr;
delete ui;
}
@@ -179,8 +179,8 @@ void qmpMainWindow::closeEvent(QCloseEvent *event)
for(auto i=mfunc.begin();i!=mfunc.end();++i)
{
i->second.i()->close();
- i->second.setAssignedControl((QReflectiveAction*)NULL),
- i->second.setAssignedControl((QReflectivePushButton*)NULL);
+ i->second.setAssignedControl((QReflectiveAction*)nullptr),
+ i->second.setAssignedControl((QReflectivePushButton*)nullptr);
}
efxw->close();chnlw->close();
plistw->close();infow->close();
@@ -211,11 +211,11 @@ void qmpMainWindow::updateWidgets()
if(!plistw->getRepeat())
{
timer->stop();stopped=true;playing=false;
- invokeCallback("main.stop",NULL);
+ invokeCallback("main.stop",nullptr);
setFuncEnabled("Render",stopped);setFuncEnabled("ReloadSynth",stopped);
chnlw->resetAcitivity();
player->playerDeinit();playerTh->join();
- delete playerTh;playerTh=NULL;
+ delete playerTh;playerTh=nullptr;
player->playerPanic(true);
chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
ui->pbPlayPause->setIcon(QIcon(getThemedIcon(":/img/play.svg")));
@@ -232,9 +232,9 @@ void qmpMainWindow::updateWidgets()
{
renderTh->join();timer->stop();
ui->centralWidget->setEnabled(true);
- delete renderTh;renderTh=NULL;
+ delete renderTh;renderTh=nullptr;
fluidrenderer->renderDeinit();
- delete fluidrenderer;fluidrenderer=NULL;
+ delete fluidrenderer;fluidrenderer=nullptr;
}
}
while(!player->isFinished()&&player->getTCeptr()>player->getStamp(ui->hsTimer->value())
@@ -259,8 +259,8 @@ void qmpMainWindow::switchTrack(QString s)
setFuncEnabled("Render",stopped);setFuncEnabled("ReloadSynth",stopped);
ui->pbPlayPause->setIcon(QIcon(getThemedIcon(":/img/pause.svg")));
timer->stop();player->playerDeinit();
- invokeCallback("main.stop",NULL);
- if(playerTh){playerTh->join();delete playerTh;playerTh=NULL;}
+ invokeCallback("main.stop",nullptr);
+ if(playerTh){playerTh->join();delete playerTh;playerTh=nullptr;}
player->playerPanic(true);
ui->hsTimer->setValue(0);
chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
@@ -272,7 +272,7 @@ void qmpMainWindow::switchTrack(QString s)
sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60);
ui->lbFinTime->setText(ts);
player->playerInit();
- invokeCallback("main.start",NULL);
+ invokeCallback("main.start",nullptr);
player->fluid()->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -359,7 +359,7 @@ int qmpMainWindow::loadFile(QString fns)
const char* c=s.c_str();
#endif
int ret=1;
- invokeCallback("main.reset",NULL);
+ invokeCallback("main.reset",nullptr);
if(!player->playerLoadFile(c))
{QMessageBox::critical(this,tr("Error"),tr("%1 is not a valid midi file.").arg(fns));ret=0;}
#ifdef _WIN32
@@ -387,7 +387,7 @@ void qmpMainWindow::on_pbPlayPause_clicked()
sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60);
ui->lbFinTime->setText(ts);
player->playerInit();
- invokeCallback("main.start",NULL);
+ invokeCallback("main.start",nullptr);
player->fluid()->setGain(ui->vsMasterVol->value()/250.);efxw->sendEfxChange();
player->setWaitVoice(qmpSettingsWindow::getSettingsIntf()->value("Midi/WaitVoice",1).toInt());
playerTh=new std::thread(&CMidiPlayer::playerThread,player);
@@ -411,7 +411,7 @@ void qmpMainWindow::on_pbPlayPause_clicked()
player->setResumed();
}
player->setTCpaused(!playing);
- invokeCallback("main.pause",NULL);
+ invokeCallback("main.pause",nullptr);
}
ui->pbPlayPause->setIcon(QIcon(getThemedIcon(playing?":/img/pause.svg":":/img/play.svg")));
}
@@ -478,11 +478,11 @@ void qmpMainWindow::on_pbStop_clicked()
if(!stopped)
{
timer->stop();stopped=true;playing=false;
- invokeCallback("main.stop",NULL);
+ invokeCallback("main.stop",nullptr);
player->playerDeinit();
setFuncEnabled("Render",stopped);setFuncEnabled("ReloadSynth",stopped);
player->playerPanic(true);chnlw->resetAcitivity();
- if(playerTh){playerTh->join();delete playerTh;playerTh=NULL;}
+ if(playerTh){playerTh->join();delete playerTh;playerTh=nullptr;}
chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked();
ui->pbPlayPause->setIcon(QIcon(getThemedIcon(":/img/play.svg")));
ui->hsTimer->setValue(0);
@@ -631,8 +631,8 @@ std::map<std::string,qmpFuncPrivate>& qmpMainWindow::getFunc()
void qmpMainWindow::setupWidget()
{
for(auto i=mfunc.begin();i!=mfunc.end();++i)
- i->second.setAssignedControl((QReflectiveAction*)NULL),
- i->second.setAssignedControl((QReflectivePushButton*)NULL);
+ i->second.setAssignedControl((QReflectiveAction*)nullptr),
+ i->second.setAssignedControl((QReflectivePushButton*)nullptr);
QList<QWidget*>w=ui->buttonwidget->findChildren<QWidget*>("",Qt::FindDirectChildrenOnly);
for(unsigned i=0;i<w.size();++i)
delete w[i];
@@ -723,7 +723,7 @@ qmpFuncPrivate::qmpFuncPrivate(qmpFuncBaseIntf *i,std::string _desc,const char *
_icon=QIcon(pixm);
}else _icon=QIcon();
checked=false;
- asgna=NULL;asgnb=NULL;
+ asgna=nullptr;asgnb=nullptr;
}
void qmpMainWindow::on_pbAdd_clicked()
diff --git a/qmidiplayer-desktop/qmpmainwindow.hpp b/qmidiplayer-desktop/qmpmainwindow.hpp
index a456dec..262bc2e 100644
--- a/qmidiplayer-desktop/qmpmainwindow.hpp
+++ b/qmidiplayer-desktop/qmpmainwindow.hpp
@@ -66,7 +66,7 @@ class QReflectiveAction:public QAction
}
public:
explicit QReflectiveAction(const QIcon& icon,const QString& text,const std::string& ref):
- QAction(icon,text,NULL),reflt(ref){
+ QAction(icon,text,nullptr),reflt(ref){
connect(this,SIGNAL(triggered(bool)),this,SLOT(triggerslot()));
}
};
@@ -102,7 +102,7 @@ class qmpFuncPrivate
public:
qmpFuncPrivate(){}
qmpFuncPrivate(qmpFuncBaseIntf* i,std::string _desc,const char* icon,int iconlen,bool checkable);
- ~qmpFuncPrivate(){asgna=NULL;asgnb=NULL;}
+ ~qmpFuncPrivate(){asgna=nullptr;asgnb=nullptr;}
qmpFuncBaseIntf* i(){return _i;}
void setAssignedControl(QReflectiveAction* a){asgna=a;if(!a)return;asgna->setCheckable(_checkable);asgna->setChecked(checked);}
void setAssignedControl(QReflectivePushButton* a){asgnb=a;if(!a)return;asgnb->setCheckable(_checkable);asgnb->setChecked(checked);}
@@ -125,9 +125,9 @@ class qmpCallBack
ICallBack* cbc;
callback_t cbf;
public:
- qmpCallBack(){t=-1;cbc=NULL;cbf=NULL;}
- qmpCallBack(ICallBack* _cb){t=0;cbc=_cb;cbf=NULL;}
- qmpCallBack(callback_t _cb){t=1;cbf=_cb;cbc=NULL;}
+ qmpCallBack(){t=-1;cbc=nullptr;cbf=nullptr;}
+ qmpCallBack(ICallBack* _cb){t=0;cbc=_cb;cbf=nullptr;}
+ qmpCallBack(callback_t _cb){t=1;cbf=_cb;cbc=nullptr;}
void operator ()(void* cbd,void* usrd)
{
if(t<0)return;
@@ -196,8 +196,8 @@ class qmpMainWindow:public QMainWindow
Ui::qmpMainWindow *ui;
QTimer *timer;
bool playing,stopped,dragging,fin,havemidi;
- std::thread *playerTh=NULL;
- std::thread *renderTh=NULL;
+ std::thread *playerTh=nullptr;
+ std::thread *renderTh=nullptr;
std::chrono::steady_clock::time_point st;
double offset;
CMidiPlayer *player;
diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp
index 13d5730..8655dff 100644
--- a/qmidiplayer-desktop/qmpplugin.cpp
+++ b/qmidiplayer-desktop/qmpplugin.cpp
@@ -101,7 +101,7 @@ qmpPluginManager::~qmpPluginManager()
if(plugins[i].initialized)plugins[i].pinterface->deinit();
delete plugins[i].pinterface;
}
- qmw=NULL;qsw=NULL;delete pluginAPI;
+ qmw=nullptr;qsw=nullptr;delete pluginAPI;
}
std::vector<qmpPlugin> *qmpPluginManager::getPlugins()
{
@@ -182,10 +182,11 @@ std::string qmpPluginAPI::getChannelPresetString(int ch)
return std::string(ret);
}
bool qmpPluginAPI::isDarkTheme(){return qmw?qmw->isDarkTheme():false;}
+void* qmpPluginAPI::getMainWindow(){return (void*)qmw;}
void qmpPluginAPI::discardCurrentEvent(){if(qmw&&qmw->getPlayer())qmw->getPlayer()->discardCurrentEvent();}
-void qmpPluginAPI::commitEventChange(SEventCallBackData d){if(qmw&&qmw->getPlayer())qmw->getPlayer()->commitEventChange(d);}
-void qmpPluginAPI::callEventReaderCB(SEventCallBackData d){if(qmw&&qmw->getPlayer())qmw->getPlayer()->callEventReaderCB(d);}
+void qmpPluginAPI::commitEventChange(SEvent d){if(qmw&&qmw->getPlayer())qmw->getPlayer()->commitEventChange(d);}
+void qmpPluginAPI::callEventReaderCB(SEvent d){if(qmw&&qmw->getPlayer())qmw->getPlayer()->callEventReaderCB(d);}
void qmpPluginAPI::setFuncState(std::string name,bool state){if(qmw)qmw->setFuncState(name,state);}
void qmpPluginAPI::setFuncEnabled(std::string name,bool enable){if(qmw)qmw->setFuncEnabled(name,enable);}
@@ -219,6 +220,18 @@ void qmpPluginAPI::registerFileReader(qmpFileReader* reader,std::string name)
{qmw->getPlayer()->registerReader(reader,name);}
void qmpPluginAPI::unregisterFileReader(std::string name)
{qmw->getPlayer()->unregisterReader(name);}
+int qmpPluginAPI::registerEventHandler(callback_t cb,void *userdata)
+{return qmw->getPlayer()->registerEventHandler(cb,userdata);}
+void qmpPluginAPI::unregisterEventHandler(int id)
+{qmw->getPlayer()->unregisterEventHandler(id);}
+int qmpPluginAPI::registerEventReadHandler(callback_t cb,void *userdata)
+{return qmw->getPlayer()->registerEventReadHandler(cb,userdata);}
+void qmpPluginAPI::unregisterEventReadHandler(int id)
+{qmw->getPlayer()->unregisterEventReadHandler(id);}
+int qmpPluginAPI::registerFileReadFinishHook(callback_t cb,void *userdata)
+{return qmw->getPlayer()->registerFileReadFinishHook(cb,userdata);}
+void qmpPluginAPI::unregisterFileReadFinishHook(int id)
+{qmw->getPlayer()->unregisterFileReadFinishHook(id);}
void qmpPluginAPI::registerOptionInt(std::string tab,std::string desc,std::string key,int min,int max,int defaultval)
{qsw->registerOptionInt(tab,desc,key,min,max,defaultval);}
diff --git a/qmidiplayer-desktop/qmpsettingswindow.cpp b/qmidiplayer-desktop/qmpsettingswindow.cpp
index 9d8b4cf..b14ff4d 100644
--- a/qmidiplayer-desktop/qmpsettingswindow.cpp
+++ b/qmidiplayer-desktop/qmpsettingswindow.cpp
@@ -8,8 +8,8 @@
#include "ui_qmpsettingswindow.h"
#include "qmpmainwindow.hpp"
-QSettings* qmpSettingsWindow::settings=NULL;
-QComboBox* qmpSettingsWindow::outwidget=NULL;
+QSettings* qmpSettingsWindow::settings=nullptr;
+QComboBox* qmpSettingsWindow::outwidget=nullptr;
void qmpFluidForEachOpt(void* data,const char*,const char* option)
{
@@ -35,7 +35,7 @@ qmpSettingsWindow::qmpSettingsWindow(QWidget *parent) :
qmpSettingsWindow::~qmpSettingsWindow()
{
delete cw;
- delete settings;settings=NULL;
+ delete settings;settings=nullptr;
delete ui;
}
@@ -447,7 +447,7 @@ void qmpSettingsWindow::updateCustomOptions()
void qmpSettingsWindow::registerOptionInt(std::string tab,std::string desc,std::string key,int min,int max,int defaultval)
{
- customOptions[key].widget=NULL;
+ customOptions[key].widget=nullptr;
customOptions[key].desc=desc;
customOptions[key].defaultval=defaultval;
customOptions[key].minv=min;
@@ -455,7 +455,7 @@ void qmpSettingsWindow::registerOptionInt(std::string tab,std::string desc,std::
customOptions[key].type=0;
if(desc.length())
{
- QGridLayout* page=NULL;
+ QGridLayout* page=nullptr;
if(customOptPages[tab])page=customOptPages[tab];
else
{
@@ -491,7 +491,7 @@ void qmpSettingsWindow::setOptionInt(std::string key,int val)
void qmpSettingsWindow::registerOptionUint(std::string tab,std::string desc,std::string key,unsigned min,unsigned max,unsigned defaultval)
{
- customOptions[key].widget=NULL;
+ customOptions[key].widget=nullptr;
customOptions[key].desc=desc;
customOptions[key].defaultval=defaultval;
customOptions[key].minv=min;
@@ -499,7 +499,7 @@ void qmpSettingsWindow::registerOptionUint(std::string tab,std::string desc,std:
customOptions[key].type=1;
if(desc.length())
{
- QGridLayout* page=NULL;
+ QGridLayout* page=nullptr;
if(customOptPages[tab])page=customOptPages[tab];
else
{
@@ -534,13 +534,13 @@ void qmpSettingsWindow::setOptionUint(std::string key,unsigned val)
void qmpSettingsWindow::registerOptionBool(std::string tab,std::string desc,std::string key,bool defaultval)
{
- customOptions[key].widget=NULL;
+ customOptions[key].widget=nullptr;
customOptions[key].desc=desc;
customOptions[key].defaultval=defaultval;
customOptions[key].type=2;
if(desc.length())
{
- QGridLayout* page=NULL;
+ QGridLayout* page=nullptr;
if(customOptPages[tab])page=customOptPages[tab];
else
{
@@ -571,7 +571,7 @@ void qmpSettingsWindow::setOptionBool(std::string key,bool val)
void qmpSettingsWindow::registerOptionDouble(std::string tab,std::string desc,std::string key,double min,double max,double defaultval)
{
- customOptions[key].widget=NULL;
+ customOptions[key].widget=nullptr;
customOptions[key].desc=desc;
customOptions[key].defaultval=defaultval;
customOptions[key].minv=min;
@@ -579,7 +579,7 @@ void qmpSettingsWindow::registerOptionDouble(std::string tab,std::string desc,st
customOptions[key].type=3;
if(desc.length())
{
- QGridLayout* page=NULL;
+ QGridLayout* page=nullptr;
if(customOptPages[tab])page=customOptPages[tab];
else
{
@@ -615,14 +615,14 @@ void qmpSettingsWindow::setOptionDouble(std::string key,double val)
void qmpSettingsWindow::registerOptionString(std::string tab,std::string desc,std::string key,std::string defaultval,bool ispath)
{
- customOptions[key].widget=NULL;
+ customOptions[key].widget=nullptr;
customOptions[key].desc=desc;
customOptions[key].defaultval=QString(defaultval.c_str());
customOptions[key].type=4;
if(ispath)customOptions[key].type=6;
if(desc.length())
{
- QGridLayout* page=NULL;
+ QGridLayout* page=nullptr;
if(customOptPages[tab])page=customOptPages[tab];
else
{
@@ -672,13 +672,13 @@ void qmpSettingsWindow::setOptionString(std::string key,std::string val)
void qmpSettingsWindow::registerOptionEnumInt(std::string tab,std::string desc,std::string key,std::vector<std::string> options,int defaultval)
{
- customOptions[key].widget=NULL;
+ customOptions[key].widget=nullptr;
customOptions[key].desc=desc;
customOptions[key].defaultval=defaultval;
customOptions[key].type=5;
if(desc.length())
{
- QGridLayout* page=NULL;
+ QGridLayout* page=nullptr;
if(customOptPages[tab])page=customOptPages[tab];
else
{
@@ -737,6 +737,6 @@ QString QFileEdit::text(){return le->text();}
void QFileEdit::setText(const QString& s){le->setText(s);}
void QFileEdit::chooseFile()
{
- QString s=QFileDialog::getOpenFileName(NULL,tr("Select a file"),QFileInfo(text()).dir().absolutePath());
+ QString s=QFileDialog::getOpenFileName(nullptr,tr("Select a file"),QFileInfo(text()).dir().absolutePath());
if(s.length())setText(s);
}
diff --git a/qmidiplayer-desktop/qmpsettingswindow.hpp b/qmidiplayer-desktop/qmpsettingswindow.hpp
index 5636f54..f186969 100644
--- a/qmidiplayer-desktop/qmpsettingswindow.hpp
+++ b/qmidiplayer-desktop/qmpsettingswindow.hpp
@@ -37,7 +37,7 @@ class QFileEdit:public QWidget
private slots:
void chooseFile();
public:
- QFileEdit(QWidget* par=NULL);
+ QFileEdit(QWidget* par=nullptr);
QString text();
void setText(const QString& s);
};
diff --git a/sample-plugin/sampleplugin.cpp b/sample-plugin/sampleplugin.cpp
index 64e5584..baf2786 100644
--- a/sample-plugin/sampleplugin.cpp
+++ b/sample-plugin/sampleplugin.cpp
@@ -2,7 +2,7 @@
#include "sampleplugin.hpp"
qmpSamplePlugin::qmpSamplePlugin(qmpPluginAPI* _api){api=_api;}
-qmpSamplePlugin::~qmpSamplePlugin(){api=NULL;}
+qmpSamplePlugin::~qmpSamplePlugin(){api=nullptr;}
void qmpSamplePlugin::init()
{fputs("Hello world from plugin init!\n",stderr);}
void qmpSamplePlugin::deinit()
diff --git a/simple-visualization/qmpkeyboardwindow.cpp b/simple-visualization/qmpkeyboardwindow.cpp
index a42a2e0..f2cc8b7 100644
--- a/simple-visualization/qmpkeyboardwindow.cpp
+++ b/simple-visualization/qmpkeyboardwindow.cpp
@@ -25,10 +25,10 @@ void qmpKeyboardWindow::onkeystatesupdate(int ch,int key,bool state)
void qmpKeyboardWindow::resetAll()
{for(int ch=0;ch<16;++ch)pw[ch]->reset();}
-void EventCallback::callBack(void* callerdata,void* userdata)
+void EventCallback::callBack(const void *callerdata,void* userdata)
{
- qmpKeyboardWindow *w=(qmpKeyboardWindow*)userdata;
- SEventCallBackData *cbd=(SEventCallBackData*)callerdata;
+ const qmpKeyboardWindow *w=(const qmpKeyboardWindow*)userdata;
+ const SEvent *cbd=(const SEvent*)callerdata;
if((cbd->type&0xF0)==0x80)
emit keystateupdated(cbd->type&0xF,cbd->p1,false);
if((cbd->type&0xF0)==0x90)
diff --git a/simple-visualization/qmpkeyboardwindow.hpp b/simple-visualization/qmpkeyboardwindow.hpp
index a99e62e..2b618fa 100644
--- a/simple-visualization/qmpkeyboardwindow.hpp
+++ b/simple-visualization/qmpkeyboardwindow.hpp
@@ -10,7 +10,7 @@ class EventCallback:public QObject,public ICallBack
{
Q_OBJECT
public:
- void callBack(void* callerdata,void* userdata);
+ void callBack(const void *callerdata,void *userdata);
signals:
void keystateupdated(int ch,int key,bool state);
};
diff --git a/simple-visualization/simplevisualization.cpp b/simple-visualization/simplevisualization.cpp
index 0a1de02..e4c0c83 100644
--- a/simple-visualization/simplevisualization.cpp
+++ b/simple-visualization/simplevisualization.cpp
@@ -7,8 +7,8 @@ void qmpSimpleVisualization::close(){p->close();}
void qmpSimpleVisualization::init()
{
api->registerFunctionality(this,"Keyboard","Keyboard",api->isDarkTheme()?":/img/visualization_i.svg":":/img/visualization.svg",0,true);
- p=new qmpKeyboardWindow(api,NULL);
- uihs=api->registerUIHook("main.stop",qmpSimpleVisualization::cbstop,(void*)this);
+ p=new qmpKeyboardWindow(api,(QWidget*)api->getMainWindow());
+ uihs=api->registerUIHook("main.stop",[this](const void*,void*){this->p->resetAll();},nullptr);
}
void qmpSimpleVisualization::deinit()
{
@@ -21,9 +21,3 @@ const char* qmpSimpleVisualization::pluginGetName()
{return "QMidiPlayer Simple Visualization Plugin";}
const char* qmpSimpleVisualization::pluginGetVersion()
{return "0.8.6";}
-
-void qmpSimpleVisualization::cbstop(void*,void* usrd)
-{
- qmpSimpleVisualization *v=(qmpSimpleVisualization*)usrd;
- v->p->resetAll();
-}
diff --git a/simple-visualization/simplevisualization.hpp b/simple-visualization/simplevisualization.hpp
index b3edeee..d79eef0 100644
--- a/simple-visualization/simplevisualization.hpp
+++ b/simple-visualization/simplevisualization.hpp
@@ -18,8 +18,6 @@ class qmpSimpleVisualization:public qmpPluginIntf,public qmpFuncBaseIntf
void deinit();
const char* pluginGetName();
const char* pluginGetVersion();
-
- static void cbstop(void* cbd,void* usrd);
};
extern "C"{
diff --git a/visualization/extrasmeltutils.cpp b/visualization/extrasmeltutils.cpp
index 6c8dd93..7e766f4 100644
--- a/visualization/extrasmeltutils.cpp
+++ b/visualization/extrasmeltutils.cpp
@@ -3,9 +3,9 @@
#include <algorithm>
#include <smcolor.hpp>
#include "extrasmeltutils.hpp"
-SMELT* smEntity3DBuffer::sm=NULL;
-SMELT* smParticle::sm=NULL;
-SMELT* smParticleSystem::sm=NULL;
+SMELT* smEntity3DBuffer::sm=nullptr;
+SMELT* smParticle::sm=nullptr;
+SMELT* smParticleSystem::sm=nullptr;
smVertex makeVertex(float x,float y,float z,DWORD color,float tx,float ty)
{smVertex v;v.x=x;v.y=y;v.z=z;v.col=color;v.tx=tx;v.ty=ty;return v;}
void smEntity3D::addVerices(int n,...)
@@ -93,7 +93,7 @@ void smParticle::update()
q.v[3].x=v3.x+pos.x;q.v[3].y=v3.y+pos.y;q.v[3].z=v3.z+pos.z;
}
smParticleSystem::smParticleSystem()
-{sm=smGetInterface(SMELT_APILEVEL);particles.clear();posGenerator=NULL;active=false;}
+{sm=smGetInterface(SMELT_APILEVEL);particles.clear();posGenerator=nullptr;active=false;}
smParticleSystem::~smParticleSystem()
{for(unsigned i=0;i<particles.size();++i)delete particles[i];particles.clear();}
void smParticleSystem::setParticleSystemInfo(smParticleSystemInfo _psinfo)
@@ -104,7 +104,7 @@ void smParticleSystem::setPSEmissionPosGen(smPSEmissionPositionGenerator *_gen)
void smParticleSystem::setPSLookAt(smvec3d at){lookat=true;lookatpos=at;}
void smParticleSystem::unsetPSLookAt(){lookat=false;}
void smParticleSystem::startPS()
-{active=true;nemdelay=0;re.setSeed(time(NULL));}
+{active=true;nemdelay=0;re.setSeed(time(nullptr));}
void smParticleSystem::stopPS()
{active=false;}
void smParticleSystem::updatePS()
@@ -166,7 +166,7 @@ void smParticleSystem::updatePS()
}
}
while(!particles.empty()&&particles.back()->dead)
- {delete particles.back();particles.back()=NULL;particles.pop_back();}
+ {delete particles.back();particles.back()=nullptr;particles.pop_back();}
}
void smParticleSystem::renderPS()
{for(unsigned i=0;i<particles.size();++i)particles[i]->render();}
diff --git a/visualization/extrasmeltutils.hpp b/visualization/extrasmeltutils.hpp
index 08868a7..fe9bb73 100644
--- a/visualization/extrasmeltutils.hpp
+++ b/visualization/extrasmeltutils.hpp
@@ -42,7 +42,7 @@ class smXLinePSGenerator:public smPSEmissionPositionGenerator
smRandomEngine re;
double var;
public:
- smXLinePSGenerator(double _var){re.setSeed(time(NULL));var=_var;}
+ smXLinePSGenerator(double _var){re.setSeed(time(nullptr));var=_var;}
smvec3d genPos(){return smvec3d(re.nextDouble(-var,var),0,0);}
};
class smParticleSystemInfo
diff --git a/visualization/qmpvirtualpiano3d.cpp b/visualization/qmpvirtualpiano3d.cpp
index bd40524..b622dd5 100644
--- a/visualization/qmpvirtualpiano3d.cpp
+++ b/visualization/qmpvirtualpiano3d.cpp
@@ -12,7 +12,7 @@ qmpVirtualPiano3D::qmpVirtualPiano3D()
qmpVirtualPiano3D::~qmpVirtualPiano3D()
{
delete wkcf;delete wkeb;delete wkd;delete wkg;delete wka;delete bk;
- wkcf=wkeb=wkd=wkg=wka=bk=NULL;delete ebuf;ebuf=NULL;
+ wkcf=wkeb=wkd=wkg=wka=bk=nullptr;delete ebuf;ebuf=nullptr;
}
void qmpVirtualPiano3D::render(smvec3d p)
{
diff --git a/visualization/qmpvisualization.cpp b/visualization/qmpvisualization.cpp
index 1452ca9..c8dbcff 100644
--- a/visualization/qmpvisualization.cpp
+++ b/visualization/qmpvisualization.cpp
@@ -41,9 +41,9 @@ bool cmp(MidiVisualEvent* a,MidiVisualEvent* b)
if(a->tcs<b->tcs)return true;if(a->tcs>b->tcs)return false;
if(a->tce<b->tce)return true;return false;
}
-void CReaderCallBack::callBack(void *callerdata,void *)
+void CReaderCallBack::callBack(const void *callerdata,void *)
{
- SEventCallBackData* cbd=(SEventCallBackData*)callerdata;
+ const SEvent* cbd=(const SEvent*)callerdata;
switch(cbd->type&0xF0)
{
case 0x80:
@@ -57,11 +57,11 @@ void CReaderCallBack::callBack(void *callerdata,void *)
break;
case 0xF0:
if(cbd->type==0xFF&&cbd->p1==0x58)
- par->tspool.push_back(std::make_pair(cbd->time,cbd->p2));
+ par->tspool.push_back(std::make_pair(cbd->time,(cbd->str[0]<<24)|(cbd->str[1]<<16)));
break;
}
}
-void CEventHandlerCallBack::callBack(void*,void*)
+void CEventHandlerCallBack::callBack(const void*,void*)
{
if(par->ctk>par->api->getCurrentTimeStamp()+par->api->getDivision()/3)
par->elb=0;
@@ -69,7 +69,7 @@ void CEventHandlerCallBack::callBack(void*,void*)
fprintf(stderr,"Visualization: out of sync! %u vs %u ad: %u\n",par->ctk,par->api->getCurrentTimeStamp());*/
par->ctk=par->api->getCurrentTimeStamp();
}
-void CFRFinishedCallBack::callBack(void*,void*)
+void CFRFinishedCallBack::callBack(const void*,void*)
{
std::sort(par->tspool.begin(),par->tspool.end());
for(uint32_t tk=0,n=4,s=0;tk<=par->api->getMaxTick();){
@@ -153,7 +153,7 @@ void qmpVisualization::showThread()
}else memset(pss,0,sizeof(pss));
if(showpiano&&!horizontal)for(int i=0;i<16;++i)p3d[i]=new qmpVirtualPiano3D();
memset(traveld,0,sizeof(traveld));
- if(noteappearance==1)nebuf=new smEntity3DBuffer();else nebuf=NULL;
+ if(noteappearance==1)nebuf=new smEntity3DBuffer();else nebuf=nullptr;
tdscn=sm->smTargetCreate(wwidth*wsupersample,wheight*wsupersample,wmultisample);
tdparticles=sm->smTargetCreate(wwidth*wsupersample,wheight*wsupersample,wmultisample);
if(!api->getOptionString("Visualization/font2").length()||!font.loadTTF(api->getOptionString("Visualization/font2").c_str(),fontsize))
@@ -206,7 +206,7 @@ void qmpVisualization::close()
{
rendererTh->join();
delete rendererTh;
- rendererTh=NULL;
+ rendererTh=nullptr;
}else return;
if(showpiano&&!horizontal)for(int i=0;i<16;++i)delete p3d[i];
@@ -746,7 +746,7 @@ void qmpVisualization::drawCube(smvec3d a,smvec3d b,DWORD col,SMTEX tex)
}
qmpVisualization::qmpVisualization(qmpPluginAPI* _api){api=_api;}
-qmpVisualization::~qmpVisualization(){api=NULL;}
+qmpVisualization::~qmpVisualization(){api=nullptr;}
void qmpVisualization::init()
{
cb=new CReaderCallBack(this);
@@ -754,17 +754,17 @@ void qmpVisualization::init()
h=new CMidiVisualHandler(this);
frcb=new CFRFinishedCallBack(this);
closeh=new CloseHandler(this);
- rendererTh=NULL;playing=false;
+ rendererTh=nullptr;playing=false;
memset(spectra,0,sizeof(spectra));
memset(spectrar,0,sizeof(spectrar));
api->registerFunctionality(this,"Visualization","Visualization",api->isDarkTheme()?":/img/visualization_i.svg":":/img/visualization.svg",0,true);
- uihb=api->registerUIHook("main.start",qmpVisualization::cbstart,(void*)this);
- uihs=api->registerUIHook("main.stop",qmpVisualization::cbstop,(void*)this);
- uihp=api->registerUIHook("main.pause",qmpVisualization::cbpause,(void*)this);
- uihr=api->registerUIHook("main.reset",qmpVisualization::cbreset,(void*)this);
- herif=api->registerEventReaderIntf(cb,NULL);
- hehif=api->registerEventHandlerIntf(hcb,NULL);
- hfrf=api->registerFileReadFinishedHandlerIntf(frcb,NULL);
+ uihb=api->registerUIHook("main.start",[this](const void*,void*){this->start();},nullptr);
+ uihs=api->registerUIHook("main.stop",[this](const void*,void*){this->stop();},nullptr);
+ uihp=api->registerUIHook("main.pause",[this](const void*,void*){this->pause();},nullptr);
+ uihr=api->registerUIHook("main.reset",[this](const void*,void*){this->reset();},nullptr);
+ herif=api->registerEventReaderIntf(cb,nullptr);
+ hehif=api->registerEventHandlerIntf(hcb,nullptr);
+ hfrf=api->registerFileReadFinishedHandlerIntf(frcb,nullptr);
api->registerOptionBool("Visualization-Appearance","Show Piano","Visualization/showpiano",true);
api->registerOptionBool("Visualization-Appearance","3D Notes","Visualization/3dnotes",true);
api->registerOptionBool("Visualization-Appearance","Arrange channels on a stair","Visualization/stairpiano",true);
@@ -850,26 +850,6 @@ const char* qmpVisualization::pluginGetName()
{return "QMidiPlayer Default Visualization Plugin";}
const char* qmpVisualization::pluginGetVersion()
{return "0.8.6";}
-void qmpVisualization::cbstart(void *,void *usrd)
-{
- qmpVisualization* v=(qmpVisualization*)usrd;
- v->start();
-}
-void qmpVisualization::cbstop(void *,void *usrd)
-{
- qmpVisualization* v=(qmpVisualization*)usrd;
- v->stop();
-}
-void qmpVisualization::cbpause(void *,void *usrd)
-{
- qmpVisualization* v=(qmpVisualization*)usrd;
- v->pause();
-}
-void qmpVisualization::cbreset(void *,void *usrd)
-{
- qmpVisualization* v=(qmpVisualization*)usrd;
- v->reset();
-}
void qmpVisualization::pushNoteOn(uint32_t tc,uint32_t ch,uint32_t key,uint32_t vel)
{
diff --git a/visualization/qmpvisualization.hpp b/visualization/qmpvisualization.hpp
index 23be1a9..4e0412b 100644
--- a/visualization/qmpvisualization.hpp
+++ b/visualization/qmpvisualization.hpp
@@ -18,7 +18,7 @@ class CReaderCallBack:public ICallBack
qmpVisualization *par;
public:
CReaderCallBack(qmpVisualization *_par){par=_par;}
- void callBack(void *callerdata,void *userdata);
+ void callBack(const void *callerdata,void *userdata);
};
class CEventHandlerCallBack:public ICallBack
{
@@ -26,7 +26,7 @@ class CEventHandlerCallBack:public ICallBack
qmpVisualization *par;
public:
CEventHandlerCallBack(qmpVisualization *_par){par=_par;}
- void callBack(void*,void*);
+ void callBack(const void*,void*);
};
class CFRFinishedCallBack:public ICallBack
{
@@ -34,7 +34,7 @@ class CFRFinishedCallBack:public ICallBack
qmpVisualization *par;
public:
CFRFinishedCallBack(qmpVisualization *_par){par=_par;}
- void callBack(void*,void*);
+ void callBack(const void*,void*);
};
struct MidiVisualEvent
{
@@ -95,11 +95,6 @@ class qmpVisualization:public qmpPluginIntf,public qmpFuncBaseIntf
void deinit();
const char* pluginGetName();
const char* pluginGetVersion();
-
- static void cbstart(void* cbd,void* usrd);
- static void cbstop(void* cbd,void* usrd);
- static void cbpause(void* cbd,void* usrd);
- static void cbreset(void* cbd,void* usrd);
};
class CMidiVisualHandler:public smHandler