From 57758986e77e625e1ddf8adab7d0eeb4c835ed49 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 1 Jun 2025 22:18:44 +0200 Subject: [PATCH] added -j argument to set the jack name --- src/ampswitch.cpp | 15 +++++++++++---- src/ampswitch.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ampswitch.cpp b/src/ampswitch.cpp index 07ba998..ac15f0d 100644 --- a/src/ampswitch.cpp +++ b/src/ampswitch.cpp @@ -45,6 +45,7 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) m_pipe[0] = -1; m_pipe[1] = -1; m_connected = false; + m_jackname = "Ampswitch"; m_client = NULL; m_port = NULL; m_samplerate = 0; @@ -56,6 +57,7 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) struct option longoptions[] = { + {"jack-name", required_argument, NULL, 'j'}, {"on-command", required_argument, NULL, 'n'}, {"off-command", required_argument, NULL, 'f'}, {"switch-time", required_argument, NULL, 's'}, @@ -65,12 +67,16 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[]) {0, 0, 0, 0} }; - const char* shortoptions = "n:f:s:t:kh"; + const char* shortoptions = "j:n:f:s:t:kh"; int c; int optionindex = 0; while ((c = getopt_long(argc, argv, shortoptions, longoptions, &optionindex)) != -1) { - if (c == 'n') + if (c == 'j') + { + m_jackname = optarg; + } + else if (c == 'n') { m_oncommand = optarg; } @@ -218,6 +224,7 @@ void CAmpSwitch::PrintHelpMessage() "\n" " options:\n" "\n" + " -j, --jack-name name of the jack client\n" " -n, --on-command command to execute when switching on\n" " -f, --off-command command to execute when switching off\n" " -s, --switch-time minimum number of seconds between switches\n" @@ -243,7 +250,7 @@ void CAmpSwitch::Connect() bool CAmpSwitch::JackConnect() { //try to connect to jackd - m_client = jack_client_open("Ampswitch", JackNoStartServer, NULL); + m_client = jack_client_open(m_jackname, JackNoStartServer, NULL); if (m_client == NULL) { printf("ERROR: Unable to connect to jack\n"); @@ -287,7 +294,7 @@ bool CAmpSwitch::JackConnect() return false; } - printf("Connected to jack\n"); + printf("Connected to jack with name %s\n", m_jackname); return true; } diff --git a/src/ampswitch.h b/src/ampswitch.h index 3851e53..4cf90e4 100644 --- a/src/ampswitch.h +++ b/src/ampswitch.h @@ -60,6 +60,7 @@ class CAmpSwitch int m_pipe[2]; bool m_connected; + const char* m_jackname; jack_client_t* m_client; jack_port_t* m_port; int m_samplerate;