diff options
Diffstat (limited to 'simple-visualization')
-rw-r--r-- | simple-visualization/qmpkeyboardwindow.cpp | 23 | ||||
-rw-r--r-- | simple-visualization/qmpkeyboardwindow.hpp | 14 |
2 files changed, 14 insertions, 23 deletions
diff --git a/simple-visualization/qmpkeyboardwindow.cpp b/simple-visualization/qmpkeyboardwindow.cpp index f2cc8b7..562596c 100644 --- a/simple-visualization/qmpkeyboardwindow.cpp +++ b/simple-visualization/qmpkeyboardwindow.cpp @@ -9,11 +9,20 @@ qmpKeyboardWindow::qmpKeyboardWindow(qmpPluginAPI *_api,QWidget *parent): for(int ch=0;ch<16;++ch) layout()->addWidget(pw[ch]=new qmpPianoWidget(this)); hide(); - api->registerEventHandlerIntf(ec=new EventCallback(),this); - connect(ec,&EventCallback::keystateupdated,this,&qmpKeyboardWindow::onkeystatesupdate); + eh=api->registerEventHandler( + [this](const void* ee,void*){ + const SEvent *e=(const SEvent*)ee; + if((e->type&0xF0)==0x80||((e->type&0xF0)==0x90&&e->p2==0)) + emit keystateupdated(e->type&0xF,e->p1,false); + if((e->type&0xF0)==0x90&&e->p2>0) + emit keystateupdated(e->type&0xF,e->p1,e->p2>0); + } + ,nullptr); + connect(this,&qmpKeyboardWindow::keystateupdated,this,&qmpKeyboardWindow::onkeystatesupdate); } qmpKeyboardWindow::~qmpKeyboardWindow() { + api->unregisterEventHandler(eh); } void qmpKeyboardWindow::closeEvent(QCloseEvent *event) { @@ -24,13 +33,3 @@ void qmpKeyboardWindow::onkeystatesupdate(int ch,int key,bool state) {pw[ch]->setKeyState(key,state);} void qmpKeyboardWindow::resetAll() {for(int ch=0;ch<16;++ch)pw[ch]->reset();} - -void EventCallback::callBack(const void *callerdata,void* userdata) -{ - 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) - emit keystateupdated(cbd->type&0xF,cbd->p1,cbd->p2>0); -} diff --git a/simple-visualization/qmpkeyboardwindow.hpp b/simple-visualization/qmpkeyboardwindow.hpp index 2b618fa..563b6b4 100644 --- a/simple-visualization/qmpkeyboardwindow.hpp +++ b/simple-visualization/qmpkeyboardwindow.hpp @@ -6,29 +6,21 @@ #include <QWidget> -class EventCallback:public QObject,public ICallBack -{ - Q_OBJECT - public: - void callBack(const void *callerdata,void *userdata); - signals: - void keystateupdated(int ch,int key,bool state); -}; - class qmpKeyboardWindow:public QWidget { Q_OBJECT - friend class EventCallback; private: qmpPianoWidget *pw[16]; qmpPluginAPI *api; - EventCallback *ec; + int eh; public: qmpKeyboardWindow(qmpPluginAPI *_api,QWidget *parent); ~qmpKeyboardWindow(); void resetAll(); protected: void closeEvent(QCloseEvent *event); + signals: + void keystateupdated(int ch,int key,bool state); public slots: void onkeystatesupdate(int ch,int key,bool state); }; |