drumstick 2.6.1
pianokeybd.h
Go to the documentation of this file.
1/*
2 Virtual Piano Widget for Qt5
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
45 public:
46 virtual ~RawKbdHandler() = default;
52 virtual bool handleKeyPressed(int keycode) = 0;
58 virtual bool handleKeyReleased(int keycode) = 0;
59 };
60
72 {
73 public:
74 virtual ~PianoHandler() = default;
80 virtual void noteOn( const int note, const int vel ) = 0;
86 virtual void noteOff( const int note, const int vel ) = 0;
87 };
88
96 typedef QHash<int, int> KeyboardMap;
97
98 extern DRUMSTICK_EXPORT KeyboardMap g_DefaultKeyMap;
99 extern DRUMSTICK_EXPORT KeyboardMap g_DefaultRawKeyMap;
100
101 const int DEFAULTSTARTINGKEY = 9;
102 const int DEFAULTBASEOCTAVE = 1;
103 const int DEFAULTNUMBEROFKEYS = 88;
104
113 };
114
122 };
123
131 };
132
140 };
141
149 OctaveC5
150 };
151
158 class DRUMSTICK_EXPORT PianoKeybd : public QGraphicsView, public RawKbdHandler
159 {
160 Q_OBJECT
161 Q_PROPERTY( int baseOctave READ baseOctave WRITE setBaseOctave )
162 Q_PROPERTY( int numKeys READ numKeys WRITE setNumKeys )
163 Q_PROPERTY( int rotation READ getRotation WRITE setRotation )
164 Q_PROPERTY( QColor keyPressedColor READ getKeyPressedColor WRITE setKeyPressedColor )
165 Q_PROPERTY( LabelVisibility showLabels READ showLabels WRITE setShowLabels )
166 Q_PROPERTY( LabelAlteration alterations READ labelAlterations WRITE setLabelAlterations )
167 Q_PROPERTY( LabelOrientation labelOrientation READ labelOrientation WRITE setLabelOrientation )
168 Q_PROPERTY( LabelCentralOctave labelOctave READ labelOctave WRITE setLabelOctave )
169 Q_PROPERTY( int transpose READ getTranspose WRITE setTranspose )
170
171#ifndef Q_MOC_RUN
172 Q_CLASSINFO("Author", "Pedro Lopez-Cabanillas <plcl@users.sf.net>")
173 Q_CLASSINFO("URL", "https://sourceforge.net/projects/drumstick")
174 Q_CLASSINFO("Version", QT_STRINGIFY(VERSION))
175#endif
176
177 public:
178 explicit PianoKeybd(QWidget *parent = nullptr);
179 PianoKeybd(const int baseOctave, const int numKeys, const int startKey, QWidget *parent = nullptr);
180 virtual ~PianoKeybd();
181
182 Q_ENUM(LabelVisibility);
183 Q_ENUM(LabelAlteration);
184 Q_ENUM(LabelOrientation);
185 Q_ENUM(LabelNaming);
186 Q_ENUM(LabelCentralOctave);
187
188 void setFont(const QFont &font);
189 PianoHandler* getPianoHandler() const;
190 void setPianoHandler(PianoHandler* handler);
191
192 PianoPalette getHighlightPalette() const;
193 void setHighlightPalette(const PianoPalette& p );
194 PianoPalette getBackgroundPalette() const;
195 void setBackgroundPalette(const PianoPalette& p );
196 PianoPalette getForegroundPalette() const;
197 void setForegroundPalette(const PianoPalette& p );
198
199 bool showColorScale() const;
200 void setShowColorScale(const bool show);
201
202 void useCustomNoteNames(const QStringList& names);
203 void useStandardNoteNames();
204 QStringList customNoteNames() const;
205 QStringList standardNoteNames() const;
206 void retranslate();
207
208 int baseOctave() const;
209 void setBaseOctave(const int baseOctave);
210 int numKeys() const;
211 int startKey() const;
212 void setNumKeys(const int numKeys, const int startKey = DEFAULTSTARTINGKEY);
213 int getRotation() const;
214 void setRotation(int r);
215 QColor getKeyPressedColor() const;
216 void setKeyPressedColor(const QColor& c);
217 void resetKeyPressedColor();
218 LabelVisibility showLabels() const;
219 void setShowLabels(const LabelVisibility show);
220 LabelAlteration labelAlterations() const;
221 void setLabelAlterations(const LabelAlteration use);
222 LabelOrientation labelOrientation() const;
223 void setLabelOrientation(const LabelOrientation orientation);
224 LabelCentralOctave labelOctave() const;
225 void setLabelOctave(const LabelCentralOctave octave);
226 int getTranspose() const;
227 void setTranspose(int t);
228 int getChannel() const;
229 void setChannel(const int c);
230 int getVelocity() const;
231 void setVelocity(const int v);
232
233 bool isKeyboardEnabled() const;
234 void setKeyboardEnabled( const bool enable );
235 bool isMouseEnabled() const;
236 void setMouseEnabled( const bool enable );
237 bool isTouchEnabled() const;
238 void setTouchEnabled( const bool enable );
239 bool velocityTint() const ;
240 void setVelocityTint( const bool enable );
241 void allKeysOff();
242
243 QSize sizeHint() const override;
244 void setKeyboardMap(KeyboardMap* m);
245 KeyboardMap* getKeyboardMap();
246 void resetKeyboardMap();
247 void setRawKeyboardMap(KeyboardMap* m);
248 KeyboardMap* getRawKeyboardMap();
249 void resetRawKeyboardMap();
250 bool getRawKeyboardMode() const;
251 void setRawKeyboardMode(const bool b);
252
253 void showNoteOn( const int note, QColor color, int vel = -1 );
254 void showNoteOn( const int note, int vel = -1 );
255 void showNoteOff( const int note, int vel = -1 );
256
257 // RawKbdHandler methods
258 bool handleKeyPressed(int keycode) override;
259 bool handleKeyReleased(int keycode) override;
260
261 void setKeyPicture(const bool natural, const QPixmap& pix);
262 QPixmap getKeyPicture(const bool natural);
263
264 void setUseKeyPictures(const bool enable);
265 bool getUseKeyPictures() const;
266
267 void setUsingNativeFilter(const bool newState);
268 bool isUsingNativeFilter() const;
269
270 signals:
278 void noteOn( int midiNote, int vel );
286 void noteOff( int midiNote, int vel );
292 void signalName( const QString& name );
293
294 protected:
295 void initialize();
296 void initDefaultMap();
297 void initScene(int base, int num, int ini, const QColor& c = QColor());
298 void resizeEvent(QResizeEvent *event) override;
299 bool viewportEvent(QEvent *ev) override;
300
301 private:
302 class PianoKeybdPrivate;
303 QScopedPointer<PianoKeybdPrivate> d;
304 };
305
308}} // namespace drumstick::widgets
309
310#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:72
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:159
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:44
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:118
DRUMSTICK_EXPORT KeyboardMap g_DefaultKeyMap
Global Key Map Variable.
Definition: pianokeybd.cpp:39
LabelCentralOctave
Labels Central Octave.
Definition: pianokeybd.h:145
LabelVisibility
Labels Visibility.
Definition: pianokeybd.h:108
LabelNaming
Labels Naming.
Definition: pianokeybd.h:136
const int DEFAULTNUMBEROFKEYS
Default number of piano keys.
Definition: pianokeybd.h:103
LabelOrientation
Labels Orientation.
Definition: pianokeybd.h:127
const int DEFAULTSTARTINGKEY
Default starting key (A)
Definition: pianokeybd.h:101
QHash< int, int > KeyboardMap
KeyboardMap.
Definition: pianokeybd.h:96
DRUMSTICK_EXPORT KeyboardMap g_DefaultRawKeyMap
Global Raw Key Map Variable.
Definition: pianokeybd.cpp:74
const int DEFAULTBASEOCTAVE
Default base octave.
Definition: pianokeybd.h:102
@ ShowSharps
Show sharps on black keys.
Definition: pianokeybd.h:119
@ ShowNothing
Do not show names on black keys.
Definition: pianokeybd.h:121
@ ShowFlats
Show flats on black keys.
Definition: pianokeybd.h:120
@ OctaveC3
Central C, MIDI note #60 is C3.
Definition: pianokeybd.h:147
@ OctaveNothing
Don't show octave numbers.
Definition: pianokeybd.h:146
@ OctaveC5
Central C, MIDI note #60 is C5.
Definition: pianokeybd.h:149
@ OctaveC4
Central C, MIDI note #60 is C4.
Definition: pianokeybd.h:148
@ ShowAlways
Show always note names.
Definition: pianokeybd.h:112
@ ShowMinimum
Show only note C names.
Definition: pianokeybd.h:110
@ ShowActivated
Show names when notes are activated.
Definition: pianokeybd.h:111
@ ShowNever
Don't show note names.
Definition: pianokeybd.h:109
@ CustomNamesWithSharps
Show custom names with sharps.
Definition: pianokeybd.h:138
@ StandardNames
Show standard names.
Definition: pianokeybd.h:137
@ CustomNamesWithFlats
Show custom names with flats.
Definition: pianokeybd.h:139
@ AutomaticOrientation
Show horizonal or vertical names depending on the size.
Definition: pianokeybd.h:130
@ VerticalOrientation
Show vertical names.
Definition: pianokeybd.h:129
@ HorizontalOrientation
Show horizontal names.
Definition: pianokeybd.h:128
Drumstick visibility macros.
Drumstick common.
Definition: alsaclient.cpp:68
Piano Palette declarations.