lmms
Cross-platform music production software
Loading...
Searching...
No Matches
Piano.h
Go to the documentation of this file.
1/*
2 * Piano.h - declaration of class Piano
3 *
4 * Copyright (c) 2004-2014 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_PIANO_H
26#define LMMS_PIANO_H
27
28#include <array>
29
30#include "Model.h"
31#include "Note.h"
32
33namespace lmms
34{
35
36
37class InstrumentTrack;
39
40class Piano final : public Model
41{
42public:
43 enum class KeyType
44 {
45 White,
46 Black
47 } ;
48
52 Piano(InstrumentTrack* track);
53
58 void setKeyState(int key, bool state);
59
60 bool isKeyPressed(int key) const
61 {
62 return m_pressedKeys[key];
63 }
64
69 void handleKeyPress(int key, int midiVelocity = -1);
70
74 void handleKeyRelease(int key);
75
77 {
78 return m_instrumentTrack;
79 }
80
82 {
83 return m_midiEvProc;
84 }
85
86 static bool isWhiteKey(int key);
87 static bool isBlackKey(int key);
88
89 static const unsigned int WhiteKeysPerOctave = 7;
90 static const unsigned int BlackKeysPerOctave = 5;
91 static const unsigned int NumWhiteKeys = 75;
92 static const unsigned int NumBlackKeys = 53;
93
94private:
95 static bool isValidKey(int key)
96 {
97 return key >= 0 && key < NumKeys;
98 }
99
102 std::array<bool, NumKeys> m_pressedKeys = {};
103
104} ;
105
106
107} // namespace lmms
108
109#endif // LMMS_PIANO_H
Definition InstrumentTrack.h:62
Definition MidiEventProcessor.h:36
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
static const unsigned int NumBlackKeys
Definition Piano.h:92
MidiEventProcessor * m_midiEvProc
Definition Piano.h:101
void handleKeyRelease(int key)
Handle a note being released on our keyboard display.
Definition Piano.cpp:92
static const unsigned int WhiteKeysPerOctave
Definition Piano.h:89
static const unsigned int NumWhiteKeys
Definition Piano.h:91
InstrumentTrack * m_instrumentTrack
Definition Piano.h:100
std::array< bool, NumKeys > m_pressedKeys
Definition Piano.h:102
Piano(InstrumentTrack *track)
Create a new keyboard display.
Definition Piano.cpp:60
static bool isBlackKey(int key)
Definition Piano.cpp:103
static bool isValidKey(int key)
Definition Piano.h:95
InstrumentTrack * instrumentTrack() const
Definition Piano.h:76
KeyType
Definition Piano.h:44
static bool isWhiteKey(int key)
Definition Piano.cpp:111
bool isKeyPressed(int key) const
Definition Piano.h:60
static const unsigned int BlackKeysPerOctave
Definition Piano.h:90
void handleKeyPress(int key, int midiVelocity=-1)
Handle a note being pressed on our keyboard display.
Definition Piano.cpp:78
void setKeyState(int key, bool state)
Turn a key on or off.
Definition Piano.cpp:67
MidiEventProcessor * midiEventProcessor() const
Definition Piano.h:81
Definition RemotePluginBase.cpp:34
const int NumKeys
Number of physical keys, limited to MIDI range (valid for both MIDI 1.0 and 2.0).
Definition Note.h:90