Browse Source

iOS: Made it clear that the "Audio Background Capability" setting must be enabled for MidiInput/Output::createNewDevice() to succeed

tags/2021-05-28
ed 6 years ago
parent
commit
251ec6daa8
3 changed files with 34 additions and 3 deletions
  1. +2
    -1
      extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h
  2. +6
    -0
      modules/juce_audio_devices/midi_io/juce_MidiDevices.h
  3. +26
    -2
      modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp

+ 2
- 1
extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h View File

@@ -334,7 +334,8 @@ public:
if (iOS) if (iOS)
{ {
props.add (new ChoicePropertyComponent (iosBackgroundAudioValue, "Audio Background Capability"), props.add (new ChoicePropertyComponent (iosBackgroundAudioValue, "Audio Background Capability"),
"Enable this to grant your app the capability to access audio when in background mode.");
"Enable this to grant your app the capability to access audio when in background mode. "
"This permission is required if your app creates a MIDI input or output device.");
props.add (new ChoicePropertyComponent (iosBackgroundBleValue, "Bluetooth MIDI Background Capability"), props.add (new ChoicePropertyComponent (iosBackgroundBleValue, "Bluetooth MIDI Background Capability"),
"Enable this to grant your app the capability to connect to Bluetooth LE devices when in background mode."); "Enable this to grant your app the capability to connect to Bluetooth LE devices when in background mode.");


+ 6
- 0
modules/juce_audio_devices/midi_io/juce_MidiDevices.h View File

@@ -112,6 +112,9 @@ public:
This will attempt to create a new midi input device with the specified name for other This will attempt to create a new midi input device with the specified name for other
apps to connect to. apps to connect to.
NB - if you are calling this method on iOS you must have enabled the "Audio Background Capability"
setting in the iOS exporter otherwise this method will fail.
Returns nullptr if a device can't be created. Returns nullptr if a device can't be created.
@param deviceName the name of the device to create @param deviceName the name of the device to create
@@ -265,6 +268,9 @@ public:
This will attempt to create a new midi output device with the specified name that other This will attempt to create a new midi output device with the specified name that other
apps can connect to and use as their midi input. apps can connect to and use as their midi input.
NB - if you are calling this method on iOS you must have enabled the "Audio Background Capability"
setting in the iOS exporter otherwise this method will fail.
Returns nullptr if a device can't be created. Returns nullptr if a device can't be created.
@param deviceName the name of the device to create @param deviceName the name of the device to create


+ 26
- 2
modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp View File

@@ -459,7 +459,19 @@ MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallba
MIDIEndpointRef endpoint; MIDIEndpointRef endpoint;
ScopedCFString name (deviceName); ScopedCFString name (deviceName);
if (CHECK_ERROR (MIDIDestinationCreate (client, name.cfString, midiInputProc, mpc.get(), &endpoint)))
auto err = MIDIDestinationCreate (client, name.cfString, midiInputProc, mpc.get(), &endpoint);
#if JUCE_IOS
if (err == kMIDINotPermitted)
{
// If you've hit this assertion then you probably haven't enabled the "Audio Background Capability"
// setting in the iOS exporter for your app - this is required if you want to create a MIDI device!
jassertfalse;
return nullptr;
}
#endif
if (CHECK_ERROR (err))
{ {
auto deviceIdentifier = createUniqueIDForMidiPort (deviceName, true); auto deviceIdentifier = createUniqueIDForMidiPort (deviceName, true);
@@ -582,7 +594,19 @@ MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
ScopedCFString name (deviceName); ScopedCFString name (deviceName);
if (CHECK_ERROR (MIDISourceCreate (client, name.cfString, &endpoint)))
auto err = MIDISourceCreate (client, name.cfString, &endpoint);
#if JUCE_IOS
if (err == kMIDINotPermitted)
{
// If you've hit this assertion then you probably haven't enabled the "Audio Background Capability"
// setting in the iOS exporter for your app - this is required if you want to create a MIDI device!
jassertfalse;
return nullptr;
}
#endif
if (CHECK_ERROR (err))
{ {
auto deviceIdentifier = createUniqueIDForMidiPort (deviceName, true); auto deviceIdentifier = createUniqueIDForMidiPort (deviceName, true);


Loading…
Cancel
Save