diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-04-22 00:16:50 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-04-22 00:16:50 +0800 |
commit | eba45fdf11a98113b439db0510b55f14845db8fb (patch) | |
tree | 1d73816893ccb36fa3a5f1f5c63a629bac7f0787 /simple-visualization/qmppianowidget.cpp | |
parent | d2b00a80c237c1c3d8bc9551966cf781292525e6 (diff) | |
download | QMidiPlayer-eba45fdf11a98113b439db0510b55f14845db8fb.tar.xz |
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.
Diffstat (limited to 'simple-visualization/qmppianowidget.cpp')
-rw-r--r-- | simple-visualization/qmppianowidget.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
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 <cstring> +#include <QPainter> +#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; +} |