clean up patch change/sysex headers.
[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::no_splash = false;
43 bool ARDOUR_COMMAND_LINE::just_version = false;
44 bool ARDOUR_COMMAND_LINE::use_vst = true;
45 bool ARDOUR_COMMAND_LINE::new_session = false;
46 char* ARDOUR_COMMAND_LINE::curvetest_file = 0;
47 bool ARDOUR_COMMAND_LINE::try_hw_optimization = true;
48 bool ARDOUR_COMMAND_LINE::no_connect_ports = false;
49 string ARDOUR_COMMAND_LINE::keybindings_path = ""; /* empty means use builtin default */
50 std::string ARDOUR_COMMAND_LINE::menus_file = "ardour.menus";
51 bool ARDOUR_COMMAND_LINE::finder_invoked_ardour = false;
52 string ARDOUR_COMMAND_LINE::immediate_save;
53 string ARDOUR_COMMAND_LINE::load_template;
54 bool ARDOUR_COMMAND_LINE::check_announcements = true;
55
56 using namespace ARDOUR_COMMAND_LINE;
57
58 int
59 print_help (const char *execname)
60 {
61         // help2man format, http://docopt.org/
62         // https://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp
63         cout
64                 << _("Usage: ") << PROGRAM_NAME << _(" [ OPTIONS ] [ SESSION-NAME ]")
65                 << "\n\n"
66                 << _("Ardour is a multichannel hard disk recorder (HDR) and digital audio workstation (DAW).")
67                 << "\n\n"
68                 << _("Options:\n")
69                 << _("  -a, --no-announcements      Do not contact website for announcements\n")
70                 << _("  -b, --bindings              Print all possible keyboard binding names\n")
71                 << _("  -B, --bypass-plugins        Bypass all plugins in an existing session\n")
72                 << _("  -c, --name <name>           Use a specific backend client name, default is ardour\n")
73 #ifndef NDEBUG
74                 << _("  -C, --curvetest filename    Curve algorithm debugger\n")
75 #endif
76                 << _("  -d, --disable-plugins       Disable all plugins (safe mode)\n")
77 #ifndef NDEBUG
78                 << _("  -D, --debug <options>       Set debug flags. Use \"-D list\" to see available options\n")
79 #endif
80                 << _("  -E, --save <file>           Load the specified session, save it to <file> and then quit\n")
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>       Draw the GUI synchronously\n")
90                 << _("  -U, --uuid <uuid>           Set (jack) backend UUID\n")
91                 << _("  -v, --version               Use session template\n")
92 #ifdef WINDOWS_VST_SUPPORT
93                 << _("  -V, --novst                 Disable WindowsVST support\n")
94 #endif
95                 << "\n\n"
96                 << _("Report bugs to http://tracker.ardour.org\n")
97                 << _("Website http://ardour.org\n")
98                 ;
99         return 1;
100
101 }
102
103 int
104 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
105 {
106         const char *optstring = "abBc:C:dD:hHk:E:m:N:nOp:PST:U:vV";
107         const char *execname = strrchr (argv[0], '/');
108
109         if (execname == 0) {
110                 execname = argv[0];
111         } else {
112                 execname++;
113         }
114
115         const struct option longopts[] = {
116                 { "version", 0, 0, 'v' },
117                 { "help", 0, 0, 'h' },
118                 { "no-announcements", 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                 { "curvetest", 1, 0, 'C' },
131                 { "save", 1, 0, 'E' },
132                 { "uuid", 1, 0, 'U' },
133                 { "template", 1, 0, 'T' },
134                 { "no-connect-ports", 0, 0, 'P' },
135                 { 0, 0, 0, 0 }
136         };
137
138         int option_index = 0;
139         int c = 0;
140
141         while (1) {
142                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
143
144                 if (c == -1) {
145                         break;
146                 }
147
148                 switch (c) {
149                 case 0:
150                         break;
151
152                 case 'v':
153                         just_version = true;
154                         break;
155
156                 case 'h':
157                         print_help (execname);
158                         exit (0);
159                         break;
160                 case 'H':
161 #ifndef NDEBUG
162                         ProcessorBox::show_all_processors = true;
163 #endif
164                         break;
165                 case 'a':
166                         check_announcements = false;
167                         break;
168
169                 case 'b':
170                         show_key_actions = true;
171                         break;
172
173                 case 'B':
174                         ARDOUR::Session::set_bypass_all_loaded_plugins (true);
175                         break;
176
177                 case 'd':
178                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
179                         break;
180
181                 case 'D':
182                         if (PBD::parse_debug_options (optarg)) {
183                                 exit (0);
184                         }
185                         break;
186
187                 case 'm':
188                         menus_file = optarg;
189                         break;
190
191                 case 'n':
192                         no_splash = true;
193                         break;
194
195                 case 'p':
196                         //undocumented OS X finder -psn_XXXXX argument
197                         finder_invoked_ardour = true;
198                         break;
199
200                 case 'S':
201                 //      ; just pass this through to gtk it will figure it out
202                         break;
203                 case 'T':
204                         load_template = optarg;
205                         break;
206
207                 case 'N':
208                         new_session = true;
209                         session_name = optarg;
210                         break;
211
212                 case 'O':
213                         try_hw_optimization = false;
214                         break;
215
216                 case 'P':
217                         no_connect_ports = true;
218                         break;
219
220                 case 'V':
221 #ifdef WINDOWS_VST_SUPPORT
222                         use_vst = false;
223 #endif /* WINDOWS_VST_SUPPORT */
224                         break;
225
226                 case 'c':
227                         backend_client_name = optarg;
228                         break;
229
230                 case 'C':
231                         curvetest_file = optarg;
232                         break;
233
234                 case 'k':
235                         keybindings_path = optarg;
236                         break;
237
238                 case 'E':
239                         immediate_save = optarg;
240                         break;
241
242                 case 'U':
243                         backend_session_uuid = optarg;
244                         break;
245
246                 default:
247                         return print_help(execname);
248                 }
249         }
250
251         if (optind < argc) {
252                 if (new_session) {
253                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
254                         return print_help(execname);
255                 }
256                 session_name = argv[optind++];
257         }
258
259         return 0;
260 }
261