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 iMidiMaps = 0; |
48 |
static int iMidiInstruments = 0; |
static int iMidiInstruments = 0; |
49 |
|
static float fVolume = 1.0f; |
50 |
|
|
51 |
if (pchBuffer == NULL) { |
if (pchBuffer == NULL) { |
52 |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
414 |
sprintf(szTemp, "%d\r\n", rand() % 100); |
sprintf(szTemp, "%d\r\n", rand() % 100); |
415 |
pszResult = szTemp; |
pszResult = szTemp; |
416 |
} |
} |
417 |
|
else if (lscp_parser_test(&tok, "VOLUME")) { |
418 |
|
// Get global volume attenuation: |
419 |
|
// GET VOLUME |
420 |
|
sprintf(szTemp, "%g\r\n", fVolume); |
421 |
|
pszResult = szTemp; |
422 |
|
} |
423 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
424 |
// Get the total count of MIDI instrument map entries: |
// Get the total count of MIDI instrument map entries: |
425 |
// GET MIDI_INSTRUMENTS |
// GET MIDI_INSTRUMENTS |
426 |
sprintf(szTemp, "%d\r\n", iMidiInstruments); |
sprintf(szTemp, "%d\r\n", iMidiInstruments); |
427 |
pszResult = szTemp; |
pszResult = szTemp; |
428 |
} |
} |
429 |
if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT", "INFO")) { |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAPS")) { |
430 |
|
// Get the total count of MIDI instrument maps: |
431 |
|
// GET MIDI_INSTRUMENT_MAPS |
432 |
|
sprintf(szTemp, "%d\r\n", iMidiMaps); |
433 |
|
pszResult = szTemp; |
434 |
|
} |
435 |
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "INFO")) { |
436 |
// Getting information about a MIDI instrument map entry: |
// Getting information about a MIDI instrument map entry: |
437 |
// GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
// GET MIDI_INSTRUMENT_MAP INFO <midi-map> |
438 |
|
strcpy(szTemp, "NAME: "); |
439 |
|
switch (lscp_parser_nextint(&tok)) { |
440 |
|
case 0: |
441 |
|
strcat(szTemp, "Chromatic\r\n"); |
442 |
|
break; |
443 |
|
case 1: |
444 |
|
strcat(szTemp, "Drum Kits\r\n"); |
445 |
|
break; |
446 |
|
} |
447 |
|
strcat(szTemp, ".\r\n"); |
448 |
|
pszResult = szTemp; |
449 |
|
} |
450 |
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT", "INFO")) { |
451 |
|
// Getting information about a MIDI instrument map entry: |
452 |
|
// GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog> |
453 |
pszResult = "NAME: DummyName\r\n" |
pszResult = "NAME: DummyName\r\n" |
454 |
"ENGINE_NAME: DummyEngine\r\n" |
"ENGINE_NAME: DummyEngine\r\n" |
455 |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
465 |
if (lscp_parser_test(&tok, "CHANNELS")) { |
if (lscp_parser_test(&tok, "CHANNELS")) { |
466 |
// Getting all created sampler channel list. |
// Getting all created sampler channel list. |
467 |
// LIST CHANNELS |
// LIST CHANNELS |
468 |
|
szTemp[0] = (char) 0; |
469 |
for (i = 0; i < iSamplerChannel && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
for (i = 0; i < iSamplerChannel && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
470 |
if (i > 0) |
if (i > 0) |
471 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
492 |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
493 |
// Getting all created audio output device list. |
// Getting all created audio output device list. |
494 |
// LIST AUDIO_OUTPUT_DEVICES |
// LIST AUDIO_OUTPUT_DEVICES |
495 |
|
szTemp[0] = (char) 0; |
496 |
for (i = 0; i < iAudioDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
for (i = 0; i < iAudioDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
497 |
if (i > 0) |
if (i > 0) |
498 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
504 |
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
505 |
// Getting all created MID input device list. |
// Getting all created MID input device list. |
506 |
// LIST MIDI_INPUT_DEVICES |
// LIST MIDI_INPUT_DEVICES |
507 |
|
szTemp[0] = (char) 0; |
508 |
for (i = 0; i < iMidiDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
for (i = 0; i < iMidiDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
509 |
if (i > 0) |
if (i > 0) |
510 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
516 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
517 |
// Getting indeces of all MIDI instrument map entries: |
// Getting indeces of all MIDI instrument map entries: |
518 |
// LIST MIDI_INSTRUMENTS |
// LIST MIDI_INSTRUMENTS |
519 |
|
szTemp[0] = (char) 0; |
520 |
for (i = 0; i < iMidiInstruments && strlen(szTemp) < sizeof(szTemp) - 16; i++) { |
for (i = 0; i < iMidiInstruments && strlen(szTemp) < sizeof(szTemp) - 16; i++) { |
521 |
if (i > 0) |
if (i > 0) |
522 |
strcat(szTemp, ","); |
strcat(szTemp, ","); |
525 |
strcat(szTemp, "\r\n"); |
strcat(szTemp, "\r\n"); |
526 |
pszResult = szTemp; |
pszResult = szTemp; |
527 |
} |
} |
528 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAPS")) { |
529 |
|
// Getting indeces of all MIDI instrument map entries: |
530 |
|
// LIST MIDI_INSTRUMENT_MAPS |
531 |
|
szTemp[0] = (char) 0; |
532 |
|
for (i = 0; i < iMidiMaps && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
533 |
|
if (i > 0) |
534 |
|
strcat(szTemp, ","); |
535 |
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
536 |
|
} |
537 |
|
strcat(szTemp, "\r\n"); |
538 |
|
pszResult = szTemp; |
539 |
|
} |
540 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
541 |
} |
} |
542 |
else if (lscp_parser_test(&tok, "SET")) { |
else if (lscp_parser_test(&tok, "SET")) { |
581 |
// Setting MIDI input channel: |
// Setting MIDI input channel: |
582 |
// SET CHANNEL MIDI_INPUT_CHANNEL <sampler-channel> <midi-input-chan> |
// SET CHANNEL MIDI_INPUT_CHANNEL <sampler-channel> <midi-input-chan> |
583 |
} |
} |
584 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
585 |
|
// Setting MIDI instrument mapl: |
586 |
|
// SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map> |
587 |
|
} |
588 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
589 |
} |
} |
590 |
|
else if (lscp_parser_test(&tok, "VOLUME")) { |
591 |
|
// Setting global volume attenuation: |
592 |
|
// SET VOLUME <volume> |
593 |
|
fVolume = lscp_parser_nextnum(&tok); |
594 |
|
} |
595 |
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "NAME")) { |
596 |
|
// Setting MIDI instrument map name: |
597 |
|
// SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name> |
598 |
|
} |
599 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
600 |
} |
} |
601 |
else if (lscp_parser_test(&tok, "LOAD")) { |
else if (lscp_parser_test(&tok, "LOAD")) { |
609 |
} |
} |
610 |
else ret = LSCP_FAILED; |
else ret = LSCP_FAILED; |
611 |
} |
} |
612 |
else if (lscp_parser_test2(&tok, "ADD", "CHANNEL")) { |
else if (lscp_parser_test(&tok, "ADD")) { |
613 |
// Adding a new sampler channel: |
if (lscp_parser_test(&tok, "CHANNEL")) { |
614 |
// ADD CHANNEL |
// Adding a new sampler channel: |
615 |
if (iSamplerChannel < 16) { |
// ADD CHANNEL |
616 |
sprintf(szTemp, "OK[%d]\r\n", iSamplerChannel++); |
if (iSamplerChannel < 16) { |
617 |
pszResult = szTemp; |
sprintf(szTemp, "OK[%d]\r\n", iSamplerChannel++); |
618 |
} else { |
pszResult = szTemp; |
619 |
iSamplerChannel = 0; |
} else { |
620 |
ret = LSCP_FAILED; |
iSamplerChannel = 0; |
621 |
|
ret = LSCP_FAILED; |
622 |
|
} |
623 |
|
} |
624 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
625 |
|
// Adding a new MIDI instrument map: |
626 |
|
// ADD MIDI_INSTRUMENT_MAP <map-name> |
627 |
|
if (iMidiMaps < 2) { |
628 |
|
sprintf(szTemp, "OK[%d]\r\n", iMidiMaps++); |
629 |
|
pszResult = szTemp; |
630 |
|
} else { |
631 |
|
iMidiMaps = 0; |
632 |
|
ret = LSCP_FAILED; |
633 |
|
} |
634 |
} |
} |
635 |
} |
} |
636 |
else if (lscp_parser_test2(&tok, "REMOVE", "CHANNEL")) { |
else if (lscp_parser_test(&tok, "REMOVE")) { |
637 |
// Removing a sampler channel: |
if (lscp_parser_test(&tok, "CHANNEL")) { |
638 |
// REMOVE CHANNEL <sampler-channel> |
// Removing a sampler channel: |
639 |
if (lscp_parser_nextint(&tok) < iSamplerChannel) |
// REMOVE CHANNEL <sampler-channel> |
640 |
iSamplerChannel--; |
if (lscp_parser_nextint(&tok) >= 0) |
641 |
else |
iSamplerChannel--; |
642 |
ret = LSCP_FAILED; |
else |
643 |
|
ret = LSCP_FAILED; |
644 |
|
} |
645 |
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
646 |
|
// Removing a MIDI instrument map: |
647 |
|
// REMOVE MIDI_INSTRUMENT_MAP <midi-map> |
648 |
|
if (lscp_parser_nextint(&tok) >= 0) |
649 |
|
iMidiMaps--; |
650 |
|
else |
651 |
|
ret = LSCP_FAILED; |
652 |
|
} |
653 |
} |
} |
654 |
else if (lscp_parser_test(&tok, "RESET")) { |
else if (lscp_parser_test(&tok, "RESET")) { |
655 |
if (lscp_parser_test(&tok, "CHANNEL")) { |
if (lscp_parser_test(&tok, "CHANNEL")) { |
663 |
iSamplerChannel = 0; |
iSamplerChannel = 0; |
664 |
iAudioDevice = 0; |
iAudioDevice = 0; |
665 |
iMidiDevice = 0; |
iMidiDevice = 0; |
666 |
|
iMidiMaps = 0; |
667 |
|
iMidiInstruments = 0; |
668 |
} |
} |
669 |
} |
} |
670 |
else if (lscp_parser_test(&tok, "CREATE")) { |
else if (lscp_parser_test(&tok, "CREATE")) { |
713 |
} |
} |
714 |
else if (lscp_parser_test2(&tok, "MAP", "MIDI_INSTRUMENT")) { |
else if (lscp_parser_test2(&tok, "MAP", "MIDI_INSTRUMENT")) { |
715 |
// Create or replace a MIDI instrumnet map entry: |
// Create or replace a MIDI instrumnet map entry: |
716 |
// MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
// MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
717 |
// <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
// <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
718 |
iMidiInstruments++; |
iMidiInstruments++; |
719 |
} |
} |
720 |
else if (lscp_parser_test2(&tok, "UNMAP", "MIDI_INSTRUMENT")) { |
else if (lscp_parser_test2(&tok, "UNMAP", "MIDI_INSTRUMENT")) { |
721 |
// Remove an entry from the MIDI instrument map: |
// Remove an entry from the MIDI instrument map: |
722 |
// UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
// UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
723 |
if (iMidiInstruments > 0) |
if (iMidiInstruments > 0) |
724 |
iMidiInstruments--; |
iMidiInstruments--; |
725 |
else |
else |
728 |
else if (lscp_parser_test2(&tok, "CLEAR", "MIDI_INSTRUMENTS")) { |
else if (lscp_parser_test2(&tok, "CLEAR", "MIDI_INSTRUMENTS")) { |
729 |
// Clear the MIDI instrumnet map: |
// Clear the MIDI instrumnet map: |
730 |
// CLEAR MIDI_INSTRUMENTS |
// CLEAR MIDI_INSTRUMENTS |
731 |
|
iMidiInstruments = 0; |
732 |
} |
} |
733 |
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
734 |
// Register frontend for receiving event notification messages: |
// Register frontend for receiving event notification messages: |
758 |
return lscp_server_result(pConnect, pszResult, strlen(pszResult)); |
return lscp_server_result(pConnect, pszResult, strlen(pszResult)); |
759 |
} |
} |
760 |
|
|
761 |
|
|
762 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
763 |
|
|
764 |
|
|