Browse Source

Clarified some badly-defined behaviour in AudioDeviceManager: if a midi callback is added with an empty-string as its target midi input device, it now gets sent incoming events from *all* devices, not just the "default" device (which was never properly defined)

tags/2021-05-28
jules 11 years ago
parent
commit
f57cd7bafd
3 changed files with 38 additions and 45 deletions
  1. +12
    -10
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  2. +19
    -24
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h
  3. +7
    -11
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp

+ 12
- 10
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -859,8 +859,11 @@ void AudioDeviceManager::addMidiInputCallback (const String& name, MidiInputCall
if (name.isEmpty() || isMidiInputEnabled (name))
{
const ScopedLock sl (midiCallbackLock);
midiCallbacks.add (callbackToAdd);
midiCallbackDevices.add (name);
MidiCallbackInfo mc;
mc.deviceName = name;
mc.callback = callbackToAdd;
midiCallbacks.add (mc);
}
}
@@ -868,11 +871,12 @@ void AudioDeviceManager::removeMidiInputCallback (const String& name, MidiInputC
{
for (int i = midiCallbacks.size(); --i >= 0;)
{
if (midiCallbackDevices[i] == name && midiCallbacks.getUnchecked(i) == callbackToRemove)
const MidiCallbackInfo& mc = midiCallbacks.getReference(i);
if (mc.callback == callbackToRemove && mc.deviceName == name)
{
const ScopedLock sl (midiCallbackLock);
midiCallbacks.remove (i);
midiCallbackDevices.remove (i);
}
}
}
@@ -881,16 +885,14 @@ void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source, const
{
if (! message.isActiveSense())
{
const bool isDefaultSource = (source == nullptr || source == enabledMidiInputs.getFirst());
const ScopedLock sl (midiCallbackLock);
for (int i = midiCallbackDevices.size(); --i >= 0;)
for (int i = 0; i < midiCallbacks.size(); ++i)
{
const String name (midiCallbackDevices[i]);
const MidiCallbackInfo& mc = midiCallbacks.getReference(i);
if ((isDefaultSource && name.isEmpty()) || (name.isNotEmpty() && name == source->getName()))
midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
if (mc.deviceName.isEmpty() || mc.deviceName == source->getName())
mc.callback->handleIncomingMidiMessage (source, message);
}
}
}


+ 19
- 24
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h View File

@@ -209,10 +209,9 @@ public:
//==============================================================================
/** Returns the current device properties that are in use.
@see setAudioDeviceSetup
*/
void getAudioDeviceSetup (AudioDeviceSetup& setup);
void getAudioDeviceSetup (AudioDeviceSetup& result);
/** Changes the current device or its settings.
@@ -261,9 +260,7 @@ public:
void setCurrentAudioDeviceType (const String& type,
bool treatAsChosenDevice);
/** Closes the currently-open device.
You can call restartLastAudioDevice() later to reopen it in the same state
that it was just in.
*/
@@ -305,8 +302,8 @@ public:
//==============================================================================
/** Returns the average proportion of available CPU being spent inside the audio callbacks.
Returns a value between 0 and 1.0
@returns A value between 0 and 1.0 to indicate the approximate proportion of CPU
time spent in the callbacks.
*/
double getCpuUsage() const;
@@ -333,16 +330,16 @@ public:
void setMidiInputEnabled (const String& midiInputDeviceName, bool enabled);
/** Returns true if a given midi input device is being used.
@see setMidiInputEnabled
*/
bool isMidiInputEnabled (const String& midiInputDeviceName) const;
/** Registers a listener for callbacks when midi events arrive from a midi input.
The device name can be empty to indicate that it wants events from whatever the
current "default" device is. Or it can be the name of one of the midi input devices
(see MidiInput::getDevices() for the names).
The device name can be empty to indicate that it wants to receive all incoming
events from all the enabled MIDI inputs. Or it can be the name of one of the
MIDI input devices if it just wants the events from that device. (see
MidiInput::getDevices() for the list of device names).
Only devices which are enabled (see the setMidiInputEnabled() method) will have their
events forwarded on to listeners.
@@ -350,8 +347,7 @@ public:
void addMidiInputCallback (const String& midiInputDeviceName,
MidiInputCallback* callback);
/** Removes a listener that was previously registered with addMidiInputCallback().
*/
/** Removes a listener that was previously registered with addMidiInputCallback(). */
void removeMidiInputCallback (const String& midiInputDeviceName,
MidiInputCallback* callback);
@@ -371,22 +367,17 @@ public:
void setDefaultMidiOutput (const String& deviceName);
/** Returns the name of the default midi output.
@see setDefaultMidiOutput, getDefaultMidiOutput
*/
String getDefaultMidiOutputName() const { return defaultMidiOutputName; }
const String& getDefaultMidiOutputName() const noexcept { return defaultMidiOutputName; }
/** Returns the current default midi output device.
If no device has been selected, or the device can't be opened, this will
return 0.
If no device has been selected, or the device can't be opened, this will return nullptr.
@see getDefaultMidiOutputName
*/
MidiOutput* getDefaultMidiOutput() const noexcept { return defaultMidiOutput; }
/** Returns a list of the types of device supported.
*/
/** Returns a list of the types of device supported. */
const OwnedArray<AudioIODeviceType>& getAvailableDeviceTypes();
//==============================================================================
@@ -429,9 +420,7 @@ public:
void enableInputLevelMeasurement (bool enableMeasurement);
/** Returns the current input level.
To use this, you must first enable it by calling enableInputLevelMeasurement().
See enableInputLevelMeasurement() for more info.
*/
double getCurrentInputLevel() const;
@@ -468,10 +457,16 @@ private:
int testSoundPosition;
AudioSampleBuffer tempBuffer;
struct MidiCallbackInfo
{
String deviceName;
MidiInputCallback* callback;
};
StringArray midiInsFromXml;
OwnedArray<MidiInput> enabledMidiInputs;
Array<MidiInputCallback*> midiCallbacks;
StringArray midiCallbackDevices;
Array<MidiCallbackInfo> midiCallbacks;
String defaultMidiOutputName;
ScopedPointer<MidiOutput> defaultMidiOutput;
CriticalSection audioCallbackLock, midiCallbackLock;


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

@@ -75,11 +75,10 @@ class AudioDeviceSelectorComponent::MidiInputSelectorComponentListBox : public
private ListBoxModel
{
public:
MidiInputSelectorComponentListBox (AudioDeviceManager& dm,
const String& noItemsMessage_)
MidiInputSelectorComponentListBox (AudioDeviceManager& dm, const String& noItems)
: ListBox (String::empty, nullptr),
deviceManager (dm),
noItemsMessage (noItemsMessage_)
noItemsMessage (noItems)
{
items = MidiInput::getDevices();
@@ -87,15 +86,12 @@ public:
setOutlineThickness (1);
}
int getNumRows()
int getNumRows() override
{
return items.size();
}
void paintListBoxItem (int row,
Graphics& g,
int width, int height,
bool rowIsSelected)
void paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected) override
{
if (isPositiveAndBelow (row, items.size()))
{
@@ -118,7 +114,7 @@ public:
}
}
void listBoxItemClicked (int row, const MouseEvent& e)
void listBoxItemClicked (int row, const MouseEvent& e) override
{
selectRow (row);
@@ -126,12 +122,12 @@ public:
flipEnablement (row);
}
void listBoxItemDoubleClicked (int row, const MouseEvent&)
void listBoxItemDoubleClicked (int row, const MouseEvent&) override
{
flipEnablement (row);
}
void returnKeyPressed (int row)
void returnKeyPressed (int row) override
{
flipEnablement (row);
}


Loading…
Cancel
Save