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 /core/qmpmidiplay.hpp | |
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 'core/qmpmidiplay.hpp')
-rw-r--r-- | core/qmpmidiplay.hpp | 40 |
1 files changed, 28 insertions, 12 deletions
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(); }; |