1 |
// example_server.c |
// example_server.c |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
liblscp - LinuxSampler Control Protocol API |
5 |
|
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
18 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
39 |
lscp_parser_t tok; |
lscp_parser_t tok; |
40 |
const char *pszResult = NULL; |
const char *pszResult = NULL; |
41 |
char szTemp[256]; |
char szTemp[256]; |
42 |
static int iChannel = 0; |
int i; |
43 |
|
static int iSamplerChannel = 0; |
44 |
|
static int iAudioDevice = 0; |
45 |
|
static int iMidiDevice = 0; |
46 |
|
|
47 |
if (pchBuffer == NULL) { |
if (pchBuffer == NULL) { |
48 |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
71 |
pszResult = "ENGINE_NAME: DummyEngine\r\n" |
pszResult = "ENGINE_NAME: DummyEngine\r\n" |
72 |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
73 |
"INSTRUMENT_NR: 0\r\n" |
"INSTRUMENT_NR: 0\r\n" |
74 |
|
"INSTRUMENT_NAME: Dummy Instrument\r\n" |
75 |
|
"INSTRUMENT_STATUS: 100\r\n" |
76 |
"AUDIO_OUTPUT_DEVICE: 0\r\n" |
"AUDIO_OUTPUT_DEVICE: 0\r\n" |
77 |
"AUDIO_OUTPUT_CHANNELS: 2\r\n" |
"AUDIO_OUTPUT_CHANNELS: 2\r\n" |
78 |
"AUDIO_OUTPUT_ROUTING: 0,1\r\n" |
"AUDIO_OUTPUT_ROUTING: 0,1\r\n" |
79 |
"MIDI_INPUT_DEVICE: 0\r\n" |
"MIDI_INPUT_DEVICE: 0\r\n" |
80 |
"MIDI_INPUT_PORT: 0\r\n" |
"MIDI_INPUT_PORT: 0\r\n" |
81 |
"MIDI_INPUT_CHANNEL: ALL\r\n" |
"MIDI_INPUT_CHANNEL: ALL\r\n" |
82 |
"VOLUME: 0.5\r\n"; |
"VOLUME: 0.5\r\n" |
83 |
|
"MUTE: FALSE\r\n" |
84 |
|
"SOLO: TRUE\r\n"; |
85 |
} |
} |
86 |
else if (lscp_parser_test(&tok, "VOICE_COUNT")) { |
else if (lscp_parser_test(&tok, "VOICE_COUNT")) { |
87 |
// Current number of active voices: |
// Current number of active voices: |
109 |
} |
} |
110 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
111 |
} |
} |
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_TYPE")) { |
|
|
// Getting audio output type: |
|
|
// GET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> |
|
|
// (unspecified as of draft 04) |
|
|
} |
|
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_CHANNEL")) { |
|
|
// Getting audio output channel: |
|
|
// GET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> |
|
|
// (unspecified as of draft 04) |
|
|
} |
|
112 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
113 |
} |
} |
114 |
else if (lscp_parser_test(&tok, "CHANNELS")) { |
else if (lscp_parser_test(&tok, "CHANNELS")) { |
115 |
// Current number of sampler channels: |
// Current number of sampler channels: |
116 |
// GET CHANNELS |
// GET CHANNELS |
117 |
sprintf(szTemp, "%d", iChannel); |
sprintf(szTemp, "%d", iSamplerChannel); |
118 |
pszResult = szTemp; |
pszResult = szTemp; |
119 |
} |
} |
120 |
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
121 |
// Getting all available audio output drivers. |
// Getting all available audio output driver count. |
122 |
// GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
// GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
123 |
pszResult = "ALSA,JACK\r\n"; |
pszResult = "2\r\n"; |
124 |
} |
} |
125 |
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
126 |
// Getting all available MIDI input drivers. |
// Getting all available MIDI input driver count. |
127 |
// GET AVAILABLE_MIDI_INPUT_DRIVERS |
// GET AVAILABLE_MIDI_INPUT_DRIVERS |
128 |
pszResult = "ALSA\r\n"; |
pszResult = "1\r\n"; |
129 |
} |
} |
130 |
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER", "INFO")) { |
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER", "INFO")) { |
131 |
// Getting informations about a specific audio output driver. |
// Getting informations about a specific audio output driver. |
132 |
// GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
// GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
133 |
if (lscp_parser_test(&tok, "ALSA")) { |
if (lscp_parser_test(&tok, "Alsa")) { |
134 |
pszResult = "DESCRIPTION: 'ALSA PCM'\r\n" |
pszResult = "DESCRIPTION: 'ALSA PCM'\r\n" |
135 |
"VERSION: '1.0'\r\n" |
"VERSION: '1.0'\r\n" |
136 |
"PARAMETERS: CHANNELS,SAMPLERATE,ACTIVE,CARD\r\n"; |
"PARAMETERS: channels,samplerate,active\r\n"; |
137 |
} |
} |
138 |
else if (lscp_parser_test(&tok, "JACK")) { |
else if (lscp_parser_test(&tok, "Jack")) { |
139 |
pszResult = "DESCRIPTION: Jack Audio Connection Kit\r\n" |
pszResult = "DESCRIPTION: JACK Audio Connection Kit\r\n" |
140 |
"VERSION: 0.98.1\r\n" |
"VERSION: 0.98.1\r\n" |
141 |
"PARAMETERS: CHANNELS,SAMPLERATE,ACTIVE\r\n"; |
"PARAMETERS: channels,samplerate,active\r\n"; |
142 |
} |
} |
143 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
144 |
} |
} |
145 |
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DRIVER", "INFO")) { |
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DRIVER", "INFO")) { |
146 |
// Getting informations about a specific MIDI input driver. |
// Getting informations about a specific MIDI input driver. |
147 |
// GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
// GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
148 |
if (lscp_parser_test(&tok, "ALSA")) { |
if (lscp_parser_test(&tok, "Alsa")) { |
149 |
pszResult = "DESCRIPTION: ALSA Sequencer\r\n" |
pszResult = "DESCRIPTION: ALSA Sequencer\r\n" |
150 |
"VERSION: 1.0\r\n" |
"VERSION: 1.0\r\n" |
151 |
"PARAMETERS: PORTS,ACTIVE\r\n"; |
"PARAMETERS: ports,active\r\n"; |
152 |
|
} |
153 |
|
else ret = LSCP_FAILED; |
154 |
|
} |
155 |
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER_PARAMETER", "INFO")) { |
156 |
|
// Getting informations about a specific audio output driver parameter. |
157 |
|
// GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-type> <param> |
158 |
|
if (lscp_parser_test(&tok, "Alsa")) { |
159 |
|
if (lscp_parser_test(&tok, "active")) { |
160 |
|
pszResult = "DESCRIPTION: 'ALSA PCM active state'\r\n" |
161 |
|
"TYPE: BOOL\r\n" |
162 |
|
"MANDATORY: TRUE\r\n" |
163 |
|
"FIX: TRUE\r\n" |
164 |
|
"MULTIPLICITY: FALSE\r\n" |
165 |
|
"DEPENDS: channels,samplerate,card\r\n" |
166 |
|
"DEFAULT: TRUE\r\n" |
167 |
|
"RANGE_MIN: FALSE\r\n" |
168 |
|
"RANGE_MAX: TRUE\r\n" |
169 |
|
"POSSIBILITIES: FALSE,TRUE\r\n"; |
170 |
|
} |
171 |
|
else if (lscp_parser_test(&tok, "channels")) { |
172 |
|
pszResult = "DESCRIPTION: 'Number of ALSA PCM channels'\r\n" |
173 |
|
"TYPE: INT\r\n" |
174 |
|
"MANDATORY: TRUE\r\n" |
175 |
|
"FIX: TRUE\r\n" |
176 |
|
"MULTIPLICITY: FALSE\r\n" |
177 |
|
"DEFAULT: 2\r\n"; |
178 |
|
} |
179 |
|
else if (lscp_parser_test(&tok, "samplerate")) { |
180 |
|
pszResult = "DESCRIPTION: 'ALSA PCM sample rate'\r\n" |
181 |
|
"TYPE: INT\r\n" |
182 |
|
"MANDATORY: TRUE\r\n" |
183 |
|
"FIX: TRUE\r\n" |
184 |
|
"MULTIPLICITY: TRUE\r\n" |
185 |
|
"DEFAULT: 44100\r\n" |
186 |
|
"POSSIBILITIES: 44100,48000,96000\r\n"; |
187 |
|
} |
188 |
|
else ret = LSCP_FAILED; |
189 |
|
} |
190 |
|
else if (lscp_parser_test(&tok, "Jack")) { |
191 |
|
if (lscp_parser_test(&tok, "active")) { |
192 |
|
pszResult = "DESCRIPTION: 'JACK active state'\r\n" |
193 |
|
"TYPE: BOOL\r\n" |
194 |
|
"MANDATORY: TRUE\r\n" |
195 |
|
"FIX: TRUE\r\n" |
196 |
|
"MULTIPLICITY: FALSE\r\n" |
197 |
|
"DEPENDS: channels,samplerate\r\n" |
198 |
|
"DEFAULT: TRUE\r\n" |
199 |
|
"RANGE_MIN: FALSE\r\n" |
200 |
|
"RANGE_MAX: TRUE\r\n" |
201 |
|
"POSSIBILITIES: FALSE,TRUE\r\n"; |
202 |
|
} |
203 |
|
else if (lscp_parser_test(&tok, "channels")) { |
204 |
|
pszResult = "DESCRIPTION: 'Number of JACK audio channels'\r\n" |
205 |
|
"TYPE: INT\r\n" |
206 |
|
"MANDATORY: TRUE\r\n" |
207 |
|
"FIX: TRUE\r\n" |
208 |
|
"MULTIPLICITY: FALSE\r\n" |
209 |
|
"DEFAULT: 2\r\n"; |
210 |
|
} |
211 |
|
else if (lscp_parser_test(&tok, "samplerate")) { |
212 |
|
pszResult = "DESCRIPTION: 'JACK sample rate'\r\n" |
213 |
|
"TYPE: INT\r\n" |
214 |
|
"MANDATORY: TRUE\r\n" |
215 |
|
"FIX: TRUE\r\n" |
216 |
|
"MULTIPLICITY: TRUE\r\n" |
217 |
|
"DEFAULT: 44100\r\n" |
218 |
|
"POSSIBILITIES: 44100,48000,96000\r\n"; |
219 |
|
} |
220 |
|
else ret = LSCP_FAILED; |
221 |
|
} |
222 |
|
else ret = LSCP_FAILED; |
223 |
|
} |
224 |
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DRIVER_PARAMETER", "INFO")) { |
225 |
|
// Getting informations about a specific MIDI input driver parameter. |
226 |
|
// GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-type> <param> |
227 |
|
if (lscp_parser_test(&tok, "Alsa")) { |
228 |
|
if (lscp_parser_test(&tok, "active")) { |
229 |
|
pszResult = "DESCRIPTION: 'ALSA Sequencer device active state'\r\n" |
230 |
|
"TYPE: BOOL\r\n" |
231 |
|
"MANDATORY: TRUE\r\n" |
232 |
|
"FIX: TRUE\r\n" |
233 |
|
"MULTIPLICITY: FALSE\r\n" |
234 |
|
"DEPENDS: channels,ports\r\n" |
235 |
|
"DEFAULT: TRUE\r\n" |
236 |
|
"RANGE_MIN: FALSE\r\n" |
237 |
|
"RANGE_MAX: TRUE\r\n" |
238 |
|
"POSSIBILITIES: FALSE,TRUE\r\n"; |
239 |
|
} |
240 |
|
else if (lscp_parser_test(&tok, "ports")) { |
241 |
|
pszResult = "DESCRIPTION: 'Number of ALSA Sequencer ports'\r\n" |
242 |
|
"TYPE: INT\r\n" |
243 |
|
"MANDATORY: FALSE\r\n" |
244 |
|
"FIX: FALSE\r\n" |
245 |
|
"MULTIPLICITY: FALSE\r\n" |
246 |
|
"DEFAULT: 1\r\n" |
247 |
|
"RANGE_MIN: 1\r\n" |
248 |
|
"RANGE_MAX: 4\r\n"; |
249 |
|
} |
250 |
|
else ret = LSCP_FAILED; |
251 |
} |
} |
252 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
253 |
} |
} |
254 |
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DEVICE", "INFO")) { |
255 |
|
// Getting informations about a specific audio output device. |
256 |
|
// GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
257 |
|
if (lscp_parser_nextint(&tok) < iAudioDevice) { |
258 |
|
pszResult = "driver: Alsa\r\n" |
259 |
|
"active: TRUE\r\n" |
260 |
|
"channels: 2\r\n" |
261 |
|
"samplerate: 44100\r\n"; |
262 |
|
} |
263 |
|
else ret = LSCP_FAILED; |
264 |
|
} |
265 |
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DEVICE", "INFO")) { |
266 |
|
// Getting informations about a specific MIDI input device. |
267 |
|
// GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
268 |
|
if (lscp_parser_nextint(&tok) < iMidiDevice) { |
269 |
|
pszResult = "driver: Alsa\r\n" |
270 |
|
"active: TRUE\r\n" |
271 |
|
"channels: 16\r\n" |
272 |
|
"ports: 1\r\n"; |
273 |
|
} |
274 |
|
else ret = LSCP_FAILED; |
275 |
|
} |
276 |
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_CHANNEL", "INFO")) { |
277 |
|
// Getting informations about an audio channel. |
278 |
|
// GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
279 |
|
if (lscp_parser_nextint(&tok) < iAudioDevice) { |
280 |
|
pszResult = "name: DummyMonitor\r\n" |
281 |
|
"is_mix_channel: FALSE\r\n" |
282 |
|
"mix_channel_destination: 0\r\n"; |
283 |
|
} |
284 |
|
else ret = LSCP_FAILED; |
285 |
|
} |
286 |
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_PORT", "INFO")) { |
287 |
|
// Getting informations about a MIDI port. |
288 |
|
// GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
289 |
|
if (lscp_parser_nextint(&tok) < iMidiDevice) { |
290 |
|
pszResult = "name: DummyKeyboard\r\n" |
291 |
|
"alsa_seq_bindings: '64:0'\r\n"; |
292 |
|
} |
293 |
|
else ret = LSCP_FAILED; |
294 |
|
} |
295 |
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_CHANNEL_PARAMETER", "INFO")) { |
296 |
|
// Getting informations about specific audio channel parameter. |
297 |
|
// GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
298 |
|
if (lscp_parser_nextint(&tok) < iAudioDevice) { |
299 |
|
lscp_parser_nextint(&tok); |
300 |
|
if (lscp_parser_test(&tok, "is_mix_channel")) { |
301 |
|
pszResult = "DESCRIPTION: 'Whether this is an audio mix channel'\r\n" |
302 |
|
"TYPE: BOOL\r\n" |
303 |
|
"MANDATORY: TRUE\r\n" |
304 |
|
"FIX: FALSE\r\n" |
305 |
|
"MULTIPLICITY: FALSE\r\n" |
306 |
|
"POSSIBILITIES: FALSE,TRUE\r\n"; |
307 |
|
} |
308 |
|
else if (lscp_parser_test(&tok, "mix_channel_destination")) { |
309 |
|
pszResult = "DESCRIPTION: 'Audio mix channel destination'\r\n" |
310 |
|
"TYPE: INT\r\n" |
311 |
|
"MANDATORY: TRUE\r\n" |
312 |
|
"FIX: FALSE\r\n" |
313 |
|
"MULTIPLICITY: TRUE\r\n" |
314 |
|
"POSSIBILITIES: 0,1\r\n"; |
315 |
|
} |
316 |
|
else ret = LSCP_FAILED; |
317 |
|
} |
318 |
|
else ret = LSCP_FAILED; |
319 |
|
} |
320 |
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_PORT_PARAMETER", "INFO")) { |
321 |
|
// Getting informations about specific MIDI port parameter. |
322 |
|
// GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
323 |
|
if (lscp_parser_nextint(&tok) < iMidiDevice) { |
324 |
|
lscp_parser_nextint(&tok); |
325 |
|
if (lscp_parser_test(&tok, "alsa_seq_bindings")) { |
326 |
|
pszResult = "DESCRIPTION: 'Alsa sequencer port bindings'\r\n" |
327 |
|
"TYPE: STRING\r\n" |
328 |
|
"MANDATORY: TRUE\r\n" |
329 |
|
"FIX: FALSE\r\n" |
330 |
|
"MULTIPLICITY: TRUE\r\n" |
331 |
|
"POSSIBILITIES: '64:0','68:0','68:1'\r\n"; |
332 |
|
} |
333 |
|
else ret = LSCP_FAILED; |
334 |
|
} |
335 |
|
else ret = LSCP_FAILED; |
336 |
|
} |
337 |
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
338 |
|
// Getting all created audio output device count. |
339 |
|
// GET AUDIO_OUTPUT_DEVICES |
340 |
|
sprintf(szTemp, "%d\r\n", iAudioDevice); |
341 |
|
pszResult = szTemp; |
342 |
|
} |
343 |
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
344 |
|
// Getting all created MID input device count. |
345 |
|
// GET MIDI_INPUT_DEVICES |
346 |
|
sprintf(szTemp, "%d\r\n", iMidiDevice); |
347 |
|
pszResult = szTemp; |
348 |
|
} |
349 |
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
350 |
// Getting all available engines: |
// Getting all available engine count: |
351 |
// GET AVAILABLE_ENGINES |
// GET AVAILABLE_ENGINES |
352 |
pszResult = "Engine1,Engine2,Engine3\r\n"; |
pszResult = "3\r\n"; |
353 |
|
} |
354 |
|
else if (lscp_parser_test2(&tok, "SERVER", "INFO")) { |
355 |
|
// Getting information about the server. |
356 |
|
// GET SERVER INFO |
357 |
|
sprintf(szTemp, "DESCRIPTION: example_server (%s) %s\r\n" |
358 |
|
"VERSION: %s\r\n", lscp_server_package(), |
359 |
|
lscp_server_build(), lscp_server_version()); |
360 |
|
pszResult = szTemp; |
361 |
} |
} |
362 |
else if (lscp_parser_test2(&tok, "ENGINE", "INFO")) { |
else if (lscp_parser_test2(&tok, "ENGINE", "INFO")) { |
363 |
// Getting information about an engine. |
// Getting information about an engine. |
364 |
// GET ENGINE INFO <engine-name> |
// GET ENGINE INFO <engine-name> |
365 |
pszResult = "DESCRIPTION: DummyEngine\r\n" |
if (lscp_parser_test(&tok, "GigEngine")) { |
366 |
"VERSION: 1.0\r\n"; |
pszResult = "DESCRIPTION: GigaSampler Engine\r\n" |
367 |
|
"VERSION: 0.3\r\n"; |
368 |
|
} |
369 |
|
else if (lscp_parser_test(&tok, "DLSEngine")) { |
370 |
|
pszResult = "DESCRIPTION: 'DLS Generic Engine'\r\n" |
371 |
|
"VERSION: 0.2\r\n"; |
372 |
|
} |
373 |
|
else if (lscp_parser_test(&tok, "AkaiEngine")) { |
374 |
|
pszResult = "DESCRIPTION: Akai Sampler Engine\r\n" |
375 |
|
"VERSION: 0.1\r\n"; |
376 |
|
} |
377 |
|
else ret = LSCP_FAILED; |
378 |
|
} |
379 |
|
else ret = LSCP_FAILED; |
380 |
|
} |
381 |
|
else if (lscp_parser_test(&tok, "LIST")) { |
382 |
|
if (lscp_parser_test(&tok, "CHANNELS")) { |
383 |
|
// Getting all created sampler channel list. |
384 |
|
// LIST CHANNELS |
385 |
|
if (iSamplerChannel > 0) { |
386 |
|
strcpy(szTemp, "0"); |
387 |
|
for (i = 1; i < iSamplerChannel && strlen(szTemp) < sizeof(szTemp) - 8; i++) |
388 |
|
sprintf(szTemp + strlen(szTemp), ",%d", i); |
389 |
|
strcat(szTemp, "\r\n"); |
390 |
|
pszResult = szTemp; |
391 |
|
} |
392 |
|
else ret = LSCP_FAILED; |
393 |
|
} |
394 |
|
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
395 |
|
// Getting all available engines: |
396 |
|
// LIST AVAILABLE_ENGINES |
397 |
|
pszResult = "GigEngine,DLSEngine,AkaiEngine\r\n"; |
398 |
|
} |
399 |
|
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
400 |
|
// Getting all available audio output drivers. |
401 |
|
// LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS |
402 |
|
pszResult = "ALSA,JACK\r\n"; |
403 |
|
} |
404 |
|
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
405 |
|
// Getting all available MIDI input drivers. |
406 |
|
// LIST AVAILABLE_MIDI_INPUT_DRIVERS |
407 |
|
pszResult = "ALSA\r\n"; |
408 |
|
} |
409 |
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
410 |
|
// Getting all created audio output device list. |
411 |
|
// LIST AUDIO_OUTPUT_DEVICES |
412 |
|
if (iAudioDevice > 0) { |
413 |
|
strcpy(szTemp, "0"); |
414 |
|
for (i = 1; i < iAudioDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) |
415 |
|
sprintf(szTemp + strlen(szTemp), ",%d", i); |
416 |
|
strcat(szTemp, "\r\n"); |
417 |
|
pszResult = szTemp; |
418 |
|
} |
419 |
|
else ret = LSCP_FAILED; |
420 |
|
} |
421 |
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
422 |
|
// Getting all created MID input device list. |
423 |
|
// LIST MIDI_INPUT_DEVICES |
424 |
|
if (iMidiDevice > 0) { |
425 |
|
strcpy(szTemp, "0"); |
426 |
|
for (i = 1; i < iMidiDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) |
427 |
|
sprintf(szTemp + strlen(szTemp), ",%d", i); |
428 |
|
strcat(szTemp, "\r\n"); |
429 |
|
pszResult = szTemp; |
430 |
|
} |
431 |
|
else ret = LSCP_FAILED; |
432 |
} |
} |
433 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
434 |
} |
} |
438 |
// Setting channel volume: |
// Setting channel volume: |
439 |
// SET CHANNEL VOLUME <sampler-channel> <volume> |
// SET CHANNEL VOLUME <sampler-channel> <volume> |
440 |
} |
} |
441 |
|
else if (lscp_parser_test(&tok, "MUTE")) { |
442 |
|
// Muting a sampler channel: |
443 |
|
// SET CHANNEL MUTE <sampler-channel> <mute> |
444 |
|
} |
445 |
|
else if (lscp_parser_test(&tok, "SOLO")) { |
446 |
|
// Soloing a sampler channel: |
447 |
|
// SET CHANNEL SOLO <sampler-channel> <solo> |
448 |
|
} |
449 |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_TYPE")) { |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_TYPE")) { |
450 |
// Setting audio output type: |
// Setting audio output type: |
451 |
// SET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> <audio-output-type> |
// SET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> <audio-output-type> |
452 |
} |
} |
453 |
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
454 |
|
// Setting audio output device: |
455 |
|
// SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id> |
456 |
|
} |
457 |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_CHANNEL")) { |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_CHANNEL")) { |
458 |
// Setting audio output channel: |
// Setting audio output channel: |
459 |
// SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-channel> |
// SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-in> <audio-out> |
460 |
} |
} |
461 |
else if (lscp_parser_test(&tok, "MIDI_INPUT_TYPE")) { |
else if (lscp_parser_test(&tok, "MIDI_INPUT_TYPE")) { |
462 |
// Setting MIDI input type: |
// Setting MIDI input type: |
463 |
// SET CHANNEL MIDI_INPUT_TYPE <sampler-channel> <midi-input-type> |
// SET CHANNEL MIDI_INPUT_TYPE <sampler-channel> <midi-input-type> |
464 |
} |
} |
465 |
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
466 |
|
// Setting MIDI input device: |
467 |
|
// SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id> |
468 |
|
} |
469 |
else if (lscp_parser_test(&tok, "MIDI_INPUT_PORT")) { |
else if (lscp_parser_test(&tok, "MIDI_INPUT_PORT")) { |
470 |
// Setting MIDI input port: |
// Setting MIDI input port: |
471 |
// SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port> |
// SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port> |
485 |
} |
} |
486 |
else if (lscp_parser_test(&tok, "INSTRUMENT")) { |
else if (lscp_parser_test(&tok, "INSTRUMENT")) { |
487 |
// Loading an instrument: |
// Loading an instrument: |
488 |
// LOAD INSTRUMENT <filename> <instr-index> <sampler-channel> |
// LOAD INSTRUMENT [NON_MODAL] <filename> <instr-index> <sampler-channel> |
489 |
} |
} |
490 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
491 |
} |
} |
492 |
else if (lscp_parser_test2(&tok, "ADD", "CHANNEL")) { |
else if (lscp_parser_test2(&tok, "ADD", "CHANNEL")) { |
493 |
// Adding a new sampler channel: |
// Adding a new sampler channel: |
494 |
// ADD CHANNEL |
// ADD CHANNEL |
495 |
sprintf(szTemp, "OK[%d]", iChannel++); |
if (iSamplerChannel < 16) { |
496 |
pszResult = szTemp; |
sprintf(szTemp, "OK[%d]", iSamplerChannel++); |
497 |
|
pszResult = szTemp; |
498 |
|
} else { |
499 |
|
iSamplerChannel = 0; |
500 |
|
ret = LSCP_FAILED; |
501 |
|
} |
502 |
} |
} |
503 |
else if (lscp_parser_test2(&tok, "REMOVE", "CHANNEL")) { |
else if (lscp_parser_test2(&tok, "REMOVE", "CHANNEL")) { |
504 |
// Removing a sampler channel: |
// Removing a sampler channel: |
505 |
// REMOVE CHANNEL <sampler-channel> |
// REMOVE CHANNEL <sampler-channel> |
506 |
|
if (lscp_parser_nextint(&tok) < iSamplerChannel) |
507 |
|
iSamplerChannel--; |
508 |
|
else |
509 |
|
ret = LSCP_FAILED; |
510 |
} |
} |
511 |
else if (lscp_parser_test2(&tok, "RESET", "CHANNEL")) { |
else if (lscp_parser_test(&tok, "RESET")) { |
512 |
// Resetting a sampler channel: |
if (lscp_parser_test(&tok, "CHANNEL")) { |
513 |
// RESET CHANNEL <sampler-channel> |
// Resetting a sampler channel: |
514 |
} |
// RESET CHANNEL <sampler-channel> |
515 |
else if (lscp_parser_test2(&tok, "SUBSCRIBE", "NOTIFICATION")) { |
if (lscp_parser_nextint(&tok) > iSamplerChannel) |
516 |
// Register frontend for receiving UDP event messages: |
ret = LSCP_FAILED; |
517 |
// SUBSCRIBE NOTIFICATION <udp-port> |
} else { |
518 |
ret = lscp_server_subscribe(pConnect, lscp_parser_nextint(&tok)); |
// Reset sampler: |
519 |
} |
// RESET |
520 |
else if (lscp_parser_test2(&tok, "UNSUBSCRIBE", "NOTIFICATION")) { |
iSamplerChannel = 0; |
521 |
// Deregister frontend for not receiving UDP event messages anymore: |
iAudioDevice = 0; |
522 |
// UNSUBSCRIBE NOTIFICATION <session-id> |
iMidiDevice = 0; |
523 |
ret = lscp_server_unsubscribe(pConnect, lscp_parser_next(&tok)); |
} |
524 |
|
} |
525 |
|
else if (lscp_parser_test(&tok, "CREATE")) { |
526 |
|
if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
527 |
|
// Creating an audio output device. |
528 |
|
// CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
529 |
|
if (iAudioDevice < 8) { |
530 |
|
sprintf(szTemp, "OK[%d]", iAudioDevice++); |
531 |
|
pszResult = szTemp; |
532 |
|
} else { |
533 |
|
iAudioDevice = 0; |
534 |
|
ret = LSCP_FAILED; |
535 |
|
} |
536 |
|
} |
537 |
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
538 |
|
// Creating an MIDI input device. |
539 |
|
// CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
540 |
|
if (iMidiDevice < 8) { |
541 |
|
sprintf(szTemp, "OK[%d]", iMidiDevice++); |
542 |
|
pszResult = szTemp; |
543 |
|
} else { |
544 |
|
iMidiDevice = 0; |
545 |
|
ret = LSCP_FAILED; |
546 |
|
} |
547 |
|
} |
548 |
|
else ret = LSCP_FAILED; |
549 |
|
} |
550 |
|
else if (lscp_parser_test(&tok, "DESTROY")) { |
551 |
|
if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
552 |
|
// Destroying an audio output device. |
553 |
|
// DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
554 |
|
if (lscp_parser_nextint(&tok) < iAudioDevice) |
555 |
|
iAudioDevice--; |
556 |
|
else |
557 |
|
ret = LSCP_FAILED; |
558 |
|
} |
559 |
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
560 |
|
// Destroying an MIDI intput device. |
561 |
|
// DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
562 |
|
if (lscp_parser_nextint(&tok) < iMidiDevice) |
563 |
|
iMidiDevice--; |
564 |
|
else |
565 |
|
ret = LSCP_FAILED; |
566 |
|
} |
567 |
|
else ret = LSCP_FAILED; |
568 |
|
} |
569 |
|
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
570 |
|
// Register frontend for receiving event notification messages: |
571 |
|
// SUBSCRIBE <event> |
572 |
|
ret = lscp_server_subscribe(pConnect, lscp_event_from_text(lscp_parser_next(&tok))); |
573 |
|
} |
574 |
|
else if (lscp_parser_test(&tok, "UNSUBSCRIBE")) { |
575 |
|
// Deregister frontend for not receiving event notification messages anymore: |
576 |
|
// UNSUBSCRIBE <event> |
577 |
|
ret = lscp_server_unsubscribe(pConnect, lscp_event_from_text(lscp_parser_next(&tok))); |
578 |
} |
} |
579 |
else if (lscp_parser_test(&tok, "QUIT")) { |
else if (lscp_parser_test(&tok, "QUIT")) { |
580 |
// Close client connection: |
// Close client connection: |
596 |
|
|
597 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
598 |
|
|
599 |
|
|
600 |
void server_usage (void) |
void server_usage (void) |
601 |
{ |
{ |
602 |
printf("\n %s %s (Build: %s)\n", lscp_server_package(), lscp_server_version(), lscp_server_build()); |
printf("\n %s %s (Build: %s)\n", lscp_server_package(), lscp_server_version(), lscp_server_build()); |
645 |
else |
else |
646 |
if (strcmp(szLine, "list") == 0) { |
if (strcmp(szLine, "list") == 0) { |
647 |
for (p = pServer->connects.first; p; p = p->next) { |
for (p = pServer->connects.first; p; p = p->next) { |
648 |
printf("client: sock=%d addr=%s tcp.port=%d udp.port=%d ping=%d sessid=%s.\n", |
printf("client: sock=%d addr=%s port=%d events=0x%04x.\n", |
649 |
p->client.sock, |
p->client.sock, |
650 |
inet_ntoa(p->client.addr.sin_addr), |
inet_ntoa(p->client.addr.sin_addr), |
651 |
ntohs(p->client.addr.sin_port), |
ntohs(p->client.addr.sin_port), |
652 |
p->port, |
(int) p->events |
|
p->ping, |
|
|
p->sessid |
|
653 |
); |
); |
654 |
} |
} |
655 |
} |
} |
656 |
else |
else |
657 |
if (cchLine > 0 && strcmp(szLine, "help") != 0) |
if (cchLine > 0 && strcmp(szLine, "help") != 0) |
658 |
lscp_server_broadcast(pServer, szLine, strlen(szLine)); |
lscp_server_broadcast(pServer, LSCP_EVENT_MISCELLANEOUS, szLine, strlen(szLine)); |
659 |
else |
else |
660 |
server_usage(); |
server_usage(); |
661 |
|
|