drumstick 2.0.0
pianoscene.h
Go to the documentation of this file.
1/*
2 Virtual Piano Widget for Qt5
3 Copyright (C) 2008-2020, 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>
27#include "pianokey.h"
28#include "keylabel.h"
29
34
35namespace 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 );
55
56 QSize sizeHint() const;
57 void setKeyboardMap( KeyboardMap *map );
60 void setPianoHandler(PianoHandler *handler);
61
63 void setHighlightPalette( const PianoPalette& p );
65 void setBackgroundPalette( const PianoPalette& p );
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);
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
84 void setShowLabels(const LabelVisibility show);
86 void setAlterations(const LabelAlteration use);
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);
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
125 signals:
133 void noteOn(int n, int v);
141 void noteOff(int n, int v);
147 void signalName(const QString& name);
148
149 protected:
150 void showKeyOn( PianoKey *key, QColor color, int vel );
151 void showKeyOn( PianoKey *key, int vel );
152 void showKeyOff( PianoKey *key, int vel );
153 void displayKeyOn(PianoKey *key);
154 void keyOn( PianoKey *key );
155 void keyOff( PianoKey *key );
156 void keyOn( PianoKey *key, qreal pressure );
157 void keyOff( PianoKey *key, qreal pressure );
158 PianoKey *getKeyForPos( const QPointF &p ) const;
159 PianoKey *getPianoKey( const int key ) const;
160 QString noteName( PianoKey *key );
161 void mouseMoveEvent ( QGraphicsSceneMouseEvent *mouseEvent ) override;
162 void mousePressEvent ( QGraphicsSceneMouseEvent *mouseEvent ) override;
163 void mouseReleaseEvent ( QGraphicsSceneMouseEvent *mouseEvent ) override;
164 void keyPressEvent ( QKeyEvent *keyEvent ) override;
165 void keyReleaseEvent ( QKeyEvent *keyEvent ) override;
166 bool event(QEvent *event) override;
167
168 void triggerNoteOn( const int note, const int vel );
169 void triggerNoteOff( const int note, const int vel );
170 int getNoteFromKey( const int key ) const;
171 void setHighlightColorFromPolicy(PianoKey *key, const int vel);
172 void hideOrShowKeys();
173 void refreshKeys();
174
175 private:
176 class PianoScenePrivate;
177 QScopedPointer<PianoScenePrivate> d;
178 };
179
181
182}} // namespace drumstick::widgets
183
184#endif /*PIANOSCENE_H_*/
The QEvent class is the base class of all event classes.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
The QObject class is the base class of all Qt objects.
The PianoHandler class callbacks.
Definition pianokeybd.h:72
The PianoPalette class.
void allKeysOff()
Deactivates all keys.
void triggerNoteOn(const int note, const int vel)
Performs a Note On MIDI event for the given MIDI note number and velocity.
void resetKeyPressedColor()
Assigns the default highlight palette colors and assigns it to the scene.
void keyOff(const int note)
Produces a MIDI Note Off event and deactivates the corresponding key for the given MIDI note number.
void showKeyOff(PianoKey *key, int vel)
Displays as deactivated a key.
void setBackgroundPalette(const PianoPalette &p)
Assigns the active background palette.
void setKeyPressedColor(const QColor &color)
Assigns a single color for key highlight.
void setRawKeyboardMode(const bool b)
Assigns the low level computer keyboard mode.
void keyOn(const int note)
Produces a MIDI Note On event and highlights the corresponding key for the given MIDI note number.
void useStandardNoteNames()
Assigns the standard note names, clearing the list of custom note names.
void hideOrShowKeys()
Hides or shows keys.
LabelCentralOctave getOctave() const
Returns the central octave name policy.
PianoScene(const int baseOctave, const int numKeys, const int startKey, const QColor &keyPressedColor=QColor(), QObject *parent=nullptr)
Constructor.
bool event(QEvent *event) override
Processes touch screen events.
int baseOctave() const
Returns the base octave number.
PianoPalette getForegroundPalette()
Returns the active foreground palette.
void setHighlightPalette(const PianoPalette &p)
Assigns the active highlight palette.
void setShowColorScale(const bool show)
Enables or disables the color scale key background mode.
void setPianoHandler(PianoHandler *handler)
Assigns a PianoHandler pointer for processing note events.
void setKeyboardMap(KeyboardMap *map)
Assigns the computer keyboard note map.
void noteOff(int n, int v)
This signal is emitted for each Note Off MIDI event created using the computer keyboard,...
void setVelocity(const int velocity)
Assigns the MIDI note velocity parameter that is assigned to the MIDI OUT notes.
void setMinNote(const int note)
Assigns the minimum MIDI note number that will be displayed.
bool showColorScale() const
Returns whether the color scale mode is enabled.
void setBaseOctave(const int base)
Assigns the octave base number.
PianoKey * getKeyForPos(const QPointF &p) const
Returns the piano key for the given scene point coordenates.
void signalName(const QString &name)
signalName is emitted for each note created, and contains a string with the MIDI note number and the ...
int numKeys() const
Returns the number of keys that will be displayed.
PianoPalette getHighlightPalette()
Returns the palette used for highlighting the played keys.
void setKeyboardEnabled(const bool enable)
Enables or disables the computer keyboard note generation.
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override
This event handler, for event mouseEvent, is reimplemented to receive mouse move events for the scene...
void triggerNoteOff(const int note, const int vel)
Performs a Note Off MIDI event for the given MIDI note number and velocity.
PianoKey * getPianoKey(const int key) const
Returns the piano key object corresponding to the given computer keyboard key.
int getVelocity()
Returns the MIDI note velocity parameter that is assigned to the MIDI OUT notes.
int getChannel() const
Returns the MIDI channel that is assigned to the output events, or used to filter the input events (u...
void setForegroundPalette(const PianoPalette &p)
Assigns the active foreground palette.
void keyPressEvent(QKeyEvent *keyEvent) override
This event handler, for event keyEvent, is reimplemented to receive keypress events.
void setVelocityTint(const bool enable)
Enables or disables the velocity parameter of note events to influence the highlight key colors.
bool velocityTint() const
Returns whether the velocity parameter of note events is used to influence the highlight key colors.
QColor getKeyPressedColor() const
Returns the single highlight palette color.
int getNoteFromKey(const int key) const
Returns the note number for the given computer keyboard key code.
void refreshLabels()
Refresh the visibility and other attributes of the labels shown over the piano keys.
void showNoteOff(const int note, int vel=-1)
Displays deactivated the corresponding key for a given MIDI note, with MIDI velocity.
void setShowLabels(const LabelVisibility show)
Assigns the label visibility policy to the piano keys.
void refreshKeys()
Refresh the background colors of all the piano keys.
QSize sizeHint() const
Returns the calculated size of the scene.
bool isOctaveStart(const int note)
Returns whether the given note number is a octave startup note.
void setAlterations(const LabelAlteration use)
Assigns the alterations name policy.
PianoPalette getBackgroundPalette()
Returns the background palette.
QStringList standardNoteNames() const
Returns the standard note names list.
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override
This event handler, for event mouseEvent, is reimplemented to receive mouse press events for the scen...
void setTranspose(const int transpose)
Assigns the transpose amount in semitones.
int getMaxNote() const
Returns the maximum MIDI note number that will be displayed.
LabelAlteration alterations() const
Returns the alterations name policy.
void setHighlightColorFromPolicy(PianoKey *key, const int vel)
Assigns to the given key the highlight color from the active highlight palette and the given MIDI vel...
PianoHandler * getPianoHandler() const
Gets the PianoHandler pointer to the note receiver.
void showKeyOn(PianoKey *key, QColor color, int vel)
Displays highlighted the activated key with the supplied color and note velocity.
KeyboardMap * getKeyboardMap() const
Returns the computer keyboard note map.
bool isMouseEnabled() const
Returns whether the computer keyboard note generation is enabled.
bool getRawKeyboardMode() const
Returns whether the low level computer keyboard mode is enabled.
void noteOn(int n, int v)
This signal is emitted for each Note On MIDI event created using the computer keyboard,...
void showNoteOn(const int note, QColor color, int vel=-1)
Displays highlighted the corresponding key for a given MIDI note, with a color and MIDI velocity.
void keyReleaseEvent(QKeyEvent *keyEvent) override
This event handler, for event keyEvent, is reimplemented to receive key release events.
void setMaxNote(const int note)
Assigns the maximum MIDI note number that will be displayed.
void retranslate()
Retranslates the standard note names.
int startKey() const
Returns the first key number that will be displayed.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override
This event handler, for event mouseEvent, is reimplemented to receive mouse release events for the sc...
void setTouchEnabled(const bool enable)
Enables or disables the touch screen note generation.
void displayKeyOn(PianoKey *key)
Displays the note label over a highligted key.
void useCustomNoteNames(const QStringList &names)
Assigns the list of custom note names, and enables this mode.
void setMouseEnabled(const bool enable)
Enables or disables the mouse note generation.
void setChannel(const int channel)
Assigns the MIDI channel that is included into the output events, or used to filter the input events ...
int getMinNote() const
Returns the minimum MIDI note number that will be displayed.
void setOrientation(const LabelOrientation orientation)
Assigns the label orientation policy.
QStringList customNoteNames() const
Returns the custom note names list.
LabelVisibility showLabels() const
Returns the label visibility policy (display note names over the piano keys).
bool isTouchEnabled() const
Returns whether the touch screen note generation is enabled.
int getTranspose() const
Returns the transpose amount in semitones.
QString noteName(PianoKey *key)
Returns the note name string that will be displayed over a given piano key.
LabelAlteration
Labels for Alterations.
Definition pianokeybd.h:118
LabelCentralOctave
Labels Central Octave.
Definition pianokeybd.h:145
LabelVisibility
Labels Visibility.
Definition pianokeybd.h:108
LabelOrientation
Labels Orientation.
Definition pianokeybd.h:127
QHash< int, int > KeyboardMap
KeyboardMap.
Definition pianokeybd.h:96
Declaration of the KeyLabel class.
Drumstick Widgets library MIDI related widgets and functions.
Drumstick common.
Declaration of the PianoKey class.
Piano Keyboard Widget.
Piano Palette declarations.