Browse Source

Add getName to MidiOutput devices

tags/2021-05-28
hogliux 9 years ago
parent
commit
c89f476127
5 changed files with 20 additions and 10 deletions
  1. +3
    -2
      modules/juce_audio_devices/midi_io/juce_MidiOutput.cpp
  2. +5
    -1
      modules/juce_audio_devices/midi_io/juce_MidiOutput.h
  3. +2
    -2
      modules/juce_audio_devices/native/juce_linux_Midi.cpp
  4. +3
    -2
      modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp
  5. +7
    -3
      modules/juce_audio_devices/native/juce_win32_Midi.cpp

+ 3
- 2
modules/juce_audio_devices/midi_io/juce_MidiOutput.cpp View File

@@ -32,10 +32,11 @@ struct MidiOutput::PendingMessage
PendingMessage* next; PendingMessage* next;
}; };
MidiOutput::MidiOutput()
MidiOutput::MidiOutput(const String& midiName)
: Thread ("midi out"), : Thread ("midi out"),
internal (nullptr), internal (nullptr),
firstMessage (nullptr)
firstMessage (nullptr),
name (midiName)
{ {
} }


+ 5
- 1
modules/juce_audio_devices/midi_io/juce_MidiOutput.h View File

@@ -84,6 +84,9 @@ public:
/** Destructor. */ /** Destructor. */
~MidiOutput(); ~MidiOutput();
/** Returns the name of this device. */
const String& getName() const noexcept { return name; }
/** Makes this device output a midi message. /** Makes this device output a midi message.
@see MidiMessage @see MidiMessage
*/ */
@@ -131,8 +134,9 @@ private:
CriticalSection lock; CriticalSection lock;
struct PendingMessage; struct PendingMessage;
PendingMessage* firstMessage; PendingMessage* firstMessage;
String name;
MidiOutput(); // These objects are created with the openDevice() method.
MidiOutput(const String& midiName); // These objects are created with the openDevice() method.
void run() override; void run() override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutput)


+ 2
- 2
modules/juce_audio_devices/native/juce_linux_Midi.cpp View File

@@ -497,7 +497,7 @@ MidiOutput* MidiOutput::openDevice (int deviceIndex)
if (port.isValid()) if (port.isValid())
{ {
newDevice = new MidiOutput();
newDevice = new MidiOutput (devices [deviceIndex]);
newDevice->internal = new MidiOutputDevice (newDevice, port); newDevice->internal = new MidiOutputDevice (newDevice, port);
} }
@@ -512,7 +512,7 @@ MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
if (port.isValid()) if (port.isValid())
{ {
newDevice = new MidiOutput();
newDevice = new MidiOutput (deviceName);
newDevice->internal = new MidiOutputDevice (newDevice, port); newDevice->internal = new MidiOutputDevice (newDevice, port);
} }


+ 3
- 2
modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp View File

@@ -332,10 +332,11 @@ MidiOutput* MidiOutput::openDevice (int index)
{ {
MIDIClientRef client = CoreMidiHelpers::getGlobalMidiClient(); MIDIClientRef client = CoreMidiHelpers::getGlobalMidiClient();
MIDIPortRef port; MIDIPortRef port;
String deviceName = CoreMidiHelpers::getConnectedEndpointName (endPoint);
if (client != 0 && CHECK_ERROR (MIDIOutputPortCreate (client, pname.cfString, &port))) if (client != 0 && CHECK_ERROR (MIDIOutputPortCreate (client, pname.cfString, &port)))
{ {
mo = new MidiOutput();
mo = new MidiOutput (deviceName);
mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (port, endPoint); mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (port, endPoint);
} }
} }
@@ -354,7 +355,7 @@ MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
if (client != 0 && CHECK_ERROR (MIDISourceCreate (client, name.cfString, &endPoint))) if (client != 0 && CHECK_ERROR (MIDISourceCreate (client, name.cfString, &endPoint)))
{ {
MidiOutput* mo = new MidiOutput();
MidiOutput* mo = new MidiOutput (deviceName);
mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (0, endPoint); mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (0, endPoint);
return mo; return mo;
} }


+ 7
- 3
modules/juce_audio_devices/native/juce_win32_Midi.cpp View File

@@ -362,6 +362,7 @@ MidiOutput* MidiOutput::openDevice (int index)
UINT deviceId = MIDI_MAPPER; UINT deviceId = MIDI_MAPPER;
const UINT num = midiOutGetNumDevs(); const UINT num = midiOutGetNumDevs();
int n = 0; int n = 0;
String deviceName;
for (UINT i = 0; i < num; ++i) for (UINT i = 0; i < num; ++i)
{ {
@@ -369,13 +370,16 @@ MidiOutput* MidiOutput::openDevice (int index)
if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR) if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
{ {
String name = String (mc.szPname, sizeof (mc.szPname));
// use the microsoft sw synth as a default - best not to allow deviceId // use the microsoft sw synth as a default - best not to allow deviceId
// to be MIDI_MAPPER, or else device sharing breaks // to be MIDI_MAPPER, or else device sharing breaks
if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
if (name.containsIgnoreCase ("microsoft"))
deviceId = i; deviceId = i;
if (index == n) if (index == n)
{ {
deviceName = name;
deviceId = i; deviceId = i;
break; break;
} }
@@ -392,7 +396,7 @@ MidiOutput* MidiOutput::openDevice (int index)
{ {
han->refCount++; han->refCount++;
MidiOutput* const out = new MidiOutput();
MidiOutput* const out = new MidiOutput (deviceName);
out->internal = han; out->internal = han;
return out; return out;
} }
@@ -411,7 +415,7 @@ MidiOutput* MidiOutput::openDevice (int index)
han->handle = h; han->handle = h;
MidiOutHandle::activeHandles.add (han); MidiOutHandle::activeHandles.add (han);
MidiOutput* const out = new MidiOutput();
MidiOutput* const out = new MidiOutput (deviceName);
out->internal = han; out->internal = han;
return out; return out;
} }


Loading…
Cancel
Save