mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
AudioDeviceManager: Send changeNotification when MIDI devices change
This patch also updates the MidiDemo to automatically refresh the device lists when the set of available devices changes.
This commit is contained in:
parent
49a954d473
commit
26a872ba9f
12 changed files with 1237 additions and 509 deletions
|
|
@ -52,19 +52,27 @@
|
|||
//==============================================================================
|
||||
struct MidiDeviceListEntry : ReferenceCountedObject
|
||||
{
|
||||
MidiDeviceListEntry (MidiDeviceInfo info) : deviceInfo (info) {}
|
||||
explicit MidiDeviceListEntry (MidiDeviceInfo info) : deviceInfo (info) {}
|
||||
|
||||
MidiDeviceInfo deviceInfo;
|
||||
std::unique_ptr<MidiInput> inDevice;
|
||||
std::unique_ptr<MidiOutput> outDevice;
|
||||
|
||||
using Ptr = ReferenceCountedObjectPtr<MidiDeviceListEntry>;
|
||||
|
||||
void stopAndReset()
|
||||
{
|
||||
if (inDevice != nullptr)
|
||||
inDevice->stop();
|
||||
|
||||
inDevice .reset();
|
||||
outDevice.reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
class MidiDemo : public Component,
|
||||
private Timer,
|
||||
private MidiKeyboardState::Listener,
|
||||
private MidiInputCallback,
|
||||
private AsyncUpdater
|
||||
|
|
@ -113,12 +121,11 @@ public:
|
|||
|
||||
setSize (732, 520);
|
||||
|
||||
startTimer (500);
|
||||
updateDeviceLists();
|
||||
}
|
||||
|
||||
~MidiDemo() override
|
||||
{
|
||||
stopTimer();
|
||||
midiInputs .clear();
|
||||
midiOutputs.clear();
|
||||
keyboardState.removeListener (this);
|
||||
|
|
@ -128,12 +135,6 @@ public:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void timerCallback() override
|
||||
{
|
||||
updateDeviceList (true);
|
||||
updateDeviceList (false);
|
||||
}
|
||||
|
||||
void handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override
|
||||
{
|
||||
MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
|
||||
|
|
@ -211,17 +212,8 @@ public:
|
|||
|
||||
void closeDevice (bool isInput, int index)
|
||||
{
|
||||
if (isInput)
|
||||
{
|
||||
jassert (midiInputs[index]->inDevice.get() != nullptr);
|
||||
midiInputs[index]->inDevice->stop();
|
||||
midiInputs[index]->inDevice.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
jassert (midiOutputs[index]->outDevice.get() != nullptr);
|
||||
midiOutputs[index]->outDevice.reset();
|
||||
}
|
||||
auto& list = isInput ? midiInputs : midiOutputs;
|
||||
list[index]->stopAndReset();
|
||||
}
|
||||
|
||||
int getNumMidiInputs() const noexcept
|
||||
|
|
@ -423,7 +415,6 @@ private:
|
|||
|
||||
if (hasDeviceListChanged (availableDevices, isInputDeviceList))
|
||||
{
|
||||
|
||||
ReferenceCountedArray<MidiDeviceListEntry>& midiDevices
|
||||
= isInputDeviceList ? midiInputs : midiOutputs;
|
||||
|
||||
|
|
@ -463,6 +454,12 @@ private:
|
|||
addAndMakeVisible (label);
|
||||
}
|
||||
|
||||
void updateDeviceLists()
|
||||
{
|
||||
for (const auto isInput : { true, false })
|
||||
updateDeviceList (isInput);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Label midiInputLabel { "Midi Input Label", "MIDI Input:" };
|
||||
Label midiOutputLabel { "Midi Output Label", "MIDI Output:" };
|
||||
|
|
@ -473,12 +470,17 @@ private:
|
|||
TextEditor midiMonitor { "MIDI Monitor" };
|
||||
TextButton pairButton { "MIDI Bluetooth devices..." };
|
||||
|
||||
std::unique_ptr<MidiDeviceListBox> midiInputSelector, midiOutputSelector;
|
||||
ReferenceCountedArray<MidiDeviceListEntry> midiInputs, midiOutputs;
|
||||
std::unique_ptr<MidiDeviceListBox> midiInputSelector, midiOutputSelector;
|
||||
|
||||
CriticalSection midiMonitorLock;
|
||||
Array<MidiMessage> incomingMessages;
|
||||
|
||||
MidiDeviceListConnection connection = MidiDeviceListConnection::make ([this]
|
||||
{
|
||||
updateDeviceLists();
|
||||
});
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiDemo)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue