26 bool AudioDeviceManager::AudioDeviceSetup::operator== (
const AudioDeviceManager::AudioDeviceSetup& other)
const
38 bool AudioDeviceManager::AudioDeviceSetup::operator!= (
const AudioDeviceManager::AudioDeviceSetup& other)
const
40 return ! operator== (other);
52 void audioDeviceIOCallback (
const float** ins,
int numIns,
float** outs,
int numOuts,
int numSamples)
override
54 owner.audioDeviceIOCallbackInt (ins, numIns, outs, numOuts, numSamples);
59 owner.audioDeviceAboutToStartInt (device);
62 void audioDeviceStopped()
override
64 owner.audioDeviceStoppedInt();
67 void audioDeviceError (
const String& message)
override
69 owner.audioDeviceErrorInt (message);
74 owner.handleIncomingMidiMessageInt (source, message);
77 void audioDeviceListChanged()
override
79 owner.audioDeviceListChanged();
95 currentAudioDevice.reset();
96 defaultMidiOutput.reset();
100 void AudioDeviceManager::createDeviceTypesIfNeeded()
102 if (availableDeviceTypes.size() == 0)
107 for (
auto* t : types)
112 if (
auto* first = availableDeviceTypes.getFirst())
113 currentDeviceType = first->getTypeName();
119 scanDevicesIfNeeded();
120 return availableDeviceTypes;
123 void AudioDeviceManager::audioDeviceListChanged()
125 if (currentAudioDevice !=
nullptr)
127 auto isCurrentDeviceStillAvailable = [&]
129 for (
auto* dt : availableDeviceTypes)
130 if (currentAudioDevice->getTypeName() == dt->getTypeName())
131 for (
auto& dn : dt->getDeviceNames())
132 if (currentAudioDevice->getName() == dn)
138 if (! isCurrentDeviceStillAvailable())
143 initialiseFromXML (*e,
true, preferredDeviceName, ¤tSetup);
145 initialiseDefault (preferredDeviceName, ¤tSetup);
148 if (currentAudioDevice !=
nullptr)
150 currentSetup.
sampleRate = currentAudioDevice->getCurrentSampleRate();
151 currentSetup.
bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
152 currentSetup.
inputChannels = currentAudioDevice->getActiveInputChannels();
153 currentSetup.
outputChannels = currentAudioDevice->getActiveOutputChannels();
161 static void addIfNotNull (OwnedArray<AudioIODeviceType>& list, AudioIODeviceType*
const device)
163 if (device !=
nullptr)
185 if (newDeviceType !=
nullptr)
187 jassert (lastDeviceTypeConfigs.size() == availableDeviceTypes.size());
189 availableDeviceTypes.add (newDeviceType.release());
192 availableDeviceTypes.getLast()->addListener (callbackHandler.get());
198 if (deviceTypeToRemove !=
nullptr)
200 jassert (lastDeviceTypeConfigs.size() == availableDeviceTypes.size());
202 auto index = availableDeviceTypes.indexOf (deviceTypeToRemove);
204 if (
auto removed = std::unique_ptr<AudioIODeviceType> (availableDeviceTypes.removeAndReturn (index)))
206 removed->removeListener (callbackHandler.get());
207 lastDeviceTypeConfigs.remove (index,
true);
215 if (deviceName.trim().equalsIgnoreCase (name.
trim()))
223 const int numOutputChannelsNeeded,
225 const bool selectDefaultDeviceOnFailure,
226 const String& preferredDefaultDeviceName,
229 scanDevicesIfNeeded();
231 numInputChansNeeded = numInputChannelsNeeded;
232 numOutputChansNeeded = numOutputChannelsNeeded;
233 preferredDeviceName = preferredDefaultDeviceName;
235 if (xml !=
nullptr && xml->
hasTagName (
"DEVICESETUP"))
236 return initialiseFromXML (*xml, selectDefaultDeviceOnFailure,
237 preferredDeviceName, preferredSetupOptions);
239 return initialiseDefault (preferredDeviceName, preferredSetupOptions);
242 String AudioDeviceManager::initialiseDefault (
const String& preferredDefaultDeviceName,
243 const AudioDeviceSetup* preferredSetupOptions)
245 AudioDeviceSetup setup;
247 if (preferredSetupOptions !=
nullptr)
249 setup = *preferredSetupOptions;
251 else if (preferredDefaultDeviceName.
isNotEmpty())
253 for (
auto* type : availableDeviceTypes)
257 if (out.matchesWildcard (preferredDefaultDeviceName,
true))
259 setup.outputDeviceName = out;
266 if (in.matchesWildcard (preferredDefaultDeviceName,
true))
268 setup.inputDeviceName = in;
275 insertDefaultDeviceNames (setup);
279 String AudioDeviceManager::initialiseFromXML (
const XmlElement& xml,
280 bool selectDefaultDeviceOnFailure,
281 const String& preferredDefaultDeviceName,
282 const AudioDeviceSetup* preferredSetupOptions)
284 lastExplicitSettings.reset (
new XmlElement (xml));
287 AudioDeviceSetup setup;
289 if (preferredSetupOptions !=
nullptr)
290 setup = *preferredSetupOptions;
292 if (xml.getStringAttribute (
"audioDeviceName").isNotEmpty())
294 setup.inputDeviceName = setup.outputDeviceName
295 = xml.getStringAttribute (
"audioDeviceName");
299 setup.inputDeviceName = xml.getStringAttribute (
"audioInputDeviceName");
300 setup.outputDeviceName = xml.getStringAttribute (
"audioOutputDeviceName");
303 currentDeviceType = xml.getStringAttribute (
"deviceType");
305 if (findType (currentDeviceType) ==
nullptr)
307 if (
auto* type = findType (setup.inputDeviceName, setup.outputDeviceName))
309 else if (
auto* firstType = availableDeviceTypes.getFirst())
310 currentDeviceType = firstType->getTypeName();
313 setup.bufferSize = xml.getIntAttribute (
"audioDeviceBufferSize", setup.bufferSize);
314 setup.sampleRate = xml.getDoubleAttribute (
"audioDeviceRate", setup.sampleRate);
316 setup.inputChannels .parseString (xml.getStringAttribute (
"audioDeviceInChans",
"11"), 2);
317 setup.outputChannels.parseString (xml.getStringAttribute (
"audioDeviceOutChans",
"11"), 2);
319 setup.useDefaultInputChannels = ! xml.hasAttribute (
"audioDeviceInChans");
320 setup.useDefaultOutputChannels = ! xml.hasAttribute (
"audioDeviceOutChans");
324 if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
325 error =
initialise (numInputChansNeeded, numOutputChansNeeded,
nullptr,
false, preferredDefaultDeviceName);
327 midiDeviceInfosFromXml.clear();
328 enabledMidiInputs.clear();
330 forEachXmlChildElementWithTagName (xml, c,
"MIDIINPUT")
331 midiDeviceInfosFromXml.add ({ c->getStringAttribute (
"name"), c->getStringAttribute (
"identifier") });
333 auto isIdentifierAvailable = [] (
const Array<MidiDeviceInfo>& available,
const String& identifier)
335 for (
auto& device : available)
336 if (device.identifier == identifier)
342 auto getUpdatedIdentifierForName = [&] (
const Array<MidiDeviceInfo>& available,
const String& name) -> String
344 for (
auto& device : available)
345 if (device.name == name)
346 return device.identifier;
353 for (
auto& info : midiDeviceInfosFromXml)
355 if (isIdentifierAvailable (inputs, info.identifier))
361 auto identifier = getUpdatedIdentifierForName (inputs, info.name);
363 if (identifier.isNotEmpty())
368 MidiDeviceInfo defaultOutputDeviceInfo (xml.getStringAttribute (
"defaultMidiOutput"),
369 xml.getStringAttribute (
"defaultMidiOutputDevice"));
373 if (isIdentifierAvailable (outputs, defaultOutputDeviceInfo.identifier))
379 auto identifier = getUpdatedIdentifierForName (outputs, defaultOutputDeviceInfo.name);
381 if (identifier.isNotEmpty())
389 int numOutputChannelsNeeded)
391 lastExplicitSettings.reset();
393 return initialise (numInputChannelsNeeded, numOutputChannelsNeeded,
394 nullptr,
false, {},
nullptr);
397 void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup)
const
401 if (numOutputChansNeeded > 0 && setup.outputDeviceName.isEmpty())
404 if (numInputChansNeeded > 0 && setup.inputDeviceName.isEmpty())
411 if (lastExplicitSettings !=
nullptr)
412 return std::make_unique<XmlElement> (*lastExplicitSettings);
418 void AudioDeviceManager::scanDevicesIfNeeded()
420 if (listNeedsScanning)
422 listNeedsScanning =
false;
424 createDeviceTypesIfNeeded();
426 for (
auto* type : availableDeviceTypes)
431 AudioIODeviceType* AudioDeviceManager::findType (
const String& typeName)
433 scanDevicesIfNeeded();
435 for (
auto* type : availableDeviceTypes)
442 AudioIODeviceType* AudioDeviceManager::findType (
const String& inputName,
const String& outputName)
444 scanDevicesIfNeeded();
446 for (
auto* type : availableDeviceTypes)
447 if ((inputName.isNotEmpty() && deviceListContains (type,
true, inputName))
448 || (outputName.isNotEmpty() && deviceListContains (type,
false, outputName)))
461 setup = currentSetup;
464 void AudioDeviceManager::deleteCurrentDevice()
466 currentAudioDevice.reset();
473 for (
int i = 0; i < availableDeviceTypes.size(); ++i)
475 if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
476 && currentDeviceType != type)
478 if (currentAudioDevice !=
nullptr)
485 currentDeviceType = type;
488 insertDefaultDeviceNames (s);
500 for (
auto* type : availableDeviceTypes)
504 return availableDeviceTypes.getFirst();
509 auto updateChannels = [](
const String& deviceName,
BigInteger& channels,
int defaultNumChannels)
515 else if (defaultNumChannels != -1)
518 channels.setRange (0, defaultNumChannels,
true);
527 bool treatAsChosenDevice)
529 jassert (&newSetup != ¤tSetup);
531 if (newSetup != currentSetup)
533 else if (currentAudioDevice !=
nullptr)
539 deleteCurrentDevice();
541 if (treatAsChosenDevice)
553 || currentAudioDevice ==
nullptr)
555 deleteCurrentDevice();
556 scanDevicesIfNeeded();
568 if (currentAudioDevice ==
nullptr)
569 error =
"Can't open the audio device!\n\n"
570 "This may be because another application is currently using the same device - "
571 "if so, you should close any other applications and try again!";
573 error = currentAudioDevice->getLastError();
577 deleteCurrentDevice();
582 currentSetup = newSetup;
587 updateSetupChannels (currentSetup, numInputChansNeeded, numOutputChansNeeded);
591 if (treatAsChosenDevice)
600 error = currentAudioDevice->open (currentSetup.
inputChannels,
607 currentDeviceType = currentAudioDevice->getTypeName();
609 currentAudioDevice->start (callbackHandler.get());
611 currentSetup.
sampleRate = currentAudioDevice->getCurrentSampleRate();
612 currentSetup.
bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
613 currentSetup.
inputChannels = currentAudioDevice->getActiveInputChannels();
614 currentSetup.
outputChannels = currentAudioDevice->getActiveOutputChannels();
616 for (
int i = 0; i < availableDeviceTypes.size(); ++i)
617 if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
618 *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
620 if (treatAsChosenDevice)
625 deleteCurrentDevice();
631 double AudioDeviceManager::chooseBestSampleRate (
double rate)
const
633 jassert (currentAudioDevice !=
nullptr);
635 auto rates = currentAudioDevice->getAvailableSampleRates();
637 if (rate > 0 && rates.contains (rate))
640 rate = currentAudioDevice->getCurrentSampleRate();
642 if (rate > 0 && rates.contains (rate))
645 double lowestAbove44 = 0.0;
647 for (
int i = rates.size(); --i >= 0;)
651 if (sr >= 44100.0 && (lowestAbove44 < 1.0 || sr < lowestAbove44))
655 if (lowestAbove44 > 0.0)
656 return lowestAbove44;
661 int AudioDeviceManager::chooseBestBufferSize (
int bufferSize)
const
663 jassert (currentAudioDevice !=
nullptr);
665 if (bufferSize > 0 && currentAudioDevice->getAvailableBufferSizes().contains (bufferSize))
668 return currentAudioDevice->getDefaultBufferSize();
671 void AudioDeviceManager::stopDevice()
673 if (currentAudioDevice !=
nullptr)
674 currentAudioDevice->stop();
682 currentAudioDevice.reset();
683 loadMeasurer.
reset();
688 if (currentAudioDevice ==
nullptr)
705 void AudioDeviceManager::updateXml()
707 lastExplicitSettings.reset (
new XmlElement (
"DEVICESETUP"));
709 lastExplicitSettings->setAttribute (
"deviceType", currentDeviceType);
710 lastExplicitSettings->setAttribute (
"audioOutputDeviceName", currentSetup.
outputDeviceName);
711 lastExplicitSettings->setAttribute (
"audioInputDeviceName", currentSetup.
inputDeviceName);
713 if (currentAudioDevice !=
nullptr)
715 lastExplicitSettings->setAttribute (
"audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
717 if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
718 lastExplicitSettings->setAttribute (
"audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
727 for (
auto& input : enabledMidiInputs)
729 auto* child = lastExplicitSettings->createNewChildElement (
"MIDIINPUT");
731 child->setAttribute (
"name", input->getName());
732 child->setAttribute (
"identifier", input->getIdentifier());
735 if (midiDeviceInfosFromXml.size() > 0)
741 for (
auto& d : midiDeviceInfosFromXml)
743 if (! availableMidiDevices.contains (d))
745 auto* child = lastExplicitSettings->createNewChildElement (
"MIDIINPUT");
747 child->setAttribute (
"name", d.name);
748 child->setAttribute (
"identifier", d.identifier);
753 if (defaultMidiOutputDeviceInfo != MidiDeviceInfo())
755 lastExplicitSettings->setAttribute (
"defaultMidiOutput", defaultMidiOutputDeviceInfo.
name);
756 lastExplicitSettings->setAttribute (
"defaultMidiOutputDevice", defaultMidiOutputDeviceInfo.
identifier);
766 if (callbacks.contains (newCallback))
770 if (currentAudioDevice !=
nullptr && newCallback !=
nullptr)
774 callbacks.add (newCallback);
779 if (callbackToRemove !=
nullptr)
781 bool needsDeinitialising = currentAudioDevice !=
nullptr;
786 needsDeinitialising = needsDeinitialising && callbacks.contains (callbackToRemove);
787 callbacks.removeFirstMatchingValue (callbackToRemove);
790 if (needsDeinitialising)
795 void AudioDeviceManager::audioDeviceIOCallbackInt (
const float** inputChannelData,
796 int numInputChannels,
797 float** outputChannelData,
798 int numOutputChannels,
803 inputLevelGetter->updateLevel (inputChannelData, numInputChannels, numSamples);
804 outputLevelGetter->updateLevel (
const_cast<const float**
> (outputChannelData), numOutputChannels, numSamples);
806 if (callbacks.size() > 0)
810 tempBuffer.
setSize (jmax (1, numOutputChannels), jmax (1, numSamples),
false,
false,
true);
812 callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
813 outputChannelData, numOutputChannels, numSamples);
817 for (
int i = callbacks.size(); --i > 0;)
819 callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
820 tempChans, numOutputChannels, numSamples);
822 for (
int chan = 0; chan < numOutputChannels; ++chan)
824 if (
auto* src = tempChans [chan])
825 if (
auto* dst = outputChannelData [chan])
826 for (
int j = 0; j < numSamples; ++j)
833 for (
int i = 0; i < numOutputChannels; ++i)
834 zeromem (outputChannelData[i], (
size_t) numSamples *
sizeof (
float));
837 if (testSound !=
nullptr)
839 auto numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
840 auto* src = testSound->getReadPointer (0, testSoundPosition);
842 for (
int i = 0; i < numOutputChannels; ++i)
843 for (
int j = 0; j < numSamps; ++j)
844 outputChannelData [i][j] += src[j];
846 testSoundPosition += numSamps;
848 if (testSoundPosition >= testSound->getNumSamples())
853 void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice*
const device)
855 loadMeasurer.
reset (device->getCurrentSampleRate(),
856 device->getCurrentBufferSizeSamples());
859 const ScopedLock sl (audioCallbackLock);
861 for (
int i = callbacks.size(); --i >= 0;)
862 callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
868 void AudioDeviceManager::audioDeviceStoppedInt()
872 const ScopedLock sl (audioCallbackLock);
874 loadMeasurer.
reset();
876 for (
int i = callbacks.size(); --i >= 0;)
877 callbacks.getUnchecked(i)->audioDeviceStopped();
880 void AudioDeviceManager::audioDeviceErrorInt (
const String& message)
882 const ScopedLock sl (audioCallbackLock);
884 for (
int i = callbacks.size(); --i >= 0;)
885 callbacks.getUnchecked(i)->audioDeviceError (message);
902 enabledMidiInputs.push_back (std::move (midiIn));
903 enabledMidiInputs.back()->start();
908 auto removePredicate = [identifier] (
const std::unique_ptr<MidiInput>& in) {
return in->getIdentifier() == identifier; };
909 enabledMidiInputs.erase (std::remove_if (std::begin (enabledMidiInputs), std::end (enabledMidiInputs), removePredicate),
910 std::end (enabledMidiInputs));
920 for (
auto& mi : enabledMidiInputs)
921 if (mi->getIdentifier() == identifier)
934 midiCallbacks.
add ({ identifier, callbackToAdd });
940 for (
int i = midiCallbacks.
size(); --i >= 0;)
944 if (mc.callback == callbackToRemove && mc.deviceIdentifier == identifier)
952 void AudioDeviceManager::handleIncomingMidiMessageInt (
MidiInput* source,
const MidiMessage& message)
958 for (
auto& mc : midiCallbacks)
959 if (mc.deviceIdentifier.isEmpty() || mc.deviceIdentifier == source->
getIdentifier())
960 mc.callback->handleIncomingMidiMessage (source, message);
967 if (defaultMidiOutputDeviceInfo.
identifier != identifier)
976 if (currentAudioDevice !=
nullptr)
977 for (
int i = oldCallbacks.
size(); --i >= 0;)
980 defaultMidiOutput.reset();
985 if (defaultMidiOutput !=
nullptr)
986 defaultMidiOutputDeviceInfo = defaultMidiOutput->getDeviceInfo();
988 defaultMidiOutputDeviceInfo = {};
990 if (currentAudioDevice !=
nullptr)
991 for (
auto* c : oldCallbacks)
992 c->audioDeviceAboutToStart (currentAudioDevice.get());
1005 AudioDeviceManager::LevelMeter::LevelMeter() noexcept : level() {}
1007 void AudioDeviceManager::LevelMeter::updateLevel (
const float*
const* channelData,
int numChannels,
int numSamples) noexcept
1009 if (getReferenceCount() <= 1)
1012 auto localLevel = level.get();
1014 if (numChannels > 0)
1016 for (
int j = 0; j < numSamples; ++j)
1020 for (
int i = 0; i < numChannels; ++i)
1021 s += std::abs (channelData[i][j]);
1023 s /= (float) numChannels;
1025 const float decayFactor = 0.99992f;
1029 else if (localLevel > 0.001f)
1030 localLevel *= decayFactor;
1043 double AudioDeviceManager::LevelMeter::getCurrentLevel() const noexcept
1045 jassert (getReferenceCount() > 1);
1052 std::unique_ptr<AudioBuffer<float>> oldSound;
1056 std::swap (oldSound, testSound);
1060 testSoundPosition = 0;
1062 if (currentAudioDevice !=
nullptr)
1064 auto sampleRate = currentAudioDevice->getCurrentSampleRate();
1065 auto soundLength = (int) sampleRate;
1067 double frequency = 440.0;
1068 float amplitude = 0.5f;
1072 std::unique_ptr<AudioBuffer<float>> newSound (
new AudioBuffer<float> (1, soundLength));
1074 for (
int i = 0; i < soundLength; ++i)
1075 newSound->setSample (0, i, amplitude * (
float) std::sin (i * phasePerSample));
1077 newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
1078 newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
1082 std::swap (testSound, newSound);
1089 auto deviceXRuns = (currentAudioDevice !=
nullptr ? currentAudioDevice->getXRunCount() : -1);
1090 return jmax (0, deviceXRuns) + loadMeasurer.
getXRunCount();
1099 if (device.name == name)
1110 if (device.name == name)
1126 if (device.name == name)
1139 if (device.name == name)
1151 if (device.name == name)
Holds a resizable array of primitive or copy-by-value objects.
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
int size() const noexcept
Returns the current number of elements in the array.
void remove(int indexToRemove)
Removes an element from the array.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
void setSize(int newNumChannels, int newNumSamples, bool keepExistingContent=false, bool clearExtraSpace=false, bool avoidReallocating=false)
Changes the buffer's size or number of channels.
Type ** getArrayOfWritePointers() noexcept
Returns an array of pointers to the channels in the buffer.
Manages the state of some audio and midi i/o devices.
bool isMidiInputDeviceEnabled(const String &deviceIdentifier) const
Returns true if a given midi input device is being used.
AudioDeviceManager()
Creates a default AudioDeviceManager.
void removeAudioDeviceType(AudioIODeviceType *deviceTypeToRemove)
Removes a previously added device type from the manager.
AudioDeviceSetup getAudioDeviceSetup() const
Returns the current device properties that are in use.
void removeMidiInputDeviceCallback(const String &deviceIdentifier, MidiInputCallback *callback)
Removes a listener that was previously registered with addMidiInputDeviceCallback().
double getCpuUsage() const
Returns the average proportion of available CPU being spent inside the audio callbacks.
AudioIODeviceType * getCurrentDeviceTypeObject() const
Returns the currently active audio device type object.
String setAudioDeviceSetup(const AudioDeviceSetup &newSetup, bool treatAsChosenDevice)
Changes the current device or its settings.
void removeMidiInputCallback(const String &, MidiInputCallback *)
Deprecated.
bool isMidiInputEnabled(const String &) const
Deprecated.
virtual void createAudioDeviceTypes(OwnedArray< AudioIODeviceType > &types)
Creates a list of available types.
void setMidiInputEnabled(const String &, bool)
Deprecated.
void setDefaultMidiOutputDevice(const String &deviceIdentifier)
Sets a midi output device to use as the default.
void setMidiInputDeviceEnabled(const String &deviceIdentifier, bool enabled)
Enables or disables a midi input device.
void setDefaultMidiOutput(const String &)
Deprecated.
int getXRunCount() const noexcept
Returns the number of under- or over runs reported.
void addMidiInputCallback(const String &, MidiInputCallback *)
Deprecated.
void addMidiInputDeviceCallback(const String &deviceIdentifier, MidiInputCallback *callback)
Registers a listener for callbacks when midi events arrive from a midi input.
void setCurrentAudioDeviceType(const String &type, bool treatAsChosenDevice)
Changes the class of audio device being used.
~AudioDeviceManager() override
Destructor.
const OwnedArray< AudioIODeviceType > & getAvailableDeviceTypes()
Returns a list of the types of device supported.
String initialise(int numInputChannelsNeeded, int numOutputChannelsNeeded, const XmlElement *savedState, bool selectDefaultDeviceOnFailure, const String &preferredDefaultDeviceName=String(), const AudioDeviceSetup *preferredSetupOptions=nullptr)
Opens a set of audio devices ready for use.
void addAudioCallback(AudioIODeviceCallback *newCallback)
Registers an audio callback to be used.
String initialiseWithDefaultDevices(int numInputChannelsNeeded, int numOutputChannelsNeeded)
Resets everything to a default device setup, clearing any stored settings.
void restartLastAudioDevice()
Tries to reload the last audio device that was running.
void removeAudioCallback(AudioIODeviceCallback *callback)
Deregisters a previously added callback.
void playTestSound()
Plays a beep through the current audio device.
void addAudioDeviceType(std::unique_ptr< AudioIODeviceType > newDeviceType)
Adds a new device type to the list of types.
void closeAudioDevice()
Closes the currently-open device.
std::unique_ptr< XmlElement > createStateXml() const
Returns some XML representing the current state of the manager.
One of these is passed to an AudioIODevice object to stream the audio data in and out.
virtual void audioDeviceAboutToStart(AudioIODevice *device)=0
Called to indicate that the device is about to start calling back.
virtual void audioDeviceStopped()=0
Called to indicate that the device has stopped.
A class for receiving events when audio devices are inserted or removed.
Represents a type of audio driver, such as DirectSound, ASIO, CoreAudio, etc.
virtual int getDefaultDeviceIndex(bool forInput) const =0
Returns the name of the default device.
static AudioIODeviceType * createAudioIODeviceType_ASIO()
Creates an ASIO device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_Oboe()
Creates an Oboe device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_CoreAudio()
Creates a CoreAudio device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_JACK()
Creates a JACK device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_DirectSound()
Creates a DirectSound device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_OpenSLES()
Creates an Android OpenSLES device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_WASAPI(bool exclusiveMode)
Creates a WASAPI device type if it's available on this platform, or returns null.
virtual StringArray getDeviceNames(bool wantInputNames=false) const =0
Returns the list of available devices of this type.
virtual void scanForDevices()=0
Refreshes the object's cached list of known devices.
static AudioIODeviceType * createAudioIODeviceType_iOSAudio()
Creates an iOS device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_Bela()
Creates a Bela device type if it's available on this platform, or returns null.
virtual AudioIODevice * createDevice(const String &outputDeviceName, const String &inputDeviceName)=0
Creates one of the devices of this type.
const String & getTypeName() const noexcept
Returns the name of this type of driver that this object manages.
static AudioIODeviceType * createAudioIODeviceType_Android()
Creates an Android device type if it's available on this platform, or returns null.
static AudioIODeviceType * createAudioIODeviceType_ALSA()
Creates an ALSA device type if it's available on this platform, or returns null.
Base class for an audio device with synchronised input and output channels.
int getXRunCount() const
Returns the number of over- (or under-) runs recorded since the state was reset.
void reset()
Resets the state.
double getLoadAsProportion() const
Returns the current load as a proportion 0 to 1.0.
An arbitrarily large integer class.
String toString(int base, int minimumNumCharacters=1) const
Converts the number to a string.
bool isZero() const noexcept
Returns true if no bits are set.
int countNumberOfSetBits() const noexcept
Returns the total number of set bits in the value.
void sendChangeMessage()
Causes an asynchronous change message to be sent to all the registered listeners.
Automatically locks and unlocks a mutex object.
Encapsulates a MIDI message.
bool isActiveSense() const noexcept
Returns true if this is an active-sense message.
static Array< MidiDeviceInfo > getAvailableDevices()
Returns a list of the available midi output devices.
static std::unique_ptr< MidiOutput > openDevice(const String &deviceIdentifier)
Tries to open one of the midi output devices.
An array designed for holding objects.
String trim() const
Returns a copy of this string with any whitespace characters removed from the start and end.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
void clear() noexcept
Resets this string to be empty.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
static void JUCE_CALLTYPE sleep(int milliseconds)
Suspends the execution of the current thread until the specified timeout period has elapsed (note tha...
Used to build a tree of elements representing an XML document.
bool hasTagName(StringRef possibleTagName) const noexcept
Tests whether this element has a particular tag name.
This structure holds a set of properties describing the current audio setup.
String outputDeviceName
The name of the audio device used for output.
bool useDefaultInputChannels
If this is true, it indicates that the inputChannels array should be ignored, and instead,...
String inputDeviceName
The name of the audio device used for input.
BigInteger outputChannels
The set of active output channels.
double sampleRate
The current sample rate.
BigInteger inputChannels
The set of active input channels.
int bufferSize
The buffer size, in samples.
bool useDefaultOutputChannels
If this is true, it indicates that the outputChannels array should be ignored, and instead,...
This class measures the time between its construction and destruction and adds it to an AudioProcessL...
Commonly used mathematical constants.
String name
The name of this device.
String identifier
The identifier for this device.