/* Copyright (C) 2001-2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id$ */ #include #include #include #include #include #include #include #include #include #include #ifdef WITH_VERSION // XXX todo generate this, or consolidate build system #include #include "version.h" #endif #include #include #include #include #include "ardour_ui.h" #include "opts.h" #include "signal_handler.h" #include "debug.h" #ifdef GTKARDOUR_DEBUG #include #include #include #include "log_viewer.h" #endif #ifdef GTKARDOUR_DEBUG_THREADS #include "thread_names.h" #endif #include "i18n.h" using namespace Gtk; using namespace GTK_ARDOUR; using namespace ARDOUR; using namespace PBD; using namespace sigc; using std::cerr; using std::endl; static ARDOUR_UI *ui = 0; namespace { bool get_default_rc_file (string& rc_file) { // XXX Is this still needed or documented? rc_file = Glib::getenv ("ARDOUR2_UI_RC"); if (!rc_file.empty()) { return true; } if(PBD::find_file_in_path(ARDOUR::Paths::config_path(), X_("ardour2_ui.rc"), rc_file)) { return true; } return false; } } gint show_ui_callback (void *arg) { ARDOUR_UI * ui = (ARDOUR_UI *) arg; ui->hide_splash(); ui->show (); return FALSE; } void gui_jack_error () { MessageDialog win (_("Ardour could not connect to JACK."), false, Gtk::MESSAGE_INFO, (Gtk::ButtonsType)(Gtk::BUTTONS_NONE)); win.set_secondary_text(_("There are several possible reasons:\n\ \n\ 1) JACK is not running.\n\ 2) JACK is running as another user, perhaps root.\n\ 3) There is already another client called \"ardour\".\n\ \n\ Please consider the possibilities, and perhaps (re)start JACK.")); win.add_button (Stock::QUIT, RESPONSE_CLOSE); win.set_default_response (RESPONSE_CLOSE); win.show_all (); win.set_position (Gtk::WIN_POS_CENTER); /* we just don't care about the result */ win.run (); } #ifdef VST_SUPPORT /* this is called from the entry point of a wine-compiled executable that is linked against gtk2_ardour built as a shared library. */ extern "C" { int ardour_main (int argc, char *argv[]) #else int main (int argc, char *argv[]) #endif { Glib::thread_init(); #ifdef GTKARDOUR_DEBUG_THREADS PBD::thread_map().register_thread(GtkArdour::gui_thread_name); #endif #ifdef GTKARDOUR_DEBUG LogViewer gtk_ardour_log_viewer(GtkArdour::log_domain); LogViewer libardour_log_viewer(ARDOUR::log_domain); LogViewer libpbd_log_viewer(PBD::log_domain); LogViewer libgtkmm2ext_log_viewer(Gtkmm2ext::log_domain); #endif GtkArdourSignalHandler signal_handler; string rc_file; if(get_default_rc_file (rc_file)) { #ifdef GTKARDOUR_DEBUG_EXTRA LOG_GTKARDOUR_DEBUG << X_("Using RC file at path") << rc_file; #endif Gtk::RC::add_default_file(rc_file); } else { #ifdef GTKARDOUR_DEBUG LOG_GTKARDOUR_WARNING << X_("Unable to find UI RC file"); #endif } Gtk::Main kit(argc, argv); #ifdef ENABLE_NLS (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); #endif if (parse_opts (argc, argv)) { return EXIT_FAILURE; } // XXX version if (just_version) { return EXIT_SUCCESS; } if (no_splash) { cerr << _("Copyright (C) 1999-2006 Paul Davis") << endl << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl << endl << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl << _("This is free software, and you are welcome to redistribute it ") << endl << _("under certain conditions; see the source for copying conditions.") << endl; } ARDOUR::AudioEngine *engine; // Try and connect to JACK and if we can't just show the error // dialog and bail. try { engine = new ARDOUR::AudioEngine (jack_client_name); } catch (AudioEngine::NoBackendAvailable& err) { gui_jack_error (); #ifdef GTKARDOUR_DEBUG LOG_GTKARDOUR_ERROR << X_("Could not connect to JACK server with client name") << jack_client_name; #endif return EXIT_FAILURE; } // Initialize libardour. try { ARDOUR::init (*engine, use_vst, try_hw_optimization); } catch (failed_constructor& err) { #ifdef GTKARDOUR_DEBUG LOG_GTKARDOUR_ERROR << X_("Could not initialize Ardour"); #endif return EXIT_FAILURE; } // Try and create UI. try { ui = new ARDOUR_UI (); } catch (failed_constructor& err) { #ifdef GTKARDOUR_DEBUG LOG_GTKARDOUR_ERROR << X_("Could not create ARDOUR GUI"); #endif return EXIT_FAILURE; } ui->set_engine (*engine); if (!no_splash) { ui->show_splash (); if (command_line_session_file_path.length()) { gtk_timeout_add (4000, show_ui_callback, ui); } } if (!command_line_session_file_path.length()) { ui->hide_splash (); if (!Config->get_no_new_session_dialog()) { ui->new_session (true); } } else { // XXX need to convert this to a real path. ui->load_session (command_line_session_file_path); if (no_splash) { ui->show(); } } ui->run (); ui = 0; #ifdef GTKARDOUR_DEBUG_EXTRA LOG_GTKARDOUR_DEBUG << X_("Back in main()"); #endif /* * XXX todo * * what are the consequences of deleting the audio engine * before calling ARDOUR::cleanup. ARDOUR::init take a pointer * to the engine, by deleting it before cleanup is there the * possibility of dangling pointers etc. Deleting after would * be a reverse of the initialization order. */ delete engine; ARDOUR::cleanup (); #ifdef GTKARDOUR_DEBUG_THREADS // not needed but just being explicit. PBD::thread_map().unregister_thread(GtkArdour::gui_thread_name); #endif return EXIT_SUCCESS; } #ifdef VST_SUPPORT } // end of extern C block #endif