2 Copyright (C) 1999-2013 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.
21 #include "gtk2ardour-config.h"
22 #include "gtk2ardour-version.h"
31 #ifndef PLATFORM_WINDOWS
32 #include <sys/resource.h>
42 #include <glib/gstdio.h>
44 #include <gtkmm/messagedialog.h>
45 #include <gtkmm/accelmap.h>
47 #include "pbd/error.h"
48 #include "pbd/basename.h"
49 #include "pbd/compose.h"
50 #include "pbd/failed_constructor.h"
51 #include "pbd/enumwriter.h"
52 #include "pbd/memento_command.h"
53 #include "pbd/openuri.h"
54 #include "pbd/stl_delete.h"
55 #include "pbd/file_utils.h"
56 #include "pbd/localtime_r.h"
57 #include "pbd/pthread_utils.h"
59 #include "gtkmm2ext/application.h"
60 #include "gtkmm2ext/bindings.h"
61 #include "gtkmm2ext/gtk_ui.h"
62 #include "gtkmm2ext/utils.h"
63 #include "gtkmm2ext/click_box.h"
64 #include "gtkmm2ext/fastmeter.h"
65 #include "gtkmm2ext/popup.h"
66 #include "gtkmm2ext/window_title.h"
68 #include "ardour/ardour.h"
69 #include "ardour/audio_backend.h"
70 #include "ardour/audioengine.h"
71 #include "ardour/audiofilesource.h"
72 #include "ardour/automation_watch.h"
73 #include "ardour/diskstream.h"
74 #include "ardour/filename_extensions.h"
75 #include "ardour/filesystem_paths.h"
76 #include "ardour/port.h"
77 #include "ardour/plugin_manager.h"
78 #include "ardour/process_thread.h"
79 #include "ardour/profile.h"
80 #include "ardour/recent_sessions.h"
81 #include "ardour/session_directory.h"
82 #include "ardour/session_route.h"
83 #include "ardour/session_state_utils.h"
84 #include "ardour/session_utils.h"
85 #include "ardour/slave.h"
86 #include "ardour/system_exec.h"
88 #ifdef WINDOWS_VST_SUPPORT
91 #ifdef AUDIOUNIT_SUPPORT
92 #include "ardour/audio_unit.h"
95 #include "timecode/time.h"
97 typedef uint64_t microseconds_t;
101 #include "add_route_dialog.h"
102 #include "ambiguous_file_dialog.h"
103 #include "ardour_ui.h"
104 #include "audio_clock.h"
105 #include "big_clock_window.h"
106 #include "bundle_manager.h"
107 #include "engine_dialog.h"
108 #include "gain_meter.h"
109 #include "global_port_matrix.h"
110 #include "gui_object.h"
111 #include "gui_thread.h"
112 #include "keyboard.h"
113 #include "keyeditor.h"
114 #include "location_ui.h"
115 #include "main_clock.h"
116 #include "missing_file_dialog.h"
117 #include "missing_plugin_dialog.h"
118 #include "mixer_ui.h"
119 #include "mouse_cursors.h"
122 #include "pingback.h"
123 #include "processor_box.h"
124 #include "prompter.h"
125 #include "public_editor.h"
126 #include "rc_option_editor.h"
127 #include "route_time_axis.h"
128 #include "route_params_ui.h"
129 #include "session_dialog.h"
130 #include "session_metadata_dialog.h"
131 #include "session_option_editor.h"
132 #include "shuttle_control.h"
133 #include "speaker_dialog.h"
136 #include "theme_manager.h"
137 #include "time_axis_view_item.h"
139 #include "video_server_dialog.h"
140 #include "add_video_dialog.h"
141 #include "transcode_video_dialog.h"
145 using namespace ARDOUR;
146 using namespace ARDOUR_UI_UTILS;
148 using namespace Gtkmm2ext;
152 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
153 UIConfiguration *ARDOUR_UI::ui_config = 0;
155 sigc::signal<void,bool> ARDOUR_UI::Blink;
156 sigc::signal<void> ARDOUR_UI::RapidScreenUpdate;
157 sigc::signal<void> ARDOUR_UI::SuperRapidScreenUpdate;
158 sigc::signal<void> ARDOUR_UI::FPSUpdate;
159 sigc::signal<void, framepos_t, bool, framepos_t> ARDOUR_UI::Clock;
160 sigc::signal<void> ARDOUR_UI::CloseAllDialogs;
162 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
164 : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
166 , gui_object_state (new GUIObjectState)
168 , primary_clock (new MainClock (X_("primary"), false, X_("transport"), true, true, true, false, true))
169 , secondary_clock (new MainClock (X_("secondary"), false, X_("secondary"), true, true, false, false, true))
173 , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
176 /* start of private members */
180 , _mixer_on_top (false)
181 , first_time_engine_run (true)
182 , blink_timeout_tag (-1)
186 , roll_controllable (new TransportControllable ("transport roll", *this, TransportControllable::Roll))
187 , stop_controllable (new TransportControllable ("transport stop", *this, TransportControllable::Stop))
188 , goto_start_controllable (new TransportControllable ("transport goto start", *this, TransportControllable::GotoStart))
189 , goto_end_controllable (new TransportControllable ("transport goto end", *this, TransportControllable::GotoEnd))
190 , auto_loop_controllable (new TransportControllable ("transport auto loop", *this, TransportControllable::AutoLoop))
191 , play_selection_controllable (new TransportControllable ("transport play selection", *this, TransportControllable::PlaySelection))
192 , rec_controllable (new TransportControllable ("transport rec-enable", *this, TransportControllable::RecordEnable))
194 , auto_return_button (ArdourButton::led_default_elements)
195 , follow_edits_button (ArdourButton::led_default_elements)
196 , auto_input_button (ArdourButton::led_default_elements)
198 , auditioning_alert_button (_("Audition"))
199 , solo_alert_button (_("Solo"))
200 , feedback_alert_button (_("Feedback"))
203 , editor_meter_peak_display()
205 , speaker_config_window (X_("speaker-config"), _("Speaker Configuration"))
206 , theme_manager (X_("theme-manager"), _("Theme Manager"))
207 , key_editor (X_("key-editor"), _("Key Bindings"))
208 , rc_option_editor (X_("rc-options-editor"), _("Preferences"))
209 , add_route_dialog (X_("add-routes"), _("Add Tracks/Busses"))
210 , about (X_("about"), _("About"))
211 , location_ui (X_("locations"), _("Locations"))
212 , route_params (X_("inspector"), _("Tracks and Busses"))
213 , audio_midi_setup (X_("audio-midi-setup"), _("Audio/MIDI Setup"))
214 , session_option_editor (X_("session-options-editor"), _("Properties"), boost::bind (&ARDOUR_UI::create_session_option_editor, this))
215 , add_video_dialog (X_("add-video"), _("Add Tracks/Busses"), boost::bind (&ARDOUR_UI::create_add_video_dialog, this))
216 , bundle_manager (X_("bundle-manager"), _("Bundle Manager"), boost::bind (&ARDOUR_UI::create_bundle_manager, this))
217 , big_clock_window (X_("big-clock"), _("Big Clock"), boost::bind (&ARDOUR_UI::create_big_clock_window, this))
218 , audio_port_matrix (X_("audio-connection-manager"), _("Audio Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::AUDIO))
219 , midi_port_matrix (X_("midi-connection-manager"), _("MIDI Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::MIDI))
221 , error_log_button (_("Errors"))
223 , _status_bar_visibility (X_("status-bar"))
224 , _feedback_exists (false)
226 Gtkmm2ext::init(localedir);
230 _numpad_locate_happening = false;
232 if (theArdourUI == 0) {
236 ui_config = new UIConfiguration();
238 ui_config->ParameterChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::parameter_changed));
239 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
240 ui_config->map_parameters (pc);
246 _session_is_new = false;
247 session_selector_window = 0;
248 last_key_press_time = 0;
249 video_server_process = 0;
250 open_session_selector = 0;
251 have_configure_timeout = false;
252 have_disk_speed_dialog_displayed = false;
253 session_loaded = false;
254 ignore_dual_punch = false;
256 roll_button.set_controllable (roll_controllable);
257 stop_button.set_controllable (stop_controllable);
258 goto_start_button.set_controllable (goto_start_controllable);
259 goto_end_button.set_controllable (goto_end_controllable);
260 auto_loop_button.set_controllable (auto_loop_controllable);
261 play_selection_button.set_controllable (play_selection_controllable);
262 rec_button.set_controllable (rec_controllable);
264 roll_button.set_name ("transport button");
265 stop_button.set_name ("transport button");
266 goto_start_button.set_name ("transport button");
267 goto_end_button.set_name ("transport button");
268 auto_loop_button.set_name ("transport button");
269 play_selection_button.set_name ("transport button");
270 rec_button.set_name ("transport recenable button");
271 midi_panic_button.set_name ("transport button");
273 last_configure_time= 0;
276 ARDOUR::Diskstream::DiskOverrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
277 ARDOUR::Diskstream::DiskUnderrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
279 ARDOUR::Session::VersionMismatch.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_format_mismatch, this, _1, _2), gui_context());
281 /* handle dialog requests */
283 ARDOUR::Session::Dialog.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_dialog, this, _1), gui_context());
285 /* handle pending state with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
287 ARDOUR::Session::AskAboutPendingState.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::pending_state_dialog, this));
289 /* handle Audio/MIDI setup when session requires it */
291 ARDOUR::Session::AudioEngineSetupRequired.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::do_audio_midi_setup, this, _1));
293 /* handle sr mismatch with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
295 ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
297 /* handle requests to quit (coming from JACK session) */
299 ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
301 /* tell the user about feedback */
303 ARDOUR::Session::FeedbackDetected.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::feedback_detected, this), gui_context ());
304 ARDOUR::Session::SuccessfulGraphSort.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::successful_graph_sort, this), gui_context ());
306 /* handle requests to deal with missing files */
308 ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3));
310 /* and ambiguous files */
312 ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2));
314 /* also plugin scan messages */
315 ARDOUR::PluginScanMessage.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::plugin_scan_dialog, this, _1, _2, _3), gui_context());
316 ARDOUR::PluginScanTimeout.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::plugin_scan_timeout, this, _1), gui_context());
318 ARDOUR::GUIIdle.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::gui_idle_handler, this), gui_context());
320 Config->ParameterChanged.connect ( forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::set_flat_buttons, this), gui_context() );
323 /* lets get this party started */
325 setup_gtk_ardour_enums ();
328 SessionEvent::create_per_thread_pool ("GUI", 512);
330 /* we like keyboards */
332 keyboard = new ArdourKeyboard(*this);
334 XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
336 keyboard->set_state (*node, Stateful::loading_state_version);
339 /* we don't like certain modifiers */
340 Bindings::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK);
344 TimeAxisViewItem::set_constant_heights ();
346 /* Set this up so that our window proxies can register actions */
348 ActionManager::init ();
350 /* The following must happen after ARDOUR::init() so that Config is set up */
352 const XMLNode* ui_xml = Config->extra_xml (X_("UI"));
355 theme_manager.set_state (*ui_xml);
356 key_editor.set_state (*ui_xml);
357 rc_option_editor.set_state (*ui_xml);
358 session_option_editor.set_state (*ui_xml);
359 speaker_config_window.set_state (*ui_xml);
360 about.set_state (*ui_xml);
361 add_route_dialog.set_state (*ui_xml);
362 add_video_dialog.set_state (*ui_xml);
363 route_params.set_state (*ui_xml);
364 bundle_manager.set_state (*ui_xml);
365 location_ui.set_state (*ui_xml);
366 big_clock_window.set_state (*ui_xml);
367 audio_port_matrix.set_state (*ui_xml);
368 midi_port_matrix.set_state (*ui_xml);
371 WM::Manager::instance().register_window (&theme_manager);
372 WM::Manager::instance().register_window (&key_editor);
373 WM::Manager::instance().register_window (&rc_option_editor);
374 WM::Manager::instance().register_window (&session_option_editor);
375 WM::Manager::instance().register_window (&speaker_config_window);
376 WM::Manager::instance().register_window (&about);
377 WM::Manager::instance().register_window (&add_route_dialog);
378 WM::Manager::instance().register_window (&add_video_dialog);
379 WM::Manager::instance().register_window (&route_params);
380 WM::Manager::instance().register_window (&audio_midi_setup);
381 WM::Manager::instance().register_window (&bundle_manager);
382 WM::Manager::instance().register_window (&location_ui);
383 WM::Manager::instance().register_window (&big_clock_window);
384 WM::Manager::instance().register_window (&audio_port_matrix);
385 WM::Manager::instance().register_window (&midi_port_matrix);
387 /* We need to instantiate the theme manager because it loads our
388 theme files. This should really change so that its window
389 and its functionality are separate
392 (void) theme_manager.get (true);
394 _process_thread = new ProcessThread ();
395 _process_thread->init ();
397 DPIReset.connect (sigc::mem_fun (*this, &ARDOUR_UI::resize_text_widgets));
402 GlobalPortMatrixWindow*
403 ARDOUR_UI::create_global_port_matrix (ARDOUR::DataType type)
408 return new GlobalPortMatrixWindow (_session, type);
412 ARDOUR_UI::attach_to_engine ()
414 AudioEngine::instance()->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context());
415 ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
419 ARDOUR_UI::engine_stopped ()
421 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_stopped)
422 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, false);
423 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, true);
427 ARDOUR_UI::engine_running ()
429 if (first_time_engine_run) {
431 first_time_engine_run = false;
434 update_disk_space ();
436 update_sample_rate (AudioEngine::instance()->sample_rate());
437 update_timecode_format ();
441 ARDOUR_UI::engine_halted (const char* reason, bool free_reason)
443 if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
444 /* we can't rely on the original string continuing to exist when we are called
445 again in the GUI thread, so make a copy and note that we need to
448 char *copy = strdup (reason);
449 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ARDOUR_UI::engine_halted, this, copy, true));
453 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, false);
454 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, true);
456 update_sample_rate (0);
460 /* if the reason is a non-empty string, it means that the backend was shutdown
461 rather than just Ardour.
464 if (strlen (reason)) {
465 msgstr = string_compose (_("The audio backend was shutdown because:\n\n%1"), reason);
467 msgstr = string_compose (_("\
468 The audio backend has either been shutdown or it\n\
469 disconnected %1 because %1\n\
470 was not fast enough. Try to restart\n\
471 the audio backend and save the session."), PROGRAM_NAME);
474 MessageDialog msg (*editor, msgstr);
475 pop_back_splash (msg);
476 msg.set_keep_above (true);
480 free (const_cast<char*> (reason));
485 ARDOUR_UI::post_engine ()
487 /* Things to be done once (and once ONLY) after we have a backend running in the AudioEngine
489 #ifdef AUDIOUNIT_SUPPORT
491 if (AUPluginInfo::au_get_crashlog(au_msg)) {
492 popup_error(_("Audio Unit Plugin Scan Failed. Automatic AU scanning has been disabled. Please see the log window for further details."));
493 error << _("Audio Unit Plugin Scan Failed:") << endmsg;
494 info << au_msg << endmsg;
498 ARDOUR::init_post_engine ();
500 /* connect to important signals */
502 AudioEngine::instance()->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
503 AudioEngine::instance()->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
504 AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
508 if (setup_windows ()) {
509 throw failed_constructor ();
512 /* Do this after setup_windows (), as that's when the _status_bar_visibility is created */
513 XMLNode* n = Config->extra_xml (X_("UI"));
515 _status_bar_visibility.set_state (*n);
518 check_memory_locking();
520 /* this is the first point at which all the keybindings are available */
522 if (ARDOUR_COMMAND_LINE::show_key_actions) {
523 vector<string> names;
524 vector<string> paths;
525 vector<string> tooltips;
527 vector<AccelKey> bindings;
529 ActionManager::get_all_actions (names, paths, tooltips, keys, bindings);
531 vector<string>::iterator n;
532 vector<string>::iterator k;
533 vector<string>::iterator p;
534 for (n = names.begin(), k = keys.begin(), p = paths.begin(); n != names.end(); ++n, ++k, ++p) {
535 cout << "Action: '" << (*n) << "' bound to '" << (*k) << "' Path: '" << (*p) << "'" << endl;
538 halt_connection.disconnect ();
539 AudioEngine::instance()->stop ();
543 blink_timeout_tag = -1;
545 /* this being a GUI and all, we want peakfiles */
547 AudioFileSource::set_build_peakfiles (true);
548 AudioFileSource::set_build_missing_peakfiles (true);
550 /* set default clock modes */
552 if (Profile->get_sae()) {
553 primary_clock->set_mode (AudioClock::BBT);
554 secondary_clock->set_mode (AudioClock::MinSec);
556 primary_clock->set_mode (AudioClock::Timecode);
557 secondary_clock->set_mode (AudioClock::BBT);
560 /* start the time-of-day-clock */
563 /* OS X provides a nearly-always visible wallclock, so don't be stupid */
564 update_wall_clock ();
565 Glib::signal_timeout().connect_seconds (sigc::mem_fun(*this, &ARDOUR_UI::update_wall_clock), 1);
570 Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
571 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
572 Config->map_parameters (pc);
576 ARDOUR_UI::~ARDOUR_UI ()
578 if (ui_config->dirty()) {
579 ui_config->save_state();
584 if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
585 // don't bother at 'real' exit. the OS cleans up for us.
587 delete primary_clock;
588 delete secondary_clock;
589 delete _process_thread;
590 delete gui_object_state;
591 FastMeter::flush_pattern_cache ();
596 ARDOUR_UI::pop_back_splash (Gtk::Window& win)
598 if (Splash::instance()) {
599 Splash::instance()->pop_back_for (win);
604 ARDOUR_UI::configure_timeout ()
606 if (last_configure_time == 0) {
607 /* no configure events yet */
611 /* force a gap of 0.5 seconds since the last configure event
614 if (get_microseconds() - last_configure_time < 500000) {
617 have_configure_timeout = false;
618 save_ardour_state ();
624 ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
626 if (have_configure_timeout) {
627 last_configure_time = get_microseconds();
629 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::configure_timeout), 100);
630 have_configure_timeout = true;
637 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
639 const XMLProperty* prop;
641 if ((prop = node.property ("roll")) != 0) {
642 roll_controllable->set_id (prop->value());
644 if ((prop = node.property ("stop")) != 0) {
645 stop_controllable->set_id (prop->value());
647 if ((prop = node.property ("goto-start")) != 0) {
648 goto_start_controllable->set_id (prop->value());
650 if ((prop = node.property ("goto-end")) != 0) {
651 goto_end_controllable->set_id (prop->value());
653 if ((prop = node.property ("auto-loop")) != 0) {
654 auto_loop_controllable->set_id (prop->value());
656 if ((prop = node.property ("play-selection")) != 0) {
657 play_selection_controllable->set_id (prop->value());
659 if ((prop = node.property ("rec")) != 0) {
660 rec_controllable->set_id (prop->value());
662 if ((prop = node.property ("shuttle")) != 0) {
663 shuttle_box->controllable()->set_id (prop->value());
668 ARDOUR_UI::get_transport_controllable_state ()
670 XMLNode* node = new XMLNode(X_("TransportControllables"));
673 roll_controllable->id().print (buf, sizeof (buf));
674 node->add_property (X_("roll"), buf);
675 stop_controllable->id().print (buf, sizeof (buf));
676 node->add_property (X_("stop"), buf);
677 goto_start_controllable->id().print (buf, sizeof (buf));
678 node->add_property (X_("goto_start"), buf);
679 goto_end_controllable->id().print (buf, sizeof (buf));
680 node->add_property (X_("goto_end"), buf);
681 auto_loop_controllable->id().print (buf, sizeof (buf));
682 node->add_property (X_("auto_loop"), buf);
683 play_selection_controllable->id().print (buf, sizeof (buf));
684 node->add_property (X_("play_selection"), buf);
685 rec_controllable->id().print (buf, sizeof (buf));
686 node->add_property (X_("rec"), buf);
687 shuttle_box->controllable()->id().print (buf, sizeof (buf));
688 node->add_property (X_("shuttle"), buf);
695 ARDOUR_UI::autosave_session ()
697 if (g_main_depth() > 1) {
698 /* inside a recursive main loop,
699 give up because we may not be able to
705 if (!Config->get_periodic_safety_backups()) {
710 _session->maybe_write_autosave();
717 ARDOUR_UI::update_autosave ()
719 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_autosave)
721 if (_session && _session->dirty()) {
722 if (_autosave_connection.connected()) {
723 _autosave_connection.disconnect();
726 _autosave_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &ARDOUR_UI::autosave_session),
727 Config->get_periodic_safety_backup_interval() * 1000);
730 if (_autosave_connection.connected()) {
731 _autosave_connection.disconnect();
737 ARDOUR_UI::check_announcements ()
740 string _annc_filename;
743 _annc_filename = PROGRAM_NAME "_announcements_osx_";
745 _annc_filename = PROGRAM_NAME "_announcements_linux_";
747 _annc_filename.append (VERSIONSTRING);
749 std::string path = Glib::build_filename (user_config_directory(), _annc_filename);
750 std::ifstream announce_file (path.c_str());
751 if ( announce_file.fail() )
752 _announce_string = "";
754 std::stringstream oss;
755 oss << announce_file.rdbuf();
756 _announce_string = oss.str();
759 pingback (VERSIONSTRING, path);
764 ARDOUR_UI::starting ()
766 Application* app = Application::instance ();
768 bool brand_new_user = ArdourStartup::required ();
770 app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish));
771 app->ShouldLoad.connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_load));
773 if (ARDOUR_COMMAND_LINE::check_announcements) {
774 check_announcements ();
779 /* we need to create this early because it may need to set the
780 * audio backend end up.
784 audio_midi_setup.get (true);
786 std::cerr << "audio-midi engine setup failed."<< std::endl;
790 if ((nsm_url = g_getenv ("NSM_URL")) != 0) {
791 nsm = new NSM_Client;
792 if (!nsm->init (nsm_url)) {
793 nsm->announce (PROGRAM_NAME, ":dirty:", "ardour3");
796 // wait for announce reply from nsm server
797 for ( i = 0; i < 5000; ++i) {
801 if (nsm->is_active()) {
806 error << _("NSM server did not announce itself") << endmsg;
809 // wait for open command from nsm server
810 for ( i = 0; i < 5000; ++i) {
813 if (nsm->client_id ()) {
819 error << _("NSM: no client ID provided") << endmsg;
823 if (_session && nsm) {
824 _session->set_nsm_state( nsm->is_active() );
826 error << _("NSM: no session created") << endmsg;
830 // nsm requires these actions disabled
831 vector<string> action_names;
832 action_names.push_back("SaveAs");
833 action_names.push_back("Rename");
834 action_names.push_back("New");
835 action_names.push_back("Open");
836 action_names.push_back("Recent");
837 action_names.push_back("Close");
839 for (vector<string>::const_iterator n = action_names.begin(); n != action_names.end(); ++n) {
840 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), (*n).c_str());
842 act->set_sensitive (false);
849 error << _("NSM: initialization failed") << endmsg;
855 if (brand_new_user) {
860 switch (s.response ()) {
861 case Gtk::RESPONSE_OK:
868 /* go get a session */
870 const bool new_session_required = (ARDOUR_COMMAND_LINE::new_session || brand_new_user);
872 if (get_session_parameters (false, new_session_required, ARDOUR_COMMAND_LINE::load_template)) {
873 std::cerr << "Cannot get session parameters."<< std::endl;
880 goto_editor_window ();
882 WM::Manager::instance().show_visible ();
884 /* We have to do this here since goto_editor_window() ends up calling show_all() on the
885 * editor window, and we may want stuff to be hidden.
887 _status_bar_visibility.update ();
889 BootMessage (string_compose (_("%1 is ready for use"), PROGRAM_NAME));
894 ARDOUR_UI::check_memory_locking ()
896 #if defined(__APPLE__) || defined(PLATFORM_WINDOWS)
897 /* OS X doesn't support mlockall(2), and so testing for memory locking capability there is pointless */
901 XMLNode* memory_warning_node = Config->instant_xml (X_("no-memory-warning"));
903 if (AudioEngine::instance()->is_realtime() && memory_warning_node == 0) {
905 struct rlimit limits;
907 long pages, page_size;
909 size_t pages_len=sizeof(pages);
910 if ((page_size = getpagesize()) < 0 ||
911 sysctlbyname("hw.availpages", &pages, &pages_len, NULL, 0))
913 if ((page_size = sysconf (_SC_PAGESIZE)) < 0 ||(pages = sysconf (_SC_PHYS_PAGES)) < 0)
918 ram = (int64_t) pages * (int64_t) page_size;
921 if (getrlimit (RLIMIT_MEMLOCK, &limits)) {
925 if (limits.rlim_cur != RLIM_INFINITY) {
927 if (ram == 0 || ((double) limits.rlim_cur / ram) < 0.75) {
931 _("WARNING: Your system has a limit for maximum amount of locked memory. "
932 "This might cause %1 to run out of memory before your system "
933 "runs out of memory. \n\n"
934 "You can view the memory limit with 'ulimit -l', "
935 "and it is normally controlled by %2"),
938 X_("/etc/login.conf")
940 X_(" /etc/security/limits.conf")
944 msg.set_default_response (RESPONSE_OK);
946 VBox* vbox = msg.get_vbox();
948 CheckButton cb (_("Do not show this window again"));
949 hbox.pack_start (cb, true, false);
950 vbox->pack_start (hbox);
955 pop_back_splash (msg);
957 editor->ensure_float (msg);
960 if (cb.get_active()) {
961 XMLNode node (X_("no-memory-warning"));
962 Config->add_instant_xml (node);
972 ARDOUR_UI::queue_finish ()
974 Glib::signal_idle().connect (mem_fun (*this, &ARDOUR_UI::idle_finish));
978 ARDOUR_UI::idle_finish ()
981 return false; /* do not call again */
988 ARDOUR_UI::instance()->video_timeline->sync_session_state();
990 if (_session->dirty()) {
991 vector<string> actions;
992 actions.push_back (_("Don't quit"));
993 actions.push_back (_("Just quit"));
994 actions.push_back (_("Save and quit"));
995 switch (ask_about_saving_session(actions)) {
1000 /* use the default name */
1001 if (save_state_canfail ("")) {
1002 /* failed - don't quit */
1003 MessageDialog msg (*editor,
1004 string_compose (_("\
1005 %1 was unable to save your session.\n\n\
1006 If you still wish to quit, please use the\n\n\
1007 \"Just quit\" option."), PROGRAM_NAME));
1008 pop_back_splash(msg);
1018 second_connection.disconnect ();
1019 point_one_second_connection.disconnect ();
1020 #ifndef PLATFORM_WINDOWS
1021 point_zero_something_second_connection.disconnect();
1023 fps_connection.disconnect();
1026 delete ARDOUR_UI::instance()->video_timeline;
1027 ARDOUR_UI::instance()->video_timeline = NULL;
1028 stop_video_server();
1030 /* Save state before deleting the session, as that causes some
1031 windows to be destroyed before their visible state can be
1034 save_ardour_state ();
1036 close_all_dialogs ();
1039 // _session->set_deletion_in_progress ();
1040 _session->set_clean ();
1041 _session->remove_pending_capture_state ();
1046 halt_connection.disconnect ();
1047 AudioEngine::instance()->stop ();
1048 #ifdef WINDOWS_VST_SUPPORT
1049 fst_stop_threading();
1055 ARDOUR_UI::ask_about_saving_session (const vector<string>& actions)
1057 ArdourDialog window (_("Unsaved Session"));
1058 Gtk::HBox dhbox; // the hbox for the image and text
1059 Gtk::Label prompt_label;
1060 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_WARNING, Gtk::ICON_SIZE_DIALOG));
1064 assert (actions.size() >= 3);
1066 window.add_button (actions[0], RESPONSE_REJECT);
1067 window.add_button (actions[1], RESPONSE_APPLY);
1068 window.add_button (actions[2], RESPONSE_ACCEPT);
1070 window.set_default_response (RESPONSE_ACCEPT);
1072 Gtk::Button noquit_button (msg);
1073 noquit_button.set_name ("EditorGTKButton");
1077 if (_session->snap_name() == _session->name()) {
1078 prompt = string_compose(_("The session \"%1\"\nhas not been saved.\n\nAny changes made this time\nwill be lost unless you save it.\n\nWhat do you want to do?"),
1079 _session->snap_name());
1081 prompt = string_compose(_("The snapshot \"%1\"\nhas not been saved.\n\nAny changes made this time\nwill be lost unless you save it.\n\nWhat do you want to do?"),
1082 _session->snap_name());
1085 prompt_label.set_text (prompt);
1086 prompt_label.set_name (X_("PrompterLabel"));
1087 prompt_label.set_alignment(ALIGN_LEFT, ALIGN_TOP);
1089 dimage->set_alignment(ALIGN_CENTER, ALIGN_TOP);
1090 dhbox.set_homogeneous (false);
1091 dhbox.pack_start (*dimage, false, false, 5);
1092 dhbox.pack_start (prompt_label, true, false, 5);
1093 window.get_vbox()->pack_start (dhbox);
1095 window.set_name (_("Prompter"));
1096 window.set_modal (true);
1097 window.set_resizable (false);
1100 prompt_label.show();
1103 window.set_keep_above (true);
1106 ResponseType r = (ResponseType) window.run();
1111 case RESPONSE_ACCEPT: // save and get out of here
1113 case RESPONSE_APPLY: // get out of here
1124 ARDOUR_UI::every_second ()
1127 update_buffer_load ();
1128 update_disk_space ();
1129 update_timecode_format ();
1131 if (nsm && nsm->is_active ()) {
1134 if (!_was_dirty && _session->dirty ()) {
1138 else if (_was_dirty && !_session->dirty ()){
1147 ARDOUR_UI::every_point_one_seconds ()
1149 shuttle_box->update_speed_display ();
1150 RapidScreenUpdate(); /* EMIT_SIGNAL */
1155 ARDOUR_UI::every_point_zero_something_seconds ()
1157 // august 2007: actual update frequency: 25Hz (40ms), not 100Hz
1159 SuperRapidScreenUpdate(); /* EMIT_SIGNAL */
1160 if (editor_meter && Config->get_show_editor_meter()) {
1161 float mpeak = editor_meter->update_meters();
1162 if (mpeak > editor_meter_max_peak) {
1163 if (mpeak >= Config->get_meter_peak()) {
1164 editor_meter_peak_display.set_active_state ( Gtkmm2ext::ExplicitActive );
1172 ARDOUR_UI::every_fps ()
1174 FPSUpdate(); /* EMIT_SIGNAL */
1175 #ifdef PLATFORM_WINDOWS
1176 every_point_zero_something_seconds();
1182 ARDOUR_UI::set_fps_timeout_connection ()
1184 unsigned int interval = 40;
1185 if (!_session) return;
1186 if (_session->timecode_frames_per_second() != 0) {
1187 /* ideally we'll use a select() to sleep and not accumulate
1188 * idle time to provide a regular periodic signal.
1189 * See linux_vst_gui_support.cc 'elapsed_time_ms'.
1190 * However, that'll require a dedicated thread and cross-thread
1191 * signals to the GUI Thread..
1193 interval = floor(500. /* update twice per FPS, since Glib::signal_timeout is very irregular */
1194 * _session->frame_rate() / _session->nominal_frame_rate()
1195 / _session->timecode_frames_per_second()
1197 #ifdef PLATFORM_WINDOWS
1198 // the smallest windows scheduler time-slice is ~15ms.
1199 // periodic GUI timeouts shorter than that will cause
1200 // WaitForSingleObject to spinlock (100% of one CPU Core)
1201 // and gtk never enters idle mode.
1202 // also changing timeBeginPeriod(1) does not affect that in
1203 // any beneficial way, so we just limit the max rate for now.
1204 interval = std::max(30u, interval); // at most ~33Hz.
1206 interval = std::max(8u, interval); // at most 120Hz.
1209 fps_connection.disconnect();
1210 fps_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_fps), interval);
1214 ARDOUR_UI::update_sample_rate (framecnt_t)
1218 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
1220 if (!AudioEngine::instance()->connected()) {
1222 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"red\">none</span>"));
1226 framecnt_t rate = AudioEngine::instance()->sample_rate();
1229 /* no sample rate available */
1230 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"red\">none</span>"));
1233 if (fmod (rate, 1000.0) != 0.0) {
1234 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"green\">%.1f kHz / %4.1f ms</span>"),
1235 (float) rate / 1000.0f,
1236 (AudioEngine::instance()->usecs_per_cycle() / 1000.0f));
1238 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"green\">%" PRId64 " kHz / %4.1f ms</span>"),
1240 (AudioEngine::instance()->usecs_per_cycle() / 1000.0f));
1244 sample_rate_label.set_markup (buf);
1248 ARDOUR_UI::update_format ()
1251 format_label.set_text ("");
1256 s << _("File:") << X_(" <span foreground=\"green\">");
1258 switch (_session->config.get_native_file_header_format ()) {
1284 switch (_session->config.get_native_file_data_format ()) {
1298 format_label.set_markup (s.str ());
1302 ARDOUR_UI::update_cpu_load ()
1306 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1307 should also be changed.
1310 float const c = AudioEngine::instance()->get_dsp_load ();
1311 snprintf (buf, sizeof (buf), _("DSP: <span foreground=\"%s\">%5.1f%%</span>"), c >= 90 ? X_("red") : X_("green"), c);
1312 cpu_load_label.set_markup (buf);
1316 ARDOUR_UI::update_buffer_load ()
1320 uint32_t const playback = _session ? _session->playback_load () : 100;
1321 uint32_t const capture = _session ? _session->capture_load () : 100;
1323 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1324 should also be changed.
1330 _("Buffers: <span foreground=\"green\">p:</span><span foreground=\"%s\">%" PRIu32 "%%</span> "
1331 "<span foreground=\"green\">c:</span><span foreground=\"%s\">%" PRIu32 "%%</span>"),
1332 playback <= 5 ? X_("red") : X_("green"),
1334 capture <= 5 ? X_("red") : X_("green"),
1338 buffer_load_label.set_markup (buf);
1340 buffer_load_label.set_text ("");
1345 ARDOUR_UI::count_recenabled_streams (Route& route)
1347 Track* track = dynamic_cast<Track*>(&route);
1348 if (track && track->record_enabled()) {
1349 rec_enabled_streams += track->n_inputs().n_total();
1354 ARDOUR_UI::update_disk_space()
1356 if (_session == 0) {
1360 boost::optional<framecnt_t> opt_frames = _session->available_capture_duration();
1362 framecnt_t fr = _session->frame_rate();
1365 /* skip update - no SR available */
1370 /* Available space is unknown */
1371 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">Unknown</span>"));
1372 } else if (opt_frames.get_value_or (0) == max_framecnt) {
1373 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">24hrs+</span>"));
1375 rec_enabled_streams = 0;
1376 _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams);
1378 framecnt_t frames = opt_frames.get_value_or (0);
1380 if (rec_enabled_streams) {
1381 frames /= rec_enabled_streams;
1388 hrs = frames / (fr * 3600);
1391 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">>24 hrs</span>"));
1393 frames -= hrs * fr * 3600;
1394 mins = frames / (fr * 60);
1395 frames -= mins * fr * 60;
1398 bool const low = (hrs == 0 && mins <= 30);
1402 _("Disk: <span foreground=\"%s\">%02dh:%02dm:%02ds</span>"),
1403 low ? X_("red") : X_("green"),
1409 disk_space_label.set_markup (buf);
1413 ARDOUR_UI::update_timecode_format ()
1419 TimecodeSlave* tcslave;
1420 SyncSource sync_src = Config->get_sync_source();
1422 if ((sync_src == LTC || sync_src == MTC) && (tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
1423 matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
1428 snprintf (buf, sizeof (buf), S_("Timecode|TC: <span foreground=\"%s\">%s</span>"),
1429 matching ? X_("green") : X_("red"),
1430 Timecode::timecode_format_name (_session->config.get_timecode_format()).c_str());
1432 snprintf (buf, sizeof (buf), "TC: n/a");
1435 timecode_format_label.set_markup (buf);
1439 ARDOUR_UI::update_wall_clock ()
1443 static int last_min = -1;
1446 tm_now = localtime (&now);
1447 if (last_min != tm_now->tm_min) {
1449 sprintf (buf, "%02d:%02d", tm_now->tm_hour, tm_now->tm_min);
1450 wall_clock_label.set_text (buf);
1451 last_min = tm_now->tm_min;
1458 ARDOUR_UI::redisplay_recent_sessions ()
1460 std::vector<std::string> session_directories;
1461 RecentSessionsSorter cmp;
1463 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
1464 recent_session_model->clear ();
1466 ARDOUR::RecentSessions rs;
1467 ARDOUR::read_recent_sessions (rs);
1470 recent_session_display.set_model (recent_session_model);
1474 // sort them alphabetically
1475 sort (rs.begin(), rs.end(), cmp);
1477 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
1478 session_directories.push_back ((*i).second);
1481 for (vector<std::string>::const_iterator i = session_directories.begin();
1482 i != session_directories.end(); ++i)
1484 std::vector<std::string> state_file_paths;
1486 // now get available states for this session
1488 get_state_files_in_directory (*i, state_file_paths);
1490 vector<string> states;
1491 vector<const gchar*> item;
1492 string fullpath = *i;
1494 /* remove any trailing / */
1496 if (fullpath[fullpath.length() - 1] == '/') {
1497 fullpath = fullpath.substr (0, fullpath.length() - 1);
1500 /* check whether session still exists */
1501 if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
1502 /* session doesn't exist */
1506 /* now get available states for this session */
1507 states = Session::possible_states (fullpath);
1509 if (states.empty()) {
1510 /* no state file? */
1514 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
1516 Gtk::TreeModel::Row row = *(recent_session_model->append());
1518 row[recent_session_columns.fullpath] = fullpath;
1519 row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath);
1521 if (state_file_names.size() > 1) {
1522 // multiple session files in the session directory - show the directory name.
1523 row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath);
1526 for (std::vector<std::string>::iterator i2 = state_file_names.begin();
1527 i2 != state_file_names.end(); ++i2)
1530 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
1532 child_row[recent_session_columns.visible_name] = *i2;
1533 child_row[recent_session_columns.fullpath] = fullpath;
1534 child_row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath);
1537 // only a single session file in the directory - show its actual name.
1538 row[recent_session_columns.visible_name] = state_file_names.front ();
1542 recent_session_display.set_tooltip_column(1); // recent_session_columns.tip
1543 recent_session_display.set_model (recent_session_model);
1547 ARDOUR_UI::build_session_selector ()
1549 session_selector_window = new ArdourDialog (_("Recent Sessions"));
1551 Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow);
1553 session_selector_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1554 session_selector_window->add_button (Stock::OPEN, RESPONSE_ACCEPT);
1555 session_selector_window->set_default_response (RESPONSE_ACCEPT);
1556 recent_session_model = TreeStore::create (recent_session_columns);
1557 recent_session_display.set_model (recent_session_model);
1558 recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name);
1559 recent_session_display.set_headers_visible (false);
1560 recent_session_display.get_selection()->set_mode (SELECTION_BROWSE);
1561 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &ARDOUR_UI::recent_session_row_activated));
1563 scroller->add (recent_session_display);
1564 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1566 session_selector_window->set_name ("SessionSelectorWindow");
1567 session_selector_window->set_size_request (200, 400);
1568 session_selector_window->get_vbox()->pack_start (*scroller);
1570 recent_session_display.show();
1575 ARDOUR_UI::recent_session_row_activated (const TreePath& /*path*/, TreeViewColumn* /*col*/)
1577 session_selector_window->response (RESPONSE_ACCEPT);
1581 ARDOUR_UI::open_recent_session ()
1583 bool can_return = (_session != 0);
1585 if (session_selector_window == 0) {
1586 build_session_selector ();
1589 redisplay_recent_sessions ();
1593 ResponseType r = (ResponseType) session_selector_window->run ();
1596 case RESPONSE_ACCEPT:
1600 session_selector_window->hide();
1607 if (recent_session_display.get_selection()->count_selected_rows() == 0) {
1611 session_selector_window->hide();
1613 Gtk::TreeModel::iterator i = recent_session_display.get_selection()->get_selected();
1615 if (i == recent_session_model->children().end()) {
1619 std::string path = (*i)[recent_session_columns.fullpath];
1620 std::string state = (*i)[recent_session_columns.visible_name];
1622 _session_is_new = false;
1624 if (load_session (path, state) == 0) {
1633 ARDOUR_UI::check_audioengine ()
1635 if (!AudioEngine::instance()->connected()) {
1636 MessageDialog msg (string_compose (
1637 _("%1 is not connected to any audio backend.\n"
1638 "You cannot open or close sessions in this condition"),
1640 pop_back_splash (msg);
1648 ARDOUR_UI::open_session ()
1650 if (!check_audioengine()) {
1655 /* popup selector window */
1657 if (open_session_selector == 0) {
1659 /* ardour sessions are folders */
1661 open_session_selector = new Gtk::FileChooserDialog (_("Open Session"), FILE_CHOOSER_ACTION_OPEN);
1662 open_session_selector->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1663 open_session_selector->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
1664 open_session_selector->set_default_response(Gtk::RESPONSE_ACCEPT);
1667 string session_parent_dir = Glib::path_get_dirname(_session->path());
1668 string::size_type last_dir_sep = session_parent_dir.rfind(G_DIR_SEPARATOR);
1669 session_parent_dir = session_parent_dir.substr(0, last_dir_sep);
1670 open_session_selector->set_current_folder(session_parent_dir);
1672 open_session_selector->set_current_folder(Config->get_default_session_parent_dir());
1675 string default_session_folder = Config->get_default_session_parent_dir();
1677 /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */
1678 open_session_selector->add_shortcut_folder (default_session_folder);
1680 catch (Glib::Error & e) {
1681 std::cerr << "open_session_selector->add_shortcut_folder (" << default_session_folder << ") threw Glib::Error " << e.what() << std::endl;
1684 FileFilter session_filter;
1685 session_filter.add_pattern ("*.ardour");
1686 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
1687 open_session_selector->add_filter (session_filter);
1688 open_session_selector->set_filter (session_filter);
1691 int response = open_session_selector->run();
1692 open_session_selector->hide ();
1695 case RESPONSE_ACCEPT:
1698 open_session_selector->hide();
1702 open_session_selector->hide();
1703 string session_path = open_session_selector->get_filename();
1707 if (session_path.length() > 0) {
1708 if (ARDOUR::find_session (session_path, path, name, isnew) == 0) {
1709 _session_is_new = isnew;
1710 load_session (path, name);
1717 ARDOUR_UI::session_add_mixed_track (const ChanCount& input, const ChanCount& output, RouteGroup* route_group,
1718 uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1720 list<boost::shared_ptr<MidiTrack> > tracks;
1722 if (_session == 0) {
1723 warning << _("You cannot add a track without a session already loaded.") << endmsg;
1728 tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template);
1730 if (tracks.size() != how_many) {
1731 error << string_compose(P_("could not create %1 new mixed track", "could not create %1 new mixed tracks", how_many), how_many) << endmsg;
1736 MessageDialog msg (*editor,
1737 string_compose (_("There are insufficient ports available\n\
1738 to create a new track or bus.\n\
1739 You should save %1, exit and\n\
1740 restart with more ports."), PROGRAM_NAME));
1747 ARDOUR_UI::session_add_midi_route (bool disk, RouteGroup* route_group, uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1749 ChanCount one_midi_channel;
1750 one_midi_channel.set (DataType::MIDI, 1);
1753 session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, instrument);
1758 ARDOUR_UI::session_add_audio_route (
1760 int32_t input_channels,
1761 int32_t output_channels,
1762 ARDOUR::TrackMode mode,
1763 RouteGroup* route_group,
1765 string const & name_template
1768 list<boost::shared_ptr<AudioTrack> > tracks;
1771 if (_session == 0) {
1772 warning << _("You cannot add a track or bus without a session already loaded.") << endmsg;
1778 tracks = _session->new_audio_track (input_channels, output_channels, mode, route_group, how_many, name_template);
1780 if (tracks.size() != how_many) {
1781 error << string_compose (P_("could not create %1 new audio track", "could not create %1 new audio tracks", how_many), how_many)
1787 routes = _session->new_audio_route (input_channels, output_channels, route_group, how_many, name_template);
1789 if (routes.size() != how_many) {
1790 error << string_compose (P_("could not create %1 new audio bus", "could not create %1 new audio busses", how_many), how_many)
1797 MessageDialog msg (*editor,
1798 string_compose (_("There are insufficient ports available\n\
1799 to create a new track or bus.\n\
1800 You should save %1, exit and\n\
1801 restart with more ports."), PROGRAM_NAME));
1802 pop_back_splash (msg);
1808 ARDOUR_UI::transport_goto_start ()
1811 _session->goto_start();
1813 /* force displayed area in editor to start no matter
1814 what "follow playhead" setting is.
1818 editor->center_screen (_session->current_start_frame ());
1824 ARDOUR_UI::transport_goto_zero ()
1827 _session->request_locate (0);
1829 /* force displayed area in editor to start no matter
1830 what "follow playhead" setting is.
1834 editor->reset_x_origin (0);
1840 ARDOUR_UI::transport_goto_wallclock ()
1842 if (_session && editor) {
1849 localtime_r (&now, &tmnow);
1851 int frame_rate = _session->frame_rate();
1853 if (frame_rate == 0) {
1854 /* no frame rate available */
1858 frames = tmnow.tm_hour * (60 * 60 * frame_rate);
1859 frames += tmnow.tm_min * (60 * frame_rate);
1860 frames += tmnow.tm_sec * frame_rate;
1862 _session->request_locate (frames, _session->transport_rolling ());
1864 /* force displayed area in editor to start no matter
1865 what "follow playhead" setting is.
1869 editor->center_screen (frames);
1875 ARDOUR_UI::transport_goto_end ()
1878 framepos_t const frame = _session->current_end_frame();
1879 _session->request_locate (frame);
1881 /* force displayed area in editor to start no matter
1882 what "follow playhead" setting is.
1886 editor->center_screen (frame);
1892 ARDOUR_UI::transport_stop ()
1898 if (_session->is_auditioning()) {
1899 _session->cancel_audition ();
1903 _session->request_stop (false, true);
1906 /** Check if any tracks are record enabled. If none are, record enable all of them.
1907 * @return true if track record-enabled status was changed, false otherwise.
1910 ARDOUR_UI::trx_record_enable_all_tracks ()
1916 boost::shared_ptr<RouteList> rl = _session->get_tracks ();
1917 bool none_record_enabled = true;
1919 for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
1920 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (*r);
1923 if (t->record_enabled()) {
1924 none_record_enabled = false;
1929 if (none_record_enabled) {
1930 _session->set_record_enabled (rl, true, Session::rt_cleanup);
1933 return none_record_enabled;
1937 ARDOUR_UI::transport_record (bool roll)
1940 switch (_session->record_status()) {
1941 case Session::Disabled:
1942 if (_session->ntracks() == 0) {
1943 MessageDialog msg (*editor, _("Please create one or more tracks before trying to record.\nYou can do this with the \"Add Track or Bus\" option in the Session menu."));
1947 if (Profile->get_trx()) {
1948 roll = trx_record_enable_all_tracks ();
1950 _session->maybe_enable_record ();
1955 case Session::Recording:
1957 _session->request_stop();
1959 _session->disable_record (false, true);
1963 case Session::Enabled:
1964 _session->disable_record (false, true);
1970 ARDOUR_UI::transport_roll ()
1976 if (_session->is_auditioning()) {
1981 if (_session->config.get_external_sync()) {
1982 switch (Config->get_sync_source()) {
1986 /* transport controlled by the master */
1992 bool rolling = _session->transport_rolling();
1994 if (_session->get_play_loop()) {
1996 /* If loop playback is not a mode, then we should cancel
1997 it when this action is requested. If it is a mode
1998 we just leave it in place.
2001 if (!Config->get_loop_is_mode()) {
2002 /* XXX it is not possible to just leave seamless loop and keep
2003 playing at present (nov 4th 2009)
2005 if (!Config->get_seamless_loop()) {
2006 /* stop loop playback and stop rolling */
2007 _session->request_play_loop (false, true);
2008 } else if (rolling) {
2009 /* stop loop playback but keep rolling */
2010 _session->request_play_loop (false, false);
2014 } else if (_session->get_play_range () ) {
2015 /* stop playing a range if we currently are */
2016 _session->request_play_range (0, true);
2020 _session->request_transport_speed (1.0f);
2025 ARDOUR_UI::get_smart_mode() const
2027 return ( editor->get_smart_mode() );
2032 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
2039 if (_session->is_auditioning()) {
2040 _session->cancel_audition ();
2044 if (_session->config.get_external_sync()) {
2045 switch (Config->get_sync_source()) {
2049 /* transport controlled by the master */
2054 bool rolling = _session->transport_rolling();
2055 bool affect_transport = true;
2057 if (rolling && roll_out_of_bounded_mode) {
2058 /* drop out of loop/range playback but leave transport rolling */
2059 if (_session->get_play_loop()) {
2060 if (Config->get_seamless_loop()) {
2061 /* the disk buffers contain copies of the loop - we can't
2062 just keep playing, so stop the transport. the user
2063 can restart as they wish.
2065 affect_transport = true;
2067 /* disk buffers are normal, so we can keep playing */
2068 affect_transport = false;
2070 _session->request_play_loop (false, affect_transport);
2071 } else if (_session->get_play_range ()) {
2072 affect_transport = false;
2073 _session->request_play_range (0, true);
2077 if (affect_transport) {
2079 _session->request_stop (with_abort, true);
2081 if ( Config->get_follow_edits() && ( editor->get_selection().time.front().start == _session->transport_frame() ) ) { //if playhead is exactly at the start of a range, we can assume it was placed there by follow_edits
2082 _session->request_play_range (&editor->get_selection().time, true);
2083 _session->set_requested_return_frame( editor->get_selection().time.front().start ); //force an auto-return here
2085 _session->request_transport_speed (1.0f);
2091 ARDOUR_UI::toggle_session_auto_loop ()
2093 Location * looploc = _session->locations()->auto_loop_location();
2095 if (!_session || !looploc) {
2099 if (_session->get_play_loop()) {
2101 /* looping enabled, our job is to disable it */
2103 _session->request_play_loop (false);
2107 /* looping not enabled, our job is to enable it.
2109 loop-is-NOT-mode: this action always starts the transport rolling.
2110 loop-IS-mode: this action simply sets the loop play mechanism, but
2111 does not start transport.
2113 if (Config->get_loop_is_mode()) {
2114 _session->request_play_loop (true, false);
2116 _session->request_play_loop (true, true);
2120 //show the loop markers
2121 looploc->set_hidden (false, this);
2125 ARDOUR_UI::transport_play_selection ()
2131 editor->play_selection ();
2135 ARDOUR_UI::transport_play_preroll ()
2140 editor->play_with_preroll ();
2144 ARDOUR_UI::transport_rewind (int option)
2146 float current_transport_speed;
2149 current_transport_speed = _session->transport_speed();
2151 if (current_transport_speed >= 0.0f) {
2154 _session->request_transport_speed (-1.0f);
2157 _session->request_transport_speed (-4.0f);
2160 _session->request_transport_speed (-0.5f);
2165 _session->request_transport_speed (current_transport_speed * 1.5f);
2171 ARDOUR_UI::transport_forward (int option)
2177 float current_transport_speed = _session->transport_speed();
2179 if (current_transport_speed <= 0.0f) {
2182 _session->request_transport_speed (1.0f);
2185 _session->request_transport_speed (4.0f);
2188 _session->request_transport_speed (0.5f);
2193 _session->request_transport_speed (current_transport_speed * 1.5f);
2198 ARDOUR_UI::toggle_record_enable (uint32_t rid)
2204 boost::shared_ptr<Route> r;
2206 if ((r = _session->route_by_remote_id (rid)) != 0) {
2210 if ((t = dynamic_cast<Track*>(r.get())) != 0) {
2211 t->set_record_enabled (!t->record_enabled(), this);
2217 ARDOUR_UI::map_transport_state ()
2220 auto_loop_button.unset_active_state ();
2221 play_selection_button.unset_active_state ();
2222 roll_button.unset_active_state ();
2223 stop_button.set_active_state (Gtkmm2ext::ExplicitActive);
2227 shuttle_box->map_transport_state ();
2229 float sp = _session->transport_speed();
2235 if (_session->get_play_range()) {
2237 play_selection_button.set_active_state (Gtkmm2ext::ExplicitActive);
2238 roll_button.unset_active_state ();
2239 auto_loop_button.unset_active_state ();
2241 } else if (_session->get_play_loop ()) {
2243 auto_loop_button.set_active (true);
2244 play_selection_button.set_active (false);
2245 if (Config->get_loop_is_mode()) {
2246 roll_button.set_active (true);
2248 roll_button.set_active (false);
2253 roll_button.set_active (true);
2254 play_selection_button.set_active (false);
2255 auto_loop_button.set_active (false);
2258 if (Config->get_follow_edits()) {
2259 /* light up both roll and play-selection if they are joined */
2260 roll_button.set_active (true);
2261 play_selection_button.set_active (true);
2264 stop_button.set_active (false);
2268 stop_button.set_active (true);
2269 roll_button.set_active (false);
2270 play_selection_button.set_active (false);
2271 if (Config->get_loop_is_mode ()) {
2272 auto_loop_button.set_active (_session->get_play_loop());
2274 auto_loop_button.set_active (false);
2276 update_disk_space ();
2281 ARDOUR_UI::update_clocks ()
2283 if (editor && !editor->dragging_playhead()) {
2284 Clock (_session->audible_frame(), false, editor->get_preferred_edit_position()); /* EMIT_SIGNAL */
2289 ARDOUR_UI::start_clocking ()
2291 if (Config->get_super_rapid_clock_update()) {
2292 clock_signal_connection = FPSUpdate.connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2294 clock_signal_connection = RapidScreenUpdate.connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2299 ARDOUR_UI::stop_clocking ()
2301 clock_signal_connection.disconnect ();
2305 ARDOUR_UI::_blink (void *arg)
2307 ((ARDOUR_UI *) arg)->blink ();
2314 Blink (blink_on = !blink_on); /* EMIT_SIGNAL */
2318 ARDOUR_UI::start_blinking ()
2320 /* Start the blink signal. Everybody with a blinking widget
2321 uses Blink to drive the widget's state.
2324 if (blink_timeout_tag < 0) {
2326 blink_timeout_tag = g_timeout_add (240, _blink, this);
2331 ARDOUR_UI::stop_blinking ()
2333 if (blink_timeout_tag >= 0) {
2334 g_source_remove (blink_timeout_tag);
2335 blink_timeout_tag = -1;
2340 /** Ask the user for the name of a new snapshot and then take it.
2344 ARDOUR_UI::snapshot_session (bool switch_to_it)
2346 ArdourPrompter prompter (true);
2349 prompter.set_name ("Prompter");
2350 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2352 prompter.set_title (_("Save as..."));
2353 prompter.set_prompt (_("New session name"));
2355 prompter.set_title (_("Take Snapshot"));
2356 prompter.set_prompt (_("Name of new snapshot"));
2359 if (!switch_to_it) {
2362 struct tm local_time;
2365 localtime_r (&n, &local_time);
2366 strftime (timebuf, sizeof(timebuf), "%FT%H.%M.%S", &local_time);
2367 prompter.set_initial_text (timebuf);
2371 switch (prompter.run()) {
2372 case RESPONSE_ACCEPT:
2374 prompter.get_result (snapname);
2376 bool do_save = (snapname.length() != 0);
2379 char illegal = Session::session_name_is_legal(snapname);
2381 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2382 "snapshot names may not contain a '%1' character"), illegal));
2388 vector<std::string> p;
2389 get_state_files_in_directory (_session->session_directory().root_path(), p);
2390 vector<string> n = get_file_names_no_extension (p);
2391 if (find (n.begin(), n.end(), snapname) != n.end()) {
2393 ArdourDialog confirm (_("Confirm Snapshot Overwrite"), true);
2394 Label m (_("A snapshot already exists with that name. Do you want to overwrite it?"));
2395 confirm.get_vbox()->pack_start (m, true, true);
2396 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2397 confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
2398 confirm.show_all ();
2399 switch (confirm.run()) {
2400 case RESPONSE_CANCEL:
2406 save_state (snapname, switch_to_it);
2416 /** Ask the user for a new session name and then rename the session to it.
2420 ARDOUR_UI::rename_session ()
2426 ArdourPrompter prompter (true);
2429 prompter.set_name ("Prompter");
2430 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2431 prompter.set_title (_("Rename Session"));
2432 prompter.set_prompt (_("New session name"));
2435 switch (prompter.run()) {
2436 case RESPONSE_ACCEPT:
2438 prompter.get_result (name);
2440 bool do_rename = (name.length() != 0);
2443 char illegal = Session::session_name_is_legal (name);
2446 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2447 "session names may not contain a '%1' character"), illegal));
2452 switch (_session->rename (name)) {
2454 MessageDialog msg (_("That name is already in use by another directory/folder. Please try again."));
2455 msg.set_position (WIN_POS_MOUSE);
2463 MessageDialog msg (_("Renaming this session failed.\nThings could be seriously messed up at this point"));
2464 msg.set_position (WIN_POS_MOUSE);
2480 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
2482 XMLNode* node = new XMLNode (X_("UI"));
2484 WM::Manager::instance().add_state (*node);
2486 node->add_child_nocopy (gui_object_state->get_state());
2488 _session->add_extra_xml (*node);
2490 save_state_canfail (name, switch_to_it);
2494 ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
2499 if (name.length() == 0) {
2500 name = _session->snap_name();
2503 if ((ret = _session->save_state (name, false, switch_to_it)) != 0) {
2508 save_ardour_state (); /* XXX cannot fail? yeah, right ... */
2513 ARDOUR_UI::primary_clock_value_changed ()
2516 _session->request_locate (primary_clock->current_time ());
2521 ARDOUR_UI::big_clock_value_changed ()
2524 _session->request_locate (big_clock->current_time ());
2529 ARDOUR_UI::secondary_clock_value_changed ()
2532 _session->request_locate (secondary_clock->current_time ());
2537 ARDOUR_UI::transport_rec_enable_blink (bool onoff)
2539 if (_session == 0) {
2543 if (_session->step_editing()) {
2547 Session::RecordState const r = _session->record_status ();
2548 bool const h = _session->have_rec_enabled_track ();
2550 if (r == Session::Enabled || (r == Session::Recording && !h)) {
2552 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2554 rec_button.set_active_state (Gtkmm2ext::Off);
2556 } else if (r == Session::Recording && h) {
2557 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2559 rec_button.unset_active_state ();
2564 ARDOUR_UI::save_template ()
2566 ArdourPrompter prompter (true);
2569 if (!check_audioengine()) {
2573 prompter.set_name (X_("Prompter"));
2574 prompter.set_title (_("Save Template"));
2575 prompter.set_prompt (_("Name for template:"));
2576 prompter.set_initial_text(_session->name() + _("-template"));
2577 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2579 switch (prompter.run()) {
2580 case RESPONSE_ACCEPT:
2581 prompter.get_result (name);
2583 if (name.length()) {
2584 _session->save_template (name);
2594 ARDOUR_UI::edit_metadata ()
2596 SessionMetadataEditor dialog;
2597 dialog.set_session (_session);
2598 editor->ensure_float (dialog);
2603 ARDOUR_UI::import_metadata ()
2605 SessionMetadataImporter dialog;
2606 dialog.set_session (_session);
2607 editor->ensure_float (dialog);
2612 ARDOUR_UI::ask_about_loading_existing_session (const std::string& session_path)
2614 std::string str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
2616 MessageDialog msg (str,
2618 Gtk::MESSAGE_WARNING,
2619 Gtk::BUTTONS_YES_NO,
2623 msg.set_name (X_("OpenExistingDialog"));
2624 msg.set_title (_("Open Existing Session"));
2625 msg.set_wmclass (X_("existing_session"), PROGRAM_NAME);
2626 msg.set_position (Gtk::WIN_POS_MOUSE);
2627 pop_back_splash (msg);
2629 switch (msg.run()) {
2638 ARDOUR_UI::build_session_from_dialog (SessionDialog& sd, const std::string& session_path, const std::string& session_name)
2640 BusProfile bus_profile;
2642 if (nsm || Profile->get_sae()) {
2644 bus_profile.master_out_channels = 2;
2645 bus_profile.input_ac = AutoConnectPhysical;
2646 bus_profile.output_ac = AutoConnectMaster;
2647 bus_profile.requested_physical_in = 0; // use all available
2648 bus_profile.requested_physical_out = 0; // use all available
2652 /* get settings from advanced section of NSD */
2654 if (sd.create_master_bus()) {
2655 bus_profile.master_out_channels = (uint32_t) sd.master_channel_count();
2657 bus_profile.master_out_channels = 0;
2660 if (sd.connect_inputs()) {
2661 bus_profile.input_ac = AutoConnectPhysical;
2663 bus_profile.input_ac = AutoConnectOption (0);
2666 bus_profile.output_ac = AutoConnectOption (0);
2668 if (sd.connect_outputs ()) {
2669 if (sd.connect_outs_to_master()) {
2670 bus_profile.output_ac = AutoConnectMaster;
2671 } else if (sd.connect_outs_to_physical()) {
2672 bus_profile.output_ac = AutoConnectPhysical;
2676 bus_profile.requested_physical_in = (uint32_t) sd.input_limit_count();
2677 bus_profile.requested_physical_out = (uint32_t) sd.output_limit_count();
2680 if (build_session (session_path, session_name, bus_profile)) {
2688 ARDOUR_UI::idle_load (const std::string& path)
2691 if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
2692 /* /path/to/foo => /path/to/foo, foo */
2693 load_session (path, basename_nosuffix (path));
2695 /* /path/to/foo/foo.ardour => /path/to/foo, foo */
2696 load_session (Glib::path_get_dirname (path), basename_nosuffix (path));
2700 ARDOUR_COMMAND_LINE::session_name = path;
2704 /** @param quit_on_cancel true if exit() should be called if the user clicks `cancel' in the new session dialog */
2706 ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, string load_template)
2708 string session_name;
2709 string session_path;
2710 string template_name;
2712 bool likely_new = false;
2713 bool cancel_not_quit;
2715 /* deal with any existing DIRTY session now, rather than later. don't
2716 * treat a non-dirty session this way, so that it stays visible
2717 * as we bring up the new session dialog.
2720 if (_session && ARDOUR_UI::instance()->video_timeline) {
2721 ARDOUR_UI::instance()->video_timeline->sync_session_state();
2724 /* if there is already a session, relabel the button
2725 on the SessionDialog so that we don't Quit directly
2727 cancel_not_quit = (_session != 0);
2729 if (_session && _session->dirty()) {
2730 if (unload_session (false)) {
2731 /* unload cancelled by user */
2734 ARDOUR_COMMAND_LINE::session_name = "";
2737 if (!load_template.empty()) {
2738 should_be_new = true;
2739 template_name = load_template;
2742 session_name = basename_nosuffix (ARDOUR_COMMAND_LINE::session_name);
2743 session_path = ARDOUR_COMMAND_LINE::session_name;
2745 if (!session_path.empty()) {
2746 if (Glib::file_test (session_path.c_str(), Glib::FILE_TEST_EXISTS)) {
2747 if (Glib::file_test (session_path.c_str(), Glib::FILE_TEST_IS_REGULAR)) {
2748 /* session/snapshot file, change path to be dir */
2749 session_path = Glib::path_get_dirname (session_path);
2754 SessionDialog session_dialog (should_be_new, session_name, session_path, load_template, cancel_not_quit);
2758 if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
2760 /* if they named a specific statefile, use it, otherwise they are
2761 just giving a session folder, and we want to use it as is
2762 to find the session.
2765 string::size_type suffix = ARDOUR_COMMAND_LINE::session_name.find (statefile_suffix);
2767 if (suffix != string::npos) {
2768 session_path = Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name);
2769 session_name = ARDOUR_COMMAND_LINE::session_name.substr (0, suffix);
2770 session_name = Glib::path_get_basename (session_name);
2772 session_path = ARDOUR_COMMAND_LINE::session_name;
2773 session_name = Glib::path_get_basename (ARDOUR_COMMAND_LINE::session_name);
2778 session_dialog.clear_given ();
2781 if (should_be_new || session_name.empty()) {
2782 /* need the dialog to get info from user */
2784 cerr << "run dialog\n";
2786 switch (session_dialog.run()) {
2787 case RESPONSE_ACCEPT:
2790 if (quit_on_cancel) {
2791 // JE - Currently (July 2014) this section can only get reached if the
2792 // user quits from the main 'Session Setup' dialog (i.e. reaching this
2793 // point does NOT indicate an abnormal termination). Therefore, let's
2794 // behave gracefully (i.e. let's do some cleanup) before we call exit()
2796 pthread_cancel_all ();
2804 session_dialog.hide ();
2807 /* if we run the startup dialog again, offer more than just "new session" */
2809 should_be_new = false;
2811 session_name = session_dialog.session_name (likely_new);
2812 session_path = session_dialog.session_folder ();
2818 string::size_type suffix = session_name.find (statefile_suffix);
2820 if (suffix != string::npos) {
2821 session_name = session_name.substr (0, suffix);
2824 /* this shouldn't happen, but we catch it just in case it does */
2826 if (session_name.empty()) {
2830 if (session_dialog.use_session_template()) {
2831 template_name = session_dialog.session_template_name();
2832 _session_is_new = true;
2835 if (session_name[0] == G_DIR_SEPARATOR ||
2836 #ifdef PLATFORM_WINDOWS
2837 (session_name.length() > 3 && session_name[1] == ':' && session_name[2] == G_DIR_SEPARATOR)
2839 (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == G_DIR_SEPARATOR) ||
2840 (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == G_DIR_SEPARATOR)
2845 /* absolute path or cwd-relative path specified for session name: infer session folder
2846 from what was given.
2849 session_path = Glib::path_get_dirname (session_name);
2850 session_name = Glib::path_get_basename (session_name);
2854 session_path = session_dialog.session_folder();
2856 char illegal = Session::session_name_is_legal (session_name);
2859 MessageDialog msg (session_dialog,
2860 string_compose (_("To ensure compatibility with various systems\n"
2861 "session names may not contain a '%1' character"),
2864 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2869 if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
2872 if (likely_new && !nsm) {
2874 std::string existing = Glib::build_filename (session_path, session_name);
2876 if (!ask_about_loading_existing_session (existing)) {
2877 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2882 _session_is_new = false;
2887 pop_back_splash (session_dialog);
2888 MessageDialog msg (string_compose (_("There is no existing session at \"%1\""), session_path));
2890 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2894 char illegal = Session::session_name_is_legal(session_name);
2897 pop_back_splash (session_dialog);
2898 MessageDialog msg (session_dialog, string_compose(_("To ensure compatibility with various systems\n"
2899 "session names may not contain a '%1' character"), illegal));
2901 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2905 _session_is_new = true;
2908 if (likely_new && template_name.empty()) {
2910 ret = build_session_from_dialog (session_dialog, session_path, session_name);
2914 ret = load_session (session_path, session_name, template_name);
2917 /* not connected to the AudioEngine, so quit to avoid an infinite loop */
2921 if (!ARDOUR_COMMAND_LINE::immediate_save.empty()) {
2922 _session->save_state (ARDOUR_COMMAND_LINE::immediate_save, false);
2926 /* clear this to avoid endless attempts to load the
2930 ARDOUR_COMMAND_LINE::session_name = "";
2938 ARDOUR_UI::close_session()
2940 if (!check_audioengine()) {
2944 if (unload_session (true)) {
2948 ARDOUR_COMMAND_LINE::session_name = "";
2950 if (get_session_parameters (true, false)) {
2954 goto_editor_window ();
2957 /** @param snap_name Snapshot name (without .ardour suffix).
2958 * @return -2 if the load failed because we are not connected to the AudioEngine.
2961 ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name, std::string mix_template)
2963 Session *new_session;
2968 unload_status = unload_session ();
2970 if (unload_status < 0) {
2972 } else if (unload_status > 0) {
2978 session_loaded = false;
2980 loading_message (string_compose (_("Please wait while %1 loads your session"), PROGRAM_NAME));
2983 new_session = new Session (*AudioEngine::instance(), path, snap_name, 0, mix_template);
2986 /* this one is special */
2988 catch (AudioEngine::PortRegistrationFailure& err) {
2990 MessageDialog msg (err.what(),
2993 Gtk::BUTTONS_CLOSE);
2995 msg.set_title (_("Port Registration Error"));
2996 msg.set_secondary_text (_("Click the Close button to try again."));
2997 msg.set_position (Gtk::WIN_POS_CENTER);
2998 pop_back_splash (msg);
3001 int response = msg.run ();
3006 case RESPONSE_CANCEL:
3016 MessageDialog msg (string_compose(
3017 _("Session \"%1 (snapshot %2)\" did not load successfully"),
3023 msg.set_keep_above (true);
3024 msg.set_title (_("Loading Error"));
3025 msg.set_position (Gtk::WIN_POS_CENTER);
3026 pop_back_splash (msg);
3035 list<string> const u = new_session->unknown_processors ();
3037 MissingPluginDialog d (_session, u);
3042 if (!new_session->writable()) {
3043 MessageDialog msg (_("This session has been opened in read-only mode.\n\nYou will not be able to record or save."),
3048 msg.set_keep_above (true);
3049 msg.set_title (_("Read-only Session"));
3050 msg.set_position (Gtk::WIN_POS_CENTER);
3051 pop_back_splash (msg);
3058 /* Now the session been created, add the transport controls */
3059 new_session->add_controllable(roll_controllable);
3060 new_session->add_controllable(stop_controllable);
3061 new_session->add_controllable(goto_start_controllable);
3062 new_session->add_controllable(goto_end_controllable);
3063 new_session->add_controllable(auto_loop_controllable);
3064 new_session->add_controllable(play_selection_controllable);
3065 new_session->add_controllable(rec_controllable);
3067 set_session (new_session);
3069 session_loaded = true;
3071 goto_editor_window ();
3074 _session->set_clean ();
3077 #ifdef WINDOWS_VST_SUPPORT
3078 fst_stop_threading();
3083 #ifdef WINDOWS_VST_SUPPORT
3084 fst_start_threading();
3093 ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name, BusProfile& bus_profile)
3095 Session *new_session;
3098 session_loaded = false;
3099 x = unload_session ();
3107 _session_is_new = true;
3110 new_session = new Session (*AudioEngine::instance(), path, snap_name, &bus_profile);
3115 MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
3116 pop_back_splash (msg);
3121 /* Give the new session the default GUI state, if such things exist */
3124 n = Config->instant_xml (X_("Editor"));
3126 new_session->add_instant_xml (*n, false);
3128 n = Config->instant_xml (X_("Mixer"));
3130 new_session->add_instant_xml (*n, false);
3133 /* Put the playhead at 0 and scroll fully left */
3134 n = new_session->instant_xml (X_("Editor"));
3136 n->add_property (X_("playhead"), X_("0"));
3137 n->add_property (X_("left-frame"), X_("0"));
3140 set_session (new_session);
3142 session_loaded = true;
3144 new_session->save_state(new_session->name());
3150 ARDOUR_UI::launch_chat ()
3153 open_uri("http://webchat.freenode.net/?channels=ardour-osx");
3154 #elif defined PLATFORM_WINDOWS
3155 open_uri("http://webchat.freenode.net/?channels=ardour-windows");
3157 open_uri("http://webchat.freenode.net/?channels=ardour");
3162 ARDOUR_UI::launch_manual ()
3164 PBD::open_uri (Config->get_tutorial_manual_url());
3168 ARDOUR_UI::launch_reference ()
3170 PBD::open_uri (Config->get_reference_manual_url());
3174 ARDOUR_UI::loading_message (const std::string& msg)
3176 if (ARDOUR_COMMAND_LINE::no_splash) {
3184 splash->message (msg);
3188 ARDOUR_UI::show_splash ()
3192 splash = new Splash;
3202 ARDOUR_UI::hide_splash ()
3209 ARDOUR_UI::display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title, const bool msg_delete)
3213 removed = rep.paths.size();
3216 MessageDialog msgd (*editor,
3217 _("No files were ready for clean-up"),
3221 msgd.set_title (_("Clean-up"));
3222 msgd.set_secondary_text (_("If this seems suprising, \n\
3223 check for any existing snapshots.\n\
3224 These may still include regions that\n\
3225 require some unused files to continue to exist."));
3231 ArdourDialog results (_("Clean-up"), true, false);
3233 struct CleanupResultsModelColumns : public Gtk::TreeModel::ColumnRecord {
3234 CleanupResultsModelColumns() {
3238 Gtk::TreeModelColumn<std::string> visible_name;
3239 Gtk::TreeModelColumn<std::string> fullpath;
3243 CleanupResultsModelColumns results_columns;
3244 Glib::RefPtr<Gtk::ListStore> results_model;
3245 Gtk::TreeView results_display;
3247 results_model = ListStore::create (results_columns);
3248 results_display.set_model (results_model);
3249 results_display.append_column (list_title, results_columns.visible_name);
3251 results_display.set_name ("CleanupResultsList");
3252 results_display.set_headers_visible (true);
3253 results_display.set_headers_clickable (false);
3254 results_display.set_reorderable (false);
3256 Gtk::ScrolledWindow list_scroller;
3259 Gtk::HBox dhbox; // the hbox for the image and text
3260 Gtk::HBox ddhbox; // the hbox we eventually pack into the dialog's vbox
3261 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_INFO, Gtk::ICON_SIZE_DIALOG));
3263 dimage->set_alignment(ALIGN_LEFT, ALIGN_TOP);
3265 const string dead_directory = _session->session_directory().dead_path();
3268 %1 - number of files removed
3269 %2 - location of "dead"
3270 %3 - size of files affected
3271 %4 - prefix for "bytes" to produce sensible results (e.g. mega, kilo, giga)
3274 const char* bprefix;
3275 double space_adjusted = 0;
3277 if (rep.space < 1000) {
3279 space_adjusted = rep.space;
3280 } else if (rep.space < 1000000) {
3281 bprefix = _("kilo");
3282 space_adjusted = floorf((float)rep.space / 1000.0);
3283 } else if (rep.space < 1000000 * 1000) {
3284 bprefix = _("mega");
3285 space_adjusted = floorf((float)rep.space / (1000.0 * 1000.0));
3287 bprefix = _("giga");
3288 space_adjusted = floorf((float)rep.space / (1000.0 * 1000 * 1000.0));
3292 txt.set_markup (string_compose (P_("\
3293 The following file was deleted from %2,\n\
3294 releasing %3 %4bytes of disk space", "\
3295 The following %1 files were deleted from %2,\n\
3296 releasing %3 %4bytes of disk space", removed),
3297 removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
3299 txt.set_markup (string_compose (P_("\
3300 The following file was not in use and \n\
3301 has been moved to: %2\n\n\
3302 After a restart of %5\n\n\
3303 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3304 will release an additional %3 %4bytes of disk space.\n", "\
3305 The following %1 files were not in use and \n\
3306 have been moved to: %2\n\n\
3307 After a restart of %5\n\n\
3308 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3309 will release an additional %3 %4bytes of disk space.\n", removed),
3310 removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
3313 dhbox.pack_start (*dimage, true, false, 5);
3314 dhbox.pack_start (txt, true, false, 5);
3316 for (vector<string>::iterator i = rep.paths.begin(); i != rep.paths.end(); ++i) {
3317 TreeModel::Row row = *(results_model->append());
3318 row[results_columns.visible_name] = *i;
3319 row[results_columns.fullpath] = *i;
3322 list_scroller.add (results_display);
3323 list_scroller.set_size_request (-1, 150);
3324 list_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
3326 dvbox.pack_start (dhbox, true, false, 5);
3327 dvbox.pack_start (list_scroller, true, false, 5);
3328 ddhbox.pack_start (dvbox, true, false, 5);
3330 results.get_vbox()->pack_start (ddhbox, true, false, 5);
3331 results.add_button (Stock::CLOSE, RESPONSE_CLOSE);
3332 results.set_default_response (RESPONSE_CLOSE);
3333 results.set_position (Gtk::WIN_POS_MOUSE);
3335 results_display.show();
3336 list_scroller.show();
3343 //results.get_vbox()->show();
3344 results.set_resizable (false);
3351 ARDOUR_UI::cleanup ()
3353 if (_session == 0) {
3354 /* shouldn't happen: menu item is insensitive */
3359 MessageDialog checker (_("Are you sure you want to clean-up?"),
3361 Gtk::MESSAGE_QUESTION,
3364 checker.set_title (_("Clean-up"));
3366 checker.set_secondary_text(_("Clean-up is a destructive operation.\n\
3367 ALL undo/redo information will be lost if you clean-up.\n\
3368 Clean-up will move all unused files to a \"dead\" location."));
3370 checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3371 checker.add_button (_("Clean-up"), RESPONSE_ACCEPT);
3372 checker.set_default_response (RESPONSE_CANCEL);
3374 checker.set_name (_("CleanupDialog"));
3375 checker.set_wmclass (X_("ardour_cleanup"), PROGRAM_NAME);
3376 checker.set_position (Gtk::WIN_POS_MOUSE);
3378 switch (checker.run()) {
3379 case RESPONSE_ACCEPT:
3385 ARDOUR::CleanupReport rep;
3387 editor->prepare_for_cleanup ();
3389 /* do not allow flush until a session is reloaded */
3391 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
3393 act->set_sensitive (false);
3396 if (_session->cleanup_sources (rep)) {
3397 editor->finish_cleanup ();
3401 editor->finish_cleanup ();
3404 display_cleanup_results (rep, _("Cleaned Files"), false);
3408 ARDOUR_UI::flush_trash ()
3410 if (_session == 0) {
3411 /* shouldn't happen: menu item is insensitive */
3415 ARDOUR::CleanupReport rep;
3417 if (_session->cleanup_trash_sources (rep)) {
3421 display_cleanup_results (rep, _("deleted file"), true);
3425 ARDOUR_UI::setup_order_hint ()
3427 uint32_t order_hint = 0;
3430 we want the new routes to have their order keys set starting from
3431 the highest order key in the selection + 1 (if available).
3433 if (add_route_dialog->get_transient_for () == mixer->get_toplevel()) {
3434 for (RouteUISelection::iterator s = mixer->selection().routes.begin(); s != mixer->selection().routes.end(); ++s) {
3435 if ((*s)->route()->order_key() > order_hint) {
3436 order_hint = (*s)->route()->order_key();
3440 if (!mixer->selection().routes.empty()) {
3445 for (TrackSelection::iterator s = editor->get_selection().tracks.begin(); s != editor->get_selection().tracks.end(); ++s) {
3446 RouteTimeAxisView* tav = dynamic_cast<RouteTimeAxisView*> (*s);
3447 if (tav && tav->route() && tav->route()->order_key() > order_hint) {
3448 order_hint = tav->route()->order_key();
3452 if (!editor->get_selection().tracks.empty()) {
3457 _session->set_order_hint (order_hint);
3459 /* create a gap in the existing route order keys to accomodate new routes.*/
3461 boost::shared_ptr <RouteList> rd = _session->get_routes();
3462 for (RouteList::iterator ri = rd->begin(); ri != rd->end(); ++ri) {
3463 boost::shared_ptr<Route> rt (*ri);
3465 if (rt->is_monitor()) {
3469 if (rt->order_key () >= order_hint) {
3470 rt->set_order_key (rt->order_key () + add_route_dialog->count());
3476 ARDOUR_UI::add_route (Gtk::Window* float_window)
3484 if (add_route_dialog->is_visible()) {
3485 /* we're already doing this */
3490 add_route_dialog->unset_transient_for ();
3491 add_route_dialog->set_transient_for (*float_window);
3494 ResponseType r = (ResponseType) add_route_dialog->run ();
3496 add_route_dialog->hide();
3499 case RESPONSE_ACCEPT:
3506 if ((count = add_route_dialog->count()) <= 0) {
3512 string template_path = add_route_dialog->track_template();
3513 DisplaySuspender ds;
3515 if (!template_path.empty()) {
3516 if (add_route_dialog->name_template_is_default()) {
3517 _session->new_route_from_template (count, template_path, string());
3519 _session->new_route_from_template (count, template_path, add_route_dialog->name_template());
3524 ChanCount input_chan= add_route_dialog->channels ();
3525 ChanCount output_chan;
3526 string name_template = add_route_dialog->name_template ();
3527 PluginInfoPtr instrument = add_route_dialog->requested_instrument ();
3528 RouteGroup* route_group = add_route_dialog->route_group ();
3529 AutoConnectOption oac = Config->get_output_auto_connect();
3531 if (oac & AutoConnectMaster) {
3532 output_chan.set (DataType::AUDIO, (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan.n_audio()));
3533 output_chan.set (DataType::MIDI, 0);
3535 output_chan = input_chan;
3538 /* XXX do something with name template */
3540 switch (add_route_dialog->type_wanted()) {
3541 case AddRouteDialog::AudioTrack:
3542 session_add_audio_track (input_chan.n_audio(), output_chan.n_audio(), add_route_dialog->mode(), route_group, count, name_template);
3544 case AddRouteDialog::MidiTrack:
3545 session_add_midi_track (route_group, count, name_template, instrument);
3547 case AddRouteDialog::MixedTrack:
3548 session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, instrument);
3550 case AddRouteDialog::AudioBus:
3551 session_add_audio_bus (input_chan.n_audio(), output_chan.n_audio(), route_group, count, name_template);
3557 ARDOUR_UI::stop_video_server (bool ask_confirm)
3559 if (!video_server_process && ask_confirm) {
3560 warning << string_compose (_("Video-Server was not launched by %1. The request to stop it is ignored."), PROGRAM_NAME) << endmsg;
3562 if (video_server_process) {
3564 ArdourDialog confirm (_("Stop Video-Server"), true);
3565 Label m (_("Do you really want to stop the Video Server?"));
3566 confirm.get_vbox()->pack_start (m, true, true);
3567 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3568 confirm.add_button (_("Yes, Stop It"), Gtk::RESPONSE_ACCEPT);
3569 confirm.show_all ();
3570 if (confirm.run() == RESPONSE_CANCEL) {
3574 delete video_server_process;
3575 video_server_process =0;
3580 ARDOUR_UI::start_video_server_menu (Gtk::Window* float_window)
3582 ARDOUR_UI::start_video_server( float_window, true);
3586 ARDOUR_UI::start_video_server (Gtk::Window* float_window, bool popup_msg)
3592 if (ARDOUR_UI::instance()->video_timeline->check_server()) {
3593 if (video_server_process) {
3594 popup_error(_("The Video Server is already started."));
3596 popup_error(_("An external Video Server is configured and can be reached. Not starting a new instance."));
3602 while (!ARDOUR_UI::instance()->video_timeline->check_server()) {
3604 warning << _("Could not connect to the Video Server. Start it or configure its access URL in Edit -> Preferences.") << endmsg;
3606 VideoServerDialog *video_server_dialog = new VideoServerDialog (_session);
3608 video_server_dialog->set_transient_for (*float_window);
3611 if (!Config->get_show_video_server_dialog() && firsttime < 2) {
3612 video_server_dialog->hide();
3614 ResponseType r = (ResponseType) video_server_dialog->run ();
3615 video_server_dialog->hide();
3616 if (r != RESPONSE_ACCEPT) { return false; }
3617 if (video_server_dialog->show_again()) {
3618 Config->set_show_video_server_dialog(false);
3622 std::string icsd_exec = video_server_dialog->get_exec_path();
3623 std::string icsd_docroot = video_server_dialog->get_docroot();
3624 if (icsd_docroot.empty()) {icsd_docroot = X_("/");}
3627 if (g_lstat (icsd_docroot.c_str(), &sb) != 0 || !S_ISDIR(sb.st_mode)) {
3628 warning << _("Specified docroot is not an existing directory.") << endmsg;
3631 #ifndef PLATFORM_WINDOWS
3632 if ( (g_lstat (icsd_exec.c_str(), &sb) != 0)
3633 || (sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) == 0 ) {
3634 warning << _("Given Video Server is not an executable file.") << endmsg;
3638 if ( (g_lstat (icsd_exec.c_str(), &sb) != 0)
3639 || (sb.st_mode & (S_IXUSR)) == 0 ) {
3640 warning << _("Given Video Server is not an executable file.") << endmsg;
3646 argp=(char**) calloc(9,sizeof(char*));
3647 argp[0] = strdup(icsd_exec.c_str());
3648 argp[1] = strdup("-P");
3649 argp[2] = (char*) calloc(16,sizeof(char)); snprintf(argp[2], 16, "%s", video_server_dialog->get_listenaddr().c_str());
3650 argp[3] = strdup("-p");
3651 argp[4] = (char*) calloc(6,sizeof(char)); snprintf(argp[4], 6, "%i", video_server_dialog->get_listenport());
3652 argp[5] = strdup("-C");
3653 argp[6] = (char*) calloc(6,sizeof(char)); snprintf(argp[6], 6, "%i", video_server_dialog->get_cachesize());
3654 argp[7] = strdup(icsd_docroot.c_str());
3656 stop_video_server();
3658 if (icsd_docroot == X_("/")) {
3659 Config->set_video_advanced_setup(false);
3661 std::ostringstream osstream;
3662 osstream << "http://localhost:" << video_server_dialog->get_listenport() << "/";
3663 Config->set_video_server_url(osstream.str());
3664 Config->set_video_server_docroot(icsd_docroot);
3665 Config->set_video_advanced_setup(true);
3668 if (video_server_process) {
3669 delete video_server_process;
3672 video_server_process = new ARDOUR::SystemExec(icsd_exec, argp);
3673 if (video_server_process->start()) {
3674 warning << _("Cannot launch the video-server") << endmsg;
3677 int timeout = 120; // 6 sec
3678 while (!ARDOUR_UI::instance()->video_timeline->check_server()) {
3679 Glib::usleep (50000);
3681 if (--timeout <= 0 || !video_server_process->is_running()) break;
3684 warning << _("Video-server was started but does not respond to requests...") << endmsg;
3686 if (!ARDOUR_UI::instance()->video_timeline->check_server_docroot()) {
3687 delete video_server_process;
3688 video_server_process = 0;
3696 ARDOUR_UI::add_video (Gtk::Window* float_window)
3702 if (!start_video_server(float_window, false)) {
3703 warning << _("Could not connect to the Video Server. Start it or configure its access URL in Edit -> Preferences.") << endmsg;
3708 add_video_dialog->set_transient_for (*float_window);
3711 if (add_video_dialog->is_visible()) {
3712 /* we're already doing this */
3716 ResponseType r = (ResponseType) add_video_dialog->run ();
3717 add_video_dialog->hide();
3718 if (r != RESPONSE_ACCEPT) { return; }
3720 bool local_file, orig_local_file;
3721 std::string path = add_video_dialog->file_name(local_file);
3723 std::string orig_path = path;
3724 orig_local_file = local_file;
3726 bool auto_set_session_fps = add_video_dialog->auto_set_session_fps();
3728 if (local_file && !Glib::file_test(path, Glib::FILE_TEST_EXISTS)) {
3729 warning << string_compose(_("could not open %1"), path) << endmsg;
3732 if (!local_file && path.length() == 0) {
3733 warning << _("no video-file selected") << endmsg;
3737 switch (add_video_dialog->import_option()) {
3738 case VTL_IMPORT_TRANSCODE:
3740 TranscodeVideoDialog *transcode_video_dialog;
3741 transcode_video_dialog = new TranscodeVideoDialog (_session, path);
3742 ResponseType r = (ResponseType) transcode_video_dialog->run ();
3743 transcode_video_dialog->hide();
3744 if (r != RESPONSE_ACCEPT) {
3745 delete transcode_video_dialog;
3748 if (!transcode_video_dialog->get_audiofile().empty()) {
3749 editor->embed_audio_from_video(
3750 transcode_video_dialog->get_audiofile(),
3751 video_timeline->get_offset(),
3752 (transcode_video_dialog->import_option() != VTL_IMPORT_NO_VIDEO)
3755 switch (transcode_video_dialog->import_option()) {
3756 case VTL_IMPORT_TRANSCODED:
3757 path = transcode_video_dialog->get_filename();
3760 case VTL_IMPORT_REFERENCE:
3763 delete transcode_video_dialog;
3766 delete transcode_video_dialog;
3770 case VTL_IMPORT_NONE:
3774 /* strip _session->session_directory().video_path() from video file if possible */
3775 if (local_file && !path.compare(0, _session->session_directory().video_path().size(), _session->session_directory().video_path())) {
3776 path=path.substr(_session->session_directory().video_path().size());
3777 if (path.at(0) == G_DIR_SEPARATOR) {
3778 path=path.substr(1);
3782 video_timeline->set_update_session_fps(auto_set_session_fps);
3783 if (video_timeline->video_file_info(path, local_file)) {
3784 XMLNode* node = new XMLNode(X_("Videotimeline"));
3785 node->add_property (X_("Filename"), path);
3786 node->add_property (X_("AutoFPS"), auto_set_session_fps?X_("1"):X_("0"));
3787 node->add_property (X_("LocalFile"), local_file?X_("1"):X_("0"));
3788 if (orig_local_file) {
3789 node->add_property (X_("OriginalVideoFile"), orig_path);
3791 node->remove_property (X_("OriginalVideoFile"));
3793 _session->add_extra_xml (*node);
3794 _session->set_dirty ();
3796 _session->maybe_update_session_range(
3797 std::max(video_timeline->get_offset(), (ARDOUR::frameoffset_t) 0),
3798 std::max(video_timeline->get_offset() + video_timeline->get_duration(), (ARDOUR::frameoffset_t) 0));
3801 if (add_video_dialog->launch_xjadeo() && local_file) {
3802 editor->set_xjadeo_sensitive(true);
3803 editor->toggle_xjadeo_proc(1);
3805 editor->toggle_xjadeo_proc(0);
3807 editor->toggle_ruler_video(true);
3812 ARDOUR_UI::remove_video ()
3814 video_timeline->close_session();
3815 editor->toggle_ruler_video(false);
3818 video_timeline->set_offset_locked(false);
3819 video_timeline->set_offset(0);
3821 /* delete session state */
3822 XMLNode* node = new XMLNode(X_("Videotimeline"));
3823 _session->add_extra_xml(*node);
3824 node = new XMLNode(X_("Videomonitor"));
3825 _session->add_extra_xml(*node);
3826 stop_video_server();
3830 ARDOUR_UI::flush_videotimeline_cache (bool localcacheonly)
3832 if (localcacheonly) {
3833 video_timeline->vmon_update();
3835 video_timeline->flush_cache();
3837 editor->queue_visual_videotimeline_update();
3841 ARDOUR_UI::mixer_settings () const
3846 node = _session->instant_xml(X_("Mixer"));
3848 node = Config->instant_xml(X_("Mixer"));
3852 node = new XMLNode (X_("Mixer"));
3859 ARDOUR_UI::editor_settings () const
3864 node = _session->instant_xml(X_("Editor"));
3866 node = Config->instant_xml(X_("Editor"));
3870 if (getenv("ARDOUR_INSTANT_XML_PATH")) {
3871 node = Config->instant_xml(getenv("ARDOUR_INSTANT_XML_PATH"));
3876 node = new XMLNode (X_("Editor"));
3883 ARDOUR_UI::keyboard_settings () const
3887 node = Config->extra_xml(X_("Keyboard"));
3890 node = new XMLNode (X_("Keyboard"));
3897 ARDOUR_UI::create_xrun_marker (framepos_t where)
3899 editor->mouse_add_new_marker (where, false, true);
3903 ARDOUR_UI::halt_on_xrun_message ()
3905 MessageDialog msg (*editor,
3906 _("Recording was stopped because your system could not keep up."));
3911 ARDOUR_UI::xrun_handler (framepos_t where)
3917 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::xrun_handler, where)
3919 if (_session && Config->get_create_xrun_marker() && _session->actively_recording()) {
3920 create_xrun_marker(where);
3923 if (_session && Config->get_stop_recording_on_xrun() && _session->actively_recording()) {
3924 halt_on_xrun_message ();
3929 ARDOUR_UI::disk_overrun_handler ()
3931 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_overrun_handler)
3933 if (!have_disk_speed_dialog_displayed) {
3934 have_disk_speed_dialog_displayed = true;
3935 MessageDialog* msg = new MessageDialog (*editor, string_compose (_("\
3936 The disk system on your computer\n\
3937 was not able to keep up with %1.\n\
3939 Specifically, it failed to write data to disk\n\
3940 quickly enough to keep up with recording.\n"), PROGRAM_NAME));
3941 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3947 /* TODO: this is getting elaborate enough to warrant being split into a dedicated class */
3948 static MessageDialog *scan_dlg = NULL;
3949 static ProgressBar *scan_pbar = NULL;
3950 static HBox *scan_tbox = NULL;
3953 ARDOUR_UI::cancel_plugin_scan ()
3955 PluginManager::instance().cancel_plugin_scan();
3959 ARDOUR_UI::cancel_plugin_timeout ()
3961 PluginManager::instance().cancel_plugin_timeout();
3966 ARDOUR_UI::plugin_scan_timeout (int timeout)
3968 if (!scan_dlg || !scan_dlg->is_mapped() || !scan_pbar) {
3972 scan_pbar->set_fraction ((float) timeout / (float) Config->get_vst_scan_timeout());
3981 ARDOUR_UI::plugin_scan_dialog (std::string type, std::string plugin, bool can_cancel)
3983 if (type == X_("closeme") && !(scan_dlg && scan_dlg->is_mapped())) {
3987 const bool cancelled = PluginManager::instance().cancelled();
3988 if (type != X_("closeme") && !Config->get_show_plugin_scan_window()) {
3989 if (cancelled && scan_dlg->is_mapped()) {
3994 if (cancelled || !can_cancel) {
3999 static Gtk::Button *cancel_button;
4000 static Gtk::Button *timeout_button;
4002 scan_dlg = new MessageDialog("", false, MESSAGE_INFO, BUTTONS_NONE); // TODO manage
4003 VBox* vbox = scan_dlg->get_vbox();
4004 vbox->set_size_request(400,-1);
4005 scan_dlg->set_title (_("Scanning for plugins"));
4007 cancel_button = manage(new Gtk::Button(_("Cancel plugin scan")));
4008 cancel_button->set_name ("EditorGTKButton");
4009 cancel_button->signal_clicked().connect ( mem_fun (*this, &ARDOUR_UI::cancel_plugin_scan) );
4010 cancel_button->show();
4012 scan_dlg->get_vbox()->pack_start ( *cancel_button, PACK_SHRINK);
4014 scan_tbox = manage( new HBox() );
4016 timeout_button = manage(new Gtk::Button(_("Stop Timeout")));
4017 timeout_button->set_name ("EditorGTKButton");
4018 timeout_button->signal_clicked().connect ( mem_fun (*this, &ARDOUR_UI::cancel_plugin_timeout) );
4019 timeout_button->show();
4021 scan_pbar = manage(new ProgressBar());
4022 scan_pbar->set_orientation(Gtk::PROGRESS_RIGHT_TO_LEFT);
4023 scan_pbar->set_text(_("Scan Timeout"));
4026 scan_tbox->pack_start (*scan_pbar, PACK_EXPAND_WIDGET, 4);
4027 scan_tbox->pack_start (*timeout_button, PACK_SHRINK, 4);
4029 scan_dlg->get_vbox()->pack_start (*scan_tbox, PACK_SHRINK, 4);
4032 assert(scan_dlg && scan_tbox && cancel_button);
4034 if (type == X_("closeme")) {
4037 scan_dlg->set_message(type + ": " + Glib::path_get_basename(plugin));
4040 if (!can_cancel || !cancelled) {
4043 cancel_button->set_sensitive(can_cancel && !cancelled);
4049 ARDOUR_UI::gui_idle_handler ()
4052 /* due to idle calls, gtk_events_pending() may always return true */
4053 while (gtk_events_pending() && --timeout) {
4054 gtk_main_iteration ();
4059 ARDOUR_UI::disk_underrun_handler ()
4061 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_underrun_handler)
4063 if (!have_disk_speed_dialog_displayed) {
4064 have_disk_speed_dialog_displayed = true;
4065 MessageDialog* msg = new MessageDialog (
4066 *editor, string_compose (_("The disk system on your computer\n\
4067 was not able to keep up with %1.\n\
4069 Specifically, it failed to read data from disk\n\
4070 quickly enough to keep up with playback.\n"), PROGRAM_NAME));
4071 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
4077 ARDOUR_UI::disk_speed_dialog_gone (int /*ignored_response*/, MessageDialog* msg)
4079 have_disk_speed_dialog_displayed = false;
4084 ARDOUR_UI::session_dialog (std::string msg)
4086 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::session_dialog, msg)
4091 d = new MessageDialog (*editor, msg, false, MESSAGE_INFO, BUTTONS_OK, true);
4093 d = new MessageDialog (msg, false, MESSAGE_INFO, BUTTONS_OK, true);
4102 ARDOUR_UI::pending_state_dialog ()
4104 HBox* hbox = manage (new HBox());
4105 Image* image = manage (new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG));
4106 ArdourDialog dialog (_("Crash Recovery"), true);
4107 Label message (string_compose (_("\
4108 This session appears to have been in the\n\
4109 middle of recording when %1 or\n\
4110 the computer was shutdown.\n\
4112 %1 can recover any captured audio for\n\
4113 you, or it can ignore it. Please decide\n\
4114 what you would like to do.\n"), PROGRAM_NAME));
4115 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
4116 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
4117 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
4118 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
4119 dialog.add_button (_("Ignore crash data"), RESPONSE_REJECT);
4120 dialog.add_button (_("Recover from crash"), RESPONSE_ACCEPT);
4121 dialog.set_default_response (RESPONSE_ACCEPT);
4122 dialog.set_position (WIN_POS_CENTER);
4127 switch (dialog.run ()) {
4128 case RESPONSE_ACCEPT:
4136 ARDOUR_UI::sr_mismatch_dialog (framecnt_t desired, framecnt_t actual)
4138 HBox* hbox = new HBox();
4139 Image* image = new Image (Stock::DIALOG_WARNING, ICON_SIZE_DIALOG);
4140 ArdourDialog dialog (_("Sample Rate Mismatch"), true);
4141 Label message (string_compose (_("\
4142 This session was created with a sample rate of %1 Hz, but\n\
4143 %2 is currently running at %3 Hz. If you load this session,\n\
4144 audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual));
4146 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
4147 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
4148 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
4149 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
4150 dialog.add_button (_("Do not load session"), RESPONSE_REJECT);
4151 dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT);
4152 dialog.set_default_response (RESPONSE_ACCEPT);
4153 dialog.set_position (WIN_POS_CENTER);
4158 switch (dialog.run()) {
4159 case RESPONSE_ACCEPT:
4169 ARDOUR_UI::disconnect_from_engine ()
4171 /* drop connection to AudioEngine::Halted so that we don't act
4172 * as if the engine unexpectedly shut down
4175 halt_connection.disconnect ();
4177 if (AudioEngine::instance()->stop ()) {
4178 MessageDialog msg (*editor, _("Could not disconnect from Audio/MIDI engine"));
4182 AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
4185 update_sample_rate (0);
4190 ARDOUR_UI::reconnect_to_engine ()
4192 if (AudioEngine::instance()->start ()) {
4194 MessageDialog msg (*editor, _("Could not reconnect to the Audio/MIDI engine"));
4197 MessageDialog msg (_("Could not reconnect to the Audio/MIDI engine"));
4203 update_sample_rate (0);
4208 ARDOUR_UI::use_config ()
4210 XMLNode* node = Config->extra_xml (X_("TransportControllables"));
4212 set_transport_controllable_state (*node);
4217 ARDOUR_UI::update_transport_clocks (framepos_t pos)
4219 if (Config->get_primary_clock_delta_edit_cursor()) {
4220 primary_clock->set (pos, false, editor->get_preferred_edit_position());
4222 primary_clock->set (pos);
4225 if (Config->get_secondary_clock_delta_edit_cursor()) {
4226 secondary_clock->set (pos, false, editor->get_preferred_edit_position());
4228 secondary_clock->set (pos);
4231 if (big_clock_window) {
4232 big_clock->set (pos);
4234 ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor(pos);
4238 ARDOUR_UI::step_edit_status_change (bool yn)
4240 // XXX should really store pre-step edit status of things
4241 // we make insensitive
4244 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
4245 rec_button.set_sensitive (false);
4247 rec_button.unset_active_state ();;
4248 rec_button.set_sensitive (true);
4253 ARDOUR_UI::record_state_changed ()
4255 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);
4257 if (!_session || !big_clock_window) {
4258 /* why bother - the clock isn't visible */
4262 if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
4263 big_clock->set_active (true);
4265 big_clock->set_active (false);
4270 ARDOUR_UI::first_idle ()
4273 _session->allow_auto_play (true);
4277 editor->first_idle();
4280 Keyboard::set_can_save_keybindings (true);
4285 ARDOUR_UI::store_clock_modes ()
4287 XMLNode* node = new XMLNode(X_("ClockModes"));
4289 for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
4290 XMLNode* child = new XMLNode (X_("Clock"));
4292 child->add_property (X_("name"), (*x)->name());
4293 child->add_property (X_("mode"), enum_2_string ((*x)->mode()));
4294 child->add_property (X_("on"), ((*x)->off() ? X_("no") : X_("yes")));
4296 node->add_child_nocopy (*child);
4299 _session->add_extra_xml (*node);
4300 _session->set_dirty ();
4303 ARDOUR_UI::TransportControllable::TransportControllable (std::string name, ARDOUR_UI& u, ToggleType tp)
4304 : Controllable (name), ui (u), type(tp)
4310 ARDOUR_UI::TransportControllable::set_value (double val)
4313 /* do nothing: these are radio-style actions */
4317 const char *action = 0;
4321 action = X_("Roll");
4324 action = X_("Stop");
4327 action = X_("GotoStart");
4330 action = X_("GotoEnd");
4333 action = X_("Loop");
4336 action = X_("PlaySelection");
4339 action = X_("Record");
4349 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", action);
4357 ARDOUR_UI::TransportControllable::get_value (void) const
4384 ARDOUR_UI::setup_profile ()
4386 if (gdk_screen_width() < 1200 || getenv ("ARDOUR_NARROW_SCREEN")) {
4387 Profile->set_small_screen ();
4390 if (g_getenv ("ARDOUR_SAE")) {
4391 Profile->set_sae ();
4392 Profile->set_single_package ();
4395 if (g_getenv ("TRX")) {
4396 Profile->set_trx ();
4399 if (g_getenv ("MIXBUS")) {
4400 Profile->set_mixbus ();
4405 ARDOUR_UI::missing_file (Session*s, std::string str, DataType type)
4407 MissingFileDialog dialog (s, str, type);
4412 int result = dialog.run ();
4419 return 1; // quit entire session load
4422 result = dialog.get_action ();
4428 ARDOUR_UI::ambiguous_file (std::string file, std::vector<std::string> hits)
4430 AmbiguousFileDialog dialog (file, hits);
4436 return dialog.get_which ();
4439 /** Allocate our thread-local buffers */
4441 ARDOUR_UI::get_process_buffers ()
4443 _process_thread->get_buffers ();
4446 /** Drop our thread-local buffers */
4448 ARDOUR_UI::drop_process_buffers ()
4450 _process_thread->drop_buffers ();
4454 ARDOUR_UI::feedback_detected ()
4456 _feedback_exists = true;
4460 ARDOUR_UI::successful_graph_sort ()
4462 _feedback_exists = false;
4466 ARDOUR_UI::midi_panic ()
4469 _session->midi_panic();
4474 ARDOUR_UI::session_format_mismatch (std::string xml_path, std::string backup_path)
4476 const char* start_big = "<span size=\"x-large\" weight=\"bold\">";
4477 const char* end_big = "</span>";
4478 const char* start_mono = "<tt>";
4479 const char* end_mono = "</tt>";
4481 MessageDialog msg (string_compose (_("%4This is a session from an older version of %3%5\n\n"
4482 "%3 has copied the old session file\n\n%6%1%7\n\nto\n\n%6%2%7\n\n"
4483 "From now on, use the -2000 version with older versions of %3"),
4484 xml_path, backup_path, PROGRAM_NAME,
4486 start_mono, end_mono), true);
4493 ARDOUR_UI::reset_peak_display ()
4495 if (!_session || !_session->master_out() || !editor_meter) return;
4496 editor_meter->clear_meters();
4497 editor_meter_max_peak = -INFINITY;
4498 editor_meter_peak_display.set_active_state ( Gtkmm2ext::Off );
4502 ARDOUR_UI::reset_group_peak_display (RouteGroup* group)
4504 if (!_session || !_session->master_out()) return;
4505 if (group == _session->master_out()->route_group()) {
4506 reset_peak_display ();
4511 ARDOUR_UI::reset_route_peak_display (Route* route)
4513 if (!_session || !_session->master_out()) return;
4514 if (_session->master_out().get() == route) {
4515 reset_peak_display ();
4520 ARDOUR_UI::do_audio_midi_setup (uint32_t desired_sample_rate)
4522 audio_midi_setup->set_desired_sample_rate (desired_sample_rate);
4523 audio_midi_setup->set_position (WIN_POS_CENTER);
4525 switch (audio_midi_setup->run()) {
4526 case Gtk::RESPONSE_OK:
4528 case Gtk::RESPONSE_APPLY:
4537 ARDOUR_UI::transport_numpad_timeout ()
4539 _numpad_locate_happening = false;
4540 if (_numpad_timeout_connection.connected() )
4541 _numpad_timeout_connection.disconnect();
4546 ARDOUR_UI::transport_numpad_decimal ()
4548 _numpad_timeout_connection.disconnect();
4550 if (_numpad_locate_happening) {
4551 if (editor) editor->goto_nth_marker(_pending_locate_num - 1);
4552 _numpad_locate_happening = false;
4554 _pending_locate_num = 0;
4555 _numpad_locate_happening = true;
4556 _numpad_timeout_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::transport_numpad_timeout), 2*1000);
4561 ARDOUR_UI::transport_numpad_event (int num)
4563 if ( _numpad_locate_happening ) {
4564 _pending_locate_num = _pending_locate_num*10 + num;
4567 case 0: toggle_roll(false, false); break;
4568 case 1: transport_rewind(1); break;
4569 case 2: transport_forward(1); break;
4570 case 3: transport_record(true); break;
4571 case 4: toggle_session_auto_loop(); break;
4572 case 5: transport_record(false); toggle_session_auto_loop(); break;
4573 case 6: toggle_punch(); break;
4574 case 7: toggle_click(); break;
4575 case 8: toggle_auto_return(); break;
4576 case 9: toggle_follow_edits(); break;
4582 ARDOUR_UI::set_flat_buttons ()
4584 CairoWidget::set_flat_buttons( config()->get_flat_buttons() );