drumstick  2.5.0
pianoscene.h
Go to the documentation of this file.
1 /*
2  Virtual Piano Widget for Qt5
3  Copyright (C) 2008-2021, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef PIANOSCENE_H_
20 #define PIANOSCENE_H_
21 
22 #include <QGraphicsScene>
23 #include <QScopedPointer>
24 #include <QHash>
25 #include <drumstick/pianokeybd.h>
26 #include <drumstick/pianopalette.h>
27 #include "pianokey.h"
28 #include "keylabel.h"
29 
35 namespace drumstick { namespace widgets {
36 
45  class DRUMSTICK_EXPORT PianoScene : public QGraphicsScene
46  {
47  Q_OBJECT
48  public:
49  PianoScene ( const int baseOctave,
50  const int numKeys,
51  const int startKey,
52  const QColor& keyPressedColor = QColor(),
53  QObject * parent = nullptr );
54  ~PianoScene();
55 
56  QSize sizeHint() const;
57  void setKeyboardMap( KeyboardMap *map );
58  KeyboardMap *getKeyboardMap() const;
59  PianoHandler *getPianoHandler() const;
60  void setPianoHandler(PianoHandler *handler);
61 
62  PianoPalette getHighlightPalette();
63  void setHighlightPalette( const PianoPalette& p );
64  PianoPalette getBackgroundPalette();
65  void setBackgroundPalette( const PianoPalette& p );
66  PianoPalette getForegroundPalette();
67  void setForegroundPalette( const PianoPalette& p );
68 
69  bool showColorScale() const;
70  void setShowColorScale(const bool show);
71 
72  QColor getKeyPressedColor() const;
73  void setKeyPressedColor(const QColor& color);
74  void resetKeyPressedColor();
75 
76  int getMinNote() const;
77  void setMinNote(const int note);
78  int getMaxNote() const;
79  void setMaxNote(const int note);
80  int getTranspose() const;
81  void setTranspose(const int transpose);
82 
83  LabelVisibility showLabels() const;
84  void setShowLabels(const LabelVisibility show);
85  LabelAlteration alterations() const;
86  void setAlterations(const LabelAlteration use);
87  LabelCentralOctave getOctave() const;
88  void setOctave(const LabelCentralOctave octave);
89  LabelOrientation getOrientation() const;
90  void setOrientation(const LabelOrientation orientation);
91 
92  bool isKeyboardEnabled() const;
93  void setKeyboardEnabled( const bool enable );
94  bool isMouseEnabled() const;
95  void setMouseEnabled( const bool enable );
96  bool isTouchEnabled() const;
97  void setTouchEnabled( const bool enable );
98  bool velocityTint() const;
99  void setVelocityTint( const bool enable );
100  bool isOctaveStart( const int note );
101 
102  void showNoteOn( const int note, QColor color, int vel = -1 );
103  void showNoteOn( const int note, int vel = -1 );
104  void showNoteOff( const int note, int vel = -1 );
105  int baseOctave() const;
106  void setBaseOctave( const int base );
107  int numKeys() const;
108  int startKey() const;
109  void allKeysOff();
110  void keyOn( const int note );
111  void keyOff( const int note );
112  bool getRawKeyboardMode() const;
113  void setRawKeyboardMode(const bool b);
114  void useCustomNoteNames(const QStringList& names);
115  void useStandardNoteNames();
116  QStringList customNoteNames() const;
117  QStringList standardNoteNames() const;
118  int getVelocity();
119  void setVelocity(const int velocity);
120  int getChannel() const;
121  void setChannel(const int channel);
122  void retranslate();
123  void refreshLabels();
124  void hideOrShowKeys();
125  void refreshKeys();
126 
127  void setKeyPicture(const bool natural, const QPixmap& pix);
128  QPixmap getKeyPicture(const bool natural);
129 
130  void setUseKeyPictures(const bool enable);
131  bool getUseKeyPictures() const;
132 
133  void saveData(QByteArray& ba);
134  void loadData(QByteArray& ba);
135 
136  signals:
144  void noteOn(int n, int v);
152  void noteOff(int n, int v);
158  void signalName(const QString& name);
159 
160  protected:
161  void showKeyOn( PianoKey *key, QColor color, int vel );
162  void showKeyOn( PianoKey *key, int vel );
163  void showKeyOff( PianoKey *key, int vel );
164  void displayKeyOn(PianoKey *key);
165  void keyOn( PianoKey *key );
166  void keyOff( PianoKey *key );
167  void keyOn( PianoKey *key, qreal pressure );
168  void keyOff( PianoKey *key, qreal pressure );
169  PianoKey *getKeyForPos( const QPointF &p ) const;
170  PianoKey *getPianoKey( const int key ) const;
171  QString noteName( PianoKey *key );
172  void mouseMoveEvent ( QGraphicsSceneMouseEvent *mouseEvent ) override;
173  void mousePressEvent ( QGraphicsSceneMouseEvent *mouseEvent ) override;
174  void mouseReleaseEvent ( QGraphicsSceneMouseEvent *mouseEvent ) override;
175  void keyPressEvent ( QKeyEvent *keyEvent ) override;
176  void keyReleaseEvent ( QKeyEvent *keyEvent ) override;
177  bool event(QEvent *event) override;
178 
179  void triggerNoteOn( const int note, const int vel );
180  void triggerNoteOff( const int note, const int vel );
181  int getNoteFromKey( const int key ) const;
182  void setHighlightColorFromPolicy(PianoKey *key, const int vel);
183 
184  private:
185  class PianoScenePrivate;
186  QScopedPointer<PianoScenePrivate> d;
187  };
188 
191 }} // namespace drumstick::widgets
192 
193 #endif /*PIANOSCENE_H_*/
The PianoHandler class callbacks.
Definition: pianokeybd.h:71
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The PianoScene class is a QGraphicsScene composed by a number of graphics items: the piano keys...
Definition: pianoscene.h:45
LabelOrientation
Labels Orientation.
Definition: pianokeybd.h:127
The PianoPalette class.
Definition: pianopalette.h:60
QHash< int, int > KeyboardMap
KeyboardMap.
Definition: pianokeybd.h:96
The QObject class is the base class of all Qt objects.
Declaration of the PianoKey class.
Drumstick common.
Definition: alsaclient.cpp:68
LabelVisibility
Labels Visibility.
Definition: pianokeybd.h:108
Declaration of the KeyLabel class.
LabelAlteration
Labels for Alterations.
Definition: pianokeybd.h:118
LabelCentralOctave
Labels Central Octave.
Definition: pianokeybd.h:145
Piano Keyboard Widget.
The QEvent class is the base class of all event classes.
Piano Palette declarations.