diff options
author | Florian Jung <flo@thinkpad.(none)> | 2011-01-10 17:57:36 +0100 |
---|---|---|
committer | Florian Jung <flo@thinkpad.(none)> | 2011-01-10 18:01:25 +0100 |
commit | b34cab5dd6d4ac16a6a58589397a3d82df38b826 (patch) | |
tree | c76bde00d0ee62d3701aacbedde55ea0f3d287bc /synth | |
parent | 4b87549a645fd62107ddc5295a5027b2a5851096 (diff) |
Implemented a yet very basic in-synth-interface
The interface understands "quit" and "exit", and accepts but ignores
"reload" and "load". It catches CTRL+C.
Diffstat (limited to 'synth')
-rw-r--r-- | synth/Makefile | 2 | ||||
-rw-r--r-- | synth/in_synth_cli.cpp | 69 | ||||
-rw-r--r-- | synth/in_synth_cli.h | 6 | ||||
-rw-r--r-- | synth/main.cpp | 5 |
4 files changed, 78 insertions, 4 deletions
diff --git a/synth/Makefile b/synth/Makefile index 864c0a7..5a308e3 100644 --- a/synth/Makefile +++ b/synth/Makefile @@ -3,7 +3,7 @@ CFLAGS=-Wall -g CXXFLAGS=$(CFLAGS) LDFLAGS=-lm `pkg-config --cflags --libs jack` -OBJ=channel.o cli.o defines.o envelope.o filter.o globals.o jack.o load.o main.o note.o note_skel.o parser.o programs.o readwave.o util.o note_loader.o +OBJ=channel.o cli.o defines.o envelope.o filter.o globals.o jack.o load.o main.o note.o note_skel.o parser.o programs.o readwave.o util.o note_loader.o in_synth_cli.o BIN=synth DEPENDFILE = .depend diff --git a/synth/in_synth_cli.cpp b/synth/in_synth_cli.cpp new file mode 100644 index 0000000..7aa1d8e --- /dev/null +++ b/synth/in_synth_cli.cpp @@ -0,0 +1,69 @@ +#include <iostream> +#include <string> +#include <signal.h> + +#include "in_synth_cli.h" +#include "util.h" + +using namespace std; + +#define PROMPT "> " + +void signal_handler(int sig) +{ + cout << endl << PROMPT << flush; +} + +void do_in_synth_cli() +{ + string input; + string command; + string params; + + if (signal(2,signal_handler)==SIG_ERR) + { + cout << "WARNING: failed to set signal handler!" << endl; + } + + + 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 '"<<params<<"'"<<endl; + else + { + //TODO: load program + } + } + 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 '"<<prgstr<<"'"<<endl; + else if (file=="") + cout << "error: expected program-file to load, found nothing"<<endl; + else + { + //TODO: load program + } + } + else if (command!="") + { + cout << "error: unrecognized command '"<<command<<"'"<<endl; + } + } +} diff --git a/synth/in_synth_cli.h b/synth/in_synth_cli.h new file mode 100644 index 0000000..27ae216 --- /dev/null +++ b/synth/in_synth_cli.h @@ -0,0 +1,6 @@ +#ifndef __IN_SYNTH_CLI_H__ +#define __IN_SYNTH_CLI_H__ + +void do_in_synth_cli(); + +#endif diff --git a/synth/main.cpp b/synth/main.cpp index 1c8dd4c..8bcfe39 100644 --- a/synth/main.cpp +++ b/synth/main.cpp @@ -13,6 +13,7 @@ #include "defines.h" #include "globals.h" #include "note_loader.h" +#include "in_synth_cli.h" using namespace std; @@ -158,9 +159,7 @@ int main(int argc, char** argv) start_jack(connect_audio, connect_midi); - char tmp[10]; - gets(tmp); - cout << "end."<< endl; + do_in_synth_cli(); cleanup(); } |