From b34cab5dd6d4ac16a6a58589397a3d82df38b826 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 10 Jan 2011 17:57:36 +0100 Subject: 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. --- synth/Makefile | 2 +- synth/in_synth_cli.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ synth/in_synth_cli.h | 6 +++++ synth/main.cpp | 5 ++-- 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 synth/in_synth_cli.cpp create mode 100644 synth/in_synth_cli.h 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 +#include +#include + +#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 '"<