summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-29 10:41:28 +0100
committerDavid Robillard <d@drobilla.net>2020-11-29 12:00:37 +0100
commit6d71c2f83b7fef4956f04e277a905d45de249745 (patch)
tree39b11d92856d98d798529061ac0f8957dc81109d /src/main.cpp
parent15004f61bf9f330b959a815465bdda09c66ec9a4 (diff)
downloadpatchage-6d71c2f83b7fef4956f04e277a905d45de249745.tar.gz
patchage-6d71c2f83b7fef4956f04e277a905d45de249745.tar.bz2
patchage-6d71c2f83b7fef4956f04e277a905d45de249745.zip
Move command line handling to main
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 6ad255f..db4721b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,12 +25,16 @@
# include <string>
#endif
+#include "Options.hpp"
#include "Patchage.hpp"
+#include "patchage_config.h"
#include <glibmm/exception.h>
#include <iostream>
+namespace {
+
#ifdef __APPLE__
void
set_bundle_environment()
@@ -67,6 +71,19 @@ set_bundle_environment()
}
#endif
+void
+print_usage()
+{
+ std::cout << "Usage: patchage [OPTION]...\n";
+ std::cout << "Visually connect JACK and ALSA Audio and MIDI ports.\n\n";
+ std::cout << "Options:\n";
+ std::cout << " -h, --help Display this help and exit.\n";
+ std::cout << " -A, --no-alsa Do not automatically attach to ALSA.\n";
+ std::cout << " -J, --no-jack Do not automatically attack to JACK.\n";
+}
+
+} // namespace
+
int
main(int argc, char** argv)
{
@@ -79,8 +96,33 @@ main(int argc, char** argv)
Glib::thread_init();
Gtk::Main app(argc, argv);
-
- Patchage patchage(argc, argv);
+ ++argv;
+ --argc;
+
+ // Parse command line options
+ Options options;
+ while (argc > 0) {
+ if (!strcmp(*argv, "-h") || !strcmp(*argv, "--help")) {
+ print_usage();
+ return 0;
+ }
+
+ if (!strcmp(*argv, "-A") || !strcmp(*argv, "--no-alsa")) {
+ options.alsa_driver_autoattach = false;
+ } else if (!strcmp(*argv, "-J") || !strcmp(*argv, "--no-jack")) {
+ options.jack_driver_autoattach = false;
+ } else {
+ std::cerr << "patchage: invalid option -- '" << *argv << "'\n";
+ print_usage();
+ return 1;
+ }
+
+ ++argv;
+ --argc;
+ }
+
+ // Run until main loop is finished
+ Patchage patchage(options);
Gtk::Main::run(*patchage.window());
patchage.save();