#include #include #include #include #include #include "in_synth_cli.h" #include "util.h" #include "communication.h" #include "globals.h" #include "load.h" using namespace std; #define PROMPT "> " void signal_handler(int sig) { cout << endl << PROMPT << flush; } void do_request(int prg_no, bool susp) { pthread_mutex_lock(&suspend_request_mutex); suspend_request.prog=prg_no; suspend_request.suspend=susp; suspend_request.done=false; pthread_mutex_unlock(&suspend_request_mutex); while (true) { usleep(100000); pthread_mutex_lock(&suspend_request_mutex); if (suspend_request.done) { pthread_mutex_unlock(&suspend_request_mutex); break; } else pthread_mutex_unlock(&suspend_request_mutex); } } void lock_and_load_program(int prg_no, string file) { do_request(prg_no, true); if (load_program(file,program_settings[prg_no])) { cout << "success" << endl; programfile[prg_no]=file; } else cout << "failed" << endl; for (int i=0;imaybe_reload_program(prg_no); do_request(prg_no, false); } void do_in_synth_cli() { string input; string command; string params; int num; if (signal(2,signal_handler)==SIG_ERR) output_warning("WARNING: failed to set signal handler in the in-synth-cli. pressing enter will\n" " kill the synth, so be careful. this is not fatal"); fatal_warnings=false; while (true) { cout << PROMPT << flush; getline(cin,input); input=trim_spaces(input); command=trim_spaces(str_before(input,' ',input)); params=trim_spaces(str_after(input,' ',"")); if ((command=="exit") || (command=="quit")) break; else if (command=="reload") { if ((!isnum(params)) || (params=="")) cout << "error: expected program-number, found '"<=0) && (num<128)) { num=atoi(params.c_str()); lock_and_load_program(num, programfile[num]); } else cout << "error: program-number must be one of 0..127" << endl; } } else if (command=="load") { string prgstr, file; prgstr=trim_spaces(str_before(params,' ',params)); file=trim_spaces(str_after(params,' ',"")); if ((!isnum(prgstr)) || (prgstr=="")) cout << "error: expected program-number, found '"<=0) && (num<128)) { lock_and_load_program(num, file); programfile[num]=file; } else cout << "error: program-number must be one of 0..127" << endl; } } else if (command=="panic") { if ((params=="") || (params=="all")) for (int i=0;ipanic(); else if (isnum(params)) { num=atoi(params.c_str()); if ((num>=0) && (numpanic(); else cout << "error: channel-number must be one of 0.."<release_all(); else if (isnum(params)) { num=atoi(params.c_str()); if ((num>=0) && (numrelease_all(); else cout << "error: channel-number must be one of 0.."<=0) && (num<128)) { if (chanstr=="") for (int i=0;ikill_program(num); else { int num2=atoi(chanstr.c_str()); if ((num2>=0)&&(num2kill_program(num); else cout << "error: channel-number must be one of 0.."<=0) && (num=0) channel[num]->set_n_voices(num2); else cout << "error: limit must be a positive number, zero or 'all'"<reset_controllers(); else if (isnum(params)) { num=atoi(params.c_str()); if ((num>=0) && (numreset_controllers(); else cout << "error: channel-number must be one of 0.."<=0) && (num=0) && (num2<128)) channel[num]->set_program(num2); else cout << "error: program must be one of 0..127"<=0) && (num=0) && (num2<128))) cout << "error: controller must be one of 0..127"<=0) && (val<128))) cout << "error: value must be one of 0..127"<set_controller(num2,val); } else cout << "error: channel-number must be one of 0.."<=0) && (num=0) channel[num]->set_portamento_time_sec(num2); else cout << "error: portamento time must be positive"<=0) && (numset_portamento(127); else //off channel[num]->set_portamento(0); } else cout << "error: channel-number must be one of 0.."<=0) && (num=0) && (num2<128)) channel[num]->set_volume(num2); else cout << "error: volume must be one of 0..127"<=0) && (num=0) && (num2<128)) channel[num]->set_balance(num2); else cout << "error: balance must be one of 0..127"<=0) && (numset_hold_pedal(onstr=="on"); else cout << "error: channel-number must be one of 0.."<=0) && (numset_sostenuto_pedal(onstr=="on"); else cout << "error: channel-number must be one of 0.."<=0) && (numset_soft_pedal(onstr=="on"); else cout << "error: channel-number must be one of 0.."<=0) && (numset_legato_pedal(onstr=="on"); else cout << "error: channel-number must be one of 0.."<