r229@gwythaint (orig r769): fugalh | 2006-08-09 08:15:05 -0600
[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
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, --use-hw-optimizations        Try to use h/w specific optimizations\n")
54 #ifdef VST_SUPPORT
55              << _("  -V, --novst                      Do not use VST support\n")
56 #endif
57              << _("  [session-name]                   Name of session to load\n")
58              << _("  -C, --curvetest filename         Curve algorithm debugger\n")
59              << _("  -g, --gtktheme                   Allow GTK to load a theme\n")
60                 ;
61         return 1;
62
63 }
64
65 int
66 GTK_ARDOUR::parse_opts (int argc, char *argv[])
67
68 {
69         const char *optstring = "U:hbvVnoc:C:N:g";
70         const char *execname = strrchr (argv[0], '/');
71
72         if (execname == 0) {
73                 execname = argv[0];
74         } else {
75                 execname++;
76         }
77
78         const struct option longopts[] = {
79                 { "version", 0, 0, 'v' },
80                 { "help", 0, 0, 'h' },
81                 { "bindings", 0, 0, 'b' },
82                 { "show-splash", 0, 0, 'n' },
83                 { "name", 1, 0, 'c' },
84                 { "novst", 0, 0, 'V' },
85                 { "new", 1, 0, 'N' },
86                 { "no-hw-optimizations", 0, 0, 'O' },
87                 { "curvetest", 1, 0, 'C' },
88                 { "gtktheme", 0, 0, 'g' },
89                 { 0, 0, 0, 0 }
90         };
91
92         int option_index = 0;
93         int c = 0;
94
95         while (1) {
96                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
97
98                 if (c == -1) {
99                         break;
100                 }
101
102                 switch (c) {
103                 case 0:
104                         break;
105                 
106                 case 'v':
107                         just_version = true;
108                         break;
109
110                 case 'h':
111                         print_help (execname);
112                         exit (0);
113                         break;
114                 case 'b':
115                         show_key_actions = true;
116                         break;
117
118                 case 'n':
119                         no_splash = false;
120                         break;
121
122                 case 'N':
123                         new_session = true;
124                         session_name = optarg;
125                         break;
126
127                 case 'O':
128                         try_hw_optimization = false;
129                         break;
130
131                 case 'V':
132 #ifdef VST_SUPPORT
133                         use_vst = false;
134 #endif /* VST_SUPPORT */
135                         break;
136
137                 case 'c':
138                         jack_client_name = optarg;
139                         break;
140
141                 case 'C':
142                         curvetest_file = optarg;
143                         break;
144
145                 default:
146                         return print_help(execname);
147                 }
148         }
149
150         if (optind < argc) {
151                 if (new_session) {
152                         cerr << "Illogical combination: you can either create a new session, or a load an existing session but not both!" << endl;
153                         return print_help(execname);
154                 }
155                 session_name = argv[optind++];
156         }
157
158
159         return 0;
160 }
161