Output to mim format + bugfixes

This commit is contained in:
zawz 2020-05-22 16:15:48 +02:00
parent 9e984f6d38
commit 9efd8cf9af
6 changed files with 81 additions and 63 deletions

View file

@ -1,49 +1,43 @@
Device "Launch Control" Device "Launch Control"
//display value 0:127 for knobs 21-28 //display value 0:127 for knobs 21-28
Command controller Command controller
id=21:28 id=21:28
shell=echo "Knob #$id ch$channel:$value" shell='echo "Knob #$id ch$channel:$value"'
//display value 0:127 for knob 41 from any channel //display value -100:100 for knob 41 on channel 0
Command controller Command controller
id=41 id=41
channel=*
shell=echo "Knob #$id ch$channel:$value"
//display value -100:100 for knob 42 on channel 0
Command controller
id=42
channel=0 channel=0
remap=-100:100 remap=-100:100
shell=echo "Knob #$id ch0:$value r:$rawvalue" shell='echo "Knob #$id ch0:$value r:$rawvalue"'
//display value 0:1:0 for knob 42 on channel 1 (first half) //display value 0:1:0 for knob 41 on channel 1 (first half)
Command controller Command controller
id=42 id=42
channel=1 channel=1
range=0:63 range=0:63
remap=0:1 remap=0:1
float=true float=true
shell=echo "Knob #$id ch1:$value r:$rawvalue" shell='echo "Knob #$id ch1:$value r:$rawvalue"'
//display value 0:1:0 for knob 42 on channel 1 (second half) //display value 0:1:0 for knob 41 on channel 1 (second half)
Command controller Command controller
id=42 id=42
channel=1 channel=1
range=64:127 range=64:127
remap=1:0 remap=1:0
float=true float=true
shell=echo "Knob #$id ch1:$value r:$rawvalue" shell='echo "Knob #$id ch1:$value r:$rawvalue"'
Device "Launchpad S" Device "Launchpad S"
//display any note pressed and its velocity
Command note Command note
shell=echo "Note $id on velocity:$velocity" shell=echo Note $id on velocity:$velocity
//display any note off
Command note Command note
trigger=0 trigger=0
shell=echo "Note $id off" shell=echo Note $id off

View file

@ -10,46 +10,38 @@
//displays value 0:127 for knobs 21-28 //displays value 0:127 for knobs 21-28
type=controller type=controller
id=21:28 id=21:28
shell=echo "Knob #$id ch$channel:$value" shell='echo "Knob #$id ch$channel:$value"'
},
// KNOBS LOW
{
//KNOB L1
//displays value 0:127 for knob 41 from any channel
type=controller
id=41
shell=echo "Knob #$id ch$channel:$value"
}, },
{ {
//KNOB L2 //KNOB L2
//displays value -100:100 for knob 42 on channel 0 //displays value -100:100 for knob 41 on channel 0
type=controller type=controller
id=42 id=42
channel=0 channel=0
remap=-100:100 remap=-100:100
shell=echo "Knob #$id ch0:$value r:$rawvalue" shell='echo "Knob #$id ch0:$value r:$rawvalue"'
}, },
{ {
//KNOB L3 H1 //KNOB L3 H1
//displays value 0:1:0 for knob 42 on channel 1 (first half) //displays value 0:1:0 for knob 41 on channel 1 (first half)
type=controller type=controller
id=42 id=42
channel=1 channel=1
range=0:63 range=0:63
remap=0:1 remap=0:1
float=true float=true
shell=echo "Knob #$id ch1:$value r:$rawvalue" shell='echo "Knob #$id ch1:$value r:$rawvalue"'
}, },
{ {
//KNOB L3 H2 //KNOB L3 H2
//displays value 0:1:0 for knob 42 on channel 1 (second half) //displays value 0:1:0 for knob 41 on channel 1 (second half)
type=controller type=controller
id=42 id=42
channel=1 channel=1
range=64:127 range=64:127
remap=1:0 remap=1:0
float=true float=true
shell=echo "Knob #$id ch1:$value r:$rawvalue" shell='echo "Knob #$id ch1:$value r:$rawvalue"'
} }
] ]
} }
@ -61,13 +53,13 @@
{ {
// ANY NOTE ON // ANY NOTE ON
type=note type=note
shell=echo "Note $id on velocity:$velocity" shell=echo Note $id on velocity:$velocity
}, },
{ {
// ANY NOTE OFF // ANY NOTE OFF
type=note type=note
trigger=0 trigger=0
shell=echo "Note $id off" shell=echo Note $id off
} }
] ]
} }

