21#define DEBUG_FORCED_KEYBOARD
24#define MIDI_SERIAL_PORT Serial1
49#ifdef MIDI_AUTO_INSTANCIATE
50#undef MIDI_AUTO_INSTANCIATE
51#define MIDI_AUTO_INSTANCIATE 0
60FASTLED_TITLE(
"Luminescent Grand");
61FASTLED_DESCRIPTION(
"A midi keyboard visualizer.");
76void HandleNoteOn(
byte channel,
byte midi_note,
byte velocity) {
78 FASTLED_DBG(
"HandleNoteOn: midi_note = " <<
int(midi_note) <<
", velocity = " <<
int(velocity));
88void HandleNoteOff(
byte channel,
byte midi_note,
byte velocity) {
90 FASTLED_DBG(
"HandleNoteOn: midi_note = " <<
int(midi_note) <<
", velocity = " <<
int(velocity));
98void HandleAfterTouchPoly(
byte channel,
byte note,
byte pressure) {
106void HandleControlChange(
byte channel,
byte d1,
byte d2) {
111void HandleAfterTouchChannel(
byte channel,
byte pressure) {
116 for (
int i = 0; i <
kNumKeys; ++i) {
137 MY_MIDI.setHandleNoteOn(HandleNoteOn);
138 MY_MIDI.setHandleNoteOff(HandleNoteOff);
139 MY_MIDI.setHandleAfterTouchPoly(HandleAfterTouchPoly);
140 MY_MIDI.setHandleAfterTouchChannel(HandleAfterTouchChannel);
141 MY_MIDI.setHandleControlChange(HandleControlChange);
146void DbgDoSimulatedKeyboardPress() {
147#ifdef DEBUG_FORCED_KEYBOARD
148 static uint32_t start_time = 0;
151 const uint32_t time_on = 25;
152 const uint32_t time_off = 500;
157 uint32_t now = millis();
158 uint32_t delta_time = now - start_time;
161 uint32_t threshold_time =
toggle ? time_off : time_on;
162 if (delta_time < threshold_time) {
166 int random_key = random(0, 88);
170 HandleNoteOn(0, random_key, 64);
172 HandleNoteOff(0, random_key, 82);
185 static uint32_t s_prev_time = 0;
186 uint32_t prev_time = 0;
188 uint32_t now_ms = millis();
189 uint32_t delta_ms = now_ms - s_prev_time;
190 s_prev_time = now_ms;
193 if (Serial.available() > 0) {
194 int v = Serial.read();
201 DbgDoSimulatedKeyboardPress();
203 const unsigned long start_time = millis();
206 for (
int i = 0; i < 100; ++i) {
210 const unsigned long midi_time = millis() - start_time;
214 const uint32_t keyboard_time_start = millis();
219 keyboard.
Update(now_ms + delta_ms, delta_ms);
220 const uint32_t keyboard_delta_time = millis() - keyboard_time_start;
231 const unsigned long start_painting = millis();
237 Painter::Paint(now_ms, delta_ms, which_vis, &keyboard, &led_rope);
239 const unsigned long paint_time = millis() - start_time;
240 const unsigned long total_time = midi_time + paint_time + keyboard_delta_time;
243 float fps = 1.0f/(float(total_time) / 1000.f);
244 Serial.print(
"fps - "); Serial.println(fps);
245 Serial.print(
"midi time - "); Serial.println(midi_time);
246 Serial.print(
"keyboard update time - "); Serial.println(keyboard_delta_time);
247 Serial.print(
"draw & paint time - "); Serial.println(paint_time);
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
void setup()
This is a work in progress showcasing a complex MIDI keyboard visualizer.
MIDI Library for the Arduino.
void Update(uint32_t now_ms, uint32_t delta_ms)
void HandleControlChange(uint8_t d1, uint8_t d2)
void HandleAfterTouchPoly(uint8_t note, uint8_t pressure)
void HandleNoteOn(uint8_t midi_note, uint8_t velocity, int color_selector_value, uint32_t now_ms)
void HandleNoteOff(uint8_t midi_note, uint8_t velocity, uint32_t now_ms)
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
#define MIDI_CHANNEL_OMNI
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name)
Create an instance of the library attached to a serial port. You can use HardwareSerial or SoftwareSe...
void SetOff(uint32_t now_ms)
static void Paint(uint32_t now_ms, uint32_t delta_ms, VisState vis_state, KeyboardState *keyboard, LedRopeInterface *light_rope)
ui_state ui_update(uint32_t now_ms, uint32_t delta_ms)
ColorSelector color_selector
#define FASTLED_UNUSED(x)