Create virtual Midi Port on iPad

Hi, I’d like to create a virtual midi port on my iPad to send message to some apps as Cubasis or AUM, but unfortunately with this code that woks on desktop app doesn’t work on iPad: the virtual port is not detected by any app and when I try to click a button that create a message to send to that port the app gives me the error: JUCE Message Thread (1): EXC_BAD_ACCESS (code=1, address=0x1c8).

MainComponent::MainComponent()
{
setSize (600, 400);
addAndMakeVisible(tb);
mo.reset(MidiOutput::createNewDevice(“test”));
MidiOutput::openDevice(mo->getDefaultDeviceIndex());
tb.onClick = [this] {
auto mm = MidiMessage::noteOn(1, 64, uint8(127));
mo->sendMessageNow(mm);
};
}

How can I solve the error and create a virtual midi port on my iPad?

Consider this experience your first lesson in unsafe pointer usage

you need to make sure before you use mo that it is not holding a nullptr.

if( mo.get() != nullptr )
{
    MidiOutput::openDevice(mo->getDefaultDeviceIndex());
    tb.onClick = [this] {
        auto mm = MidiMessage::noteOn(1, 64, uint8(127));
        mo->sendMessageNow(mm);
    };
}

Secondly, can you even confirm if Virtual Midi ports exist on iOS? I thought they were an OS-X specific thing only.

Really Thank you! I suppose that virtual midi ports exist also in iOS because I noticed that when I open a synth app I could send midi message to it through a port that the synth creates at opening (for example I opened Kaspar, Igrand, iSynphonic, synthmaster one and after cubasis and from cubasis I have a list of output midi ports with the name of apps opened through I can send message from cubasis to these other apps).

1 Like

I tried again creating new project, this time choosing audio plugin from wizard in Projucer enabling in setting only standalone and IAA, after I created a new midi output device and a new midi input device but nothing change. Here what I’ve done:
on Plugin Editor I put under private members those two variables:

MidiInput* mi;
MidiOutput* mo;

on init function I put this code:

mo = MidiOutput::createNewDevice("MyDeviceOut");
// PREVIOUS LINE PRINT IN CONSOLE: CoreMIDI error: 417 - ffffd5a4
if (mo != nullptr) {
    MidiOutput::openDevice(mo->getDefaultDeviceIndex());
}

mi = MidiInput::createNewDevice("MyDeviceIn", this);
// PREVIOUS LINE PRINT IN CONSOLE; CoreMIDI error: 560 - ffffd5a4
if (mi != nullptr) {
    mi->start();
}

Obviously I tried that code on a desktop version and it works!
In attachment a screenshot of how cubasis looks when before it I open another app that create his own midi ports (while if I launch my test it looks the same but without in this case “iGrand Piano”).

Some Ideas? (really thank you again for support!).

Have you enabled the “Audio Background Capability” setting in the iOS exporter in the Projucer? This is needed to create MIDI devices otherwise CoreMidi will throw a kMIDINotPermitted error (which is the ffffd5a4 error you’re seeing).

Actually, we could do a much better job of making this clearer so things won’t just silently fail like in your case. I’ll push something shortly.

EDIT:

2 Likes

Really thank you, now all works perfectly!

Is this actually working?
Here we can only successfully call MidiInput::createNewDevice() if the app is running standalone. If we run the AUv3 in AUM or Cubasis we get the kMIDINotPermitted error.

We are using CMake and we are setting BACKGROUND_AUDIO_ENABLED
to TRUE which results in the same XCode Project Config as if we were using the Projucer. However even within XCode it seems I can’t set the Background Mode for Audio like stated in Apple’s documentation here:

There are apps around which create their own virtual Midi ports though, even when hosted as an AUv3. So there must be a way, but how?

Thank you!

Nobody here using virtual Midi Ports on iOS? It’s pretty common…

Ok, I’ve spent a couple of hours down the rabbit hole:

It seems like this never worked for AUv3s, @Ayra also told me in a PM that it was only tested in Standalone. There seems to be no way to enable Audio Background Mode for an AUv3, I’ve pretty much tried everything in XCode…

It’s not a JUCE bug at least, it seems to be a restriction by Apple. Maybe one of the JUCE devs, @reuk ?, can confirm this and add it to the documentation? My hours are gone but someone else’s could be saved :wink:

2 Likes

Are there no AUv3s that can handle this functionality?

You can‘t create your own virtual MIDI devices but you can enable MIDI I/O: