2 Copyright (C) 1999-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "gtk2ardour-config.h"
37 #include <sys/resource.h>
38 #include <sys/types.h>
39 #include <sys/sysctl.h>
41 #include <gtkmm/messagedialog.h>
42 #include <gtkmm/accelmap.h>
44 #include "pbd/error.h"
45 #include "pbd/basename.h"
46 #include "pbd/compose.h"
47 #include "pbd/failed_constructor.h"
48 #include "pbd/enumwriter.h"
49 #include "pbd/memento_command.h"
50 #include "pbd/openuri.h"
51 #include "pbd/file_utils.h"
53 #include "gtkmm2ext/application.h"
54 #include "gtkmm2ext/bindings.h"
55 #include "gtkmm2ext/gtk_ui.h"
56 #include "gtkmm2ext/utils.h"
57 #include "gtkmm2ext/click_box.h"
58 #include "gtkmm2ext/fastmeter.h"
59 #include "gtkmm2ext/popup.h"
60 #include "gtkmm2ext/window_title.h"
62 #include "midi++/manager.h"
64 #include "ardour/ardour.h"
65 #include "ardour/audioengine.h"
66 #include "ardour/audiofilesource.h"
67 #include "ardour/automation_watch.h"
68 #include "ardour/diskstream.h"
69 #include "ardour/filename_extensions.h"
70 #include "ardour/port.h"
71 #include "ardour/process_thread.h"
72 #include "ardour/profile.h"
73 #include "ardour/recent_sessions.h"
74 #include "ardour/session_directory.h"
75 #include "ardour/session_route.h"
76 #include "ardour/session_state_utils.h"
77 #include "ardour/session_utils.h"
78 #include "ardour/slave.h"
80 #include "timecode/time.h"
82 typedef uint64_t microseconds_t;
86 #include "add_route_dialog.h"
87 #include "ambiguous_file_dialog.h"
88 #include "ardour_ui.h"
89 #include "audio_clock.h"
90 #include "bundle_manager.h"
91 #include "engine_dialog.h"
92 #include "gain_meter.h"
93 #include "global_port_matrix.h"
94 #include "gui_object.h"
95 #include "gui_thread.h"
97 #include "location_ui.h"
98 #include "main_clock.h"
99 #include "missing_file_dialog.h"
100 #include "missing_plugin_dialog.h"
101 #include "mixer_ui.h"
102 #include "mouse_cursors.h"
104 #include "processor_box.h"
105 #include "prompter.h"
106 #include "public_editor.h"
107 #include "route_time_axis.h"
108 #include "session_metadata_dialog.h"
109 #include "shuttle_control.h"
110 #include "speaker_dialog.h"
113 #include "theme_manager.h"
114 #include "time_axis_view_item.h"
116 #include "window_proxy.h"
120 using namespace ARDOUR;
122 using namespace Gtkmm2ext;
126 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
127 UIConfiguration *ARDOUR_UI::ui_config = 0;
129 sigc::signal<void,bool> ARDOUR_UI::Blink;
130 sigc::signal<void> ARDOUR_UI::RapidScreenUpdate;
131 sigc::signal<void> ARDOUR_UI::SuperRapidScreenUpdate;
132 sigc::signal<void, framepos_t, bool, framepos_t> ARDOUR_UI::Clock;
134 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
136 : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
138 , gui_object_state (new GUIObjectState)
139 , primary_clock (new MainClock (X_("primary"), false, X_("transport"), true, true, true, false, true))
140 , secondary_clock (new MainClock (X_("secondary"), false, X_("secondary"), true, true, false, false, true))
144 , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
148 , roll_controllable (new TransportControllable ("transport roll", *this, TransportControllable::Roll))
149 , stop_controllable (new TransportControllable ("transport stop", *this, TransportControllable::Stop))
150 , goto_start_controllable (new TransportControllable ("transport goto start", *this, TransportControllable::GotoStart))
151 , goto_end_controllable (new TransportControllable ("transport goto end", *this, TransportControllable::GotoEnd))
152 , auto_loop_controllable (new TransportControllable ("transport auto loop", *this, TransportControllable::AutoLoop))
153 , play_selection_controllable (new TransportControllable ("transport play selection", *this, TransportControllable::PlaySelection))
154 , rec_controllable (new TransportControllable ("transport rec-enable", *this, TransportControllable::RecordEnable))
156 , auto_return_button (ArdourButton::led_default_elements)
157 , follow_edits_button (ArdourButton::led_default_elements)
158 , auto_input_button (ArdourButton::led_default_elements)
160 , auditioning_alert_button (_("audition"))
161 , solo_alert_button (_("solo"))
162 , feedback_alert_button (_("feedback"))
164 , error_log_button (_("Errors"))
166 , _status_bar_visibility (X_("status-bar"))
167 , _feedback_exists (false)
176 if (theArdourUI == 0) {
180 ui_config = new UIConfiguration();
181 theme_manager = new ThemeManager();
189 _session_is_new = false;
190 big_clock_window = 0;
191 big_clock_height = 0;
192 big_clock_resize_in_progress = false;
193 session_selector_window = 0;
194 last_key_press_time = 0;
195 add_route_dialog = 0;
198 rc_option_editor = 0;
199 session_option_editor = 0;
201 open_session_selector = 0;
202 have_configure_timeout = false;
203 have_disk_speed_dialog_displayed = false;
204 session_loaded = false;
205 ignore_dual_punch = false;
206 original_big_clock_width = -1;
207 original_big_clock_height = -1;
208 original_big_clock_font_size = 0;
210 roll_button.set_controllable (roll_controllable);
211 stop_button.set_controllable (stop_controllable);
212 goto_start_button.set_controllable (goto_start_controllable);
213 goto_end_button.set_controllable (goto_end_controllable);
214 auto_loop_button.set_controllable (auto_loop_controllable);
215 play_selection_button.set_controllable (play_selection_controllable);
216 rec_button.set_controllable (rec_controllable);
218 roll_button.set_name ("transport button");
219 stop_button.set_name ("transport button");
220 goto_start_button.set_name ("transport button");
221 goto_end_button.set_name ("transport button");
222 auto_loop_button.set_name ("transport button");
223 play_selection_button.set_name ("transport button");
224 rec_button.set_name ("transport recenable button");
225 midi_panic_button.set_name ("transport button");
227 goto_start_button.set_tweaks (ArdourButton::ShowClick);
228 goto_end_button.set_tweaks (ArdourButton::ShowClick);
229 midi_panic_button.set_tweaks (ArdourButton::ShowClick);
231 last_configure_time= 0;
234 ARDOUR::Diskstream::DiskOverrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
235 ARDOUR::Diskstream::DiskUnderrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
237 /* handle dialog requests */
239 ARDOUR::Session::Dialog.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_dialog, this, _1), gui_context());
241 /* handle pending state with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
243 ARDOUR::Session::AskAboutPendingState.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::pending_state_dialog, this));
245 /* handle sr mismatch with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
247 ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
249 /* handle requests to quit (coming from JACK session) */
251 ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
253 /* tell the user about feedback */
255 ARDOUR::Session::FeedbackDetected.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::feedback_detected, this), gui_context ());
256 ARDOUR::Session::SuccessfulGraphSort.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::successful_graph_sort, this), gui_context ());
258 /* handle requests to deal with missing files */
260 ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3));
262 /* and ambiguous files */
264 ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2, _3));
266 /* lets get this party started */
269 if (ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization)) {
270 throw failed_constructor ();
273 setup_gtk_ardour_enums ();
276 GainMeter::setup_slider_pix ();
277 RouteTimeAxisView::setup_slider_pix ();
278 ProcessorEntry::setup_slider_pix ();
279 SessionEvent::create_per_thread_pool ("GUI", 512);
281 } catch (failed_constructor& err) {
282 error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg;
287 /* we like keyboards */
289 keyboard = new ArdourKeyboard(*this);
291 XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
293 keyboard->set_state (*node, Stateful::loading_state_version);
296 /* we don't like certain modifiers */
297 Bindings::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK);
301 TimeAxisViewItem::set_constant_heights ();
303 /* The following must happen after ARDOUR::init() so that Config is set up */
305 location_ui = new ActionWindowProxy<LocationUIWindow> (X_("locations"), Config->extra_xml (X_("UI")), X_("ToggleLocations"));
306 big_clock_window = new ActionWindowProxy<Gtk::Window> (X_("bigclock"), Config->extra_xml (X_("UI")), X_("ToggleBigClock"));
307 speaker_config_window = new ActionWindowProxy<SpeakerDialog> (X_("speakerconf"), Config->extra_xml (X_("UI")), X_("toggle-speaker-config"));
309 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
310 _global_port_matrix[*i] = new ActionWindowProxy<GlobalPortMatrixWindow> (
311 string_compose ("GlobalPortMatrix-%1", (*i).to_string()),
312 Config->extra_xml (X_("UI")),
313 string_compose ("toggle-%1-connection-manager", (*i).to_string())
319 SpeakerDialog* s = new SpeakerDialog ();
320 s->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/toggle-speaker-config")));
321 speaker_config_window->set (s);
323 starting.connect (sigc::mem_fun(*this, &ARDOUR_UI::startup));
324 stopping.connect (sigc::mem_fun(*this, &ARDOUR_UI::shutdown));
326 _process_thread = new ProcessThread ();
327 _process_thread->init ();
329 DPIReset.connect (sigc::mem_fun (*this, &ARDOUR_UI::resize_text_widgets));
334 ARDOUR_UI::create_engine ()
336 // this gets called every time by new_session()
342 loading_message (_("Starting audio engine"));
345 engine = new ARDOUR::AudioEngine (ARDOUR_COMMAND_LINE::jack_client_name, ARDOUR_COMMAND_LINE::jack_session_uuid);
352 engine->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
353 engine->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context());
354 engine->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
356 engine->Halted.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
358 ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
366 ARDOUR_UI::post_engine ()
368 /* Things to be done once we create the AudioEngine
371 ARDOUR::init_post_engine ();
373 /* load up the UI manager */
375 ActionManager::init ();
379 if (setup_windows ()) {
380 throw failed_constructor ();
383 /* Do this after setup_windows (), as that's when the _status_bar_visibility is created */
384 XMLNode* n = Config->extra_xml (X_("UI"));
386 _status_bar_visibility.set_state (*n);
389 check_memory_locking();
391 /* this is the first point at which all the keybindings are available */
393 if (ARDOUR_COMMAND_LINE::show_key_actions) {
394 vector<string> names;
395 vector<string> paths;
396 vector<string> tooltips;
398 vector<AccelKey> bindings;
400 ActionManager::get_all_actions (names, paths, tooltips, keys, bindings);
402 vector<string>::iterator n;
403 vector<string>::iterator k;
404 for (n = names.begin(), k = keys.begin(); n != names.end(); ++n, ++k) {
405 cout << "Action: " << (*n) << " bound to " << (*k) << endl;
411 blink_timeout_tag = -1;
413 /* this being a GUI and all, we want peakfiles */
415 AudioFileSource::set_build_peakfiles (true);
416 AudioFileSource::set_build_missing_peakfiles (true);
418 /* set default clock modes */
420 if (Profile->get_sae()) {
421 primary_clock->set_mode (AudioClock::BBT);
422 secondary_clock->set_mode (AudioClock::MinSec);
424 primary_clock->set_mode (AudioClock::Timecode);
425 secondary_clock->set_mode (AudioClock::BBT);
428 /* start the time-of-day-clock */
431 /* OS X provides a nearly-always visible wallclock, so don't be stupid */
432 update_wall_clock ();
433 Glib::signal_timeout().connect_seconds (sigc::mem_fun(*this, &ARDOUR_UI::update_wall_clock), 1);
436 update_disk_space ();
438 update_sample_rate (engine->frame_rate());
439 update_timecode_format ();
441 Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
442 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
443 Config->map_parameters (pc);
445 /* now start and maybe save state */
447 if (do_engine_start () == 0) {
448 if (_session && _session_is_new) {
449 /* we need to retain initial visual
450 settings for a new session
452 _session->save_state ("");
457 ARDOUR_UI::~ARDOUR_UI ()
462 delete add_route_dialog;
466 ARDOUR_UI::pop_back_splash (Gtk::Window& win)
468 if (Splash::instance()) {
469 Splash::instance()->pop_back_for (win);
474 ARDOUR_UI::configure_timeout ()
476 if (last_configure_time == 0) {
477 /* no configure events yet */
481 /* force a gap of 0.5 seconds since the last configure event
484 if (get_microseconds() - last_configure_time < 500000) {
487 have_configure_timeout = false;
488 save_ardour_state ();
494 ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
496 if (have_configure_timeout) {
497 last_configure_time = get_microseconds();
499 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::configure_timeout), 100);
500 have_configure_timeout = true;
507 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
509 const XMLProperty* prop;
511 if ((prop = node.property ("roll")) != 0) {
512 roll_controllable->set_id (prop->value());
514 if ((prop = node.property ("stop")) != 0) {
515 stop_controllable->set_id (prop->value());
517 if ((prop = node.property ("goto-start")) != 0) {
518 goto_start_controllable->set_id (prop->value());
520 if ((prop = node.property ("goto-end")) != 0) {
521 goto_end_controllable->set_id (prop->value());
523 if ((prop = node.property ("auto-loop")) != 0) {
524 auto_loop_controllable->set_id (prop->value());
526 if ((prop = node.property ("play-selection")) != 0) {
527 play_selection_controllable->set_id (prop->value());
529 if ((prop = node.property ("rec")) != 0) {
530 rec_controllable->set_id (prop->value());
532 if ((prop = node.property ("shuttle")) != 0) {
533 shuttle_box->controllable()->set_id (prop->value());
538 ARDOUR_UI::get_transport_controllable_state ()
540 XMLNode* node = new XMLNode(X_("TransportControllables"));
543 roll_controllable->id().print (buf, sizeof (buf));
544 node->add_property (X_("roll"), buf);
545 stop_controllable->id().print (buf, sizeof (buf));
546 node->add_property (X_("stop"), buf);
547 goto_start_controllable->id().print (buf, sizeof (buf));
548 node->add_property (X_("goto_start"), buf);
549 goto_end_controllable->id().print (buf, sizeof (buf));
550 node->add_property (X_("goto_end"), buf);
551 auto_loop_controllable->id().print (buf, sizeof (buf));
552 node->add_property (X_("auto_loop"), buf);
553 play_selection_controllable->id().print (buf, sizeof (buf));
554 node->add_property (X_("play_selection"), buf);
555 rec_controllable->id().print (buf, sizeof (buf));
556 node->add_property (X_("rec"), buf);
557 shuttle_box->controllable()->id().print (buf, sizeof (buf));
558 node->add_property (X_("shuttle"), buf);
565 ARDOUR_UI::autosave_session ()
567 if (g_main_depth() > 1) {
568 /* inside a recursive main loop,
569 give up because we may not be able to
575 if (!Config->get_periodic_safety_backups()) {
580 _session->maybe_write_autosave();
587 ARDOUR_UI::update_autosave ()
589 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_autosave)
591 if (_session && _session->dirty()) {
592 if (_autosave_connection.connected()) {
593 _autosave_connection.disconnect();
596 _autosave_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &ARDOUR_UI::autosave_session),
597 Config->get_periodic_safety_backup_interval() * 1000);
600 if (_autosave_connection.connected()) {
601 _autosave_connection.disconnect();
607 ARDOUR_UI::startup ()
609 Application* app = Application::instance ();
611 app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish));
612 app->ShouldLoad.connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_load));
615 call_the_mothership (VERSIONSTRING);
620 if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
626 goto_editor_window ();
628 /* Add the window proxies here; their addition may cause windows to be opened, and we want them
629 to be opened on top of the editor window that goto_editor_window() just opened.
631 add_window_proxy (location_ui);
632 add_window_proxy (big_clock_window);
633 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
634 add_window_proxy (_global_port_matrix[*i]);
637 /* We have to do this here since goto_editor_window() ends up calling show_all() on the
638 * editor window, and we may want stuff to be hidden.
640 _status_bar_visibility.update ();
642 BootMessage (string_compose (_("%1 is ready for use"), PROGRAM_NAME));
646 ARDOUR_UI::no_memory_warning ()
648 XMLNode node (X_("no-memory-warning"));
649 Config->add_instant_xml (node);
653 ARDOUR_UI::check_memory_locking ()
656 /* OS X doesn't support mlockall(2), and so testing for memory locking capability there is pointless */
660 XMLNode* memory_warning_node = Config->instant_xml (X_("no-memory-warning"));
662 if (engine->is_realtime() && memory_warning_node == 0) {
664 struct rlimit limits;
666 long pages, page_size;
668 size_t pages_len=sizeof(pages);
669 if ((page_size = getpagesize()) < 0 ||
670 sysctlbyname("hw.availpages", &pages, &pages_len, NULL, 0))
672 if ((page_size = sysconf (_SC_PAGESIZE)) < 0 ||(pages = sysconf (_SC_PHYS_PAGES)) < 0)
677 ram = (int64_t) pages * (int64_t) page_size;
680 if (getrlimit (RLIMIT_MEMLOCK, &limits)) {
684 if (limits.rlim_cur != RLIM_INFINITY) {
686 if (ram == 0 || ((double) limits.rlim_cur / ram) < 0.75) {
690 _("WARNING: Your system has a limit for maximum amount of locked memory. "
691 "This might cause %1 to run out of memory before your system "
692 "runs out of memory. \n\n"
693 "You can view the memory limit with 'ulimit -l', "
694 "and it is normally controlled by %2"),
695 PROGRAM_NAME).c_str(),
697 X_("/etc/login.conf")
699 X_(" /etc/security/limits.conf")
703 msg.set_default_response (RESPONSE_OK);
705 VBox* vbox = msg.get_vbox();
707 CheckButton cb (_("Do not show this window again"));
709 cb.signal_toggled().connect (sigc::mem_fun (*this, &ARDOUR_UI::no_memory_warning));
711 hbox.pack_start (cb, true, false);
712 vbox->pack_start (hbox);
717 pop_back_splash (msg);
719 editor->ensure_float (msg);
729 ARDOUR_UI::queue_finish ()
731 Glib::signal_idle().connect (mem_fun (*this, &ARDOUR_UI::idle_finish));
735 ARDOUR_UI::idle_finish ()
738 return false; /* do not call again */
746 if (_session->dirty()) {
747 vector<string> actions;
748 actions.push_back (_("Don't quit"));
749 actions.push_back (_("Just quit"));
750 actions.push_back (_("Save and quit"));
751 switch (ask_about_saving_session(actions)) {
756 /* use the default name */
757 if (save_state_canfail ("")) {
758 /* failed - don't quit */
759 MessageDialog msg (*editor,
761 %1 was unable to save your session.\n\n\
762 If you still wish to quit, please use the\n\n\
763 \"Just quit\" option."), PROGRAM_NAME));
764 pop_back_splash(msg);
774 second_connection.disconnect ();
775 point_one_second_connection.disconnect ();
776 point_oh_five_second_connection.disconnect ();
777 point_zero_one_second_connection.disconnect();
780 /* Save state before deleting the session, as that causes some
781 windows to be destroyed before their visible state can be
784 save_ardour_state ();
786 loading_message (string_compose (_("Please wait while %1 cleans up..."), PROGRAM_NAME));
789 // _session->set_deletion_in_progress ();
790 _session->set_clean ();
791 _session->remove_pending_capture_state ();
796 ArdourDialog::close_all_dialogs ();
802 ARDOUR_UI::ask_about_saving_session (const vector<string>& actions)
804 ArdourDialog window (_("Unsaved Session"));
805 Gtk::HBox dhbox; // the hbox for the image and text
806 Gtk::Label prompt_label;
807 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_WARNING, Gtk::ICON_SIZE_DIALOG));
811 assert (actions.size() >= 3);
813 window.add_button (actions[0], RESPONSE_REJECT);
814 window.add_button (actions[1], RESPONSE_APPLY);
815 window.add_button (actions[2], RESPONSE_ACCEPT);
817 window.set_default_response (RESPONSE_ACCEPT);
819 Gtk::Button noquit_button (msg);
820 noquit_button.set_name ("EditorGTKButton");
824 if (_session->snap_name() == _session->name()) {
825 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?"),
826 _session->snap_name());
828 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?"),
829 _session->snap_name());
832 prompt_label.set_text (prompt);
833 prompt_label.set_name (X_("PrompterLabel"));
834 prompt_label.set_alignment(ALIGN_LEFT, ALIGN_TOP);
836 dimage->set_alignment(ALIGN_CENTER, ALIGN_TOP);
837 dhbox.set_homogeneous (false);
838 dhbox.pack_start (*dimage, false, false, 5);
839 dhbox.pack_start (prompt_label, true, false, 5);
840 window.get_vbox()->pack_start (dhbox);
842 window.set_name (_("Prompter"));
843 window.set_position (Gtk::WIN_POS_MOUSE);
844 window.set_modal (true);
845 window.set_resizable (false);
851 window.set_keep_above (true);
854 ResponseType r = (ResponseType) window.run();
859 case RESPONSE_ACCEPT: // save and get out of here
861 case RESPONSE_APPLY: // get out of here
872 ARDOUR_UI::every_second ()
875 update_buffer_load ();
876 update_disk_space ();
877 update_timecode_format ();
882 ARDOUR_UI::every_point_one_seconds ()
884 shuttle_box->update_speed_display ();
885 RapidScreenUpdate(); /* EMIT_SIGNAL */
890 ARDOUR_UI::every_point_zero_one_seconds ()
892 // august 2007: actual update frequency: 40Hz, not 100Hz
894 SuperRapidScreenUpdate(); /* EMIT_SIGNAL */
899 ARDOUR_UI::update_sample_rate (framecnt_t)
903 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
905 if (!engine->connected()) {
907 snprintf (buf, sizeof (buf), "%s", _("disconnected"));
911 framecnt_t rate = engine->frame_rate();
913 if (fmod (rate, 1000.0) != 0.0) {
914 snprintf (buf, sizeof (buf), _("JACK: <span foreground=\"green\">%.1f kHz / %4.1f ms</span>"),
915 (float) rate/1000.0f,
916 (engine->frames_per_cycle() / (float) rate) * 1000.0f);
918 snprintf (buf, sizeof (buf), _("JACK: <span foreground=\"green\">%" PRId64 " kHz / %4.1f ms</span>"),
920 (engine->frames_per_cycle() / (float) rate) * 1000.0f);
924 sample_rate_label.set_markup (buf);
928 ARDOUR_UI::update_format ()
931 format_label.set_text ("");
936 s << _("File:") << X_(" <span foreground=\"green\">");
938 switch (_session->config.get_native_file_header_format ()) {
964 switch (_session->config.get_native_file_data_format ()) {
978 format_label.set_markup (s.str ());
982 ARDOUR_UI::update_cpu_load ()
986 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
987 should also be changed.
990 float const c = engine->get_cpu_load ();
991 snprintf (buf, sizeof (buf), _("DSP: <span foreground=\"%s\">%5.1f%%</span>"), c >= 90 ? X_("red") : X_("green"), c);
992 cpu_load_label.set_markup (buf);
996 ARDOUR_UI::update_buffer_load ()
1000 uint32_t const playback = _session ? _session->playback_load () : 100;
1001 uint32_t const capture = _session ? _session->capture_load () : 100;
1003 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1004 should also be changed.
1010 _("Buffers: <span foreground=\"green\">p:</span><span foreground=\"%s\">%" PRIu32 "%%</span> "
1011 "<span foreground=\"green\">c:</span><span foreground=\"%s\">%" PRIu32 "%%</span>"),
1012 playback <= 5 ? X_("red") : X_("green"),
1014 capture <= 5 ? X_("red") : X_("green"),
1018 buffer_load_label.set_markup (buf);
1020 buffer_load_label.set_text ("");
1025 ARDOUR_UI::count_recenabled_streams (Route& route)
1027 Track* track = dynamic_cast<Track*>(&route);
1028 if (track && track->record_enabled()) {
1029 rec_enabled_streams += track->n_inputs().n_total();
1034 ARDOUR_UI::update_disk_space()
1036 if (_session == 0) {
1040 boost::optional<framecnt_t> opt_frames = _session->available_capture_duration();
1042 framecnt_t fr = _session->frame_rate();
1045 /* Available space is unknown */
1046 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">Unknown</span>"));
1047 } else if (opt_frames.get_value_or (0) == max_framecnt) {
1048 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">24hrs+</span>"));
1050 rec_enabled_streams = 0;
1051 _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams);
1053 framecnt_t frames = opt_frames.get_value_or (0);
1055 if (rec_enabled_streams) {
1056 frames /= rec_enabled_streams;
1063 hrs = frames / (fr * 3600);
1066 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">>24 hrs</span>"));
1068 frames -= hrs * fr * 3600;
1069 mins = frames / (fr * 60);
1070 frames -= mins * fr * 60;
1073 bool const low = (hrs == 0 && mins <= 30);
1077 _("Disk: <span foreground=\"%s\">%02dh:%02dm:%02ds</span>"),
1078 low ? X_("red") : X_("green"),
1084 disk_space_label.set_markup (buf);
1088 ARDOUR_UI::update_timecode_format ()
1094 TimecodeSlave* tcslave;
1095 SyncSource sync_src = Config->get_sync_source();
1097 if ((sync_src == LTC || sync_src == MTC) && (tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
1098 matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
1103 snprintf (buf, sizeof (buf), S_("Timecode|TC: <span foreground=\"%s\">%s</span>"),
1104 matching ? X_("green") : X_("red"),
1105 Timecode::timecode_format_name (_session->config.get_timecode_format()).c_str());
1107 snprintf (buf, sizeof (buf), "TC: n/a");
1110 timecode_format_label.set_markup (buf);
1114 ARDOUR_UI::update_wall_clock ()
1118 static int last_min = -1;
1121 tm_now = localtime (&now);
1122 if (last_min != tm_now->tm_min) {
1124 sprintf (buf, "%02d:%02d", tm_now->tm_hour, tm_now->tm_min);
1125 wall_clock_label.set_text (buf);
1126 last_min = tm_now->tm_min;
1133 ARDOUR_UI::redisplay_recent_sessions ()
1135 std::vector<std::string> session_directories;
1136 RecentSessionsSorter cmp;
1138 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
1139 recent_session_model->clear ();
1141 ARDOUR::RecentSessions rs;
1142 ARDOUR::read_recent_sessions (rs);
1145 recent_session_display.set_model (recent_session_model);
1149 // sort them alphabetically
1150 sort (rs.begin(), rs.end(), cmp);
1152 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
1153 session_directories.push_back ((*i).second);
1156 for (vector<std::string>::const_iterator i = session_directories.begin();
1157 i != session_directories.end(); ++i)
1159 std::vector<std::string> state_file_paths;
1161 // now get available states for this session
1163 get_state_files_in_directory (*i, state_file_paths);
1165 vector<string*>* states;
1166 vector<const gchar*> item;
1167 string fullpath = *i;
1169 /* remove any trailing / */
1171 if (fullpath[fullpath.length() - 1] == '/') {
1172 fullpath = fullpath.substr (0, fullpath.length() - 1);
1175 /* check whether session still exists */
1176 if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
1177 /* session doesn't exist */
1181 /* now get available states for this session */
1183 if ((states = Session::possible_states (fullpath)) == 0) {
1184 /* no state file? */
1188 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
1190 Gtk::TreeModel::Row row = *(recent_session_model->append());
1192 row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath);
1193 row[recent_session_columns.fullpath] = fullpath;
1195 if (state_file_names.size() > 1) {
1199 for (std::vector<std::string>::iterator i2 = state_file_names.begin();
1200 i2 != state_file_names.end(); ++i2)
1203 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
1205 child_row[recent_session_columns.visible_name] = *i2;
1206 child_row[recent_session_columns.fullpath] = fullpath;
1211 recent_session_display.set_tooltip_column(1); // recent_session_columns.fullpath
1212 recent_session_display.set_model (recent_session_model);
1216 ARDOUR_UI::build_session_selector ()
1218 session_selector_window = new ArdourDialog (_("Recent Sessions"));
1220 Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow);
1222 session_selector_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1223 session_selector_window->add_button (Stock::OPEN, RESPONSE_ACCEPT);
1224 session_selector_window->set_default_response (RESPONSE_ACCEPT);
1225 recent_session_model = TreeStore::create (recent_session_columns);
1226 recent_session_display.set_model (recent_session_model);
1227 recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name);
1228 recent_session_display.set_headers_visible (false);
1229 recent_session_display.get_selection()->set_mode (SELECTION_BROWSE);
1230 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &ARDOUR_UI::recent_session_row_activated));
1232 scroller->add (recent_session_display);
1233 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1235 session_selector_window->set_name ("SessionSelectorWindow");
1236 session_selector_window->set_size_request (200, 400);
1237 session_selector_window->get_vbox()->pack_start (*scroller);
1239 recent_session_display.show();
1244 ARDOUR_UI::recent_session_row_activated (const TreePath& /*path*/, TreeViewColumn* /*col*/)
1246 session_selector_window->response (RESPONSE_ACCEPT);
1250 ARDOUR_UI::open_recent_session ()
1252 bool can_return = (_session != 0);
1254 if (session_selector_window == 0) {
1255 build_session_selector ();
1258 redisplay_recent_sessions ();
1262 session_selector_window->set_position (WIN_POS_MOUSE);
1264 ResponseType r = (ResponseType) session_selector_window->run ();
1267 case RESPONSE_ACCEPT:
1271 session_selector_window->hide();
1278 if (recent_session_display.get_selection()->count_selected_rows() == 0) {
1282 session_selector_window->hide();
1284 Gtk::TreeModel::iterator i = recent_session_display.get_selection()->get_selected();
1286 if (i == recent_session_model->children().end()) {
1290 std::string path = (*i)[recent_session_columns.fullpath];
1291 std::string state = (*i)[recent_session_columns.visible_name];
1293 _session_is_new = false;
1295 if (load_session (path, state) == 0) {
1304 ARDOUR_UI::check_audioengine ()
1307 if (!engine->connected()) {
1308 MessageDialog msg (string_compose (
1309 _("%1 is not connected to JACK\n"
1310 "You cannot open or close sessions in this condition"),
1312 pop_back_splash (msg);
1323 ARDOUR_UI::open_session ()
1325 if (!check_audioengine()) {
1330 /* popup selector window */
1332 if (open_session_selector == 0) {
1334 /* ardour sessions are folders */
1336 open_session_selector = new Gtk::FileChooserDialog (_("Open Session"), FILE_CHOOSER_ACTION_OPEN);
1337 open_session_selector->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1338 open_session_selector->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
1339 open_session_selector->set_default_response(Gtk::RESPONSE_ACCEPT);
1342 string session_parent_dir = Glib::path_get_dirname(_session->path());
1343 string::size_type last_dir_sep = session_parent_dir.rfind(G_DIR_SEPARATOR);
1344 session_parent_dir = session_parent_dir.substr(0, last_dir_sep);
1345 open_session_selector->set_current_folder(session_parent_dir);
1347 open_session_selector->set_current_folder(Config->get_default_session_parent_dir());
1350 open_session_selector->add_shortcut_folder (Config->get_default_session_parent_dir());
1352 FileFilter session_filter;
1353 session_filter.add_pattern ("*.ardour");
1354 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
1355 open_session_selector->add_filter (session_filter);
1356 open_session_selector->set_filter (session_filter);
1359 int response = open_session_selector->run();
1360 open_session_selector->hide ();
1363 case RESPONSE_ACCEPT:
1366 open_session_selector->hide();
1370 open_session_selector->hide();
1371 string session_path = open_session_selector->get_filename();
1375 if (session_path.length() > 0) {
1376 if (ARDOUR::find_session (session_path, path, name, isnew) == 0) {
1377 _session_is_new = isnew;
1378 load_session (path, name);
1385 ARDOUR_UI::session_add_mixed_track (const ChanCount& input, const ChanCount& output, RouteGroup* route_group,
1386 uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1388 list<boost::shared_ptr<MidiTrack> > tracks;
1390 if (_session == 0) {
1391 warning << _("You cannot add a track without a session already loaded.") << endmsg;
1396 tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template);
1398 if (tracks.size() != how_many) {
1399 if (how_many == 1) {
1400 error << _("could not create a new mixed track") << endmsg;
1402 error << string_compose (_("could not create %1 new mixed tracks"), how_many) << endmsg;
1408 MessageDialog msg (*editor,
1409 string_compose (_("There are insufficient JACK ports available\n\
1410 to create a new track or bus.\n\
1411 You should save %1, exit and\n\
1412 restart JACK with more ports."), PROGRAM_NAME));
1419 ARDOUR_UI::session_add_midi_route (bool disk, RouteGroup* route_group, uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1421 ChanCount one_midi_channel;
1422 one_midi_channel.set (DataType::MIDI, 1);
1425 session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, instrument);
1430 ARDOUR_UI::session_add_audio_route (
1432 int32_t input_channels,
1433 int32_t output_channels,
1434 ARDOUR::TrackMode mode,
1435 RouteGroup* route_group,
1437 string const & name_template
1440 list<boost::shared_ptr<AudioTrack> > tracks;
1443 if (_session == 0) {
1444 warning << _("You cannot add a track or bus without a session already loaded.") << endmsg;
1450 tracks = _session->new_audio_track (input_channels, output_channels, mode, route_group, how_many, name_template);
1452 if (tracks.size() != how_many) {
1453 error << string_compose (P_("could not create %1 new audio track", "could not create %1 new audio tracks", how_many), how_many)
1459 routes = _session->new_audio_route (input_channels, output_channels, route_group, how_many, name_template);
1461 if (routes.size() != how_many) {
1462 error << string_compose (P_("could not create %1 new audio bus", "could not create %1 new audio busses", how_many), how_many)
1469 MessageDialog msg (*editor,
1470 string_compose (_("There are insufficient JACK ports available\n\
1471 to create a new track or bus.\n\
1472 You should save %1, exit and\n\
1473 restart JACK with more ports."), PROGRAM_NAME));
1474 pop_back_splash (msg);
1480 ARDOUR_UI::transport_goto_start ()
1483 _session->goto_start();
1485 /* force displayed area in editor to start no matter
1486 what "follow playhead" setting is.
1490 editor->center_screen (_session->current_start_frame ());
1496 ARDOUR_UI::transport_goto_zero ()
1499 _session->request_locate (0);
1501 /* force displayed area in editor to start no matter
1502 what "follow playhead" setting is.
1506 editor->reset_x_origin (0);
1512 ARDOUR_UI::transport_goto_wallclock ()
1514 if (_session && editor) {
1521 localtime_r (&now, &tmnow);
1523 frames = tmnow.tm_hour * (60 * 60 * _session->frame_rate());
1524 frames += tmnow.tm_min * (60 * _session->frame_rate());
1525 frames += tmnow.tm_sec * _session->frame_rate();
1527 _session->request_locate (frames, _session->transport_rolling ());
1529 /* force displayed area in editor to start no matter
1530 what "follow playhead" setting is.
1534 editor->center_screen (frames);
1540 ARDOUR_UI::transport_goto_end ()
1543 framepos_t const frame = _session->current_end_frame();
1544 _session->request_locate (frame);
1546 /* force displayed area in editor to start no matter
1547 what "follow playhead" setting is.
1551 editor->center_screen (frame);
1557 ARDOUR_UI::transport_stop ()
1563 if (_session->is_auditioning()) {
1564 _session->cancel_audition ();
1568 _session->request_stop (false, true);
1572 ARDOUR_UI::transport_record (bool roll)
1576 switch (_session->record_status()) {
1577 case Session::Disabled:
1578 if (_session->ntracks() == 0) {
1579 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."));
1583 _session->maybe_enable_record ();
1588 case Session::Recording:
1590 _session->request_stop();
1592 _session->disable_record (false, true);
1596 case Session::Enabled:
1597 _session->disable_record (false, true);
1603 ARDOUR_UI::transport_roll ()
1609 if (_session->is_auditioning()) {
1614 if (_session->config.get_external_sync()) {
1615 switch (Config->get_sync_source()) {
1619 /* transport controlled by the master */
1625 bool rolling = _session->transport_rolling();
1627 if (_session->get_play_loop()) {
1628 /* XXX it is not possible to just leave seamless loop and keep
1629 playing at present (nov 4th 2009)
1631 if (!Config->get_seamless_loop()) {
1632 _session->request_play_loop (false, true);
1634 } else if (_session->get_play_range () && !Config->get_always_play_range()) {
1635 /* stop playing a range if we currently are */
1636 _session->request_play_range (0, true);
1640 _session->request_transport_speed (1.0f);
1645 ARDOUR_UI::get_smart_mode() const
1647 return ( editor->get_smart_mode() );
1652 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
1659 if (_session->is_auditioning()) {
1660 _session->cancel_audition ();
1664 if (_session->config.get_external_sync()) {
1665 switch (Config->get_sync_source()) {
1669 /* transport controlled by the master */
1674 bool rolling = _session->transport_rolling();
1675 bool affect_transport = true;
1677 if (rolling && roll_out_of_bounded_mode) {
1678 /* drop out of loop/range playback but leave transport rolling */
1679 if (_session->get_play_loop()) {
1680 if (Config->get_seamless_loop()) {
1681 /* the disk buffers contain copies of the loop - we can't
1682 just keep playing, so stop the transport. the user
1683 can restart as they wish.
1685 affect_transport = true;
1687 /* disk buffers are normal, so we can keep playing */
1688 affect_transport = false;
1690 _session->request_play_loop (false, true);
1691 } else if (_session->get_play_range ()) {
1692 affect_transport = false;
1693 _session->request_play_range (0, true);
1697 if (affect_transport) {
1699 _session->request_stop (with_abort, true);
1701 if ( Config->get_always_play_range() ) {
1702 _session->request_play_range (&editor->get_selection().time, true);
1705 _session->request_transport_speed (1.0f);
1711 ARDOUR_UI::toggle_session_auto_loop ()
1713 Location * looploc = _session->locations()->auto_loop_location();
1715 if (!_session || !looploc) {
1719 if (_session->get_play_loop()) {
1721 if (_session->transport_rolling()) {
1723 _session->request_locate (looploc->start(), true);
1724 _session->request_play_loop (false);
1727 _session->request_play_loop (false);
1730 _session->request_play_loop (true);
1733 //show the loop markers
1734 looploc->set_hidden (false, this);
1738 ARDOUR_UI::transport_play_selection ()
1744 editor->play_selection ();
1748 ARDOUR_UI::transport_play_preroll ()
1753 editor->play_with_preroll ();
1757 ARDOUR_UI::transport_rewind (int option)
1759 float current_transport_speed;
1762 current_transport_speed = _session->transport_speed();
1764 if (current_transport_speed >= 0.0f) {
1767 _session->request_transport_speed (-1.0f);
1770 _session->request_transport_speed (-4.0f);
1773 _session->request_transport_speed (-0.5f);
1778 _session->request_transport_speed (current_transport_speed * 1.5f);
1784 ARDOUR_UI::transport_forward (int option)
1790 float current_transport_speed = _session->transport_speed();
1792 if (current_transport_speed <= 0.0f) {
1795 _session->request_transport_speed (1.0f);
1798 _session->request_transport_speed (4.0f);
1801 _session->request_transport_speed (0.5f);
1806 _session->request_transport_speed (current_transport_speed * 1.5f);
1811 ARDOUR_UI::toggle_record_enable (uint32_t rid)
1817 boost::shared_ptr<Route> r;
1819 if ((r = _session->route_by_remote_id (rid)) != 0) {
1823 if ((t = dynamic_cast<Track*>(r.get())) != 0) {
1824 t->set_record_enabled (!t->record_enabled(), this);
1830 ARDOUR_UI::map_transport_state ()
1833 auto_loop_button.unset_active_state ();
1834 play_selection_button.unset_active_state ();
1835 roll_button.unset_active_state ();
1836 stop_button.set_active_state (Gtkmm2ext::ExplicitActive);
1840 shuttle_box->map_transport_state ();
1842 float sp = _session->transport_speed();
1848 if (_session->get_play_range()) {
1850 play_selection_button.set_active_state (Gtkmm2ext::ExplicitActive);
1851 roll_button.unset_active_state ();
1852 auto_loop_button.unset_active_state ();
1854 } else if (_session->get_play_loop ()) {
1856 auto_loop_button.set_active (true);
1857 play_selection_button.set_active (false);
1858 roll_button.set_active (false);
1862 roll_button.set_active (true);
1863 play_selection_button.set_active (false);
1864 auto_loop_button.set_active (false);
1867 if (Config->get_always_play_range()) {
1868 /* light up both roll and play-selection if they are joined */
1869 roll_button.set_active (true);
1870 play_selection_button.set_active (true);
1873 stop_button.set_active (false);
1877 stop_button.set_active (true);
1878 roll_button.set_active (false);
1879 play_selection_button.set_active (false);
1880 auto_loop_button.set_active (false);
1881 update_disk_space ();
1886 ARDOUR_UI::engine_stopped ()
1888 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_stopped)
1889 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, false);
1890 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, true);
1894 ARDOUR_UI::engine_running ()
1896 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_running)
1897 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, true);
1898 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, false);
1900 Glib::RefPtr<Action> action;
1901 const char* action_name = 0;
1903 switch (engine->frames_per_cycle()) {
1905 action_name = X_("JACKLatency32");
1908 action_name = X_("JACKLatency64");
1911 action_name = X_("JACKLatency128");
1914 action_name = X_("JACKLatency512");
1917 action_name = X_("JACKLatency1024");
1920 action_name = X_("JACKLatency2048");
1923 action_name = X_("JACKLatency4096");
1926 action_name = X_("JACKLatency8192");
1929 /* XXX can we do anything useful ? */
1935 action = ActionManager::get_action (X_("JACK"), action_name);
1938 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (action);
1939 ract->set_active ();
1945 ARDOUR_UI::engine_halted (const char* reason, bool free_reason)
1947 if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
1948 /* we can't rely on the original string continuing to exist when we are called
1949 again in the GUI thread, so make a copy and note that we need to
1952 char *copy = strdup (reason);
1953 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ARDOUR_UI::engine_halted, this, copy, true));
1957 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, false);
1958 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, true);
1960 update_sample_rate (0);
1964 /* if the reason is a non-empty string, it means that the backend was shutdown
1965 rather than just Ardour.
1968 if (strlen (reason)) {
1969 msgstr = string_compose (_("The audio backend (JACK) was shutdown because:\n\n%1"), reason);
1971 msgstr = string_compose (_("\
1972 JACK has either been shutdown or it\n\
1973 disconnected %1 because %1\n\
1974 was not fast enough. Try to restart\n\
1975 JACK, reconnect and save the session."), PROGRAM_NAME);
1978 MessageDialog msg (*editor, msgstr);
1979 pop_back_splash (msg);
1983 free (const_cast<char*> (reason));
1988 ARDOUR_UI::do_engine_start ()
1996 error << _("Unable to start the session running")
2006 ARDOUR_UI::update_clocks ()
2008 if (!editor || !editor->dragging_playhead()) {
2009 Clock (_session->audible_frame(), false, editor->get_preferred_edit_position()); /* EMIT_SIGNAL */
2014 ARDOUR_UI::start_clocking ()
2016 clock_signal_connection = RapidScreenUpdate.connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2020 ARDOUR_UI::stop_clocking ()
2022 clock_signal_connection.disconnect ();
2026 ARDOUR_UI::_blink (void *arg)
2028 ((ARDOUR_UI *) arg)->blink ();
2035 Blink (blink_on = !blink_on); /* EMIT_SIGNAL */
2039 ARDOUR_UI::start_blinking ()
2041 /* Start the blink signal. Everybody with a blinking widget
2042 uses Blink to drive the widget's state.
2045 if (blink_timeout_tag < 0) {
2047 blink_timeout_tag = g_timeout_add (240, _blink, this);
2052 ARDOUR_UI::stop_blinking ()
2054 if (blink_timeout_tag >= 0) {
2055 g_source_remove (blink_timeout_tag);
2056 blink_timeout_tag = -1;
2061 /** Ask the user for the name of a new snapshot and then take it.
2065 ARDOUR_UI::snapshot_session (bool switch_to_it)
2067 ArdourPrompter prompter (true);
2070 prompter.set_name ("Prompter");
2071 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2072 prompter.set_title (_("Take Snapshot"));
2073 prompter.set_prompt (_("Name of new snapshot"));
2075 if (!switch_to_it) {
2078 struct tm local_time;
2081 localtime_r (&n, &local_time);
2082 strftime (timebuf, sizeof(timebuf), "%FT%H.%M.%S", &local_time);
2083 prompter.set_initial_text (timebuf);
2087 switch (prompter.run()) {
2088 case RESPONSE_ACCEPT:
2090 prompter.get_result (snapname);
2092 bool do_save = (snapname.length() != 0);
2095 char illegal = Session::session_name_is_legal(snapname);
2097 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2098 "snapshot names may not contain a '%1' character"), illegal));
2104 vector<std::string> p;
2105 get_state_files_in_directory (_session->session_directory().root_path(), p);
2106 vector<string> n = get_file_names_no_extension (p);
2107 if (find (n.begin(), n.end(), snapname) != n.end()) {
2109 ArdourDialog confirm (_("Confirm Snapshot Overwrite"), true);
2110 Label m (_("A snapshot already exists with that name. Do you want to overwrite it?"));
2111 confirm.get_vbox()->pack_start (m, true, true);
2112 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2113 confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
2114 confirm.show_all ();
2115 switch (confirm.run()) {
2116 case RESPONSE_CANCEL:
2122 save_state (snapname, switch_to_it);
2132 /** Ask the user for a new session name and then rename the session to it.
2136 ARDOUR_UI::rename_session ()
2142 ArdourPrompter prompter (true);
2145 prompter.set_name ("Prompter");
2146 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2147 prompter.set_title (_("Rename Session"));
2148 prompter.set_prompt (_("New session name"));
2151 switch (prompter.run()) {
2152 case RESPONSE_ACCEPT:
2154 prompter.get_result (name);
2156 bool do_rename = (name.length() != 0);
2159 char illegal = Session::session_name_is_legal (name);
2162 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2163 "session names may not contain a '%1' character"), illegal));
2168 switch (_session->rename (name)) {
2170 MessageDialog msg (_("That name is already in use by another directory/folder. Please try again."));
2171 msg.set_position (WIN_POS_MOUSE);
2179 MessageDialog msg (_("Renaming this session failed.\nThings could be seriously messed up at this point"));
2180 msg.set_position (WIN_POS_MOUSE);
2196 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
2198 XMLNode* node = new XMLNode (X_("UI"));
2200 for (list<WindowProxyBase*>::iterator i = _window_proxies.begin(); i != _window_proxies.end(); ++i) {
2201 if (!(*i)->rc_configured()) {
2202 node->add_child_nocopy (*((*i)->get_state ()));
2206 node->add_child_nocopy (gui_object_state->get_state());
2208 _session->add_extra_xml (*node);
2210 save_state_canfail (name, switch_to_it);
2214 ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
2219 if (name.length() == 0) {
2220 name = _session->snap_name();
2223 if ((ret = _session->save_state (name, false, switch_to_it)) != 0) {
2228 save_ardour_state (); /* XXX cannot fail? yeah, right ... */
2233 ARDOUR_UI::primary_clock_value_changed ()
2236 _session->request_locate (primary_clock->current_time ());
2241 ARDOUR_UI::big_clock_value_changed ()
2244 _session->request_locate (big_clock->current_time ());
2249 ARDOUR_UI::secondary_clock_value_changed ()
2252 _session->request_locate (secondary_clock->current_time ());
2257 ARDOUR_UI::transport_rec_enable_blink (bool onoff)
2259 if (_session == 0) {
2263 if (_session->step_editing()) {
2267 Session::RecordState const r = _session->record_status ();
2268 bool const h = _session->have_rec_enabled_track ();
2270 if (r == Session::Enabled || (r == Session::Recording && !h)) {
2272 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2274 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
2276 } else if (r == Session::Recording && h) {
2277 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2279 rec_button.unset_active_state ();
2284 ARDOUR_UI::save_template ()
2286 ArdourPrompter prompter (true);
2289 if (!check_audioengine()) {
2293 prompter.set_name (X_("Prompter"));
2294 prompter.set_title (_("Save Template"));
2295 prompter.set_prompt (_("Name for template:"));
2296 prompter.set_initial_text(_session->name() + _("-template"));
2297 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2299 switch (prompter.run()) {
2300 case RESPONSE_ACCEPT:
2301 prompter.get_result (name);
2303 if (name.length()) {
2304 _session->save_template (name);
2314 ARDOUR_UI::edit_metadata ()
2316 SessionMetadataEditor dialog;
2317 dialog.set_session (_session);
2318 editor->ensure_float (dialog);
2323 ARDOUR_UI::import_metadata ()
2325 SessionMetadataImporter dialog;
2326 dialog.set_session (_session);
2327 editor->ensure_float (dialog);
2332 ARDOUR_UI::ask_about_loading_existing_session (const std::string& session_path)
2334 std::string str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
2336 MessageDialog msg (str,
2338 Gtk::MESSAGE_WARNING,
2339 Gtk::BUTTONS_YES_NO,
2343 msg.set_name (X_("OpenExistingDialog"));
2344 msg.set_title (_("Open Existing Session"));
2345 msg.set_wmclass (X_("existing_session"), PROGRAM_NAME);
2346 msg.set_position (Gtk::WIN_POS_MOUSE);
2347 pop_back_splash (msg);
2349 switch (msg.run()) {
2358 ARDOUR_UI::build_session_from_nsd (const std::string& session_path, const std::string& session_name)
2360 BusProfile bus_profile;
2362 if (Profile->get_sae()) {
2364 bus_profile.master_out_channels = 2;
2365 bus_profile.input_ac = AutoConnectPhysical;
2366 bus_profile.output_ac = AutoConnectMaster;
2367 bus_profile.requested_physical_in = 0; // use all available
2368 bus_profile.requested_physical_out = 0; // use all available
2372 /* get settings from advanced section of NSD */
2374 if (_startup->create_master_bus()) {
2375 bus_profile.master_out_channels = (uint32_t) _startup->master_channel_count();
2377 bus_profile.master_out_channels = 0;
2380 if (_startup->connect_inputs()) {
2381 bus_profile.input_ac = AutoConnectPhysical;
2383 bus_profile.input_ac = AutoConnectOption (0);
2386 bus_profile.output_ac = AutoConnectOption (0);
2388 if (_startup->connect_outputs ()) {
2389 if (_startup->connect_outs_to_master()) {
2390 bus_profile.output_ac = AutoConnectMaster;
2391 } else if (_startup->connect_outs_to_physical()) {
2392 bus_profile.output_ac = AutoConnectPhysical;
2396 bus_profile.requested_physical_in = (uint32_t) _startup->input_limit_count();
2397 bus_profile.requested_physical_out = (uint32_t) _startup->output_limit_count();
2400 if (build_session (session_path, session_name, bus_profile)) {
2408 ARDOUR_UI::idle_load (const std::string& path)
2411 if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
2412 /* /path/to/foo => /path/to/foo, foo */
2413 load_session (path, basename_nosuffix (path));
2415 /* /path/to/foo/foo.ardour => /path/to/foo, foo */
2416 load_session (Glib::path_get_dirname (path), basename_nosuffix (path));
2420 ARDOUR_COMMAND_LINE::session_name = path;
2424 /** @param quit_on_cancel true if exit() should be called if the user clicks `cancel' in the new session dialog */
2426 ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, string load_template)
2428 string session_name;
2429 string session_path;
2430 string template_name;
2432 bool likely_new = false;
2434 /* deal with any existing DIRTY session now, rather than later. don't
2435 * treat a non-dirty session this way, so that it stays visible
2436 * as we bring up the new session dialog.
2439 if (_session && _session->dirty()) {
2440 if (unload_session (false)) {
2441 /* unload cancelled by user */
2444 ARDOUR_COMMAND_LINE::session_name = "";
2447 if (!load_template.empty()) {
2448 should_be_new = true;
2449 template_name = load_template;
2454 if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
2456 /* if they named a specific statefile, use it, otherwise they are
2457 just giving a session folder, and we want to use it as is
2458 to find the session.
2461 string::size_type suffix = ARDOUR_COMMAND_LINE::session_name.find (statefile_suffix);
2463 if (suffix != string::npos) {
2464 session_path = Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name);
2465 session_name = ARDOUR_COMMAND_LINE::session_name.substr (0, suffix);
2466 session_name = Glib::path_get_basename (session_name);
2468 session_path = ARDOUR_COMMAND_LINE::session_name;
2469 session_name = Glib::path_get_basename (ARDOUR_COMMAND_LINE::session_name);
2477 _startup = new ArdourStartup (should_be_new, session_name, session_path, load_template);
2479 if (!_startup->ready_without_display()) {
2480 _startup->present ();
2485 switch (_startup->response()) {
2489 if (quit_on_cancel) {
2496 /* if we run the startup dialog again, offer more than just "new session" */
2498 should_be_new = false;
2500 session_name = _startup->session_name (likely_new);
2502 string::size_type suffix = session_name.find (statefile_suffix);
2504 if (suffix != string::npos) {
2505 session_name = session_name.substr (0, suffix);
2508 /* this shouldn't happen, but we catch it just in case it does */
2510 if (session_name.empty()) {
2514 if (_startup->use_session_template()) {
2515 template_name = _startup->session_template_name();
2516 _session_is_new = true;
2519 if (session_name[0] == G_DIR_SEPARATOR ||
2520 (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == G_DIR_SEPARATOR) ||
2521 (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == G_DIR_SEPARATOR)) {
2523 /* absolute path or cwd-relative path specified for session name: infer session folder
2524 from what was given.
2527 session_path = Glib::path_get_dirname (session_name);
2528 session_name = Glib::path_get_basename (session_name);
2532 session_path = _startup->session_folder();
2534 char illegal = Session::session_name_is_legal (session_name);
2537 MessageDialog msg (*_startup,
2538 string_compose (_("To ensure compatibility with various systems\n"
2539 "session names may not contain a '%1' character"),
2542 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2547 if (create_engine ()) {
2551 if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
2555 std::string existing = Glib::build_filename (session_path, session_name);
2557 if (!ask_about_loading_existing_session (existing)) {
2558 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2563 _session_is_new = false;
2569 pop_back_splash (*_startup);
2574 MessageDialog msg (string_compose (_("There is no existing session at \"%1\""), session_path));
2576 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2580 char illegal = Session::session_name_is_legal(session_name);
2582 pop_back_splash (*_startup);
2583 MessageDialog msg (*_startup, string_compose(_("To ensure compatibility with various systems\n"
2584 "session names may not contain a '%1' character"), illegal));
2586 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2590 _session_is_new = true;
2593 if (likely_new && template_name.empty()) {
2595 ret = build_session_from_nsd (session_path, session_name);
2599 ret = load_session (session_path, session_name, template_name);
2602 /* not connected to the AudioEngine, so quit to avoid an infinite loop */
2606 if (!ARDOUR_COMMAND_LINE::immediate_save.empty()) {
2607 _session->save_state (ARDOUR_COMMAND_LINE::immediate_save, false);
2617 ARDOUR_UI::close_session()
2619 if (!check_audioengine()) {
2623 if (unload_session (true)) {
2627 ARDOUR_COMMAND_LINE::session_name = "";
2629 if (get_session_parameters (true, false)) {
2633 goto_editor_window ();
2636 /** @param snap_name Snapshot name (without .ardour suffix).
2637 * @return -2 if the load failed because we are not connected to the AudioEngine.
2640 ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name, std::string mix_template)
2642 Session *new_session;
2646 session_loaded = false;
2648 if (!check_audioengine()) {
2652 unload_status = unload_session ();
2654 if (unload_status < 0) {
2656 } else if (unload_status > 0) {
2661 loading_message (string_compose (_("Please wait while %1 loads your session"), PROGRAM_NAME));
2664 new_session = new Session (*engine, path, snap_name, 0, mix_template);
2667 /* this one is special */
2669 catch (AudioEngine::PortRegistrationFailure& err) {
2671 MessageDialog msg (err.what(),
2674 Gtk::BUTTONS_CLOSE);
2676 msg.set_title (_("Port Registration Error"));
2677 msg.set_secondary_text (_("Click the Close button to try again."));
2678 msg.set_position (Gtk::WIN_POS_CENTER);
2679 pop_back_splash (msg);
2682 int response = msg.run ();
2687 case RESPONSE_CANCEL:
2697 MessageDialog msg (string_compose(
2698 _("Session \"%1 (snapshot %2)\" did not load successfully"),
2704 msg.set_title (_("Loading Error"));
2705 msg.set_secondary_text (_("Click the Refresh button to try again."));
2706 msg.add_button (Stock::REFRESH, 1);
2707 msg.set_position (Gtk::WIN_POS_CENTER);
2708 pop_back_splash (msg);
2711 int response = msg.run ();
2726 list<string> const u = new_session->unknown_processors ();
2728 MissingPluginDialog d (_session, u);
2733 /* Now the session been created, add the transport controls */
2734 new_session->add_controllable(roll_controllable);
2735 new_session->add_controllable(stop_controllable);
2736 new_session->add_controllable(goto_start_controllable);
2737 new_session->add_controllable(goto_end_controllable);
2738 new_session->add_controllable(auto_loop_controllable);
2739 new_session->add_controllable(play_selection_controllable);
2740 new_session->add_controllable(rec_controllable);
2742 set_session (new_session);
2744 session_loaded = true;
2746 goto_editor_window ();
2749 _session->set_clean ();
2760 ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name, BusProfile& bus_profile)
2762 Session *new_session;
2765 if (!check_audioengine()) {
2769 session_loaded = false;
2771 x = unload_session ();
2779 _session_is_new = true;
2782 new_session = new Session (*engine, path, snap_name, &bus_profile);
2787 MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
2788 pop_back_splash (msg);
2793 /* Give the new session the default GUI state, if such things exist */
2796 n = Config->instant_xml (X_("Editor"));
2798 new_session->add_instant_xml (*n, false);
2800 n = Config->instant_xml (X_("Mixer"));
2802 new_session->add_instant_xml (*n, false);
2805 /* Put the playhead at 0 and scroll fully left */
2806 n = new_session->instant_xml (X_("Editor"));
2808 n->add_property (X_("playhead"), X_("0"));
2809 n->add_property (X_("left-frame"), X_("0"));
2812 set_session (new_session);
2814 session_loaded = true;
2816 new_session->save_state(new_session->name());
2822 ARDOUR_UI::launch_chat ()
2825 open_uri("http://webchat.freenode.net/?channels=ardour-osx");
2827 open_uri("http://webchat.freenode.net/?channels=ardour");
2832 ARDOUR_UI::show_about ()
2836 about->signal_response().connect (sigc::mem_fun (*this, &ARDOUR_UI::about_signal_response));
2839 about->set_transient_for(*editor);
2844 ARDOUR_UI::launch_manual ()
2846 PBD::open_uri("http://ardour.org/flossmanual");
2850 ARDOUR_UI::launch_reference ()
2852 PBD::open_uri ("http://ardour.org/refmanual");
2856 ARDOUR_UI::hide_about ()
2859 about->get_window()->set_cursor ();
2865 ARDOUR_UI::about_signal_response (int /*response*/)
2871 ARDOUR_UI::loading_message (const std::string& msg)
2873 if (ARDOUR_COMMAND_LINE::no_splash) {
2881 splash->message (msg);
2885 ARDOUR_UI::show_splash ()
2889 splash = new Splash;
2899 ARDOUR_UI::hide_splash ()
2906 ARDOUR_UI::display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
2907 const string& plural_msg, const string& singular_msg)
2911 removed = rep.paths.size();
2914 MessageDialog msgd (*editor,
2915 _("No files were ready for clean-up"),
2919 msgd.set_title (_("Clean-up"));
2920 msgd.set_secondary_text (_("If this seems suprising, \n\
2921 check for any existing snapshots.\n\
2922 These may still include regions that\n\
2923 require some unused files to continue to exist."));
2929 ArdourDialog results (_("Clean-up"), true, false);
2931 struct CleanupResultsModelColumns : public Gtk::TreeModel::ColumnRecord {
2932 CleanupResultsModelColumns() {
2936 Gtk::TreeModelColumn<std::string> visible_name;
2937 Gtk::TreeModelColumn<std::string> fullpath;
2941 CleanupResultsModelColumns results_columns;
2942 Glib::RefPtr<Gtk::ListStore> results_model;
2943 Gtk::TreeView results_display;
2945 results_model = ListStore::create (results_columns);
2946 results_display.set_model (results_model);
2947 results_display.append_column (list_title, results_columns.visible_name);
2949 results_display.set_name ("CleanupResultsList");
2950 results_display.set_headers_visible (true);
2951 results_display.set_headers_clickable (false);
2952 results_display.set_reorderable (false);
2954 Gtk::ScrolledWindow list_scroller;
2957 Gtk::HBox dhbox; // the hbox for the image and text
2958 Gtk::HBox ddhbox; // the hbox we eventually pack into the dialog's vbox
2959 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_INFO, Gtk::ICON_SIZE_DIALOG));
2961 dimage->set_alignment(ALIGN_LEFT, ALIGN_TOP);
2963 const string dead_directory = _session->session_directory().dead_path();
2966 %1 - number of files removed
2967 %2 - location of "dead"
2968 %3 - size of files affected
2969 %4 - prefix for "bytes" to produce sensible results (e.g. mega, kilo, giga)
2972 const char* bprefix;
2973 double space_adjusted = 0;
2975 if (rep.space < 1000) {
2977 space_adjusted = rep.space;
2978 } else if (rep.space < 1000000) {
2979 bprefix = _("kilo");
2980 space_adjusted = truncf((float)rep.space / 1000.0);
2981 } else if (rep.space < 1000000 * 1000) {
2982 bprefix = _("mega");
2983 space_adjusted = truncf((float)rep.space / (1000.0 * 1000.0));
2985 bprefix = _("giga");
2986 space_adjusted = truncf((float)rep.space / (1000.0 * 1000 * 1000.0));
2990 txt.set_markup (string_compose (plural_msg, removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
2992 txt.set_markup (string_compose (singular_msg, removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
2995 dhbox.pack_start (*dimage, true, false, 5);
2996 dhbox.pack_start (txt, true, false, 5);
2998 for (vector<string>::iterator i = rep.paths.begin(); i != rep.paths.end(); ++i) {
2999 TreeModel::Row row = *(results_model->append());
3000 row[results_columns.visible_name] = *i;
3001 row[results_columns.fullpath] = *i;
3004 list_scroller.add (results_display);
3005 list_scroller.set_size_request (-1, 150);
3006 list_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
3008 dvbox.pack_start (dhbox, true, false, 5);
3009 dvbox.pack_start (list_scroller, true, false, 5);
3010 ddhbox.pack_start (dvbox, true, false, 5);
3012 results.get_vbox()->pack_start (ddhbox, true, false, 5);
3013 results.add_button (Stock::CLOSE, RESPONSE_CLOSE);
3014 results.set_default_response (RESPONSE_CLOSE);
3015 results.set_position (Gtk::WIN_POS_MOUSE);
3017 results_display.show();
3018 list_scroller.show();
3025 //results.get_vbox()->show();
3026 results.set_resizable (false);
3033 ARDOUR_UI::cleanup ()
3035 if (_session == 0) {
3036 /* shouldn't happen: menu item is insensitive */
3041 MessageDialog checker (_("Are you sure you want to clean-up?"),
3043 Gtk::MESSAGE_QUESTION,
3046 checker.set_title (_("Clean-up"));
3048 checker.set_secondary_text(_("Clean-up is a destructive operation.\n\
3049 ALL undo/redo information will be lost if you clean-up.\n\
3050 Clean-up will move all unused files to a \"dead\" location."));
3052 checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3053 checker.add_button (_("Clean-up"), RESPONSE_ACCEPT);
3054 checker.set_default_response (RESPONSE_CANCEL);
3056 checker.set_name (_("CleanupDialog"));
3057 checker.set_wmclass (X_("ardour_cleanup"), PROGRAM_NAME);
3058 checker.set_position (Gtk::WIN_POS_MOUSE);
3060 switch (checker.run()) {
3061 case RESPONSE_ACCEPT:
3067 ARDOUR::CleanupReport rep;
3069 editor->prepare_for_cleanup ();
3071 /* do not allow flush until a session is reloaded */
3073 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
3075 act->set_sensitive (false);
3078 if (_session->cleanup_sources (rep)) {
3079 editor->finish_cleanup ();
3083 editor->finish_cleanup ();
3086 display_cleanup_results (rep,
3089 The following %1 files were not in use and \n\
3090 have been moved to: %2\n\n\
3091 After a restart of %5\n\n\
3092 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3093 will release an additional %3 %4bytes of disk space.\n"),
3095 The following file was not in use and \n\
3096 has been moved to: %2\n\n\
3097 After a restart of %5\n\n\
3098 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3099 will release an additional %3 %4bytes of disk space.\n"
3105 ARDOUR_UI::flush_trash ()
3107 if (_session == 0) {
3108 /* shouldn't happen: menu item is insensitive */
3112 ARDOUR::CleanupReport rep;
3114 if (_session->cleanup_trash_sources (rep)) {
3118 display_cleanup_results (rep,
3120 _("The following %1 files were deleted from %2,\n\
3121 releasing %3 %4bytes of disk space"),
3122 _("The following file was deleted from %2,\n\
3123 releasing %3 %4bytes of disk space"));
3127 ARDOUR_UI::add_route (Gtk::Window* float_window)
3135 if (add_route_dialog == 0) {
3136 add_route_dialog = new AddRouteDialog (_session);
3137 add_route_dialog->set_position (WIN_POS_MOUSE);
3139 add_route_dialog->set_transient_for (*float_window);
3143 if (add_route_dialog->is_visible()) {
3144 /* we're already doing this */
3148 ResponseType r = (ResponseType) add_route_dialog->run ();
3150 add_route_dialog->hide();
3153 case RESPONSE_ACCEPT:
3160 if ((count = add_route_dialog->count()) <= 0) {
3164 PBD::ScopedConnection idle_connection;
3167 ARDOUR::GUIIdle.connect (idle_connection, MISSING_INVALIDATOR, boost::bind (&Gtkmm2ext::UI::flush_pending, this), gui_context());
3170 string template_path = add_route_dialog->track_template();
3172 if (!template_path.empty()) {
3173 _session->new_route_from_template (count, template_path);
3177 ChanCount input_chan= add_route_dialog->channels ();
3178 ChanCount output_chan;
3179 string name_template = add_route_dialog->name_template ();
3180 PluginInfoPtr instrument = add_route_dialog->requested_instrument ();
3181 RouteGroup* route_group = add_route_dialog->route_group ();
3182 AutoConnectOption oac = Config->get_output_auto_connect();
3184 if (oac & AutoConnectMaster) {
3185 output_chan.set (DataType::AUDIO, (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan.n_audio()));
3186 output_chan.set (DataType::MIDI, 0);
3188 output_chan = input_chan;
3191 /* XXX do something with name template */
3193 switch (add_route_dialog->type_wanted()) {
3194 case AddRouteDialog::AudioTrack:
3195 session_add_audio_track (input_chan.n_audio(), output_chan.n_audio(), add_route_dialog->mode(), route_group, count, name_template);
3197 case AddRouteDialog::MidiTrack:
3198 session_add_midi_track (route_group, count, name_template, instrument);
3200 case AddRouteDialog::MixedTrack:
3201 session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, instrument);
3203 case AddRouteDialog::AudioBus:
3204 session_add_audio_bus (input_chan.n_audio(), output_chan.n_audio(), route_group, count, name_template);
3208 /* idle connection will end at scope end */
3212 ARDOUR_UI::mixer_settings () const
3217 node = _session->instant_xml(X_("Mixer"));
3219 node = Config->instant_xml(X_("Mixer"));
3223 node = new XMLNode (X_("Mixer"));
3230 ARDOUR_UI::editor_settings () const
3235 node = _session->instant_xml(X_("Editor"));
3237 node = Config->instant_xml(X_("Editor"));
3241 if (getenv("ARDOUR_INSTANT_XML_PATH")) {
3242 node = Config->instant_xml(getenv("ARDOUR_INSTANT_XML_PATH"));
3247 node = new XMLNode (X_("Editor"));
3254 ARDOUR_UI::keyboard_settings () const
3258 node = Config->extra_xml(X_("Keyboard"));
3261 node = new XMLNode (X_("Keyboard"));
3268 ARDOUR_UI::create_xrun_marker (framepos_t where)
3270 editor->mouse_add_new_marker (where, false, true);
3274 ARDOUR_UI::halt_on_xrun_message ()
3276 MessageDialog msg (*editor,
3277 _("Recording was stopped because your system could not keep up."));
3282 ARDOUR_UI::xrun_handler (framepos_t where)
3288 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::xrun_handler, where)
3290 if (_session && Config->get_create_xrun_marker() && _session->actively_recording()) {
3291 create_xrun_marker(where);
3294 if (_session && Config->get_stop_recording_on_xrun() && _session->actively_recording()) {
3295 halt_on_xrun_message ();
3300 ARDOUR_UI::disk_overrun_handler ()
3302 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_overrun_handler)
3304 if (!have_disk_speed_dialog_displayed) {
3305 have_disk_speed_dialog_displayed = true;
3306 MessageDialog* msg = new MessageDialog (*editor, string_compose (_("\
3307 The disk system on your computer\n\
3308 was not able to keep up with %1.\n\
3310 Specifically, it failed to write data to disk\n\
3311 quickly enough to keep up with recording.\n"), PROGRAM_NAME));
3312 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3318 ARDOUR_UI::disk_underrun_handler ()
3320 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_underrun_handler)
3322 if (!have_disk_speed_dialog_displayed) {
3323 have_disk_speed_dialog_displayed = true;
3324 MessageDialog* msg = new MessageDialog (
3325 *editor, string_compose (_("The disk system on your computer\n\
3326 was not able to keep up with %1.\n\
3328 Specifically, it failed to read data from disk\n\
3329 quickly enough to keep up with playback.\n"), PROGRAM_NAME));
3330 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3336 ARDOUR_UI::disk_speed_dialog_gone (int /*ignored_response*/, MessageDialog* msg)
3338 have_disk_speed_dialog_displayed = false;
3343 ARDOUR_UI::session_dialog (std::string msg)
3345 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::session_dialog, msg)
3350 d = new MessageDialog (*editor, msg, false, MESSAGE_INFO, BUTTONS_OK, true);
3352 d = new MessageDialog (msg, false, MESSAGE_INFO, BUTTONS_OK, true);
3361 ARDOUR_UI::pending_state_dialog ()
3363 HBox* hbox = new HBox();
3364 Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
3365 ArdourDialog dialog (_("Crash Recovery"), true);
3366 Label message (string_compose (_("\
3367 This session appears to have been in\n\
3368 middle of recording when ardour or\n\
3369 the computer was shutdown.\n\
3371 %1 can recover any captured audio for\n\
3372 you, or it can ignore it. Please decide\n\
3373 what you would like to do.\n"), PROGRAM_NAME));
3374 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
3375 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
3376 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
3377 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
3378 dialog.add_button (_("Ignore crash data"), RESPONSE_REJECT);
3379 dialog.add_button (_("Recover from crash"), RESPONSE_ACCEPT);
3380 dialog.set_default_response (RESPONSE_ACCEPT);
3381 dialog.set_position (WIN_POS_CENTER);
3386 switch (dialog.run ()) {
3387 case RESPONSE_ACCEPT:
3395 ARDOUR_UI::sr_mismatch_dialog (framecnt_t desired, framecnt_t actual)
3397 HBox* hbox = new HBox();
3398 Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
3399 ArdourDialog dialog (_("Sample Rate Mismatch"), true);
3400 Label message (string_compose (_("\
3401 This session was created with a sample rate of %1 Hz, but\n\
3402 %2 is currently running at %3 Hz. If you load this session,\n\
3403 audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual));
3405 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
3406 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
3407 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
3408 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
3409 dialog.add_button (_("Do not load session"), RESPONSE_REJECT);
3410 dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT);
3411 dialog.set_default_response (RESPONSE_ACCEPT);
3412 dialog.set_position (WIN_POS_CENTER);
3417 switch (dialog.run ()) {
3418 case RESPONSE_ACCEPT:
3427 ARDOUR_UI::disconnect_from_jack ()
3430 if (engine->disconnect_from_jack ()) {
3431 MessageDialog msg (*editor, _("Could not disconnect from JACK"));
3435 update_sample_rate (0);
3440 ARDOUR_UI::reconnect_to_jack ()
3443 if (engine->reconnect_to_jack ()) {
3444 MessageDialog msg (*editor, _("Could not reconnect to JACK"));
3448 update_sample_rate (0);
3453 ARDOUR_UI::use_config ()
3455 XMLNode* node = Config->extra_xml (X_("TransportControllables"));
3457 set_transport_controllable_state (*node);
3462 ARDOUR_UI::update_transport_clocks (framepos_t pos)
3464 if (Config->get_primary_clock_delta_edit_cursor()) {
3465 primary_clock->set (pos, false, editor->get_preferred_edit_position());
3467 primary_clock->set (pos);
3470 if (Config->get_secondary_clock_delta_edit_cursor()) {
3471 secondary_clock->set (pos, false, editor->get_preferred_edit_position());
3473 secondary_clock->set (pos);
3476 if (big_clock_window->get()) {
3477 big_clock->set (pos);
3483 ARDOUR_UI::step_edit_status_change (bool yn)
3485 // XXX should really store pre-step edit status of things
3486 // we make insensitive
3489 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
3490 rec_button.set_sensitive (false);
3492 rec_button.unset_active_state ();;
3493 rec_button.set_sensitive (true);
3498 ARDOUR_UI::record_state_changed ()
3500 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);
3502 if (!_session || !big_clock_window->get()) {
3503 /* why bother - the clock isn't visible */
3507 if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
3508 big_clock->set_active (true);
3510 big_clock->set_active (false);
3515 ARDOUR_UI::first_idle ()
3518 _session->allow_auto_play (true);
3522 editor->first_idle();
3525 Keyboard::set_can_save_keybindings (true);
3530 ARDOUR_UI::store_clock_modes ()
3532 XMLNode* node = new XMLNode(X_("ClockModes"));
3534 for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
3535 XMLNode* child = new XMLNode (X_("Clock"));
3537 child->add_property (X_("name"), (*x)->name());
3538 child->add_property (X_("mode"), enum_2_string ((*x)->mode()));
3539 child->add_property (X_("on"), ((*x)->off() ? X_("no") : X_("yes")));
3541 node->add_child_nocopy (*child);
3544 _session->add_extra_xml (*node);
3545 _session->set_dirty ();
3548 ARDOUR_UI::TransportControllable::TransportControllable (std::string name, ARDOUR_UI& u, ToggleType tp)
3549 : Controllable (name), ui (u), type(tp)
3555 ARDOUR_UI::TransportControllable::set_value (double val)
3558 /* do nothing: these are radio-style actions */
3562 const char *action = 0;
3566 action = X_("Roll");
3569 action = X_("Stop");
3572 action = X_("GotoStart");
3575 action = X_("GotoEnd");
3578 action = X_("Loop");
3581 action = X_("PlaySelection");
3584 action = X_("Record");
3594 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", action);
3602 ARDOUR_UI::TransportControllable::get_value (void) const
3629 ARDOUR_UI::setup_profile ()
3631 if (gdk_screen_width() < 1200 || getenv ("ARDOUR_NARROW_SCREEN")) {
3632 Profile->set_small_screen ();
3635 if (getenv ("ARDOUR_SAE")) {
3636 Profile->set_sae ();
3637 Profile->set_single_package ();
3642 ARDOUR_UI::toggle_translations ()
3644 using namespace Glib;
3646 RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("EnableTranslation"));
3648 RefPtr<ToggleAction> ract = RefPtr<ToggleAction>::cast_dynamic (act);
3651 string i18n_killer = ARDOUR::translation_kill_path();
3653 bool already_enabled = !ARDOUR::translations_are_disabled ();
3655 if (ract->get_active ()) {
3656 /* we don't care about errors */
3657 int fd = ::open (i18n_killer.c_str(), O_RDONLY|O_CREAT, 0644);
3660 /* we don't care about errors */
3661 unlink (i18n_killer.c_str());
3664 if (already_enabled != ract->get_active()) {
3665 MessageDialog win (already_enabled ? _("Translations disabled") : _("Translations enabled"),
3667 Gtk::MESSAGE_WARNING,
3669 win.set_secondary_text (string_compose (_("You must restart %1 for this to take effect."), PROGRAM_NAME));
3670 win.set_position (Gtk::WIN_POS_CENTER);
3678 /** Add a window proxy to our list, so that its state will be saved.
3679 * This call also causes the window to be created and opened if its
3680 * state was saved as `visible'.
3683 ARDOUR_UI::add_window_proxy (WindowProxyBase* p)
3685 _window_proxies.push_back (p);
3689 /** Remove a window proxy from our list. Must be called if a WindowProxy
3690 * is deleted, to prevent hanging pointers.
3693 ARDOUR_UI::remove_window_proxy (WindowProxyBase* p)
3695 _window_proxies.remove (p);
3699 ARDOUR_UI::missing_file (Session*s, std::string str, DataType type)
3701 MissingFileDialog dialog (s, str, type);
3706 int result = dialog.run ();
3713 return 1; // quit entire session load
3716 result = dialog.get_action ();
3722 ARDOUR_UI::ambiguous_file (std::string file, std::string /*path*/, std::vector<std::string> hits)
3724 AmbiguousFileDialog dialog (file, hits);
3730 return dialog.get_which ();
3733 /** Allocate our thread-local buffers */
3735 ARDOUR_UI::get_process_buffers ()
3737 _process_thread->get_buffers ();
3740 /** Drop our thread-local buffers */
3742 ARDOUR_UI::drop_process_buffers ()
3744 _process_thread->drop_buffers ();
3748 ARDOUR_UI::feedback_detected ()
3750 _feedback_exists = true;
3754 ARDOUR_UI::successful_graph_sort ()
3756 _feedback_exists = false;
3760 ARDOUR_UI::midi_panic ()
3763 _session->midi_panic();