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>
25 #include <pbd/error.h>
26 #include <pbd/file_utils.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>
36 #include <ardour/session_utils.h>
37 #include <ardour/filesystem_paths.h>
39 #include <gtkmm/main.h>
40 #include <gtkmm2ext/popup.h>
41 #include <gtkmm2ext/utils.h>
43 #include "../svn_revision.h"
46 #include "ardour_ui.h"
53 using namespace ARDOUR_COMMAND_LINE;
54 using namespace ARDOUR;
58 TextReceiver text_receiver ("ardour");
60 extern int curvetest (string);
62 static ARDOUR_UI *ui = 0;
63 static const char* localedir = LOCALEDIR;
68 MessageDialog win (_("Ardour could not connect to JACK."),
71 (Gtk::ButtonsType)(Gtk::BUTTONS_NONE));
72 win.set_secondary_text(_("There are several possible reasons:\n\
74 1) JACK is not running.\n\
75 2) JACK is running as another user, perhaps root.\n\
76 3) There is already another client called \"ardour\".\n\
78 Please consider the possibilities, and perhaps (re)start JACK."));
80 win.add_button (Stock::QUIT, RESPONSE_CLOSE);
81 win.set_default_response (RESPONSE_CLOSE);
84 win.set_position (Gtk::WIN_POS_CENTER);
90 /* we just don't care about the result, but we want to block */
98 #include <mach-o/dyld.h>
99 #include <sys/param.h>
103 fixup_bundle_environment ()
105 if (!getenv ("ARDOUR_BUNDLED")) {
109 char execpath[MAXPATHLEN+1];
110 uint32_t pathsz = sizeof (execpath);
112 _NSGetExecutablePath (execpath, &pathsz);
114 Glib::ustring exec_path (execpath);
115 Glib::ustring dir_path = Glib::path_get_dirname (exec_path);
117 const char *cstr = getenv ("PATH");
119 /* ensure that we find any bundled executables (e.g. JACK) */
126 setenv ("PATH", path.c_str(), 1);
129 path += "/../Resources";
131 path += "/../Resources/Surfaces";
133 path += "/../Resources/Panners";
135 setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
138 path += "/../Resources/icons:";
140 path += "/../Resources/pixmaps:";
142 path += "/../Resources/share:";
144 path += "/../Resources";
146 setenv ("ARDOUR_PATH", path.c_str(), 1);
147 setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
148 setenv ("ARDOUR_DATA_PATH", path.c_str(), 1);
150 cstr = getenv ("LADSPA_PATH");
156 path += "/../Plugins";
158 setenv ("LADSPA_PATH", path.c_str(), 1);
160 cstr = getenv ("LV2_PATH");
166 path += "/../Plugins";
168 setenv ("LV2_PATH", path.c_str(), 1);
171 path += "/../Frameworks/clearlooks";
173 setenv ("GTK_PATH", path.c_str(), 1);
176 path += "/../Resources/locale";
178 localedir = strdup (path.c_str());
180 /* write a pango.rc file and tell pango to use it */
183 path += "/../Resources/pango.rc";
185 std::ofstream pangorc (path.c_str());
187 error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
189 pangorc << "[Pango]\nModuleFiles=";
190 Glib::ustring mpath = dir_path;
191 mpath += "/../Resources/pango.modules";
192 pangorc << mpath << endl;
195 setenv ("PANGO_RC_FILE", path.c_str(), 1);
198 // gettext charset aliases
200 setenv ("CHARSETALIASDIR", path.c_str(), 1);
205 path += "/../Resources/fonts.conf";
207 setenv ("FONTCONFIG_FILE", path.c_str(), 1);
209 // GDK Pixbuf loader module file
212 path += "/../Resources/gdk-pixbuf.loaders";
214 setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
216 if (getenv ("ARDOUR_WITH_JACK")) {
220 path += "/../Frameworks";
222 setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
229 setup_keybindings (ARDOUR_UI* ui)
233 if (keybindings_path.empty()) {
234 keybindings_path = "ardour";
239 if (keybindings_path.find (".bindings") == string::npos) {
241 // just a style name - allow user to
242 // specify the layout type.
246 if ((layout = getenv ("ARDOUR_KEYBOARD_LAYOUT")) != 0) {
247 keybindings_path += '-';
248 keybindings_path += layout;
251 keybindings_path += ".bindings";
255 // XXX timbyr - we need a portable test for "is-absolute" here
257 if (keybindings_path[0] != '/' && keybindings_path[0] != '.') {
259 /* not absolute - look in the usual places */
261 sys::path key_bindings_file;
263 find_file_in_search_path (ardour_search_path() + system_config_search_path(),
264 keybindings_path, key_bindings_file);
266 path = key_bindings_file.to_string();
269 warning << string_compose (_("Key bindings file \"%1\" not found. Default bindings used instead"),
270 keybindings_path) << endmsg;
275 // absolute path from user - use it as is
277 path = keybindings_path;
281 ui->set_keybindings_path (path);
286 /* this is called from the entry point of a wine-compiled
287 executable that is linked against gtk2_ardour built
291 int ardour_main (int argc, char *argv[])
293 int main (int argc, char *argv[])
296 vector<Glib::ustring> null_file_list;
299 fixup_bundle_environment ();
305 (void) bindtextdomain (PACKAGE, localedir);
306 /* our i18n translations are all in UTF-8, so make sure
307 that even if the user locale doesn't specify UTF-8,
308 we use that when handling them.
310 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
311 (void) textdomain (PACKAGE);
313 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
315 // catch error message system signals ();
317 text_receiver.listen_to (error);
318 text_receiver.listen_to (info);
319 text_receiver.listen_to (fatal);
320 text_receiver.listen_to (warning);
322 if (parse_opts (argc, argv)) {
326 if (curvetest_file) {
327 return curvetest (curvetest_file);
330 cout << _("Ardour/GTK ")
332 << _("\n (built using ")
333 << ardour_svn_revision
335 << _(" and GCC version ") << __VERSION__
345 cerr << _("Copyright (C) 1999-2007 Paul Davis") << endl
346 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
348 << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
349 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
350 << _("This is free software, and you are welcome to redistribute it ") << endl
351 << _("under certain conditions; see the source for copying conditions.")
355 /* some GUI objects need this */
360 ui = new ARDOUR_UI (&argc, &argv);
361 } catch (failed_constructor& err) {
362 error << _("could not create ARDOUR GUI") << endmsg;
366 setup_keybindings (ui);
368 ui->run (text_receiver);
372 pthread_cancel_all ();
376 } // end of extern C block