aboutsummaryrefslogtreecommitdiff
path: root/visualization
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2017-10-18 11:40:51 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2017-10-18 11:40:51 +0800
commitd985112164bd2bfeca0c895abb523d45f0e065bb (patch)
tree3a44ae92001c2a8cac89eb46fe74248249d6e0ea /visualization
parent48dd5f9fb11f0a2e69291271d9140ebcec640117 (diff)
downloadQMidiPlayer-d985112164bd2bfeca0c895abb523d45f0e065bb.tar.xz
API changes and crash fixes.
Details in the changelog.
Diffstat (limited to 'visualization')
-rw-r--r--visualization/qmpvisualization.cpp43
-rw-r--r--visualization/qmpvisualization.hpp32
2 files changed, 44 insertions, 31 deletions
diff --git a/visualization/qmpvisualization.cpp b/visualization/qmpvisualization.cpp
index 30e4075..62534bd 100644
--- a/visualization/qmpvisualization.cpp
+++ b/visualization/qmpvisualization.cpp
@@ -159,18 +159,18 @@ void qmpVisualization::showThread()
if(!api->getOptionString("Visualization/font2").length()||!font.loadTTF(api->getOptionString("Visualization/font2").c_str(),fontsize))
if(!font.loadTTF("/usr/share/fonts/truetype/freefont/FreeMono.ttf",fontsize))
if(!font.loadTTF("/usr/share/fonts/gnu-free/FreeMono.otf",fontsize))
- if(!font.loadTTF((std::string(getenv("windir"))+"/Fonts/cour.ttf").c_str(),fontsize))
+ if(!font.loadTTF((std::string(getenv("windir")?getenv("windir"):"")+"/Fonts/cour.ttf").c_str(),fontsize))
printf("W: Font load failed.\n");
if(!api->getOptionString("Visualization/font2").length()||!fonthdpi.loadTTF(api->getOptionString("Visualization/font2").c_str(),180))
if(!fonthdpi.loadTTF("/usr/share/fonts/truetype/freefont/FreeMono.ttf",180))
if(!fonthdpi.loadTTF("/usr/share/fonts/gnu-free/FreeMono.otf",180))
- if(!fonthdpi.loadTTF((std::string(getenv("windir"))+"/Fonts/cour.ttf").c_str(),180))
+ if(!fonthdpi.loadTTF((std::string(getenv("windir")?getenv("windir"):"")+"/Fonts/cour.ttf").c_str(),180))
printf("W: Font load failed.\n");
if(!api->getOptionString("Visualization/font1").length()||!font2.loadTTF(api->getOptionString("Visualization/font1").c_str(),fontsize))
if(!font2.loadTTF("/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",fontsize))
if(!font2.loadTTF("/usr/share/fonts/wenquanyi/wqy-microhei/wqy-microhei.ttc",fontsize))
- if(!font2.loadTTF((std::string(getenv("windir"))+"/Fonts/msyh.ttc").c_str(),fontsize))
- if(!font2.loadTTF((std::string(getenv("windir"))+"/Fonts/segoeui.ttf").c_str(),fontsize))
+ if(!font2.loadTTF((std::string(getenv("windir")?getenv("windir"):"")+"/Fonts/msyh.ttc").c_str(),fontsize))
+ if(!font2.loadTTF((std::string(getenv("windir")?getenv("windir"):"")+"/Fonts/segoeui.ttf").c_str(),fontsize))
printf("W: Font load failed.\n");
if(horizontal)
{
@@ -751,14 +751,17 @@ void qmpVisualization::init()
{
cb=new CReaderCallBack(this);
hcb=new CEventHandlerCallBack(this);
- vi=new CDemoVisualization(this);
h=new CMidiVisualHandler(this);
frcb=new CFRFinishedCallBack(this);
closeh=new CloseHandler(this);
rendererTh=NULL;playing=false;
memset(spectra,0,sizeof(spectra));
memset(spectrar,0,sizeof(spectrar));
- api->registerVisualizationIntf(vi,"Visualization","Visualization",api->isDarkTheme()?":/img/visualization_i.svg":":/img/visualization.svg",0);
+ api->registerFunctionality(this,"Visualization","Visualization",api->isDarkTheme()?":/img/visualization_i.svg":":/img/visualization.svg",0,true);
+ api->registerUIHook("main.start",qmpVisualization::cbstart,(void*)this);
+ api->registerUIHook("main.stop",qmpVisualization::cbstop,(void*)this);
+ api->registerUIHook("main.pause",qmpVisualization::cbpause,(void*)this);
+ api->registerUIHook("main.reset",qmpVisualization::cbreset,(void*)this);
herif=api->registerEventReaderIntf(cb,NULL);
hehif=api->registerEventHandlerIntf(hcb,NULL);
hfrf=api->registerFileReadFinishedHandlerIntf(frcb,NULL);
@@ -788,7 +791,7 @@ void qmpVisualization::init()
api->registerOptionInt("Visualization-Appearance","Note stretch","Visualization/notestretch",20,500,100);
api->registerOptionInt("Visualization-Appearance","Minimum note length","Visualization/minnotelen",20,500,100);
api->registerOptionUint("Visualization-Appearance","Chequer board tint (AARRGGBB)","Visualization/chkrtint",0,0xFFFFFFFF,0xFF999999);
- api->registerOptionString("Visualization-Appearance","Background Image","Visualization/background","");
+ api->registerOptionString("Visualization-Appearance","Background Image","Visualization/background","",true);
api->registerOptionDouble("","","Visualization/px",-999999999,999999999,0);
api->registerOptionDouble("","","Visualization/py",-999999999,999999999,120);
api->registerOptionDouble("","","Visualization/pz",-999999999,999999999,70);
@@ -832,17 +835,37 @@ void qmpVisualization::deinit()
{
if(!api)return;close();tspool.clear();
for(unsigned i=0;i<pool.size();++i)delete pool[i];pool.clear();
- api->unregisterVisualizationIntf("Visualization");
+ api->unregisterFunctionality("Visualization");
api->unregisterEventReaderIntf(herif);
api->unregisterEventHandlerIntf(hehif);
api->unregisterFileReadFinishedHandlerIntf(hfrf);
- delete cb;delete hcb;delete vi;delete frcb;
+ delete cb;delete hcb;delete frcb;
delete h;delete closeh;
}
const char* qmpVisualization::pluginGetName()
{return "QMidiPlayer Default Visualization Plugin";}
const char* qmpVisualization::pluginGetVersion()
-{return "0.8.3";}
+{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 f9e6062..9d62397 100644
--- a/visualization/qmpvisualization.hpp
+++ b/visualization/qmpvisualization.hpp
@@ -12,7 +12,7 @@
#include "../include/qmpcorepublic.hpp"
class qmpVisualization;
-class CReaderCallBack:public IMidiCallBack
+class CReaderCallBack:public ICallBack
{
private:
qmpVisualization *par;
@@ -20,7 +20,7 @@ class CReaderCallBack:public IMidiCallBack
CReaderCallBack(qmpVisualization *_par){par=_par;}
void callBack(void *callerdata,void *userdata);
};
-class CEventHandlerCallBack:public IMidiCallBack
+class CEventHandlerCallBack:public ICallBack
{
private:
qmpVisualization *par;
@@ -28,7 +28,7 @@ class CEventHandlerCallBack:public IMidiCallBack
CEventHandlerCallBack(qmpVisualization *_par){par=_par;}
void callBack(void*,void*);
};
-class CFRFinishedCallBack:public IMidiCallBack
+class CFRFinishedCallBack:public ICallBack
{
private:
qmpVisualization *par;
@@ -42,7 +42,7 @@ struct MidiVisualEvent
uint32_t key,vel;
uint32_t ch;
};
-class qmpVisualization:public qmpPluginIntf
+class qmpVisualization:public qmpPluginIntf,public qmpFuncBaseIntf
{
friend class CEventHandlerCallBack;
friend class CReaderCallBack;
@@ -52,7 +52,6 @@ class qmpVisualization:public qmpPluginIntf
qmpPluginAPI* api;
CReaderCallBack* cb;
CEventHandlerCallBack* hcb;
- qmpVisualizationIntf* vi;
CFRFinishedCallBack* frcb;
std::thread* rendererTh;
std::vector<MidiVisualEvent*>pool;
@@ -83,18 +82,23 @@ class qmpVisualization:public qmpPluginIntf
public:
qmpVisualization(qmpPluginAPI* _api);
~qmpVisualization();
+ void show();
+ void close();
bool update();
void start();
void stop();
void pause();
- void show();
- void close();
void reset();
void init();
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
@@ -122,20 +126,6 @@ class CloseHandler:public smHandler
}
};
-class CDemoVisualization:public qmpVisualizationIntf
-{
- private:
- qmpVisualization* par;
- public:
- CDemoVisualization(qmpVisualization *p){par=p;}
- void show(){par->show();}
- void close(){par->close();}
- void start(){par->start();}
- void stop(){par->stop();}
- void pause(){par->pause();}
- void reset(){par->reset();}
-};
-
extern "C"{
EXPORTSYM qmpPluginIntf* qmpPluginGetInterface(qmpPluginAPI* api)
{return new qmpVisualization(api);}