diff --git a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp index a08cbe7611..5f4ea10796 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp @@ -1366,21 +1366,7 @@ public: } } - void stop() override - { - AudioIODeviceCallback* lastCallback = nullptr; - - { - const ScopedLock sl (callbackLock); - std::swap (callback, lastCallback); - } - - for (int i = 0; i < devices.size(); ++i) - devices.getUnchecked(i)->device->stop(); - - if (lastCallback != nullptr) - lastCallback->audioDeviceStopped(); - } + void stop() override { shutdown ({}); } String getLastError() override { @@ -1456,6 +1442,27 @@ private: } } + void shutdown (const String& error) + { + AudioIODeviceCallback* lastCallback = nullptr; + + { + const ScopedLock sl (callbackLock); + std::swap (callback, lastCallback); + } + + for (int i = 0; i < devices.size(); ++i) + devices.getUnchecked(i)->device->stop(); + + if (lastCallback != nullptr) + { + if (error.isNotEmpty()) + lastCallback->audioDeviceError (error); + else + lastCallback->audioDeviceStopped(); + } + } + void reset() { for (int i = 0; i < devices.size(); ++i) @@ -1584,21 +1591,8 @@ private: callback->audioDeviceAboutToStart (device); } - void handleAudioDeviceStopped() - { - const ScopedLock sl (callbackLock); - - if (callback != nullptr) - callback->audioDeviceStopped(); - } - - void handleAudioDeviceError (const String& errorMessage) - { - const ScopedLock sl (callbackLock); - - if (callback != nullptr) - callback->audioDeviceError (errorMessage); - } + void handleAudioDeviceStopped() { shutdown ({}); } + void handleAudioDeviceError (const String& errorMessage) { shutdown (errorMessage.isNotEmpty() ? errorMessage : String ("unknown")); } //============================================================================== struct DeviceWrapper : private AudioIODeviceCallback