Hello, while starting on a synth project on my Daisy Pod, I saw a few threads asking about this feature only to see that the MIDIHandler does not directly support this feature yet.
Since I have not seen anything similar posted here yet: I would like to demonstrate a simple temporary workaround, which is based off of the MIDI and USB CDC seed examples.
In short, my code copies the data buffer and size from the USB callback and sets a flag to notify that the there are MIDI packets to process. Once the main function is called, my code then simply passes each byte through the MIDIHandler’s parse function, which will then create Midi Events that will later be processed.
Example Code:
static DaisyPod pod;
static MidiHandler midi;
uint8_t buffer[128];
bool MsgRcvd = false;
uint8_t MsgSize = 0;
void UsbCallback(uint8_t* buf, uint32_t* len)
{
if(!buf || !len)
return;
uint8_t tmpSize;
if(*len < 128U)
tmpSize = *len;
else
tmpSize = 128U;
for(size_t i = 0; i < tmpSize; i++)
{
buffer[i] = buf[i];
}
MsgRcvd = true;
MsgSize = *len;
}
// …
int main(void)
{
pod.Init();
pod.seed.usb_handle.Init(UsbHandle::FS_INTERNAL);
dsy_system_delay(250);
// Initialize MIDI with UART so that state machine is initialized
midi.Init(MidiHandler::INPUT_MODE_UART1, MidiHandler::OUTPUT_MODE_NONE);
// …
pod.seed.usb_handle.SetReceiveCallback(UsbCallback, UsbHandle::FS_INTERNAL);
while(1)
{
// If there is USB Data to process, process the data and clear the buffers
if(MsgRcvd == true)
{
for(int i = 0; i < MsgSize; ++i)
{
midi.Parse(buffer[i]);
buffer[i] = 0;
}
MsgRcvd = false;
MsgSize = 0U;
}
// Handle MIDI Events
while(midi.HasEvents())
{
HandleMidiMessage(midi.PopEvent());
}
}
}
Usb Device Setup
Port Settings:
Bps:115200
Data bits: 8
Parity: None
Stop Bits: 1
Flow Control: None
Tools for Midi
LoopMidi (Virtual Midi port)
https://www.tobias-erichsen.de/software/loopmidi.html
Hairless MIDI Serial (Used to route messages from the Virtual Midi port to the Daisy’s COM port):
https://projectgus.github.io/hairless-midiserial/