summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-12-01 21:00:15 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-12-01 21:00:15 +0100
commit0a0becd384da4b0ed892dcd32285dd646ad720df (patch)
tree4097357a85aacb996a657610ccd21bc3b1fe28f8
parent5288afdaa77bf51fab48a7764b08fe7b7d500c82 (diff)
Add endpos parameter to cli.
-rw-r--r--drumgizmo/drumgizmoc.cc13
-rw-r--r--src/drumgizmo.cc28
-rw-r--r--src/drumgizmo.h10
-rw-r--r--test/kit/midimap.xml5
4 files changed, 29 insertions, 27 deletions
diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc
index 8de610f..c96736f 100644
--- a/drumgizmo/drumgizmoc.cc
+++ b/drumgizmo/drumgizmoc.cc
@@ -59,6 +59,7 @@ static const char usage_str[] =
" -I, --inputparms parmlist Set input engine parameters.\n"
" -o, --outputengine dummy|alsa|jack|sndfile Use said audio output engine.\n"
" -O, --outputparms parmlist Set output engine parameters.\n"
+" -e, --endpos Number of samples to process, -1: infinite.\n"
" -v, --version Print version information and exit.\n"
" -h, --help Print this message and exit.\n"
;
@@ -72,6 +73,7 @@ int main(int argc, char *argv[])
std::string iparms;
std::string oparms;
bool preload = false;
+ int endpos = -1;
int option_index = 0;
while(1) {
@@ -81,12 +83,13 @@ int main(int argc, char *argv[])
{"inputparms", required_argument, 0, 'I'},
{"outputengine", required_argument, 0, 'o'},
{"outputparms", required_argument, 0, 'O'},
- {"help", no_argument, 0, 'h'},
+ {"endpos", required_argument, 0, 'e'},
{"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
- c = getopt_long (argc, argv, "hvpo:O:i:I:", long_options, &option_index);
+ c = getopt_long (argc, argv, "hvpo:O:i:I:e:", long_options, &option_index);
if (c == -1)
break;
@@ -120,6 +123,10 @@ int main(int argc, char *argv[])
preload = true;
break;
+ case 'e':
+ endpos = atoi(optarg);
+ break;
+
case '?':
case 'h':
printf("%s", version_str);
@@ -246,7 +253,7 @@ int main(int argc, char *argv[])
return 1;
}
- gizmo.run();
+ gizmo.run(endpos);
printf("Quit.\n"); fflush(stdout);
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index c4ef194..fa26640 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -49,23 +49,14 @@ DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i)
DrumGizmo::~DrumGizmo()
{
- DEBUG(drumgizmo, "!");
- loader.stop();
-}
-
-std::string DrumGizmo::drumkitfile()
-{
- return kitfile;
}
bool DrumGizmo::loadkit(std::string file)
{
- if(file == this->kitfile) return 1;
+ if(file == kit.file()) return 1;
if(file == "") return 1;
- this->kitfile = file;
-
- DEBUG(drumgizmo, "loadkit(%s)\n", kitfile.c_str());
+ DEBUG(drumgizmo, "loadkit(%s)\n", file.c_str());
// Remove all queue AudioFiles from loader before we actually delete them.
loader.skip();
@@ -73,9 +64,9 @@ bool DrumGizmo::loadkit(std::string file)
// Delete all Channels, Instruments, Samples and AudioFiles.
kit.clear();
- DrumKitParser parser(kitfile, kit);
+ DrumKitParser parser(file, kit);
if(parser.parse()) {
- ERR(drumgizmo, "Drumkit parser failed: %s\n", kitfile.c_str());
+ ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str());
return false;
}
@@ -123,8 +114,6 @@ void DrumGizmo::handleMessage(Message *msg)
break;
case Message::EngineSettingsMessage:
{
- DEBUG(msg, "--------------- Send: EngineSettingsMessage ------------ \n");
-
bool mmap_loaded = false;
std::string mmapfile;
if(ie->isMidiEngine()) {
@@ -136,7 +125,7 @@ void DrumGizmo::handleMessage(Message *msg)
EngineSettingsMessage *msg = new EngineSettingsMessage();
msg->midimapfile = mmapfile;
msg->midimap_loaded = mmap_loaded;
- msg->drumkitfile = drumkitfile();
+ msg->drumkitfile = kit.file();
msg->drumkit_loaded = loader.isDone();
msg->enable_velocity_modifier = Conf::enable_velocity_modifier;
msg->velocity_modifier_falloff = Conf::velocity_modifier_falloff;
@@ -293,7 +282,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
return true;
}
-void DrumGizmo::run()
+void DrumGizmo::run(int endpos)
{
ie->start();
oe->start();
@@ -304,6 +293,7 @@ void DrumGizmo::run()
while(run(pos, samples, nsamples) == true) {
pos += nsamples;
+ if(endpos != -1 && pos >= (size_t)endpos) break;
}
ie->stop();
@@ -429,7 +419,7 @@ std::string DrumGizmo::configString()
return
"<config>\n"
- " <value name=\"drumkitfile\">" + kitfile + "</value>\n"
+ " <value name=\"drumkitfile\">" + kit.file() + "</value>\n"
" <value name=\"midimapfile\">" + mmapfile + "</value>\n"
" <value name=\"enable_velocity_modifier\">" +
bool2str(Conf::enable_velocity_modifier) + "</value>\n"
@@ -482,7 +472,7 @@ bool DrumGizmo::setConfigString(std::string cfg)
}
std::string newkit = p.value("drumkitfile");
- if(newkit != "" && drumkitfile() != newkit) {
+ if(newkit != "" && kit.file() != newkit) {
/*
if(!loadkit(p.values["drumkitfile"])) return false;
init(true);
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 2ef0aeb..37b26e5 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -54,11 +54,13 @@ public:
virtual ~DrumGizmo();
bool loadkit(std::string kitfile);
- std::string drumkitfile();
bool init(bool preload = true);
-
- void run();
+
+ /**
+ * @param endpos number of samples to process, -1 := never stop.
+ */
+ void run(int endpos);
bool run(size_t pos, sample_t *samples, size_t nsamples);
void stop();
@@ -69,8 +71,6 @@ public:
std::string configString();
bool setConfigString(std::string cfg);
- std::string kitfile;
-
void handleMessage(Message *msg);
int samplerate();
diff --git a/test/kit/midimap.xml b/test/kit/midimap.xml
new file mode 100644
index 0000000..746c745
--- /dev/null
+++ b/test/kit/midimap.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<midimap>
+ <map note="1" instr="instr1"/>
+ <map note="2" instr="instr2"/>
+</midimap>