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