debug flag for MTC; make ardour/timecode.h simply include the "authoritative" one...
[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::jack_client_name = "ardour";
36 bool  ARDOUR_COMMAND_LINE::show_key_actions = false;
37 bool ARDOUR_COMMAND_LINE::no_splash = true;
38 bool ARDOUR_COMMAND_LINE::just_version = false;
39 bool ARDOUR_COMMAND_LINE::use_vst = true;
40 bool ARDOUR_COMMAND_LINE::new_session = false;
41 char* ARDOUR_COMMAND_LINE::curvetest_file = 0;
42 bool ARDOUR_COMMAND_LINE::try_hw_optimization = true;
43 string ARDOUR_COMMAND_LINE::keybindings_path = ""; /* empty means use builtin default */
44 Glib::ustring ARDOUR_COMMAND_LINE::menus_file = "ardour.menus";
45 bool ARDOUR_COMMAND_LINE::finder_invoked_ardour = false;
46 string ARDOUR_COMMAND_LINE::immediate_save;
47
48 using namespace ARDOUR_COMMAND_LINE;
49
50 int
51 print_help (const char *execname)
52 {
53         cout << _("Usage: ") << execname << " [OPTION]... [SESSION_NAME]\n\n"
54              << _("  [SESSION_NAME]              Name of session to load\n")
55              << _("  -v, --version               Show version information\n")
56              << _("  -h, --help                  Print this message\n")
57              << _("  -b, --bindings              Print all possible keyboard binding names\n")
58              << _("  -c, --name <name>           Use a specific jack client name, default is ardour\n")
59              << _("  -d, --disable-plugins       Disable all plugins in an existing session\n")
60              << _("  -D, --debug <options>       Set debug flags. Use \"-D list\" to see available options\n")
61              << _("  -n, --show-splash           Show splash screen\n")
62              << _("  -m, --menus file            Use \"file\" for Ardour menus\n")
63              << _("  -N, --new session-name      Create a new session from the command line\n")
64              << _("  -O, --no-hw-optimizations   Disable h/w specific optimizations\n")
65              << _("  -S, --sync                  Draw the gui synchronously \n")
66 #ifdef VST_SUPPORT
67              << _("  -V, --novst                 Do not use VST support\n")
68 #endif
69              << _("  -E, --save <file>           Load the specified session, save it to <file> and then quit\n")
70              << _("  -C, --curvetest filename    Curve algorithm debugger\n")
71              << _("  -k, --keybindings filename  Name of key bindings to load (default is ~/.ardour3/ardour.bindings)\n")
72                 ;
73         return 1;
74
75 }
76
77 static void
78 list_debug_options ()
79 {
80         cerr << _("The following debug options are available. Separate multipe options with commas.\nNames are case-insensitive and can be abbreviated.") << "\n\n";
81         cerr << "\tMidiSourceIO\n";
82         cerr << "\tMidiPlaylistIO\n";
83         cerr << "\tMidiDiskstreamIO\n";
84         cerr << "\tSnapBBT\n";
85         cerr << "\tConfiguration\n";
86         cerr << "\tLatency\n";
87         cerr << "\tGraph\n";
88         cerr << "\tDestruction\n";
89 }
90
91 static int
92 parse_debug_options (const char* str)
93 {
94         char* p;
95         char* sp;
96         uint64_t bits = 0;
97         char* copy = strdup (str);
98
99         p = strtok_r (copy, ",", &sp);
100
101         while (p) {
102                 if (strcasecmp (p, "list") == 0) {
103                         list_debug_options ();
104                         free (copy);
105                         return 1;
106                 }
107
108                 if (strcasecmp (p, "all") == 0) {
109                         ARDOUR::set_debug_bits (~0ULL);
110                         free (copy);
111                         return 0;
112                 }
113
114                 if (strncasecmp (p, "midisourceio", strlen (p)) == 0) {
115                         bits |= ARDOUR::DEBUG::MidiSourceIO;
116                 } else if (strncasecmp (p, "midiplaylistio", strlen (p)) == 0) {
117                         bits |= ARDOUR::DEBUG::MidiPlaylistIO;
118                 } else if (strncasecmp (p, "mididiskstreamio", strlen (p)) == 0) {
119                         bits |= ARDOUR::DEBUG::MidiDiskstreamIO;
120                 } else if (strncasecmp (p, "snapbbt", strlen (p)) == 0) {
121                         bits |= ARDOUR::DEBUG::SnapBBT;
122                 } else if (strncasecmp (p, "configuration", strlen (p)) == 0) {
123                         bits |= ARDOUR::DEBUG::Configuration;
124                 } else if (strncasecmp (p, "latency", strlen (p)) == 0) {
125                         bits |= ARDOUR::DEBUG::Latency;
126                 } else if (strncasecmp (p, "processors", strlen (p)) == 0) {
127                         bits |= ARDOUR::DEBUG::Processors;
128                 } else if (strncasecmp (p, "graph", strlen (p)) == 0) {
129                         bits |= ARDOUR::DEBUG::Graph;
130                 } else if (strncasecmp (p, "destruction", strlen (p)) == 0) {
131                         bits |= ARDOUR::DEBUG::Destruction;
132                 } else if (strncasecmp (p, "mtc", strlen (p)) == 0) {
133                         bits |= ARDOUR::DEBUG::MTC;
134                 }
135
136                 p = strtok_r (0, ",", &sp);
137         }
138         
139         free (copy);
140         ARDOUR::set_debug_bits (bits);
141         return 0;
142 }
143
144
145 int
146 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
147 {
148         const char *optstring = "bc:C:dD:hk:E:m:N:nOp:SU:vV";
149         const char *execname = strrchr (argv[0], '/');
150
151         if (getenv ("ARDOUR_SAE")) {
152                 menus_file = "ardour-sae.menus";
153                 keybindings_path = "SAE";
154         }
155
156         if (execname == 0) {
157                 execname = argv[0];
158         } else {
159                 execname++;
160         }
161
162         const struct option longopts[] = {
163                 { "version", 0, 0, 'v' },
164                 { "help", 0, 0, 'h' },
165                 { "bindings", 0, 0, 'b' },
166                 { "debug", 1, 0, 'D' },
167                 { "show-splash", 0, 0, 'n' },
168                 { "menus", 1, 0, 'm' },
169                 { "name", 1, 0, 'c' },
170                 { "novst", 0, 0, 'V' },
171                 { "new", 1, 0, 'N' },
172                 { "no-hw-optimizations", 0, 0, 'O' },
173                 { "sync", 0, 0, 'S' },
174                 { "curvetest", 1, 0, 'C' },
175                 { "save", 1, 0, 'E' },
176                 { 0, 0, 0, 0 }
177         };
178
179         int option_index = 0;
180         int c = 0;
181
182         while (1) {
183                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
184
185                 if (c == -1) {
186                         break;
187                 }
188
189                 switch (c) {
190                 case 0:
191                         break;
192
193                 case 'v':
194                         just_version = true;
195                         break;
196
197                 case 'h':
198                         print_help (execname);
199                         exit (0);
200                         break;
201                 case 'b':
202                         show_key_actions = true;
203                         break;
204
205                 case 'd':
206                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
207                         break;
208
209                 case 'D':
210                         if (parse_debug_options (optarg)) {
211                                 exit (0);
212                         }
213                         break;
214                         
215                 case 'm':
216                         menus_file = optarg;
217                         break;
218
219                 case 'n':
220                         no_splash = false;
221                         break;
222
223                 case 'p':
224                         //undocumented OS X finder -psn_XXXXX argument
225                         finder_invoked_ardour = true;
226                         break;
227
228                 case 'S':
229                 //      ; just pass this through to gtk it will figure it out
230                         break;
231
232                 case 'N':
233                         new_session = true;
234                         session_name = optarg;
235                         break;
236
237                 case 'O':
238                         try_hw_optimization = false;
239                         break;
240
241                 case 'V':
242 #ifdef VST_SUPPORT
243                         use_vst = false;
244 #endif /* VST_SUPPORT */
245                         break;
246
247                 case 'c':
248                         jack_client_name = optarg;
249                         break;
250
251                 case 'C':
252                         curvetest_file = optarg;
253                         break;
254
255                 case 'k':
256                         keybindings_path = optarg;
257                         break;
258
259                 case 'E':
260                         immediate_save = optarg;
261                         break;
262
263                 default:
264                         return print_help(execname);
265                 }
266         }
267
268         if (optind < argc) {
269                 if (new_session) {
270                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
271                         return print_help(execname);
272                 }
273                 session_name = argv[optind++];
274         }
275
276         return 0;
277 }
278