25 |
|
|
26 |
namespace LinuxSampler { |
namespace LinuxSampler { |
27 |
|
|
28 |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa); |
REGISTER_MIDI_INPUT_DRIVER(MidiInputDeviceAlsa); |
29 |
|
|
30 |
/* Common parameters */ |
/* Common parameters */ |
31 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterActive); |
32 |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
REGISTER_MIDI_INPUT_DRIVER_PARAMETER(MidiInputDeviceAlsa, ParameterPorts); |
33 |
|
|
|
MidiInputDeviceAlsa::MidiInputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : MidiInputDevice(Parameters), Thread(true, 1, -1) { |
|
|
if (snd_seq_open(&hAlsaSeq, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { |
|
|
throw MidiInputException("Error opening ALSA sequencer"); |
|
|
} |
|
|
this->hAlsaSeqClient = snd_seq_client_id(hAlsaSeq); |
|
|
snd_seq_set_client_name(hAlsaSeq, "LinuxSampler"); |
|
|
AcquirePorts(((DeviceCreationParameterInt*)Parameters["ports"])->ValueAsInt()); |
|
|
if (((DeviceCreationParameterBool*)Parameters["active"])->ValueAsBool()) { |
|
|
Listen(); |
|
|
} |
|
|
} |
|
34 |
|
|
35 |
MidiInputDeviceAlsa::~MidiInputDeviceAlsa() { |
|
36 |
snd_seq_close(hAlsaSeq); |
// *************** ParameterName *************** |
37 |
|
// * |
38 |
|
|
39 |
|
MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterName::ParameterName(MidiInputPort* pPort) throw (LinuxSamplerException) : MidiInputPort::ParameterName(pPort, "Port " + ToString(pPort->GetPortNumber())) { |
40 |
|
OnSetValue(ValueAsString()); // initialize port name |
41 |
} |
} |
42 |
|
|
43 |
MidiInputDeviceAlsa::MidiInputPortAlsa::MidiInputPortAlsa(MidiInputDeviceAlsa* pDevice, int alsaPort) : MidiInputPort(pDevice, alsaPort) { |
void MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) { |
44 |
Parameters["alsa_seq_bindings"] = new ParameterAlsaSeqBindings(this); |
if (s.size() > 16) throw LinuxSamplerException("Name too long for ALSA MIDI input port (max. 16 characters)"); |
45 |
this->pDevice = pDevice; |
snd_seq_port_info_t* hInfo; |
46 |
|
snd_seq_port_info_malloc(&hInfo); |
47 |
|
snd_seq_get_port_info(((MidiInputDeviceAlsa*)pPort->GetDevice())->hAlsaSeq, pPort->GetPortNumber(), hInfo); |
48 |
|
snd_seq_port_info_set_name(hInfo, s.c_str()); |
49 |
|
snd_seq_set_port_info(((MidiInputDeviceAlsa*)pPort->GetDevice())->hAlsaSeq, pPort->GetPortNumber(), hInfo); |
50 |
|
snd_seq_port_info_free(hInfo); |
51 |
} |
} |
52 |
|
|
53 |
MidiInputDeviceAlsa::MidiInputPortAlsa::~MidiInputPortAlsa() { |
|
54 |
snd_seq_delete_simple_port(pDevice->hAlsaSeq, portNumber); |
|
55 |
|
// *************** ParameterAlsaSeqBindings *************** |
56 |
|
// * |
57 |
|
|
58 |
|
|
59 |
|
MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterAlsaSeqBindings::ParameterAlsaSeqBindings(MidiInputPortAlsa* pPort) : DeviceRuntimeParameterStrings( std::vector<String>() ) { |
60 |
|
this->pPort = pPort; |
61 |
} |
} |
62 |
|
|
63 |
MidiInputDeviceAlsa::MidiInputPortAlsa* MidiInputDeviceAlsa::CreateMidiPort() { |
String MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterAlsaSeqBindings::Description() { |
64 |
int alsaPort; |
return "Bindings to other Alsa sequencer clients"; |
65 |
if ((alsaPort = snd_seq_create_simple_port(hAlsaSeq, "LinuxSampler", |
} |
66 |
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, |
bool MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterAlsaSeqBindings::Fix() { |
67 |
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { |
return false; |
|
throw MidiInputException("Error creating sequencer port"); |
|
|
} |
|
|
return ( new MidiInputPortAlsa(this, alsaPort) ); |
|
68 |
} |
} |
69 |
|
|
70 |
String MidiInputDeviceAlsa::Name() { |
std::vector<String> MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterAlsaSeqBindings::PossibilitiesAsString() { |
71 |
return "Alsa"; |
return std::vector<String>(); //TODO |
72 |
} |
} |
73 |
|
|
74 |
String MidiInputDeviceAlsa::Driver() { |
void MidiInputDeviceAlsa::MidiInputPortAlsa::ParameterAlsaSeqBindings::OnSetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
75 |
return Name(); |
std::vector<String>::iterator iter = vS.begin(); |
76 |
|
for (; iter != vS.end(); iter++) pPort->ConnectToAlsaMidiSource((*iter).c_str()); |
77 |
} |
} |
78 |
|
|
79 |
void MidiInputDeviceAlsa::Listen() { |
|
80 |
StartThread(); |
|
81 |
|
// *************** MidiInputPortAlsa *************** |
82 |
|
// * |
83 |
|
|
84 |
|
MidiInputDeviceAlsa::MidiInputPortAlsa::MidiInputPortAlsa(MidiInputDeviceAlsa* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) { |
85 |
|
this->pDevice = pDevice; |
86 |
|
|
87 |
|
// create Alsa sequencer port |
88 |
|
int alsaPort = snd_seq_create_simple_port(pDevice->hAlsaSeq, "unnamed port", |
89 |
|
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, |
90 |
|
SND_SEQ_PORT_TYPE_APPLICATION); |
91 |
|
if (alsaPort < 0) throw MidiInputException("Error creating sequencer port"); |
92 |
|
this->portNumber = alsaPort; |
93 |
|
|
94 |
|
Parameters["NAME"] = new ParameterName(this); |
95 |
|
Parameters["ALSA_SEQ_BINDINGS"] = new ParameterAlsaSeqBindings(this); |
96 |
} |
} |
97 |
|
|
98 |
void MidiInputDeviceAlsa::StopListen() { |
MidiInputDeviceAlsa::MidiInputPortAlsa::~MidiInputPortAlsa() { |
99 |
StopThread(); |
snd_seq_delete_simple_port(pDevice->hAlsaSeq, portNumber); |
100 |
} |
} |
101 |
|
|
102 |
/** |
/** |
103 |
* Connects this Alsa midi input device with an Alsa MIDI source. |
* Connects this Alsa midi input device with an Alsa MIDI source. |
104 |
* |
* |
105 |
* @param Client - Alsa sequencer client and port ID of a MIDI source |
* @param Client - Alsa sequencer client and port ID of a MIDI source |
106 |
* (e.g. "64:0") |
* (e.g. "64:0") |
107 |
* @throws MidiInputException if connection cannot be established |
* @throws MidiInputException if connection cannot be established |
108 |
*/ |
*/ |
109 |
void MidiInputDeviceAlsa::MidiInputPortAlsa::ConnectToAlsaMidiSource(const char* MidiSource) { |
void MidiInputDeviceAlsa::MidiInputPortAlsa::ConnectToAlsaMidiSource(const char* MidiSource) { |
110 |
snd_seq_addr_t sender, dest; |
snd_seq_addr_t sender, dest; |
111 |
snd_seq_port_subscribe_t* subs; |
snd_seq_port_subscribe_t* subs; |
126 |
throw MidiInputException(String("Unable to connect to Alsa seq client \'") + MidiSource + "\' (" + snd_strerror(errno) + ")"); |
throw MidiInputException(String("Unable to connect to Alsa seq client \'") + MidiSource + "\' (" + snd_strerror(errno) + ")"); |
127 |
} |
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
// *************** MidiInputDeviceAlsa *************** |
132 |
|
// * |
133 |
|
|
134 |
|
MidiInputDeviceAlsa::MidiInputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : MidiInputDevice(Parameters), Thread(true, 1, -1) { |
135 |
|
if (snd_seq_open(&hAlsaSeq, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { |
136 |
|
throw MidiInputException("Error opening ALSA sequencer"); |
137 |
|
} |
138 |
|
this->hAlsaSeqClient = snd_seq_client_id(hAlsaSeq); |
139 |
|
snd_seq_set_client_name(hAlsaSeq, "LinuxSampler"); |
140 |
|
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
141 |
|
if (((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) { |
142 |
|
Listen(); |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
MidiInputDeviceAlsa::~MidiInputDeviceAlsa() { |
147 |
|
snd_seq_close(hAlsaSeq); |
148 |
|
} |
149 |
|
|
150 |
|
MidiInputDeviceAlsa::MidiInputPortAlsa* MidiInputDeviceAlsa::CreateMidiPort() { |
151 |
|
return new MidiInputPortAlsa(this); |
152 |
|
} |
153 |
|
|
154 |
|
String MidiInputDeviceAlsa::Name() { |
155 |
|
return "ALSA"; |
156 |
|
} |
157 |
|
|
158 |
|
String MidiInputDeviceAlsa::Driver() { |
159 |
|
return Name(); |
160 |
|
} |
161 |
|
|
162 |
|
void MidiInputDeviceAlsa::Listen() { |
163 |
|
StartThread(); |
164 |
|
} |
165 |
|
|
166 |
|
void MidiInputDeviceAlsa::StopListen() { |
167 |
|
StopThread(); |
168 |
|
} |
169 |
|
|
170 |
String MidiInputDeviceAlsa::Description() { |
String MidiInputDeviceAlsa::Description() { |
171 |
return "Advanced Linux Sound Architecture"; |
return "Advanced Linux Sound Architecture"; |
172 |
} |
} |
173 |
|
|
174 |
String MidiInputDeviceAlsa::Version() { |
String MidiInputDeviceAlsa::Version() { |
175 |
String s = "$Revision: 1.8 $"; |
String s = "$Revision: 1.9 $"; |
176 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
177 |
} |
} |
178 |
|
|
188 |
if (poll(pfd, npfd, 100000) > 0) { |
if (poll(pfd, npfd, 100000) > 0) { |
189 |
do { |
do { |
190 |
snd_seq_event_input(hAlsaSeq, &ev); |
snd_seq_event_input(hAlsaSeq, &ev); |
191 |
int port = (int) ev->dest.port; |
int port = (int) ev->dest.port; |
192 |
MidiInputPort* pMidiInputPort = Ports[port]; |
MidiInputPort* pMidiInputPort = Ports[port]; |
193 |
|
|
194 |
switch (ev->type) { |
switch (ev->type) { |
195 |
case SND_SEQ_EVENT_CONTROLLER: |
case SND_SEQ_EVENT_CONTROLLER: |