How to send multiple MIDI Events over USB on iOs with Xamarin?

I am using Core Midi to send MIDI Events over USB on a Xamarin iOs app, I am based on this example https://developer.xamarin.com/samples/monotouch/CoreMidiSample/

I want to modify the above example in order to send multiple NoteOn MIDI Events at the same time over USB, Unfortunately, It works only to send one NoteOn Midi Event at time,

Here is the modified part

void SendNote ()
        {
            for (int i = 0; i < Midi.DestinationCount; i++) {
                var endpoint = MidiEndpoint.GetDestination (i);
                // play note
                outputPort.Send (endpoint, new MidiPacket [] { new MidiPacket (0, new byte [] { 0x90, 60, 127 }) });
                outputPort.Send(endpoint, new MidiPacket[] { new MidiPacket(0, new byte[] { 0x90, 64, 127 }) });
                outputPort.Send(endpoint, new MidiPacket[] { new MidiPacket(0, new byte[] { 0x90, 68, 127 }) });
            }
        }

It sound only one note sometimes, sometimes two notes, I would expect to get the three notes to sound at the same time always, How can I do that?

1 answer

  • answered 2018-07-11 06:28 CL.

    A MidiPacket contains just a bunch of bytes to be sent. So you can concatenate them:

    new byte [] { 0x90, 60, 127, 0x90, 64, 127, 0x90, 68, 127 }
    

    or even use running status:

    new byte [] { 0x90, 60, 127, 64, 127, 68, 127 }