Add support for system reserved signals

This commit is contained in:
zawz 2019-06-17 17:44:20 +02:00
parent c146f55d48
commit 20dd41e434
5 changed files with 53 additions and 21 deletions

24
README
View file

@ -25,24 +25,25 @@ To scan a device's inputs use `$ aseqdump -p <client name>`
Format is a regular shell format Format is a regular shell format
-- Environment -- Environment
- Global
$channel: channel of the
- Note - Note
$id: id of the note $id: id of the note
$channel: channel of the note
$velocity: velocity of the note $velocity: velocity of the note
- Controller - Controller
$id: id of the controller
$value: value of the controller (remapped) $value: value of the controller (remapped)
$id: id of the controller
$channel: channel of the controller
$rawvalue: original value of the controller $rawvalue: original value of the controller
- Pitch bend - Pitch
$value: value of the bend (remapped) $value: value of the bend (remapped)
$rawvalue: original value of the bend $rawvalue: original value of the bend
- System
$code: hexadecimal code of the system signal
-- FILE FORMAT -- -- FILE FORMAT --
[<device>,<device>] [<device>,<device>]
@ -57,32 +58,33 @@ $rawvalue: original value of the bend
- <command> format (global): - <command> format (global):
{ {
type=<note/controller/pitch> type=<note/controller/pitch/system>
shell=<shell command> shell=<shell command>
channel=<*/x>
} }
- -
*type: type of the signal: note/controller/pitch *type: type of the signal: note/controller/pitch
> mandatory > mandatory
*shell: shell command to be executed *shell: shell command to be executed
> mandatory > mandatory
*channel: value from 0 to 16 for channel. Can use * for any channel
> optional, default *
- <command> format (note) - <command> format (note)
{ {
id=<x/x:y/*> id=<x/x:y/*>
channel=<*/x>
trigger=<x/x:y/*> trigger=<x/x:y/*>
} }
- -
*id: value from 0 to 127 referring to id of note/controller *id: value from 0 to 127 referring to id of note/controller
> optional, default 0:127 > optional, default 0:127
*channel: value from 0 to 16 for channel. Can use * for any channel
> optional, default *
*trigger: note velocity from 0 to 127 that triggers the command. Can enter an interval x:y or single value *trigger: note velocity from 0 to 127 that triggers the command. Can enter an interval x:y or single value
> optional, default 1:127 > optional, default 1:127
- <command> format (controller) - <command> format (controller)
{ {
id=<x/x:y/*> id=<x/x:y/*>
channel=<*/x>
range=<x/x:y/*> range=<x/x:y/*>
remap=<x/x:y/*> remap=<x/x:y/*>
float=<true/false> float=<true/false>
@ -90,6 +92,8 @@ $rawvalue: original value of the bend
- -
*id: value from 0 to 127 referring to id of note/controller *id: value from 0 to 127 referring to id of note/controller
> optional, default 0:127 > optional, default 0:127
*channel: value from 0 to 16 for channel. Can use * for any channel
> optional, default *
*range: controller value from 0 to 127 that triggers command. Can enter an interval x:y or single value *range: controller value from 0 to 127 that triggers command. Can enter an interval x:y or single value
> optional, default 0:127 > optional, default 0:127
*remap: remaps the range to given interval. Interval can be inversed and float *remap: remaps the range to given interval. Interval can be inversed and float

View file

@ -9,7 +9,7 @@ class NoteCommand
{ {
public: public:
NoteCommand(int8_t ch, uint8_t l, uint8_t h, std::string sh); NoteCommand(int8_t ch, uint8_t l, uint8_t h, std::string const& sh);
int8_t channel; int8_t channel;
uint8_t low; uint8_t low;
@ -21,7 +21,7 @@ class ControllerCommand
{ {
public: public:
ControllerCommand(int8_t ch, uint8_t l, uint8_t h, float ml, float mm, bool fl, std::string sh); ControllerCommand(int8_t ch, uint8_t l, uint8_t h, float ml, float mm, bool fl, std::string const& sh);
int8_t channel; int8_t channel;
uint8_t min; uint8_t min;
@ -36,7 +36,7 @@ class PitchCommand
{ {
public: public:
PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh, bool fl, std::string sh); PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh, bool fl, std::string const& sh);
int8_t channel; int8_t channel;
int16_t min; int16_t min;
@ -47,5 +47,13 @@ public:
std::string shell; std::string shell;
}; };
class SystemCommand
{
public:
SystemCommand(std::string const& sh);
std::string shell;
};
#endif //COMMAND_HPP #endif //COMMAND_HPP

View file

@ -28,7 +28,7 @@ public:
std::vector<NoteCommand> noteCommands[128]; std::vector<NoteCommand> noteCommands[128];
std::vector<ControllerCommand> ctrlCommands[128]; std::vector<ControllerCommand> ctrlCommands[128];
std::vector<PitchCommand> pitchCommands; std::vector<PitchCommand> pitchCommands;
// std::vector<Command> sysCommands; std::vector<SystemCommand> sysCommands;
std::thread thread; std::thread thread;
private: private:

View file

@ -1,6 +1,6 @@
#include "command.hpp" #include "command.hpp"
NoteCommand::NoteCommand(int8_t ch, uint8_t l, uint8_t h, std::string sh) NoteCommand::NoteCommand(int8_t ch, uint8_t l, uint8_t h, std::string const& sh)
{ {
this->channel=ch; this->channel=ch;
this->low=l; this->low=l;
@ -8,7 +8,7 @@ NoteCommand::NoteCommand(int8_t ch, uint8_t l, uint8_t h, std::string sh)
this->shell=sh; this->shell=sh;
} }
ControllerCommand::ControllerCommand(int8_t ch, uint8_t l, uint8_t h, float ml, float mh, bool fl, std::string sh) ControllerCommand::ControllerCommand(int8_t ch, uint8_t l, uint8_t h, float ml, float mh, bool fl, std::string const& sh)
{ {
this->channel=ch; this->channel=ch;
this->min=l; this->min=l;
@ -19,7 +19,7 @@ ControllerCommand::ControllerCommand(int8_t ch, uint8_t l, uint8_t h, float ml,
this->shell=sh; this->shell=sh;
} }
PitchCommand::PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh, bool fl, std::string sh) PitchCommand::PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh, bool fl, std::string const& sh)
{ {
this->channel=ch; this->channel=ch;
this->min=l; this->min=l;
@ -29,3 +29,8 @@ PitchCommand::PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh,
this->floating=fl; this->floating=fl;
this->shell=sh; this->shell=sh;
} }
SystemCommand::SystemCommand(std::string const& sh)
{
this->shell=sh;
}

View file

@ -113,7 +113,9 @@ bool Device::import_chunk(Chunk const& ch)
std::string tstr=tch["type"].strval(); std::string tstr=tch["type"].strval();
if(tstr == "system") //type system if(tstr == "system") //type system
{ {
throw std::runtime_error("System commands not implemented yet"); std::string shell;
shell=tch["shell"].strval();
this->sysCommands.push_back(SystemCommand(shell));
} }
else else
{ {
@ -237,10 +239,23 @@ void Device::run_signal(char* buff)
else if (index(buff, ':') != NULL) // MIDI command else if (index(buff, ':') != NULL) // MIDI command
{ {
if (strstr(buff, "System exclusive") != NULL) if (strstr(buff, "System exclusive") != NULL) //system exclusive
{ {
printf("%s", buff); char* val=buff+35;
//do stuff std::string strval;
while(*val != '\n')
{
if(*val != ' ')
strval += *val;
val++;
}
for( auto it : this->sysCommands )
{
std::string command="code=" + strval + ";";
command += it.shell;
std::thread(sh, command).detach();
}
} }
else else
{ {