Convert to PlatformIO/Arduino format
- Replace ESP-IDF structure with PlatformIO (platformio.ini) - Move source files to src/ and include/ - Move libraries to lib/ directory - Replace FreeRTOS with Arduino task/vTaskDelay - Use Arduino MIDI library instead of raw TinyUSB - Dual-core: MIDI on core 0, controller on core 1
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
struct MidiEvent {
|
||||
enum Type {
|
||||
NOTE_ON,
|
||||
NOTE_OFF,
|
||||
CONTROL_CHANGE,
|
||||
PROGRAM_CHANGE,
|
||||
PITCH_BEND,
|
||||
AFTERTOUCH_POLY,
|
||||
AFTERTOUCH_CHAN,
|
||||
SYSEX
|
||||
} type;
|
||||
|
||||
uint8_t channel; // MIDI channel (1-16)
|
||||
uint8_t data1; // Note number or CC number
|
||||
uint8_t data2; // Velocity or CC value
|
||||
uint32_t timestamp; // Event timestamp
|
||||
};
|
||||
|
||||
class UsbMidiTransport {
|
||||
public:
|
||||
UsbMidiTransport();
|
||||
~UsbMidiTransport();
|
||||
|
||||
bool begin();
|
||||
void update();
|
||||
|
||||
// Callback registration
|
||||
void on_midi_receive(std::function<void(const MidiEvent&)> callback);
|
||||
|
||||
// Send MIDI
|
||||
void send_note_on(uint8_t channel, uint8_t note, uint8_t velocity);
|
||||
void send_note_off(uint8_t channel, uint8_t note, uint8_t velocity);
|
||||
void send_cc(uint8_t channel, uint8_t cc, uint8_t value);
|
||||
|
||||
private:
|
||||
std::function<void(const MidiEvent&)> receive_callback;
|
||||
bool initialized;
|
||||
|
||||
void parse_midi_packet(const uint8_t* buffer, uint32_t size, MidiEvent& event);
|
||||
};
|
||||
Reference in New Issue
Block a user