drumstick
2.0.0
|
The PianoKeybd class. More...
#include <pianokeybd.h>
Signals | |
void | noteOn (int midiNote, int vel) |
This signal is emitted for each Note On MIDI event created using the computer keyboard, mouse or touch screen. More... | |
void | noteOff (int midiNote, int vel) |
This signal is emitted for each Note Off MIDI event created using the computer keyboard, mouse or touch screen. More... | |
void | signalName (const QString &name) |
signalName is emitted for each note created, and contains a string with the MIDI note number and the note name for each note on event. More... | |
Public Member Functions | |
PianoKeybd (QWidget *parent=nullptr) | |
Constructor. More... | |
PianoKeybd (const int baseOctave, const int numKeys, const int startKey, QWidget *parent=nullptr) | |
Constructor providing not only a parent widget, but also custom values for octave, number of keys and starting key. More... | |
virtual | ~PianoKeybd () |
Destructor. | |
void | setFont (const QFont &font) |
Assigns a typographic font for drawing the note labels over the piano keys. More... | |
PianoHandler * | getPianoHandler () const |
Gets the PianoHandler pointer to the note receiver. More... | |
void | setPianoHandler (PianoHandler *handler) |
Assigns a PianoHandler pointer for processing note events. More... | |
PianoPalette | getHighlightPalette () const |
Returns the palette used for highlighting the played keys. More... | |
void | setHighlightPalette (const PianoPalette &p) |
Assigns the palette used for highlighting the played keys. More... | |
PianoPalette | getBackgroundPalette () const |
Returns the palette used to paint the keys' background. More... | |
void | setBackgroundPalette (const PianoPalette &p) |
Assigns the palette used to paint the keys' background. More... | |
PianoPalette | getForegroundPalette () const |
Returns the palette used to paint texts over the keys like the note names or custom labels. More... | |
void | setForegroundPalette (const PianoPalette &p) |
Assigns the palette used to paint texts over the keys like the note names or custom labels. More... | |
bool | showColorScale () const |
Returns true if the color scale background palette is assigned and active. More... | |
void | setShowColorScale (const bool show) |
Enables or disables the color scale background palette. More... | |
void | useCustomNoteNames (const QStringList &names) |
Assigns a list of custom text labels to be displayer over the keys. More... | |
void | useStandardNoteNames () |
Disables the custom note names usage as labels over the keys, and restores the standard note names instead. | |
QStringList | customNoteNames () const |
Returns the list of custom note names. More... | |
QStringList | standardNoteNames () const |
Returns the list of standard note names. More... | |
void | retranslate () |
Updates the standard names of notes according to the currently active program language translation. More... | |
void | setBaseOctave (const int baseOctave) |
Assigns the base octave number. More... | |
int | startKey () const |
Returns the starting key note: C=0, A=9 and so on. More... | |
void | setNumKeys (const int numKeys, const int startKey=DEFAULTSTARTINGKEY) |
This method changes the number of displayed keys and the starting key number, keeping the other settings the same. More... | |
int | getRotation () const |
Returns the rotation angle in degrees, clockwise, of the piano view. More... | |
void | setRotation (int r) |
Rotates the keyboard view an angle clockwise. More... | |
QColor | getKeyPressedColor () const |
Returns the key highlight color. More... | |
void | setKeyPressedColor (const QColor &c) |
Assigns a single color for key highlight. More... | |
void | resetKeyPressedColor () |
Assigns the default highlight palette colors and assigns it to the scene. | |
void | setShowLabels (const LabelVisibility show) |
Assigns the label visibility policy. More... | |
LabelAlteration | labelAlterations () const |
Returns the label alterations policy. More... | |
void | setLabelAlterations (const LabelAlteration use) |
Assigns the label alterations policy. More... | |
void | setLabelOrientation (const LabelOrientation orientation) |
Assigns the labels orientation policy. More... | |
void | setLabelOctave (const LabelCentralOctave octave) |
Assigns the octave label policy. More... | |
int | getTranspose () const |
Returns the transpose amount in semitones. More... | |
void | setTranspose (int t) |
Assigns the transpose amount in semitones. More... | |
int | getChannel () const |
Returns the MIDI Channel (0-15). More... | |
void | setChannel (const int c) |
Assigns the MIDI Channel (0-15). More... | |
int | getVelocity () const |
Returns the MIDI note velocity. More... | |
void | setVelocity (const int v) |
Assigns the MIDI note velocity. More... | |
bool | isKeyboardEnabled () const |
Returns whether the computer keyboard is enabled. More... | |
void | setKeyboardEnabled (const bool enable) |
Enables or disables the computer keyboard note input. More... | |
bool | isMouseEnabled () const |
Returns whether the mouse note input is enabled. More... | |
void | setMouseEnabled (const bool enable) |
Enables or disables the mouse note input. More... | |
bool | isTouchEnabled () const |
Returns whether the touch screen note input is enabled. More... | |
void | setTouchEnabled (const bool enable) |
Enables or disables the touch screen note input. More... | |
bool | velocityTint () const |
Returns whether the note MIDI velocity influences the highlight color tint. More... | |
void | setVelocityTint (const bool enable) |
Enables or disables the note MIDI velocity influencing the highlight color tint. More... | |
void | allKeysOff () |
Forces all active notes to silence. | |
QSize | sizeHint () const override |
Overrides QGraphicsView::sizeHint() providing a size value based on the piano scene. More... | |
void | setKeyboardMap (KeyboardMap *m) |
Assigns the computer keyboard note map. More... | |
KeyboardMap * | getKeyboardMap () |
Returns the computer keyboard note map. More... | |
void | resetKeyboardMap () |
Resets the low level computer keyboard note map to the default one. | |
void | setRawKeyboardMap (KeyboardMap *m) |
Assigns the low level computer keyboard note map. More... | |
KeyboardMap * | getRawKeyboardMap () |
Returns the low level computer keyboard note map. More... | |
void | resetRawKeyboardMap () |
Resets the computer keyboard note map to the default one. | |
bool | getRawKeyboardMode () const |
Returns the low level computer keyboard note map. More... | |
void | setRawKeyboardMode (const bool b) |
Enables or disables the low level computer keyboard mode. More... | |
void | showNoteOn (const int note, QColor color, int vel=-1) |
Highlights one note key with the specified color and velocity. More... | |
void | showNoteOn (const int note, int vel=-1) |
Highlights one note key with the specified velocity. More... | |
void | showNoteOff (const int note, int vel=-1) |
Shows inactive one note key with the specified velocity. More... | |
bool | handleKeyPressed (int keycode) override |
handleKeyPressed handles low level computer keyboard press events More... | |
bool | handleKeyReleased (int keycode) override |
handleKeyReleased handles low level computer keyboard reelase events More... | |
Protected Member Functions | |
void | initialize () |
This method is called from the available constructors to initialize some widget attributes, settings, and optimizations. | |
void | initScene (int base, int num, int ini, const QColor &c=QColor()) |
Creates and initializes a new PianoScene instance and assigns it to this widget. More... | |
void | resizeEvent (QResizeEvent *event) override |
This method overrides QGraphicsView::resizeEvent() to keep the aspect ratio of the keys scene when the view is resized. More... | |
Properties | |
int | baseOctave |
Returns the base octave number. More... | |
int | numKeys |
Returns the total number of keys. More... | |
LabelVisibility | showLabels |
Returns the label visibility policy. More... | |
LabelOrientation | labelOrientation |
Returns the labels orientation policy. More... | |
LabelCentralOctave | labelOctave |
Returns the octave label policy. More... | |
The PianoKeybd class.
This class is a widget providing the look and behavior of a musical piano keyboard. It is implemented as a QGraphicsView displaying the contents of a QGraphicsScene (PianoScene).
Definition at line 158 of file pianokeybd.h.
|
explicit |
Constructor.
This is the usual constructor when using QtDesigner and without providing custom settings, using the default octave, number of keys and starting key.
parent | Widget's parent |
Definition at line 220 of file pianokeybd.cpp.
References drumstick::widgets::DEFAULTBASEOCTAVE, drumstick::widgets::DEFAULTNUMBEROFKEYS, drumstick::widgets::DEFAULTSTARTINGKEY, PianoKeybd::initialize(), and PianoKeybd::initScene().
PianoKeybd | ( | const int | baseOctave, |
const int | numKeys, | ||
const int | startKey, | ||
QWidget * | parent = nullptr |
||
) |
Constructor providing not only a parent widget, but also custom values for octave, number of keys and starting key.
baseOctave | The base octave number |
numKeys | The number of displayed keys |
startKey | The startup key |
parent | The widget's parent |
Definition at line 235 of file pianokeybd.cpp.
References PianoKeybd::initialize(), PianoKeybd::initScene(), and PianoKeybd::startKey().
QStringList customNoteNames | ( | ) | const |
Returns the list of custom note names.
Definition at line 379 of file pianokeybd.cpp.
PianoPalette getBackgroundPalette | ( | ) | const |
Returns the palette used to paint the keys' background.
Definition at line 300 of file pianokeybd.cpp.
int getChannel | ( | ) | const |
Returns the MIDI Channel (0-15).
Definition at line 722 of file pianokeybd.cpp.
PianoPalette getForegroundPalette | ( | ) | const |
Returns the palette used to paint texts over the keys like the note names or custom labels.
Definition at line 319 of file pianokeybd.cpp.
PianoPalette getHighlightPalette | ( | ) | const |
Returns the palette used for highlighting the played keys.
Definition at line 280 of file pianokeybd.cpp.
KeyboardMap * getKeyboardMap | ( | ) |
Returns the computer keyboard note map.
Definition at line 849 of file pianokeybd.cpp.
QColor getKeyPressedColor | ( | ) | const |
Returns the key highlight color.
Definition at line 594 of file pianokeybd.cpp.
PianoHandler * getPianoHandler | ( | ) | const |
Gets the PianoHandler pointer to the note receiver.
If this method returns null, then there is not a PianoHandler class assigned, and then the signals noteOn() and noteOff() are emitted instead.
Definition at line 258 of file pianokeybd.cpp.
KeyboardMap * getRawKeyboardMap | ( | ) |
Returns the low level computer keyboard note map.
Definition at line 901 of file pianokeybd.cpp.
bool getRawKeyboardMode | ( | ) | const |
Returns the low level computer keyboard note map.
Definition at line 866 of file pianokeybd.cpp.
int getRotation | ( | ) | const |
Returns the rotation angle in degrees, clockwise, of the piano view.
Definition at line 585 of file pianokeybd.cpp.
int getTranspose | ( | ) | const |
Returns the transpose amount in semitones.
Definition at line 703 of file pianokeybd.cpp.
int getVelocity | ( | ) | const |
Returns the MIDI note velocity.
Definition at line 741 of file pianokeybd.cpp.
|
overridevirtual |
handleKeyPressed handles low level computer keyboard press events
keycode | The low level key code pressed |
Implements RawKbdHandler.
Definition at line 525 of file pianokeybd.cpp.
|
overridevirtual |
handleKeyReleased handles low level computer keyboard reelase events
keycode | The low level key code released |
Implements RawKbdHandler.
Definition at line 534 of file pianokeybd.cpp.
|
protected |
Creates and initializes a new PianoScene instance and assigns it to this widget.
base | octave base number |
num | number of displayed keys |
strt | starting note number |
c | single default highlight color |
Definition at line 410 of file pianokeybd.cpp.
References drumstick::widgets::g_DefaultKeyMap, PianoScene::noteOff(), PianoKeybd::noteOff(), PianoScene::noteOn(), PianoKeybd::noteOn(), PianoScene::signalName(), and PianoKeybd::signalName().
Referenced by PianoKeybd::PianoKeybd(), and PianoKeybd::setNumKeys().
bool isKeyboardEnabled | ( | ) | const |
Returns whether the computer keyboard is enabled.
Definition at line 760 of file pianokeybd.cpp.
bool isMouseEnabled | ( | ) | const |
Returns whether the mouse note input is enabled.
Definition at line 778 of file pianokeybd.cpp.
bool isTouchEnabled | ( | ) | const |
Returns whether the touch screen note input is enabled.
Definition at line 796 of file pianokeybd.cpp.
LabelAlteration labelAlterations | ( | ) | const |
Returns the label alterations policy.
Definition at line 643 of file pianokeybd.cpp.
|
signal |
This signal is emitted for each Note Off MIDI event created using the computer keyboard, mouse or touch screen.
It is not emitted if a PianoHandler has been assigned using setPianoHandler().
midiNote | the MIDI note number |
vel | the MIDI velocity |
Referenced by PianoKeybd::initScene().
|
signal |
This signal is emitted for each Note On MIDI event created using the computer keyboard, mouse or touch screen.
It is not emitted if a PianoHandler has been assigned using setPianoHandler().
midiNote | the MIDI note number |
vel | the MIDI velocity |
Referenced by PianoKeybd::initScene().
|
overrideprotected |
This method overrides QGraphicsView::resizeEvent() to keep the aspect ratio of the keys scene when the view is resized.
event |
Definition at line 445 of file pianokeybd.cpp.
void retranslate | ( | ) |
Updates the standard names of notes according to the currently active program language translation.
The custom note names are not affected.
Definition at line 398 of file pianokeybd.cpp.
void setBackgroundPalette | ( | const PianoPalette & | p | ) |
Assigns the palette used to paint the keys' background.
p | PianoPalette const reference |
Definition at line 309 of file pianokeybd.cpp.
void setBaseOctave | ( | const int | baseOctave | ) |
Assigns the base octave number.
baseOctave | the base octave number |
Definition at line 557 of file pianokeybd.cpp.
void setChannel | ( | const int | c | ) |
Assigns the MIDI Channel (0-15).
c | the MIDI Channel (0-15) |
Definition at line 731 of file pianokeybd.cpp.
void setFont | ( | const QFont & | font | ) |
Assigns a typographic font for drawing the note labels over the piano keys.
font | typographic font for drawing the note labels |
Definition at line 941 of file pianokeybd.cpp.
void setForegroundPalette | ( | const PianoPalette & | p | ) |
Assigns the palette used to paint texts over the keys like the note names or custom labels.
p | PianoPalette const reference |
Definition at line 329 of file pianokeybd.cpp.
void setHighlightPalette | ( | const PianoPalette & | p | ) |
Assigns the palette used for highlighting the played keys.
When the palette has a single color, the method setKeyPressedColor() may be used instead.
p | PianoPalette const reference |
Definition at line 291 of file pianokeybd.cpp.
void setKeyboardEnabled | ( | const bool | enable | ) |
Enables or disables the computer keyboard note input.
enable | the computer keyboard note input. |
Definition at line 769 of file pianokeybd.cpp.
void setKeyboardMap | ( | KeyboardMap * | m | ) |
Assigns the computer keyboard note map.
m | the computer keyboard note map. |
Definition at line 840 of file pianokeybd.cpp.
Referenced by PianoKeybd::~PianoKeybd().
void setKeyPressedColor | ( | const QColor & | c | ) |
Assigns a single color for key highlight.
This is an alternative to creating a highlight palette with a single color and assigning it.
c | color for key highlight |
Definition at line 605 of file pianokeybd.cpp.
void setLabelAlterations | ( | const LabelAlteration | use | ) |
Assigns the label alterations policy.
use | the label alterations policy |
Definition at line 653 of file pianokeybd.cpp.
void setLabelOctave | ( | const LabelCentralOctave | octave | ) |
Assigns the octave label policy.
octave | the octave label policy |
Definition at line 693 of file pianokeybd.cpp.
void setLabelOrientation | ( | const LabelOrientation | orientation | ) |
Assigns the labels orientation policy.
orientation | the labels orientation policy |
Definition at line 673 of file pianokeybd.cpp.
void setMouseEnabled | ( | const bool | enable | ) |
Enables or disables the mouse note input.
enable | the mouse note input |
Definition at line 787 of file pianokeybd.cpp.
void setNumKeys | ( | const int | numKeys, |
const int | startKey = DEFAULTSTARTINGKEY |
||
) |
This method changes the number of displayed keys and the starting key number, keeping the other settings the same.
numKeys | The new number of keys |
startKey | The number of the starting key |
Definition at line 457 of file pianokeybd.cpp.
References PianoKeybd::baseOctave, PianoKeybd::initScene(), PianoKeybd::showLabels, and PianoKeybd::startKey().
void setPianoHandler | ( | PianoHandler * | handler | ) |
Assigns a PianoHandler pointer for processing note events.
When this member is used to assign a PianoHandler instance, then the methods in that instance are called instead of emitting the signals noteOn() and noteOff().
handler | pointer to the PianoHandler instance |
Definition at line 271 of file pianokeybd.cpp.
void setRawKeyboardMap | ( | KeyboardMap * | m | ) |
Assigns the low level computer keyboard note map.
m | the low level computer keyboard note map |
Definition at line 892 of file pianokeybd.cpp.
void setRawKeyboardMode | ( | const bool | b | ) |
Enables or disables the low level computer keyboard mode.
b | the low level computer keyboard mode |
Definition at line 875 of file pianokeybd.cpp.
void setRotation | ( | int | r | ) |
Rotates the keyboard view an angle clockwise.
r | rotating angle in degrees to rotate. |
Definition at line 505 of file pianokeybd.cpp.
void setShowColorScale | ( | const bool | show | ) |
Enables or disables the color scale background palette.
show | the color scale activation state |
Definition at line 347 of file pianokeybd.cpp.
void setShowLabels | ( | const LabelVisibility | show | ) |
Assigns the label visibility policy.
show | the label visibility policy |
Definition at line 633 of file pianokeybd.cpp.
void setTouchEnabled | ( | const bool | enable | ) |
Enables or disables the touch screen note input.
enable | the touch screen note input. |
Definition at line 805 of file pianokeybd.cpp.
void setTranspose | ( | int | t | ) |
Assigns the transpose amount in semitones.
t | the transpose amount in semitones |
Definition at line 713 of file pianokeybd.cpp.
void setVelocity | ( | const int | v | ) |
Assigns the MIDI note velocity.
v | the MIDI note velocity |
Definition at line 751 of file pianokeybd.cpp.
void setVelocityTint | ( | const bool | enable | ) |
Enables or disables the note MIDI velocity influencing the highlight color tint.
enable | the note MIDI velocity influencing the highlight color tint |
Definition at line 823 of file pianokeybd.cpp.
bool showColorScale | ( | ) | const |
Returns true if the color scale background palette is assigned and active.
Definition at line 338 of file pianokeybd.cpp.
void showNoteOff | ( | const int | note, |
int | vel = -1 |
||
) |
Shows inactive one note key with the specified velocity.
note | The MIDI note number |
vel | The MIDI note velocity |
Definition at line 932 of file pianokeybd.cpp.
void showNoteOn | ( | const int | note, |
QColor | color, | ||
int | vel = -1 |
||
) |
Highlights one note key with the specified color and velocity.
note | The MIDI note number |
color | The highlight color |
vel | The MIDI note velocity |
Definition at line 912 of file pianokeybd.cpp.
void showNoteOn | ( | const int | note, |
int | vel = -1 |
||
) |
Highlights one note key with the specified velocity.
note | The MIDI note number |
vel | The MIDI note velocity |
Definition at line 922 of file pianokeybd.cpp.
|
signal |
signalName is emitted for each note created, and contains a string with the MIDI note number and the note name for each note on event.
name | the MIDI note number and name |
Referenced by PianoKeybd::initScene().
|
override |
Overrides QGraphicsView::sizeHint() providing a size value based on the piano scene.
Definition at line 519 of file pianokeybd.cpp.
QStringList standardNoteNames | ( | ) | const |
Returns the list of standard note names.
Definition at line 388 of file pianokeybd.cpp.
int startKey | ( | ) | const |
Returns the starting key note: C=0, A=9 and so on.
Definition at line 576 of file pianokeybd.cpp.
Referenced by PianoKeybd::PianoKeybd(), and PianoKeybd::setNumKeys().
void useCustomNoteNames | ( | const QStringList & | names | ) |
Assigns a list of custom text labels to be displayer over the keys.
This can be used for instance, to display the names of the percussion sounds for General MIDI channel 10. The number of elements should be 128, when naming the whole set of MIDI notes, or at least 12 when naming the note names, in which case an octave designation may be attached to the supplied name.
names | list of key labels |
Definition at line 361 of file pianokeybd.cpp.
bool velocityTint | ( | ) | const |
Returns whether the note MIDI velocity influences the highlight color tint.
Definition at line 814 of file pianokeybd.cpp.
|
readwrite |
Returns the base octave number.
Definition at line 161 of file pianokeybd.h.
Referenced by PianoKeybd::setNumKeys().
|
readwrite |
Returns the octave label policy.
Definition at line 168 of file pianokeybd.h.
|
readwrite |
Returns the labels orientation policy.
Definition at line 167 of file pianokeybd.h.
|
readwrite |
Returns the total number of keys.
Definition at line 162 of file pianokeybd.h.
|
readwrite |
Returns the label visibility policy.
Definition at line 165 of file pianokeybd.h.
Referenced by PianoKeybd::setNumKeys().