Skip to content

Commit be65fec

Browse files
author
plcl
committed
* new option: show colorized scale
* updated translations git-svn-id: https://vmpk.svn.sourceforge.net/svnroot/vmpk/trunk@349 64c129e3-8119-4a17-9932-72cb407d3134
1 parent b7b4e16 commit be65fec

18 files changed

+1333
-1215
lines changed

desktop/src/colordialog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ ColorDialog::currentPalette()
226226
return m_currentPalette;
227227
}
228228

229+
PianoPalette *
230+
ColorDialog::getPalette(int pal)
231+
{
232+
if (pal >= 0 && pal < m_paletteList.count()) {
233+
return m_paletteList[pal];
234+
}
235+
return 0;
236+
}
237+
229238
QList<QString>
230239
ColorDialog::availablePaletteNames()
231240
{

desktop/src/colordialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ColorDialog : public QDialog
3636
explicit ColorDialog(QWidget *parent = 0);
3737
~ColorDialog();
3838
PianoPalette *currentPalette();
39+
PianoPalette *getPalette(int pal);
3940
QList<QString> availablePaletteNames();
4041
QColor getColor(int i);
4142
void saveCurrentPalette();

desktop/src/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const QString QSTR_DRIVERNAMENET("Network UDP (IpMIDI)");
103103
const QString QSTR_MULTICAST_ADDRESS("225.0.0.37");
104104
const QString QSTR_PALETTEPREFIX("Palette_");
105105
const QString QSTR_CURRENTPALETTE("CurrentPalette");
106+
const QString QSTR_SHOWCOLORSCALE("ShowColorScale");
106107

107108
#if defined(Q_OS_LINUX)
108109
const QString QSTR_DRIVERDEFAULT(QSTR_DRIVERNAMEALSA);

desktop/src/pianokey.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ void PianoKey::setPressed(bool p)
8181
update();
8282
}
8383
}
84+
85+
void PianoKey::resetBrush()
86+
{
87+
if (m_black)
88+
m_brush = blackBrush;
89+
else
90+
m_brush = whiteBrush;
91+
}

desktop/src/pianokey.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class VPIANO_EXPORT PianoKey : public QGraphicsRectItem
3232
PianoKey(const QRectF &rect, const bool black, const int note);
3333
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
3434
int getNote() const { return m_note; }
35+
void setBrush(const QBrush& b) { m_brush = b; }
3536
void setPressedBrush(const QBrush& b) { m_selectedBrush = b; }
37+
void resetBrush();
3638
bool isPressed() const { return m_pressed; }
3739
void setPressed(bool p);
3840
int getDegree() const { return m_note % 12; }

desktop/src/pianoscene.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ PianoScene::PianoScene ( const int baseOctave,
4949
m_mousePressed( false ),
5050
m_velocity( 100 ),
5151
m_channel( 0 ),
52+
m_showColorScale( false ),
5253
m_handler( 0 ),
53-
m_palette( 0 )
54+
m_palette( 0 ),
55+
m_scalePalette( 0 )
5456
{
5557
QBrush hilightBrush(m_keyPressedColor.isValid() ? m_keyPressedColor : QApplication::palette().highlight());
5658
QFont lblFont(QApplication::font());
@@ -498,6 +500,21 @@ void PianoScene::refreshLabels()
498500
}
499501
}
500502

