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