Create virtual Midi Port on iPad

ios
midi
#1

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?

0 Likes

#2

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.

0 Likes

#3

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).

0 Likes

#4
1 Like

#5

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!).

0 Likes

#6

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).

0 Likes

Midi input from other apps on ipad
#7

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

#8

Really thank you, now all works perfectly!

0 Likes