merged with 1697 revision of trunk (which is post-rc1 but pre-rc2
[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 "opts.h"
25
26 #include "i18n.h"
27
28 using namespace std;
29
30 string GTK_ARDOUR::session_name = "";
31 string GTK_ARDOUR::jack_client_name = "ardour";
32 bool  GTK_ARDOUR::show_key_actions = false;
33 bool GTK_ARDOUR::no_splash = true;
34 bool GTK_ARDOUR::just_version = false;
35 bool GTK_ARDOUR::use_vst = true;
36 bool GTK_ARDOUR::new_session = false;
37 char* GTK_ARDOUR::curvetest_file = 0;
38 bool GTK_ARDOUR::try_hw_optimization = true;
39 string GTK_ARDOUR::keybindings_path = ""; /* empty means use builtin default */
40
41 using namespace GTK_ARDOUR;
42
43 int
44 print_help (const char *execname)
45 {
46         cout << _("Usage: ") << execname << "\n"
47              << _("  -v, --version                    Show version information\n")
48              << _("  -h, --help                       Print this message\n")
49              << _("  -b, --bindings                   Print all possible keyboard binding names\n")
50              << _("  -n, --show-splash                Show splash screen\n")
51              << _("  -c, --name  name                 Use a specific jack client name, default is ardour\n")
52              << _("  -N, --new session-name           Create a new session from the command line\n")                       
53              << _("  -O, --no-hw-optimizations        Disable h/w specific optimizations\n")
54              << _("  -S, --sync                    Draw the gui synchronously \n")
55 #ifdef VST_SUPPORT
56              << _("  -V, --novst                      Do not use VST support\n")
57 #endif
58              << _("  [session-name]                   Name of session to load\n")
59              << _("  -C, --curvetest filename         Curve algorithm debugger\n")
60              << _("  -k, --keybindings filename       Name of key bindings to load (default is ~/.ardour2/ardour.bindings)\n")
61                 ;
62         return 1;
63
64 }
65
66 int
67 GTK_ARDOUR::parse_opts (int argc, char *argv[])
68
69 {
70         const char *optstring = "U:hSbvVnOc:C:N:k:";
71         const char *execname = strrchr (argv[0], '/');
72
73         if (execname == 0) {
74                 execname = argv[0];
75         } else {
76                 execname++;
77         }
78
79         const struct option longopts[] = {
80                 { "version", 0, 0, 'v' },
81                 { "help", 0, 0, 'h' },
82                 { "bindings", 0, 0, 'b' },
83                 { "show-splash", 0, 0, 'n' },
84                 { "name", 1, 0, 'c' },
85                 { "novst", 0, 0, 'V' },
86                 { "new", 1, 0, 'N' },
87                 { "no-hw-optimizations", 0, 0, 'O' },
88                 { "sync", 0, 0, 'O' },
89                 { "curvetest", 1, 0, 'C' },
90                 { 0, 0, 0, 0 }
91         };
92
93         int option_index = 0;
94         int c = 0;
95
96         while (1) {
97                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
98
99                 if (c == -1) {
100                         break;
101                 }
102
103                 switch (c) {
104                 case 0:
105                         break;
106                 
107                 case 'v':
108                         just_version = true;
109                         break;
110
111                 case 'h':
112                         print_help (execname);
113                         exit (0);
114                         break;
115                 case 'b':
116                         show_key_actions = true;
117                         break;
118
119                 case 'n':
120                         no_splash = false;
121                         break;
122                 
123                 case 'S':
124                 //      ; just pass this through to gtk it will figure it out
125                         break;
126
127                 case 'N':
128                         new_session = true;
129                         session_name = optarg;
130                         break;
131
132                 case 'O':
133                         try_hw_optimization = false;
134                         break;
135
136                 case 'V':
137 #ifdef VST_SUPPORT
138                         use_vst = false;
139 #endif /* VST_SUPPORT */
140                         break;
141
142                 case 'c':
143                         jack_client_name = optarg;
144                         break;
145
146                 case 'C':
147                         curvetest_file = optarg;
148                         break;
149
150                 case 'k':
151                         keybindings_path = optarg;
152                         break;
153
154                 default:
155                         return print_help(execname);
156                 }
157         }
158
159         if (optind < argc) {
160                 if (new_session) {
161                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
162                         return print_help(execname);
163                 }
164                 session_name = argv[optind++];
165         }
166
167
168         return 0;
169 }
170