aboutsummaryrefslogtreecommitdiff
path: root/simple-visualization
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2019-05-26 15:55:28 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2019-05-26 15:55:28 +0800
commit7b03fd544837fbe0bc5a5373b60dfd5de50892e1 (patch)
treea343c4efea96295d60b6e4b7944b8fa23d118db0 /simple-visualization
parent3f72121ac41741d53e4916f1275cbd4f93259c4d (diff)
downloadQMidiPlayer-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')
-rw-r--r--simple-visualization/qmpkeyboardwindow.cpp23
-rw-r--r--simple-visualization/qmpkeyboardwindow.hpp14
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);
};