2 Copyright (C) 2001-2012 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.
26 #include <sigc++/bind.h>
27 #include <gtkmm/settings.h>
29 #include "pbd/error.h"
30 #include "pbd/file_utils.h"
31 #include "pbd/textreceiver.h"
32 #include "pbd/failed_constructor.h"
33 #include "pbd/pathexpand.h"
34 #include "pbd/pthread_utils.h"
35 #ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
36 #include "pbd/boost_debug.h"
39 #include "ardour/revision.h"
40 #include "ardour/version.h"
41 #include "ardour/ardour.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/session_utils.h"
44 #include "ardour/filesystem_paths.h"
46 #include <gtkmm/main.h>
47 #include <gtkmm2ext/application.h>
48 #include <gtkmm2ext/popup.h>
49 #include <gtkmm2ext/utils.h>
53 #include "ardour_ui.h"
56 #include "bundle_env.h"
61 #include <fcntl.h> // Needed for '_fmode'
66 using namespace ARDOUR_COMMAND_LINE;
67 using namespace ARDOUR;
70 TextReceiver text_receiver ("ardour");
72 extern int curvetest (string);
74 static ARDOUR_UI *ui = 0;
75 static const char* localedir = LOCALEDIR;
80 MessageDialog win (string_compose (_("%1 could not connect to the audio backend."), PROGRAM_NAME),
85 win.add_button (Stock::QUIT, RESPONSE_CLOSE);
86 win.set_default_response (RESPONSE_CLOSE);
89 win.set_position (Gtk::WIN_POS_CENTER);
95 /* we just don't care about the result, but we want to block */
101 tell_about_backend_death (void* /* ignored */)
103 if (AudioEngine::instance()->processed_frames() == 0) {
104 /* died during startup */
105 MessageDialog msg (string_compose (_("The audio backend (%1) has failed, or terminated"), AudioEngine::instance()->current_backend_name()), false);
106 msg.set_position (Gtk::WIN_POS_CENTER);
107 msg.set_secondary_text (string_compose (_(
108 "%2 exited unexpectedly, and without notifying %1.\n\
110 This could be due to misconfiguration or to an error inside %2.\n\
112 Click OK to exit %1."), PROGRAM_NAME, AudioEngine::instance()->current_backend_name()));
119 /* engine has already run, so this is a mid-session backend death */
121 MessageDialog msg (string_compose (_("The audio backend (%1) has failed, or terminated"), AudioEngine::instance()->current_backend_name()), false);
122 msg.set_secondary_text (string_compose (_("%2 exited unexpectedly, and without notifying %1."),
123 PROGRAM_NAME, AudioEngine::instance()->current_backend_name()));
126 return false; /* do not call again */
130 sigpipe_handler (int /*signal*/)
132 /* XXX fix this so that we do this again after a reconnect to the backend
135 static bool done_the_backend_thing = false;
137 if (!done_the_backend_thing) {
138 AudioEngine::instance()->died ();
139 g_idle_add (tell_about_backend_death, 0);
140 done_the_backend_thing = true;
144 #if (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
146 * Release build with MSVC uses ardour_main()
148 int ardour_main (int argc, char *argv[])
150 #elif (defined WINDOWS_VST_SUPPORT && !defined PLATFORM_WINDOWS)
152 // prototype for function in windows_vst_plugin_ui.cc
153 extern int windows_vst_gui_init (int* argc, char** argv[]);
155 /* this is called from the entry point of a wine-compiled
156 executable that is linked against gtk2_ardour built
161 int ardour_main (int argc, char *argv[])
164 int main (int argc, char *argv[])
168 // Essential!! Make sure that any files used by Ardour
169 // will be created or opened in BINARY mode!
173 fixup_bundle_environment (argc, argv, &localedir);
175 load_custom_fonts(); /* needs to happen before any gtk and pango init calls */
177 if (!Glib::thread_supported()) {
185 #if (defined WINDOWS_VST_SUPPORT && !defined PLATFORM_WINDOWS)
186 /* this does some magic that is needed to make GTK and X11 client interact properly.
187 * the platform dependent code is in windows_vst_plugin_ui.cc
189 windows_vst_gui_init (&argc, &argv);
193 cerr << "bind txt domain [" << PACKAGE << "] to " << localedir << endl;
195 (void) bindtextdomain (PACKAGE, localedir);
196 /* our i18n translations are all in UTF-8, so make sure
197 that even if the user locale doesn't specify UTF-8,
198 we use that when handling them.
200 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
203 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
205 // catch error message system signals ();
207 text_receiver.listen_to (error);
208 text_receiver.listen_to (info);
209 text_receiver.listen_to (fatal);
210 text_receiver.listen_to (warning);
212 #ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
213 if (g_getenv ("BOOST_DEBUG")) {
214 boost_debug_shared_ptr_show_live_debugging (true);
218 if (parse_opts (argc, argv)) {
219 #if (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
220 // Since we don't ordinarily have access to stdout and stderr with
221 // an MSVC app, let the user know we encountered a parsing error.
222 Gtk::Main app(&argc, &argv); // Calls 'gtk_init()'
224 Gtk::MessageDialog dlgReportParseError (_("\n Ardour could not understand your command line "),
225 false, MESSAGE_ERROR, BUTTONS_CLOSE, true);
226 dlgReportParseError.set_title (_("An error was encountered while launching Ardour"));
227 dlgReportParseError.run ();
234 << _(" (built using ")
237 << _(" and GCC version ") << __VERSION__
247 cerr << _("Copyright (C) 1999-2012 Paul Davis") << endl
248 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker, Robin Gareus") << endl
250 << string_compose (_("%1 comes with ABSOLUTELY NO WARRANTY"), PROGRAM_NAME) << endl
251 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
252 << _("This is free software, and you are welcome to redistribute it ") << endl
253 << _("under certain conditions; see the source for copying conditions.")
257 /* some GUI objects need this */
259 if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) {
260 error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg;
264 if (curvetest_file) {
265 return curvetest (curvetest_file);
268 #ifndef PLATFORM_WINDOWS
269 if (::signal (SIGPIPE, sigpipe_handler)) {
270 cerr << _("Cannot xinstall SIGPIPE error handler") << endl;
275 ui = new ARDOUR_UI (&argc, &argv, localedir);
276 } catch (failed_constructor& err) {
277 error << string_compose (_("could not create %1 GUI"), PROGRAM_NAME) << endmsg;
281 ui->run (text_receiver);
282 Gtkmm2ext::Application::instance()->cleanup();
287 pthread_cancel_all ();
291 #if (defined WINDOWS_VST_SUPPORT && !defined PLATFORM_WINDOWS)
292 } // end of extern "C" block