From 849a276043f87c7ccf0f1c324b4915603c7f2af5 Mon Sep 17 00:00:00 2001 From: zawz Date: Mon, 8 Jul 2019 05:52:07 +0200 Subject: [PATCH] Added connect and disconnect commands --- makefile => Makefile | 9 +++++---- README | 14 +++++++------- include/command.hpp | 16 ++++++++++++++++ include/device.hpp | 2 ++ src/command.cpp | 10 ++++++++++ src/device.cpp | 22 ++++++++++++++++++++++ 6 files changed, 62 insertions(+), 11 deletions(-) rename makefile => Makefile (90%) diff --git a/makefile b/Makefile similarity index 90% rename from makefile rename to Makefile index 04f6dfa..a830d1d 100644 --- a/makefile +++ b/Makefile @@ -1,7 +1,7 @@ IDIR=include SRCDIR=src ODIR=obj -BINDIR=bin +BINDIR=. NAME = zmidimap @@ -9,9 +9,7 @@ LDFLAGS = -lpthread CC=g++ CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17 -ifeq ($(RELEASE),true) - BINDIR=. -else +ifeq ($(DEBUG),true) CXXFLAGS += -g endif @@ -37,3 +35,6 @@ clean: clear: rm $(BINDIR)/$(NAME) + +install: + mv $(BINDIR)/$(NAME) /usr/bin diff --git a/README b/README index 0221620..ae46cbb 100644 --- a/README +++ b/README @@ -22,26 +22,26 @@ To scan a device's inputs use `$ aseqdump -p ` -- [COMMAND FORMAT] -- -Format is a regular shell format +Format is regular shell format -- Environment -- Note +[Note] $id: id of the note $channel: channel of the note $velocity: velocity of the note -- Controller +[Controller] $value: value of the controller (remapped) $id: id of the controller $channel: channel of the controller $rawvalue: original value of the controller -- Pitch +[Pitch] $value: value of the bend (remapped) $rawvalue: original value of the bend -- System +[System] $code: hexadecimal code of the system signal @@ -68,10 +68,10 @@ $code: hexadecimal code of the system signal -- COMMAND TAGS [Global tags] - type= + type= shell= -- -*type: type of the signal: note/controller/pitch +*type: type of the signal: note/controller/pitch/system/connect/disconnect > mandatory *shell: shell command to be executed > mandatory diff --git a/include/command.hpp b/include/command.hpp index 0cccedf..c887ded 100644 --- a/include/command.hpp +++ b/include/command.hpp @@ -47,6 +47,22 @@ public: 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 { public: diff --git a/include/device.hpp b/include/device.hpp index 68f923f..6904c0d 100644 --- a/include/device.hpp +++ b/include/device.hpp @@ -29,6 +29,8 @@ public: std::vector ctrlCommands[128]; std::vector pitchCommands; std::vector sysCommands; + std::vector connectCommands; + std::vector disconnectCommands; std::thread thread; private: diff --git a/src/command.cpp b/src/command.cpp index 45ace6e..e107778 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -30,6 +30,16 @@ PitchCommand::PitchCommand(uint8_t ch, int16_t l, int16_t h, float ml, float mh, 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) { this->shell=sh; diff --git a/src/device.cpp b/src/device.cpp index f5cb8bc..a40b163 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -117,6 +117,18 @@ bool Device::import_chunk(Chunk const& ch) shell=tch["shell"].strval(); 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 { int8_t channel; @@ -401,11 +413,21 @@ void Device::loop(Device* dev) char* buff = NULL; size_t buff_size = 0; + for( auto it : dev->connectCommands ) + { + std::thread(sh, it.shell).detach(); + } + while (getline(&buff, &buff_size, stream) > 0) { dev->run_signal(buff); } + for( auto it : dev->disconnectCommands ) + { + std::thread(sh, it.shell).detach(); + } + printf("Device '%s' disconnected\n", dev->name.c_str()); pclose(stream);