2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
liblscp - LinuxSampler Control Protocol API |
liblscp - LinuxSampler Control Protocol API |
5 |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, 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 |
44 |
static int iSamplerChannel = 0; |
static int iSamplerChannel = 0; |
45 |
static int iAudioDevice = 0; |
static int iAudioDevice = 0; |
46 |
static int iMidiDevice = 0; |
static int iMidiDevice = 0; |
47 |
|
static int iFxSend = 0; |
48 |
static int iMidiMaps = 0; |
static int iMidiMaps = 0; |
49 |
static int iMidiInstruments = 0; |
static int iMidiInstruments = 0; |
50 |
|
static float fVolume = 1.0f; |
51 |
|
|
52 |
if (pchBuffer == NULL) { |
if (pchBuffer == NULL) { |
53 |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
415 |
sprintf(szTemp, "%d\r\n", rand() % 100); |
sprintf(szTemp, "%d\r\n", rand() % 100); |
416 |
pszResult = szTemp; |
pszResult = szTemp; |
417 |
} |
} |
418 |
|
else if (lscp_parser_test(&tok, "VOLUME")) { |
419 |
|
// Get global volume attenuation: |
420 |
|
// GET VOLUME |
421 |
|
sprintf(szTemp, "%g\r\n", fVolume); |
422 |
|
pszResult = szTemp; |
423 |
|
} |
424 |
|
else if (lscp_parser_test2(&tok, "FX_SEND", "INFO")) { |
425 |
|
// Getting effect send informations: |
426 |
|
// GET FX_SEND INFO <sampler-channel> <fx-send-id> |
427 |
|
pszResult = "NAME: DummyFxSend\r\n" |
428 |
|
"MIDI_CONTROLLER: 99\r\n" |
429 |
|
"AUDIO_OUTPUT_ROUTING: 0,1\r\n" |
430 |
|
"LEVEL: 0.15\r\n" |
431 |
|
".\r\n"; |
432 |
|
} |
433 |
|
else if (lscp_parser_test(&tok, "FX_SENDS")) { |
434 |
|
// Get ammount of effect sends on a sampler channel: |
435 |
|
// GET FX_SENDS <sampler-channel> |
436 |
|
sprintf(szTemp, "%d\r\n", iFxSend); |
437 |
|
pszResult = szTemp; |
438 |
|
} |
439 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
440 |
// Get the total count of MIDI instrument map entries: |
// Get the total count of MIDI instrument map entries: |
441 |
// GET MIDI_INSTRUMENTS |
// GET MIDI_INSTRUMENTS |
529 |
strcat(szTemp, "\r\n"); |
strcat(szTemp, "\r\n"); |
530 |
pszResult = szTemp; |
pszResult = szTemp; |
531 |
} |
} |
532 |
|
else if (lscp_parser_test(&tok, "FX_SENDS")) { |
533 |
|
// Listing all effect sends on a sampler channel: |
534 |
|
// LIST FX_SENDS <sampler-channel> |
535 |
|
szTemp[0] = (char) 0; |
536 |
|
for (i = 0; i < iFxSend && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
537 |
|
if (i > 0) |
538 |
|
strcat(szTemp, ","); |
539 |
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
540 |
|
} |
541 |
|
strcat(szTemp, "\r\n"); |
542 |
|
pszResult = szTemp; |
543 |
|
} |
544 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
545 |
// Getting indeces of all MIDI instrument map entries: |
// Getting indeces of all MIDI instrument map entries: |
546 |
// LIST MIDI_INSTRUMENTS |
// LIST MIDI_INSTRUMENTS |
615 |
} |
} |
616 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
617 |
} |
} |
618 |
|
else if (lscp_parser_test(&tok, "VOLUME")) { |
619 |
|
// Setting global volume attenuation: |
620 |
|
// SET VOLUME <volume> |
621 |
|
fVolume = lscp_parser_nextnum(&tok); |
622 |
|
} |
623 |
|
else if (lscp_parser_test(&tok, "FX_SEND")) { |
624 |
|
if (lscp_parser_test(&tok, "MIDI_CONTROLLER")) { |
625 |
|
// Altering effect send MIDI controller: |
626 |
|
// SET FX_SEND MIDI_CONTROLLER <sampler-channel> <fx-send-id> <midi-ctrl> |
627 |
|
} |
628 |
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_CHANNEL")) { |
629 |
|
// Altering effect send audio routing: |
630 |
|
// SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-channel> <fx-send-id> <midi-ctrl> <audio-src> <audio-dst> |
631 |
|
} |
632 |
|
else if (lscp_parser_test(&tok, "LEVEL")) { |
633 |
|
// Altering effect send audio level: |
634 |
|
// SET FX_SEND LEVEL <sampler-channel> <fx-send-id> <midi-ctrl> <volume> |
635 |
|
} |
636 |
|
else ret = LSCP_FAILED; |
637 |
|
} |
638 |
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "NAME")) { |
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "NAME")) { |
639 |
// Setting MIDI instrument map name: |
// Setting MIDI instrument map name: |
640 |
// SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name> |
// SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name> |
706 |
iSamplerChannel = 0; |
iSamplerChannel = 0; |
707 |
iAudioDevice = 0; |
iAudioDevice = 0; |
708 |
iMidiDevice = 0; |
iMidiDevice = 0; |
709 |
|
iMidiMaps = 0; |
710 |
|
iMidiInstruments = 0; |
711 |
} |
} |
712 |
} |
} |
713 |
else if (lscp_parser_test(&tok, "CREATE")) { |
else if (lscp_parser_test(&tok, "CREATE")) { |
733 |
ret = LSCP_FAILED; |
ret = LSCP_FAILED; |
734 |
} |
} |
735 |
} |
} |
736 |
|
else if (lscp_parser_test(&tok, "FX_SEND")) { |
737 |
|
// Adding an effect send to a sampler channel: |
738 |
|
// CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>] |
739 |
|
if (iFxSend < 8) { |
740 |
|
sprintf(szTemp, "OK[%d]\r\n", iFxSend++); |
741 |
|
pszResult = szTemp; |
742 |
|
} else { |
743 |
|
iFxSend = 0; |
744 |
|
ret = LSCP_FAILED; |
745 |
|
} |
746 |
|
} |
747 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
748 |
} |
} |
749 |
else if (lscp_parser_test(&tok, "DESTROY")) { |
else if (lscp_parser_test(&tok, "DESTROY")) { |
750 |
if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
751 |
// Destroying an audio output device. |
// Destroying an audio output device. |
752 |
// DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
// DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
753 |
if (lscp_parser_nextint(&tok) < iAudioDevice) |
if (lscp_parser_nextint(&tok) >= 0 && iAudioDevice > 0) |
754 |
iAudioDevice--; |
iAudioDevice--; |
755 |
else |
else |
756 |
ret = LSCP_FAILED; |
ret = LSCP_FAILED; |
758 |
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
759 |
// Destroying an MIDI intput device. |
// Destroying an MIDI intput device. |
760 |
// DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
// DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
761 |
if (lscp_parser_nextint(&tok) < iMidiDevice) |
if (lscp_parser_nextint(&tok) >= 0 && iMidiDevice > 0) |
762 |
iMidiDevice--; |
iMidiDevice--; |
763 |
else |
else |
764 |
ret = LSCP_FAILED; |
ret = LSCP_FAILED; |
765 |
} |
} |
766 |
|
else if (lscp_parser_test(&tok, "FX_SEND")) { |
767 |
|
// Removing an effect send from a sampler channel: |
768 |
|
// CREATE FX_SEND <sampler-channel> <fx-send-id> |
769 |
|
if (lscp_parser_nextint(&tok) >= 0 && iFxSend > 0) |
770 |
|
iFxSend--; |
771 |
|
else |
772 |
|
ret = LSCP_FAILED; |
773 |
|
} |
774 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
775 |
} |
} |
776 |
else if (lscp_parser_test2(&tok, "MAP", "MIDI_INSTRUMENT")) { |
else if (lscp_parser_test2(&tok, "MAP", "MIDI_INSTRUMENT")) { |
790 |
else if (lscp_parser_test2(&tok, "CLEAR", "MIDI_INSTRUMENTS")) { |
else if (lscp_parser_test2(&tok, "CLEAR", "MIDI_INSTRUMENTS")) { |
791 |
// Clear the MIDI instrumnet map: |
// Clear the MIDI instrumnet map: |
792 |
// CLEAR MIDI_INSTRUMENTS |
// CLEAR MIDI_INSTRUMENTS |
793 |
|
iMidiInstruments = 0; |
794 |
} |
} |
795 |
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
796 |
// Register frontend for receiving event notification messages: |
// Register frontend for receiving event notification messages: |