View file

@ -5,6 +5,8 @@
ztd::chunkdat mimtochk(std::string mim); ztd::chunkdat mimtochk(std::string mim);
std::string chktomim(ztd::chunkdat const& chk, std::string const& aligner);
std::string file_strimport(const std::string& path); std::string file_strimport(const std::string& path);
bool is_mim(const std::string& str); bool is_mim(const std::string& str);

View file

@ -98,6 +98,29 @@ ztd::chunkdat mimtochk(std::string mim)
return chk; return chk;
} }
std::string chktomim(ztd::chunkdat const& chk, std::string const& aligner)
{
std::string ret;
for(int i=0 ; i<chk.listSize() ; i++)
{
ztd::chunkdat& device=chk[i];
ret += "Device " + device.subChunkRef("name").str() + "\n\n";
for(int j=0 ; j < device["commands"].listSize() ; j++)
{
ztd::chunkdat command=device["commands"][j];
ret += aligner + "Command " + command["type"].str() + '\n';
command.erase("type");
for(auto it : command.getmap())
{
ret += aligner+aligner + it.first + '=' + it.second->str() + '\n';
}
ret += '\n';
// ret += command.str(2, aligner) + '\n';
}
}
return ret;
}
bool is_mim(const std::string& str) bool is_mim(const std::string& str)
{ {
unsigned int i=0; unsigned int i=0;

View file

@ -75,11 +75,11 @@ void load_filedat(ztd::filedat& file, bool from_stdin, std::string const& path)
file.setFilePath(path); file.setFilePath(path);
std::string str=file_strimport(path); std::string str=file_strimport(path);
if(options.find("zfd")->activated) if(options["zfd"])
{ {
file.data() = str; file.data() = str;
} }
else if(options.find("mim")->activated) else if(options["mim"])
{ {
file.data() = mimtochk(str); file.data() = mimtochk(str);
} }
@ -100,11 +100,11 @@ void load_filedat(ztd::filedat& file, bool from_stdin, std::string const& path)
{ {
file.setFilePath(path); file.setFilePath(path);
log("Loading map file '" + path + "'\n"); log("Loading map file '" + path + "'\n");
if(options.find("zfd")->activated) if(options["zfd"])
{ {
file.import_file(); file.import_file();
} }
else if(options.find("mim")->activated) else if(options["mim"])
{ {
file.data() = mimtochk(file_strimport(path)); file.data() = mimtochk(file_strimport(path));
} }
@ -161,7 +161,8 @@ int main(int argc, char* argv[])
options.add(ztd::option("\r [Map file]")); options.add(ztd::option("\r [Map file]"));
options.add(ztd::option('m',"mim", false, "Read file in mim format")); options.add(ztd::option('m',"mim", false, "Read file in mim format"));
options.add(ztd::option('z',"zfd", false, "Read file in zfd format")); options.add(ztd::option('z',"zfd", false, "Read file in zfd format"));
options.add(ztd::option('o',"output", true, "Output the resulting zfd map to file. - for stdout", "file")); options.add(ztd::option('o',"output", true, "Output the resulting map to file", "file"));
options.add(ztd::option("out-zfd", false, "Output in zfd format"));
options.add(ztd::option("aligner", true, "String to use for aligning output map format. Default \\t", "string")); options.add(ztd::option("aligner", true, "String to use for aligning output map format. Default \\t", "string"));
options.add(ztd::option("no-reload", false, "Disable auto reloading when file changes are detected")); options.add(ztd::option("no-reload", false, "Disable auto reloading when file changes are detected"));
options.add(ztd::option("\rIf no file format is specified, the program will try to guess the format")); options.add(ztd::option("\rIf no file format is specified, the program will try to guess the format"));
@ -180,74 +181,72 @@ int main(int argc, char* argv[])
stop(1); stop(1);
} }
ztd::option* op=nullptr;
//exit options //exit options
if( options.find('h')->activated ) if( options['h'] )
{ {
help(); help();
stop(0); stop(0);
} }
if( options.find('v')->activated ) if( options['v'] )
{ {
version(); version();
stop(0); stop(0);
} }
if( options.find("mim-format")->activated ) if( options["mim-format"] )
{ {
printf("%s\n", MIM_FORMAT); printf("%s\n", MIM_FORMAT);
stop(0); stop(0);
} }
if( options.find("zfd-format")->activated ) if( options["zfd-format"] )
{ {
printf("%s\n", ZFD_FORMAT); printf("%s\n", ZFD_FORMAT);
stop(0); stop(0);
} }
if( options.find("command-tags")->activated ) if( options["command-tags"] )
{ {
printf("%s\n", COMMAND_TAGS); printf("%s\n", COMMAND_TAGS);
stop(0); stop(0);
} }
if( options.find("shell-format")->activated ) if( options["shell-format"] )
{ {
printf("%s\n", SHELL_FORMAT); printf("%s\n", SHELL_FORMAT);
stop(0); stop(0);
} }
if( options.find('L')->activated ) if( options['L'] )
{ {
ztd::shr("aseqdump -l"); ztd::shr("aseqdump -l");
stop(0); stop(0);
} }
if( options.find('l')->activated ) if( options['l'] )
{ {
ztd::shr(LIST_COMMAND); ztd::shr(LIST_COMMAND);
stop(0); stop(0);
} }
op = options.find('p'); if( options['p'] )
if( op->activated )
{ {
option_p(op->argument); option_p(options['p']);
stop(0); stop(0);
} }
if (options.find('o')->activated) if (options['o'])
{ {
log_on=false; log_on=false;
} }
//behavioral options //behavioral options
if( options.find("no-reload")->activated ) if( options["no-reload"] )
{ {
autoreload=false; autoreload=false;
} }
if( options.find("no-log")->activated ) if( options["no-log"] )
{ {
log_on=false; log_on=false;
} }
std::string aligner="\t"; std::string aligner="\t";
if(options.find("aligner")->activated) if(options["aligner"])
{ {
aligner=options.find("aligner")->argument; aligner=options["aligner"].argument;
} }
//no argument: display help //no argument: display help
@ -274,14 +273,24 @@ int main(int argc, char* argv[])
//load //load
load_filedat(file, from_stdin, filepath); load_filedat(file, from_stdin, filepath);
//output //output
if(options.find('o')->activated) if(options['o'])
{ {
if(options.find('o')->argument == "-") { std::string ret;
std::cout << file.strval(aligner) << std::endl; if(options["out-zfd"])
ret=file.data().str(0, aligner);
else
ret=chktomim(file.data(), aligner);
if(options['o'].argument == "-") {
std::cout << ret << std::endl;
} }
else { else {
file.setFilePath(options.find('o')->argument); std::ofstream output(options['o']);
file.export_file(); if(!output)
{
std::cerr << "Cannot write to file '" + options['o'].argument + "'\n";
return 1;
}
output << ret << std::endl ;
} }
return 0; return 0;
} }

View file

@ -97,8 +97,6 @@ void announce_loop()
} }
int ret = WEXITSTATUS(ztd::pclose2(stream, announce_thread_pid)); int ret = WEXITSTATUS(ztd::pclose2(stream, announce_thread_pid));
if( ret != 0 )
throw std::runtime_error("ALSA error");
if(buff != NULL) if(buff != NULL)
free(buff); free(buff);