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.
23 #include <sigc++/bind.h>
24 #include <gtkmm/settings.h>
26 #include "pbd/error.h"
27 #include "pbd/file_utils.h"
28 #include "pbd/textreceiver.h"
29 #include "pbd/failed_constructor.h"
30 #include "pbd/pthread_utils.h"
32 #include <jack/jack.h>
34 #include "ardour/svn_revision.h"
35 #include "ardour/version.h"
36 #include "ardour/ardour.h"
37 #include "ardour/audioengine.h"
38 #include "ardour/session_utils.h"
39 #include "ardour/filesystem_paths.h"
41 #include <gtkmm/main.h>
42 #include <gtkmm2ext/popup.h>
43 #include <gtkmm2ext/utils.h>
47 #include "ardour_ui.h"
55 using namespace ARDOUR_COMMAND_LINE;
56 using namespace ARDOUR;
60 TextReceiver text_receiver ("ardour");
62 extern int curvetest (string);
64 static ARDOUR_UI *ui = 0;
65 static const char* localedir = LOCALEDIR;
70 MessageDialog win (_("Ardour could not connect to JACK."),
73 (Gtk::ButtonsType)(Gtk::BUTTONS_NONE));
74 win.set_secondary_text(_("There are several possible reasons:\n\
76 1) JACK is not running.\n\
77 2) JACK is running as another user, perhaps root.\n\
78 3) There is already another client called \"ardour\".\n\
80 Please consider the possibilities, and perhaps (re)start JACK."));
82 win.add_button (Stock::QUIT, RESPONSE_CLOSE);
83 win.set_default_response (RESPONSE_CLOSE);
86 win.set_position (Gtk::WIN_POS_CENTER);
92 /* we just don't care about the result, but we want to block */
100 #include <mach-o/dyld.h>
101 #include <sys/param.h>
105 fixup_bundle_environment ()
107 if (!getenv ("ARDOUR_BUNDLED")) {
111 char execpath[MAXPATHLEN+1];
112 uint32_t pathsz = sizeof (execpath);
114 _NSGetExecutablePath (execpath, &pathsz);
116 Glib::ustring exec_path (execpath);
117 Glib::ustring dir_path = Glib::path_get_dirname (exec_path);
119 const char *cstr = getenv ("PATH");
121 /* ensure that we find any bundled executables (e.g. JACK),
122 and find them before any instances of the same name
131 setenv ("PATH", path.c_str(), 1);
134 path += "/../Resources";
136 path += "/../Resources/Surfaces";
138 path += "/../Resources/Panners";
140 setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
143 path += "/../Resources/icons:";
145 path += "/../Resources/pixmaps:";
147 path += "/../Resources/share:";
149 path += "/../Resources";
151 setenv ("ARDOUR_PATH", path.c_str(), 1);
152 setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
153 setenv ("ARDOUR_DATA_PATH", path.c_str(), 1);
156 path += "/../Resources";
157 setenv ("ARDOUR_INSTANT_XML_PATH", path.c_str(), 1);
159 cstr = getenv ("LADSPA_PATH");
167 path += "/../Plugins";
169 setenv ("LADSPA_PATH", path.c_str(), 1);
171 cstr = getenv ("VAMP_PATH");
179 path += "/../Frameworks";
181 setenv ("VAMP_PATH", path.c_str(), 1);
183 cstr = getenv ("ARDOUR_CONTROL_SURFACE_PATH");
191 path += "/../Surfaces";
193 setenv ("ARDOUR_CONTROL_SURFACE_PATH", path.c_str(), 1);
195 cstr = getenv ("LV2_PATH");
203 path += "/../Plugins";
205 setenv ("LV2_PATH", path.c_str(), 1);
208 path += "/../Frameworks/clearlooks";
210 setenv ("GTK_PATH", path.c_str(), 1);
213 path += "/../Resources/locale";
215 localedir = strdup (path.c_str());
217 /* write a pango.rc file and tell pango to use it. we'd love
218 to put this into the Ardour.app bundle and leave it there,
219 but the user may not have write permission. so ...
221 we also have to make sure that the user ardour directory
226 sys::create_directories (user_config_directory ());
228 catch (const sys::filesystem_error& ex) {
229 error << _("Could not create user configuration directory") << endmsg;
232 sys::path pangopath = user_config_directory();
233 pangopath /= "pango.rc";
234 path = pangopath.to_string();
236 std::ofstream pangorc (path.c_str());
238 error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
241 pangorc << "[Pango]\nModuleFiles=";
243 pangopath = dir_path;
245 pangopath /= "Resources";
246 pangopath /= "pango.modules";
248 pangorc << pangopath.to_string() << endl;
252 setenv ("PANGO_RC_FILE", path.c_str(), 1);
255 // gettext charset aliases
257 setenv ("CHARSETALIASDIR", path.c_str(), 1);
262 path += "/../Resources/fonts.conf";
264 setenv ("FONTCONFIG_FILE", path.c_str(), 1);
266 // GDK Pixbuf loader module file
269 path += "/../Resources/gdk-pixbuf.loaders";
271 setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
273 if (getenv ("ARDOUR_WITH_JACK")) {
277 path += "/../Frameworks";
279 setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
286 sigpipe_handler (int sig)
288 cerr << _("SIGPIPE received - JACK has probably died") << endl;
293 extern int gui_init (int* argc, char** argv[]);
295 /* this is called from the entry point of a wine-compiled
296 executable that is linked against gtk2_ardour built
300 int ardour_main (int argc, char *argv[])
302 int main (int argc, char *argv[])
305 vector<Glib::ustring> null_file_list;
308 fixup_bundle_environment ();
315 /* this does some magic that is needed to make GTK and Wine's own
316 X11 client interact properly.
318 gui_init (&argc, &argv);
321 (void) bindtextdomain (PACKAGE, localedir);
322 /* our i18n translations are all in UTF-8, so make sure
323 that even if the user locale doesn't specify UTF-8,
324 we use that when handling them.
326 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
327 (void) textdomain (PACKAGE);
329 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
331 // catch error message system signals ();
333 text_receiver.listen_to (error);
334 text_receiver.listen_to (info);
335 text_receiver.listen_to (fatal);
336 text_receiver.listen_to (warning);
338 if (parse_opts (argc, argv)) {
342 if (curvetest_file) {
343 return curvetest (curvetest_file);
346 cout << _("Ardour/GTK ")
348 << _(" (built using ")
351 << _(" and GCC version ") << __VERSION__
361 cerr << _("Copyright (C) 1999-2008 Paul Davis") << endl
362 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
364 << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
365 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
366 << _("This is free software, and you are welcome to redistribute it ") << endl
367 << _("under certain conditions; see the source for copying conditions.")
371 /* some GUI objects need this */
375 if (::signal (SIGPIPE, sigpipe_handler)) {
376 cerr << _("Cannot install SIGPIPE error handler") << endl;
380 ui = new ARDOUR_UI (&argc, &argv);
381 } catch (failed_constructor& err) {
382 error << _("could not create ARDOUR GUI") << endmsg;
386 ui->run (text_receiver);
390 pthread_cancel_all ();
394 } // end of extern C block