simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
--- a/bash-completion.sh Wed Oct 07 01:45:30 2020 +0200
+++ b/bash-completion.sh Wed Oct 07 22:29:38 2020 +0200
@@ -17,7 +17,7 @@
_relpipe_in_jack_completion_ports() {
if type relpipe-in-jack &> /dev/null && type relpipe-out-nullbyte &> /dev/null; then
- relpipe-in-jack --list-jack-ports true --list-midi-messages false 2>/dev/null \
+ relpipe-in-jack --list-ports true --list-midi-messages false 2>/dev/null \
| relpipe-out-nullbyte \
| while _relpipe_in_jack_completion_read_nullbyte "name" "input" "output" "physical" "terminal" "mine" "midi" "type"; do
if [[ "$midi" = "true" && "$output" = "true" && "$mine" = "false" ]]; then echo "$name"; fi; done
@@ -38,17 +38,19 @@
"false"
)
- if [[ "$w1" == "--jack-client-name" && "x$w0" == "x" ]]; then COMPREPLY=("'relpipe-in-jack'")
- elif [[ "$w1" == "--jack-connect-to-port" ]]; then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
- elif [[ "$w1" == "--required-jack-connections" && "x$w0" == "x" ]]; then COMPREPLY=("0")
- elif [[ "$w1" == "--list-jack-ports" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
+ if [[ "$w1" == "--client" && "x$w0" == "x" ]]; then COMPREPLY=("'relpipe-in-jack'")
+ elif [[ "$w1" == "--port" && "x$w0" == "x" ]]; then COMPREPLY=("'midi-in'")
+ elif [[ "$w1" == "--connect-to" ]]; then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
+ elif [[ "$w1" == "--required-connections" && "x$w0" == "x" ]]; then COMPREPLY=("0")
+ elif [[ "$w1" == "--list-ports" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
elif [[ "$w1" == "--list-midi-messages" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
else
OPTIONS=(
- "--jack-client-name"
- "--jack-connect-to-port"
- "--required-jack-connections"
- "--list-jack-ports"
+ "--client"
+ "--port"
+ "--connect-to"
+ "--required-connections"
+ "--list-ports"
"--list-midi-messages"
)
COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
--- a/src/CLIParser.h Wed Oct 07 01:45:30 2020 +0200
+++ b/src/CLIParser.h Wed Oct 07 22:29:38 2020 +0200
@@ -48,10 +48,11 @@
public:
- static const relpipe::common::type::StringX OPTION_JACK_CLIENT_NAME;
- static const relpipe::common::type::StringX OPTION_JACK_CONNECT_TO_PORT;
- static const relpipe::common::type::StringX OPTION_REQUIRED_JACK_CONNECTIONS;
- static const relpipe::common::type::StringX OPTION_LIST_JACK_PORTS;
+ static const relpipe::common::type::StringX OPTION_CLIENT;
+ static const relpipe::common::type::StringX OPTION_PORT;
+ static const relpipe::common::type::StringX OPTION_CONNECT_TO;
+ static const relpipe::common::type::StringX OPTION_REQUIRED_CONNECTIONS;
+ static const relpipe::common::type::StringX OPTION_LIST_PORTS;
static const relpipe::common::type::StringX OPTION_LIST_MIDI_MESSAGES;
Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
@@ -60,14 +61,16 @@
for (int i = 0; i < arguments.size();) {
relpipe::common::type::StringX option = readNext(arguments, i);
- if (option == OPTION_JACK_CLIENT_NAME) {
- c.jackClientName = readNext(arguments, i);
- } else if (option == OPTION_JACK_CONNECT_TO_PORT) {
- c.portsToConnect.push_back(readNext(arguments, i));
- } else if (option == OPTION_REQUIRED_JACK_CONNECTIONS) {
- c.requiredJackConnections = std::stoi(readNext(arguments, i));
- } else if (option == OPTION_LIST_JACK_PORTS) {
- c.listJackPorts = parseBoolean(readNext(arguments, i));
+ if (option == OPTION_CLIENT) {
+ c.client = readNext(arguments, i);
+ } else if (option == OPTION_PORT) {
+ c.port = readNext(arguments, i);
+ } else if (option == OPTION_CONNECT_TO) {
+ c.connectTo.push_back(readNext(arguments, i));
+ } else if (option == OPTION_REQUIRED_CONNECTIONS) {
+ c.requiredConnections = std::stoi(readNext(arguments, i));
+ } else if (option == OPTION_LIST_PORTS) {
+ c.listPorts = parseBoolean(readNext(arguments, i));
} else if (option == OPTION_LIST_MIDI_MESSAGES) {
c.listMidiMessages = parseBoolean(readNext(arguments, i));
} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
@@ -80,10 +83,11 @@
}
};
-const relpipe::common::type::StringX CLIParser::OPTION_JACK_CLIENT_NAME = L"--jack-client-name";
-const relpipe::common::type::StringX CLIParser::OPTION_JACK_CONNECT_TO_PORT = L"--jack-connect-to-port";
-const relpipe::common::type::StringX CLIParser::OPTION_REQUIRED_JACK_CONNECTIONS = L"--required-jack-connections";
-const relpipe::common::type::StringX CLIParser::OPTION_LIST_JACK_PORTS = L"--list-jack-ports";
+const relpipe::common::type::StringX CLIParser::OPTION_CLIENT = L"--client";
+const relpipe::common::type::StringX CLIParser::OPTION_PORT = L"--port";
+const relpipe::common::type::StringX CLIParser::OPTION_CONNECT_TO = L"--connect-to";
+const relpipe::common::type::StringX CLIParser::OPTION_REQUIRED_CONNECTIONS = L"--required-connections";
+const relpipe::common::type::StringX CLIParser::OPTION_LIST_PORTS = L"--list-ports";
const relpipe::common::type::StringX CLIParser::OPTION_LIST_MIDI_MESSAGES = L"--list-midi-messages";
}
--- a/src/Configuration.h Wed Oct 07 01:45:30 2020 +0200
+++ b/src/Configuration.h Wed Oct 07 22:29:38 2020 +0200
@@ -34,10 +34,11 @@
MIDI_OUTPUT
};
- relpipe::common::type::StringX jackClientName = L"relpipe-in-jack";
- std::vector<relpipe::common::type::StringX> portsToConnect;
- int requiredJackConnections = 0;
- relpipe::common::type::Boolean listJackPorts = false;
+ relpipe::common::type::StringX client = L"relpipe-in-jack";
+ relpipe::common::type::StringX port = L"midi-in";
+ std::vector<relpipe::common::type::StringX> connectTo;
+ int requiredConnections = 0;
+ relpipe::common::type::Boolean listPorts = false;
relpipe::common::type::Boolean listMidiMessages = true;
virtual ~Configuration() {
--- a/src/JackCommand.h Wed Oct 07 01:45:30 2020 +0200
+++ b/src/JackCommand.h Wed Oct 07 22:29:38 2020 +0200
@@ -247,7 +247,7 @@
pthread_mutex_lock(&realTimeContext.processingLock);
// Initialize JACK connection:
- std::string clientName = convertor.to_bytes(configuration.jackClientName);
+ std::string clientName = convertor.to_bytes(configuration.client);
realTimeContext.jackClient = jack_client_open(clientName.c_str(), JackNullOption, nullptr);
if (realTimeContext.jackClient == nullptr) failInConstructor(L"Could not create JACK client.");
@@ -258,7 +258,7 @@
jack_set_error_function(jackErrorCallback);
jack_set_info_function(jackErrorCallback);
- realTimeContext.jackPort = jack_port_register(realTimeContext.jackClient, "input", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
+ realTimeContext.jackPort = jack_port_register(realTimeContext.jackClient, convertor.to_bytes(configuration.port).c_str(), JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
if (realTimeContext.jackPort == nullptr) failInConstructor(L"Could not register the JACK port.");
if (mlockall(MCL_CURRENT | MCL_FUTURE)) fwprintf(stderr, L"Warning: Can not lock memory.\n");
@@ -269,7 +269,7 @@
// Connect to configured destination ports:
const char* jackPortName = jack_port_name(realTimeContext.jackPort);
- for (auto sourcePort : configuration.portsToConnect) {
+ for (auto sourcePort : configuration.connectTo) {
int error = jack_connect(realTimeContext.jackClient, convertor.to_bytes(sourcePort).c_str(), jackPortName);
if (error) failInConstructor(L"Connection to the JACK port failed: " + sourcePort);
}
@@ -281,7 +281,7 @@
using namespace relpipe::writer;
vector<AttributeMetadata> metadata;
- if (configuration.listJackPorts) listPorts(writer);
+ if (configuration.listPorts) listPorts(writer);
if (!configuration.listMidiMessages) return;
metadata.push_back({L"event", TypeId::STRING});
@@ -306,10 +306,10 @@
waitForRTCycle();
// Once the Configuration::requiredJackConnections count was reached, we will disconnect if the count drops under this level.
- if (configuration.requiredJackConnections) {
+ if (configuration.requiredConnections) {
int currentConnectionCount = jack_port_connected(realTimeContext.jackPort);
if (currentConnectionCount > maxJackPortConnections) maxJackPortConnections = currentConnectionCount;
- else if (maxJackPortConnections >= configuration.requiredJackConnections && currentConnectionCount < configuration.requiredJackConnections) break;
+ else if (maxJackPortConnections >= configuration.requiredConnections && currentConnectionCount < configuration.requiredConnections) break;
}
}
}