From 3927d073e938973be113ee08db4e596c7d853ad3 Mon Sep 17 00:00:00 2001 From: pszsh Date: Sat, 7 Mar 2026 10:42:15 -0800 Subject: [PATCH] a god damn doozy --- docs/_index.md | 26 +++++++++++++ docs/classes.md | 7 ++-- docs/examples/03-interfaces/03-usb-midi.md | 26 +++++++++++++ docs/examples/03-interfaces/04-serial-midi.md | 25 ++++++++++++ docs/examples/03-interfaces/05-dual-midi.md | 34 ++++++++++++++++ docs/examples/03-interfaces/06-applemidi.md | 33 ++++++++++++++++ .../03-interfaces/07-applemidi-ble.md | 39 +++++++++++++++++++ docs/roadmap.md | 7 ++-- 8 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 docs/examples/03-interfaces/03-usb-midi.md create mode 100644 docs/examples/03-interfaces/04-serial-midi.md create mode 100644 docs/examples/03-interfaces/05-dual-midi.md create mode 100644 docs/examples/03-interfaces/06-applemidi.md create mode 100644 docs/examples/03-interfaces/07-applemidi-ble.md diff --git a/docs/_index.md b/docs/_index.md index 3582d92..c38da72 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -26,6 +26,32 @@ int main() { } ``` +## Build + +cs-midi is a static library meant to be included in a pico-sdk project: + +```cmake +add_subdirectory(lib/cs-midi) +target_link_libraries(your_target cs_midi) +``` + +CMake options (set before `add_subdirectory()`): + +| Option | Default | Description | +|--------|---------|-------------| +| `CS_MIDI_BLE` | ON | BLE MIDI via BTstack | +| `CS_MIDI_USB` | OFF | USB MIDI via TinyUSB | +| `CS_MIDI_SERIAL` | OFF | Serial MIDI over UART | +| `CS_MIDI_APPLEMIDI` | OFF | AppleMIDI (RTP-MIDI over WiFi) | + +USB MIDI requires `tusb_config.h` and `usb_descriptors.c` in your project — see `templates/` for reference files. + +To compile-verify all examples standalone: + +```sh +cd lib/cs-midi && make tests +``` + ## Differences from Control Surface - `#include ` replaces `#include ` diff --git a/docs/classes.md b/docs/classes.md index d6e6f60..3d5ee4b 100644 --- a/docs/classes.md +++ b/docs/classes.md @@ -85,7 +85,10 @@ These classes are available in cs-midi and work identically to their Control Sur | Class | Template | Description | |-------|----------|-------------| -| `BluetoothMIDI_Interface` | | BLE MIDI interface | +| `BluetoothMIDI_Interface` | | BLE MIDI via BTstack | +| `USBMIDI_Interface` | | USB MIDI device via TinyUSB | +| `HardwareSerialMIDI_Interface` | | 5-pin DIN MIDI over UART | +| `AppleMIDI_Interface` | | RTP-MIDI over WiFi (AppleMIDI/Bonjour) | ### MIDI Routing @@ -201,7 +204,6 @@ Full Mackie Control protocol support — VU meters, V-Pots, LCD, time display, e | Class | Description | |-------|-------------| -| `USBMIDI_Interface` | USB MIDI device interface | | `USBHostMIDI_Interface` | USB Host MIDI interface | | `GenericUSBMIDI_Interface` | Configurable USB MIDI backend | | `USBDebugMIDI_Interface` | Serial monitor debug output | @@ -210,7 +212,6 @@ Full Mackie Control protocol support — VU meters, V-Pots, LCD, time display, e | Class | Description | |-------|-------------| -| `HardwareSerialMIDI_Interface` | 5-pin DIN MIDI over UART | | `SoftwareSerialMIDI_Interface` | Software serial MIDI | | `HairlessMIDI_Interface` | Hairless MIDI serial bridge | diff --git a/docs/examples/03-interfaces/03-usb-midi.md b/docs/examples/03-interfaces/03-usb-midi.md new file mode 100644 index 0000000..7dd6d3c --- /dev/null +++ b/docs/examples/03-interfaces/03-usb-midi.md @@ -0,0 +1,26 @@ +# USB MIDI + +USB MIDI device interface via TinyUSB. + +Requires `tusb_config.h` and `usb_descriptors.c` in the project — see `lib/cs-midi/templates/` for reference files. Link `tinyusb_device` and `tinyusb_board` in CMake. + +```cpp +#include "pico/stdlib.h" +#include "tusb.h" +#include + +using namespace cs; + +USBMIDI_Interface midi; + +NoteButton button {5, {MIDI_Notes::C[4], Channel_1}}; + +int main() { + stdio_init_all(); + tusb_init(); + Control_Surface.begin(); + while (true) { + Control_Surface.loop(); + } +} +``` diff --git a/docs/examples/03-interfaces/04-serial-midi.md b/docs/examples/03-interfaces/04-serial-midi.md new file mode 100644 index 0000000..aa28be0 --- /dev/null +++ b/docs/examples/03-interfaces/04-serial-midi.md @@ -0,0 +1,25 @@ +# Serial MIDI + +Classic 5-pin DIN MIDI over hardware UART at 31250 baud. + +Constructor: `HardwareSerialMIDI_Interface(uart_inst_t *uart, uint tx_pin, uint rx_pin)` + +```cpp +#include "pico/stdlib.h" +#include + +using namespace cs; + +HardwareSerialMIDI_Interface midi {uart0, 12, 13}; + +CCRotaryEncoder enc {{0, 2}, {16, Channel_1}, 1, 4}; + +int main() { + stdio_init_all(); + Control_Surface.begin(); + while (true) { + Control_Surface.loop(); + sleep_ms(1); + } +} +``` diff --git a/docs/examples/03-interfaces/05-dual-midi.md b/docs/examples/03-interfaces/05-dual-midi.md new file mode 100644 index 0000000..d44b81f --- /dev/null +++ b/docs/examples/03-interfaces/05-dual-midi.md @@ -0,0 +1,34 @@ +# Dual MIDI (BLE + USB) + +Multiple MIDI interfaces with pipe routing. Elements send to both transports simultaneously. + +```cpp +#include "pico/stdlib.h" +#include "pico/cyw43_arch.h" +#include "tusb.h" +#include + +using namespace cs; + +BluetoothMIDI_Interface ble; +USBMIDI_Interface usb; + +MIDI_PipeFactory<2> pipes; + +NoteButton button {5, {MIDI_Notes::C[4], Channel_1}}; +CCRotaryEncoder enc {{0, 2}, {16, Channel_1}, 1, 4}; + +int main() { + stdio_init_all(); + if (cyw43_arch_init()) return 1; + tusb_init(); + + Control_Surface >> pipes >> ble; + Control_Surface >> pipes >> usb; + + Control_Surface.begin(); + while (true) { + Control_Surface.loop(); + } +} +``` diff --git a/docs/examples/03-interfaces/06-applemidi.md b/docs/examples/03-interfaces/06-applemidi.md new file mode 100644 index 0000000..545027c --- /dev/null +++ b/docs/examples/03-interfaces/06-applemidi.md @@ -0,0 +1,33 @@ +# AppleMIDI (RTP-MIDI over WiFi) + +RTP-MIDI over WiFi — appears as a Bonjour MIDI device in macOS Audio MIDI Setup, +Windows rtpMIDI, and iOS. Requires WiFi connection before `Control_Surface.begin()`. + +Build with `CS_MIDI_APPLEMIDI=ON`. + +```cpp +#include "pico/stdlib.h" +#include "pico/cyw43_arch.h" +#include + +using namespace cs; + +AppleMIDI_Interface midi {"PicoW-MIDI", 5004}; + +NoteButton button {5, {MIDI_Notes::C[4], Channel_1}}; +CCRotaryEncoder enc {{0, 2}, {16, Channel_1}, 1, 4}; + +int main() { + stdio_init_all(); + if (cyw43_arch_init()) return 1; + + cyw43_arch_enable_sta_mode(); + cyw43_arch_wifi_connect_blocking("SSID", "PASS", CYW43_AUTH_WPA2_AES_PSK); + + Control_Surface.begin(); + while (true) { + Control_Surface.loop(); + sleep_ms(1); + } +} +``` diff --git a/docs/examples/03-interfaces/07-applemidi-ble.md b/docs/examples/03-interfaces/07-applemidi-ble.md new file mode 100644 index 0000000..defc469 --- /dev/null +++ b/docs/examples/03-interfaces/07-applemidi-ble.md @@ -0,0 +1,39 @@ +# Dual Transport (BLE + AppleMIDI) + +BLE for direct iOS/macOS connection, AppleMIDI for DAW integration over WiFi. +Elements send to both transports simultaneously via pipe routing. + +Build with `CS_MIDI_BLE=ON CS_MIDI_APPLEMIDI=ON`. + +```cpp +#include "pico/stdlib.h" +#include "pico/cyw43_arch.h" +#include + +using namespace cs; + +BluetoothMIDI_Interface ble; +AppleMIDI_Interface applemidi {"PicoW-MIDI", 5004}; + +MIDI_PipeFactory<2> pipes; + +NoteButton button {5, {MIDI_Notes::C[4], Channel_1}}; +CCRotaryEncoder enc {{0, 2}, {16, Channel_1}, 1, 4}; + +int main() { + stdio_init_all(); + if (cyw43_arch_init()) return 1; + + cyw43_arch_enable_sta_mode(); + cyw43_arch_wifi_connect_blocking("SSID", "PASS", CYW43_AUTH_WPA2_AES_PSK); + + Control_Surface >> pipes >> ble; + Control_Surface >> pipes >> applemidi; + + Control_Surface.begin(); + while (true) { + Control_Surface.loop(); + sleep_ms(1); + } +} +``` diff --git a/docs/roadmap.md b/docs/roadmap.md index 48dd47a..a20c7a5 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -44,6 +44,9 @@ Extraction status of [tttapa/Control-Surface](https://github.com/tttapa/Control- ### MIDI Interfaces - [x] `BluetoothMIDI_Interface` — BLE MIDI via BTstack (pico-native) +- [x] `USBMIDI_Interface` — USB MIDI device via TinyUSB +- [x] `HardwareSerialMIDI_Interface` — 5-pin DIN MIDI over UART (31250 baud) +- [x] `AppleMIDI_Interface` — RTP-MIDI over WiFi with mDNS/Bonjour discovery - [x] `MIDI_Pipe` / `MIDI_PipeFactory` / `BidirectionalMIDI_PipeFactory` - [x] `Control_Surface` singleton — declarative begin/loop lifecycle @@ -66,8 +69,6 @@ Extraction status of [tttapa/Control-Surface](https://github.com/tttapa/Control- output-side examples.* ### Additional MIDI Interfaces -- [ ] USB MIDI Interface (TinyUSB) -- [ ] Serial/Hardware MIDI Interface - [ ] Debug MIDI Interface (serial monitor output) ### Display Elements @@ -84,4 +85,4 @@ output-side examples.* ### Advanced Features - [ ] MIDI input fine-grained callbacks (per-message-type) - [ ] SysEx send/receive helpers -- [ ] AppleMIDI (RTP-MIDI over WiFi) +- [x] AppleMIDI (RTP-MIDI over WiFi)