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