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 ("VAMP_PATH");
166 path += "/../Frameworks";
168 setenv ("VAMP_PATH", path.c_str(), 1);
170 cstr = getenv ("ARDOUR_CONTROL_SURFACE_PATH");
176 path += "/../Surfaces";
178 setenv ("ARDOUR_CONTROL_SURFACE_PATH", path.c_str(), 1);
180 cstr = getenv ("LV2_PATH");
186 path += "/../Plugins";
188 setenv ("LV2_PATH", path.c_str(), 1);
191 path += "/../Frameworks/clearlooks";
193 setenv ("GTK_PATH", path.c_str(), 1);
196 path += "/../Resources/locale";
198 localedir = strdup (path.c_str());
200 /* write a pango.rc file and tell pango to use it. we'd love
201 to put this into the Ardour.app bundle and leave it there,
202 but the user may not have write permission. so ...
204 we also have to make sure that the user ardour directory
209 sys::create_directories (user_config_directory ());
211 catch (const sys::filesystem_error& ex) {
212 error << _("Could not create user configuration directory") << endmsg;
215 sys::path pangopath = user_config_directory();
216 pangopath /= "pango.rc";
217 path = pangopath.to_string();
219 std::ofstream pangorc (path.c_str());
221 error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
224 pangorc << "[Pango]\nModuleFiles=";
226 pangopath = dir_path;
228 pangopath /= "Resources";
229 pangopath /= "pango.modules";
231 pangorc << pangopath.to_string() << endl;
235 setenv ("PANGO_RC_FILE", path.c_str(), 1);
238 // gettext charset aliases
240 setenv ("CHARSETALIASDIR", path.c_str(), 1);
245 path += "/../Resources/fonts.conf";
247 setenv ("FONTCONFIG_FILE", path.c_str(), 1);
249 // GDK Pixbuf loader module file
252 path += "/../Resources/gdk-pixbuf.loaders";
254 setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
256 if (getenv ("ARDOUR_WITH_JACK")) {
260 path += "/../Frameworks";
262 setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
269 /* this is called from the entry point of a wine-compiled
270 executable that is linked against gtk2_ardour built
274 int ardour_main (int argc, char *argv[])
276 int main (int argc, char *argv[])
279 vector<Glib::ustring> null_file_list;
282 fixup_bundle_environment ();
288 (void) bindtextdomain (PACKAGE, localedir);
289 /* our i18n translations are all in UTF-8, so make sure
290 that even if the user locale doesn't specify UTF-8,
291 we use that when handling them.
293 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
294 (void) textdomain (PACKAGE);
296 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
298 // catch error message system signals ();
300 text_receiver.listen_to (error);
301 text_receiver.listen_to (info);
302 text_receiver.listen_to (fatal);
303 text_receiver.listen_to (warning);
305 if (parse_opts (argc, argv)) {
309 if (curvetest_file) {
310 return curvetest (curvetest_file);
313 cout << _("Ardour/GTK ")
315 << _("\n (built using ")
316 << ardour_svn_revision
318 << _(" and GCC version ") << __VERSION__
328 cerr << _("Copyright (C) 1999-2008 Paul Davis") << endl
329 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
331 << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
332 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
333 << _("This is free software, and you are welcome to redistribute it ") << endl
334 << _("under certain conditions; see the source for copying conditions.")
338 /* some GUI objects need this */
343 ui = new ARDOUR_UI (&argc, &argv);
344 } catch (failed_constructor& err) {
345 error << _("could not create ARDOUR GUI") << endmsg;
349 ui->run (text_receiver);
353 pthread_cancel_all ();
357 } // end of extern C block