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 |
31 |
static WSADATA _wsaData; |
static WSADATA _wsaData; |
32 |
#endif |
#endif |
33 |
|
|
34 |
|
|
35 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
36 |
|
|
37 |
lscp_status_t server_callback ( lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer, void *pvData ) |
lscp_status_t server_callback ( lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer, void *pvData ) |
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; |
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 |
442 |
sprintf(szTemp, "%d\r\n", iMidiInstruments); |
sprintf(szTemp, "%d\r\n", iMidiInstruments); |
443 |
pszResult = szTemp; |
pszResult = szTemp; |
444 |
} |
} |
445 |
if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT", "INFO")) { |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAPS")) { |
446 |
|
// Get the total count of MIDI instrument maps: |
447 |
|
// GET MIDI_INSTRUMENT_MAPS |
448 |
|
sprintf(szTemp, "%d\r\n", iMidiMaps); |
449 |
|
pszResult = szTemp; |
450 |
|
} |
451 |
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "INFO")) { |
452 |
// Getting information about a MIDI instrument map entry: |
// Getting information about a MIDI instrument map entry: |
453 |
// GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
// GET MIDI_INSTRUMENT_MAP INFO <midi-map> |
454 |
|
strcpy(szTemp, "NAME: "); |
455 |
|
switch (lscp_parser_nextint(&tok)) { |
456 |
|
case 0: |
457 |
|
strcat(szTemp, "Chromatic\r\n"); |
458 |
|
break; |
459 |
|
case 1: |
460 |
|
strcat(szTemp, "Drum Kits\r\n"); |
461 |
|
break; |
462 |
|
} |
463 |
|
strcat(szTemp, ".\r\n"); |
464 |
|
pszResult = szTemp; |
465 |
|
} |
466 |
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT", "INFO")) { |
467 |
|
// Getting information about a MIDI instrument map entry: |
468 |
|
// GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog> |
469 |
pszResult = "NAME: DummyName\r\n" |
pszResult = "NAME: DummyName\r\n" |
470 |
"ENGINE_NAME: DummyEngine\r\n" |
"ENGINE_NAME: DummyEngine\r\n" |
471 |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
481 |
if (lscp_parser_test(&tok, "CHANNELS")) { |
if (lscp_parser_test(&tok, "CHANNELS")) { |
482 |
// Getting all created sampler channel list. |
// Getting all created sampler channel list. |
483 |
// LIST CHANNELS |
// LIST CHANNELS |
484 |
|
szTemp[0] = (char) 0; |
485 |
for (i = 0; i < iSamplerChannel && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
for (i = 0; i < iSamplerChannel && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
486 |
if (i > 0) |
if (i > 0) |
487 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
508 |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
509 |
// Getting all created audio output device list. |
// Getting all created audio output device list. |
510 |
// LIST AUDIO_OUTPUT_DEVICES |
// LIST AUDIO_OUTPUT_DEVICES |
511 |
|
szTemp[0] = (char) 0; |
512 |
for (i = 0; i < iAudioDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
for (i = 0; i < iAudioDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
513 |
if (i > 0) |
if (i > 0) |
514 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
520 |
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
521 |
// Getting all created MID input device list. |
// Getting all created MID input device list. |
522 |
// LIST MIDI_INPUT_DEVICES |
// LIST MIDI_INPUT_DEVICES |
523 |
|
szTemp[0] = (char) 0; |
524 |
for (i = 0; i < iMidiDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
for (i = 0; i < iMidiDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
525 |
if (i > 0) |
if (i > 0) |
526 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
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 |
547 |
|
szTemp[0] = (char) 0; |
548 |
for (i = 0; i < iMidiInstruments && strlen(szTemp) < sizeof(szTemp) - 16; i++) { |
for (i = 0; i < iMidiInstruments && strlen(szTemp) < sizeof(szTemp) - 16; i++) { |
549 |
if (i > 0) |
if (i > 0) |
550 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
553 |
strcat(szTemp, "\r\n"); |
strcat(szTemp, "\r\n"); |
554 |
pszResult = szTemp; |
pszResult = szTemp; |
555 |
} |
} |
556 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAPS")) { |
557 |
|
// Getting indeces of all MIDI instrument map entries: |
558 |
|
// LIST MIDI_INSTRUMENT_MAPS |
559 |
|
szTemp[0] = (char) 0; |
560 |
|
for (i = 0; i < iMidiMaps && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
561 |
|
if (i > 0) |
562 |
|
strcat(szTemp, ","); |
563 |
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
564 |
|
} |
565 |
|
strcat(szTemp, "\r\n"); |
566 |
|
pszResult = szTemp; |
567 |
|
} |
568 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
569 |
} |
} |
570 |
else if (lscp_parser_test(&tok, "SET")) { |
else if (lscp_parser_test(&tok, "SET")) { |
609 |
// Setting MIDI input channel: |
// Setting MIDI input channel: |
610 |
// SET CHANNEL MIDI_INPUT_CHANNEL <sampler-channel> <midi-input-chan> |
// SET CHANNEL MIDI_INPUT_CHANNEL <sampler-channel> <midi-input-chan> |
611 |
} |
} |
612 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
613 |
|
// Setting MIDI instrument mapl: |
614 |
|
// SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map> |
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")) { |
639 |
|
// Setting MIDI instrument map name: |
640 |
|
// SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name> |
641 |
|
} |
642 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
643 |
} |
} |
644 |
else if (lscp_parser_test(&tok, "LOAD")) { |
else if (lscp_parser_test(&tok, "LOAD")) { |
652 |
} |
} |
653 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
654 |
} |
} |
655 |
else if (lscp_parser_test2(&tok, "ADD", "CHANNEL")) { |
else if (lscp_parser_test(&tok, "ADD")) { |
656 |
// Adding a new sampler channel: |
if (lscp_parser_test(&tok, "CHANNEL")) { |
657 |
// ADD CHANNEL |
// Adding a new sampler channel: |
658 |
if (iSamplerChannel < 16) { |
// ADD CHANNEL |
659 |
sprintf(szTemp, "OK[%d]\r\n", iSamplerChannel++); |
if (iSamplerChannel < 16) { |
660 |
pszResult = szTemp; |
sprintf(szTemp, "OK[%d]\r\n", iSamplerChannel++); |
661 |
} else { |
pszResult = szTemp; |
662 |
iSamplerChannel = 0; |
} else { |
663 |
ret = LSCP_FAILED; |
iSamplerChannel = 0; |
664 |
|
ret = LSCP_FAILED; |
665 |
|
} |
666 |
|
} |
667 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
668 |
|
// Adding a new MIDI instrument map: |
669 |
|
// ADD MIDI_INSTRUMENT_MAP <map-name> |
670 |
|
if (iMidiMaps < 2) { |
671 |
|
sprintf(szTemp, "OK[%d]\r\n", iMidiMaps++); |
672 |
|
pszResult = szTemp; |
673 |
|
} else { |
674 |
|
iMidiMaps = 0; |
675 |
|
ret = LSCP_FAILED; |
676 |
|
} |
677 |
} |
} |
678 |
} |
} |
679 |
else if (lscp_parser_test2(&tok, "REMOVE", "CHANNEL")) { |
else if (lscp_parser_test(&tok, "REMOVE")) { |
680 |
// Removing a sampler channel: |
if (lscp_parser_test(&tok, "CHANNEL")) { |
681 |
// REMOVE CHANNEL <sampler-channel> |
// Removing a sampler channel: |
682 |
if (lscp_parser_nextint(&tok) < iSamplerChannel) |
// REMOVE CHANNEL <sampler-channel> |
683 |
iSamplerChannel--; |
if (lscp_parser_nextint(&tok) >= 0) |
684 |
else |
iSamplerChannel--; |
685 |
ret = LSCP_FAILED; |
else |
686 |
|
ret = LSCP_FAILED; |
687 |
|
} |
688 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
689 |
|
// Removing a MIDI instrument map: |
690 |
|
// REMOVE MIDI_INSTRUMENT_MAP <midi-map> |
691 |
|
if (lscp_parser_nextint(&tok) >= 0) |
692 |
|
iMidiMaps--; |
693 |
|
else |
694 |
|
ret = LSCP_FAILED; |
695 |
|
} |
696 |
} |
} |
697 |
else if (lscp_parser_test(&tok, "RESET")) { |
else if (lscp_parser_test(&tok, "RESET")) { |
698 |
if (lscp_parser_test(&tok, "CHANNEL")) { |
if (lscp_parser_test(&tok, "CHANNEL")) { |
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")) { |
777 |
// Create or replace a MIDI instrumnet map entry: |
// Create or replace a MIDI instrumnet map entry: |
778 |
// MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
// MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
779 |
// <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
// <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
780 |
iMidiInstruments++; |
iMidiInstruments++; |
781 |
} |
} |
782 |
else if (lscp_parser_test2(&tok, "UNMAP", "MIDI_INSTRUMENT")) { |
else if (lscp_parser_test2(&tok, "UNMAP", "MIDI_INSTRUMENT")) { |
783 |
// Remove an entry from the MIDI instrument map: |
// Remove an entry from the MIDI instrument map: |
784 |
// UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
// UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
785 |
if (iMidiInstruments > 0) |
if (iMidiInstruments > 0) |
786 |
iMidiInstruments--; |
iMidiInstruments--; |
787 |
else |
else |
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: |
820 |
return lscp_server_result(pConnect, pszResult, strlen(pszResult)); |
return lscp_server_result(pConnect, pszResult, strlen(pszResult)); |
821 |
} |
} |
822 |
|
|
823 |
|
|
824 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
825 |
|
|
826 |
|
|