start of a nominal debug tracing system, with 64 bits available for flags; track...
[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 << "\n"
54              << _("  -v, --version                    Show version information\n")
55              << _("  -h, --help                       Print this message\n")
56              << _("  -b, --bindings                   Print all possible keyboard binding names\n")
57              << _("  -c, --name <name>                Use a specific jack client name, default is ardour\n")
58              << _("  -d, --disable-plugins            Disable all plugins in an existing session\n")
59              << _("  -D, --debug <options>            Set debug flags. Use \"-D list\" to see available options\n")
60              << _("  -n, --show-splash                Show splash screen\n")
61              << _("  -m, --menus file                 Use \"file\" for Ardour menus\n")
62              << _("  -N, --new session-name           Create a new session from the command line\n")
63              << _("  -O, --no-hw-optimizations        Disable h/w specific optimizations\n")
64              << _("  -S, --sync                       Draw the gui synchronously \n")
65 #ifdef VST_SUPPORT
66              << _("  -V, --novst                      Do not use VST support\n")
67 #endif
68              << _("  -E, --save <file>                Load the specified session, save it to <file> and then quit\n")
69              << _("  [session-name]                   Name of session to load\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. Their use is case-insensitive.\n\n");
81         cerr << "\tMidiSourceIO\n";
82 }
83
84 static int
85 parse_debug_options (const char* str)
86 {
87         char* p;
88         char* sp;
89         uint64_t bits = 0;
90         char* copy = strdup (str);
91
92         p = strtok_r (copy, ",", &sp);
93
94         while (p) {
95                 if (strcasecmp (p, "list") == 0) {
96                         list_debug_options ();
97                         free (copy);
98                         return 1;
99                 }
100
101                 if (strcasecmp (p, "midisourceio") == 0) {
102                         bits |= ARDOUR::DEBUG::MidiSourceIO;
103                 }
104
105                 p = strtok_r (0, ",", &sp);
106         }
107         
108         free (copy);
109         ARDOUR::set_debug_bits (bits);
110         return 0;
111 }
112
113
114 int
115 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
116 {
117         const char *optstring = "bc:C:dD:hk:E:m:N:nOp:SU:vV";
118         const char *execname = strrchr (argv[0], '/');
119
120         if (getenv ("ARDOUR_SAE")) {
121                 menus_file = "ardour-sae.menus";
122                 keybindings_path = "SAE";
123         }
124
125         if (execname == 0) {
126                 execname = argv[0];
127         } else {
128                 execname++;
129         }
130
131         const struct option longopts[] = {
132                 { "version", 0, 0, 'v' },
133                 { "help", 0, 0, 'h' },
134                 { "bindings", 0, 0, 'b' },
135                 { "debug", 1, 0, 'D' },
136                 { "show-splash", 0, 0, 'n' },
137                 { "menus", 1, 0, 'm' },
138                 { "name", 1, 0, 'c' },
139                 { "novst", 0, 0, 'V' },
140                 { "new", 1, 0, 'N' },
141                 { "no-hw-optimizations", 0, 0, 'O' },
142                 { "sync", 0, 0, 'S' },
143                 { "curvetest", 1, 0, 'C' },
144                 { "save", 1, 0, 'E' },
145                 { 0, 0, 0, 0 }
146         };
147
148         int option_index = 0;
149         int c = 0;
150
151         while (1) {
152                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
153
154                 if (c == -1) {
155                         break;
156                 }
157
158                 switch (c) {
159                 case 0:
160                         break;
161
162                 case 'v':
163                         just_version = true;
164                         break;
165
166                 case 'h':
167                         print_help (execname);
168                         exit (0);
169                         break;
170                 case 'b':
171                         show_key_actions = true;
172                         break;
173
174                 case 'd':
175                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
176                         break;
177
178                 case 'D':
179                         if (parse_debug_options (optarg)) {
180                                 exit (0);
181                         }
182                         break;
183                         
184                 case 'm':
185                         menus_file = optarg;
186                         break;
187
188                 case 'n':
189                         no_splash = false;
190                         break;
191
192                 case 'p':
193                         //undocumented OS X finder -psn_XXXXX argument
194                         finder_invoked_ardour = true;
195                         break;
196
197                 case 'S':
198                 //      ; just pass this through to gtk it will figure it out
199                         break;
200
201                 case 'N':
202                         new_session = true;
203                         session_name = optarg;
204                         break;
205
206                 case 'O':
207                         try_hw_optimization = false;
208                         break;
209
210                 case 'V':
211 #ifdef VST_SUPPORT
212                         use_vst = false;
213 #endif /* VST_SUPPORT */
214                         break;
215
216                 case 'c':
217                         jack_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                 default:
233                         return print_help(execname);
234                 }
235         }
236
237         if (optind < argc) {
238                 if (new_session) {
239                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
240                         return print_help(execname);
241                 }
242                 session_name = argv[optind++];
243         }
244
245         return 0;
246 }
247