mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Automatically connect midi input devices on mobile in standalone filter apps
This commit is contained in:
parent
5ba1723512
commit
aa150395f4
1 changed files with 52 additions and 0 deletions
|
|
@ -34,6 +34,9 @@
|
|||
computer's audio/MIDI devices using AudioDeviceManager and AudioProcessorPlayer.
|
||||
*/
|
||||
class StandalonePluginHolder
|
||||
#if JUCE_IOS || JUCE_ANDROID
|
||||
: private Timer
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
/** Creates an instance of the default plugin.
|
||||
|
|
@ -61,10 +64,18 @@ public:
|
|||
setupAudioDevices (preferredDefaultDeviceName, preferredSetupOptions);
|
||||
reloadPluginState();
|
||||
startPlaying();
|
||||
|
||||
#if JUCE_IOS || JUCE_ANDROID
|
||||
startTimer (500);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~StandalonePluginHolder()
|
||||
{
|
||||
#if JUCE_IOS || JUCE_ANDROID
|
||||
stopTimer();
|
||||
#endif
|
||||
|
||||
deletePlugin();
|
||||
shutDownAudioDevices();
|
||||
}
|
||||
|
|
@ -265,6 +276,10 @@ public:
|
|||
AudioDeviceManager deviceManager;
|
||||
AudioProcessorPlayer player;
|
||||
|
||||
#if JUCE_IOS || JUCE_ANDROID
|
||||
StringArray lastMidiDevices;
|
||||
#endif
|
||||
|
||||
private:
|
||||
void setupAudioDevices (const String& preferredDefaultDeviceName,
|
||||
const AudioDeviceManager::AudioDeviceSetup* preferredSetupOptions)
|
||||
|
|
@ -283,6 +298,43 @@ private:
|
|||
deviceManager.removeAudioCallback (&player);
|
||||
}
|
||||
|
||||
#if JUCE_IOS || JUCE_ANDROID
|
||||
void timerCallback() override
|
||||
{
|
||||
StringArray midiInputDevices = MidiInput::getDevices();
|
||||
if (midiInputDevices != lastMidiDevices)
|
||||
{
|
||||
{
|
||||
const int n = lastMidiDevices.size();
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
const String& oldDevice = lastMidiDevices[i];
|
||||
|
||||
if (! midiInputDevices.contains (oldDevice))
|
||||
{
|
||||
deviceManager.setMidiInputEnabled (oldDevice, false);
|
||||
deviceManager.removeMidiInputCallback (oldDevice, &player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const int n = midiInputDevices.size();
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
const String& newDevice = midiInputDevices[i];
|
||||
|
||||
if (! lastMidiDevices.contains (newDevice))
|
||||
{
|
||||
deviceManager.addMidiInputCallback (newDevice, &player);
|
||||
deviceManager.setMidiInputEnabled (newDevice, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StandalonePluginHolder)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue