From a7407edaf81c685d4a389785a405a53a5de4b148 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 12 May 2020 00:58:40 +0800 Subject: Format EVERYTHING. Hopefully this will make the source code less horrendous and actually readable. The command used was: ``` astyle --suffix=none --style=allman --attach-extern-c --attach-closing-while --indent-switches --indent-after-parens --pad-oper --pad-header --unpad-paren --align-pointer=name --recursive './*.cpp,*.hpp' ``` --- simple-visualization/qmpkeyboardwindow.cpp | 107 ++++++++++++++------------- simple-visualization/qmpkeyboardwindow.hpp | 34 ++++----- simple-visualization/qmppianowidget.cpp | 105 +++++++++++++------------- simple-visualization/qmppianowidget.hpp | 28 +++---- simple-visualization/simplevisualization.cpp | 66 +++++++++++------ simple-visualization/simplevisualization.hpp | 42 ++++++----- 6 files changed, 204 insertions(+), 178 deletions(-) (limited to 'simple-visualization') diff --git a/simple-visualization/qmpkeyboardwindow.cpp b/simple-visualization/qmpkeyboardwindow.cpp index 2c5e70a..b33bb4b 100644 --- a/simple-visualization/qmpkeyboardwindow.cpp +++ b/simple-visualization/qmpkeyboardwindow.cpp @@ -6,66 +6,69 @@ #include "qmppianowidget.hpp" #include "qmpkeyboardwindow.hpp" -qmpKeyboardWindow::qmpKeyboardWindow(qmpPluginAPI *_api,QWidget *parent): - QWidget(parent,Qt::Dialog),api(_api) +qmpKeyboardWindow::qmpKeyboardWindow(qmpPluginAPI *_api, QWidget *parent): + QWidget(parent, Qt::Dialog), api(_api) { - setWindowTitle("Keyboard"); - QGridLayout *grid; - setLayout(grid=new QGridLayout()); - for(int ch=0;ch<16;++ch) - { - grid->addWidget(lb[ch]=new QLabel,ch,0); - grid->addWidget(pw[ch]=new qmpPianoWidget(this),ch,1); - lb[ch]->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)); - pw[ch]->setSizePolicy(QSizePolicy::Policy::Expanding,QSizePolicy::Policy::Preferred); - QPalette p=palette(); - p.setColor(QPalette::ColorRole::Highlight,api->getOptionUint("Keyboard/acolor"+std::to_string(ch))); - p.setColor(QPalette::ColorRole::Base,api->getOptionUint("Keyboard/bcolor"+std::to_string(ch))); - pw[ch]->setPalette(p); - } - hide(); - eh=api->registerEventHandler( - [this](const void* ee,void*){ - const SEvent *e=(const SEvent*)ee; - int ch=e->type&0xF; - if((e->type&0xF0)==0x80||((e->type&0xF0)==0x90&&e->p2==0)) - emit keystateupdated(ch,e->p1,false); - if((e->type&0xF0)==0x90&&e->p2>0) - emit keystateupdated(ch,e->p1,e->p2>0); - if((e->type&0xF0)==0xB0||(e->type&0xF0)==0xC0) - lb[ch]->setText( - QString::fromStdString(api->getChannelPresetString(ch))+ - QString("\nch:%1 v:0x%2 p:0x%3 e:0x%4") - .arg(ch+1,2,10,QChar('0')) - .arg(api->getChannelCC(ch,0x7),2,16,QChar('0')) - .arg(api->getChannelCC(ch,0xa),2,16,QChar('0')) - .arg(api->getChannelCC(ch,0xb),2,16,QChar('0'))); - } - ,nullptr,true); - connect(this,&qmpKeyboardWindow::keystateupdated,this,&qmpKeyboardWindow::onkeystatesupdate); + setWindowTitle("Keyboard"); + QGridLayout *grid; + setLayout(grid = new QGridLayout()); + for (int ch = 0; ch < 16; ++ch) + { + grid->addWidget(lb[ch] = new QLabel, ch, 0); + grid->addWidget(pw[ch] = new qmpPianoWidget(this), ch, 1); + lb[ch]->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont)); + pw[ch]->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Preferred); + QPalette p = palette(); + p.setColor(QPalette::ColorRole::Highlight, api->getOptionUint("Keyboard/acolor" + std::to_string(ch))); + p.setColor(QPalette::ColorRole::Base, api->getOptionUint("Keyboard/bcolor" + std::to_string(ch))); + pw[ch]->setPalette(p); + } + hide(); + eh = api->registerEventHandler( + [this](const void *ee, void *) + { + const SEvent *e = (const SEvent *)ee; + int ch = e->type & 0xF; + if ((e->type & 0xF0) == 0x80 || ((e->type & 0xF0) == 0x90 && e->p2 == 0)) + emit keystateupdated(ch, e->p1, false); + if ((e->type & 0xF0) == 0x90 && e->p2 > 0) + emit keystateupdated(ch, e->p1, e->p2 > 0); + if ((e->type & 0xF0) == 0xB0 || (e->type & 0xF0) == 0xC0) + lb[ch]->setText( + QString::fromStdString(api->getChannelPresetString(ch)) + + QString("\nch:%1 v:0x%2 p:0x%3 e:0x%4") + .arg(ch + 1, 2, 10, QChar('0')) + .arg(api->getChannelCC(ch, 0x7), 2, 16, QChar('0')) + .arg(api->getChannelCC(ch, 0xa), 2, 16, QChar('0')) + .arg(api->getChannelCC(ch, 0xb), 2, 16, QChar('0'))); + } + , nullptr, true); + connect(this, &qmpKeyboardWindow::keystateupdated, this, &qmpKeyboardWindow::onkeystatesupdate); } qmpKeyboardWindow::~qmpKeyboardWindow() { - api->unregisterEventHandler(eh); + api->unregisterEventHandler(eh); } void qmpKeyboardWindow::closeEvent(QCloseEvent *event) { - api->setFuncState("Keyboard",false); - event->accept(); + api->setFuncState("Keyboard", false); + event->accept(); +} +void qmpKeyboardWindow::onkeystatesupdate(int ch, int key, bool state) +{ + pw[ch]->setKeyState(key, state); } -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(); - lb[ch]->setText( - QString::fromStdString(api->getChannelPresetString(ch))+ - QString("\nch:%1 v:0x%2 p:0x%3 e:0x%4") - .arg(ch+1,2,10,QChar('0')) - .arg(api->getChannelCC(ch,0x7),2,16,QChar('0')) - .arg(api->getChannelCC(ch,0xa),2,16,QChar('0')) - .arg(api->getChannelCC(ch,0xb),2,16,QChar('0'))); - } + for (int ch = 0; ch < 16; ++ch) + { + pw[ch]->reset(); + lb[ch]->setText( + QString::fromStdString(api->getChannelPresetString(ch)) + + QString("\nch:%1 v:0x%2 p:0x%3 e:0x%4") + .arg(ch + 1, 2, 10, QChar('0')) + .arg(api->getChannelCC(ch, 0x7), 2, 16, QChar('0')) + .arg(api->getChannelCC(ch, 0xa), 2, 16, QChar('0')) + .arg(api->getChannelCC(ch, 0xb), 2, 16, QChar('0'))); + } } diff --git a/simple-visualization/qmpkeyboardwindow.hpp b/simple-visualization/qmpkeyboardwindow.hpp index 65ad266..b540cca 100644 --- a/simple-visualization/qmpkeyboardwindow.hpp +++ b/simple-visualization/qmpkeyboardwindow.hpp @@ -7,24 +7,24 @@ class QLabel; class qmpPianoWidget; -class qmpKeyboardWindow:public QWidget +class qmpKeyboardWindow: public QWidget { - Q_OBJECT - private: - qmpPianoWidget *pw[16]; - QLabel *lb[16]; - qmpPluginAPI *api; - 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); + Q_OBJECT +private: + qmpPianoWidget *pw[16]; + QLabel *lb[16]; + qmpPluginAPI *api; + 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); }; #endif diff --git a/simple-visualization/qmppianowidget.cpp b/simple-visualization/qmppianowidget.cpp index daeff25..05a84ed 100644 --- a/simple-visualization/qmppianowidget.cpp +++ b/simple-visualization/qmppianowidget.cpp @@ -4,82 +4,83 @@ qmpPianoWidget::qmpPianoWidget(QWidget *parent) : QWidget(parent) { - memset(keystates,0,sizeof(keystates)); - QPalette p=palette(); - p.setColor(QPalette::ColorRole::Highlight,0xff66cc); - p.setColor(QPalette::ColorRole::Base,0x66ccff); - setPalette(p); + memset(keystates, 0, sizeof(keystates)); + QPalette p = palette(); + p.setColor(QPalette::ColorRole::Highlight, 0xff66cc); + p.setColor(QPalette::ColorRole::Base, 0x66ccff); + setPalette(p); } -void qmpPianoWidget::setKeyState(int key,bool state) +void qmpPianoWidget::setKeyState(int key, bool state) { - keystates[key]=state; - update(); + keystates[key] = state; + update(); } void qmpPianoWidget::reset() { - memset(keystates,0,sizeof(keystates)); - update(); + memset(keystates, 0, sizeof(keystates)); + update(); } QSize qmpPianoWidget::minimumSizeHint()const { - return QSize(320,22); + return QSize(320, 22); } bool qmpPianoWidget::hasHeightForWidth()const { - return true; + return true; } int qmpPianoWidget::heightForWidth(int w)const { - return w*22/320; + return w * 22 / 320; } void qmpPianoWidget::paintEvent(QPaintEvent *event) { - Q_UNUSED(event) - for(int i=0;i<128;++i) - { - QRectF r=getKeyRect(i); - QColor activeColor=palette().color(QPalette::ColorRole::Highlight); - QColor inactiveColor=palette().color(QPalette::ColorRole::Base); - if(i/12%2) - { - if(inactiveColor.valueF()>0.5) - inactiveColor=inactiveColor.darker(112); - else - inactiveColor=inactiveColor.lighter(112); - } - paintKey(r,keystates[i]?activeColor:inactiveColor); - } + Q_UNUSED(event) + for (int i = 0; i < 128; ++i) + { + QRectF r = getKeyRect(i); + QColor activeColor = palette().color(QPalette::ColorRole::Highlight); + QColor inactiveColor = palette().color(QPalette::ColorRole::Base); + if (i / 12 % 2) + { + if (inactiveColor.valueF() > 0.5) + inactiveColor = inactiveColor.darker(112); + else + inactiveColor = inactiveColor.lighter(112); + } + paintKey(r, keystates[i] ? activeColor : inactiveColor); + } } 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; + 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) +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; + 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 index cca643c..aec034d 100644 --- a/simple-visualization/qmppianowidget.hpp +++ b/simple-visualization/qmppianowidget.hpp @@ -6,22 +6,22 @@ class qmpPianoWidget : public QWidget { - Q_OBJECT - public: - explicit qmpPianoWidget(QWidget *parent = nullptr); - void setKeyState(int key,bool state); - void reset(); - QSize minimumSizeHint()const override; - bool hasHeightForWidth()const override; - int heightForWidth(int w)const override; + Q_OBJECT +public: + explicit qmpPianoWidget(QWidget *parent = nullptr); + void setKeyState(int key, bool state); + void reset(); + QSize minimumSizeHint()const override; + bool hasHeightForWidth()const override; + int heightForWidth(int w)const override; - protected: - void paintEvent(QPaintEvent *event)override; +protected: + void paintEvent(QPaintEvent *event)override; - private: - bool keystates[128]; - QRectF getKeyRect(int key); - void paintKey(QRectF keyrect,QColor keycolor); +private: + bool keystates[128]; + QRectF getKeyRect(int key); + void paintKey(QRectF keyrect, QColor keycolor); }; #endif // QMPPIANOWIDGET_HPP diff --git a/simple-visualization/simplevisualization.cpp b/simple-visualization/simplevisualization.cpp index b93af30..0c3a5b9 100644 --- a/simple-visualization/simplevisualization.cpp +++ b/simple-visualization/simplevisualization.cpp @@ -1,33 +1,51 @@ #include "simplevisualization.hpp" #include "qmpkeyboardwindow.hpp" -qmpSimpleVisualization::qmpSimpleVisualization(qmpPluginAPI *_api){api=_api;} -void qmpSimpleVisualization::show(){p->show();} -void qmpSimpleVisualization::close(){p->close();} +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); - for(int i=0;i<16;++i) - { - api->registerOptionUint("","","Keyboard/acolor"+std::to_string(i),0,0xffffff,0xffff66cc); - api->registerOptionUint("","","Keyboard/bcolor"+std::to_string(i),0,0xffffff,0xff66ccff); - } - p=new qmpKeyboardWindow(api,(QWidget*)api->getMainWindow()); - auto refreshfn=[this](const void*,void*){this->p->resetAll();}; - uihs=api->registerUIHook("main.stop",refreshfn,nullptr); - uihsk=api->registerUIHook("main.seek",refreshfn,nullptr); - uihsk=api->registerUIHook("preset.set",refreshfn,nullptr); - uihsk=api->registerUIHook("channel.ccchange",refreshfn,nullptr); + api->registerFunctionality(this, "Keyboard", "Keyboard", api->isDarkTheme() ? ":/img/visualization_i.svg" : ":/img/visualization.svg", 0, true); + for (int i = 0; i < 16; ++i) + { + api->registerOptionUint("", "", "Keyboard/acolor" + std::to_string(i), 0, 0xffffff, 0xffff66cc); + api->registerOptionUint("", "", "Keyboard/bcolor" + std::to_string(i), 0, 0xffffff, 0xff66ccff); + } + p = new qmpKeyboardWindow(api, (QWidget *)api->getMainWindow()); + auto refreshfn = [this](const void *, void *) + { + this->p->resetAll(); + }; + uihs = api->registerUIHook("main.stop", refreshfn, nullptr); + uihsk = api->registerUIHook("main.seek", refreshfn, nullptr); + uihsk = api->registerUIHook("preset.set", refreshfn, nullptr); + uihsk = api->registerUIHook("channel.ccchange", refreshfn, nullptr); } void qmpSimpleVisualization::deinit() { - if(!api)return;close(); - api->unregisterFunctionality("Keyboard"); - api->unregisterUIHook("main.stop",uihs); - api->unregisterUIHook("main.seek",uihsk); - delete p; + if (!api) + return; + close(); + api->unregisterFunctionality("Keyboard"); + api->unregisterUIHook("main.stop", uihs); + api->unregisterUIHook("main.seek", uihsk); + delete p; +} +const char *qmpSimpleVisualization::pluginGetName() +{ + return "QMidiPlayer Simple Visualization Plugin"; +} +const char *qmpSimpleVisualization::pluginGetVersion() +{ + return PLUGIN_VERSION; } -const char* qmpSimpleVisualization::pluginGetName() -{return "QMidiPlayer Simple Visualization Plugin";} -const char* qmpSimpleVisualization::pluginGetVersion() -{return PLUGIN_VERSION;} diff --git a/simple-visualization/simplevisualization.hpp b/simple-visualization/simplevisualization.hpp index 58b02ac..6d09cb6 100644 --- a/simple-visualization/simplevisualization.hpp +++ b/simple-visualization/simplevisualization.hpp @@ -4,28 +4,32 @@ #include "../include/qmpcorepublic.hpp" class qmpKeyboardWindow; -class qmpSimpleVisualization:public qmpPluginIntf,public qmpFuncBaseIntf +class qmpSimpleVisualization: public qmpPluginIntf, public qmpFuncBaseIntf { - private: - qmpPluginAPI* api; - qmpKeyboardWindow *p; - int uihs; - int uihsk; - public: - qmpSimpleVisualization(qmpPluginAPI* _api); - void show(); - void close(); - void init(); - void deinit(); - const char* pluginGetName(); - const char* pluginGetVersion(); +private: + qmpPluginAPI *api; + qmpKeyboardWindow *p; + int uihs; + int uihsk; +public: + qmpSimpleVisualization(qmpPluginAPI *_api); + void show(); + void close(); + void init(); + void deinit(); + const char *pluginGetName(); + const char *pluginGetVersion(); }; -extern "C"{ - EXPORTSYM qmpPluginIntf* qmpPluginGetInterface(qmpPluginAPI* api) - {return new qmpSimpleVisualization(api);} - EXPORTSYM const char* qmpPluginGetAPIRev() - {return QMP_PLUGIN_API_REV;} +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