9#include "shared/defs.h"
22#define DEBUG_FORCED_KEYBOARD
25#define MIDI_SERIAL_PORT Serial1
32#include "shared/Keyboard.h"
33#include "shared/color.h"
34#include "shared/led_layout_array.h"
35#include "shared/Keyboard.h"
36#include "shared/Painter.h"
37#include "shared/settings.h"
38#include "arduino/LedRopeTCL.h"
39#include "arduino/ui_state.h"
40#include "shared/dprint.h"
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));
79 keyboard.HandleNoteOn(midi_note, velocity, color_selector.curr_val(), millis());
88void HandleNoteOff(
byte channel,
byte midi_note,
byte velocity) {
89 FASTLED_DBG(
"HandleNoteOn: midi_note = " <<
int(midi_note) <<
", velocity = " <<
int(velocity));
90 keyboard.HandleNoteOff(midi_note, velocity, millis());
97void HandleAfterTouchPoly(
byte channel,
byte note,
byte pressure) {
98 keyboard.HandleAfterTouchPoly(note, pressure);
104void HandleControlChange(
byte channel,
byte d1,
byte d2) {
105 keyboard.HandleControlChange(d1, d2);
108void HandleAfterTouchChannel(
byte channel,
byte pressure) {
111 for (
int i = 0; i < kNumKeys; ++i) {
112 Key& key = keyboard.keys_[i];
124 FASTLED_DBG(
"setup");
129 MY_MIDI.begin(MIDI_CHANNEL_OMNI);
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;
144 static bool toggle = 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;
181 FASTLED_UNUSED(prev_time);
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;
216 ui_state ui_st = ui_update(now_ms, delta_ms);
225 const unsigned long start_painting = millis();
226 FASTLED_UNUSED(start_painting);
230 Painter::VisState which_vis = Painter::VisState(ui_st.which_visualizer);
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);
245 FASTLED_DBG(
"is_debugging = " << is_debugging);
central include file for FastLED, defines the CFastLED class/object
MIDI Library for the Arduino.
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name)
Create an instance of the library attached to a serial port. You can use HardwareSerial or SoftwareSe...