Browse Source

AudioDeviceManager: Fix MidiOutput dangling pointer

Changed the lifetime of the default MIDI oputput.
Removed the need for Timer workaround in AudioDeviceSelectorComponent.
pull/22/head
Oli Tom Poole 3 years ago
parent
commit
2bca60e52c
3 changed files with 4 additions and 16 deletions
  1. +3
    -2
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  2. +0
    -11
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp
  3. +1
    -3
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.h

+ 3
- 2
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -1088,6 +1088,7 @@ void AudioDeviceManager::setDefaultMidiOutputDevice (const String& identifier)
{
if (defaultMidiOutputDeviceInfo.identifier != identifier)
{
std::unique_ptr<MidiOutput> oldMidiPort;
Array<AudioIODeviceCallback*> oldCallbacks;
{
@@ -1099,7 +1100,7 @@ void AudioDeviceManager::setDefaultMidiOutputDevice (const String& identifier)
for (int i = oldCallbacks.size(); --i >= 0;)
oldCallbacks.getUnchecked (i)->audioDeviceStopped();
defaultMidiOutput.reset();
std::swap (oldMidiPort, defaultMidiOutput);
if (identifier.isNotEmpty())
defaultMidiOutput = MidiOutput::openDevice (identifier);
@@ -1119,7 +1120,7 @@ void AudioDeviceManager::setDefaultMidiOutputDevice (const String& identifier)
}
updateXml();
sendChangeMessage();
sendSynchronousChangeMessage();
}
}


+ 0
- 11
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp View File

@@ -1044,7 +1044,6 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager&
deviceManager.addChangeListener (this);
updateAllControls();
startTimer (1000);
}
AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
@@ -1098,16 +1097,6 @@ void AudioDeviceSelectorComponent::resized()
setSize (getWidth(), r.getY());
}
void AudioDeviceSelectorComponent::timerCallback()
{
// TODO
// unfortunately, the AudioDeviceManager only gives us changeListenerCallbacks
// if an audio device has changed, but not if a MIDI device has changed.
// This needs to be implemented properly. Until then, we use a workaround
// where we update the whole component once per second on a timer callback.
updateAllControls();
}
void AudioDeviceSelectorComponent::updateDeviceType()
{
if (auto* type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1])


+ 1
- 3
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.h View File

@@ -31,8 +31,7 @@ namespace juce
@tags{Audio}
*/
class JUCE_API AudioDeviceSelectorComponent : public Component,
private ChangeListener,
private Timer
private ChangeListener
{
public:
//==============================================================================
@@ -85,7 +84,6 @@ public:
private:
//==============================================================================
void timerCallback() override;
void handleBluetoothButton();
void updateDeviceType();
void updateMidiOutput();


Loading…
Cancel
Save