2 Copyright (C) 2001-2007 Paul Davis
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.
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.
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.
22 #include <sigc++/bind.h>
23 #include <gtkmm/settings.h>
24 #include <glibmm/ustring.h>
26 #include <pbd/error.h>
27 #include <pbd/textreceiver.h>
28 #include <pbd/failed_constructor.h>
29 #include <pbd/pthread_utils.h>
31 #include <jack/jack.h>
33 #include <ardour/version.h>
34 #include <ardour/ardour.h>
35 #include <ardour/audioengine.h>
37 #include <gtkmm/main.h>
38 #include <gtkmm2ext/popup.h>
39 #include <gtkmm2ext/utils.h>
41 #include "svn_revision.h"
43 #include "ardour_ui.h"
50 using namespace ARDOUR_COMMAND_LINE;
51 using namespace ARDOUR;
55 TextReceiver text_receiver ("ardour");
57 extern int curvetest (string);
59 static ARDOUR_UI *ui = 0;
60 static char* localedir = LOCALEDIR;
63 show_ui_callback (void *arg)
65 ARDOUR_UI * ui = (ARDOUR_UI *) arg;
74 #include <mach-o/dyld.h>
75 #include <sys/param.h>
79 fixup_bundle_environment ()
81 if (!getenv ("ARDOUR_BUNDLED")) {
85 char execpath[MAXPATHLEN+1];
86 uint32_t pathsz = sizeof (execpath);
88 _NSGetExecutablePath (execpath, &pathsz);
90 Glib::ustring exec_path (execpath);
91 Glib::ustring dir_path = Glib::path_get_dirname (exec_path);
93 const char *cstr = getenv ("PATH");
95 /* ensure that we find any bundled executables (e.g. JACK) */
102 setenv ("PATH", path.c_str(), 1);
105 path += "/../Resources";
107 path += "/../Resources/Surfaces";
109 path += "/../Resources/Panners";
111 setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
114 path += "/../Resources/icons:";
116 path += "/../Resources/pixmaps:";
118 path += "/../Resources/share:";
120 path += "/../Resources";
122 setenv ("ARDOUR_PATH", path.c_str(), 1);
123 setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
124 setenv ("ARDOUR_DATA_PATH", path.c_str(), 1);
126 cstr = getenv ("LADSPA_PATH");
132 path += "/../Plugins";
134 setenv ("LADSPA_PATH", path.c_str(), 1);
137 path += "/../Frameworks/clearlooks";
139 setenv ("GTK_PATH", path.c_str(), 1);
142 path += "/../Resources/locale";
144 localedir = strdup (path.c_str());
146 /* write a pango.rc file and tell pango to use it */
149 path += "/../Resources/pango.rc";
151 std::ofstream pangorc (path.c_str());
153 error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
155 pangorc << "[Pango]\nModuleFiles=";
156 Glib::ustring mpath = dir_path;
157 mpath += "/../Resources/pango.modules";
158 pangorc << mpath << endl;
161 setenv ("PANGO_RC_FILE", path.c_str(), 1);
164 // gettext charset aliases
166 setenv ("CHARSETALIASDIR", path.c_str(), 1);
171 path += "/../Resources/fonts.conf";
173 setenv ("FONTCONFIG_FILE", path.c_str(), 1);
175 // GDK Pixbuf loader module file
178 path += "/../Resources/gdk-pixbuf.loaders";
180 setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
182 if (getenv ("ARDOUR_WITH_JACK")) {
186 path += "/../Frameworks";
188 setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
195 setup_keybindings (ARDOUR_UI* ui)
199 if (keybindings_path.empty()) {
200 keybindings_path = "ardour";
205 if (keybindings_path.find (".bindings") == string::npos) {
207 // just a style name - allow user to
208 // specify the layout type.
212 if ((layout = getenv ("ARDOUR_KEYBOARD_LAYOUT")) != 0) {
213 keybindings_path += '-';
214 keybindings_path += layout;
217 keybindings_path += ".bindings";
221 // XXX timbyr - we need a portable test for "is-absolute" here
223 if (keybindings_path[0] != '/' && keybindings_path[0] != '.') {
225 /* not absolute - look in the usual places */
227 path = find_config_file (keybindings_path);
230 warning << string_compose (_("Key bindings file \"%1\" not found. Default bindings used instead"),
237 // absolute path from user - use it as is
239 path = keybindings_path;
243 ui->set_keybindings_path (path);
248 /* this is called from the entry point of a wine-compiled
249 executable that is linked against gtk2_ardour built
253 int ardour_main (int argc, char *argv[])
255 int main (int argc, char* argv[])
258 vector<Glib::ustring> null_file_list;
261 fixup_bundle_environment ();
267 (void) bindtextdomain (PACKAGE, localedir);
268 /* our i18n translations are all in UTF-8, so make sure
269 that even if the user locale doesn't specify UTF-8,
270 we use that when handling them.
272 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
273 (void) textdomain (PACKAGE);
275 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
277 // catch error message system signals ();
279 text_receiver.listen_to (error);
280 text_receiver.listen_to (info);
281 text_receiver.listen_to (fatal);
282 text_receiver.listen_to (warning);
284 if (parse_opts (argc, argv)) {
288 if (curvetest_file) {
289 return curvetest (curvetest_file);
292 cout << _("Ardour/GTK ")
294 << _("\n (built using ")
295 << ardour_svn_revision
297 << _(" and GCC version ") << __VERSION__
307 cerr << _("Copyright (C) 1999-2007 Paul Davis") << endl
308 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
310 << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
311 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
312 << _("This is free software, and you are welcome to redistribute it ") << endl
313 << _("under certain conditions; see the source for copying conditions.")
317 /* some GUI objects need this */
322 ui = new ARDOUR_UI (&argc, &argv);
323 } catch (failed_constructor& err) {
324 error << _("could not create ARDOUR GUI") << endmsg;
330 if (session_name.length()) {
331 g_timeout_add (4000, show_ui_callback, ui);
335 setup_keybindings (ui);
337 ui->run (text_receiver);
341 pthread_cancel_all ();
345 } // end of extern C block