diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-05-26 15:55:28 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-05-26 15:55:28 +0800 |
commit | 7b03fd544837fbe0bc5a5373b60dfd5de50892e1 (patch) | |
tree | a343c4efea96295d60b6e4b7944b8fa23d118db0 /simple-visualization/qmpkeyboardwindow.cpp | |
parent | 3f72121ac41741d53e4916f1275cbd4f93259c4d (diff) | |
download | QMidiPlayer-7b03fd544837fbe0bc5a5373b60dfd5de50892e1.tar.xz |
Major code refactor continued and (mostly) concluded.
Removed all references to ICallback in official plugins.
New flag field in SEvent.
Further type usage corrections.
Diffstat (limited to 'simple-visualization/qmpkeyboardwindow.cpp')
-rw-r--r-- | simple-visualization/qmpkeyboardwindow.cpp | 23 |
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); -} |