drumstick 2.7.2
pianokeybd.h
Go to the documentation of this file.
1/*
2 Virtual Piano Widget for Qt
3 Copyright (C) 2008-2022, 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 PIANOKEYBD_H
20#define PIANOKEYBD_H
21
22#include <QGraphicsView>
23#include <QScopedPointer>
24#include <QGraphicsScene>
25#include "macros.h"
26#include "pianopalette.h"
27
33namespace drumstick { namespace widgets {
34
35 Q_NAMESPACE
36
47 public:
48 virtual ~RawKbdHandler() = default;
54 virtual bool handleKeyPressed(int keycode) = 0;
60 virtual bool handleKeyReleased(int keycode) = 0;
61 };
62
74 {
75 public:
76 virtual ~PianoHandler() = default;
82 virtual void noteOn( const int note, const int vel ) = 0;
88 virtual void noteOff( const int note, const int vel ) = 0;
89 };
90
98 typedef QHash<int, int> KeyboardMap;
99
100 extern DRUMSTICK_EXPORT KeyboardMap g_DefaultKeyMap;
101 extern DRUMSTICK_EXPORT KeyboardMap g_DefaultRawKeyMap;
102
103 const int DEFAULTSTARTINGKEY = 9;
104 const int DEFAULTBASEOCTAVE = 1;
105 const int DEFAULTNUMBEROFKEYS = 88;
106
115 };
116 Q_ENUM_NS(LabelVisibility)
117
118
125 };
126 Q_ENUM_NS(LabelAlteration)
127
128
135 };
136 Q_ENUM_NS(LabelOrientation)
137
138
145 };
146 Q_ENUM_NS(LabelNaming)
147
148
155 OctaveC5
156 };
157 Q_ENUM_NS(LabelCentralOctave)
158
159
165 class DRUMSTICK_EXPORT PianoKeybd : public QGraphicsView, public RawKbdHandler
166 {
167 Q_OBJECT
168 Q_PROPERTY( int baseOctave READ baseOctave WRITE setBaseOctave )
169 Q_PROPERTY( int numKeys READ numKeys WRITE setNumKeys )
170 Q_PROPERTY( int rotation READ getRotation WRITE setRotation )
171 Q_PROPERTY( QColor keyPressedColor READ getKeyPressedColor WRITE setKeyPressedColor )
172 Q_PROPERTY( drumstick::widgets::LabelVisibility showLabels READ showLabels WRITE setShowLabels )
173 Q_PROPERTY( drumstick::widgets::LabelAlteration alterations READ labelAlterations WRITE setLabelAlterations )
174 Q_PROPERTY( drumstick::widgets::LabelOrientation labelOrientation READ labelOrientation WRITE setLabelOrientation )
175 Q_PROPERTY( drumstick::widgets::LabelCentralOctave labelOctave READ labelOctave WRITE setLabelOctave )
176 Q_PROPERTY( int transpose READ getTranspose WRITE setTranspose )
177 Q_PROPERTY( int startKey READ startKey WRITE setStartKey )
178 Q_PROPERTY( QFont labelFont READ font WRITE setFont )
179
180#ifndef Q_MOC_RUN
181 Q_CLASSINFO("Author", "Pedro Lopez-Cabanillas <plcl@users.sf.net>")
182 Q_CLASSINFO("URL", "https://sourceforge.net/projects/drumstick")
183 Q_CLASSINFO("Version", QT_STRINGIFY(VERSION))
184#endif
185
186 public:
187 explicit PianoKeybd(QWidget *parent = nullptr);
188 PianoKeybd(const int baseOctave, const int numKeys, const int startKey, QWidget *parent = nullptr);
189 virtual ~PianoKeybd();
190
191 void setFont(const QFont &font);
192 PianoHandler* getPianoHandler() const;
193 void setPianoHandler(PianoHandler* handler);
194
195 PianoPalette getHighlightPalette() const;
196 void setHighlightPalette(const PianoPalette& p );
197 PianoPalette getBackgroundPalette() const;
198 void setBackgroundPalette(const PianoPalette& p );
199 PianoPalette getForegroundPalette() const;
200 void setForegroundPalette(const PianoPalette& p );
201
202 bool showColorScale() const;
203 void setShowColorScale(const bool show);
204
205 void useCustomNoteNames(const QStringList& names);
206 void useStandardNoteNames();
207 QStringList customNoteNames() const;
208 QStringList standardNoteNames() const;
209 void retranslate();
210
211 int baseOctave() const;
212 void setBaseOctave(const int baseOctave);
213 int numKeys() const;
214 int startKey() const;
215 void setNumKeys(const int numKeys, const int startKey = DEFAULTSTARTINGKEY);
216 int getRotation() const;
217 void setRotation(int r);
218 QColor getKeyPressedColor() const;
219 void setKeyPressedColor(const QColor& c);
220 void resetKeyPressedColor();
221 LabelVisibility showLabels() const;
222 void setShowLabels(const LabelVisibility show);
223 LabelAlteration labelAlterations() const;
224 void setLabelAlterations(const LabelAlteration use);
225 LabelOrientation labelOrientation() const;
226 void setLabelOrientation(const LabelOrientation orientation);
227 LabelCentralOctave labelOctave() const;
228 void setLabelOctave(const LabelCentralOctave octave);
229 int getTranspose() const;
230 void setTranspose(int t);
231 int getChannel() const;
232 void setChannel(const int c);
233 int getVelocity() const;
234 void setVelocity(const int v);
235
236 bool isKeyboardEnabled() const;
237 void setKeyboardEnabled( const bool enable );
238 bool isMouseEnabled() const;
239 void setMouseEnabled( const bool enable );
240 bool isTouchEnabled() const;
241 void setTouchEnabled( const bool enable );
242 bool velocityTint() const ;
243 void setVelocityTint( const bool enable );
244 void allKeysOff();
245
246 QSize sizeHint() const override;
247 void setKeyboardMap(KeyboardMap* m);
248 KeyboardMap* getKeyboardMap();
249 void resetKeyboardMap();
250 void setRawKeyboardMap(KeyboardMap* m);
251 KeyboardMap* getRawKeyboardMap();
252 void resetRawKeyboardMap();
253 bool getRawKeyboardMode() const;
254 void setRawKeyboardMode(const bool b);
255
256 void showNoteOn( const int note, QColor color, int vel = -1 );
257 void showNoteOn( const int note, int vel = -1 );
258 void showNoteOff( const int note, int vel = -1 );
259
260 // RawKbdHandler methods
261 bool handleKeyPressed(int keycode) override;
262 bool handleKeyReleased(int keycode) override;
263
264 void setKeyPicture(const bool natural, const QPixmap& pix);
265 QPixmap getKeyPicture(const bool natural);
266
267 void setUseKeyPictures(const bool enable);
268 bool getUseKeyPictures() const;
269
270 void setUsingNativeFilter(const bool newState);
271 bool isUsingNativeFilter() const;
272
273 void setOctaveSubscript(const bool enable);
274 bool octaveSubscript() const;
275
276 void setStartKey(const int startKey);
277
278 signals:
286 void noteOn( int midiNote, int vel );
294 void noteOff( int midiNote, int vel );
300 void signalName( const QString& name );
301
302 protected:
303 void initialize();
304 void initDefaultMap();
305 void initScene(int base, int num, int ini, const QColor& c = QColor());
306 void resizeEvent(QResizeEvent *event) override;
307 bool viewportEvent(QEvent *ev) override;
308
309 private:
310 class PianoKeybdPrivate;
311 QScopedPointer<PianoKeybdPrivate> d;
312 };
313
316}} // namespace drumstick::widgets
317
318#endif // PIANOKEYBD_H
The QEvent class is the base class of all event classes.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
The PianoHandler class callbacks.
Definition: pianokeybd.h:74
virtual void noteOff(const int note, const int vel)=0
noteOff handles MIDI note off events
virtual void noteOn(const int note, const int vel)=0
noteOn handles MIDI note on events
The PianoKeybd class.
Definition: pianokeybd.h:166
void signalName(const QString &name)
signalName is emitted for each note created, and contains a string with the MIDI note number and the ...
void noteOff(int midiNote, int vel)
This signal is emitted for each Note Off MIDI event created using the computer keyboard,...
void noteOn(int midiNote, int vel)
This signal is emitted for each Note On MIDI event created using the computer keyboard,...
The PianoPalette class.
Definition: pianopalette.h:61
The RawKbdHandler class callbacks.
Definition: pianokeybd.h:46
virtual bool handleKeyReleased(int keycode)=0
handleKeyReleased handles low level computer keyboard reelase events
virtual bool handleKeyPressed(int keycode)=0
handleKeyPressed handles low level computer keyboard press events
LabelAlteration
Labels for Alterations.
Definition: pianokeybd.h:121
DRUMSTICK_EXPORT KeyboardMap g_DefaultKeyMap
Global Key Map Variable.
Definition: pianokeybd.cpp:39
LabelCentralOctave
Labels Central Octave.
Definition: pianokeybd.h:151
LabelVisibility
Labels Visibility.
Definition: pianokeybd.h:110
LabelNaming
Labels Naming.
Definition: pianokeybd.h:141
const int DEFAULTNUMBEROFKEYS
Default number of piano keys.
Definition: pianokeybd.h:105
LabelOrientation
Labels Orientation.
Definition: pianokeybd.h:131
const int DEFAULTSTARTINGKEY
Default starting key (A)
Definition: pianokeybd.h:103
QHash< int, int > KeyboardMap
KeyboardMap.
Definition: pianokeybd.h:98
DRUMSTICK_EXPORT KeyboardMap g_DefaultRawKeyMap
Global Raw Key Map Variable.
Definition: pianokeybd.cpp:74
const int DEFAULTBASEOCTAVE
Default base octave.
Definition: pianokeybd.h:104
@ ShowSharps
Show sharps on black keys.
Definition: pianokeybd.h:122
@ ShowNothing
Do not show names on black keys.
Definition: pianokeybd.h:124
@ ShowFlats
Show flats on black keys.
Definition: pianokeybd.h:123
@ OctaveC3
Central C, MIDI note #60 is C3.
Definition: pianokeybd.h:153
@ OctaveNothing
Don't show octave numbers.
Definition: pianokeybd.h:152
@ OctaveC5
Central C, MIDI note #60 is C5.
Definition: pianokeybd.h:155
@ OctaveC4
Central C, MIDI note #60 is C4.
Definition: pianokeybd.h:154
@ ShowAlways
Show always note names.
Definition: pianokeybd.h:114
@ ShowMinimum
Show only note C names.
Definition: pianokeybd.h:112
@ ShowActivated
Show names when notes are activated.
Definition: pianokeybd.h:113
@ ShowNever
Don't show note names.
Definition: pianokeybd.h:111
@ CustomNamesWithSharps
Show custom names with sharps.
Definition: pianokeybd.h:143
@ StandardNames
Show standard names.
Definition: pianokeybd.h:142
@ CustomNamesWithFlats
Show custom names with flats.
Definition: pianokeybd.h:144
@ AutomaticOrientation
Show horizonal or vertical names depending on the size.
Definition: pianokeybd.h:134
@ VerticalOrientation
Show vertical names.
Definition: pianokeybd.h:133
@ HorizontalOrientation
Show horizontal names.
Definition: pianokeybd.h:132
Drumstick visibility macros.
Drumstick common.
Definition: alsaclient.cpp:68
Piano Palette declarations.