add option to disable or bypass plugins
[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 #include "opts.h"
29
30 #include "i18n.h"
31
32 using namespace std;
33
34 string ARDOUR_COMMAND_LINE::session_name = "";
35 string ARDOUR_COMMAND_LINE::backend_client_name = "ardour";
36 string ARDOUR_COMMAND_LINE::backend_session_uuid;
37 bool  ARDOUR_COMMAND_LINE::show_key_actions = false;
38 bool ARDOUR_COMMAND_LINE::no_splash = false;
39 bool ARDOUR_COMMAND_LINE::just_version = false;
40 bool ARDOUR_COMMAND_LINE::use_vst = true;
41 bool ARDOUR_COMMAND_LINE::new_session = false;
42 char* ARDOUR_COMMAND_LINE::curvetest_file = 0;
43 bool ARDOUR_COMMAND_LINE::try_hw_optimization = true;
44 bool ARDOUR_COMMAND_LINE::no_connect_ports = false;
45 string ARDOUR_COMMAND_LINE::keybindings_path = ""; /* empty means use builtin default */
46 std::string ARDOUR_COMMAND_LINE::menus_file = "ardour.menus";
47 bool ARDOUR_COMMAND_LINE::finder_invoked_ardour = false;
48 string ARDOUR_COMMAND_LINE::immediate_save;
49 string ARDOUR_COMMAND_LINE::load_template;
50 bool ARDOUR_COMMAND_LINE::check_announcements = true;
51
52 using namespace ARDOUR_COMMAND_LINE;
53
54 int
55 print_help (const char *execname)
56 {
57         cout << _("Usage: ") << execname << " [OPTION]... [SESSION_NAME]\n\n"
58              << _("  [SESSION_NAME]              Name of session to load\n")
59              << _("  -v, --version               Show version information\n")
60              << _("  -h, --help                  Print this message\n")
61              << _("  -a, --no-announcements      Do not contact website for announcements\n")
62              << _("  -b, --bindings              Print all possible keyboard binding names\n")
63              << _("  -B, --bypass-plugins        Bypass all plugins in an existing session\n")
64              << _("  -c, --name <name>           Use a specific backend client name, default is ardour\n")
65              << _("  -d, --disable-plugins       Disable all plugins in an existing session\n")
66              << _("  -D, --debug <options>       Set debug flags. Use \"-D list\" to see available options\n")
67              << _("  -n, --no-splash             Do not show splash screen\n")
68              << _("  -m, --menus file            Use \"file\" to define menus\n")
69              << _("  -N, --new session-name      Create a new session from the command line\n")
70              << _("  -O, --no-hw-optimizations   Disable h/w specific optimizations\n")
71              << _("  -P, --no-connect-ports      Do not connect any ports at startup\n")
72              << _("  -S, --sync                  Draw the gui synchronously \n")
73 #ifdef WINDOWS_VST_SUPPORT
74              << _("  -V, --novst                 Do not use VST support\n")
75 #endif
76              << _("  -E, --save <file>           Load the specified session, save it to <file> and then quit\n")
77              << _("  -C, --curvetest filename    Curve algorithm debugger\n")
78              << _("  -k, --keybindings filename  Name of key bindings to load\n")
79                 ;
80         return 1;
81
82 }
83
84 int
85 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
86 {
87         const char *optstring = "abBc:C:dD:hk:E:m:N:nOp:PST:U:vV";
88         const char *execname = strrchr (argv[0], '/');
89
90         if (getenv ("ARDOUR_SAE")) {
91                 menus_file = "ardour-sae.menus";
92                 keybindings_path = "SAE";
93         }
94
95         if (execname == 0) {
96                 execname = argv[0];
97         } else {
98                 execname++;
99         }
100
101         const struct option longopts[] = {
102                 { "version", 0, 0, 'v' },
103                 { "help", 0, 0, 'h' },
104                 { "no-announcements", 0, 0, 'a' },
105                 { "bindings", 0, 0, 'b' },
106                 { "bypass-plugins", 0, 0, 'B' },
107                 { "disable-plugins", 0, 0, 'd' },
108                 { "debug", 1, 0, 'D' },
109                 { "no-splash", 0, 0, 'n' },
110                 { "menus", 1, 0, 'm' },
111                 { "name", 1, 0, 'c' },
112                 { "novst", 0, 0, 'V' },
113                 { "new", 1, 0, 'N' },
114                 { "no-hw-optimizations", 0, 0, 'O' },
115                 { "sync", 0, 0, 'S' },
116                 { "curvetest", 1, 0, 'C' },
117                 { "save", 1, 0, 'E' },
118                 { "uuid", 1, 0, 'U' },
119                 { "template", 1, 0, 'T' },
120                 { "no-connect-ports", 0, 0, 'P' },
121                 { 0, 0, 0, 0 }
122         };
123
124         int option_index = 0;
125         int c = 0;
126
127         while (1) {
128                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
129
130                 if (c == -1) {
131                         break;
132                 }
133
134                 switch (c) {
135                 case 0:
136                         break;
137
138                 case 'v':
139                         just_version = true;
140                         break;
141
142                 case 'h':
143                         print_help (execname);
144                         exit (0);
145                         break;
146                 case 'a':
147                         check_announcements = false;
148                         break;
149
150                 case 'b':
151                         show_key_actions = true;
152                         break;
153
154                 case 'B':
155                         ARDOUR::Session::set_bypass_all_loaded_plugins (true);
156                         break;
157
158                 case 'd':
159                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
160                         break;
161
162                 case 'D':
163                         if (PBD::parse_debug_options (optarg)) {
164                                 exit (0);
165                         }
166                         break;
167
168                 case 'm':
169                         menus_file = optarg;
170                         break;
171
172                 case 'n':
173                         no_splash = true;
174                         break;
175
176                 case 'p':
177                         //undocumented OS X finder -psn_XXXXX argument
178                         finder_invoked_ardour = true;
179                         break;
180
181                 case 'S':
182                 //      ; just pass this through to gtk it will figure it out
183                         break;
184                 case 'T':
185                         load_template = optarg;
186                         break;
187
188                 case 'N':
189                         new_session = true;
190                         session_name = optarg;
191                         break;
192
193                 case 'O':
194                         try_hw_optimization = false;
195                         break;
196
197                 case 'P':
198                         no_connect_ports = true;
199                         break;
200
201                 case 'V':
202 #ifdef WINDOWS_VST_SUPPORT
203                         use_vst = false;
204 #endif /* WINDOWS_VST_SUPPORT */
205                         break;
206
207                 case 'c':
208                         backend_client_name = optarg;
209                         break;
210
211                 case 'C':
212                         curvetest_file = optarg;
213                         break;
214
215                 case 'k':
216                         keybindings_path = optarg;
217                         break;
218
219                 case 'E':
220                         immediate_save = optarg;
221                         break;
222
223                 case 'U':
224                         backend_session_uuid = optarg;
225                         break;
226
227                 default:
228                         return print_help(execname);
229                 }
230         }
231
232         if (optind < argc) {
233                 if (new_session) {
234                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
235                         return print_help(execname);
236                 }
237                 session_name = argv[optind++];
238         }
239
240         return 0;
241 }
242