diff --git a/main.c b/main.c index fed4847..2c8ee57 100644 --- a/main.c +++ b/main.c @@ -22,21 +22,17 @@ along with this program. If not, see . #include #include #include -#include #include #include #include "serial.h" #include "serial2.h" -#include "config.h" #include "misc.h" #include "udpsock.h" #include "tcpsock.h" #include "alsa.h" #include "ini.h" #include "modem.h" - -#define DEFAULT_TCPFlow -1 -#define DEFAULT_TCPDTR 1 +#include "config.h" enum MODE {ModeUSBMIDI, ModeTCP, ModeUDP, ModeUSBSER, ModeMUNT, ModeMUNTGM, ModeFSYNTH, ModeUDPMUNT, ModeUDPMUNTGM, ModeUDPFSYNTH}; @@ -46,18 +42,11 @@ static int fdMidi = -1; static int fdMidiIN = -1; int MIDI_DEBUG = TRUE; -int socket_lst = -1; -int socket_out = -1; -int fdSerial = -1; int socket_in = -1; +int socket_out = -1; +int socket_lst = -1; +int fdSerial = -1; int baudRate = -1; -char MT32LCDMsg[21] = "MiSTer MidiLink! BB7"; -char fsynthSoundFont [150] = "/media/fat/linux/soundfonts/SC-55.sf2"; -char MUNTRomPath[150] = "/media/fat/linux/mt32-rom-data"; -char UDPServer [100] = ""; -char mixerControl[20] = "Master"; -char MUNTOptions[30] = ""; -char USBSerModule[100] = ""; int muntVolume = -1; int fsynthVolume = -1; int midilinkPriority = 0; @@ -67,8 +56,8 @@ int UDPBaudRate_alt = -1; int TCPBaudRate_alt = -1; int MIDIBaudRate = -1; int USBSerBaudRate = -1; -int TCPFlow = DEFAULT_TCPFlow; -int TCPDTR = DEFAULT_TCPDTR; +int TCPFlow = -1; +int TCPDTR = 1; int UDPFlow = -1; int MUNTCPUMask = -1; int FSYNTHCPUMask = -1; @@ -76,6 +65,13 @@ unsigned int DELAYSYSEX = FALSE; unsigned int UDPServerPort = 1999; unsigned int TCPServerPort = 23; unsigned int UDPServerFilterIP = FALSE; +char MT32LCDMsg[21] = "MiSTer MidiLink! BB7"; +char fsynthSoundFont [150] = "/media/fat/linux/soundfonts/SC-55.sf2"; +char MUNTRomPath[150] = "/media/fat/linux/mt32-rom-data"; +char UDPServer [100] = ""; +char mixerControl[20] = "Master"; +char MUNTOptions[30] = ""; +char USBSerModule[100] = ""; static pthread_t midiInThread; static pthread_t midiINInThread; @@ -246,7 +242,6 @@ void write_midi_packet(char * buf, int bufLen) } } - /////////////////////////////////////////////////////////////////////////////////////// // // write_socket_packet() @@ -269,7 +264,6 @@ void write_socket_packet(int sock, char * buf, int bufLen) show_debug_buf("SOCK OUT ", buf, bufLen); } - /////////////////////////////////////////////////////////////////////////////////////// // // void * udpsock_thread_function(void * x) @@ -305,7 +299,6 @@ void * udpsock_thread_function_ext (void * x) if (rdLen > 0) { write_alsa_packet(buf, rdLen); - //show_debug_buf("USOCK2 IN", buf, rdLen); } } while (TRUE); } @@ -389,33 +382,6 @@ void * serial_thread_function (void * x) } while (TRUE); } -/////////////////////////////////////////////////////////////////////////////////////// -// -// int get_softsynth_port(int softSynth) -// -// -int get_softsynth_port(int softSynth) -{ - int midiPort = alsa_get_midi_port("MT-32"); - if (midiPort == -1) - midiPort = alsa_get_midi_port("FLUID Synth"); - if (midiPort == -1) - { - switch(softSynth) - { - case MUNT: - midiPort = start_munt(); - break; - case FluidSynth: - midiPort = start_fsynth(); - break; - case -1: //do nothing. - break; - } - } - return midiPort; -} - /////////////////////////////////////////////////////////////////////////////////////// // // test_midi_device() @@ -502,6 +468,7 @@ int main(int argc, char *argv[]) misc_print(0, "\e[2J\e[H"); misc_print(0, helloStr); misc_print(0, "\n"); + misc_get_core_name(coreName, sizeof(coreName)); misc_print(0, "CORE --> '%s'\n", coreName); @@ -781,6 +748,7 @@ int main(int argc, char *argv[]) break; case ModeTCP: { + modem_set_defaults(); if(TCPFlow > 0) serial_set_flow_control(fdSerial, TCPFlow); //serial2_set_DCD(sericlDevice, fdSerial, FALSE); diff --git a/midilink b/midilink index 7b6cf0c..206979c 100755 Binary files a/midilink and b/midilink differ diff --git a/modem.c b/modem.c index ca72f00..a4f03f3 100644 --- a/modem.c +++ b/modem.c @@ -1,18 +1,3 @@ -/*-------------------------------------------------------------------- -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . ----------------------------------------------------------------------*/ - #include #include #include @@ -39,7 +24,6 @@ along with this program. If not, see . #define DEFAULT_TCPDTR 1 #define DEFAULT_TCPQuiet 0 - enum SOFTSYNTH TCPSoftSynth = FluidSynth; enum ASCIITRANS TCPAsciiTrans = DEFAULT_TCPAsciiTrans; char MP3Path[500] = "/media/fat/MP3"; @@ -56,13 +40,13 @@ int modemVolume = DEFAULT_modemVolume; int TCPQuiet = DEFAULT_TCPQuiet; int MODEMSOUND = DEFAULT_MODEMSOUND; +extern int MIDI_DEBUG; extern int CPUMASK; extern int MODEMSOUND; -extern int fdSerial; +extern int socket_in; extern int socket_out; extern int socket_lst; -extern int socket_in; -extern int MIDI_DEBUG; +extern int fdSerial; extern int baudRate; extern int TCPQuiet; extern int modemVolume; @@ -77,11 +61,12 @@ extern char * serialDevice; extern char * helloStr; extern char fsynthSoundFont[]; -static pthread_t socketInThread; +static pthread_t socketInThread; +int start_munt(); +int start_fsynth(); void show_debug_buf(char * descr, char * buf, int bufLen); void killall_softsynth(int delay); -int get_softsynth_port(int softSynth); void set_pcm_volume(int value); /////////////////////////////////////////////////////////////////////////////////////// @@ -120,6 +105,33 @@ void modem_killall_aplay(int delay) sleep(delay); } +/////////////////////////////////////////////////////////////////////////////////////// +// +// int modem_get_softsynth_port(int softSynth) +// +// +int modem_get_softsynth_port(int softSynth) +{ + int midiPort = alsa_get_midi_port("MT-32"); + if (midiPort == -1) + midiPort = alsa_get_midi_port("FLUID Synth"); + if (midiPort == -1) + { + switch(softSynth) + { + case MUNT: + midiPort = start_munt(); + break; + case FluidSynth: + midiPort = start_fsynth(); + break; + case -1: //do nothing. + break; + } + } + return midiPort; +} + /////////////////////////////////////////////////////////////////////////////////////// // // void modem_play_conenct_sound(char * tmp) @@ -291,6 +303,21 @@ void * modem_tcplst_thread_function (void * x) } while(TRUE); } +/////////////////////////////////////////////////////////////////////////////////////// +// +// void modem_set_defaults() +// +// +void modem_set_defaults() +{ + MODEMSOUND = DEFAULT_MODEMSOUND; + modemVolume = DEFAULT_modemVolume; + TCPAsciiTrans = DEFAULT_TCPAsciiTrans; + TCPTermRows = DEFAULT_TCPTermRows; + TCPFlow = DEFAULT_TCPFlow; + TCPDTR = DEFAULT_TCPDTR; + TCPQuiet = DEFAULT_TCPQuiet; +} /////////////////////////////////////////////////////////////////////////////////////// // @@ -465,7 +492,6 @@ int do_file_picker(char * pathBuf, char * fileNameBuf) return result; } - /////////////////////////////////////////////////////////////////////////////////////// // // BOOL modem_handle_at_command(char * lineBuf) @@ -627,7 +653,7 @@ int modem_handle_at_command(char * lineBuf) modem_killall_aplaymidi(0); misc_swrite(fdSerial, "\r\nMIDI --> OFF"); sleep(2); - int midiPort = get_softsynth_port(-1); + int midiPort = modem_get_softsynth_port(-1); if(midiPort != -1) { alsa_open_seq(midiPort, 0); @@ -642,7 +668,7 @@ int modem_handle_at_command(char * lineBuf) misc_swrite(fdSerial, "\r\nLoading --> FluidSynth"); killall_softsynth(3); TCPSoftSynth = FluidSynth; - get_softsynth_port(TCPSoftSynth); + modem_get_softsynth_port(TCPSoftSynth); } else if(lineBuf[5] == '2') { @@ -651,7 +677,7 @@ int modem_handle_at_command(char * lineBuf) misc_swrite(fdSerial, "\r\nLoading --> MUNT"); killall_softsynth(3); TCPSoftSynth = MUNT; - get_softsynth_port(TCPSoftSynth); + modem_get_softsynth_port(TCPSoftSynth); } else if(lineBuf[5] == 'S' && lineBuf[6] == 'F') { @@ -677,7 +703,7 @@ int modem_handle_at_command(char * lineBuf) { KILL_MP3_SLEEP; modem_killall_aplaymidi(0); - int midiPort = get_softsynth_port(TCPSoftSynth); + int midiPort = modem_get_softsynth_port(TCPSoftSynth); chdir("/root"); sprintf(tmp, "taskset %d aplaymidi --port %d \"%s/%s\" 2> /tmp/aplaymidi & ", CPUMASK, midiPort, MIDIPath, fileName);; misc_print(1, "Play MIDI --> %s\n", tmp); @@ -864,13 +890,7 @@ int modem_handle_at_command(char * lineBuf) else if (memcmp(lineBuf, "ATZ", 3) == 0) { misc_print(1, "Resetting TCP defaults...\n"); - MODEMSOUND = DEFAULT_MODEMSOUND; - modemVolume = DEFAULT_modemVolume; - TCPAsciiTrans = DEFAULT_TCPAsciiTrans; - TCPTermRows = DEFAULT_TCPTermRows; - TCPFlow = DEFAULT_TCPFlow; - TCPDTR = DEFAULT_TCPDTR; - TCPQuiet = DEFAULT_TCPQuiet; + modem_set_defaults(); TELNET_NEGOTIATE = TRUE; misc_print(1, "Reloading INI defaults...\n"); misc_get_core_name(tmp, sizeof(tmp)); diff --git a/modem.h b/modem.h index 84d0f0d..af8013a 100644 --- a/modem.h +++ b/modem.h @@ -11,7 +11,8 @@ void modem_killall_aplaymidi(int delay); void modem_killall_mpg123(int delay); void * modem_tcplst_thread_function (void * x); void * modem_tcpsock_thread_function (void * x); - +int modem_get_softsynth_port(int softSynth); +void modem_set_defaults();