#pragma once #include #include 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 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 receive_callback; bool initialized; void parse_midi_packet(const uint8_t* buffer, uint32_t size, MidiEvent& event); };