22#define DEBUG_FORCED_KEYBOARD
25#define MIDI_SERIAL_PORT Serial1
50#ifdef MIDI_AUTO_INSTANCIATE
51#undef MIDI_AUTO_INSTANCIATE
52#define MIDI_AUTO_INSTANCIATE 0
61FASTLED_TITLE(
"Luminescent Grand");
62FASTLED_DESCRIPTION(
"A midi keyboard visualizer.");
77void 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) {
89 FASTLED_DBG(
"HandleNoteOn: midi_note = " <<
int(midi_note) <<
", velocity = " <<
int(velocity));
97void HandleAfterTouchPoly(
byte channel,
byte note,
byte pressure) {
104void HandleControlChange(
byte channel,
byte d1,
byte d2) {
108void HandleAfterTouchChannel(
byte channel,
byte pressure) {
111 for (
int i = 0; i <
kNumKeys; ++i) {
132 MY_MIDI.setHandleNoteOn(HandleNoteOn);
133 MY_MIDI.setHandleNoteOff(HandleNoteOff);
134 MY_MIDI.setHandleAfterTouchPoly(HandleAfterTouchPoly);
135 MY_MIDI.setHandleAfterTouchChannel(HandleAfterTouchChannel);
136 MY_MIDI.setHandleControlChange(HandleControlChange);
141void DbgDoSimulatedKeyboardPress() {
142#ifdef DEBUG_FORCED_KEYBOARD
143 static uint32_t start_time = 0;
146 const uint32_t time_on = 25;
147 const uint32_t time_off = 500;
152 uint32_t now = millis();
153 uint32_t delta_time = now - start_time;
156 uint32_t threshold_time =
toggle ? time_off : time_on;
157 if (delta_time < threshold_time) {
161 int random_key = random(0, 88);
165 HandleNoteOn(0, random_key, 64);
167 HandleNoteOff(0, random_key, 82);
179 static uint32_t s_prev_time = 0;
180 uint32_t prev_time = 0;
182 uint32_t now_ms = millis();
183 uint32_t delta_ms = now_ms - s_prev_time;
184 s_prev_time = now_ms;
187 if (Serial.available() > 0) {
188 int v = Serial.read();
195 DbgDoSimulatedKeyboardPress();
197 const unsigned long start_time = millis();
200 for (
int i = 0; i < 100; ++i) {
204 const unsigned long midi_time = millis() - start_time;
208 const uint32_t keyboard_time_start = millis();
213 keyboard.
Update(now_ms + delta_ms, delta_ms);
214 const uint32_t keyboard_delta_time = millis() - keyboard_time_start;
225 const unsigned long start_painting = millis();
231 Painter::Paint(now_ms, delta_ms, which_vis, &keyboard, &led_rope);
233 const unsigned long paint_time = millis() - start_time;
234 const unsigned long total_time = midi_time + paint_time + keyboard_delta_time;
237 float fps = 1.0f/(float(total_time) / 1000.f);
238 Serial.print(
"fps - "); Serial.println(fps);
239 Serial.print(
"midi time - "); Serial.println(midi_time);
240 Serial.print(
"keyboard update time - "); Serial.println(keyboard_delta_time);
241 Serial.print(
"draw & paint time - "); Serial.println(paint_time);
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)