Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Viewer for the keyboard. More...
#include <keyboardgraphicsview.h>
Signals | |
void | selectionChanged (int8_t key) |
Signal beeing emitted if the selected key changed. More... | |
Public Member Functions | |
KeyboardGraphicsView (QWidget *parent) | |
Constructor. More... | |
~KeyboardGraphicsView () | |
const QGraphicsScene & | getScene () const |
Getter for mScene. More... | |
void | setKeyboard (const Keyboard *kb) |
Setter for mKeyboard. More... | |
const Keyboard * | getKeyboard () const |
Getter for mKeyboard. More... | |
int8_t | getSelectedKeyIndex () const |
Getter for mSelectedKey. More... | |
const Key * | getSelectedKey () const |
KeyState | getSelectedKeyState () const |
Getter for mSelectedKeyState. More... | |
int8_t | getPreliminaryKey () const |
Getter for mPreliminaryKey. More... | |
void | setSelection (int key, KeyState state, int preliminary) |
Function to set the current selection. More... | |
void | centerOnKey (int8_t key) |
This function will center the view on the given key. More... | |
void | addAutoScaledGraphicsView (AutoScaledToKeyboardGraphicsView *view) |
Function to add a AutoScaledToKeyboardGraphicsView. More... | |
void | selectKey (int8_t key0, KeyState keyState, bool notifyMessageListeners=true) |
Function to select or deselect a key. More... | |
QRectF | getVisibleContentsRect () const |
Static Public Attributes | |
static const qreal | GLOBAL_SCALING = 1 |
A global scaling factor. More... | |
static const qreal | PEN_THIN_LINE = 1 * KeyboardGraphicsView::GLOBAL_SCALING |
Thin pen line width. More... | |
static const qreal | PEN_MEDIUM_LINE = 2 * KeyboardGraphicsView::GLOBAL_SCALING |
Medium pen line width. More... | |
static const qreal | KEY_WIDTH = 10 * KeyboardGraphicsView::GLOBAL_SCALING |
Width of a single key. More... | |
static const qreal | KEY_HEIGHT = 80 * KeyboardGraphicsView::GLOBAL_SCALING |
Height of a single key. More... | |
static const qreal | KEY_SPACING_TO_MARKERS = KeyboardGraphicsView::KEY_WIDTH + 2 * KeyboardGraphicsView::GLOBAL_SCALING |
Space between keys and markers. More... | |
static const qreal | KEY_MARKERS_MARGIN = 1 * KeyboardGraphicsView::GLOBAL_SCALING |
Margin of a single marker. More... | |
static const qreal | TOTAL_HEIGHT = KeyboardGraphicsView::KEY_HEIGHT + KeyboardGraphicsView::KEY_SPACING_TO_MARKERS |
Total height of the view. More... | |
static const qreal | KEY_BLACK_TO_WHITE_RATIO = 0.6 |
Size ratio of black and white keys. More... | |
static const qreal | KEY_WHITE_KEY_SIZE = KeyboardGraphicsView::KEY_WIDTH * 12.0 / 7.0 |
Size of a white key (a bit bigger than KEY_WIDTH) More... | |
static const QColor | KEY_PRELIMINARY_COLOR = Qt::gray |
Color of the preliminary key. More... | |
static const QColor | KEY_SELECTED_RECORDED_COLOR |
Color of the selected key if it is recorded. More... | |
static const QColor | KEY_SELECTED_UNRECORDED_COLOR |
Color of the selected key if it is not recorded. More... | |
static const qreal | KEY_FORCED_FACTOR = 0.5 |
Color scaling if the key is forced. More... | |
static const QColor | KEY_PRELIMINARY_AND_SELECTED_COLOR |
Color if the preliminary key equates the selected key. More... | |
static const int | NO_KEY = -1 |
No key selection constant. More... | |
Protected Member Functions | |
virtual QSize | sizeHint () const overridefinal |
virtual QSize | minimumSizeHint () const overridefinal |
void | showEvent (QShowEvent *event) override |
Reimplemented to keep the complete scene rect in the view. More... | |
void | resizeEvent (QResizeEvent *event) override |
Reimplemented to keep the complete scene rect in the view. More... | |
virtual void | scrollContentsBy (int dx, int dy) overridefinal |
void | mousePressEvent (QMouseEvent *event) override |
The mouse press will select the klicked key. More... | |
void | mouseMoveEvent (QMouseEvent *event) override |
void | keyPressEvent (QKeyEvent *event) override |
Handler for key presses. More... | |
void | handleMessage (MessagePtr m) override |
Message handling. More... | |
int | heightForWidth (int w) const override |
Get the height for a given view width. More... | |
Private Types | |
using | KeyState = piano::KeyState |
using | KeyColor = piano::KeyColor |
Private Slots | |
void | selectNext () |
Slot that will select the next key. More... | |
void | selectPrevious () |
Slot that will select the previous key. More... | |
void | deselectKey (bool notifyListeners=true) |
Slot to deselect a key. More... | |
Private Member Functions | |
void | resetKey (int8_t key) |
Function to reset the key and marker color to the unselected state. More... | |
void | setKeyColor (int8_t key) |
Function to set the key color of key. More... | |
void | selectPreliminaryKey (int8_t key0) |
Function to change the prelimary key stored in mPreliminaryKey. More... | |
void | redrawAllMarkers () |
Force all markers to update its state. More... | |
void | updateColorMarker (int8_t key0) |
Function to update a single color marker. More... | |
QPixmap | getPixmapForKeyRecordingState (bool recorded) |
Function to get the QPixmap for the given recording state. More... | |
QColor | getKeyColor (piano::KeyColor color, bool selected, KeyState keyState, bool recorded) |
Function to get the key color. More... | |
QRectF | keyShape (int8_t key0) |
Returns a QRectF as shape of the given key. More... | |
void | changeTotalNumberOfKeys (int keys, int keyA) |
Function to change the total number of keys and the key number of A. More... | |
void | fitAllInView () |
Fit the complete scene rect in the given view. More... | |
int | getKeyAtPosition (const QPoint &pos) |
Function to get the key index at the given position. More... | |
Private Attributes | |
int | mResizeBlocked = 0 |
const Keyboard * | mKeyboard |
Pointer to the keyboard that is displayed. More... | |
QGraphicsScene | mScene |
The QGraphicsScene in which the elements will be drawed. More... | |
std::vector < QGraphicsPixmapItem * > | mMarkerPixmapItems |
List of all marker items. More... | |
std::vector< QGraphicsRectItem * > | mKeysGraphicsItems |
List of all key items. More... | |
int8_t | mCenterOnKey |
Index of the key to center on. More... | |
int8_t | mSelectedKey |
The selected key. More... | |
KeyState | mSelectedKeyState |
The key state of the selected key. More... | |
int8_t | mPreliminaryKey |
The preliminary key. More... | |
int | mKeyNumberOfA |
The keynumber of A of the given mKeyboard. More... | |
QList < AutoScaledToKeyboardGraphicsView * > | mAutoScaledGraphicsViews |
List of other graphic views that are scaled along this keyboard view. More... | |
Viewer for the keyboard.
This class will draw the keyboard into the QGraphicsView.
The class can be set to a different KeyboardMode depending on how it should react on a mouse click. A MODE_NORMAL just selects the clicked key. A MODE_CLICK_RAISES_FULLSCREEN will open a FullScreenKeyboardDialog to display a keyboard in MODE_FULLSCREEN. If MODE_SCROLLBAR is set, the keyboard will display a scrollbar. The window will have a fixed width-height ratio defined by heightForWidth(int).
Definition at line 47 of file keyboardgraphicsview.h.
|
private |
Definition at line 75 of file keyboardgraphicsview.h.
|
private |
Definition at line 74 of file keyboardgraphicsview.h.
KeyboardGraphicsView::KeyboardGraphicsView | ( | QWidget * | parent | ) |
Constructor.
parent | : The parent widget |
mode | : The KeyboadMode |
Definition at line 65 of file keyboardgraphicsview.cpp.
KeyboardGraphicsView::~KeyboardGraphicsView | ( | ) |
Definition at line 103 of file keyboardgraphicsview.cpp.
|
inline |
Function to add a AutoScaledToKeyboardGraphicsView.
view | The view to add |
Definition at line 152 of file keyboardgraphicsview.h.
void KeyboardGraphicsView::centerOnKey | ( | int8_t | key | ) |
This function will center the view on the given key.
key | : The key to center or -1 |
Definition at line 120 of file keyboardgraphicsview.cpp.
|
private |
Function to change the total number of keys and the key number of A.
keys | : Number of keys |
keyA | : Index of A |
This function will also recreate all elements.
Definition at line 419 of file keyboardgraphicsview.cpp.
|
privateslot |
Slot to deselect a key.
Definition at line 550 of file keyboardgraphicsview.cpp.
|
private |
Fit the complete scene rect in the given view.
Definition at line 510 of file keyboardgraphicsview.cpp.
|
private |
Function to get the key index at the given position.
pos | : The position to search for a key |
This function is usually called by a mousePressEvent(QMouseEvent*) to select the clicked key.
Definition at line 517 of file keyboardgraphicsview.cpp.
|
inline |
|
private |
Function to get the key color.
color | The color of the key. |
selected | Is the key selected? |
keyState | The state of the key. |
recorded | Is the key recorded? |
Definition at line 380 of file keyboardgraphicsview.cpp.
|
private |
Function to get the QPixmap for the given recording state.
recorded | : The recording state |
Definition at line 372 of file keyboardgraphicsview.cpp.
|
inline |
Getter for mPreliminaryKey.
Definition at line 129 of file keyboardgraphicsview.h.
|
inline |
|
inline |
|
inline |
|
inline |
Getter for mSelectedKeyState.
Definition at line 122 of file keyboardgraphicsview.h.
QRectF KeyboardGraphicsView::getVisibleContentsRect | ( | ) | const |
Definition at line 555 of file keyboardgraphicsview.cpp.
|
overrideprotectedvirtual |
Message handling.
m | : The message |
Implements MessageListener.
Definition at line 203 of file keyboardgraphicsview.cpp.
|
overrideprotected |
Get the height for a given view width.
w | : The width |
Definition at line 160 of file keyboardgraphicsview.cpp.
|
overrideprotected |
Handler for key presses.
event | : The key event |
Pressing return will set the current selected key to forced mode.
Definition at line 195 of file keyboardgraphicsview.cpp.
|
private |
Returns a QRectF as shape of the given key.
key0 | : The key index |
Definition at line 400 of file keyboardgraphicsview.cpp.
|
inlinefinaloverrideprotectedvirtual |
Definition at line 170 of file keyboardgraphicsview.h.
|
overrideprotected |
|
overrideprotected |
The mouse press will select the klicked key.
event | : The mouse event |
In in MODE_CLICK_RAISES_FULLSCREEN, this will open a FullScreenKeyboardDialog
Definition at line 167 of file keyboardgraphicsview.cpp.
|
private |
Force all markers to update its state.
E.g. this function is called when a new piano was loaded.
Definition at line 353 of file keyboardgraphicsview.cpp.
|
private |
Function to reset the key and marker color to the unselected state.
key | : The key index |
Definition at line 247 of file keyboardgraphicsview.cpp.
|
overrideprotected |
Reimplemented to keep the complete scene rect in the view.
event | : The resize event |
Definition at line 131 of file keyboardgraphicsview.cpp.
|
finaloverrideprotectedvirtual |
|
signal |
Signal beeing emitted if the selected key changed.
key | The newly selected key index |
void KeyboardGraphicsView::selectKey | ( | int8_t | key0, |
piano::KeyState | keyState, | ||
bool | notifyMessageListeners = true |
||
) |
Function to select or deselect a key.
key0 | The key index to select or -1. |
keyState | The state of the key. |
notifyMessageListeners | Notiy the message listeners by sending a message |
The current selected key is stored in mSelectedKey and its state in mSelectedKeyState.
Definition at line 297 of file keyboardgraphicsview.cpp.
|
privateslot |
Slot that will select the next key.
Definition at line 540 of file keyboardgraphicsview.cpp.
|
private |
Function to change the prelimary key stored in mPreliminaryKey.
key0 | : The new preliminary key |
Definition at line 334 of file keyboardgraphicsview.cpp.
|
privateslot |
Slot that will select the previous key.
Definition at line 545 of file keyboardgraphicsview.cpp.
void KeyboardGraphicsView::setKeyboard | ( | const Keyboard * | kb | ) |
Setter for mKeyboard.
kb | : The Keyboard |
Definition at line 108 of file keyboardgraphicsview.cpp.
|
private |
Function to set the key color of key.
key The key index |
Depending on mSelectedKey, mPreliminaryKey and mSelectedKeyState this function will chose the correct color and apply it to the key.
Definition at line 261 of file keyboardgraphicsview.cpp.
void KeyboardGraphicsView::setSelection | ( | int | key, |
KeyState | state, | ||
int | preliminary | ||
) |
Function to set the current selection.
key | : The selected key or -1 |
state | : The selected KeyState |
preliminary | : The preliminary key or -1 |
Definition at line 115 of file keyboardgraphicsview.cpp.
|
overrideprotected |
Reimplemented to keep the complete scene rect in the view.
event | : The show event |
Definition at line 127 of file keyboardgraphicsview.cpp.
|
inlinefinaloverrideprotectedvirtual |
Definition at line 169 of file keyboardgraphicsview.h.
|
private |
Function to update a single color marker.
key0 | : The index of the marker |
This function will read the current state of the key in the mKeyboard and adjust the QPixmap of the marker
Definition at line 361 of file keyboardgraphicsview.cpp.
|
static |
A global scaling factor.
Definition at line 52 of file keyboardgraphicsview.h.
|
static |
Size ratio of black and white keys.
Definition at line 60 of file keyboardgraphicsview.h.
|
static |
Color scaling if the key is forced.
Definition at line 67 of file keyboardgraphicsview.h.
|
static |
Height of a single key.
Definition at line 56 of file keyboardgraphicsview.h.
|
static |
Margin of a single marker.
Definition at line 58 of file keyboardgraphicsview.h.
|
static |
Color if the preliminary key equates the selected key.
Definition at line 68 of file keyboardgraphicsview.h.
|
static |
Color of the preliminary key.
Definition at line 64 of file keyboardgraphicsview.h.
|
static |
Color of the selected key if it is recorded.
Definition at line 65 of file keyboardgraphicsview.h.
|
static |
Color of the selected key if it is not recorded.
Definition at line 66 of file keyboardgraphicsview.h.
|
static |
Space between keys and markers.
Definition at line 57 of file keyboardgraphicsview.h.
|
static |
Size of a white key (a bit bigger than KEY_WIDTH)
Definition at line 61 of file keyboardgraphicsview.h.
|
static |
Width of a single key.
Definition at line 55 of file keyboardgraphicsview.h.
|
private |
List of other graphic views that are scaled along this keyboard view.
Definition at line 376 of file keyboardgraphicsview.h.
|
private |
Index of the key to center on.
This variable is needed in the fullscreen keyboard to center on the key that was pressed in the small size keyboard view.
Definition at line 361 of file keyboardgraphicsview.h.
|
private |
Pointer to the keyboard that is displayed.
Definition at line 343 of file keyboardgraphicsview.h.
|
private |
The keynumber of A of the given mKeyboard.
Definition at line 373 of file keyboardgraphicsview.h.
|
private |
List of all key items.
Definition at line 352 of file keyboardgraphicsview.h.
|
private |
List of all marker items.
Definition at line 349 of file keyboardgraphicsview.h.
|
private |
The preliminary key.
Definition at line 370 of file keyboardgraphicsview.h.
|
private |
Definition at line 341 of file keyboardgraphicsview.h.
|
private |
The QGraphicsScene in which the elements will be drawed.
Definition at line 346 of file keyboardgraphicsview.h.
|
private |
The selected key.
Definition at line 364 of file keyboardgraphicsview.h.
|
private |
The key state of the selected key.
Definition at line 367 of file keyboardgraphicsview.h.
|
static |
No key selection constant.
Definition at line 70 of file keyboardgraphicsview.h.
|
static |
Medium pen line width.
Definition at line 54 of file keyboardgraphicsview.h.
|
static |
Thin pen line width.
Definition at line 53 of file keyboardgraphicsview.h.
|
static |
Total height of the view.
Definition at line 59 of file keyboardgraphicsview.h.