FastLED 3.9.15
Loading...
Searching...
No Matches
Keyboard.h
Go to the documentation of this file.
1
2#ifndef KEYBOARD_H_
3#define KEYBOARD_H_
4
5#include <Arduino.h>
6#include "color.h"
7#include "./util.h"
8
9class KeyboardState;
10
11// // NOTE: AS OF NOV-12-2013 we've disable all of the auto-sustained
12// notes in the high end of the keyboard.
13enum {
14 // kFirstNoteNoDamp = 69, // First key that has no dampener
15 kFirstNoteNoDamp = 89, // DISABLED - Greater than last key.
16};
17
18inline uint8_t KeyIndex(int midi_pitch) {
19 return constrain(midi_pitch, 21, 108) - 21;
20}
21
22struct Key {
23 Key();
24 void SetOn(uint8_t vel, const ColorHSV& color, uint32_t now_ms);
25 void SetOff(uint32_t now_ms);
26 void SetSustained();
27
28 void Update(uint32_t now_ms, uint32_t delta_ms, bool sustain_pedal_on);
29
30 float VelocityFactor() const;
31 float CalcAttackDecayFactor(uint32_t delta_ms) const;
32 float AttackRemapFactor(uint32_t now_ms);
33 float IntensityFactor() const;
34 void UpdateIntensity(uint32_t now_ms, uint32_t delta_ms);
35
36 bool mOn; // Max number of MIDI keys.
39 uint8_t mVelocity;
40 int mIdx;
41 unsigned long mEventTime;
42
43 // 0.0 -> 1.0 How intense the key is, used for light sequences to represent
44 // 0 -> 0% of lights on to 1.0 -> 100% of lights on. this is a smooth
45 // value through time.
49};
50
51// Interface into the Keyboard state.
52// Convenience class which holds all the keys in the keyboard. Also
53// has a convenience function will allows one to map the midi notes
54// (21-108) to the midi keys (0-88).
56 public:
57
58 // NOTE: AS OF NOV-12-2013 we've disable all of the auto-sustained
59 // notes in the high end of the keyboard.
60 //enum {
61 // kFirstNoteNoDamp = 69, // First key that has no dampener
62 // kFirstNoteNoDamp = 89, // DISABLED - Greater than last key.
63 //};
64
66 void Update(uint32_t now_ms, uint32_t delta_ms);
67
68
70 // Called when the note is pressed.
71 // Input:
72 // channel - Ignored.
73 // midi_note - Value between 21-108 which maps to the keyboard keys.
74 // velocity - Value between 0-127
75 void HandleNoteOn(uint8_t midi_note, uint8_t velocity, int color_selector_value, uint32_t now_ms);
76
78 // Called when the note is released.
79 // Input:
80 // channel - Ignored.
81 // midi_note - Value between 21-108 which maps to the keyboard keys.
82 // velocity - Value between 0-127
83 void HandleNoteOff(uint8_t midi_note, uint8_t velocity, uint32_t now_ms);
84
86 // This is uninmplemented because the test keyboard didn't
87 // have this functionality. Right now the only thing it does is
88 // print out that the key was pressed.
89 void HandleAfterTouchPoly(uint8_t note, uint8_t pressure);
90
91
93 // Detects whether the foot pedal has been touched.
94 void HandleControlChange(uint8_t d1, uint8_t d2);
95
96
97 static uint8_t KeyIndex(int midi_pitch);
98
99 Key* GetKey(int midi_pitch);
100
101 static const int kNumKeys = 88;
104};
105
106
107#endif // KEYBOARD_H_
108
@ kFirstNoteNoDamp
Definition Keyboard.h:15
uint8_t KeyIndex(int midi_pitch)
Definition Keyboard.h:18
void Update(uint32_t now_ms, uint32_t delta_ms)
Definition Keyboard.cpp:198
static const int kNumKeys
Definition Keyboard.h:101
void HandleControlChange(uint8_t d1, uint8_t d2)
Definition Keyboard.cpp:168
void HandleAfterTouchPoly(uint8_t note, uint8_t pressure)
Definition Keyboard.cpp:179
void HandleNoteOn(uint8_t midi_note, uint8_t velocity, int color_selector_value, uint32_t now_ms)
Definition Keyboard.cpp:115
static uint8_t KeyIndex(int midi_pitch)
Definition Keyboard.cpp:204
Key * GetKey(int midi_pitch)
Definition Keyboard.cpp:209
bool mSustainPedal
Definition Keyboard.h:102
void HandleNoteOff(uint8_t midi_note, uint8_t velocity, uint32_t now_ms)
Definition Keyboard.cpp:148
Key mKeys[kNumKeys]
Definition Keyboard.h:103
void SetOff(uint32_t now_ms)
Definition Keyboard.cpp:24
uint8_t mVelocity
Definition Keyboard.h:39
bool mOn
Definition Keyboard.h:36
void SetSustained()
Definition Keyboard.cpp:31
Key()
Definition Keyboard.cpp:10
bool mSustainPedalOn
Definition Keyboard.h:38
ColorHSV mOrigColor
Definition Keyboard.h:47
bool mSustained
Definition Keyboard.h:37
float AttackRemapFactor(uint32_t now_ms)
Definition Keyboard.cpp:58
float IntensityFactor() const
Definition Keyboard.cpp:66
unsigned long mEventTime
Definition Keyboard.h:41
float mIntensity
Definition Keyboard.h:46
int mIdx
Definition Keyboard.h:40
void SetOn(uint8_t vel, const ColorHSV &color, uint32_t now_ms)
Definition Keyboard.cpp:13
float CalcAttackDecayFactor(uint32_t delta_ms) const
Definition Keyboard.cpp:46
void Update(uint32_t now_ms, uint32_t delta_ms, bool sustain_pedal_on)
Definition Keyboard.cpp:35
float VelocityFactor() const
Definition Keyboard.cpp:44
ColorHSV mCurrColor
Definition Keyboard.h:48
void UpdateIntensity(uint32_t now_ms, uint32_t delta_ms)
Definition Keyboard.cpp:70
Definition Keyboard.h:22