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/textreceiver.h>
27 #include <pbd/failed_constructor.h>
28 #include <pbd/pthread_utils.h>
30 #include <jack/jack.h>
32 #include <ardour/version.h>
33 #include <ardour/ardour.h>
34 #include <ardour/audioengine.h>
36 #include <gtkmm/main.h>
37 #include <gtkmm2ext/popup.h>
38 #include <gtkmm2ext/utils.h>
40 #include "svn_revision.h"
42 #include "ardour_ui.h"
49 using namespace GTK_ARDOUR;
50 using namespace ARDOUR;
54 TextReceiver text_receiver ("ardour");
56 extern int curvetest (string);
58 static ARDOUR_UI *ui = 0;
66 if ((env = getenv ("ARDOUR2_UI_RC")) != 0 && strlen (env)) {
69 rcfile = "ardour2_ui.rc";
72 rcfile = find_config_file (rcfile);
75 warning << _("Without a UI style file, ardour will look strange.\n Please set ARDOUR2_UI_RC to point to a valid UI style file") << endmsg;
77 cerr << "Loading ui configuration file " << rcfile << endl;
84 show_ui_callback (void *arg)
86 ARDOUR_UI * ui = (ARDOUR_UI *) arg;
96 MessageDialog win (_("Ardour could not connect to JACK."),
99 (Gtk::ButtonsType)(Gtk::BUTTONS_NONE));
100 win.set_secondary_text(_("There are several possible reasons:\n\
102 1) JACK is not running.\n\
103 2) JACK is running as another user, perhaps root.\n\
104 3) There is already another client called \"ardour\".\n\
106 Please consider the possibilities, and perhaps (re)start JACK."));
108 win.add_button (Stock::QUIT, RESPONSE_CLOSE);
109 win.set_default_response (RESPONSE_CLOSE);
112 win.set_position (Gtk::WIN_POS_CENTER);
118 /* we just don't care about the result, but we want to block */
124 maybe_load_session ()
126 /* If no session name is given: we're not loading a session yet, nor creating a new one */
127 if (!session_name.length()) {
129 if (!Config->get_no_new_session_dialog()) {
130 if (!ui->new_session ()) {
138 /* Load session or start the new session dialog */
143 if (Session::find_session (session_name, path, name, isnew)) {
144 error << string_compose(_("could not load command line session \"%1\""), session_name) << endmsg;
150 /* Loading a session, but the session doesn't exist */
152 error << string_compose (_("\n\nNo session named \"%1\" exists.\n"
153 "To create it from the command line, start ardour as \"ardour --new %1"), path)
158 if (ui->load_session (path, name)) {
165 /* TODO: This bit of code doesn't work properly yet
166 Glib::signal_idle().connect (bind (mem_fun (*ui, &ARDOUR_UI::cmdline_new_session), path));
167 ui->set_will_create_new_session_automatically (true);
172 if (!Config->get_no_new_session_dialog()) {
173 if (!ui->new_session ()) {
183 /* this is called from the entry point of a wine-compiled
184 executable that is linked against gtk2_ardour built
188 int ardour_main (int argc, char *argv[])
190 int main (int argc, char *argv[])
194 ARDOUR::AudioEngine *engine;
195 vector<Glib::ustring> null_file_list;
200 (void) bindtextdomain (PACKAGE, LOCALEDIR);
201 /* our i18n translations are all in UTF-8, so make sure
202 that even if the user locale doesn't specify UTF-8,
203 we use that when handling them.
205 (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
206 (void) textdomain (PACKAGE);
208 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
210 // catch error message system signals ();
212 text_receiver.listen_to (error);
213 text_receiver.listen_to (info);
214 text_receiver.listen_to (fatal);
215 text_receiver.listen_to (warning);
217 if (parse_opts (argc, argv)) {
221 if (curvetest_file) {
222 return curvetest (curvetest_file);
225 cout << _("Ardour/GTK ")
227 << _("\n (built using ")
228 << ardour_svn_revision
230 << _(" and GCC version ") << __VERSION__
240 cerr << _("Copyright (C) 1999-2007 Paul Davis") << endl
241 << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
243 << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
244 << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
245 << _("This is free software, and you are welcome to redistribute it ") << endl
246 << _("under certain conditions; see the source for copying conditions.")
250 /* some GUI objects need this */
255 ui = new ARDOUR_UI (&argc, &argv, which_ui_rcfile());
256 } catch (failed_constructor& err) {
257 error << _("could not create ARDOUR GUI") << endmsg;
261 if (!keybindings_path.empty()) {
262 ui->set_keybindings_path (keybindings_path);
267 if (session_name.length()) {
268 g_timeout_add (4000, show_ui_callback, ui);
273 ARDOUR::init (use_vst, try_hw_optimization);
274 setup_gtk_ardour_enums ();
275 Config->set_current_owner (ConfigVariableBase::Interface);
276 ui->setup_profile ();
279 engine = new ARDOUR::AudioEngine (jack_client_name);
280 } catch (AudioEngine::NoBackendAvailable& err) {
282 error << string_compose (_("Could not connect to JACK server as \"%1\""), jack_client_name) << endmsg;
286 ui->set_engine (*engine);
288 } catch (failed_constructor& err) {
289 error << _("could not initialize Ardour.") << endmsg;
295 if (maybe_load_session ()) {
296 ui->run (text_receiver);
307 pthread_cancel_all ();
314 } // end of extern C block