From eba45fdf11a98113b439db0510b55f14845db8fb Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 22 Apr 2019 00:16:50 +0800 Subject: New development cycle! Partially reintroduce High DPI handling. Pressing enter when a preset is focused now opens the preset selection dialog. Close all functionality windows before shutting down. Temporary fix for switching all channels of an external synth to mono mode unintentionally. And the most important one of them all: simple visualization! I'm ditching the 0.8.6 cycle because there was no clear goal for that release now (as the OPL3 emulation is now delayed indefinitely). In contrast, the 0.8.7 release has a pretty good-looking feature set mainly focused on improving support for external synthesizers: - Per-device initialization profile. - Instrument mapping files. - And a simple visualization ~~for showing off your external synthesizers~~. As always no ETA is set, nor will I promise the implementaion of all the features listed above. --- simple-visualization/qmpkeyboardwindow.cpp | 36 ++++++++++++++++ simple-visualization/qmpkeyboardwindow.hpp | 36 ++++++++++++++++ simple-visualization/qmppianowidget.cpp | 62 +++++++++++++++++++++++++++ simple-visualization/qmppianowidget.hpp | 25 +++++++++++ simple-visualization/simple-visualization.pro | 39 +++++++++++++++++ simple-visualization/simplevisualization.cpp | 29 +++++++++++++ simple-visualization/simplevisualization.hpp | 32 ++++++++++++++ 7 files changed, 259 insertions(+) create mode 100644 simple-visualization/qmpkeyboardwindow.cpp create mode 100644 simple-visualization/qmpkeyboardwindow.hpp create mode 100644 simple-visualization/qmppianowidget.cpp create mode 100644 simple-visualization/qmppianowidget.hpp create mode 100644 simple-visualization/simple-visualization.pro create mode 100644 simple-visualization/simplevisualization.cpp create mode 100644 simple-visualization/simplevisualization.hpp (limited to 'simple-visualization') diff --git a/simple-visualization/qmpkeyboardwindow.cpp b/simple-visualization/qmpkeyboardwindow.cpp new file mode 100644 index 0000000..a42a2e0 --- /dev/null +++ b/simple-visualization/qmpkeyboardwindow.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "qmpkeyboardwindow.hpp" + +qmpKeyboardWindow::qmpKeyboardWindow(qmpPluginAPI *_api,QWidget *parent): + QWidget(parent,Qt::Dialog),api(_api) +{ + setLayout(new QVBoxLayout()); + 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); +} +qmpKeyboardWindow::~qmpKeyboardWindow() +{ +} +void qmpKeyboardWindow::closeEvent(QCloseEvent *event) +{ + api->setFuncState("Keyboard",false); + event->accept(); +} +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(void* callerdata,void* userdata) +{ + qmpKeyboardWindow *w=(qmpKeyboardWindow*)userdata; + SEventCallBackData *cbd=(SEventCallBackData*)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 new file mode 100644 index 0000000..a99e62e --- /dev/null +++ b/simple-visualization/qmpkeyboardwindow.hpp @@ -0,0 +1,36 @@ +#ifndef QMPKEYBOARDWINDOW_HPP +#define QMPKEYBOARDWINDOW_HPP + +#include "../include/qmpcorepublic.hpp" +#include "qmppianowidget.hpp" + +#include + +class EventCallback:public QObject,public ICallBack +{ + Q_OBJECT + public: + void callBack(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; + public: + qmpKeyboardWindow(qmpPluginAPI *_api,QWidget *parent); + ~qmpKeyboardWindow(); + void resetAll(); + protected: + void closeEvent(QCloseEvent *event); + public slots: + void onkeystatesupdate(int ch,int key,bool state); +}; + +#endif diff --git a/simple-visualization/qmppianowidget.cpp b/simple-visualization/qmppianowidget.cpp new file mode 100644 index 0000000..febd90f --- /dev/null +++ b/simple-visualization/qmppianowidget.cpp @@ -0,0 +1,62 @@ +#include +#include +#include "qmppianowidget.hpp" + +qmpPianoWidget::qmpPianoWidget(QWidget *parent) : QWidget(parent) +{ + memset(keystates,0,sizeof(keystates)); +} +void qmpPianoWidget::setKeyState(int key,bool state) +{ + keystates[key]=state; + update(); +} +void qmpPianoWidget::reset() +{ + memset(keystates,0,sizeof(keystates)); + update(); +} +QSize qmpPianoWidget::minimumSizeHint()const +{ + return QSize(320,22); +} + +void qmpPianoWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + for(int i=0;i<128;++i) + { + QRectF r=getKeyRect(i); + paintKey(r,QColor(keystates[i]?0xff66cc:0x66ccff)); + } +} + +QRectF qmpPianoWidget::getKeyRect(int key) +{ + int octave=key/12;key%=12; + bool is_black=(key<5&&(key&1))||(key>5&&((key&1)^1)); + double key_width=width()/75.; + QRectF ret(0,0,key_width,height()/2.); + if(!is_black) + { + ret.moveTop(height()/2.); + int shift=(key+(key>=5))>>1; + ret.moveLeft((octave*7+shift)*key_width); + } + else + ret.moveLeft((octave*7+(key+(key>=5))/2.)*key_width); + return ret; +} +void qmpPianoWidget::paintKey(QRectF keyrect,QColor keycolor) +{ + QColor bordercolor(keycolor); + if(keycolor.valueF()>0.5) + bordercolor=bordercolor.darker(150); + else + bordercolor=bordercolor.lighter(150); + QPainter *p=new QPainter(this); + p->setPen(bordercolor); + p->setBrush(QBrush(keycolor)); + p->drawRect(keyrect.adjusted(1,1,-1,-1)); + delete p; +} diff --git a/simple-visualization/qmppianowidget.hpp b/simple-visualization/qmppianowidget.hpp new file mode 100644 index 0000000..22af6ce --- /dev/null +++ b/simple-visualization/qmppianowidget.hpp @@ -0,0 +1,25 @@ +#ifndef QMPPIANOWIDGET_HPP +#define QMPPIANOWIDGET_HPP + +#include +#include + +class qmpPianoWidget : public QWidget +{ + Q_OBJECT + public: + explicit qmpPianoWidget(QWidget *parent = nullptr); + void setKeyState(int key,bool state); + void reset(); + QSize minimumSizeHint()const override; + + protected: + void paintEvent(QPaintEvent *event)override; + + private: + bool keystates[128]; + QRectF getKeyRect(int key); + void paintKey(QRectF keyrect,QColor keycolor); +}; + +#endif // QMPPIANOWIDGET_HPP diff --git a/simple-visualization/simple-visualization.pro b/simple-visualization/simple-visualization.pro new file mode 100644 index 0000000..7a22769 --- /dev/null +++ b/simple-visualization/simple-visualization.pro @@ -0,0 +1,39 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-04-08T17:50:57 +# +#------------------------------------------------- + +QT += widgets +QT += gui + +TARGET = simple-visualization +TEMPLATE = lib + +DEFINES += SIMPLEVISUALIZATION_LIBRARY + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + simplevisualization.cpp \ + qmppianowidget.cpp \ + qmpkeyboardwindow.cpp + +HEADERS += \ + simplevisualization.hpp \ + qmppianowidget.hpp \ + qmpkeyboardwindow.hpp + +unix { + target.path = /usr/lib + INSTALLS += target +} diff --git a/simple-visualization/simplevisualization.cpp b/simple-visualization/simplevisualization.cpp new file mode 100644 index 0000000..0a1de02 --- /dev/null +++ b/simple-visualization/simplevisualization.cpp @@ -0,0 +1,29 @@ +#include "simplevisualization.hpp" +#include "qmpkeyboardwindow.hpp" + +qmpSimpleVisualization::qmpSimpleVisualization(qmpPluginAPI *_api){api=_api;} +void qmpSimpleVisualization::show(){p->show();} +void qmpSimpleVisualization::close(){p->close();} +void qmpSimpleVisualization::init() +{ + api->registerFunctionality(this,"Keyboard","Keyboard",api->isDarkTheme()?":/img/visualization_i.svg":":/img/visualization.svg",0,true); + p=new qmpKeyboardWindow(api,NULL); + uihs=api->registerUIHook("main.stop",qmpSimpleVisualization::cbstop,(void*)this); +} +void qmpSimpleVisualization::deinit() +{ + if(!api)return;close(); + api->unregisterFunctionality("Keyboard"); + api->unregisterUIHook("main.stop",uihs); + delete p; +} +const char* qmpSimpleVisualization::pluginGetName() +{return "QMidiPlayer Simple Visualization Plugin";} +const char* qmpSimpleVisualization::pluginGetVersion() +{return "0.8.6";} + +void qmpSimpleVisualization::cbstop(void*,void* usrd) +{ + qmpSimpleVisualization *v=(qmpSimpleVisualization*)usrd; + v->p->resetAll(); +} diff --git a/simple-visualization/simplevisualization.hpp b/simple-visualization/simplevisualization.hpp new file mode 100644 index 0000000..b3edeee --- /dev/null +++ b/simple-visualization/simplevisualization.hpp @@ -0,0 +1,32 @@ +#ifndef SIMPLEVISUALIZATION_HPP +#define SIMPLEVISUALIZATION_HPP + +#include "../include/qmpcorepublic.hpp" + +class qmpKeyboardWindow; +class qmpSimpleVisualization:public qmpPluginIntf,public qmpFuncBaseIntf +{ + private: + qmpPluginAPI* api; + qmpKeyboardWindow *p; + int uihs; + public: + qmpSimpleVisualization(qmpPluginAPI* _api); + void show(); + void close(); + void init(); + void deinit(); + const char* pluginGetName(); + const char* pluginGetVersion(); + + static void cbstop(void* cbd,void* usrd); +}; + +extern "C"{ + EXPORTSYM qmpPluginIntf* qmpPluginGetInterface(qmpPluginAPI* api) + {return new qmpSimpleVisualization(api);} + EXPORTSYM const char* qmpPluginGetAPIRev() + {return QMP_PLUGIN_API_REV;} +} + +#endif // SIMPLEVISUALIZATION_HPP -- cgit v1.2.3