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 |
|
|
43 |
static int iSamplerChannel = 0; |
static int iSamplerChannel = 0; |
44 |
static int iAudioDevice = 0; |
static int iAudioDevice = 0; |
45 |
static int iMidiDevice = 0; |
static int iMidiDevice = 0; |
46 |
|
static int iMidiInstruments = 0; |
47 |
|
|
48 |
if (pchBuffer == NULL) { |
if (pchBuffer == NULL) { |
49 |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
72 |
pszResult = "ENGINE_NAME: DummyEngine\r\n" |
pszResult = "ENGINE_NAME: DummyEngine\r\n" |
73 |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
74 |
"INSTRUMENT_NR: 0\r\n" |
"INSTRUMENT_NR: 0\r\n" |
75 |
|
"INSTRUMENT_NAME: Dummy Instrument\r\n" |
76 |
"INSTRUMENT_STATUS: 100\r\n" |
"INSTRUMENT_STATUS: 100\r\n" |
77 |
"AUDIO_OUTPUT_DEVICE: 0\r\n" |
"AUDIO_OUTPUT_DEVICE: 0\r\n" |
78 |
"AUDIO_OUTPUT_CHANNELS: 2\r\n" |
"AUDIO_OUTPUT_CHANNELS: 2\r\n" |
80 |
"MIDI_INPUT_DEVICE: 0\r\n" |
"MIDI_INPUT_DEVICE: 0\r\n" |
81 |
"MIDI_INPUT_PORT: 0\r\n" |
"MIDI_INPUT_PORT: 0\r\n" |
82 |
"MIDI_INPUT_CHANNEL: ALL\r\n" |
"MIDI_INPUT_CHANNEL: ALL\r\n" |
83 |
"VOLUME: 0.5\r\n"; |
"VOLUME: 0.5\r\n" |
84 |
|
"MUTE: FALSE\r\n" |
85 |
|
"SOLO: TRUE\r\n"; |
86 |
} |
} |
87 |
else if (lscp_parser_test(&tok, "VOICE_COUNT")) { |
else if (lscp_parser_test(&tok, "VOICE_COUNT")) { |
88 |
// Current number of active voices: |
// Current number of active voices: |
119 |
pszResult = szTemp; |
pszResult = szTemp; |
120 |
} |
} |
121 |
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
122 |
// Getting all available audio output drivers. |
// Getting all available audio output driver count. |
123 |
// GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
// GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
124 |
pszResult = "Alsa,Jack\r\n"; |
pszResult = "2\r\n"; |
125 |
} |
} |
126 |
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
127 |
// Getting all available MIDI input drivers. |
// Getting all available MIDI input driver count. |
128 |
// GET AVAILABLE_MIDI_INPUT_DRIVERS |
// GET AVAILABLE_MIDI_INPUT_DRIVERS |
129 |
pszResult = "Alsa\r\n"; |
pszResult = "1\r\n"; |
130 |
} |
} |
131 |
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER", "INFO")) { |
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER", "INFO")) { |
132 |
// Getting informations about a specific audio output driver. |
// Getting informations about a specific audio output driver. |
348 |
pszResult = szTemp; |
pszResult = szTemp; |
349 |
} |
} |
350 |
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
351 |
// Getting all available engines: |
// Getting all available engine count: |
352 |
// GET AVAILABLE_ENGINES |
// GET AVAILABLE_ENGINES |
353 |
pszResult = "GigEngine,DLSEngine,AkaiEngine\r\n"; |
pszResult = "3\r\n"; |
354 |
|
} |
355 |
|
else if (lscp_parser_test2(&tok, "SERVER", "INFO")) { |
356 |
|
// Getting information about the server. |
357 |
|
// GET SERVER INFO |
358 |
|
sprintf(szTemp, "DESCRIPTION: example_server (%s) %s\r\n" |
359 |
|
"VERSION: %s\r\n", lscp_server_package(), |
360 |
|
lscp_server_build(), lscp_server_version()); |
361 |
|
pszResult = szTemp; |
362 |
} |
} |
363 |
else if (lscp_parser_test2(&tok, "ENGINE", "INFO")) { |
else if (lscp_parser_test2(&tok, "ENGINE", "INFO")) { |
364 |
// Getting information about an engine. |
// Getting information about an engine. |
377 |
} |
} |
378 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
379 |
} |
} |
380 |
|
else if (lscp_parser_test(&tok, "TOTAL_VOICE_COUNT")) { |
381 |
|
// Current number of active voices: |
382 |
|
// GET TOTAL_VOICE_COUNT |
383 |
|
sprintf(szTemp, "%d", rand() % 100); |
384 |
|
pszResult = szTemp; |
385 |
|
} |
386 |
|
else if (lscp_parser_test(&tok, "TOTAL_VOICE_COUNT_MAX")) { |
387 |
|
// Maximum amount of active voices: |
388 |
|
// GET TOTAL_VOICE_COUNT_MAX |
389 |
|
sprintf(szTemp, "%d", rand() % 100); |
390 |
|
pszResult = szTemp; |
391 |
|
} |
392 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
393 |
|
// Get the total count of MIDI instrument map entries: |
394 |
|
// GET MIDI_INSTRUMENTS |
395 |
|
sprintf(szTemp, "%d", iMidiInstruments); |
396 |
|
pszResult = szTemp; |
397 |
|
} |
398 |
|
if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT", "INFO")) { |
399 |
|
// Getting information about a MIDI instrument map entry: |
400 |
|
// GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
401 |
|
pszResult = "NAME: DummyName\r\n" |
402 |
|
"ENGINE_NAME: DummyEngine\r\n" |
403 |
|
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
404 |
|
"INSTRUMENT_NR: 0\r\n" |
405 |
|
"INSTRUMENT_NAME: Dummy Instrument\r\n" |
406 |
|
"LOAD_MODE: ON_DEMAND\r\n" |
407 |
|
"VOLUME: 0.5\r\n"; |
408 |
|
} |
409 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
410 |
} |
} |
411 |
else if (lscp_parser_test(&tok, "LIST")) { |
else if (lscp_parser_test(&tok, "LIST")) { |
421 |
} |
} |
422 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
423 |
} |
} |
424 |
|
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
425 |
|
// Getting all available engines: |
426 |
|
// LIST AVAILABLE_ENGINES |
427 |
|
pszResult = "GigEngine,DLSEngine,AkaiEngine\r\n"; |
428 |
|
} |
429 |
|
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
430 |
|
// Getting all available audio output drivers. |
431 |
|
// LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS |
432 |
|
pszResult = "ALSA,JACK\r\n"; |
433 |
|
} |
434 |
|
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
435 |
|
// Getting all available MIDI input drivers. |
436 |
|
// LIST AVAILABLE_MIDI_INPUT_DRIVERS |
437 |
|
pszResult = "ALSA\r\n"; |
438 |
|
} |
439 |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
440 |
// Getting all created audio output device list. |
// Getting all created audio output device list. |
441 |
// LIST AUDIO_OUTPUT_DEVICES |
// LIST AUDIO_OUTPUT_DEVICES |
460 |
} |
} |
461 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
462 |
} |
} |
463 |
|
else if (lscp_parser_test(&tok, "LIST_MIDI_INSTRUMENTS")) { |
464 |
|
// Getting indeces of all MIDI instrument map entries: |
465 |
|
// LIST MIDI_INSTRUMENTS |
466 |
|
if (iMidiInstruments > 0) { |
467 |
|
strcpy(szTemp, "{0,0,0}"); |
468 |
|
for (i = 1; i < iMidiInstruments && strlen(szTemp) < sizeof(szTemp) - 16; i++) |
469 |
|
sprintf(szTemp + strlen(szTemp), ",{0,%d,%d}", i / 128, i % 128); |
470 |
|
strcat(szTemp, "\r\n"); |
471 |
|
pszResult = szTemp; |
472 |
|
} |
473 |
|
else ret = LSCP_FAILED; |
474 |
|
} |
475 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
476 |
} |
} |
477 |
else if (lscp_parser_test(&tok, "SET")) { |
else if (lscp_parser_test(&tok, "SET")) { |
480 |
// Setting channel volume: |
// Setting channel volume: |
481 |
// SET CHANNEL VOLUME <sampler-channel> <volume> |
// SET CHANNEL VOLUME <sampler-channel> <volume> |
482 |
} |
} |
483 |
|
else if (lscp_parser_test(&tok, "MUTE")) { |
484 |
|
// Muting a sampler channel: |
485 |
|
// SET CHANNEL MUTE <sampler-channel> <mute> |
486 |
|
} |
487 |
|
else if (lscp_parser_test(&tok, "SOLO")) { |
488 |
|
// Soloing a sampler channel: |
489 |
|
// SET CHANNEL SOLO <sampler-channel> <solo> |
490 |
|
} |
491 |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_TYPE")) { |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_TYPE")) { |
492 |
// Setting audio output type: |
// Setting audio output type: |
493 |
// SET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> <audio-output-type> |
// SET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> <audio-output-type> |
608 |
} |
} |
609 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
610 |
} |
} |
611 |
|
else if (lscp_parser_test2(&tok, "MAP", "MIDI_INSTRUMENT")) { |
612 |
|
// Create or replace a MIDI instrumnet map entry: |
613 |
|
// MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
614 |
|
// <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
615 |
|
iMidiInstruments++; |
616 |
|
} |
617 |
|
else if (lscp_parser_test2(&tok, "UNMAP", "MIDI_INSTRUMENT")) { |
618 |
|
// Remove an entry from the MIDI instrument map: |
619 |
|
// UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
620 |
|
if (iMidiInstruments > 0) |
621 |
|
iMidiInstruments--; |
622 |
|
else |
623 |
|
ret = LSCP_FAILED; |
624 |
|
} |
625 |
|
else if (lscp_parser_test2(&tok, "CLEAR", "MIDI_INSTRUMENTS")) { |
626 |
|
// Clear the MIDI instrumnet map: |
627 |
|
// CLEAR MIDI_INSTRUMENTS |
628 |
|
} |
629 |
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
630 |
// Register frontend for receiving event notification messages: |
// Register frontend for receiving event notification messages: |
631 |
// SUBSCRIBE <event> |
// SUBSCRIBE <event> |