503+
void PianoScene::refreshKeys()
504+
{
505+
QList<PianoKey*>::ConstIterator it;
506+
for(it = m_keys.constBegin(); it != m_keys.constEnd(); ++it) {
507+
PianoKey* key = (*it);
508+
if (m_showColorScale && m_scalePalette != 0) {
509+
int degree = key->getNote() % 12;
510+
key->setBrush(m_scalePalette->getColor(degree));
511+
} else {
512+
key->resetBrush();
513+
}
514+
key->setPressed(false);
515+
}
516+
}
517+
501518
void PianoScene::setShowLabels(bool show)
502519
{
503520
if (m_showLabels != show) {
@@ -597,3 +614,12 @@ void PianoScene::retranslate()
597614
<< trUtf8("B");
598615
refreshLabels();
599616
}
617+
618+
void PianoScene::setShowColorScale(const bool show)
619+
{
620+
if (m_showColorScale != show && m_scalePalette != 0 ) {
621+
m_showColorScale = show;
622+
refreshKeys();
623+
invalidate();
624+
}
625+
}

desktop/src/pianoscene.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class VPIANO_EXPORT PianoScene : public QGraphicsScene
5252
void setPianoHandler(PianoHandler* handler) { m_handler = handler; }
5353
PianoPalette* getPianoPalette() const { return m_palette; }
5454
void setPianoPalette( PianoPalette* p ) { m_palette = p; }
55+
void setColorScalePalette( PianoPalette* p ) { m_scalePalette = p; }
5556

5657
QColor getKeyPressedColor() const { return m_keyPressedColor; }
5758
void setKeyPressedColor(const QColor& color);
@@ -71,6 +72,8 @@ class VPIANO_EXPORT PianoScene : public QGraphicsScene
7172
void setMouseEnabled( const bool enable );
7273
bool isTouchEnabled() const { return m_touchEnabled; }
7374
void setTouchEnabled( const bool enable );
75+
bool showColorScale() const { return m_showColorScale; }
76+
void setShowColorScale(const bool show);
7477

7578
void showNoteOn( const int note, QColor color, int vel = -1 );
7679
void showNoteOn( const int note, int vel = -1 );
@@ -116,6 +119,7 @@ class VPIANO_EXPORT PianoScene : public QGraphicsScene
116119
private:
117120
void hideOrShowKeys();
118121
void refreshLabels();
122+
void refreshKeys();
119123
void triggerNoteOn( const int note, const int vel );
120124
void triggerNoteOff( const int note, const int vel );
121125
int getNoteFromKey( const int key ) const;
@@ -136,6 +140,7 @@ class VPIANO_EXPORT PianoScene : public QGraphicsScene
136140
bool m_mousePressed;
137141
int m_velocity;
138142
int m_channel;
143+
bool m_showColorScale;
139144
PianoHandler* m_handler;
140145
KeyboardMap* m_keybdMap;
141146
QList<PianoKey*> m_keys;
@@ -144,6 +149,7 @@ class VPIANO_EXPORT PianoScene : public QGraphicsScene
144149
QStringList m_names_s;
145150
QStringList m_names_f;
146151
PianoPalette* m_palette;
152+
PianoPalette* m_scalePalette;
147153
};
148154

149155
#endif /*PIANOSCENE_H_*/

desktop/src/vpiano.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ VPiano::VPiano( QWidget * parent, Qt::WindowFlags flags )
120120
connect(ui.actionMouseInput, SIGNAL(toggled(bool)), SLOT(slotMouseInput(bool)));
121121
connect(ui.actionTouchScreenInput, SIGNAL(toggled(bool)), SLOT(slotTouchScreenInput(bool)));
122122
connect(ui.actionColorPalette, SIGNAL(triggered()), SLOT(slotColorPolicy()));
123+
connect(ui.actionColorScale, SIGNAL(toggled(bool)), SLOT(slotColorScale(bool)));
123124
// Toolbars actions: toggle view
124125
connect(ui.toolBarNotes->toggleViewAction(), SIGNAL(toggled(bool)),
125126
ui.actionNotes, SLOT(setChecked(bool)));
@@ -143,8 +144,6 @@ VPiano::VPiano( QWidget * parent, Qt::WindowFlags flags )
143144
setWindowTitle("VMPK " + PGM_VERSION);
144145
#endif
145146
ui.pianokeybd->setPianoHandler(this);
146-
// PianoScene *scene = (PianoScene *) ui.pianokeybd->scene();
147-
// scene->setMouseEnabled(false);
148147
initialization();
149148
}
150149

@@ -718,6 +717,7 @@ void VPiano::readSettings()
718717
NetworkSettings::instance().setIface(QNetworkInterface::interfaceFromName(iface));
719718
#endif
720719
m_currentPalette = settings.value(QSTR_CURRENTPALETTE, PAL_SINGLE).toInt();
720+
bool colorScale = settings.value(QSTR_SHOWCOLORSCALE, false).toBool();
721721
settings.endGroup();
722722

