lmms
Cross-platform music production software
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:
50 PianoView(QWidget* parent);
51 ~PianoView() override = default;
52
54 static int getKeyFromKeyEvent( QKeyEvent * _ke );
55
56
57public:
64 void keyPressEvent(QKeyEvent* ke) override;
65
71 void keyReleaseEvent(QKeyEvent* ke) override;
72
73
74protected:
75
77 void modelChanged() override;
78
82 void contextMenuEvent(QContextMenuEvent* me) override;
83
88 void paintEvent(QPaintEvent*) override;
89
104 void mousePressEvent(QMouseEvent* me) override;
105
111 void mouseReleaseEvent(QMouseEvent* me) override;
112
122 void mouseMoveEvent(QMouseEvent* me) override;
123
129 void focusOutEvent(QFocusEvent*) override;
130
131 void focusInEvent( QFocusEvent * fe ) override;
132
136 void resizeEvent(QResizeEvent*) override;
137
138
139private:
142 int getKeyFromMouse(const QPoint& p) const;
143
154 int getKeyX(int key_num) const;
155
157 int getKeyWidth(int key_num) const;
158
160 int getKeyHeight(int key_num) const;
161
163 IntModel *getNearestMarker(int key, QString* title = nullptr);
164
165 QPixmap m_whiteKeyPm = embed::getIconPixmap("white_key");
166 QPixmap m_blackKeyPm = embed::getIconPixmap("black_key");
167 QPixmap m_whiteKeyPressedPm = embed::getIconPixmap("white_key_pressed");
168 QPixmap m_blackKeyPressedPm = embed::getIconPixmap("black_key_pressed");
169 QPixmap m_whiteKeyDisabledPm = embed::getIconPixmap("white_key_disabled");
170 QPixmap m_blackKeyDisabledPm = embed::getIconPixmap("black_key_disabled");
171
172 Piano* m_piano = nullptr;
173
174 QScrollBar * m_pianoScroll;
176 int m_lastKey = -1;
178
179private slots:
185 void pianoScrolled(int newPos);
186
187signals:
188 void keyPressed( int );
190};
191
192
193} // namespace gui
194
195} // namespace lmms
196
197#endif // LMMS_GUI_PIANO_VIEW_H
Definition AutomatableModel.h:486
Definition Piano.h:41
ModelView(Model *model, QWidget *widget)
Definition ModelView.cpp:33
void resizeEvent(QResizeEvent *) override
update scrollbar range after resize
Definition PianoView.cpp:599
static int getKeyFromKeyEvent(QKeyEvent *_ke)
Map a keyboard key being pressed to a note in our keyboard view.
Definition PianoView.cpp:254
~PianoView() override=default
QPixmap m_blackKeyPressedPm
Definition PianoView.h:168
QPixmap m_whiteKeyPm
Definition PianoView.h:165
void mousePressEvent(QMouseEvent *me) override
Handle a mouse click on this piano display view.
Definition PianoView.cpp:369
int getKeyFromMouse(const QPoint &p) const
Get the key from the mouse position in the piano display.
Definition PianoView.cpp:277
int getKeyHeight(int key_num) const
Return the height of a given key.
Definition PianoView.cpp:655
int getKeyX(int key_num) const
Convert a key number to an X coordinate in the piano display view.
Definition PianoView.cpp:609
void pianoScrolled(int newPos)
Handle the scrolling on the piano display view.
Definition PianoView.cpp:336
QPixmap m_blackKeyDisabledPm
Definition PianoView.h:170
IntModel * getNearestMarker(int key, QString *title=nullptr)
Return model and title of the marker closest to the given key.
Definition PianoView.cpp:661
void paintEvent(QPaintEvent *) override
Paint the piano display view in response to an event.
Definition PianoView.cpp:685
void focusOutEvent(QFocusEvent *) override
Handle the focus leaving the piano display view.
Definition PianoView.cpp:557
QPixmap m_whiteKeyPressedPm
Definition PianoView.h:167
void keyReleaseEvent(QKeyEvent *ke) override
Handle a key release event on the piano display view.
Definition PianoView.cpp:536
int m_startKey
first key when drawing
Definition PianoView.h:175
void mouseMoveEvent(QMouseEvent *me) override
Handle a mouse move event on the piano display view.
Definition PianoView.cpp:448
int m_lastKey
previously pressed key
Definition PianoView.h:176
QPixmap m_blackKeyPm
Definition PianoView.h:166
void keyPressEvent(QKeyEvent *ke) override
Handle a key press event on the piano display view.
Definition PianoView.cpp:514
PianoView(QWidget *parent)
Create a new keyboard display view.
Definition PianoView.cpp:79
IntModel * m_movedNoteModel
note marker which is being moved
Definition PianoView.h:177
QScrollBar * m_pianoScroll
Definition PianoView.h:174
void mouseReleaseEvent(QMouseEvent *me) override
Handle a mouse release event on the piano display view.
Definition PianoView.cpp:427
Piano * m_piano
Definition PianoView.h:172
int getKeyWidth(int key_num) const
Return the width of a given key.
Definition PianoView.cpp:650
void focusInEvent(QFocusEvent *fe) override
Definition PianoView.cpp:592
void contextMenuEvent(QContextMenuEvent *me) override
Handle a context menu selection on the piano display view.
Definition PianoView.cpp:347
void modelChanged() override
Register a change to this piano display view.
Definition PianoView.cpp:260
QPixmap m_whiteKeyDisabledPm
Definition PianoView.h:169
auto getIconPixmap(std::string_view name, int width, int height, const char *const *xpm) -> QPixmap
Return an image for the icon pixmap cache.
Definition embed.cpp:107
Definition AudioPortAudio.cpp:209
Definition RemotePluginBase.cpp:34