diff --git a/Makefile b/Makefile index 53ccf80..206d0da 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ LDFLAGS=-lasound -lm -pthread all : $(CC) $(CCFLAGS) $(LDFLAGS) main.c serial.c serial2.c misc.c udpsock.c tcpsock.c alsa.c ini.c directory.c modem_snd.c -o midilink $(STRIP) midilink - $(CC) $(CCFLAGS) mlinkutil.c misc.c serial2.c -o mlinkutil + $(CC) $(CCFLAGS) mlinkutil.c misc.c serial2.c tcpsock.c -o mlinkutil $(STRIP) mlinkutil clean: rm -f midilink *~ *.orig DEADJOE diff --git a/mlinkutil b/mlinkutil index 992b871..090ccff 100755 Binary files a/mlinkutil and b/mlinkutil differ diff --git a/mlinkutil.c b/mlinkutil.c index 7b28b76..a0eeabc 100644 --- a/mlinkutil.c +++ b/mlinkutil.c @@ -9,13 +9,15 @@ #include "serial2.h" #include "misc.h" #include "config.h" +#include "tcpsock.h" #define DEFAULT_TCPAsciiTrans AsciiNoTrans int MIDI_DEBUG = TRUE; enum ASCIITRANS TCPAsciiTrans = DEFAULT_TCPAsciiTrans; -static int fdSerial = -1; +int fdSerial = -1; +int socket_out = -1; /////////////////////////////////////////////////////////////////////////////////////// @@ -25,24 +27,78 @@ static int fdSerial = -1; int main(int argc, char *argv[]) { int result = misc_check_args_option(argc, argv, "BAUD"); - + if(result && (result + 1 < argc)) { - char * ptr; - int baud = strtol(argv[result + 1], &ptr, 10); - if (!serial2_is_valid_rate (baud)) - { - printf("ERROR : BAUD not valid --> %s\n", argv[result + 1]); - return -1; - } - //printf("SET BAUD --> %d\n", baud); - fdSerial = open(serialDevice, O_RDWR | O_NOCTTY | O_SYNC); - if (fdSerial < 0) - { - misc_print(0, "ERROR: opening %s: %s\n", serialDevice, strerror(errno)); - return -2; - } - serial2_set_baud(serialDevice, fdSerial, baud); - close(fdSerial); + char * ptr; + int baud = strtol(argv[result + 1], &ptr, 10); + if (!serial2_is_valid_rate (baud)) + { + printf("ERROR : BAUD not valid --> %s\n", argv[result + 1]); + return -1; + } + //printf("SET BAUD --> %d\n", baud); + fdSerial = open(serialDevice, O_RDWR | O_NOCTTY | O_SYNC); + if (fdSerial < 0) + { + misc_print(0, "ERROR: opening %s: %s\n", serialDevice, strerror(errno)); + return -2; + } + serial2_set_baud(serialDevice, fdSerial, baud); + close(fdSerial); } + + result = misc_check_args_option(argc, argv, "FSSFONT"); + if(result && (result + 1 < argc)) + { + if(misc_check_file(argv[result + 1])) + { + socket_out = tcpsock_client_connect("127.0.0.1", 9800, fdSerial); + if (socket_out > 0) + { + char sListSF[] = "fonts\n"; + tcpsock_write(socket_out, sListSF, strlen(sListSF)); + sleep(1); + + char buf[1024]; + int TCPresult = tcpsock_read(socket_out, buf, sizeof(buf)); + if(TCPresult > 15) + { + buf[TCPresult] = 0x00; + if (strncmp("ID Name", buf, 7)) + { + char * sfNo = &buf[9]; + if (sfNo[0] == ' ') sfNo++; + char * tm = strchr(sfNo, ' '); + if (tm) *tm = 0x00; + if (strchr("1234567890", sfNo[0])) + { + printf("Unload Sounfont #%s --> '%s'\n", sfNo, tm + 1); + char sUnloadSF[30]; + sprintf(sUnloadSF, "unload %s\n", sfNo); + tcpsock_write(socket_out, sUnloadSF, strlen(sUnloadSF)); + sleep(1); + } + } + } + char sLoadSF[250]; + sprintf(sLoadSF, "load %s\n", argv[result + 1]); + printf("Loading SoundFont --> '%s'\n", argv[result + 1]); + tcpsock_write(socket_out, sLoadSF, strlen(sLoadSF)); + sleep(1); + close(socket_out); + } + else + { + printf("ERROR --> unable to connect to FluidSynth:9800\n"); + return -4; + } + } + else + { + printf("ERROR --> unable to open file '%s'\n", argv[result+1]); + return -3; + } + } + return 0; }