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>
39 #include <gtkmm/messagedialog.h>
40 #include <gtkmm/accelmap.h>
42 #include "pbd/error.h"
43 #include "pbd/basename.h"
44 #include "pbd/compose.h"
45 #include "pbd/failed_constructor.h"
46 #include "pbd/enumwriter.h"
47 #include "pbd/memento_command.h"
48 #include "pbd/openuri.h"
49 #include "pbd/file_utils.h"
51 #include "gtkmm2ext/application.h"
52 #include "gtkmm2ext/bindings.h"
53 #include "gtkmm2ext/gtk_ui.h"
54 #include "gtkmm2ext/utils.h"
55 #include "gtkmm2ext/click_box.h"
56 #include "gtkmm2ext/fastmeter.h"
57 #include "gtkmm2ext/popup.h"
58 #include "gtkmm2ext/window_title.h"
60 #include "midi++/manager.h"
62 #include "ardour/ardour.h"
63 #include "ardour/audioengine.h"
64 #include "ardour/audiofilesource.h"
65 #include "ardour/automation_watch.h"
66 #include "ardour/diskstream.h"
67 #include "ardour/filename_extensions.h"
68 #include "ardour/port.h"
69 #include "ardour/process_thread.h"
70 #include "ardour/profile.h"
71 #include "ardour/recent_sessions.h"
72 #include "ardour/session_directory.h"
73 #include "ardour/session_route.h"
74 #include "ardour/session_state_utils.h"
75 #include "ardour/session_utils.h"
77 typedef uint64_t microseconds_t;
81 #include "add_route_dialog.h"
82 #include "ambiguous_file_dialog.h"
83 #include "ardour_ui.h"
84 #include "audio_clock.h"
85 #include "bundle_manager.h"
86 #include "engine_dialog.h"
87 #include "gain_meter.h"
88 #include "global_port_matrix.h"
89 #include "gui_object.h"
90 #include "gui_thread.h"
92 #include "location_ui.h"
93 #include "main_clock.h"
94 #include "missing_file_dialog.h"
95 #include "missing_plugin_dialog.h"
98 #include "processor_box.h"
100 #include "public_editor.h"
101 #include "route_time_axis.h"
102 #include "session_metadata_dialog.h"
103 #include "shuttle_control.h"
104 #include "speaker_dialog.h"
107 #include "theme_manager.h"
108 #include "time_axis_view_item.h"
110 #include "window_proxy.h"
114 using namespace ARDOUR;
116 using namespace Gtkmm2ext;
120 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
121 UIConfiguration *ARDOUR_UI::ui_config = 0;
123 sigc::signal<void,bool> ARDOUR_UI::Blink;
124 sigc::signal<void> ARDOUR_UI::RapidScreenUpdate;
125 sigc::signal<void> ARDOUR_UI::SuperRapidScreenUpdate;
126 sigc::signal<void, framepos_t, bool, framepos_t> ARDOUR_UI::Clock;
128 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
130 : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
132 , gui_object_state (new GUIObjectState)
133 , primary_clock (new MainClock (X_("primary"), false, X_("transport"), true, true, true, false, true))
134 , secondary_clock (new MainClock (X_("secondary"), false, X_("secondary"), true, true, false, false, true))
138 , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
142 , roll_controllable (new TransportControllable ("transport roll", *this, TransportControllable::Roll))
143 , stop_controllable (new TransportControllable ("transport stop", *this, TransportControllable::Stop))
144 , goto_start_controllable (new TransportControllable ("transport goto start", *this, TransportControllable::GotoStart))
145 , goto_end_controllable (new TransportControllable ("transport goto end", *this, TransportControllable::GotoEnd))
146 , auto_loop_controllable (new TransportControllable ("transport auto loop", *this, TransportControllable::AutoLoop))
147 , play_selection_controllable (new TransportControllable ("transport play selection", *this, TransportControllable::PlaySelection))
148 , rec_controllable (new TransportControllable ("transport rec-enable", *this, TransportControllable::RecordEnable))
150 , auto_return_button (ArdourButton::led_default_elements)
151 , auto_play_button (ArdourButton::led_default_elements)
152 , auto_input_button (ArdourButton::led_default_elements)
154 , auditioning_alert_button (_("audition"))
155 , solo_alert_button (_("solo"))
156 , feedback_alert_button (_("feedback"))
158 , error_log_button (_("Errors"))
160 , _status_bar_visibility (X_("status-bar"))
161 , _feedback_exists (false)
170 if (theArdourUI == 0) {
174 ui_config = new UIConfiguration();
175 theme_manager = new ThemeManager();
183 _session_is_new = false;
184 big_clock_window = 0;
185 big_clock_height = 0;
186 big_clock_resize_in_progress = false;
187 session_selector_window = 0;
188 last_key_press_time = 0;
189 add_route_dialog = 0;
192 rc_option_editor = 0;
193 session_option_editor = 0;
195 open_session_selector = 0;
196 have_configure_timeout = false;
197 have_disk_speed_dialog_displayed = false;
198 session_loaded = false;
199 ignore_dual_punch = false;
200 original_big_clock_width = -1;
201 original_big_clock_height = -1;
202 original_big_clock_font_size = 0;
204 roll_button.set_elements (ArdourButton::Element (ArdourButton::Body|ArdourButton::Text));
205 play_selection_button.set_elements (ArdourButton::Element (ArdourButton::Body|ArdourButton::Text));
207 roll_button.set_controllable (roll_controllable);
208 stop_button.set_controllable (stop_controllable);
209 goto_start_button.set_controllable (goto_start_controllable);
210 goto_end_button.set_controllable (goto_end_controllable);
211 auto_loop_button.set_controllable (auto_loop_controllable);
212 play_selection_button.set_controllable (play_selection_controllable);
213 rec_button.set_controllable (rec_controllable);
215 roll_button.set_name ("transport button");
216 stop_button.set_name ("transport button");
217 goto_start_button.set_name ("transport button");
218 goto_end_button.set_name ("transport button");
219 auto_loop_button.set_name ("transport button");
220 play_selection_button.set_name ("transport button");
221 rec_button.set_name ("transport recenable button");
222 midi_panic_button.set_name ("transport button");
224 goto_start_button.set_tweaks (ArdourButton::ShowClick);
225 goto_end_button.set_tweaks (ArdourButton::ShowClick);
226 midi_panic_button.set_tweaks (ArdourButton::ShowClick);
228 last_configure_time= 0;
231 ARDOUR::Diskstream::DiskOverrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
232 ARDOUR::Diskstream::DiskUnderrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
234 /* handle dialog requests */
236 ARDOUR::Session::Dialog.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_dialog, this, _1), gui_context());
238 /* handle pending state with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
240 ARDOUR::Session::AskAboutPendingState.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::pending_state_dialog, this));
242 /* handle sr mismatch with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
244 ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
246 /* handle requests to quit (coming from JACK session) */
248 ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
250 /* tell the user about feedback */
252 ARDOUR::Session::FeedbackDetected.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::feedback_detected, this), gui_context ());
253 ARDOUR::Session::SuccessfulGraphSort.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::successful_graph_sort, this), gui_context ());
255 /* handle requests to deal with missing files */
257 ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3));
259 /* and ambiguous files */
261 ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2, _3));
263 /* lets get this party started */
266 if (ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization)) {
267 throw failed_constructor ();
270 setup_gtk_ardour_enums ();
273 GainMeter::setup_slider_pix ();
274 RouteTimeAxisView::setup_slider_pix ();
275 ProcessorEntry::setup_slider_pix ();
276 SessionEvent::create_per_thread_pool ("GUI", 512);
278 } catch (failed_constructor& err) {
279 error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg;
284 /* we like keyboards */
286 keyboard = new ArdourKeyboard(*this);
288 XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
290 keyboard->set_state (*node, Stateful::loading_state_version);
293 /* we don't like certain modifiers */
294 Bindings::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK);
298 TimeAxisViewItem::set_constant_heights ();
300 /* The following must happen after ARDOUR::init() so that Config is set up */
302 location_ui = new ActionWindowProxy<LocationUIWindow> (X_("locations"), Config->extra_xml (X_("UI")), X_("ToggleLocations"));
303 big_clock_window = new ActionWindowProxy<Gtk::Window> (X_("bigclock"), Config->extra_xml (X_("UI")), X_("ToggleBigClock"));
304 speaker_config_window = new ActionWindowProxy<SpeakerDialog> (X_("speakerconf"), Config->extra_xml (X_("UI")), X_("toggle-speaker-config"));
306 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
307 _global_port_matrix[*i] = new ActionWindowProxy<GlobalPortMatrixWindow> (
308 string_compose ("GlobalPortMatrix-%1", (*i).to_string()),
309 Config->extra_xml (X_("UI")),
310 string_compose ("toggle-%1-connection-manager", (*i).to_string())
316 SpeakerDialog* s = new SpeakerDialog ();
317 s->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/toggle-speaker-config")));
318 speaker_config_window->set (s);
320 starting.connect (sigc::mem_fun(*this, &ARDOUR_UI::startup));
321 stopping.connect (sigc::mem_fun(*this, &ARDOUR_UI::shutdown));
323 _process_thread = new ProcessThread ();
324 _process_thread->init ();
326 DPIReset.connect (sigc::mem_fun (*this, &ARDOUR_UI::resize_text_widgets));
329 /** @return true if a session was chosen and `apply' clicked, otherwise false if `cancel' was clicked */
331 ARDOUR_UI::run_startup (bool should_be_new, std::string load_template)
334 _startup = new ArdourStartup ();
336 XMLNode* audio_setup = Config->extra_xml ("AudioSetup");
338 if (audio_setup && _startup->engine_control()) {
339 _startup->engine_control()->set_state (*audio_setup);
342 _startup->set_new_only (should_be_new);
343 if (!load_template.empty()) {
344 _startup->set_load_template (load_template);
346 _startup->present ();
352 switch (_startup->response()) {
361 ARDOUR_UI::create_engine ()
363 // this gets called every time by new_session()
369 loading_message (_("Starting audio engine"));
372 engine = new ARDOUR::AudioEngine (ARDOUR_COMMAND_LINE::jack_client_name, ARDOUR_COMMAND_LINE::jack_session_uuid);
379 engine->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
380 engine->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context());
381 engine->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
383 engine->Halted.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
385 ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
393 ARDOUR_UI::post_engine ()
395 /* Things to be done once we create the AudioEngine
398 ARDOUR::init_post_engine ();
400 /* load up the UI manager */
402 ActionManager::init ();
406 if (setup_windows ()) {
407 throw failed_constructor ();
410 /* Do this after setup_windows (), as that's when the _status_bar_visibility is created */
411 XMLNode* n = Config->extra_xml (X_("UI"));
413 _status_bar_visibility.set_state (*n);
416 check_memory_locking();
418 /* this is the first point at which all the keybindings are available */
420 if (ARDOUR_COMMAND_LINE::show_key_actions) {
421 vector<string> names;
422 vector<string> paths;
423 vector<string> tooltips;
425 vector<AccelKey> bindings;
427 ActionManager::get_all_actions (names, paths, tooltips, keys, bindings);
429 vector<string>::iterator n;
430 vector<string>::iterator k;
431 for (n = names.begin(), k = keys.begin(); n != names.end(); ++n, ++k) {
432 cerr << "Action: " << (*n) << " bound to " << (*k) << endl;
438 blink_timeout_tag = -1;
440 /* this being a GUI and all, we want peakfiles */
442 AudioFileSource::set_build_peakfiles (true);
443 AudioFileSource::set_build_missing_peakfiles (true);
445 /* set default clock modes */
447 if (Profile->get_sae()) {
448 primary_clock->set_mode (AudioClock::BBT);
449 secondary_clock->set_mode (AudioClock::MinSec);
451 primary_clock->set_mode (AudioClock::Timecode);
452 secondary_clock->set_mode (AudioClock::BBT);
455 /* start the time-of-day-clock */
458 /* OS X provides a nearly-always visible wallclock, so don't be stupid */
459 update_wall_clock ();
460 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::update_wall_clock), 60000);
463 update_disk_space ();
465 update_sample_rate (engine->frame_rate());
467 Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
468 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
469 Config->map_parameters (pc);
471 /* now start and maybe save state */
473 if (do_engine_start () == 0) {
474 if (_session && _session_is_new) {
475 /* we need to retain initial visual
476 settings for a new session
478 _session->save_state ("");
483 ARDOUR_UI::~ARDOUR_UI ()
488 delete add_route_dialog;
492 ARDOUR_UI::pop_back_splash (Gtk::Window& win)
494 if (Splash::instance()) {
495 Splash::instance()->pop_back_for (win);
500 ARDOUR_UI::configure_timeout ()
502 if (last_configure_time == 0) {
503 /* no configure events yet */
507 /* force a gap of 0.5 seconds since the last configure event
510 if (get_microseconds() - last_configure_time < 500000) {
513 have_configure_timeout = false;
514 save_ardour_state ();
520 ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
522 if (have_configure_timeout) {
523 last_configure_time = get_microseconds();
525 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::configure_timeout), 100);
526 have_configure_timeout = true;
533 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
535 const XMLProperty* prop;
537 if ((prop = node.property ("roll")) != 0) {
538 roll_controllable->set_id (prop->value());
540 if ((prop = node.property ("stop")) != 0) {
541 stop_controllable->set_id (prop->value());
543 if ((prop = node.property ("goto-start")) != 0) {
544 goto_start_controllable->set_id (prop->value());
546 if ((prop = node.property ("goto-end")) != 0) {
547 goto_end_controllable->set_id (prop->value());
549 if ((prop = node.property ("auto-loop")) != 0) {
550 auto_loop_controllable->set_id (prop->value());
552 if ((prop = node.property ("play-selection")) != 0) {
553 play_selection_controllable->set_id (prop->value());
555 if ((prop = node.property ("rec")) != 0) {
556 rec_controllable->set_id (prop->value());
558 if ((prop = node.property ("shuttle")) != 0) {
559 shuttle_box->controllable()->set_id (prop->value());
564 ARDOUR_UI::get_transport_controllable_state ()
566 XMLNode* node = new XMLNode(X_("TransportControllables"));
569 roll_controllable->id().print (buf, sizeof (buf));
570 node->add_property (X_("roll"), buf);
571 stop_controllable->id().print (buf, sizeof (buf));
572 node->add_property (X_("stop"), buf);
573 goto_start_controllable->id().print (buf, sizeof (buf));
574 node->add_property (X_("goto_start"), buf);
575 goto_end_controllable->id().print (buf, sizeof (buf));
576 node->add_property (X_("goto_end"), buf);
577 auto_loop_controllable->id().print (buf, sizeof (buf));
578 node->add_property (X_("auto_loop"), buf);
579 play_selection_controllable->id().print (buf, sizeof (buf));
580 node->add_property (X_("play_selection"), buf);
581 rec_controllable->id().print (buf, sizeof (buf));
582 node->add_property (X_("rec"), buf);
583 shuttle_box->controllable()->id().print (buf, sizeof (buf));
584 node->add_property (X_("shuttle"), buf);
591 ARDOUR_UI::autosave_session ()
593 if (g_main_depth() > 1) {
594 /* inside a recursive main loop,
595 give up because we may not be able to
601 if (!Config->get_periodic_safety_backups()) {
606 _session->maybe_write_autosave();
613 ARDOUR_UI::update_autosave ()
615 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_autosave)
617 if (_session && _session->dirty()) {
618 if (_autosave_connection.connected()) {
619 _autosave_connection.disconnect();
622 _autosave_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &ARDOUR_UI::autosave_session),
623 Config->get_periodic_safety_backup_interval() * 1000);
626 if (_autosave_connection.connected()) {
627 _autosave_connection.disconnect();
633 ARDOUR_UI::startup ()
635 Application* app = Application::instance ();
637 app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish));
638 app->ShouldLoad.connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_load));
641 call_the_mothership (VERSIONSTRING);
646 if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
652 goto_editor_window ();
654 /* Add the window proxies here; their addition may cause windows to be opened, and we want them
655 to be opened on top of the editor window that goto_editor_window() just opened.
657 add_window_proxy (location_ui);
658 add_window_proxy (big_clock_window);
659 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
660 add_window_proxy (_global_port_matrix[*i]);
663 /* We have to do this here since goto_editor_window() ends up calling show_all() on the
664 * editor window, and we may want stuff to be hidden.
666 _status_bar_visibility.update ();
668 BootMessage (string_compose (_("%1 is ready for use"), PROGRAM_NAME));
672 ARDOUR_UI::no_memory_warning ()
674 XMLNode node (X_("no-memory-warning"));
675 Config->add_instant_xml (node);
679 ARDOUR_UI::check_memory_locking ()
682 /* OS X doesn't support mlockall(2), and so testing for memory locking capability there is pointless */
686 XMLNode* memory_warning_node = Config->instant_xml (X_("no-memory-warning"));
688 if (engine->is_realtime() && memory_warning_node == 0) {
690 struct rlimit limits;
692 long pages, page_size;
694 if ((page_size = sysconf (_SC_PAGESIZE)) < 0 ||(pages = sysconf (_SC_PHYS_PAGES)) < 0) {
697 ram = (int64_t) pages * (int64_t) page_size;
700 if (getrlimit (RLIMIT_MEMLOCK, &limits)) {
704 if (limits.rlim_cur != RLIM_INFINITY) {
706 if (ram == 0 || ((double) limits.rlim_cur / ram) < 0.75) {
710 _("WARNING: Your system has a limit for maximum amount of locked memory. "
711 "This might cause %1 to run out of memory before your system "
712 "runs out of memory. \n\n"
713 "You can view the memory limit with 'ulimit -l', "
714 "and it is normally controlled by /etc/security/limits.conf"),
715 PROGRAM_NAME).c_str());
717 VBox* vbox = msg.get_vbox();
719 CheckButton cb (_("Do not show this window again"));
721 cb.signal_toggled().connect (sigc::mem_fun (*this, &ARDOUR_UI::no_memory_warning));
723 hbox.pack_start (cb, true, false);
724 vbox->pack_start (hbox);
729 pop_back_splash (msg);
731 editor->ensure_float (msg);
741 ARDOUR_UI::queue_finish ()
743 Glib::signal_idle().connect (mem_fun (*this, &ARDOUR_UI::idle_finish));
747 ARDOUR_UI::idle_finish ()
750 return false; /* do not call again */
758 if (_session->dirty()) {
759 vector<string> actions;
760 actions.push_back (_("Don't quit"));
761 actions.push_back (_("Just quit"));
762 actions.push_back (_("Save and quit"));
763 switch (ask_about_saving_session(actions)) {
768 /* use the default name */
769 if (save_state_canfail ("")) {
770 /* failed - don't quit */
771 MessageDialog msg (*editor,
773 %1 was unable to save your session.\n\n\
774 If you still wish to quit, please use the\n\n\
775 \"Just quit\" option."), PROGRAM_NAME));
776 pop_back_splash(msg);
786 second_connection.disconnect ();
787 point_one_second_connection.disconnect ();
788 point_oh_five_second_connection.disconnect ();
789 point_zero_one_second_connection.disconnect();
792 /* Save state before deleting the session, as that causes some
793 windows to be destroyed before their visible state can be
796 save_ardour_state ();
798 loading_message (string_compose (_("Please wait while %1 cleans up..."), PROGRAM_NAME));
801 // _session->set_deletion_in_progress ();
802 _session->set_clean ();
803 _session->remove_pending_capture_state ();
808 ArdourDialog::close_all_dialogs ();
814 ARDOUR_UI::ask_about_saving_session (const vector<string>& actions)
816 ArdourDialog window (_("Unsaved Session"));
817 Gtk::HBox dhbox; // the hbox for the image and text
818 Gtk::Label prompt_label;
819 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_WARNING, Gtk::ICON_SIZE_DIALOG));
823 assert (actions.size() >= 3);
825 window.add_button (actions[0], RESPONSE_REJECT);
826 window.add_button (actions[1], RESPONSE_APPLY);
827 window.add_button (actions[2], RESPONSE_ACCEPT);
829 window.set_default_response (RESPONSE_ACCEPT);
831 Gtk::Button noquit_button (msg);
832 noquit_button.set_name ("EditorGTKButton");
836 if (_session->snap_name() == _session->name()) {
837 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?"),
838 _session->snap_name());
840 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?"),
841 _session->snap_name());
844 prompt_label.set_text (prompt);
845 prompt_label.set_name (X_("PrompterLabel"));
846 prompt_label.set_alignment(ALIGN_LEFT, ALIGN_TOP);
848 dimage->set_alignment(ALIGN_CENTER, ALIGN_TOP);
849 dhbox.set_homogeneous (false);
850 dhbox.pack_start (*dimage, false, false, 5);
851 dhbox.pack_start (prompt_label, true, false, 5);
852 window.get_vbox()->pack_start (dhbox);
854 window.set_name (_("Prompter"));
855 window.set_position (Gtk::WIN_POS_MOUSE);
856 window.set_modal (true);
857 window.set_resizable (false);
863 window.set_keep_above (true);
866 ResponseType r = (ResponseType) window.run();
871 case RESPONSE_ACCEPT: // save and get out of here
873 case RESPONSE_APPLY: // get out of here
884 ARDOUR_UI::every_second ()
887 update_buffer_load ();
888 update_disk_space ();
893 ARDOUR_UI::every_point_one_seconds ()
895 shuttle_box->update_speed_display ();
896 RapidScreenUpdate(); /* EMIT_SIGNAL */
901 ARDOUR_UI::every_point_zero_one_seconds ()
903 // august 2007: actual update frequency: 40Hz, not 100Hz
905 SuperRapidScreenUpdate(); /* EMIT_SIGNAL */
910 ARDOUR_UI::update_sample_rate (framecnt_t)
914 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
916 if (!engine->connected()) {
918 snprintf (buf, sizeof (buf), "%s", _("disconnected"));
922 framecnt_t rate = engine->frame_rate();
924 if (fmod (rate, 1000.0) != 0.0) {
925 snprintf (buf, sizeof (buf), _("JACK: <span foreground=\"green\">%.1f kHz / %4.1f ms</span>"),
926 (float) rate/1000.0f,
927 (engine->frames_per_cycle() / (float) rate) * 1000.0f);
929 snprintf (buf, sizeof (buf), _("JACK: <span foreground=\"green\">%" PRId64 " kHz / %4.1f ms</span>"),
931 (engine->frames_per_cycle() / (float) rate) * 1000.0f);
935 sample_rate_label.set_markup (buf);
939 ARDOUR_UI::update_format ()
942 format_label.set_text ("");
947 s << _("File:") << X_(" <span foreground=\"green\">");
949 switch (_session->config.get_native_file_header_format ()) {
975 switch (_session->config.get_native_file_data_format ()) {
989 format_label.set_markup (s.str ());
993 ARDOUR_UI::update_cpu_load ()
997 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
998 should also be changed.
1001 float const c = engine->get_cpu_load ();
1002 snprintf (buf, sizeof (buf), _("DSP: <span foreground=\"%s\">%5.1f%%</span>"), c >= 90 ? X_("red") : X_("green"), c);
1003 cpu_load_label.set_markup (buf);
1007 ARDOUR_UI::update_buffer_load ()
1011 uint32_t const playback = _session ? _session->playback_load () : 100;
1012 uint32_t const capture = _session ? _session->capture_load () : 100;
1014 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1015 should also be changed.
1021 _("Buffers: <span foreground=\"green\">p:</span><span foreground=\"%s\">%" PRIu32 "%%</span> "
1022 "<span foreground=\"green\">c:</span><span foreground=\"%s\">%" PRIu32 "%%</span>"),
1023 playback <= 5 ? X_("red") : X_("green"),
1025 capture <= 5 ? X_("red") : X_("green"),
1029 buffer_load_label.set_markup (buf);
1031 buffer_load_label.set_text ("");
1036 ARDOUR_UI::count_recenabled_streams (Route& route)
1038 Track* track = dynamic_cast<Track*>(&route);
1039 if (track && track->record_enabled()) {
1040 rec_enabled_streams += track->n_inputs().n_total();
1045 ARDOUR_UI::update_disk_space()
1047 if (_session == 0) {
1051 boost::optional<framecnt_t> opt_frames = _session->available_capture_duration();
1053 framecnt_t fr = _session->frame_rate();
1056 /* Available space is unknown */
1057 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">Unknown</span>"));
1058 } else if (opt_frames.get_value_or (0) == max_framecnt) {
1059 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">24hrs+</span>"));
1061 rec_enabled_streams = 0;
1062 _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams);
1064 framecnt_t frames = opt_frames.get_value_or (0);
1066 if (rec_enabled_streams) {
1067 frames /= rec_enabled_streams;
1074 hrs = frames / (fr * 3600);
1077 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">>24 hrs</span>"));
1079 frames -= hrs * fr * 3600;
1080 mins = frames / (fr * 60);
1081 frames -= mins * fr * 60;
1084 bool const low = (hrs == 0 && mins <= 30);
1088 _("Disk: <span foreground=\"%s\">%02dh:%02dm:%02ds</span>"),
1089 low ? X_("red") : X_("green"),
1095 disk_space_label.set_markup (buf);
1099 ARDOUR_UI::update_wall_clock ()
1106 tm_now = localtime (&now);
1108 sprintf (buf, "%02d:%02d", tm_now->tm_hour, tm_now->tm_min);
1109 wall_clock_label.set_text (buf);
1115 ARDOUR_UI::redisplay_recent_sessions ()
1117 std::vector<std::string> session_directories;
1118 RecentSessionsSorter cmp;
1120 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
1121 recent_session_model->clear ();
1123 ARDOUR::RecentSessions rs;
1124 ARDOUR::read_recent_sessions (rs);
1127 recent_session_display.set_model (recent_session_model);
1131 // sort them alphabetically
1132 sort (rs.begin(), rs.end(), cmp);
1134 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
1135 session_directories.push_back ((*i).second);
1138 for (vector<std::string>::const_iterator i = session_directories.begin();
1139 i != session_directories.end(); ++i)
1141 std::vector<std::string> state_file_paths;
1143 // now get available states for this session
1145 get_state_files_in_directory (*i, state_file_paths);
1147 vector<string*>* states;
1148 vector<const gchar*> item;
1149 string fullpath = *i;
1151 /* remove any trailing / */
1153 if (fullpath[fullpath.length() - 1] == '/') {
1154 fullpath = fullpath.substr (0, fullpath.length() - 1);
1157 /* check whether session still exists */
1158 if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
1159 /* session doesn't exist */
1163 /* now get available states for this session */
1165 if ((states = Session::possible_states (fullpath)) == 0) {
1166 /* no state file? */
1170 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
1172 Gtk::TreeModel::Row row = *(recent_session_model->append());
1174 row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath);
1175 row[recent_session_columns.fullpath] = fullpath;
1177 if (state_file_names.size() > 1) {
1181 for (std::vector<std::string>::iterator i2 = state_file_names.begin();
1182 i2 != state_file_names.end(); ++i2)
1185 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
1187 child_row[recent_session_columns.visible_name] = *i2;
1188 child_row[recent_session_columns.fullpath] = fullpath;
1193 recent_session_display.set_tooltip_column(1); // recent_session_columns.fullpath
1194 recent_session_display.set_model (recent_session_model);
1198 ARDOUR_UI::build_session_selector ()
1200 session_selector_window = new ArdourDialog (_("Recent Sessions"));
1202 Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow);
1204 session_selector_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1205 session_selector_window->add_button (Stock::OPEN, RESPONSE_ACCEPT);
1206 session_selector_window->set_default_response (RESPONSE_ACCEPT);
1207 recent_session_model = TreeStore::create (recent_session_columns);
1208 recent_session_display.set_model (recent_session_model);
1209 recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name);
1210 recent_session_display.set_headers_visible (false);
1211 recent_session_display.get_selection()->set_mode (SELECTION_BROWSE);
1212 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &ARDOUR_UI::recent_session_row_activated));
1214 scroller->add (recent_session_display);
1215 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1217 session_selector_window->set_name ("SessionSelectorWindow");
1218 session_selector_window->set_size_request (200, 400);
1219 session_selector_window->get_vbox()->pack_start (*scroller);
1221 recent_session_display.show();
1226 ARDOUR_UI::recent_session_row_activated (const TreePath& /*path*/, TreeViewColumn* /*col*/)
1228 session_selector_window->response (RESPONSE_ACCEPT);
1232 ARDOUR_UI::open_recent_session ()
1234 bool can_return = (_session != 0);
1236 if (session_selector_window == 0) {
1237 build_session_selector ();
1240 redisplay_recent_sessions ();
1244 session_selector_window->set_position (WIN_POS_MOUSE);
1246 ResponseType r = (ResponseType) session_selector_window->run ();
1249 case RESPONSE_ACCEPT:
1253 session_selector_window->hide();
1260 if (recent_session_display.get_selection()->count_selected_rows() == 0) {
1264 session_selector_window->hide();
1266 Gtk::TreeModel::iterator i = recent_session_display.get_selection()->get_selected();
1268 if (i == recent_session_model->children().end()) {
1272 std::string path = (*i)[recent_session_columns.fullpath];
1273 std::string state = (*i)[recent_session_columns.visible_name];
1275 _session_is_new = false;
1277 if (load_session (path, state) == 0) {
1286 ARDOUR_UI::check_audioengine ()
1289 if (!engine->connected()) {
1290 MessageDialog msg (string_compose (
1291 _("%1 is not connected to JACK\n"
1292 "You cannot open or close sessions in this condition"),
1294 pop_back_splash (msg);
1305 ARDOUR_UI::open_session ()
1307 if (!check_audioengine()) {
1312 /* popup selector window */
1314 if (open_session_selector == 0) {
1316 /* ardour sessions are folders */
1318 open_session_selector = new Gtk::FileChooserDialog (_("Open Session"), FILE_CHOOSER_ACTION_OPEN);
1319 open_session_selector->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1320 open_session_selector->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
1321 open_session_selector->set_default_response(Gtk::RESPONSE_ACCEPT);
1324 string session_parent_dir = Glib::path_get_dirname(_session->path());
1325 string::size_type last_dir_sep = session_parent_dir.rfind(G_DIR_SEPARATOR);
1326 session_parent_dir = session_parent_dir.substr(0, last_dir_sep);
1327 open_session_selector->set_current_folder(session_parent_dir);
1329 open_session_selector->set_current_folder(Config->get_default_session_parent_dir());
1332 open_session_selector->add_shortcut_folder (Config->get_default_session_parent_dir());
1334 FileFilter session_filter;
1335 session_filter.add_pattern ("*.ardour");
1336 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
1337 open_session_selector->add_filter (session_filter);
1338 open_session_selector->set_filter (session_filter);
1341 int response = open_session_selector->run();
1342 open_session_selector->hide ();
1345 case RESPONSE_ACCEPT:
1348 open_session_selector->hide();
1352 open_session_selector->hide();
1353 string session_path = open_session_selector->get_filename();
1357 if (session_path.length() > 0) {
1358 if (ARDOUR::find_session (session_path, path, name, isnew) == 0) {
1359 _session_is_new = isnew;
1360 load_session (path, name);
1367 ARDOUR_UI::session_add_mixed_track (const ChanCount& input, const ChanCount& output, RouteGroup* route_group,
1368 uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1370 list<boost::shared_ptr<MidiTrack> > tracks;
1372 if (_session == 0) {
1373 warning << _("You cannot add a track without a session already loaded.") << endmsg;
1378 tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template);
1380 if (tracks.size() != how_many) {
1381 if (how_many == 1) {
1382 error << _("could not create a new mixed track") << endmsg;
1384 error << string_compose (_("could not create %1 new mixed tracks"), how_many) << endmsg;
1390 MessageDialog msg (*editor,
1391 string_compose (_("There are insufficient JACK ports available\n\
1392 to create a new track or bus.\n\
1393 You should save %1, exit and\n\
1394 restart JACK with more ports."), PROGRAM_NAME));
1401 ARDOUR_UI::session_add_midi_route (bool disk, RouteGroup* route_group, uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1403 ChanCount one_midi_channel;
1404 one_midi_channel.set (DataType::MIDI, 1);
1407 session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, instrument);
1412 ARDOUR_UI::session_add_audio_route (
1414 int32_t input_channels,
1415 int32_t output_channels,
1416 ARDOUR::TrackMode mode,
1417 RouteGroup* route_group,
1419 string const & name_template
1422 list<boost::shared_ptr<AudioTrack> > tracks;
1425 if (_session == 0) {
1426 warning << _("You cannot add a track or bus without a session already loaded.") << endmsg;
1432 tracks = _session->new_audio_track (input_channels, output_channels, mode, route_group, how_many, name_template);
1434 if (tracks.size() != how_many) {
1435 if (how_many == 1) {
1436 error << _("could not create a new audio track") << endmsg;
1438 error << string_compose (_("could only create %1 of %2 new audio %3"),
1439 tracks.size(), how_many, (track ? _("tracks") : _("busses"))) << endmsg;
1445 routes = _session->new_audio_route (input_channels, output_channels, route_group, how_many, name_template);
1447 if (routes.size() != how_many) {
1448 if (how_many == 1) {
1449 error << _("could not create a new audio bus") << endmsg;
1451 error << string_compose (_("could not create %1 new audio busses"), how_many) << endmsg;
1458 MessageDialog msg (*editor,
1459 string_compose (_("There are insufficient JACK ports available\n\
1460 to create a new track or bus.\n\
1461 You should save %1, exit and\n\
1462 restart JACK with more ports."), PROGRAM_NAME));
1463 pop_back_splash (msg);
1469 ARDOUR_UI::transport_goto_start ()
1472 _session->goto_start();
1474 /* force displayed area in editor to start no matter
1475 what "follow playhead" setting is.
1479 editor->center_screen (_session->current_start_frame ());
1485 ARDOUR_UI::transport_goto_zero ()
1488 _session->request_locate (0);
1490 /* force displayed area in editor to start no matter
1491 what "follow playhead" setting is.
1495 editor->reset_x_origin (0);
1501 ARDOUR_UI::transport_goto_wallclock ()
1503 if (_session && editor) {
1510 localtime_r (&now, &tmnow);
1512 frames = tmnow.tm_hour * (60 * 60 * _session->frame_rate());
1513 frames += tmnow.tm_min * (60 * _session->frame_rate());
1514 frames += tmnow.tm_sec * _session->frame_rate();
1516 _session->request_locate (frames, _session->transport_rolling ());
1518 /* force displayed area in editor to start no matter
1519 what "follow playhead" setting is.
1523 editor->center_screen (frames);
1529 ARDOUR_UI::transport_goto_end ()
1532 framepos_t const frame = _session->current_end_frame();
1533 _session->request_locate (frame);
1535 /* force displayed area in editor to start no matter
1536 what "follow playhead" setting is.
1540 editor->center_screen (frame);
1546 ARDOUR_UI::transport_stop ()
1552 if (_session->is_auditioning()) {
1553 _session->cancel_audition ();
1557 _session->request_stop (false, true);
1561 ARDOUR_UI::transport_record (bool roll)
1565 switch (_session->record_status()) {
1566 case Session::Disabled:
1567 if (_session->ntracks() == 0) {
1568 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."));
1572 _session->maybe_enable_record ();
1577 case Session::Recording:
1579 _session->request_stop();
1581 _session->disable_record (false, true);
1585 case Session::Enabled:
1586 _session->disable_record (false, true);
1592 ARDOUR_UI::transport_roll ()
1598 if (_session->is_auditioning()) {
1603 if (_session->config.get_external_sync()) {
1604 switch (_session->config.get_sync_source()) {
1608 /* transport controlled by the master */
1614 bool rolling = _session->transport_rolling();
1616 if (_session->get_play_loop()) {
1617 /* XXX it is not possible to just leave seamless loop and keep
1618 playing at present (nov 4th 2009)
1620 if (!Config->get_seamless_loop()) {
1621 _session->request_play_loop (false, true);
1623 } else if (_session->get_play_range () && !Config->get_always_play_range()) {
1624 /* stop playing a range if we currently are */
1625 _session->request_play_range (0, true);
1628 if (Config->get_always_play_range()) {
1629 _session->request_play_range (&editor->get_selection().time, true);
1633 _session->request_transport_speed (1.0f);
1638 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
1645 if (_session->is_auditioning()) {
1646 _session->cancel_audition ();
1650 if (_session->config.get_external_sync()) {
1651 switch (_session->config.get_sync_source()) {
1655 /* transport controlled by the master */
1660 bool rolling = _session->transport_rolling();
1661 bool affect_transport = true;
1663 if (rolling && roll_out_of_bounded_mode) {
1664 /* drop out of loop/range playback but leave transport rolling */
1665 if (_session->get_play_loop()) {
1666 if (Config->get_seamless_loop()) {
1667 /* the disk buffers contain copies of the loop - we can't
1668 just keep playing, so stop the transport. the user
1669 can restart as they wish.
1671 affect_transport = true;
1673 /* disk buffers are normal, so we can keep playing */
1674 affect_transport = false;
1676 _session->request_play_loop (false, true);
1677 } else if (_session->get_play_range ()) {
1678 affect_transport = false;
1679 _session->request_play_range (0, true);
1683 if (affect_transport) {
1685 _session->request_stop (with_abort, true);
1687 if (Config->get_always_play_range ()) {
1688 _session->request_play_range (&editor->get_selection().time, true);
1691 _session->request_transport_speed (1.0f);
1697 ARDOUR_UI::toggle_session_auto_loop ()
1699 Location * looploc = _session->locations()->auto_loop_location();
1701 if (!_session || !looploc) {
1705 if (_session->get_play_loop()) {
1707 if (_session->transport_rolling()) {
1709 _session->request_locate (looploc->start(), true);
1710 _session->request_play_loop (false);
1713 _session->request_play_loop (false);
1716 _session->request_play_loop (true);
1719 //show the loop markers
1720 looploc->set_hidden (false, this);
1724 ARDOUR_UI::transport_play_selection ()
1730 editor->play_selection ();
1734 ARDOUR_UI::transport_rewind (int option)
1736 float current_transport_speed;
1739 current_transport_speed = _session->transport_speed();
1741 if (current_transport_speed >= 0.0f) {
1744 _session->request_transport_speed (-1.0f);
1747 _session->request_transport_speed (-4.0f);
1750 _session->request_transport_speed (-0.5f);
1755 _session->request_transport_speed (current_transport_speed * 1.5f);
1761 ARDOUR_UI::transport_forward (int option)
1767 float current_transport_speed = _session->transport_speed();
1769 if (current_transport_speed <= 0.0f) {
1772 _session->request_transport_speed (1.0f);
1775 _session->request_transport_speed (4.0f);
1778 _session->request_transport_speed (0.5f);
1783 _session->request_transport_speed (current_transport_speed * 1.5f);
1788 ARDOUR_UI::toggle_record_enable (uint32_t rid)
1794 boost::shared_ptr<Route> r;
1796 if ((r = _session->route_by_remote_id (rid)) != 0) {
1800 if ((t = dynamic_cast<Track*>(r.get())) != 0) {
1801 t->set_record_enabled (!t->record_enabled(), this);
1807 ARDOUR_UI::map_transport_state ()
1810 auto_loop_button.unset_active_state ();
1811 play_selection_button.unset_active_state ();
1812 roll_button.unset_active_state ();
1813 stop_button.set_active_state (Gtkmm2ext::ExplicitActive);
1817 shuttle_box->map_transport_state ();
1819 float sp = _session->transport_speed();
1825 if (_session->get_play_range()) {
1827 play_selection_button.set_active_state (Gtkmm2ext::ExplicitActive);
1828 roll_button.unset_active_state ();
1829 auto_loop_button.unset_active_state ();
1831 } else if (_session->get_play_loop ()) {
1833 auto_loop_button.set_active (true);
1834 play_selection_button.set_active (false);
1835 roll_button.set_active (false);
1839 roll_button.set_active (true);
1840 play_selection_button.set_active (false);
1841 auto_loop_button.set_active (false);
1844 if (Config->get_always_play_range()) {
1845 /* light up both roll and play-selection if they are joined */
1846 roll_button.set_active (true);
1847 play_selection_button.set_active (true);
1850 stop_button.set_active (false);
1854 stop_button.set_active (true);
1855 roll_button.set_active (false);
1856 play_selection_button.set_active (false);
1857 auto_loop_button.set_active (false);
1858 update_disk_space ();
1863 ARDOUR_UI::engine_stopped ()
1865 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_stopped)
1866 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, false);
1867 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, true);
1871 ARDOUR_UI::engine_running ()
1873 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_running)
1874 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, true);
1875 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, false);
1877 Glib::RefPtr<Action> action;
1878 const char* action_name = 0;
1880 switch (engine->frames_per_cycle()) {
1882 action_name = X_("JACKLatency32");
1885 action_name = X_("JACKLatency64");
1888 action_name = X_("JACKLatency128");
1891 action_name = X_("JACKLatency512");
1894 action_name = X_("JACKLatency1024");
1897 action_name = X_("JACKLatency2048");
1900 action_name = X_("JACKLatency4096");
1903 action_name = X_("JACKLatency8192");
1906 /* XXX can we do anything useful ? */
1912 action = ActionManager::get_action (X_("JACK"), action_name);
1915 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (action);
1916 ract->set_active ();
1922 ARDOUR_UI::engine_halted (const char* reason, bool free_reason)
1924 if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
1925 /* we can't rely on the original string continuing to exist when we are called
1926 again in the GUI thread, so make a copy and note that we need to
1929 char *copy = strdup (reason);
1930 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ARDOUR_UI::engine_halted, this, copy, true));
1934 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, false);
1935 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, true);
1937 update_sample_rate (0);
1941 /* if the reason is a non-empty string, it means that the backend was shutdown
1942 rather than just Ardour.
1945 if (strlen (reason)) {
1946 msgstr = string_compose (_("The audio backend (JACK) was shutdown because:\n\n%1"), reason);
1948 msgstr = string_compose (_("\
1949 JACK has either been shutdown or it\n\
1950 disconnected %1 because %1\n\
1951 was not fast enough. Try to restart\n\
1952 JACK, reconnect and save the session."), PROGRAM_NAME);
1955 MessageDialog msg (*editor, msgstr);
1956 pop_back_splash (msg);
1960 free (const_cast<char*> (reason));
1965 ARDOUR_UI::do_engine_start ()
1973 error << _("Unable to start the session running")
1983 ARDOUR_UI::update_clocks ()
1985 if (!editor || !editor->dragging_playhead()) {
1986 Clock (_session->audible_frame(), false, editor->get_preferred_edit_position()); /* EMIT_SIGNAL */
1991 ARDOUR_UI::start_clocking ()
1993 clock_signal_connection = RapidScreenUpdate.connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
1997 ARDOUR_UI::stop_clocking ()
1999 clock_signal_connection.disconnect ();
2003 ARDOUR_UI::_blink (void *arg)
2005 ((ARDOUR_UI *) arg)->blink ();
2012 Blink (blink_on = !blink_on); /* EMIT_SIGNAL */
2016 ARDOUR_UI::start_blinking ()
2018 /* Start the blink signal. Everybody with a blinking widget
2019 uses Blink to drive the widget's state.
2022 if (blink_timeout_tag < 0) {
2024 blink_timeout_tag = g_timeout_add (240, _blink, this);
2029 ARDOUR_UI::stop_blinking ()
2031 if (blink_timeout_tag >= 0) {
2032 g_source_remove (blink_timeout_tag);
2033 blink_timeout_tag = -1;
2038 /** Ask the user for the name of a new snapshot and then take it.
2042 ARDOUR_UI::snapshot_session (bool switch_to_it)
2044 ArdourPrompter prompter (true);
2047 prompter.set_name ("Prompter");
2048 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2049 prompter.set_title (_("Take Snapshot"));
2050 prompter.set_prompt (_("Name of new snapshot"));
2052 if (!switch_to_it) {
2055 struct tm local_time;
2058 localtime_r (&n, &local_time);
2059 strftime (timebuf, sizeof(timebuf), "%FT%H.%M.%S", &local_time);
2060 prompter.set_initial_text (timebuf);
2064 switch (prompter.run()) {
2065 case RESPONSE_ACCEPT:
2067 prompter.get_result (snapname);
2069 bool do_save = (snapname.length() != 0);
2072 char illegal = Session::session_name_is_legal(snapname);
2074 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2075 "snapshot names may not contain a '%1' character"), illegal));
2081 vector<std::string> p;
2082 get_state_files_in_directory (_session->session_directory().root_path(), p);
2083 vector<string> n = get_file_names_no_extension (p);
2084 if (find (n.begin(), n.end(), snapname) != n.end()) {
2086 ArdourDialog confirm (_("Confirm Snapshot Overwrite"), true);
2087 Label m (_("A snapshot already exists with that name. Do you want to overwrite it?"));
2088 confirm.get_vbox()->pack_start (m, true, true);
2089 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2090 confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
2091 confirm.show_all ();
2092 switch (confirm.run()) {
2093 case RESPONSE_CANCEL:
2099 save_state (snapname, switch_to_it);
2109 /** Ask the user for a new session name and then rename the session to it.
2113 ARDOUR_UI::rename_session ()
2119 ArdourPrompter prompter (true);
2122 prompter.set_name ("Prompter");
2123 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2124 prompter.set_title (_("Rename Session"));
2125 prompter.set_prompt (_("New session name"));
2128 switch (prompter.run()) {
2129 case RESPONSE_ACCEPT:
2131 prompter.get_result (name);
2133 bool do_rename = (name.length() != 0);
2136 char illegal = Session::session_name_is_legal (name);
2139 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2140 "session names may not contain a '%1' character"), illegal));
2145 switch (_session->rename (name)) {
2147 MessageDialog msg (_("That name is already in use by another directory/folder. Please try again."));
2148 msg.set_position (WIN_POS_MOUSE);
2156 MessageDialog msg (_("Renaming this session failed.\nThings could be seriously messed up at this point"));
2157 msg.set_position (WIN_POS_MOUSE);
2173 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
2175 XMLNode* node = new XMLNode (X_("UI"));
2177 for (list<WindowProxyBase*>::iterator i = _window_proxies.begin(); i != _window_proxies.end(); ++i) {
2178 if (!(*i)->rc_configured()) {
2179 node->add_child_nocopy (*((*i)->get_state ()));
2183 node->add_child_nocopy (gui_object_state->get_state());
2185 _session->add_extra_xml (*node);
2187 save_state_canfail (name, switch_to_it);
2191 ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
2196 if (name.length() == 0) {
2197 name = _session->snap_name();
2200 if ((ret = _session->save_state (name, false, switch_to_it)) != 0) {
2205 save_ardour_state (); /* XXX cannot fail? yeah, right ... */
2210 ARDOUR_UI::primary_clock_value_changed ()
2213 _session->request_locate (primary_clock->current_time ());
2218 ARDOUR_UI::big_clock_value_changed ()
2221 _session->request_locate (big_clock->current_time ());
2226 ARDOUR_UI::secondary_clock_value_changed ()
2229 _session->request_locate (secondary_clock->current_time ());
2234 ARDOUR_UI::transport_rec_enable_blink (bool onoff)
2236 if (_session == 0) {
2240 if (_session->step_editing()) {
2244 Session::RecordState const r = _session->record_status ();
2245 bool const h = _session->have_rec_enabled_track ();
2247 if (r == Session::Enabled || (r == Session::Recording && !h)) {
2249 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2251 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
2253 } else if (r == Session::Recording && h) {
2254 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2256 rec_button.unset_active_state ();
2261 ARDOUR_UI::save_template ()
2263 ArdourPrompter prompter (true);
2266 if (!check_audioengine()) {
2270 prompter.set_name (X_("Prompter"));
2271 prompter.set_title (_("Save Template"));
2272 prompter.set_prompt (_("Name for template:"));
2273 prompter.set_initial_text(_session->name() + _("-template"));
2274 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2276 switch (prompter.run()) {
2277 case RESPONSE_ACCEPT:
2278 prompter.get_result (name);
2280 if (name.length()) {
2281 _session->save_template (name);
2291 ARDOUR_UI::edit_metadata ()
2293 SessionMetadataEditor dialog;
2294 dialog.set_session (_session);
2295 editor->ensure_float (dialog);
2300 ARDOUR_UI::import_metadata ()
2302 SessionMetadataImporter dialog;
2303 dialog.set_session (_session);
2304 editor->ensure_float (dialog);
2309 ARDOUR_UI::ask_about_loading_existing_session (const std::string& session_path)
2311 std::string str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
2313 MessageDialog msg (str,
2315 Gtk::MESSAGE_WARNING,
2316 Gtk::BUTTONS_YES_NO,
2320 msg.set_name (X_("OpenExistingDialog"));
2321 msg.set_title (_("Open Existing Session"));
2322 msg.set_wmclass (X_("existing_session"), PROGRAM_NAME);
2323 msg.set_position (Gtk::WIN_POS_MOUSE);
2324 pop_back_splash (msg);
2326 switch (msg.run()) {
2335 ARDOUR_UI::build_session_from_nsd (const std::string& session_path, const std::string& session_name)
2337 BusProfile bus_profile;
2339 if (Profile->get_sae()) {
2341 bus_profile.master_out_channels = 2;
2342 bus_profile.input_ac = AutoConnectPhysical;
2343 bus_profile.output_ac = AutoConnectMaster;
2344 bus_profile.requested_physical_in = 0; // use all available
2345 bus_profile.requested_physical_out = 0; // use all available
2349 /* get settings from advanced section of NSD */
2351 if (_startup->create_master_bus()) {
2352 bus_profile.master_out_channels = (uint32_t) _startup->master_channel_count();
2354 bus_profile.master_out_channels = 0;
2357 if (_startup->connect_inputs()) {
2358 bus_profile.input_ac = AutoConnectPhysical;
2360 bus_profile.input_ac = AutoConnectOption (0);
2363 bus_profile.output_ac = AutoConnectOption (0);
2365 if (_startup->connect_outputs ()) {
2366 if (_startup->connect_outs_to_master()) {
2367 bus_profile.output_ac = AutoConnectMaster;
2368 } else if (_startup->connect_outs_to_physical()) {
2369 bus_profile.output_ac = AutoConnectPhysical;
2373 bus_profile.requested_physical_in = (uint32_t) _startup->input_limit_count();
2374 bus_profile.requested_physical_out = (uint32_t) _startup->output_limit_count();
2377 if (build_session (session_path, session_name, bus_profile)) {
2385 ARDOUR_UI::idle_load (const std::string& path)
2388 if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
2389 /* /path/to/foo => /path/to/foo, foo */
2390 load_session (path, basename_nosuffix (path));
2392 /* /path/to/foo/foo.ardour => /path/to/foo, foo */
2393 load_session (Glib::path_get_dirname (path), basename_nosuffix (path));
2397 ARDOUR_COMMAND_LINE::session_name = path;
2401 /** @param quit_on_cancel true if exit() should be called if the user clicks `cancel' in the new session dialog */
2403 ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, string load_template)
2405 string session_name;
2406 string session_path;
2407 string template_name;
2409 bool likely_new = false;
2411 if (!load_template.empty()) {
2412 should_be_new = true;
2413 template_name = load_template;
2418 if (!should_be_new && !ARDOUR_COMMAND_LINE::session_name.empty()) {
2420 /* if they named a specific statefile, use it, otherwise they are
2421 just giving a session folder, and we want to use it as is
2422 to find the session.
2425 string::size_type suffix = ARDOUR_COMMAND_LINE::session_name.find (statefile_suffix);
2427 if (suffix != string::npos) {
2428 session_path = Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name);
2429 session_name = ARDOUR_COMMAND_LINE::session_name.substr (0, suffix);
2430 session_name = Glib::path_get_basename (session_name);
2432 session_path = ARDOUR_COMMAND_LINE::session_name;
2433 session_name = Glib::path_get_basename (ARDOUR_COMMAND_LINE::session_name);
2438 bool const apply = run_startup (should_be_new, load_template);
2441 if (quit_on_cancel) {
2448 /* if we run the startup dialog again, offer more than just "new session" */
2450 should_be_new = false;
2452 session_name = _startup->session_name (likely_new);
2454 string::size_type suffix = session_name.find (statefile_suffix);
2456 if (suffix != string::npos) {
2457 session_name = session_name.substr (0, suffix);
2460 /* this shouldn't happen, but we catch it just in case it does */
2462 if (session_name.empty()) {
2466 if (_startup->use_session_template()) {
2467 template_name = _startup->session_template_name();
2468 _session_is_new = true;
2471 if (session_name[0] == G_DIR_SEPARATOR ||
2472 (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == G_DIR_SEPARATOR) ||
2473 (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == G_DIR_SEPARATOR)) {
2475 /* absolute path or cwd-relative path specified for session name: infer session folder
2476 from what was given.
2479 session_path = Glib::path_get_dirname (session_name);
2480 session_name = Glib::path_get_basename (session_name);
2484 session_path = _startup->session_folder();
2486 char illegal = Session::session_name_is_legal (session_name);
2489 MessageDialog msg (*_startup,
2490 string_compose (_("To ensure compatibility with various systems\n"
2491 "session names may not contain a '%1' character"),
2494 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2500 if (create_engine ()) {
2504 if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
2508 std::string existing = Glib::build_filename (session_path, session_name);
2510 if (!ask_about_loading_existing_session (existing)) {
2511 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2516 _session_is_new = false;
2522 pop_back_splash (*_startup);
2527 MessageDialog msg (string_compose (_("There is no existing session at \"%1\""), session_path));
2529 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2533 char illegal = Session::session_name_is_legal(session_name);
2535 pop_back_splash (*_startup);
2536 MessageDialog msg (*_startup, string_compose(_("To ensure compatibility with various systems\n"
2537 "session names may not contain a '%1' character"), illegal));
2539 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2543 _session_is_new = true;
2546 if (likely_new && template_name.empty()) {
2548 ret = build_session_from_nsd (session_path, session_name);
2552 ret = load_session (session_path, session_name, template_name);
2555 /* not connected to the AudioEngine, so quit to avoid an infinite loop */
2559 if (!ARDOUR_COMMAND_LINE::immediate_save.empty()) {
2560 _session->save_state (ARDOUR_COMMAND_LINE::immediate_save, false);
2570 ARDOUR_UI::close_session()
2572 if (!check_audioengine()) {
2576 if (unload_session (true)) {
2580 ARDOUR_COMMAND_LINE::session_name = "";
2582 if (get_session_parameters (true, false)) {
2586 goto_editor_window ();
2589 /** @param snap_name Snapshot name (without .ardour suffix).
2590 * @return -2 if the load failed because we are not connected to the AudioEngine.
2593 ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name, std::string mix_template)
2595 Session *new_session;
2599 session_loaded = false;
2601 if (!check_audioengine()) {
2605 unload_status = unload_session ();
2607 if (unload_status < 0) {
2609 } else if (unload_status > 0) {
2614 loading_message (string_compose (_("Please wait while %1 loads your session"), PROGRAM_NAME));
2617 new_session = new Session (*engine, path, snap_name, 0, mix_template);
2620 /* this one is special */
2622 catch (AudioEngine::PortRegistrationFailure& err) {
2624 MessageDialog msg (err.what(),
2627 Gtk::BUTTONS_CLOSE);
2629 msg.set_title (_("Port Registration Error"));
2630 msg.set_secondary_text (_("Click the Close button to try again."));
2631 msg.set_position (Gtk::WIN_POS_CENTER);
2632 pop_back_splash (msg);
2635 int response = msg.run ();
2640 case RESPONSE_CANCEL:
2650 MessageDialog msg (string_compose(
2651 _("Session \"%1 (snapshot %2)\" did not load successfully"),
2657 msg.set_title (_("Loading Error"));
2658 msg.set_secondary_text (_("Click the Refresh button to try again."));
2659 msg.add_button (Stock::REFRESH, 1);
2660 msg.set_position (Gtk::WIN_POS_CENTER);
2661 pop_back_splash (msg);
2664 int response = msg.run ();
2679 list<string> const u = new_session->unknown_processors ();
2681 MissingPluginDialog d (_session, u);
2686 /* Now the session been created, add the transport controls */
2687 new_session->add_controllable(roll_controllable);
2688 new_session->add_controllable(stop_controllable);
2689 new_session->add_controllable(goto_start_controllable);
2690 new_session->add_controllable(goto_end_controllable);
2691 new_session->add_controllable(auto_loop_controllable);
2692 new_session->add_controllable(play_selection_controllable);
2693 new_session->add_controllable(rec_controllable);
2695 set_session (new_session);
2697 session_loaded = true;
2699 goto_editor_window ();
2702 _session->set_clean ();
2713 ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name, BusProfile& bus_profile)
2715 Session *new_session;
2718 if (!check_audioengine()) {
2722 session_loaded = false;
2724 x = unload_session ();
2732 _session_is_new = true;
2735 new_session = new Session (*engine, path, snap_name, &bus_profile);
2740 MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
2741 pop_back_splash (msg);
2746 /* Give the new session the default GUI state, if such things exist */
2749 n = Config->instant_xml (X_("Editor"));
2751 new_session->add_instant_xml (*n, false);
2753 n = Config->instant_xml (X_("Mixer"));
2755 new_session->add_instant_xml (*n, false);
2758 /* Put the playhead at 0 and scroll fully left */
2759 n = new_session->instant_xml (X_("Editor"));
2761 n->add_property (X_("playhead"), X_("0"));
2762 n->add_property (X_("left-frame"), X_("0"));
2765 set_session (new_session);
2767 session_loaded = true;
2769 new_session->save_state(new_session->name());
2775 ARDOUR_UI::launch_chat ()
2778 open_uri("http://webchat.freenode.net/?channels=ardour-osx");
2780 open_uri("http://webchat.freenode.net/?channels=ardour");
2785 ARDOUR_UI::show_about ()
2789 about->signal_response().connect (sigc::mem_fun (*this, &ARDOUR_UI::about_signal_response));
2792 about->set_transient_for(*editor);
2797 ARDOUR_UI::launch_manual ()
2799 PBD::open_uri("http://ardour.org/flossmanual");
2803 ARDOUR_UI::launch_reference ()
2805 PBD::open_uri ("http://ardour.org/refmanual");
2809 ARDOUR_UI::hide_about ()
2812 about->get_window()->set_cursor ();
2818 ARDOUR_UI::about_signal_response (int /*response*/)
2824 ARDOUR_UI::loading_message (const std::string& msg)
2826 if (ARDOUR_COMMAND_LINE::no_splash) {
2834 splash->message (msg);
2838 ARDOUR_UI::show_splash ()
2842 splash = new Splash;
2852 ARDOUR_UI::hide_splash ()
2859 ARDOUR_UI::display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
2860 const string& plural_msg, const string& singular_msg)
2864 removed = rep.paths.size();
2867 MessageDialog msgd (*editor,
2868 _("No files were ready for clean-up"),
2872 msgd.set_title (_("Clean-up"));
2873 msgd.set_secondary_text (_("If this seems suprising, \n\
2874 check for any existing snapshots.\n\
2875 These may still include regions that\n\
2876 require some unused files to continue to exist."));
2882 ArdourDialog results (_("Clean-up"), true, false);
2884 struct CleanupResultsModelColumns : public Gtk::TreeModel::ColumnRecord {
2885 CleanupResultsModelColumns() {
2889 Gtk::TreeModelColumn<std::string> visible_name;
2890 Gtk::TreeModelColumn<std::string> fullpath;
2894 CleanupResultsModelColumns results_columns;
2895 Glib::RefPtr<Gtk::ListStore> results_model;
2896 Gtk::TreeView results_display;
2898 results_model = ListStore::create (results_columns);
2899 results_display.set_model (results_model);
2900 results_display.append_column (list_title, results_columns.visible_name);
2902 results_display.set_name ("CleanupResultsList");
2903 results_display.set_headers_visible (true);
2904 results_display.set_headers_clickable (false);
2905 results_display.set_reorderable (false);
2907 Gtk::ScrolledWindow list_scroller;
2910 Gtk::HBox dhbox; // the hbox for the image and text
2911 Gtk::HBox ddhbox; // the hbox we eventually pack into the dialog's vbox
2912 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_INFO, Gtk::ICON_SIZE_DIALOG));
2914 dimage->set_alignment(ALIGN_LEFT, ALIGN_TOP);
2916 const string dead_directory = _session->session_directory().dead_path();
2919 %1 - number of files removed
2920 %2 - location of "dead"
2921 %3 - size of files affected
2922 %4 - prefix for "bytes" to produce sensible results (e.g. mega, kilo, giga)
2925 const char* bprefix;
2926 double space_adjusted = 0;
2928 if (rep.space < 1000) {
2930 space_adjusted = rep.space;
2931 } else if (rep.space < 1000000) {
2932 bprefix = X_("kilo");
2933 space_adjusted = truncf((float)rep.space / 1000.0);
2934 } else if (rep.space < 1000000 * 1000) {
2935 bprefix = X_("mega");
2936 space_adjusted = truncf((float)rep.space / (1000.0 * 1000.0));
2938 bprefix = X_("giga");
2939 space_adjusted = truncf((float)rep.space / (1000.0 * 1000 * 1000.0));
2943 txt.set_text (string_compose (plural_msg, removed, dead_directory, space_adjusted, bprefix, PROGRAM_NAME));
2945 txt.set_text (string_compose (singular_msg, removed, dead_directory, space_adjusted, bprefix, PROGRAM_NAME));
2948 dhbox.pack_start (*dimage, true, false, 5);
2949 dhbox.pack_start (txt, true, false, 5);
2951 for (vector<string>::iterator i = rep.paths.begin(); i != rep.paths.end(); ++i) {
2952 TreeModel::Row row = *(results_model->append());
2953 row[results_columns.visible_name] = *i;
2954 row[results_columns.fullpath] = *i;
2957 list_scroller.add (results_display);
2958 list_scroller.set_size_request (-1, 150);
2959 list_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
2961 dvbox.pack_start (dhbox, true, false, 5);
2962 dvbox.pack_start (list_scroller, true, false, 5);
2963 ddhbox.pack_start (dvbox, true, false, 5);
2965 results.get_vbox()->pack_start (ddhbox, true, false, 5);
2966 results.add_button (Stock::CLOSE, RESPONSE_CLOSE);
2967 results.set_default_response (RESPONSE_CLOSE);
2968 results.set_position (Gtk::WIN_POS_MOUSE);
2970 results_display.show();
2971 list_scroller.show();
2978 //results.get_vbox()->show();
2979 results.set_resizable (false);
2986 ARDOUR_UI::cleanup ()
2988 if (_session == 0) {
2989 /* shouldn't happen: menu item is insensitive */
2994 MessageDialog checker (_("Are you sure you want to clean-up?"),
2996 Gtk::MESSAGE_QUESTION,
2999 checker.set_title (_("Clean-up"));
3001 checker.set_secondary_text(_("Clean-up is a destructive operation.\n\
3002 ALL undo/redo information will be lost if you clean-up.\n\
3003 Clean-up will move all unused files to a \"dead\" location."));
3005 checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3006 checker.add_button (_("Clean-up"), RESPONSE_ACCEPT);
3007 checker.set_default_response (RESPONSE_CANCEL);
3009 checker.set_name (_("CleanupDialog"));
3010 checker.set_wmclass (X_("ardour_cleanup"), PROGRAM_NAME);
3011 checker.set_position (Gtk::WIN_POS_MOUSE);
3013 switch (checker.run()) {
3014 case RESPONSE_ACCEPT:
3020 ARDOUR::CleanupReport rep;
3022 editor->prepare_for_cleanup ();
3024 /* do not allow flush until a session is reloaded */
3026 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
3028 act->set_sensitive (false);
3031 if (_session->cleanup_sources (rep)) {
3032 editor->finish_cleanup ();
3036 editor->finish_cleanup ();
3039 display_cleanup_results (rep,
3042 The following %1 files were not in use and \n\
3043 have been moved to:\n\n\
3045 After a restart of %5,\n\n\
3046 Session -> Clean-up -> Flush Wastebasket\n\n\
3047 will release an additional\n\
3048 %3 %4bytes of disk space.\n"),
3050 The following file was not in use and \n\
3051 has been moved to:\n \
3053 After a restart of %5,\n\n\
3054 Session -> Clean-up -> Flush Wastebasket\n\n\
3055 will release an additional\n\
3056 %3 %4bytes of disk space.\n"
3062 ARDOUR_UI::flush_trash ()
3064 if (_session == 0) {
3065 /* shouldn't happen: menu item is insensitive */
3069 ARDOUR::CleanupReport rep;
3071 if (_session->cleanup_trash_sources (rep)) {
3075 display_cleanup_results (rep,
3077 _("The following %1 files were deleted from\n\
3079 releasing %3 %4bytes of disk space"),
3080 _("The following file was deleted from\n\
3082 releasing %3 %4bytes of disk space"));
3086 ARDOUR_UI::add_route (Gtk::Window* float_window)
3094 if (add_route_dialog == 0) {
3095 add_route_dialog = new AddRouteDialog (_session);
3096 add_route_dialog->set_position (WIN_POS_MOUSE);
3098 add_route_dialog->set_transient_for (*float_window);
3102 if (add_route_dialog->is_visible()) {
3103 /* we're already doing this */
3107 ResponseType r = (ResponseType) add_route_dialog->run ();
3109 add_route_dialog->hide();
3112 case RESPONSE_ACCEPT:
3119 if ((count = add_route_dialog->count()) <= 0) {
3123 string template_path = add_route_dialog->track_template();
3125 if (!template_path.empty()) {
3126 _session->new_route_from_template (count, template_path);
3130 ChanCount input_chan= add_route_dialog->channels ();
3131 ChanCount output_chan;
3132 string name_template = add_route_dialog->name_template ();
3133 PluginInfoPtr instrument = add_route_dialog->requested_instrument ();
3134 RouteGroup* route_group = add_route_dialog->route_group ();
3136 AutoConnectOption oac = Config->get_output_auto_connect();
3138 if (oac & AutoConnectMaster) {
3139 output_chan.set (DataType::AUDIO, (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan.n_audio()));
3140 output_chan.set (DataType::MIDI, 0);
3142 output_chan = input_chan;
3145 /* XXX do something with name template */
3147 switch (add_route_dialog->type_wanted()) {
3148 case AddRouteDialog::AudioTrack:
3149 session_add_audio_track (input_chan.n_audio(), output_chan.n_audio(), add_route_dialog->mode(), route_group, count, name_template);
3151 case AddRouteDialog::MidiTrack:
3152 session_add_midi_track (route_group, count, name_template, instrument);
3154 case AddRouteDialog::MixedTrack:
3155 session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, instrument);
3157 case AddRouteDialog::AudioBus:
3158 session_add_audio_bus (input_chan.n_audio(), output_chan.n_audio(), route_group, count, name_template);
3164 ARDOUR_UI::mixer_settings () const
3169 node = _session->instant_xml(X_("Mixer"));
3171 node = Config->instant_xml(X_("Mixer"));
3175 node = new XMLNode (X_("Mixer"));
3182 ARDOUR_UI::editor_settings () const
3187 node = _session->instant_xml(X_("Editor"));
3189 node = Config->instant_xml(X_("Editor"));
3193 if (getenv("ARDOUR_INSTANT_XML_PATH")) {
3194 node = Config->instant_xml(getenv("ARDOUR_INSTANT_XML_PATH"));
3199 node = new XMLNode (X_("Editor"));
3206 ARDOUR_UI::keyboard_settings () const
3210 node = Config->extra_xml(X_("Keyboard"));
3213 node = new XMLNode (X_("Keyboard"));
3220 ARDOUR_UI::create_xrun_marker (framepos_t where)
3222 editor->mouse_add_new_marker (where, false, true);
3226 ARDOUR_UI::halt_on_xrun_message ()
3228 MessageDialog msg (*editor,
3229 _("Recording was stopped because your system could not keep up."));
3234 ARDOUR_UI::xrun_handler (framepos_t where)
3240 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::xrun_handler, where)
3242 if (_session && Config->get_create_xrun_marker() && _session->actively_recording()) {
3243 create_xrun_marker(where);
3246 if (_session && Config->get_stop_recording_on_xrun() && _session->actively_recording()) {
3247 halt_on_xrun_message ();
3252 ARDOUR_UI::disk_overrun_handler ()
3254 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_overrun_handler)
3256 if (!have_disk_speed_dialog_displayed) {
3257 have_disk_speed_dialog_displayed = true;
3258 MessageDialog* msg = new MessageDialog (*editor, string_compose (_("\
3259 The disk system on your computer\n\
3260 was not able to keep up with %1.\n\
3262 Specifically, it failed to write data to disk\n\
3263 quickly enough to keep up with recording.\n"), PROGRAM_NAME));
3264 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3270 ARDOUR_UI::disk_underrun_handler ()
3272 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_underrun_handler)
3274 if (!have_disk_speed_dialog_displayed) {
3275 have_disk_speed_dialog_displayed = true;
3276 MessageDialog* msg = new MessageDialog (
3277 *editor, string_compose (_("The disk system on your computer\n\
3278 was not able to keep up with %1.\n\
3280 Specifically, it failed to read data from disk\n\
3281 quickly enough to keep up with playback.\n"), PROGRAM_NAME));
3282 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3288 ARDOUR_UI::disk_speed_dialog_gone (int /*ignored_response*/, MessageDialog* msg)
3290 have_disk_speed_dialog_displayed = false;
3295 ARDOUR_UI::session_dialog (std::string msg)
3297 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::session_dialog, msg)
3302 d = new MessageDialog (*editor, msg, false, MESSAGE_INFO, BUTTONS_OK, true);
3304 d = new MessageDialog (msg, false, MESSAGE_INFO, BUTTONS_OK, true);
3313 ARDOUR_UI::pending_state_dialog ()
3315 HBox* hbox = new HBox();
3316 Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
3317 ArdourDialog dialog (_("Crash Recovery"), true);
3318 Label message (string_compose (_("\
3319 This session appears to have been in\n\
3320 middle of recording when ardour or\n\
3321 the computer was shutdown.\n\
3323 %1 can recover any captured audio for\n\
3324 you, or it can ignore it. Please decide\n\
3325 what you would like to do.\n"), PROGRAM_NAME));
3326 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
3327 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
3328 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
3329 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
3330 dialog.add_button (_("Ignore crash data"), RESPONSE_REJECT);
3331 dialog.add_button (_("Recover from crash"), RESPONSE_ACCEPT);
3332 dialog.set_default_response (RESPONSE_ACCEPT);
3333 dialog.set_position (WIN_POS_CENTER);
3338 switch (dialog.run ()) {
3339 case RESPONSE_ACCEPT:
3347 ARDOUR_UI::sr_mismatch_dialog (framecnt_t desired, framecnt_t actual)
3349 HBox* hbox = new HBox();
3350 Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
3351 ArdourDialog dialog (_("Sample Rate Mismatch"), true);
3352 Label message (string_compose (_("\
3353 This session was created with a sample rate of %1 Hz, but\n\
3354 %2 is currently running at %3 Hz. If you load this session,\n\
3355 audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual));
3357 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
3358 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
3359 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
3360 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
3361 dialog.add_button (_("Do not load session"), RESPONSE_REJECT);
3362 dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT);
3363 dialog.set_default_response (RESPONSE_ACCEPT);
3364 dialog.set_position (WIN_POS_CENTER);
3369 switch (dialog.run ()) {
3370 case RESPONSE_ACCEPT:
3379 ARDOUR_UI::disconnect_from_jack ()
3382 if (engine->disconnect_from_jack ()) {
3383 MessageDialog msg (*editor, _("Could not disconnect from JACK"));
3387 update_sample_rate (0);
3392 ARDOUR_UI::reconnect_to_jack ()
3395 if (engine->reconnect_to_jack ()) {
3396 MessageDialog msg (*editor, _("Could not reconnect to JACK"));
3400 update_sample_rate (0);
3405 ARDOUR_UI::use_config ()
3407 XMLNode* node = Config->extra_xml (X_("TransportControllables"));
3409 set_transport_controllable_state (*node);
3414 ARDOUR_UI::update_transport_clocks (framepos_t pos)
3416 if (Config->get_primary_clock_delta_edit_cursor()) {
3417 primary_clock->set (pos, false, editor->get_preferred_edit_position());
3419 primary_clock->set (pos);
3422 if (Config->get_secondary_clock_delta_edit_cursor()) {
3423 secondary_clock->set (pos, false, editor->get_preferred_edit_position());
3425 secondary_clock->set (pos);
3428 if (big_clock_window->get()) {
3429 big_clock->set (pos);
3435 ARDOUR_UI::step_edit_status_change (bool yn)
3437 // XXX should really store pre-step edit status of things
3438 // we make insensitive
3441 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
3442 rec_button.set_sensitive (false);
3444 rec_button.unset_active_state ();;
3445 rec_button.set_sensitive (true);
3450 ARDOUR_UI::record_state_changed ()
3452 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);
3454 if (!_session || !big_clock_window->get()) {
3455 /* why bother - the clock isn't visible */
3459 if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
3460 big_clock->set_active (true);
3462 big_clock->set_active (false);
3467 ARDOUR_UI::first_idle ()
3470 _session->allow_auto_play (true);
3474 editor->first_idle();
3477 Keyboard::set_can_save_keybindings (true);
3482 ARDOUR_UI::store_clock_modes ()
3484 XMLNode* node = new XMLNode(X_("ClockModes"));
3486 for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
3487 XMLNode* child = new XMLNode (X_("Clock"));
3489 child->add_property (X_("name"), (*x)->name());
3490 child->add_property (X_("mode"), enum_2_string ((*x)->mode()));
3491 child->add_property (X_("on"), ((*x)->off() ? X_("no") : X_("yes")));
3493 node->add_child_nocopy (*child);
3496 _session->add_extra_xml (*node);
3497 _session->set_dirty ();
3500 ARDOUR_UI::TransportControllable::TransportControllable (std::string name, ARDOUR_UI& u, ToggleType tp)
3501 : Controllable (name), ui (u), type(tp)
3507 ARDOUR_UI::TransportControllable::set_value (double val)
3510 /* do nothing: these are radio-style actions */
3514 const char *action = 0;
3518 action = X_("Roll");
3521 action = X_("Stop");
3524 action = X_("GotoStart");
3527 action = X_("GotoEnd");
3530 action = X_("Loop");
3533 action = X_("PlaySelection");
3536 action = X_("Record");
3546 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", action);
3554 ARDOUR_UI::TransportControllable::get_value (void) const
3581 ARDOUR_UI::setup_profile ()
3583 if (gdk_screen_width() < 1200 || getenv ("ARDOUR_NARROW_SCREEN")) {
3584 Profile->set_small_screen ();
3587 if (getenv ("ARDOUR_SAE")) {
3588 Profile->set_sae ();
3589 Profile->set_single_package ();
3594 ARDOUR_UI::toggle_translations ()
3596 using namespace Glib;
3598 RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("EnableTranslation"));
3600 RefPtr<ToggleAction> ract = RefPtr<ToggleAction>::cast_dynamic (act);
3603 string i18n_killer = ARDOUR::translation_kill_path();
3605 bool already_enabled = !ARDOUR::translations_are_disabled ();
3607 if (ract->get_active ()) {
3608 /* we don't care about errors */
3609 int fd = ::open (i18n_killer.c_str(), O_RDONLY|O_CREAT, 0644);
3612 /* we don't care about errors */
3613 unlink (i18n_killer.c_str());
3616 if (already_enabled != ract->get_active()) {
3617 MessageDialog win (already_enabled ? _("Translations disabled") : _("Translations enabled"),
3619 Gtk::MESSAGE_WARNING,
3621 win.set_secondary_text (string_compose (_("You must restart %1 for this to take effect."), PROGRAM_NAME));
3622 win.set_position (Gtk::WIN_POS_CENTER);
3630 /** Add a window proxy to our list, so that its state will be saved.
3631 * This call also causes the window to be created and opened if its
3632 * state was saved as `visible'.
3635 ARDOUR_UI::add_window_proxy (WindowProxyBase* p)
3637 _window_proxies.push_back (p);
3641 /** Remove a window proxy from our list. Must be called if a WindowProxy
3642 * is deleted, to prevent hanging pointers.
3645 ARDOUR_UI::remove_window_proxy (WindowProxyBase* p)
3647 _window_proxies.remove (p);
3651 ARDOUR_UI::missing_file (Session*s, std::string str, DataType type)
3653 MissingFileDialog dialog (s, str, type);
3658 int result = dialog.run ();
3665 return 1; // quit entire session load
3668 result = dialog.get_action ();
3674 ARDOUR_UI::ambiguous_file (std::string file, std::string /*path*/, std::vector<std::string> hits)
3676 AmbiguousFileDialog dialog (file, hits);
3682 return dialog.get_which ();
3685 /** Allocate our thread-local buffers */
3687 ARDOUR_UI::get_process_buffers ()
3689 _process_thread->get_buffers ();
3692 /** Drop our thread-local buffers */
3694 ARDOUR_UI::drop_process_buffers ()
3696 _process_thread->drop_buffers ();
3700 ARDOUR_UI::feedback_detected ()
3702 _feedback_exists = true;
3706 ARDOUR_UI::successful_graph_sort ()
3708 _feedback_exists = false;
3712 ARDOUR_UI::midi_panic ()
3715 _session->midi_panic();