Fix DSP load sorting with inactive plugins
[ardour.git] / gtk2_ardour / opts.cc
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2006-2007 Sampo Savolainen <v2@iki.fi>
4  * Copyright (C) 2006-2019 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
6  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2015-2017 Len Ovens <len@ovenwerks.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include <getopt.h>
26 #include <string.h>
27 #include <iostream>
28 #include <cstdlib>
29
30 #include "ardour/debug.h"
31 #include "ardour/session.h"
32
33 #ifndef NDEBUG // "-H"
34 #include "processor_box.h"
35 #endif
36
37 #include "opts.h"
38
39 #include "pbd/i18n.h"
40
41 using namespace std;
42
43 string ARDOUR_COMMAND_LINE::session_name = "";
44 string ARDOUR_COMMAND_LINE::backend_client_name = "ardour";
45 bool  ARDOUR_COMMAND_LINE::show_key_actions = false;
46 bool  ARDOUR_COMMAND_LINE::show_actions = false;
47 bool ARDOUR_COMMAND_LINE::no_splash = false;
48 bool ARDOUR_COMMAND_LINE::just_version = false;
49 bool ARDOUR_COMMAND_LINE::use_vst = true;
50 bool ARDOUR_COMMAND_LINE::new_session = false;
51 bool ARDOUR_COMMAND_LINE::try_hw_optimization = true;
52 bool ARDOUR_COMMAND_LINE::no_connect_ports = false;
53 string ARDOUR_COMMAND_LINE::keybindings_path = ""; /* empty means use builtin default */
54 std::string ARDOUR_COMMAND_LINE::menus_file = "ardour.menus";
55 bool ARDOUR_COMMAND_LINE::finder_invoked_ardour = false;
56 string ARDOUR_COMMAND_LINE::load_template;
57 bool ARDOUR_COMMAND_LINE::check_announcements = true;
58
59 using namespace ARDOUR_COMMAND_LINE;
60
61 int
62 print_help (const char *execname)
63 {
64         // help2man format, http://docopt.org/
65         // https://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp
66         cout
67                 << _("Usage: ") << PROGRAM_NAME << _(" [ OPTIONS ] [ SESSION-NAME ]")
68                 << "\n\n"
69                 << _("Ardour is a multichannel hard disk recorder (HDR) and digital audio workstation (DAW).")
70                 << "\n\n"
71                 << _("Options:\n")
72                 << _("  -a, --no-announcements      Do not contact website for announcements\n")
73                 << _("  -A, --actions               Print all possible menu action names\n")
74                 << _("  -b, --bindings              Display all current key bindings\n")
75                 << _("  -B, --bypass-plugins        Bypass all plugins in an existing session\n")
76                 << _("  -c, --name <name>           Use a specific backend client name, default is ardour\n")
77                 << _("  -d, --disable-plugins       Disable all plugins (safe mode)\n")
78 #ifndef NDEBUG
79                 << _("  -D, --debug <options>       Set debug flags. Use \"-D list\" to see available options\n")
80 #endif
81                 << _("  -h, --help                  Print this message\n")
82                 << _("  -k, --keybindings <file>    Name of key bindings to load\n")
83                 << _("  -m, --menus file            Use \"file\" to define menus\n")
84                 << _("  -n, --no-splash             Do not show splash screen\n")
85                 << _("  -N, --new session-name      Create a new session from the command line\n")
86                 << _("  -O, --no-hw-optimizations   Disable h/w specific optimizations\n")
87                 << _("  -P, --no-connect-ports      Do not connect any ports at startup\n")
88                 << _("  -S, --sync                  Draw the GUI synchronously\n")
89                 << _("  -T, --template <name>       Use given template for new session\n")
90                 << _("  -v, --version               Print version and exit\n")
91 #ifdef WINDOWS_VST_SUPPORT
92                 << _("  -V, --novst                 Disable WindowsVST support\n")
93 #endif
94                 << "\n\n"
95                 << _("Report bugs to http://tracker.ardour.org\n")
96                 << _("Website http://ardour.org\n")
97                 ;
98         return 1;
99
100 }
101
102 int
103 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
104 {
105         const char *optstring = "aAbBc:C:dD:hHk:E:m:N:nOp:PST:U:vV";
106         const char *execname = strrchr (argv[0], '/');
107
108         if (execname == 0) {
109                 execname = argv[0];
110         } else {
111                 execname++;
112         }
113
114         const struct option longopts[] = {
115                 { "version", 0, 0, 'v' },
116                 { "help", 0, 0, 'h' },
117                 { "no-announcements", 0, 0, 'a' },
118                 { "actions", 0, 0, 'A' },
119                 { "bindings", 0, 0, 'b' },
120                 { "bypass-plugins", 0, 0, 'B' },
121                 { "disable-plugins", 0, 0, 'd' },
122                 { "debug", 1, 0, 'D' },
123                 { "no-splash", 0, 0, 'n' },
124                 { "menus", 1, 0, 'm' },
125                 { "name", 1, 0, 'c' },
126                 { "novst", 0, 0, 'V' },
127                 { "new", 1, 0, 'N' },
128                 { "no-hw-optimizations", 0, 0, 'O' },
129                 { "sync", 0, 0, 'S' },
130                 { "template", 1, 0, 'T' },
131                 { "no-connect-ports", 0, 0, 'P' },
132                 { 0, 0, 0, 0 }
133         };
134
135         int option_index = 0;
136         int c = 0;
137
138         while (1) {
139                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
140
141                 if (c == -1) {
142                         break;
143                 }
144
145                 switch (c) {
146                 case 0:
147                         break;
148
149                 case 'v':
150                         just_version = true;
151                         break;
152
153                 case 'h':
154                         print_help (execname);
155                         exit (EXIT_SUCCESS);
156                         break;
157                 case 'H':
158 #ifndef NDEBUG
159                         ProcessorBox::show_all_processors = true;
160 #endif
161                         break;
162                 case 'a':
163                         check_announcements = false;
164                         break;
165
166                 case 'A':
167                         show_actions = true;
168                         break;
169
170                 case 'b':
171                         show_key_actions = true;
172                         break;
173
174                 case 'B':
175                         ARDOUR::Session::set_bypass_all_loaded_plugins (true);
176                         break;
177
178                 case 'd':
179                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
180                         break;
181
182                 case 'D':
183                         if (PBD::parse_debug_options (optarg)) {
184                                 exit (EXIT_SUCCESS);
185                         }
186                         break;
187
188                 case 'm':
189                         menus_file = optarg;
190                         break;
191
192                 case 'n':
193                         no_splash = true;
194                         break;
195
196                 case 'p':
197                         //undocumented OS X finder -psn_XXXXX argument
198                         finder_invoked_ardour = true;
199                         break;
200
201                 case 'S':
202                 //      ; just pass this through to gtk it will figure it out
203                         break;
204                 case 'T':
205                         load_template = optarg;
206                         break;
207
208                 case 'N':
209                         new_session = true;
210                         session_name = optarg;
211                         break;
212
213                 case 'O':
214                         try_hw_optimization = false;
215                         break;
216
217                 case 'P':
218                         no_connect_ports = true;
219                         break;
220
221                 case 'V':
222 #ifdef WINDOWS_VST_SUPPORT
223                         use_vst = false;
224 #endif /* WINDOWS_VST_SUPPORT */
225                         break;
226
227                 case 'c':
228                         backend_client_name = optarg;
229                         break;
230
231                 case 'k':
232                         keybindings_path = optarg;
233                         break;
234
235                 default:
236                         return print_help(execname);
237                 }
238         }
239
240         if (optind < argc) {
241                 if (new_session) {
242                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
243                         return print_help(execname);
244                 }
245                 session_name = argv[optind++];
246         }
247
248         return 0;
249 }
250