LMMS
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 {
47 } ;
48
49 Piano(InstrumentTrack* track);
50
51 void setKeyState(int key, bool state);
52
53 bool isKeyPressed(int key) const
54 {
55 return m_pressedKeys[key];
56 }
57
58 void handleKeyPress(int key, int midiVelocity = -1);
59 void handleKeyRelease(int key);
60
62 {
63 return m_instrumentTrack;
64 }
65
67 {
68 return m_midiEvProc;
69 }
70
71 static bool isWhiteKey(int key);
72 static bool isBlackKey(int key);
73
74 static const unsigned int WhiteKeysPerOctave = 7;
75 static const unsigned int BlackKeysPerOctave = 5;
76 static const unsigned int NumWhiteKeys = 75;
77 static const unsigned int NumBlackKeys = 53;
78
79private:
80 static bool isValidKey(int key)
81 {
82 return key >= 0 && key < NumKeys;
83 }
84
87 std::array<bool, NumKeys> m_pressedKeys = {};
88
89} ;
90
91
92} // namespace lmms
93
94#endif // LMMS_PIANO_H
#define final
Definition DistrhoDefines.h:74
Definition White.h:35
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:77
MidiEventProcessor * m_midiEvProc
Definition Piano.h:86
void handleKeyRelease(int key)
Handle a note being released on our keyboard display.
Definition Piano.cpp:115
static const unsigned int WhiteKeysPerOctave
Definition Piano.h:74
static const unsigned int NumWhiteKeys
Definition Piano.h:76
InstrumentTrack * m_instrumentTrack
Definition Piano.h:85
std::array< bool, NumKeys > m_pressedKeys
Definition Piano.h:87
Piano(InstrumentTrack *track)
Create a new keyboard display.
Definition Piano.cpp:65
static bool isBlackKey(int key)
Definition Piano.cpp:126
static bool isValidKey(int key)
Definition Piano.h:80
InstrumentTrack * instrumentTrack() const
Definition Piano.h:61
KeyType
Definition Piano.h:44
@ Black
Definition Piano.h:46
static bool isWhiteKey(int key)
Definition Piano.cpp:134
bool isKeyPressed(int key) const
Definition Piano.h:53
static const unsigned int BlackKeysPerOctave
Definition Piano.h:75
void handleKeyPress(int key, int midiVelocity=-1)
Handle a note being pressed on our keyboard display.
Definition Piano.cpp:94
void setKeyState(int key, bool state)
Turn a key on or off.
Definition Piano.cpp:77
MidiEventProcessor * midiEventProcessor() const
Definition Piano.h:66
Definition AudioAlsa.cpp:35
const int NumKeys
Number of physical keys, limited to MIDI range (valid for both MIDI 1.0 and 2.0).
Definition Note.h:90
ZCONST char * key
Definition crypt.c:587