option: --required-jack-connections (start after given number of port connections) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 02 Oct 2020 00:34:14 +0200
branchv_0
changeset 9 14cf28d7681c
parent 8 27579c5cdc51
child 10 6aa881c10efd
option: --required-jack-connections (start after given number of port connections)
bash-completion.sh
src/CLIParser.h
src/Configuration.h
src/JackHandler.h
--- a/bash-completion.sh	Fri Oct 02 00:18:34 2020 +0200
+++ b/bash-completion.sh	Fri Oct 02 00:34:14 2020 +0200
@@ -29,9 +29,11 @@
 
 	if   [[ "$w1" == "--TODO"                                          ]];    then COMPREPLY=($(compgen -W "${BOOLEAN[*]}" -- "$w0"))
 	elif [[ "$w1" == "--jack-client-name"             && "x$w0" == "x" ]];    then COMPREPLY=("'relpipe-out-jack'")
+	elif [[ "$w1" == "--required-jack-connections"    && "x$w0" == "x" ]];    then COMPREPLY=("1")
 	else
 		OPTIONS=(
 			"--jack-client-name"
+			"--required-jack-connections"
 		)
 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
 	fi
--- a/src/CLIParser.h	Fri Oct 02 00:18:34 2020 +0200
+++ b/src/CLIParser.h	Fri Oct 02 00:34:14 2020 +0200
@@ -49,6 +49,7 @@
 public:
 
 	static const relpipe::common::type::StringX OPTION_JACK_CLIENT_NAME;
+	static const relpipe::common::type::StringX OPTION_REQUIRED_JACK_CONNECTIONS;
 
 	Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
 		Configuration c;
@@ -58,6 +59,8 @@
 
 			if (option == OPTION_JACK_CLIENT_NAME) {
 				c.jackClientName = readNext(arguments, i);
+			} else if (option == OPTION_REQUIRED_JACK_CONNECTIONS) {
+				c.requiredJackConnections = std::stoi(readNext(arguments, i));
 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 		}
 
@@ -69,6 +72,7 @@
 };
 
 const relpipe::common::type::StringX CLIParser::OPTION_JACK_CLIENT_NAME = L"--jack-client-name";
+const relpipe::common::type::StringX CLIParser::OPTION_REQUIRED_JACK_CONNECTIONS = L"--required-jack-connections";
 
 }
 }
--- a/src/Configuration.h	Fri Oct 02 00:18:34 2020 +0200
+++ b/src/Configuration.h	Fri Oct 02 00:34:14 2020 +0200
@@ -29,6 +29,7 @@
 class Configuration {
 public:
 	relpipe::common::type::StringX jackClientName = L"relpipe-out-jack";
+	int requiredJackConnections = 1;
 
 	virtual ~Configuration() {
 	}
--- a/src/JackHandler.h	Fri Oct 02 00:18:34 2020 +0200
+++ b/src/JackHandler.h	Fri Oct 02 00:34:14 2020 +0200
@@ -97,8 +97,7 @@
 		if (jackError) throw JackException(L"Could not activate client.");
 
 		// Wait for a port connection, because it does not make much sense to send MIDI events nowhere:
-		// TODO: configurable waiting (number of connections)
-		while (jack_port_connected(jackPort) == 0) usleep(10000);
+		while (jack_port_connected(jackPort) < configuration.requiredJackConnections) usleep(10000);
 
 		// TODO: configurable auto-connection to another client/port
 	}