LMMS
Loading...
Searching...
No Matches
lmms::gui::PianoView Class Reference

#include <PianoView.h>

Inheritance diagram for lmms::gui::PianoView:
lmms::gui::ModelView

Signals

void keyPressed (int)
void baseNoteChanged ()

Public Member Functions

 PianoView (QWidget *_parent)
 Create a new keyboard display view.
 ~PianoView () override=default
void keyPressEvent (QKeyEvent *ke) override
 Handle a key press event on the piano display view.
void keyReleaseEvent (QKeyEvent *ke) override
 Handle a key release event on the piano display view.
Public Member Functions inherited from lmms::gui::ModelView
 ModelView (Model *model, QWidget *widget)
virtual ~ModelView ()
virtual void setModel (Model *model, bool isOldModelValid=true)
virtual void unsetModel ()
Modelmodel ()
const Modelmodel () const
template<class T>
T * castModel ()
template<class T>
const T * castModel () const

Static Public Member Functions

static int getKeyFromKeyEvent (QKeyEvent *_ke)
 Map a keyboard key being pressed to a note in our keyboard view.

Protected Member Functions

void modelChanged () override
 Register a change to this piano display view.
void contextMenuEvent (QContextMenuEvent *_me) override
 Handle a context menu selection on the piano display view.
void paintEvent (QPaintEvent *) override
 Paint the piano display view in response to an event.
void mousePressEvent (QMouseEvent *me) override
 Handle a mouse click on this piano display view.
void mouseReleaseEvent (QMouseEvent *me) override
 Handle a mouse release event on the piano display view.
void mouseMoveEvent (QMouseEvent *me) override
 Handle a mouse move event on the piano display view.
void focusOutEvent (QFocusEvent *_fe) override
 Handle the focus leaving the piano display view.
void focusInEvent (QFocusEvent *fe) override
void resizeEvent (QResizeEvent *_event) override
 update scrollbar range after resize
Protected Member Functions inherited from lmms::gui::ModelView
QWidget * widget ()
virtual void doConnections ()

Private Slots

void pianoScrolled (int _new_pos)
 Handle the scrolling on the piano display view.

Private Member Functions

int getKeyFromMouse (const QPoint &_p) const
 Get the key from the mouse position in the piano display.
int getKeyX (int _key_num) const
 Convert a key number to an X coordinate in the piano display view.
int getKeyWidth (int key_num) const
 Return the width of a given key.
int getKeyHeight (int key_num) const
 Return the height of a given key.
IntModelgetNearestMarker (int key, QString *title=nullptr)
 Return model and title of the marker closest to the given key.

Private Attributes

QPixmap m_whiteKeyPm = embed::getIconPixmap("white_key")
QPixmap m_blackKeyPm = embed::getIconPixmap("black_key")
QPixmap m_whiteKeyPressedPm = embed::getIconPixmap("white_key_pressed")
QPixmap m_blackKeyPressedPm = embed::getIconPixmap("black_key_pressed")
QPixmap m_whiteKeyDisabledPm = embed::getIconPixmap("white_key_disabled")
QPixmap m_blackKeyDisabledPm = embed::getIconPixmap("black_key_disabled")
Pianom_piano
QScrollBar * m_pianoScroll
int m_startKey
 first key when drawing
int m_lastKey
 previously pressed key
IntModelm_movedNoteModel
 note marker which is being moved

Constructor & Destructor Documentation

◆ PianoView()

lmms::gui::PianoView::PianoView ( QWidget * parent)

Create a new keyboard display view.

Parameters
_parentthe parent instrument plugin window
Todo
are the descriptions of the m_startkey and m_lastkey properties correct?

< Our parent

< Our view Model

< Our piano Model

< The first key displayed?

< The last key displayed?

< Key marker which is being moved

◆ ~PianoView()

lmms::gui::PianoView::~PianoView ( )
overridedefault

Member Function Documentation

◆ baseNoteChanged

void lmms::gui::PianoView::baseNoteChanged ( )
signal

◆ contextMenuEvent()

void lmms::gui::PianoView::contextMenuEvent ( QContextMenuEvent * me)
overrideprotected

Handle a context menu selection on the piano display view.

Parameters
methe ContextMenuEvent to handle.
Todo
Is this right, or does this create the context menu?

◆ focusInEvent()

void lmms::gui::PianoView::focusInEvent ( QFocusEvent * fe)
overrideprotected

◆ focusOutEvent()

void lmms::gui::PianoView::focusOutEvent ( QFocusEvent * _fe)
overrideprotected

Handle the focus leaving the piano display view.

Turn off all notes if we lose focus.

Todo
Is there supposed to be a parameter given here?

◆ getKeyFromKeyEvent()

int lmms::gui::PianoView::getKeyFromKeyEvent ( QKeyEvent * _ke)
static

Map a keyboard key being pressed to a note in our keyboard view.

◆ getKeyFromMouse()

int lmms::gui::PianoView::getKeyFromMouse ( const QPoint & p) const
private

Get the key from the mouse position in the piano display.

Parameters
pThe point that the mouse was pressed.

◆ getKeyHeight()

int lmms::gui::PianoView::getKeyHeight ( int key_num) const
private

Return the height of a given key.

◆ getKeyWidth()

int lmms::gui::PianoView::getKeyWidth ( int key_num) const
private

Return the width of a given key.

◆ getKeyX()

int lmms::gui::PianoView::getKeyX ( int _key_num) const
private

Convert a key number to an X coordinate in the piano display view.

