I’m writing a sequencer and I want it to send MIDI out messages. From what I can tell, there’s good documentation and examples on how to handle MIDI in but there isn’t much info on how to handle MIDI out.
/** SendMessage
Send raw bytes as message
*/
void SendMessage(uint8_t* bytes, size_t size)
{
transport_.Tx(bytes, size);
}
This function sends a message based on a set of bytes but how do I populate that set of bytes?
My questions:
How are LibDaisy’s MIDI out capabilities intended to be used?
Are there any existing examples of daisy creating MIDI output?
How do I create and send a MIDI message with LibDaisy? For example, Let’s say I want to create a message that says “play the note C3”
I understand that I could create the bytes for my MIDI out message manually but I’m assuming that LibDaisy provides some sort of tools to makes that process easier.
Say I want to send a C4 note on channel 1 at max velocity. To my understanding I could do something like this:
DaisyField* hw = new DaisyField();
// NOTE ON message
uint8_t rawBytes[] = {
145, // (status byte) 1001 0001
// 1001 = status code for NOTE ON
// 0001 = channel number 1
60, // (pitch) C4
127, // (velocity) max velocity
};
hw.midi.SendMessage((uint8_t*) rawBytes, sizeof(rawBytes));
However I don’t understand how using MidiEvent would make this process any easier. To me it looks like MidiEvent is designed to be used to parse incoming messages.
Sorry, it looks like I’ve pointed you the wrong way. As you’ve noticed correctly, there’s only parsing in libDaisy and it doesn’t help that much for generating them.
I think that the easiest way to deal with this would be by writing an overloaded function that serializes events of different types. Unit tests for MIDI events would help here as they generate bytes the same way as you need, i.e. libDaisy/Midi_gtest.cpp at master · electro-smith/libDaisy · GitHub
But note that serialization code in those files are not fool proof, i.e. you could create an event with velocity = 128 and it would end up malformed. You could add masks to data bytes (&0x7f) to avoid that.
I think you are asking for a higher level of functionality so you don’t have to deal with building midi messages byte by byte.
If I understood the question, then you may find RtMidi - an abstract base class for realtime midi input/output from McGill University to be a good example.
Here’s how it expects you to build a note on message:
// Note On: 144, 64, 90
message[0] = 144;
message[1] = 64;
message[2] = 90;
midiout->sendMessage( &message );
Getting it working on Daisy might be a bigger project than what you’re trying to do, but I think it would be worth looking at as an example.
No worries! I have no qualms writing my own MIDI serialization code, I was just operating under the assumption that LibDaisy provided this functionality.
That unit test is a good find, I’ll use that test code as a reference to write my mini-library.
Woah, thanks! That’s definitely helpful. Porting the library over to daisy outright might be a bit out of scope for my project but at the very least I could take some bits and pieces from it.
This is something we meant to add to libDaisy, and must have gotten accidentally scrubbed from the TODO lists at some point!
I’ve opened a github issue in case anyone wants to contribute code along the way. If not, we’ll be able to slot out some time for our team to work on adding something.
Sorry to bump an old thread but I’m having trouble getting MIDI output to work. Do I have to do anything ahead of calling SendMessage? Do I need to enable MIDI output or something like that?