mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AudioDeviceManager: Fix MidiOutput dangling pointer
Changed the lifetime of the default MIDI oputput. Removed the need for Timer workaround in AudioDeviceSelectorComponent.
This commit is contained in:
parent
319da1608d
commit
2bca60e52c
3 changed files with 4 additions and 16 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue