| @@ -176,10 +176,8 @@ void AudioDeviceManager::addAudioDeviceType (AudioIODeviceType* newDeviceType) | |||||
| static bool deviceListContains (AudioIODeviceType* type, bool isInput, const String& name) | static bool deviceListContains (AudioIODeviceType* type, bool isInput, const String& name) | ||||
| { | { | ||||
| StringArray devices (type->getDeviceNames (isInput)); | |||||
| for (int i = devices.size(); --i >= 0;) | |||||
| if (devices[i].trim().equalsIgnoreCase (name.trim())) | |||||
| for (auto& deviceName : type->getDeviceNames (isInput)) | |||||
| if (deviceName.trim().equalsIgnoreCase (name.trim())) | |||||
| return true; | return true; | ||||
| return false; | return false; | ||||
| @@ -216,28 +214,22 @@ String AudioDeviceManager::initialiseDefault (const String& preferredDefaultDevi | |||||
| } | } | ||||
| else if (preferredDefaultDeviceName.isNotEmpty()) | else if (preferredDefaultDeviceName.isNotEmpty()) | ||||
| { | { | ||||
| for (int j = availableDeviceTypes.size(); --j >= 0;) | |||||
| for (auto* type : availableDeviceTypes) | |||||
| { | { | ||||
| AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j); | |||||
| const StringArray outs (type->getDeviceNames (false)); | |||||
| for (int i = 0; i < outs.size(); ++i) | |||||
| for (auto& out : type->getDeviceNames (false)) | |||||
| { | { | ||||
| if (outs[i].matchesWildcard (preferredDefaultDeviceName, true)) | |||||
| if (out.matchesWildcard (preferredDefaultDeviceName, true)) | |||||
| { | { | ||||
| setup.outputDeviceName = outs[i]; | |||||
| setup.outputDeviceName = out; | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| const StringArray ins (type->getDeviceNames (true)); | |||||
| for (int i = 0; i < ins.size(); ++i) | |||||
| for (auto& in : type->getDeviceNames (true)) | |||||
| { | { | ||||
| if (ins[i].matchesWildcard (preferredDefaultDeviceName, true)) | |||||
| if (in.matchesWildcard (preferredDefaultDeviceName, true)) | |||||
| { | { | ||||
| setup.inputDeviceName = ins[i]; | |||||
| setup.inputDeviceName = in; | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| @@ -249,7 +241,7 @@ String AudioDeviceManager::initialiseDefault (const String& preferredDefaultDevi | |||||
| } | } | ||||
| String AudioDeviceManager::initialiseFromXML (const XmlElement& xml, | String AudioDeviceManager::initialiseFromXML (const XmlElement& xml, | ||||
| const bool selectDefaultDeviceOnFailure, | |||||
| bool selectDefaultDeviceOnFailure, | |||||
| const String& preferredDefaultDeviceName, | const String& preferredDefaultDeviceName, | ||||
| const AudioDeviceSetup* preferredSetupOptions) | const AudioDeviceSetup* preferredSetupOptions) | ||||
| { | { | ||||
| @@ -276,10 +268,10 @@ String AudioDeviceManager::initialiseFromXML (const XmlElement& xml, | |||||
| if (findType (currentDeviceType) == nullptr) | if (findType (currentDeviceType) == nullptr) | ||||
| { | { | ||||
| if (AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName)) | |||||
| if (auto* type = findType (setup.inputDeviceName, setup.outputDeviceName)) | |||||
| currentDeviceType = type->getTypeName(); | currentDeviceType = type->getTypeName(); | ||||
| else if (availableDeviceTypes.size() > 0) | |||||
| currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName(); | |||||
| else if (auto* firstType = availableDeviceTypes.getFirst()) | |||||
| currentDeviceType = firstType->getTypeName(); | |||||
| } | } | ||||
| setup.bufferSize = xml.getIntAttribute ("audioDeviceBufferSize", setup.bufferSize); | setup.bufferSize = xml.getIntAttribute ("audioDeviceBufferSize", setup.bufferSize); | ||||
| @@ -345,8 +337,8 @@ void AudioDeviceManager::scanDevicesIfNeeded() | |||||
| createDeviceTypesIfNeeded(); | createDeviceTypesIfNeeded(); | ||||
| for (int i = availableDeviceTypes.size(); --i >= 0;) | |||||
| availableDeviceTypes.getUnchecked(i)->scanForDevices(); | |||||
| for (auto* type : availableDeviceTypes) | |||||
| type->scanForDevices(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -354,29 +346,23 @@ AudioIODeviceType* AudioDeviceManager::findType (const String& typeName) | |||||
| { | { | ||||
| scanDevicesIfNeeded(); | scanDevicesIfNeeded(); | ||||
| for (int i = availableDeviceTypes.size(); --i >= 0;) | |||||
| if (availableDeviceTypes.getUnchecked(i)->getTypeName() == typeName) | |||||
| return availableDeviceTypes.getUnchecked(i); | |||||
| for (auto* type : availableDeviceTypes) | |||||
| if (type->getTypeName() == typeName) | |||||
| return type; | |||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName) | AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName) | ||||
| { | { | ||||
| scanDevicesIfNeeded(); | scanDevicesIfNeeded(); | ||||
| for (int i = availableDeviceTypes.size(); --i >= 0;) | |||||
| { | |||||
| AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i); | |||||
| for (auto* type : availableDeviceTypes) | |||||
| if ((inputName.isNotEmpty() && deviceListContains (type, true, inputName)) | if ((inputName.isNotEmpty() && deviceListContains (type, true, inputName)) | ||||
| || (outputName.isNotEmpty() && deviceListContains (type, false, outputName))) | || (outputName.isNotEmpty() && deviceListContains (type, false, outputName))) | ||||
| { | |||||
| return type; | return type; | ||||
| } | |||||
| } | |||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup) const | void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup) const | ||||
| @@ -391,8 +377,7 @@ void AudioDeviceManager::deleteCurrentDevice() | |||||
| currentSetup.outputDeviceName.clear(); | currentSetup.outputDeviceName.clear(); | ||||
| } | } | ||||
| void AudioDeviceManager::setCurrentAudioDeviceType (const String& type, | |||||
| const bool treatAsChosenDevice) | |||||
| void AudioDeviceManager::setCurrentAudioDeviceType (const String& type, bool treatAsChosenDevice) | |||||
| { | { | ||||
| for (int i = 0; i < availableDeviceTypes.size(); ++i) | for (int i = 0; i < availableDeviceTypes.size(); ++i) | ||||
| { | { | ||||
| @@ -421,15 +406,15 @@ void AudioDeviceManager::setCurrentAudioDeviceType (const String& type, | |||||
| AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const | AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const | ||||
| { | { | ||||
| for (int i = 0; i < availableDeviceTypes.size(); ++i) | |||||
| if (availableDeviceTypes.getUnchecked(i)->getTypeName() == currentDeviceType) | |||||
| return availableDeviceTypes.getUnchecked(i); | |||||
| for (auto* type : availableDeviceTypes) | |||||
| if (type->getTypeName() == currentDeviceType) | |||||
| return type; | |||||
| return availableDeviceTypes[0]; | |||||
| return availableDeviceTypes.getFirst(); | |||||
| } | } | ||||
| String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup, | String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup, | ||||
| const bool treatAsChosenDevice) | |||||
| bool treatAsChosenDevice) | |||||
| { | { | ||||
| jassert (&newSetup != ¤tSetup); // this will have no effect | jassert (&newSetup != ¤tSetup); // this will have no effect | ||||
| @@ -441,11 +426,11 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup | |||||
| stopDevice(); | stopDevice(); | ||||
| const String newInputDeviceName (numInputChansNeeded == 0 ? String() : newSetup.inputDeviceName); | |||||
| const String newOutputDeviceName (numOutputChansNeeded == 0 ? String() : newSetup.outputDeviceName); | |||||
| auto newInputDeviceName (numInputChansNeeded == 0 ? String() : newSetup.inputDeviceName); | |||||
| auto newOutputDeviceName (numOutputChansNeeded == 0 ? String() : newSetup.outputDeviceName); | |||||
| String error; | String error; | ||||
| AudioIODeviceType* type = getCurrentDeviceTypeObject(); | |||||
| auto* type = getCurrentDeviceTypeObject(); | |||||
| if (type == nullptr || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty())) | if (type == nullptr || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty())) | ||||
| { | { | ||||
| @@ -544,7 +529,7 @@ double AudioDeviceManager::chooseBestSampleRate (double rate) const | |||||
| { | { | ||||
| jassert (currentAudioDevice != nullptr); | jassert (currentAudioDevice != nullptr); | ||||
| const Array<double> rates (currentAudioDevice->getAvailableSampleRates()); | |||||
| auto rates = currentAudioDevice->getAvailableSampleRates(); | |||||
| if (rate > 0 && rates.contains (rate)) | if (rate > 0 && rates.contains (rate)) | ||||
| return rate; | return rate; | ||||
| @@ -558,7 +543,7 @@ double AudioDeviceManager::chooseBestSampleRate (double rate) const | |||||
| for (int i = rates.size(); --i >= 0;) | for (int i = rates.size(); --i >= 0;) | ||||
| { | { | ||||
| const double sr = rates[i]; | |||||
| auto sr = rates[i]; | |||||
| if (sr >= 44100.0 && (lowestAbove44 < 1.0 || sr < lowestAbove44)) | if (sr >= 44100.0 && (lowestAbove44 < 1.0 || sr < lowestAbove44)) | ||||
| lowestAbove44 = sr; | lowestAbove44 = sr; | ||||
| @@ -592,6 +577,7 @@ void AudioDeviceManager::closeAudioDevice() | |||||
| { | { | ||||
| stopDevice(); | stopDevice(); | ||||
| currentAudioDevice.reset(); | currentAudioDevice.reset(); | ||||
| cpuUsageMs = 0; | |||||
| } | } | ||||
| void AudioDeviceManager::restartLastAudioDevice() | void AudioDeviceManager::restartLastAudioDevice() | ||||
| @@ -660,6 +646,7 @@ void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback) | |||||
| { | { | ||||
| { | { | ||||
| const ScopedLock sl (audioCallbackLock); | const ScopedLock sl (audioCallbackLock); | ||||
| if (callbacks.contains (newCallback)) | if (callbacks.contains (newCallback)) | ||||
| return; | return; | ||||
| } | } | ||||