Part 1 of loading 2.X sessions; some things work, some things don't, hacks a-plenty.
[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 <iostream>
22 #include <cstdlib>
23
24 #include "ardour/session.h"
25
26 #include "opts.h"
27
28 #include "i18n.h"
29
30 using namespace std;
31
32 string ARDOUR_COMMAND_LINE::session_name = "";
33 string ARDOUR_COMMAND_LINE::jack_client_name = "ardour";
34 bool  ARDOUR_COMMAND_LINE::show_key_actions = false;
35 bool ARDOUR_COMMAND_LINE::no_splash = true;
36 bool ARDOUR_COMMAND_LINE::just_version = false;
37 bool ARDOUR_COMMAND_LINE::use_vst = true;
38 bool ARDOUR_COMMAND_LINE::new_session = false;
39 char* ARDOUR_COMMAND_LINE::curvetest_file = 0;
40 bool ARDOUR_COMMAND_LINE::try_hw_optimization = true;
41 string ARDOUR_COMMAND_LINE::keybindings_path = ""; /* empty means use builtin default */
42 Glib::ustring ARDOUR_COMMAND_LINE::menus_file = "ardour.menus";
43 bool ARDOUR_COMMAND_LINE::finder_invoked_ardour = false;
44 string ARDOUR_COMMAND_LINE::immediate_save;
45
46 using namespace ARDOUR_COMMAND_LINE;
47
48 int
49 print_help (const char *execname)
50 {
51         cout << _("Usage: ") << execname << "\n"
52              << _("  -v, --version                    Show version information\n")
53              << _("  -h, --help                       Print this message\n")
54              << _("  -b, --bindings                   Print all possible keyboard binding names\n")
55              << _("  -c, --name <name>                Use a specific jack client name, default is ardour\n")
56              << _("  -d, --disable-plugins            Disable all plugins in an existing session\n")
57              << _("  -n, --show-splash                Show splash screen\n")
58              << _("  -m, --menus file                 Use \"file\" for Ardour menus\n")
59              << _("  -N, --new session-name           Create a new session from the command line\n")
60              << _("  -O, --no-hw-optimizations        Disable h/w specific optimizations\n")
61              << _("  -S, --sync                       Draw the gui synchronously \n")
62 #ifdef VST_SUPPORT
63              << _("  -V, --novst                      Do not use VST support\n")
64 #endif
65              << _("  -E, --save <file>                Load the specified session, save it to <file> and then quit\n")
66              << _("  [session-name]                   Name of session to load\n")
67              << _("  -C, --curvetest filename         Curve algorithm debugger\n")
68              << _("  -k, --keybindings filename       Name of key bindings to load (default is ~/.ardour3/ardour.bindings)\n")
69                 ;
70         return 1;
71
72 }
73
74 int
75 ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
76 {
77         const char *optstring = "U:hSbvVnOdc:C:m:N:k:p:E:";
78         const char *execname = strrchr (argv[0], '/');
79
80         if (getenv ("ARDOUR_SAE")) {
81                 menus_file = "ardour-sae.menus";
82                 keybindings_path = "SAE";
83         }
84
85         if (execname == 0) {
86                 execname = argv[0];
87         } else {
88                 execname++;
89         }
90
91         const struct option longopts[] = {
92                 { "version", 0, 0, 'v' },
93                 { "help", 0, 0, 'h' },
94                 { "bindings", 0, 0, 'b' },
95                 { "show-splash", 0, 0, 'n' },
96                 { "menus", 1, 0, 'm' },
97                 { "name", 1, 0, 'c' },
98                 { "novst", 0, 0, 'V' },
99                 { "new", 1, 0, 'N' },
100                 { "no-hw-optimizations", 0, 0, 'O' },
101                 { "sync", 0, 0, 'S' },
102                 { "curvetest", 1, 0, 'C' },
103                 { "save", 1, 0, 'E' },
104                 { 0, 0, 0, 0 }
105         };
106
107         int option_index = 0;
108         int c = 0;
109
110         while (1) {
111                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
112
113                 if (c == -1) {
114                         break;
115                 }
116
117                 switch (c) {
118                 case 0:
119                         break;
120
121                 case 'v':
122                         just_version = true;
123                         break;
124
125                 case 'h':
126                         print_help (execname);
127                         exit (0);
128                         break;
129                 case 'b':
130                         show_key_actions = true;
131                         break;
132
133                 case 'd':
134                         ARDOUR::Session::set_disable_all_loaded_plugins (true);
135                         break;
136
137                 case 'm':
138                         menus_file = optarg;
139                         break;
140
141                 case 'n':
142                         no_splash = false;
143                         break;
144
145                 case 'p':
146                         //undocumented OS X finder -psn_XXXXX argument
147                         finder_invoked_ardour = true;
148                         break;
149
150                 case 'S':
151                 //      ; just pass this through to gtk it will figure it out
152                         break;
153
154                 case 'N':
155                         new_session = true;
156                         session_name = optarg;
157                         break;
158
159                 case 'O':
160                         try_hw_optimization = false;
161                         break;
162
163                 case 'V':
164 #ifdef VST_SUPPORT
165                         use_vst = false;
166 #endif /* VST_SUPPORT */
167                         break;
168
169                 case 'c':
170                         jack_client_name = optarg;
171                         break;
172
173                 case 'C':
174                         curvetest_file = optarg;
175                         break;
176
177                 case 'k':
178                         keybindings_path = optarg;
179                         break;
180
181                 case 'E':
182                         immediate_save = optarg;
183                         break;
184
185                 default:
186                         return print_help(execname);
187                 }
188         }
189
190         if (optind < argc) {
191                 if (new_session) {
192                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
193                         return print_help(execname);
194                 }
195                 session_name = argv[optind++];
196         }
197
198         return 0;
199 }
200