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