diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-05-25 22:40:15 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-05-25 22:40:15 +0800 |
commit | 3f72121ac41741d53e4916f1275cbd4f93259c4d (patch) | |
tree | 15bba079c86de0e241812cd657ad190eb0c2c41a /midifmt-plugin/midifmtplugin.cpp | |
parent | eba45fdf11a98113b439db0510b55f14845db8fb (diff) | |
download | QMidiPlayer-3f72121ac41741d53e4916f1275cbd4f93259c4d.tar.xz |
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.
Not recommended for daily usage, or even testing: the code refactor
is still a work in progress.
Diffstat (limited to 'midifmt-plugin/midifmtplugin.cpp')
-rw-r--r-- | midifmt-plugin/midifmtplugin.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
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"); |