zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit b956eb9f64b9ec06331761c3f103d438962b7945
parent 2cc968c0fa38ef79528740269109e18c45aa002b
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Tue,  4 May 2010 10:11:16 -0400

WIP: Nio arguments and cleanup

Diffstat:
Msrc/main.cpp | 126++++++++++++++++++++++++++++++++++++-------------------------------------------
1 file changed, 58 insertions(+), 68 deletions(-)

diff --git a/src/main.cpp b/src/main.cpp @@ -243,9 +243,7 @@ char getopt(int argc, char *argv[], const char *shortopts, int *index) result = argv[*index][1]; if(*index + 1 < argc) snprintf(winoptarguments, ARGSIZE, "%s", argv[*index + 1]); - ; } - ; (*index)++; return result; } @@ -297,33 +295,35 @@ int main(int argc, char *argv[]) {"no-gui", 2, NULL, 'U'}, {"dummy", 2, NULL, 'Y'}, {"help", 2, NULL, 'h'}, + {"output", 1, NULL, 'O'}, + {"input", 1, NULL, 'I'}, {0, 0, 0, 0} }; #endif opterr = 0; int option_index = 0, opt, exitwithhelp = 0; - char loadfile[1001]; - ZERO(loadfile, 1001); - char loadinstrument[1001]; - ZERO(loadinstrument, 1001); + string loadfile, loadinstrument, input, output; while(1) { /**\todo check this process for a small memory leak*/ #if OS_LINUX || OS_CYGWIN - opt = getopt_long(argc, argv, "l:L:r:b:o:hSDUY", opts, &option_index); + opt = getopt_long(argc, argv, "l:L:r:b:o:I:O:hSDUY", opts, &option_index); char *optarguments = optarg; #elif OS_WINDOWS - opt = getopt(argc, argv, "l:L:r:b:o:hSDUY", &option_index); + opt = getopt(argc, argv, "l:L:r:b:o:I:O:hSDUY", &option_index); char *optarguments = &winoptarguments[0]; #else #error Undefined OS #endif +#define GETOP(x) if(optarguments) x = optarguments +#define GETOPNUM(x) if(optarguments) x = atoi(optarguments) + + if(opt == -1) break; - int tmp; switch(opt) { case 'h': exitwithhelp = 1; @@ -339,52 +339,35 @@ int main(int argc, char *argv[]) noui = 1; break; case 'l': - tmp = 0; - if(optarguments != NULL) - snprintf(loadfile, 1000, "%s", optarguments); - ; + GETOP(loadfile); break; case 'L': - tmp = 0; - if(optarguments != NULL) - snprintf(loadinstrument, 1000, "%s", optarguments); - ; + GETOP(loadinstrument); break; case 'r': - tmp = 0; - if(optarguments != NULL) - tmp = atoi(optarguments); - if(tmp >= 4000) - SAMPLE_RATE = tmp; - else { + GETOPNUM(SAMPLE_RATE); + if(SAMPLE_RATE < 4000) { cerr << "ERROR:Incorrect sample rate: " << optarguments << endl; exit(1); } break; case 'b': - tmp = 0; - if(optarguments != NULL) - tmp = atoi(optarguments); - if(tmp >= 2) - SOUND_BUFFER_SIZE = tmp; - else { + GETOPNUM(SOUND_BUFFER_SIZE); + if(SOUND_BUFFER_SIZE < 2) { cerr << "ERROR:Incorrect buffer size: " << optarguments << endl; exit(1); } break; case 'o': - tmp = 0; - if(optarguments != NULL) - tmp = atoi(optarguments); - OSCIL_SIZE = tmp; + int tmp; + if(optarguments) + OSCIL_SIZE = tmp = atoi(optarguments); if(OSCIL_SIZE < MAX_AD_HARMONICS * 2) OSCIL_SIZE = MAX_AD_HARMONICS * 2; OSCIL_SIZE = (int) pow(2, ceil(log(OSCIL_SIZE - 1.0) / log(2.0))); if(tmp != OSCIL_SIZE) { - cerr - << - "\nOSCIL_SIZE is wrong (must be 2^n) or too small. Adjusting to "; - cerr << OSCIL_SIZE << "." << endl; + cerr << "OSCIL_SIZE is wrong (must be 2^n) or too small. Adjusting to " + << OSCIL_SIZE << "." << endl; } break; case 'S': @@ -393,6 +376,12 @@ int main(int argc, char *argv[]) case 'D': dump.startnow(); break; + case 'I': + GETOP(input); + break; + case 'O': + GETOP(output); + break; case '?': cerr << "ERROR:Bad option or parameter.\n" << endl; exitwithhelp = 1; @@ -401,31 +390,23 @@ int main(int argc, char *argv[]) } if(exitwithhelp != 0) { - cout << "Usage: zynaddsubfx [OPTION]\n" << endl; - cout << " -h , --help \t\t\t\t display command-line help and exit" - << endl; - cout << " -l file, --load=FILE\t\t\t loads a .xmz file" << endl; - cout << " -L file, --load-instrument=FILE\t\t loads a .xiz file" - << endl; - cout << " -r SR, --sample-rate=SR\t\t set the sample rate SR" << endl; - cout - << " -b BS, --buffer-size=SR\t\t set the buffer size (granularity)" - << endl; - cout << " -o OS, --oscil-size=OS\t\t set the ADsynth oscil. size" - << endl; - cout << " -S , --swap\t\t\t\t swap Left <--> Right" << endl; - cout << " -D , --dump\t\t\t\t Dumps midi note ON/OFF commands" << endl; - cout - << " -U , --no-gui\t\t\t\t Run ZynAddSubFX without user interface" - << endl; + cout << "Usage: zynaddsubfx [OPTION]\n\n" + << " -h , --help \t\t\t\t Display command-line help and exit\n" + << " -l file, --load=FILE\t\t\t Loads a .xmz file\n" + << " -L file, --load-instrument=FILE\t Loads a .xiz file\n" + << " -r SR, --sample-rate=SR\t\t Set the sample rate SR\n" + << " -b BS, --buffer-size=SR\t\t Set the buffer size (granularity)\n" + << " -o OS, --oscil-size=OS\t\t Set the ADsynth oscil. size\n" + << " -S , --swap\t\t\t\t Swap Left <--> Right\n" + << " -D , --dump\t\t\t\t Dumps midi note ON/OFF commands\n" + << " -U , --no-gui\t\t\t\t Run ZynAddSubFX without user interface\n" + << " -O , --output\t\t\t\t Set Output Engine\n" + << " -I , --input\t\t\t\t Set Input Engine" << endl; + #if OS_WINDOWS - cout - << - "\nWARNING: On Windows systems, only short comandline parameters works." - << endl; - cout << " eg. instead '--buffer-size=512' use '-b 512'" << endl; + cout << "nWARNING: On Windows systems, only short comandline parameters works.\n" + << " eg. instead '--buffer-size=512' use '-b 512'" << endl; #endif - cout << '\n' << endl; return 0; } @@ -445,12 +426,11 @@ int main(int argc, char *argv[]) #endif - if(strlen(loadfile) > 1) { - int tmp = master->loadXML(loadfile); + if(!loadfile.empty()) { + int tmp = master->loadXML(loadfile.c_str()); if(tmp < 0) { - fprintf(stderr, - "ERROR:Could not load master file %s .\n", - loadfile); + cerr << "ERROR: Could not load master file " << loadfile + << "." << endl; exit(1); } else { @@ -459,11 +439,11 @@ int main(int argc, char *argv[]) } } - if(strlen(loadinstrument) > 1) { + if(!loadinstrument.empty()) { int loadtopart = 0; - int tmp = master->part[loadtopart]->loadXMLinstrument(loadinstrument); + int tmp = master->part[loadtopart]->loadXMLinstrument(loadinstrument.c_str()); if(tmp < 0) { - cerr << "ERROR:Could not load instrument file " + cerr << "ERROR: Could not load instrument file " << loadinstrument << '.' << endl; exit(1); } @@ -473,6 +453,15 @@ int main(int argc, char *argv[]) } } + //if selection + // if driver_valid + // setup + // else + // warn and exit + + cout << "User Wants " << (input.empty() ? "DEFAULT" : input) << "->" + << (output.empty() ? "DEFAULT" : output) << endl; + #ifndef DISABLE_GUI if(noui == 0) { @@ -486,6 +475,7 @@ int main(int argc, char *argv[]) InitWinMidi(master); #endif + //TODO look into a conditional variable here, it seems to match usage while(Pexitprogram == 0) { #ifdef OS_LINUX usleep(100000);