723723
dlgColorPolicy()->loadPalette(m_currentPalette);
@@ -747,6 +747,7 @@ void VPiano::readSettings()
747747
ui.pianokeybd->setMouseEnabled(enableMouse);
748748
ui.pianokeybd->setTouchEnabled(enableTouch);
749749
ui.pianokeybd->getPianoScene()->setChannel(m_baseChannel);
750+
ui.actionColorScale->setChecked(colorScale);
750751
slotShowNoteNames();
751752
if (!insFileName.isEmpty()) {
752753
dlgPreferences()->setInstrumentsFileName(insFileName);
@@ -901,6 +902,7 @@ void VPiano::writeSettings()
901902
settings.setValue(QSTR_NETWORKIFACE, dlgPreferences()->getNetworkInterfaceName());
902903
#endif
903904
settings.setValue(QSTR_CURRENTPALETTE, m_currentPalette);
905+
settings.setValue(QSTR_SHOWCOLORSCALE, ui.actionColorScale->isChecked());
904906
settings.endGroup();
905907

906908
settings.beginGroup(QSTR_CONNECTIONS);
@@ -1548,7 +1550,9 @@ void VPiano::applyPreferences()
15481550
ui.pianokeybd->resetRawKeyboardMap();
15491551

15501552
m_currentPalette = dlgColorPolicy()->currentPalette()->paletteId();
1551-
ui.pianokeybd->getPianoScene()->setPianoPalette(dlgColorPolicy()->currentPalette());
1553+
currentPianoScene()->setPianoPalette(dlgColorPolicy()->currentPalette());
1554+
currentPianoScene()->setColorScalePalette(dlgColorPolicy()->getPalette(PAL_SCALE));
1555+
currentPianoScene()->setShowColorScale(ui.actionColorScale->isChecked());
15521556

15531557
populateInstruments();
15541558
populateControllers();
@@ -2477,3 +2481,13 @@ void VPiano::slotColorPolicy()
24772481
ui.pianokeybd->getPianoScene()->setPianoPalette(dlgColorPolicy()->currentPalette());
24782482
}
24792483
}
2484+
2485+
void VPiano::slotColorScale(bool value)
2486+
{
2487+
currentPianoScene()->setShowColorScale(value);
2488+
}
2489+
2490+
PianoScene *VPiano::currentPianoScene()
2491+
{
2492+
return ui.pianokeybd->getPianoScene();
2493+
}

desktop/src/vpiano.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ protected Q_SLOTS:
143143
void slotMouseInput(bool value);
144144
void slotTouchScreenInput(bool value);
145145
void slotColorPolicy();
146+
void slotColorScale(bool value);
146147
//void slotEditPrograms();
147148
//void slotDebugDestroyed(QObject *obj);
148149

@@ -198,6 +199,7 @@ protected Q_SLOTS:
198199
QString configuredLanguage();
199200
void enforceMIDIChannelState();
200201
QColor getColorFromPolicy(NoteOnEvent *ev);
202+
PianoScene *currentPianoScene();
201203

202204
About *dlgAbout();
203205
Preferences *dlgPreferences();

desktop/src/vpiano.ui

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<rect>
2424
<x>0</x>
2525
<y>0</y>
26-
<width>569</width>
27-
<height>219</height>
26+
<width>567</width>
27+
<height>217</height>
2828
</rect>
2929
</property>
3030
<property name="windowTitle">
@@ -49,7 +49,7 @@
4949
<rect>
5050
<x>0</x>
5151
<y>0</y>
52-
<width>569</width>
52+
<width>567</width>
5353
<height>24</height>
5454
</rect>
5555
</property>
@@ -100,6 +100,7 @@
100100
<addaction name="actionExtraControls"/>
101101
<addaction name="separator"/>
102102
<addaction name="actionNoteNames"/>
103+
<addaction name="actionColorScale"/>
103104
<addaction name="actionStatusBar"/>
104105
</widget>
105106
<widget class="QMenu" name="menuTools">
@@ -715,6 +716,14 @@
715716
<string>Color Palette</string>
716717
</property>
717718
</action>
719+
<action name="actionColorScale">
720+
<property name="checkable">
721+
<bool>true</bool>
722+
</property>
723+
<property name="text">
724+
<string>Color Scale</string>
725+
</property>
726+
</action>
718727
</widget>
719728
<customwidgets>
720729
<customwidget>

0 commit comments

Comments
 (0)