Changed the lifetime of the default MIDI oputput. Removed the need for Timer workaround in AudioDeviceSelectorComponent.pull/22/head
| @@ -1088,6 +1088,7 @@ void AudioDeviceManager::setDefaultMidiOutputDevice (const String& identifier) | |||||
| { | { | ||||
| if (defaultMidiOutputDeviceInfo.identifier != identifier) | if (defaultMidiOutputDeviceInfo.identifier != identifier) | ||||
| { | { | ||||
| std::unique_ptr<MidiOutput> oldMidiPort; | |||||
| Array<AudioIODeviceCallback*> oldCallbacks; | Array<AudioIODeviceCallback*> oldCallbacks; | ||||
| { | { | ||||
| @@ -1099,7 +1100,7 @@ void AudioDeviceManager::setDefaultMidiOutputDevice (const String& identifier) | |||||
| for (int i = oldCallbacks.size(); --i >= 0;) | for (int i = oldCallbacks.size(); --i >= 0;) | ||||
| oldCallbacks.getUnchecked (i)->audioDeviceStopped(); | oldCallbacks.getUnchecked (i)->audioDeviceStopped(); | ||||
| defaultMidiOutput.reset(); | |||||
| std::swap (oldMidiPort, defaultMidiOutput); | |||||
| if (identifier.isNotEmpty()) | if (identifier.isNotEmpty()) | ||||
| defaultMidiOutput = MidiOutput::openDevice (identifier); | defaultMidiOutput = MidiOutput::openDevice (identifier); | ||||
| @@ -1119,7 +1120,7 @@ void AudioDeviceManager::setDefaultMidiOutputDevice (const String& identifier) | |||||
| } | } | ||||
| updateXml(); | updateXml(); | ||||
| sendChangeMessage(); | |||||
| sendSynchronousChangeMessage(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1044,7 +1044,6 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& | |||||
| deviceManager.addChangeListener (this); | deviceManager.addChangeListener (this); | ||||
| updateAllControls(); | updateAllControls(); | ||||
| startTimer (1000); | |||||
| } | } | ||||
| AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent() | AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent() | ||||
| @@ -1098,16 +1097,6 @@ void AudioDeviceSelectorComponent::resized() | |||||
| setSize (getWidth(), r.getY()); | 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() | void AudioDeviceSelectorComponent::updateDeviceType() | ||||
| { | { | ||||
| if (auto* type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1]) | if (auto* type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1]) | ||||
| @@ -31,8 +31,7 @@ namespace juce | |||||
| @tags{Audio} | @tags{Audio} | ||||
| */ | */ | ||||
| class JUCE_API AudioDeviceSelectorComponent : public Component, | class JUCE_API AudioDeviceSelectorComponent : public Component, | ||||
| private ChangeListener, | |||||
| private Timer | |||||
| private ChangeListener | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -85,7 +84,6 @@ public: | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| void timerCallback() override; | |||||
| void handleBluetoothButton(); | void handleBluetoothButton(); | ||||
| void updateDeviceType(); | void updateDeviceType(); | ||||
| void updateMidiOutput(); | void updateMidiOutput(); | ||||