aboutsummaryrefslogtreecommitdiff
path: root/simple-visualization/qmpkeyboardwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'simple-visualization/qmpkeyboardwindow.cpp')
-rw-r--r--simple-visualization/qmpkeyboardwindow.cpp23
1 files changed, 11 insertions, 12 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);
-}