LMMS
Loading...
Searching...
No Matches
PianoView.h
Go to the documentation of this file.
1/*
2 * PianoView.h - declaration of PianoView, an interactive piano/keyboard-widget
3 *
4 * Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_GUI_PIANO_VIEW_H
26#define LMMS_GUI_PIANO_VIEW_H
27
28#include <QPixmap>
29#include <QScrollBar>
30
31#include "AutomatableModel.h"
32#include "ModelView.h"
33#include "embed.h"
34
35namespace lmms
36{
37
38class Piano;
39
40namespace gui
41{
42
43class PianoView : public QWidget, public ModelView
44{
45 Q_OBJECT
46public:
47 PianoView( QWidget * _parent );
48 ~PianoView() override = default;
49
50 static int getKeyFromKeyEvent( QKeyEvent * _ke );
51
52
53public:
54 void keyPressEvent( QKeyEvent * ke ) override;
55 void keyReleaseEvent( QKeyEvent * ke ) override;
56
57
58protected:
59 void modelChanged() override;
60 void contextMenuEvent( QContextMenuEvent * _me ) override;
61 void paintEvent( QPaintEvent * ) override;
62 void mousePressEvent( QMouseEvent * me ) override;
63 void mouseReleaseEvent( QMouseEvent * me ) override;
64 void mouseMoveEvent( QMouseEvent * me ) override;
65 void focusOutEvent( QFocusEvent * _fe ) override;
66 void focusInEvent( QFocusEvent * fe ) override;
67 void resizeEvent( QResizeEvent * _event ) override;
68
69
70private:
71 int getKeyFromMouse( const QPoint & _p ) const;
72 int getKeyX( int _key_num ) const;
73 int getKeyWidth(int key_num) const;
74 int getKeyHeight(int key_num) const;
75 IntModel *getNearestMarker(int key, QString* title = nullptr);
76
77 QPixmap m_whiteKeyPm = embed::getIconPixmap("white_key");
78 QPixmap m_blackKeyPm = embed::getIconPixmap("black_key");
79 QPixmap m_whiteKeyPressedPm = embed::getIconPixmap("white_key_pressed");
80 QPixmap m_blackKeyPressedPm = embed::getIconPixmap("black_key_pressed");
81 QPixmap m_whiteKeyDisabledPm = embed::getIconPixmap("white_key_disabled");
82 QPixmap m_blackKeyDisabledPm = embed::getIconPixmap("black_key_disabled");
83
85
86 QScrollBar * m_pianoScroll;
90
91
92
93private slots:
94 void pianoScrolled( int _new_pos );
95
96signals:
97 void keyPressed( int );
99
100} ;
101
102
103} // namespace gui
104
105} // namespace lmms
106
107#endif // LMMS_GUI_PIANO_VIEW_H
Definition AutomatableModel.h:481
Definition Piano.h:41
ModelView(Model *model, QWidget *widget)
Definition ModelView.cpp:33
static int getKeyFromKeyEvent(QKeyEvent *_ke)
Map a keyboard key being pressed to a note in our keyboard view.
Definition PianoView.cpp:264
int getKeyFromMouse(const QPoint &_p) const
Get the key from the mouse position in the piano display.
Definition PianoView.cpp:295
~PianoView() override=default
QPixmap m_blackKeyPressedPm
Definition PianoView.h:80
QPixmap m_whiteKeyPm
Definition PianoView.h:77
void mousePressEvent(QMouseEvent *me) override
Handle a mouse click on this piano display view.
Definition PianoView.cpp:417
int getKeyHeight(int key_num) const
Return the height of a given key.
Definition PianoView.cpp:769
int getKeyX(int _key_num) const
Convert a key number to an X coordinate in the piano display view.
Definition PianoView.cpp:720
PianoView(QWidget *_parent)
Create a new keyboard display view.
Definition PianoView.cpp:85
void contextMenuEvent(QContextMenuEvent *_me) override
Handle a context menu selection on the piano display view.
Definition PianoView.cpp:377
QPixmap m_blackKeyDisabledPm
Definition PianoView.h:82
IntModel * getNearestMarker(int key, QString *title=nullptr)
Return model and title of the marker closest to the given key.
Definition PianoView.cpp:777
void paintEvent(QPaintEvent *) override
Paint the piano display view in response to an event.
Definition PianoView.cpp:808
QPixmap m_whiteKeyPressedPm
Definition PianoView.h:79
void keyReleaseEvent(QKeyEvent *ke) override
Handle a key release event on the piano display view.
Definition PianoView.cpp:620
int m_startKey
first key when drawing
Definition PianoView.h:87
void mouseMoveEvent(QMouseEvent *me) override
Handle a mouse move event on the piano display view.
Definition PianoView.cpp:518
int m_lastKey
previously pressed key
Definition PianoView.h:88
QPixmap m_blackKeyPm
Definition PianoView.h:78
void pianoScrolled(int _new_pos)
Handle the scrolling on the piano display view.
Definition PianoView.cpp:361
void keyPressEvent(QKeyEvent *ke) override
Handle a key press event on the piano display view.
Definition PianoView.cpp:592
IntModel * m_movedNoteModel
note marker which is being moved
Definition PianoView.h:89
QScrollBar * m_pianoScroll
Definition PianoView.h:86
void resizeEvent(QResizeEvent *_event) override
update scrollbar range after resize
Definition PianoView.cpp:696
void mouseReleaseEvent(QMouseEvent *me) override
Handle a mouse release event on the piano display view.
Definition PianoView.cpp:483
Piano * m_piano
Definition PianoView.h:84
int getKeyWidth(int key_num) const
Return the width of a given key.
Definition PianoView.cpp:762
void focusInEvent(QFocusEvent *fe) override
Definition PianoView.cpp:682
void modelChanged() override
Register a change to this piano display view.
Definition PianoView.cpp:273
void focusOutEvent(QFocusEvent *_fe) override
Handle the focus leaving the piano display view.
Definition PianoView.cpp:647
QPixmap m_whiteKeyDisabledPm
Definition PianoView.h:81
static const char * title
Definition pugl.h:1747
auto getIconPixmap(std::string_view name, int width, int height, const char *const *xpm) -> QPixmap
Definition embed.cpp:107
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35
ZCONST char * key
Definition crypt.c:587