Output to mim format + bugfixes
This commit is contained in:
parent
9e984f6d38
commit
9efd8cf9af
6 changed files with 81 additions and 63 deletions
28
example.mim
28
example.mim
|
|
@ -1,49 +1,43 @@
|
|||
|
||||
|
||||
Device "Launch Control"
|
||||
|
||||
//display value 0:127 for knobs 21-28
|
||||
Command controller
|
||||
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
|
||||
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
|
||||
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
|
||||
id=42
|
||||
channel=1
|
||||
range=0:63
|
||||
remap=0:1
|
||||
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
|
||||
id=42
|
||||
channel=1
|
||||
range=64:127
|
||||
remap=1:0
|
||||
float=true
|
||||
shell=echo "Knob #$id ch1:$value r:$rawvalue"
|
||||
shell='echo "Knob #$id ch1:$value r:$rawvalue"'
|
||||
|
||||
|
||||
Device "Launchpad S"
|
||||
|
||||
//display any note pressed and its velocity
|
||||
Command note
|
||||
shell=echo "Note $id on velocity:$velocity"
|
||||
shell=echo Note $id on velocity:$velocity
|
||||
|
||||
//display any note off
|
||||
Command note
|
||||
trigger=0
|
||||
shell=echo "Note $id off"
|
||||
shell=echo Note $id off
|
||||
|
|
|
|||
26
example.zfd
26
example.zfd
|
|
@ -10,46 +10,38 @@
|
|||
//displays value 0:127 for knobs 21-28
|
||||
type=controller
|
||||
id=21:28
|
||||
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"
|
||||
shell='echo "Knob #$id ch$channel:$value"'
|
||||
},
|
||||
{
|
||||
//KNOB L2
|
||||
//displays value -100:100 for knob 42 on channel 0
|
||||
//displays value -100:100 for knob 41 on channel 0
|
||||
type=controller
|
||||
id=42
|
||||
channel=0
|
||||
remap=-100:100
|
||||
shell=echo "Knob #$id ch0:$value r:$rawvalue"
|
||||
shell='echo "Knob #$id ch0:$value r:$rawvalue"'
|
||||
},
|
||||
{
|
||||
//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
|
||||
id=42
|
||||
channel=1
|
||||
range=0:63
|
||||
remap=0:1
|
||||
float=true
|
||||
shell=echo "Knob #$id ch1:$value r:$rawvalue"
|
||||
shell='echo "Knob #$id ch1:$value r:$rawvalue"'
|
||||
},
|
||||
{
|
||||
//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
|
||||
id=42
|
||||
channel=1
|
||||
range=64:127
|
||||
remap=1:0
|
||||
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
|
||||
type=note
|
||||
shell=echo "Note $id on velocity:$velocity"
|
||||
shell=echo Note $id on velocity:$velocity
|
||||
},
|
||||
{
|
||||
// ANY NOTE OFF
|
||||
type=note
|
||||
trigger=0
|
||||
shell=echo "Note $id off"
|
||||
shell=echo Note $id off
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
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);
|
||||
|
||||
bool is_mim(const std::string& str);
|
||||
|
|
|
|||
|
|
@ -98,6 +98,29 @@ ztd::chunkdat mimtochk(std::string mim)
|
|||
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)
|
||||
{
|
||||
unsigned int i=0;
|
||||
|
|
|
|||
63
src/main.cpp
63
src/main.cpp
|
|
@ -75,11 +75,11 @@ void load_filedat(ztd::filedat& file, bool from_stdin, std::string const& path)
|
|||
file.setFilePath(path);
|
||||
std::string str=file_strimport(path);
|
||||
|
||||
if(options.find("zfd")->activated)
|
||||
if(options["zfd"])
|
||||
{
|
||||
file.data() = str;
|
||||
}
|
||||
else if(options.find("mim")->activated)
|
||||
else if(options["mim"])
|
||||
{
|
||||
file.data() = mimtochk(str);
|
||||
}
|
||||
|
|
@ -100,11 +100,11 @@ void load_filedat(ztd::filedat& file, bool from_stdin, std::string const& path)
|
|||
{
|
||||
file.setFilePath(path);
|
||||
log("Loading map file '" + path + "'\n");
|
||||
if(options.find("zfd")->activated)
|
||||
if(options["zfd"])
|
||||
{
|
||||
file.import_file();
|
||||
}
|
||||
else if(options.find("mim")->activated)
|
||||
else if(options["mim"])
|
||||
{
|
||||
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('m',"mim", false, "Read file in mim 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("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"));
|
||||
|
|
@ -180,74 +181,72 @@ int main(int argc, char* argv[])
|
|||
stop(1);
|
||||
}
|
||||
|
||||
ztd::option* op=nullptr;
|
||||
//exit options
|
||||
if( options.find('h')->activated )
|
||||
if( options['h'] )
|
||||
{
|
||||
help();
|
||||
stop(0);
|
||||
}
|
||||
if( options.find('v')->activated )
|
||||
if( options['v'] )
|
||||
{
|
||||
version();
|
||||
stop(0);
|
||||
}
|
||||
if( options.find("mim-format")->activated )
|
||||
if( options["mim-format"] )
|
||||
{
|
||||
printf("%s\n", MIM_FORMAT);
|
||||
stop(0);
|
||||
}
|
||||
if( options.find("zfd-format")->activated )
|
||||
if( options["zfd-format"] )
|
||||
{
|
||||
printf("%s\n", ZFD_FORMAT);
|
||||
stop(0);
|
||||
}
|
||||
if( options.find("command-tags")->activated )
|
||||
if( options["command-tags"] )
|
||||
{
|
||||
printf("%s\n", COMMAND_TAGS);
|
||||
stop(0);
|
||||
}
|
||||
if( options.find("shell-format")->activated )
|
||||
if( options["shell-format"] )
|
||||
{
|
||||
printf("%s\n", SHELL_FORMAT);
|
||||
stop(0);
|
||||
}
|
||||
if( options.find('L')->activated )
|
||||
if( options['L'] )
|
||||
{
|
||||
ztd::shr("aseqdump -l");
|
||||
stop(0);
|
||||
}
|
||||
if( options.find('l')->activated )
|
||||
if( options['l'] )
|
||||
{
|
||||
ztd::shr(LIST_COMMAND);
|
||||
stop(0);
|
||||
}
|
||||
|
||||
op = options.find('p');
|
||||
if( op->activated )
|
||||
if( options['p'] )
|
||||
{
|
||||
option_p(op->argument);
|
||||
option_p(options['p']);
|
||||
stop(0);
|
||||
}
|
||||
|
||||
if (options.find('o')->activated)
|
||||
if (options['o'])
|
||||
{
|
||||
log_on=false;
|
||||
}
|
||||
|
||||
//behavioral options
|
||||
if( options.find("no-reload")->activated )
|
||||
if( options["no-reload"] )
|
||||
{
|
||||
autoreload=false;
|
||||
}
|
||||
if( options.find("no-log")->activated )
|
||||
if( options["no-log"] )
|
||||
{
|
||||
log_on=false;
|
||||
}
|
||||
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
|
||||
|
|
@ -274,14 +273,24 @@ int main(int argc, char* argv[])
|
|||
//load
|
||||
load_filedat(file, from_stdin, filepath);
|
||||
//output
|
||||
if(options.find('o')->activated)
|
||||
if(options['o'])
|
||||
{
|
||||
if(options.find('o')->argument == "-") {
|
||||
std::cout << file.strval(aligner) << std::endl;
|
||||
std::string ret;
|
||||
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 {
|
||||
file.setFilePath(options.find('o')->argument);
|
||||
file.export_file();
|
||||
std::ofstream output(options['o']);
|
||||
if(!output)
|
||||
{
|
||||
std::cerr << "Cannot write to file '" + options['o'].argument + "'\n";
|
||||
return 1;
|
||||
}
|
||||
output << ret << std::endl ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,6 @@ void announce_loop()
|
|||
}
|
||||
|
||||
int ret = WEXITSTATUS(ztd::pclose2(stream, announce_thread_pid));
|
||||
if( ret != 0 )
|
||||
throw std::runtime_error("ALSA error");
|
||||
|
||||
if(buff != NULL)
|
||||
free(buff);
|
||||
|
|
|
|||
Loading…
Reference in a new issue