add new Graph debug bit ; make adding aux sends really work
[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 }
89
90 static int
91 parse_debug_options (const char* str)
92 {
93         char* p;
94         char* sp;
95         uint64_t bits = 0;
96         char* copy = strdup (str);
97
98         p = strtok_r (copy, ",", &sp);
99
100         while (p) {
101                 if (strcasecmp (p, "list") == 0) {
102                         list_debug_options ();
103                         free (copy);
104                         return 1;
105                 }
106
107                 if (strcasecmp (p, "all") == 0) {
108                         ARDOUR::set_debug_bits (~0ULL);
109                         free (copy);
110                         return 0;
111                 }
112
113                 if (strncasecmp (p, "midisourceio", strlen (p)) == 0) {
114                         bits |= ARDOUR::DEBUG::MidiSourceIO;
115                 } else if (strncasecmp (p, "midiplaylistio", strlen (p)) == 0) {
116                         bits |= ARDOUR::DEBUG::MidiPlaylistIO;
117                 } else if (strncasecmp (p, "mididiskstreamio", strlen (p)) == 0) {
118                         bits |= ARDOUR::DEBUG::MidiDiskstreamIO;
119                 } else if (strncasecmp (p, "snapbbt", strlen (p)) == 0) {
120                         bits |= ARDOUR::DEBUG::SnapBBT;
121                 } else if (strncasecmp (p, "configuration", strlen (p)) == 0) {
122                         bits |= ARDOUR::DEBUG::Configuration;
123                 } else if (strncasecmp (p, "latency", strlen (p)) == 0) {
124                         bits |= ARDOUR::DEBUG::Latency;
125                 } else if (strncasecmp (p, "processors", strlen (p)) == 0) {
126                         bits |= ARDOUR::DEBUG::Processors;
127                 } else if (strncasecmp (p, "graph", strlen (p)) == 0) {
128                         bits |= ARDOUR::DEBUG::Graph;
129                 }
130
131                 p = strtok_r (0, ",", &sp);
132         }
133         
134         free (copy);
135         ARDOUR::set_debug_bits (bits);
136         return 0;
137 }
138
139
140 int
141 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
142 {
143         const char *optstring = "bc:C:dD:hk:E:m:N:nOp:SU:vV";
144         const char *execname = strrchr (argv[0], '/');
145
146         if (getenv ("ARDOUR_SAE")) {
147                 menus_file = "ardour-sae.menus";
148                 keybindings_path = "SAE";
149         }
150
151         if (execname == 0) {
152                 execname = argv[0];
153         } else {
154                 execname++;
155         }
156
157         const struct option longopts[] = {
158                 { "version", 0, 0, 'v' },
159                 { "help", 0, 0, 'h' },
160                 { "bindings", 0, 0, 'b' },
161                 { "debug", 1, 0, 'D' },
162                 { "show-splash", 0, 0, 'n' },
163                 { "menus", 1, 0, 'm' },
164                 { "name", 1, 0, 'c' },
165                 { "novst", 0, 0, 'V' },
166                 { "new", 1, 0, 'N' },
167                 { "no-hw-optimizations", 0, 0, 'O' },
168                 { "sync", 0, 0, 'S' },
169                 { "curvetest", 1, 0, 'C' },
170                 { "save", 1, 0, 'E' },
171                 { 0, 0, 0, 0 }
172         };
173
174         int option_index = 0;
175         int c = 0;
176
177         while (1) {
178                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
179
180                 if (c == -1) {
181                         break;
182                 }
183
184                 switch (c) {
185                 case 0:
186                         break;
187
188                 case 'v':
189                         just_version = true;
190                         break;
191
192                 case 'h':
193                         print_help (execname);
194                         exit (0);
195                         break;
196                 case 'b':
197                         show_key_actions = true;
198                         break;
199
200                 case 'd':
201                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
202                         break;
203
204                 case 'D':
205                         if (parse_debug_options (optarg)) {
206                                 exit (0);
207                         }
208                         break;
209                         
210                 case 'm':
211                         menus_file = optarg;
212                         break;
213
214                 case 'n':
215                         no_splash = false;
216                         break;
217
218                 case 'p':
219                         //undocumented OS X finder -psn_XXXXX argument
220                         finder_invoked_ardour = true;
221                         break;
222
223                 case 'S':
224                 //      ; just pass this through to gtk it will figure it out
225                         break;
226
227                 case 'N':
228                         new_session = true;
229                         session_name = optarg;
230                         break;
231
232                 case 'O':
233                         try_hw_optimization = false;
234                         break;
235
236                 case 'V':
237 #ifdef VST_SUPPORT
238                         use_vst = false;
239 #endif /* VST_SUPPORT */
240                         break;
241
242                 case 'c':
243                         jack_client_name = optarg;
244                         break;
245
246                 case 'C':
247                         curvetest_file = optarg;
248                         break;
249
250                 case 'k':
251                         keybindings_path = optarg;
252                         break;
253
254                 case 'E':
255                         immediate_save = optarg;
256                         break;
257
258                 default:
259                         return print_help(execname);
260                 }
261         }
262
263         if (optind < argc) {
264                 if (new_session) {
265                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
266                         return print_help(execname);
267                 }
268                 session_name = argv[optind++];
269         }
270
271         return 0;
272 }
273