fix setting of BWF info (from 3.0). thanks carl
[ardour2.git] / gtk2_ardour / main.cc
blob98f06d18fda1ea4e0917f07e9e660c052b981430
1 /*
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.
20 #include <cstdlib>
21 #include <signal.h>
23 #include <sigc++/bind.h>
24 #include <gtkmm/settings.h>
25 #include <glibmm/ustring.h>
27 #include <pbd/error.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>
39 #include <gtkmm/main.h>
40 #include <gtkmm2ext/popup.h>
41 #include <gtkmm2ext/utils.h>
43 #include "version.h"
44 #include "ardour_ui.h"
45 #include "opts.h"
46 #include "enums.h"
48 #include "i18n.h"
50 using namespace Gtk;
51 using namespace ARDOUR_COMMAND_LINE;
52 using namespace ARDOUR;
53 using namespace PBD;
54 using namespace sigc;
56 TextReceiver text_receiver ("ardour");
58 extern int curvetest (string);
60 static ARDOUR_UI *ui = 0;
61 static const char* localedir = LOCALEDIR;
63 #ifdef __APPLE__
65 #include <mach-o/dyld.h>
66 #include <sys/param.h>
67 #include <fstream>
69 void
70 fixup_bundle_environment ()
72 if (!getenv ("ARDOUR_BUNDLED")) {
73 return;
76 char execpath[MAXPATHLEN+1];
77 uint32_t pathsz = sizeof (execpath);
79 _NSGetExecutablePath (execpath, &pathsz);
81 Glib::ustring exec_path (execpath);
82 Glib::ustring dir_path = Glib::path_get_dirname (exec_path);
83 Glib::ustring path;
84 const char *cstr = getenv ("PATH");
86 /* ensure that we find any bundled executables (e.g. JACK),
87 and find them before any instances of the same name
88 elsewhere in PATH
91 path = dir_path;
92 if (cstr) {
93 path += ':';
94 path += cstr;
96 setenv ("PATH", path.c_str(), 1);
98 path = dir_path;
99 path += "/../Resources";
100 path += dir_path;
101 path += "/../Resources/Surfaces";
102 path += dir_path;
103 path += "/../Resources/Panners";
105 setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
107 path = dir_path;
108 path += "/../Resources/icons:";
109 path += dir_path;
110 path += "/../Resources/pixmaps:";
111 path += dir_path;
112 path += "/../Resources/share:";
113 path += dir_path;
114 path += "/../Resources";
116 setenv ("ARDOUR_PATH", path.c_str(), 1);
117 setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
118 setenv ("ARDOUR_DATA_PATH", path.c_str(), 1);
120 path = dir_path;
121 path += "/../Resources";
122 setenv ("ARDOUR_INSTANT_XML_PATH", path.c_str(), 1);
124 cstr = getenv ("LADSPA_PATH");
125 if (cstr) {
126 path = cstr;
127 path += ':';
128 } else {
129 path = "";
131 path += dir_path;
132 path += "/../Plugins";
134 setenv ("LADSPA_PATH", path.c_str(), 1);
136 cstr = getenv ("VAMP_PATH");
137 if (cstr) {
138 path = cstr;
139 path += ':';
140 } else {
141 path = "";
143 path += dir_path;
144 path += "/../Frameworks";
146 setenv ("VAMP_PATH", path.c_str(), 1);
148 cstr = getenv ("ARDOUR_CONTROL_SURFACE_PATH");
149 if (cstr) {
150 path = cstr;
151 path += ':';
152 } else {
153 path = "";
155 path += dir_path;
156 path += "/../Surfaces";
158 setenv ("ARDOUR_CONTROL_SURFACE_PATH", path.c_str(), 1);
160 cstr = getenv ("LV2_PATH");
161 if (cstr) {
162 path = cstr;
163 path += ':';
164 } else {
165 path = "";
167 path += dir_path;
168 path += "/../Plugins";
170 setenv ("LV2_PATH", path.c_str(), 1);
172 path = dir_path;
173 path += "/../Frameworks/clearlooks";
175 setenv ("GTK_PATH", path.c_str(), 1);
177 path = dir_path;
178 path += "/../Resources/locale";
180 localedir = strdup (path.c_str());
182 /* write a pango.rc file and tell pango to use it. we'd love
183 to put this into the Ardour.app bundle and leave it there,
184 but the user may not have write permission. so ...
186 we also have to make sure that the user ardour directory
187 actually exists ...
190 if (g_mkdir_with_parents (ARDOUR::get_user_ardour_path().c_str(), 0755) < 0) {
191 error << string_compose (_("cannot create user ardour folder %1 (%2)"), ARDOUR::get_user_ardour_path(), strerror (errno))
192 << endmsg;
193 } else {
195 path = Glib::build_filename (ARDOUR::get_user_ardour_path(), "pango.rc");
197 std::ofstream pangorc (path.c_str());
198 if (!pangorc) {
199 error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
200 } else {
201 pangorc << "[Pango]\nModuleFiles=";
202 Glib::ustring mpath;
204 mpath = dir_path;
205 mpath += "/../Resources/pango.modules";
207 pangorc << mpath << endl;
209 pangorc.close ();
210 setenv ("PANGO_RC_FILE", path.c_str(), 1);
214 // gettext charset aliases
216 setenv ("CHARSETALIASDIR", path.c_str(), 1);
218 // font config
220 path = dir_path;
221 path += "/../Resources/fonts.conf";
223 setenv ("FONTCONFIG_FILE", path.c_str(), 1);
225 // GDK Pixbuf loader module file
227 path = dir_path;
228 path += "/../Resources/gdk-pixbuf.loaders";
230 setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
232 if (getenv ("ARDOUR_WITH_JACK")) {
233 // JACK driver dir
235 path = dir_path;
236 path += "/../Frameworks";
238 setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
242 #endif
244 static gboolean
245 tell_about_jack_death (void* /* ignored */)
247 if (AudioEngine::instance()->processed_frames() == 0) {
248 /* died during startup */
249 MessageDialog msg (_("JACK exited"), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK);
250 msg.set_position (Gtk::WIN_POS_CENTER);
251 msg.set_secondary_text (_(
252 "JACK exited unexpectedly, and without notifying Ardour.\n\
254 This could be due to misconfiguration or to an error inside JACK.\n\
256 Click OK to exit Ardour."));
258 msg.run ();
259 _exit (0);
261 } else {
263 /* engine has already run, so this is a mid-session JACK death */
265 MessageDialog* msg = manage (new MessageDialog (_("JACK exited"), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_NONE));
266 msg->set_secondary_text (_(
267 "JACK exited unexpectedly, and without notifying Ardour.\n\
269 This is probably due to an error inside JACK. You should restart JACK\n\
270 and reconnect Ardour to it, or exit Ardour now. You cannot save your\n\
271 session at this time, because we would lose your connection information.\n"));
272 msg->present ();
274 return false; /* do not call again */
277 static void
278 sigpipe_handler (int sig)
280 static bool done_the_jack_thing = false;
282 if (!done_the_jack_thing) {
283 AudioEngine::instance()->died ();
284 g_idle_add (tell_about_jack_death, 0);
285 done_the_jack_thing = true;
289 #ifdef HAVE_LV2
290 void close_external_ui_windows();
291 #endif
293 #ifdef VST_SUPPORT
295 extern int gui_init (int* argc, char** argv[]);
297 /* this is called from the entry point of a wine-compiled
298 executable that is linked against gtk2_ardour built
299 as a shared library.
302 extern "C" {
303 int ardour_main (int argc, char *argv[])
304 #else
305 int main (int argc, char* argv[])
306 #endif
308 vector<Glib::ustring> null_file_list;
310 #ifdef __APPLE__
311 fixup_bundle_environment ();
312 #endif
314 Glib::thread_init();
315 gtk_set_locale ();
317 #ifdef VST_SUPPORT
318 /* this does some magic that is needed to make GTK and Wine's own
319 X11 client interact properly.
321 gui_init (&argc, &argv);
322 #endif
324 (void) bindtextdomain (PACKAGE, localedir);
325 /* our i18n translations are all in UTF-8, so make sure
326 that even if the user locale doesn't specify UTF-8,
327 we use that when handling them.
329 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
330 (void) textdomain (PACKAGE);
332 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
334 // catch error message system signals ();
336 text_receiver.listen_to (error);
337 text_receiver.listen_to (info);
338 text_receiver.listen_to (fatal);
339 text_receiver.listen_to (warning);
341 if (parse_opts (argc, argv)) {
342 exit (1);
345 if (curvetest_file) {
346 return curvetest (curvetest_file);
349 cout << _("Ardour/GTK ")
350 << VERSIONSTRING
351 << _("\n (built using ")
352 << svn_revision
353 #ifdef __GNUC__
354 << _(" and GCC version ") << __VERSION__
355 #endif
356 << ')'
357 << endl;
359 if (just_version) {
360 exit (0);
363 if (no_splash) {
364 cerr << _("Copyright (C) 1999-2008 Paul Davis") << endl
365 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
366 << endl
367 << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
368 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
369 << _("This is free software, and you are welcome to redistribute it ") << endl
370 << _("under certain conditions; see the source for copying conditions.")
371 << endl;
374 /* some GUI objects need this */
376 PBD::ID::init ();
378 if (::signal (SIGPIPE, sigpipe_handler)) {
379 cerr << _("Cannot install SIGPIPE error handler") << endl;
382 try {
383 ui = new ARDOUR_UI (&argc, &argv);
384 } catch (failed_constructor& err) {
385 error << _("could not create ARDOUR GUI") << endmsg;
386 exit (1);
389 ui->run (text_receiver);
390 ui = 0;
392 ARDOUR::cleanup ();
393 pthread_cancel_all ();
394 #ifdef HAVE_LV2
395 close_external_ui_windows();
396 #endif
397 return 0;
399 #ifdef VST_SUPPORT
400 } // end of extern C block
401 #endif