properly sending Virtual Midi with Sunvox on Mac & iOS

Found a bug? Post it here.
Post Reply
Ol sen
Posts: 20
Joined: Sat Feb 12, 2022 6:26 am

properly sending Virtual Midi with Sunvox on Mac & iOS

Post by Ol sen »

as mentioned in another comment in this forum that was possibly the wrong place for such..

sending virtual midi to another app no matter if iOS or macOS is a reciprocal procedure.
Why is that?
When you deal with system managed midi buffers in which apps hock up or send to you actually get direct access to its buffer, as you just place a callback that gives you the data or a place to send to. Now virtual midi means it is not just a software receiver it is also a buffer managed by the system but allocated by the app that claimed a callback onto it when creating its virtual-In midi buff. Means a mac-virtual-midi-buffer owned by another app will receive data when its callback is triggered to analyse what came in and wise versa trigger your callback with a receive command when your app should receive data. Which leads to a reciprocal behaviour which is not extensively documented but very logic. Otherwise the system would have to shuffle midi buffers on top just to flip flop the reciprocal calls needed.

So what do you do to address such?

yes.

Sending to another App Virtual-Midi-Port is realised when you make a "MIDIReceived" call with the data and wise versa.
Receiving from another App Virtual-Midi-Port is realised when the other app calls "MIDIReceived" with the data for your apps buffer in effect triggering your input callback.

so in code you want to distinguish between virtual devices and physical devices to use the right mechanism for each of them.

Code: Select all

// as seen in sound_apple_midi.hpp > device_midi_client_send_event()
MIDISend( port->port, port->endpoint, &list ); //to normal real physical existing device
MIDIReceived(port->endpoint, &list); // to virtual port of another app
happy coding

PS:
bool isVirtualPort in sunvox_midi_port for mac and set it at virtual (main) port creation so it can be used to distinguish which function to use, depending on port: either physical or virtual.
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: properly sending Virtual Midi with Sunvox on Mac & iOS

Post by NightRadio »

Thanks for the detailed description!
I just made some changes in sound_apple_midi.hpp to work correctly with virtual midi.
But it doesn't affect anything in the current version, because SunVox does not create a virtual MIDI OUT (source) port.
For MIDI OUT i use MIDIGetDestination() to get MIDI destination in the system. So I am forced to use MIDISend().

From the MIDIReceived() description:
Clients which have created virtual sources, using MIDISourceCreate, should call this function when the source is generating MIDI.

I will try to add virtual MIDI OUT port support in one of the updates...
Post Reply