FastLED 3.9.7
Loading...
Searching...
No Matches
Keyboard.h
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 on_; // Max number of MIDI keys.
37 bool sustained_;
38 bool sustain_pedal_on_;
39 uint8_t velocity_;
40 int idx_;
41 unsigned long event_time_;
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.
46 float intensity_;
47 ColorHSV orig_color_;
48 ColorHSV curr_color_;
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;
102 bool sustain_pedal_;
103 Key keys_[kNumKeys];
104};
105
106
107#endif // KEYBOARD_H_
108
Definition Keyboard.h:22