Added connect and disconnect commands
This commit is contained in:
parent
f83c23b831
commit
849a276043
6 changed files with 62 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
IDIR=include
|
IDIR=include
|
||||||
SRCDIR=src
|
SRCDIR=src
|
||||||
ODIR=obj
|
ODIR=obj
|
||||||
BINDIR=bin
|
BINDIR=.
|
||||||
|
|
||||||
NAME = zmidimap
|
NAME = zmidimap
|
||||||
|
|
||||||
|
|
@ -9,9 +9,7 @@ LDFLAGS = -lpthread
|
||||||
|
|
||||||
CC=g++
|
CC=g++
|
||||||
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17
|
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17
|
||||||
ifeq ($(RELEASE),true)
|
ifeq ($(DEBUG),true)
|
||||||
BINDIR=.
|
|
||||||
else
|
|
||||||
CXXFLAGS += -g
|
CXXFLAGS += -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
@ -37,3 +35,6 @@ clean:
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
rm $(BINDIR)/$(NAME)
|
rm $(BINDIR)/$(NAME)
|
||||||
|
|
||||||
|
install:
|
||||||
|
mv $(BINDIR)/$(NAME) /usr/bin
|
||||||
14
README
14
README
|
|
@ -22,26 +22,26 @@ To scan a device's inputs use `$ aseqdump -p <client name>`
|
||||||
|
|
||||||
-- [COMMAND FORMAT] --
|
-- [COMMAND FORMAT] --
|
||||||
|
|
||||||
Format is a regular shell format
|
Format is regular shell format
|
||||||
|
|
||||||
-- Environment
|
-- Environment
|
||||||
|
|
||||||
- Note
|
[Note]
|
||||||
$id: id of the note
|
$id: id of the note
|
||||||
$channel: channel of the note
|
$channel: channel of the note
|
||||||
$velocity: velocity of the note
|
$velocity: velocity of the note
|
||||||
|
|
||||||
- Controller
|
[Controller]
|
||||||
$value: value of the controller (remapped)
|
$value: value of the controller (remapped)
|
||||||
$id: id of the controller
|
$id: id of the controller
|
||||||
$channel: channel of the controller
|
$channel: channel of the controller
|
||||||
$rawvalue: original value of the controller
|
$rawvalue: original value of the controller
|
||||||
|
|
||||||
- Pitch
|
[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
|
[System]
|
||||||
$code: hexadecimal code of the system signal
|
$code: hexadecimal code of the system signal
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,10 +68,10 @@ $code: hexadecimal code of the system signal
|
||||||
-- COMMAND TAGS
|
-- COMMAND TAGS
|
||||||
|
|
||||||
[Global tags]
|
[Global tags]
|
||||||
type=<note/controller/pitch/system>
|
type=<note/controller/pitch/system/connect/disconnect>
|
||||||
shell=<shell command>
|
shell=<shell command>
|
||||||
--
|
--
|
||||||
*type: type of the signal: note/controller/pitch
|
*type: type of the signal: note/controller/pitch/system/connect/disconnect
|
||||||
> mandatory
|
> mandatory
|
||||||
*shell: shell command to be executed
|
*shell: shell command to be executed
|
||||||
> mandatory
|
> mandatory
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,22 @@ public:
|
||||||
std::string shell;
|
std::string shell;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ConnectCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ConnectCommand(std::string const& sh);
|
||||||
|
|
||||||
|
std::string shell;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DisconnectCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DisconnectCommand(std::string const& sh);
|
||||||
|
|
||||||
|
std::string shell;
|
||||||
|
};
|
||||||
|
|
||||||
class SystemCommand
|
class SystemCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ public:
|
||||||
std::vector<ControllerCommand> ctrlCommands[128];
|
std::vector<ControllerCommand> ctrlCommands[128];
|
||||||
std::vector<PitchCommand> pitchCommands;
|
std::vector<PitchCommand> pitchCommands;
|
||||||
std::vector<SystemCommand> sysCommands;
|
std::vector<SystemCommand> sysCommands;
|
||||||
|
std::vector<ConnectCommand> connectCommands;
|
||||||
|
std::vector<DisconnectCommand> disconnectCommands;
|
||||||
|
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,16 @@ PitchCommand::PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh,
|
||||||
this->shell=sh;
|
this->shell=sh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectCommand::ConnectCommand(std::string const& sh)
|
||||||
|
{
|
||||||
|
this->shell=sh;
|
||||||
|
}
|
||||||
|
|
||||||
|
DisconnectCommand::DisconnectCommand(std::string const& sh)
|
||||||
|
{
|
||||||
|
this->shell=sh;
|
||||||
|
}
|
||||||
|
|
||||||
SystemCommand::SystemCommand(std::string const& sh)
|
SystemCommand::SystemCommand(std::string const& sh)
|
||||||
{
|
{
|
||||||
this->shell=sh;
|
this->shell=sh;
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,18 @@ bool Device::import_chunk(Chunk const& ch)
|
||||||
shell=tch["shell"].strval();
|
shell=tch["shell"].strval();
|
||||||
this->sysCommands.push_back(SystemCommand(shell));
|
this->sysCommands.push_back(SystemCommand(shell));
|
||||||
}
|
}
|
||||||
|
else if (tstr == "connect")
|
||||||
|
{
|
||||||
|
std::string shell;
|
||||||
|
shell=tch["shell"].strval();
|
||||||
|
this->connectCommands.push_back(ConnectCommand(shell));
|
||||||
|
}
|
||||||
|
else if (tstr == "disconnect")
|
||||||
|
{
|
||||||
|
std::string shell;
|
||||||
|
shell=tch["shell"].strval();
|
||||||
|
this->disconnectCommands.push_back(DisconnectCommand(shell));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int8_t channel;
|
int8_t channel;
|
||||||
|
|
@ -401,11 +413,21 @@ void Device::loop(Device* dev)
|
||||||
char* buff = NULL;
|
char* buff = NULL;
|
||||||
size_t buff_size = 0;
|
size_t buff_size = 0;
|
||||||
|
|
||||||
|
for( auto it : dev->connectCommands )
|
||||||
|
{
|
||||||
|
std::thread(sh, it.shell).detach();
|
||||||
|
}
|
||||||
|
|
||||||
while (getline(&buff, &buff_size, stream) > 0)
|
while (getline(&buff, &buff_size, stream) > 0)
|
||||||
{
|
{
|
||||||
dev->run_signal(buff);
|
dev->run_signal(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for( auto it : dev->disconnectCommands )
|
||||||
|
{
|
||||||
|
std::thread(sh, it.shell).detach();
|
||||||
|
}
|
||||||
|
|
||||||
printf("Device '%s' disconnected\n", dev->name.c_str());
|
printf("Device '%s' disconnected\n", dev->name.c_str());
|
||||||
|
|
||||||
pclose(stream);
|
pclose(stream);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue