1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-29 02:40:05 +00:00

Correctly account for midi ports in Alsa when listing/opening devices and other ALSA midi cleanups

This commit is contained in:
hogliux 2016-07-11 15:27:35 +01:00
parent 872f84dfd9
commit 76007233ae

View file

@ -50,6 +50,9 @@ public:
{
snd_seq_open (&handle, "default", forInput ? SND_SEQ_OPEN_INPUT
: SND_SEQ_OPEN_OUTPUT, 0);
snd_seq_set_client_name (handle, forInput ? JUCE_ALSA_MIDI_INPUT_NAME
: JUCE_ALSA_MIDI_OUTPUT_NAME);
}
~AlsaClient()
@ -71,11 +74,6 @@ public:
bool isInput() const noexcept { return input; }
void setName (const String& name)
{
snd_seq_set_client_name (handle, name.toUTF8());
}
void registerCallback (AlsaPortAndCallback* cb)
{
if (cb != nullptr)
@ -336,19 +334,23 @@ static AlsaPort iterateMidiClient (const AlsaClient::Ptr& seq,
&& (snd_seq_port_info_get_capability (portInfo) & (forInput ? SND_SEQ_PORT_CAP_READ
: SND_SEQ_PORT_CAP_WRITE)) != 0)
{
deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
const String clientName = snd_seq_client_info_get_name (clientInfo);
const String portName = snd_seq_port_info_get_name(portInfo);
if (clientName == portName)
deviceNamesFound.add (clientName);
else
deviceNamesFound.add (clientName + ": " + portName);
if (deviceNamesFound.size() == deviceIndexToOpen + 1)
{
const int sourcePort = snd_seq_port_info_get_port (portInfo);
const int sourceClient = snd_seq_client_info_get_client (clientInfo);
if (sourcePort != -1)
{
const String name (forInput ? JUCE_ALSA_MIDI_INPUT_NAME
: JUCE_ALSA_MIDI_OUTPUT_NAME);
seq->setName (name);
port.createPort (seq, name, forInput);
const int sourceClient = snd_seq_client_info_get_client (clientInfo);
port.createPort (seq, portName, forInput);
port.connectWith (sourceClient, sourcePort);
}
}
@ -398,19 +400,6 @@ static AlsaPort iterateMidiDevices (const bool forInput,
return port;
}
AlsaPort createMidiDevice (const bool forInput, const String& deviceNameToOpen)
{
AlsaPort port;
AlsaClient::Ptr client (new AlsaClient (forInput));
if (client->get())
{
client->setName (deviceNameToOpen + (forInput ? " Input" : " Output"));
port.createPort (client, forInput ? "in" : "out", forInput);
}
return port;
}
//==============================================================================
class MidiOutputDevice
@ -461,7 +450,7 @@ public:
numBytes -= numSent;
data += numSent;
snd_seq_ev_set_source (&event, 0);
snd_seq_ev_set_source (&event, port.portId);
snd_seq_ev_set_subs (&event);
snd_seq_ev_set_direct (&event);
@ -518,8 +507,11 @@ MidiOutput* MidiOutput::openDevice (int deviceIndex)
MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
{
MidiOutput* newDevice = nullptr;
AlsaPort port;
AlsaPort port (createMidiDevice (false, deviceName));
const AlsaClient::Ptr client (globalAlsaSequencer (false));
port.createPort (client, deviceName, false);
if (port.isValid())
{
@ -595,8 +587,11 @@ MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
{
MidiInput* newDevice = nullptr;
AlsaPort port;
AlsaPort port (createMidiDevice (true, deviceName));
const AlsaClient::Ptr client (globalAlsaSequencer (true));
port.createPort (client, deviceName, true);
if (port.isValid())
{