We can immediately discard the trivial case of when the key number is less than our starting key. We then iterate through the keys from the start key to this key, adding the width of each key as we go. For black keys, and the first white key if there is no black key between two white keys, we add half a white key width; for that second white key, we add a whole width. That takes us to the boundary of a white key - subtract half a width to get to the middle.

Parameters
_key_numthe keyboard key to translate
Todo

is this description of what the method does correct?

replace the final subtract with initialising x to width/2.

◆ getNearestMarker()

IntModel * lmms::gui::PianoView::getNearestMarker ( int key,
QString * title = nullptr )
private

Return model and title of the marker closest to the given key.

◆ keyPressed

void lmms::gui::PianoView::keyPressed ( int )
signal

◆ keyPressEvent()

void lmms::gui::PianoView::keyPressEvent ( QKeyEvent * _ke)
override

Handle a key press event on the piano display view.

We determine our key number from the getKeyFromKeyEvent() method, and pass the event on to the piano's handleKeyPress() method if auto-repeat is off.

Parameters
_kethe KeyEvent to handle.

◆ keyReleaseEvent()

void lmms::gui::PianoView::keyReleaseEvent ( QKeyEvent * _ke)
override

Handle a key release event on the piano display view.

The same logic as the keyPressEvent() method.

Parameters
_kethe KeyEvent to handle.

◆ modelChanged()

void lmms::gui::PianoView::modelChanged ( )
overrideprotectedvirtual

Register a change to this piano display view.

Reimplemented from lmms::gui::ModelView.

◆ mouseMoveEvent()

void lmms::gui::PianoView::mouseMoveEvent ( QMouseEvent * _me)
overrideprotected

Handle a mouse move event on the piano display view.

This handles the user dragging the mouse across the keys. It uses code from mousePressEvent() and mouseReleaseEvent(), also correcting for if the mouse movement has stayed within one key and if the mouse has moved outside the vertical area of the keyboard (which is still allowed but won't make the volume go up to 11).

Parameters
_methe ContextMenuEvent to handle.
Todo
Paul Wayper thinks that this code should be refactored to reduce or remove the duplication between this, the mousePressEvent() and mouseReleaseEvent() methods.

◆ mousePressEvent()

void lmms::gui::PianoView::mousePressEvent ( QMouseEvent * me)
overrideprotected

Handle a mouse click on this piano display view.

We first determine the key number using the getKeyFromMouse() method.

If we're below the 'root key selection' area, we set the volume of the note to be proportional to the vertical position on the keyboard - lower down the key is louder, within the boundaries of the (white or black) key pressed. We then tell the instrument to play that note, scaling for MIDI max loudness = 127.

If we're in the 'root key selection' area, of course, we set the root key to be that key.

We finally update ourselves to show the key press

Parameters
methe mouse click to handle.

◆ mouseReleaseEvent()

void lmms::gui::PianoView::mouseReleaseEvent ( QMouseEvent * me)
overrideprotected

Handle a mouse release event on the piano display view.

If a key was pressed by the in the mousePressEvent() function, we turn the note off.

Parameters
_methe mousePressEvent to handle.

◆ paintEvent()

void lmms::gui::PianoView::paintEvent ( QPaintEvent * )
overrideprotected

Paint the piano display view in response to an event.

This method draws the piano and the 'root note' base. It draws the base first, then all the white keys, then all the black keys.

Todo
Is there supposed to be a parameter given here?

◆ pianoScrolled

void lmms::gui::PianoView::pianoScrolled ( int newPos)
privateslot

Handle the scrolling on the piano display view.

We need to update our start key position based on the new position.

Parameters
newPosthe new key position, counting only white keys.

◆ resizeEvent()

void lmms::gui::PianoView::resizeEvent ( QResizeEvent * event)
overrideprotected

update scrollbar range after resize

After resizing we need to adjust range of scrollbar for not allowing to scroll too far to the right.

Parameters
Eventresize-event object (unused)

Member Data Documentation

◆ m_blackKeyDisabledPm

QPixmap lmms::gui::PianoView::m_blackKeyDisabledPm = embed::getIconPixmap("black_key_disabled")
private

◆ m_blackKeyPm

QPixmap lmms::gui::PianoView::m_blackKeyPm = embed::getIconPixmap("black_key")
private

◆ m_blackKeyPressedPm

QPixmap lmms::gui::PianoView::m_blackKeyPressedPm = embed::getIconPixmap("black_key_pressed")
private

◆ m_lastKey

int lmms::gui::PianoView::m_lastKey
private

previously pressed key

◆ m_movedNoteModel

IntModel* lmms::gui::PianoView::m_movedNoteModel
private

note marker which is being moved

◆ m_piano

Piano* lmms::gui::PianoView::m_piano
private

◆ m_pianoScroll

QScrollBar* lmms::gui::PianoView::m_pianoScroll
private

◆ m_startKey

int lmms::gui::PianoView::m_startKey
private

first key when drawing

◆ m_whiteKeyDisabledPm

QPixmap lmms::gui::PianoView::m_whiteKeyDisabledPm = embed::getIconPixmap("white_key_disabled")
private

◆ m_whiteKeyPm

QPixmap lmms::gui::PianoView::m_whiteKeyPm = embed::getIconPixmap("white_key")
private

◆ m_whiteKeyPressedPm

QPixmap lmms::gui::PianoView::m_whiteKeyPressedPm = embed::getIconPixmap("white_key_pressed")
private

The documentation for this class was generated from the following files: