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"
76 #include "ardour/slave.h"
78 #include "timecode/time.h"
80 typedef uint64_t microseconds_t;
84 #include "add_route_dialog.h"
85 #include "ambiguous_file_dialog.h"
86 #include "ardour_ui.h"
87 #include "audio_clock.h"
88 #include "bundle_manager.h"
89 #include "engine_dialog.h"
90 #include "gain_meter.h"
91 #include "global_port_matrix.h"
92 #include "gui_object.h"
93 #include "gui_thread.h"
95 #include "location_ui.h"
96 #include "main_clock.h"
97 #include "missing_file_dialog.h"
98 #include "missing_plugin_dialog.h"
100 #include "mouse_cursors.h"
102 #include "processor_box.h"
103 #include "prompter.h"
104 #include "public_editor.h"
105 #include "route_time_axis.h"
106 #include "session_metadata_dialog.h"
107 #include "shuttle_control.h"
108 #include "speaker_dialog.h"
111 #include "theme_manager.h"
112 #include "time_axis_view_item.h"
114 #include "window_proxy.h"
118 using namespace ARDOUR;
120 using namespace Gtkmm2ext;
124 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
125 UIConfiguration *ARDOUR_UI::ui_config = 0;
127 sigc::signal<void,bool> ARDOUR_UI::Blink;
128 sigc::signal<void> ARDOUR_UI::RapidScreenUpdate;
129 sigc::signal<void> ARDOUR_UI::SuperRapidScreenUpdate;
130 sigc::signal<void, framepos_t, bool, framepos_t> ARDOUR_UI::Clock;
132 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
134 : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
136 , gui_object_state (new GUIObjectState)
137 , primary_clock (new MainClock (X_("primary"), false, X_("transport"), true, true, true, false, true))
138 , secondary_clock (new MainClock (X_("secondary"), false, X_("secondary"), true, true, false, false, true))
142 , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
146 , roll_controllable (new TransportControllable ("transport roll", *this, TransportControllable::Roll))
147 , stop_controllable (new TransportControllable ("transport stop", *this, TransportControllable::Stop))
148 , goto_start_controllable (new TransportControllable ("transport goto start", *this, TransportControllable::GotoStart))
149 , goto_end_controllable (new TransportControllable ("transport goto end", *this, TransportControllable::GotoEnd))
150 , auto_loop_controllable (new TransportControllable ("transport auto loop", *this, TransportControllable::AutoLoop))
151 , play_selection_controllable (new TransportControllable ("transport play selection", *this, TransportControllable::PlaySelection))
152 , rec_controllable (new TransportControllable ("transport rec-enable", *this, TransportControllable::RecordEnable))
154 , auto_return_button (ArdourButton::led_default_elements)
155 , follow_edits_button (ArdourButton::led_default_elements)
156 , auto_input_button (ArdourButton::led_default_elements)
158 , auditioning_alert_button (_("audition"))
159 , solo_alert_button (_("solo"))
160 , feedback_alert_button (_("feedback"))
162 , error_log_button (_("Errors"))
164 , _status_bar_visibility (X_("status-bar"))
165 , _feedback_exists (false)
174 if (theArdourUI == 0) {
178 ui_config = new UIConfiguration();
179 theme_manager = new ThemeManager();
187 _session_is_new = false;
188 big_clock_window = 0;
189 big_clock_height = 0;
190 big_clock_resize_in_progress = false;
191 session_selector_window = 0;
192 last_key_press_time = 0;
193 add_route_dialog = 0;
196 rc_option_editor = 0;
197 session_option_editor = 0;
199 open_session_selector = 0;
200 have_configure_timeout = false;
201 have_disk_speed_dialog_displayed = false;
202 session_loaded = false;
203 ignore_dual_punch = false;
204 original_big_clock_width = -1;
205 original_big_clock_height = -1;
206 original_big_clock_font_size = 0;
208 roll_button.set_controllable (roll_controllable);
209 stop_button.set_controllable (stop_controllable);
210 goto_start_button.set_controllable (goto_start_controllable);
211 goto_end_button.set_controllable (goto_end_controllable);
212 auto_loop_button.set_controllable (auto_loop_controllable);
213 play_selection_button.set_controllable (play_selection_controllable);
214 rec_button.set_controllable (rec_controllable);
216 roll_button.set_name ("transport button");
217 stop_button.set_name ("transport button");
218 goto_start_button.set_name ("transport button");
219 goto_end_button.set_name ("transport button");
220 auto_loop_button.set_name ("transport button");
221 play_selection_button.set_name ("transport button");
222 rec_button.set_name ("transport recenable button");
223 midi_panic_button.set_name ("transport button");
225 goto_start_button.set_tweaks (ArdourButton::ShowClick);
226 goto_end_button.set_tweaks (ArdourButton::ShowClick);
227 midi_panic_button.set_tweaks (ArdourButton::ShowClick);
229 last_configure_time= 0;
232 ARDOUR::Diskstream::DiskOverrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
233 ARDOUR::Diskstream::DiskUnderrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
235 /* handle dialog requests */
237 ARDOUR::Session::Dialog.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_dialog, this, _1), gui_context());
239 /* handle pending state with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
241 ARDOUR::Session::AskAboutPendingState.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::pending_state_dialog, this));
243 /* handle sr mismatch with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
245 ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
247 /* handle requests to quit (coming from JACK session) */
249 ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
251 /* tell the user about feedback */
253 ARDOUR::Session::FeedbackDetected.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::feedback_detected, this), gui_context ());
254 ARDOUR::Session::SuccessfulGraphSort.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::successful_graph_sort, this), gui_context ());
256 /* handle requests to deal with missing files */
258 ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3));
260 /* and ambiguous files */
262 ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2, _3));
264 /* lets get this party started */
267 if (ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization)) {
268 throw failed_constructor ();
271 setup_gtk_ardour_enums ();
274 GainMeter::setup_slider_pix ();
275 RouteTimeAxisView::setup_slider_pix ();
276 ProcessorEntry::setup_slider_pix ();
277 SessionEvent::create_per_thread_pool ("GUI", 512);
279 } catch (failed_constructor& err) {
280 error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg;
285 /* we like keyboards */
287 keyboard = new ArdourKeyboard(*this);
289 XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
291 keyboard->set_state (*node, Stateful::loading_state_version);
294 /* we don't like certain modifiers */
295 Bindings::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK);
299 TimeAxisViewItem::set_constant_heights ();
301 /* The following must happen after ARDOUR::init() so that Config is set up */
303 location_ui = new ActionWindowProxy<LocationUIWindow> (X_("locations"), Config->extra_xml (X_("UI")), X_("ToggleLocations"));
304 big_clock_window = new ActionWindowProxy<Gtk::Window> (X_("bigclock"), Config->extra_xml (X_("UI")), X_("ToggleBigClock"));
305 speaker_config_window = new ActionWindowProxy<SpeakerDialog> (X_("speakerconf"), Config->extra_xml (X_("UI")), X_("toggle-speaker-config"));
307 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
308 _global_port_matrix[*i] = new ActionWindowProxy<GlobalPortMatrixWindow> (
309 string_compose ("GlobalPortMatrix-%1", (*i).to_string()),
310 Config->extra_xml (X_("UI")),
311 string_compose ("toggle-%1-connection-manager", (*i).to_string())
317 SpeakerDialog* s = new SpeakerDialog ();
318 s->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/toggle-speaker-config")));
319 speaker_config_window->set (s);
321 starting.connect (sigc::mem_fun(*this, &ARDOUR_UI::startup));
322 stopping.connect (sigc::mem_fun(*this, &ARDOUR_UI::shutdown));
324 _process_thread = new ProcessThread ();
325 _process_thread->init ();
327 DPIReset.connect (sigc::mem_fun (*this, &ARDOUR_UI::resize_text_widgets));
332 ARDOUR_UI::create_engine ()
334 // this gets called every time by new_session()
340 loading_message (_("Starting audio engine"));
343 engine = new ARDOUR::AudioEngine (ARDOUR_COMMAND_LINE::jack_client_name, ARDOUR_COMMAND_LINE::jack_session_uuid);
350 engine->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
351 engine->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context());
352 engine->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
354 engine->Halted.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
356 ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
364 ARDOUR_UI::post_engine ()
366 /* Things to be done once we create the AudioEngine
369 ARDOUR::init_post_engine ();
371 /* load up the UI manager */
373 ActionManager::init ();
377 if (setup_windows ()) {
378 throw failed_constructor ();
381 /* Do this after setup_windows (), as that's when the _status_bar_visibility is created */
382 XMLNode* n = Config->extra_xml (X_("UI"));
384 _status_bar_visibility.set_state (*n);
387 check_memory_locking();
389 /* this is the first point at which all the keybindings are available */
391 if (ARDOUR_COMMAND_LINE::show_key_actions) {
392 vector<string> names;
393 vector<string> paths;
394 vector<string> tooltips;
396 vector<AccelKey> bindings;
398 ActionManager::get_all_actions (names, paths, tooltips, keys, bindings);
400 vector<string>::iterator n;
401 vector<string>::iterator k;
402 for (n = names.begin(), k = keys.begin(); n != names.end(); ++n, ++k) {
403 cout << "Action: " << (*n) << " bound to " << (*k) << endl;
409 blink_timeout_tag = -1;
411 /* this being a GUI and all, we want peakfiles */
413 AudioFileSource::set_build_peakfiles (true);
414 AudioFileSource::set_build_missing_peakfiles (true);
416 /* set default clock modes */
418 if (Profile->get_sae()) {
419 primary_clock->set_mode (AudioClock::BBT);
420 secondary_clock->set_mode (AudioClock::MinSec);
422 primary_clock->set_mode (AudioClock::Timecode);
423 secondary_clock->set_mode (AudioClock::BBT);
426 /* start the time-of-day-clock */
429 /* OS X provides a nearly-always visible wallclock, so don't be stupid */
430 update_wall_clock ();
431 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::update_wall_clock), 60000);
434 update_disk_space ();
436 update_sample_rate (engine->frame_rate());
437 update_timecode_format ();
439 Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
440 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
441 Config->map_parameters (pc);
443 /* now start and maybe save state */
445 if (do_engine_start () == 0) {
446 if (_session && _session_is_new) {
447 /* we need to retain initial visual
448 settings for a new session
450 _session->save_state ("");
455 ARDOUR_UI::~ARDOUR_UI ()
460 delete add_route_dialog;
464 ARDOUR_UI::pop_back_splash (Gtk::Window& win)
466 if (Splash::instance()) {
467 Splash::instance()->pop_back_for (win);
472 ARDOUR_UI::configure_timeout ()
474 if (last_configure_time == 0) {
475 /* no configure events yet */
479 /* force a gap of 0.5 seconds since the last configure event
482 if (get_microseconds() - last_configure_time < 500000) {
485 have_configure_timeout = false;
486 save_ardour_state ();
492 ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
494 if (have_configure_timeout) {
495 last_configure_time = get_microseconds();
497 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::configure_timeout), 100);
498 have_configure_timeout = true;
505 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
507 const XMLProperty* prop;
509 if ((prop = node.property ("roll")) != 0) {
510 roll_controllable->set_id (prop->value());
512 if ((prop = node.property ("stop")) != 0) {
513 stop_controllable->set_id (prop->value());
515 if ((prop = node.property ("goto-start")) != 0) {
516 goto_start_controllable->set_id (prop->value());
518 if ((prop = node.property ("goto-end")) != 0) {
519 goto_end_controllable->set_id (prop->value());
521 if ((prop = node.property ("auto-loop")) != 0) {
522 auto_loop_controllable->set_id (prop->value());
524 if ((prop = node.property ("play-selection")) != 0) {
525 play_selection_controllable->set_id (prop->value());
527 if ((prop = node.property ("rec")) != 0) {
528 rec_controllable->set_id (prop->value());
530 if ((prop = node.property ("shuttle")) != 0) {
531 shuttle_box->controllable()->set_id (prop->value());
536 ARDOUR_UI::get_transport_controllable_state ()
538 XMLNode* node = new XMLNode(X_("TransportControllables"));
541 roll_controllable->id().print (buf, sizeof (buf));
542 node->add_property (X_("roll"), buf);
543 stop_controllable->id().print (buf, sizeof (buf));
544 node->add_property (X_("stop"), buf);
545 goto_start_controllable->id().print (buf, sizeof (buf));
546 node->add_property (X_("goto_start"), buf);
547 goto_end_controllable->id().print (buf, sizeof (buf));
548 node->add_property (X_("goto_end"), buf);
549 auto_loop_controllable->id().print (buf, sizeof (buf));
550 node->add_property (X_("auto_loop"), buf);
551 play_selection_controllable->id().print (buf, sizeof (buf));
552 node->add_property (X_("play_selection"), buf);
553 rec_controllable->id().print (buf, sizeof (buf));
554 node->add_property (X_("rec"), buf);
555 shuttle_box->controllable()->id().print (buf, sizeof (buf));
556 node->add_property (X_("shuttle"), buf);
563 ARDOUR_UI::autosave_session ()
565 if (g_main_depth() > 1) {
566 /* inside a recursive main loop,
567 give up because we may not be able to
573 if (!Config->get_periodic_safety_backups()) {
578 _session->maybe_write_autosave();
585 ARDOUR_UI::update_autosave ()
587 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_autosave)
589 if (_session && _session->dirty()) {
590 if (_autosave_connection.connected()) {
591 _autosave_connection.disconnect();
594 _autosave_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &ARDOUR_UI::autosave_session),
595 Config->get_periodic_safety_backup_interval() * 1000);
598 if (_autosave_connection.connected()) {
599 _autosave_connection.disconnect();
605 ARDOUR_UI::startup ()
607 Application* app = Application::instance ();
609 app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish));
610 app->ShouldLoad.connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_load));
613 call_the_mothership (VERSIONSTRING);
618 if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
624 goto_editor_window ();
626 /* Add the window proxies here; their addition may cause windows to be opened, and we want them
627 to be opened on top of the editor window that goto_editor_window() just opened.
629 add_window_proxy (location_ui);
630 add_window_proxy (big_clock_window);
631 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
632 add_window_proxy (_global_port_matrix[*i]);
635 /* We have to do this here since goto_editor_window() ends up calling show_all() on the
636 * editor window, and we may want stuff to be hidden.
638 _status_bar_visibility.update ();
640 BootMessage (string_compose (_("%1 is ready for use"), PROGRAM_NAME));
644 ARDOUR_UI::no_memory_warning ()
646 XMLNode node (X_("no-memory-warning"));
647 Config->add_instant_xml (node);
651 ARDOUR_UI::check_memory_locking ()
654 /* OS X doesn't support mlockall(2), and so testing for memory locking capability there is pointless */
658 XMLNode* memory_warning_node = Config->instant_xml (X_("no-memory-warning"));
660 if (engine->is_realtime() && memory_warning_node == 0) {
662 struct rlimit limits;
664 long pages, page_size;
666 if ((page_size = sysconf (_SC_PAGESIZE)) < 0 ||(pages = sysconf (_SC_PHYS_PAGES)) < 0) {
669 ram = (int64_t) pages * (int64_t) page_size;
672 if (getrlimit (RLIMIT_MEMLOCK, &limits)) {
676 if (limits.rlim_cur != RLIM_INFINITY) {
678 if (ram == 0 || ((double) limits.rlim_cur / ram) < 0.75) {
682 _("WARNING: Your system has a limit for maximum amount of locked memory. "
683 "This might cause %1 to run out of memory before your system "
684 "runs out of memory. \n\n"
685 "You can view the memory limit with 'ulimit -l', "
686 "and it is normally controlled by /etc/security/limits.conf"),
687 PROGRAM_NAME).c_str());
689 msg.set_default_response (RESPONSE_OK);
691 VBox* vbox = msg.get_vbox();
693 CheckButton cb (_("Do not show this window again"));
695 cb.signal_toggled().connect (sigc::mem_fun (*this, &ARDOUR_UI::no_memory_warning));
697 hbox.pack_start (cb, true, false);
698 vbox->pack_start (hbox);
703 pop_back_splash (msg);
705 editor->ensure_float (msg);
715 ARDOUR_UI::queue_finish ()
717 Glib::signal_idle().connect (mem_fun (*this, &ARDOUR_UI::idle_finish));
721 ARDOUR_UI::idle_finish ()
724 return false; /* do not call again */
732 if (_session->dirty()) {
733 vector<string> actions;
734 actions.push_back (_("Don't quit"));
735 actions.push_back (_("Just quit"));
736 actions.push_back (_("Save and quit"));
737 switch (ask_about_saving_session(actions)) {
742 /* use the default name */
743 if (save_state_canfail ("")) {
744 /* failed - don't quit */
745 MessageDialog msg (*editor,
747 %1 was unable to save your session.\n\n\
748 If you still wish to quit, please use the\n\n\
749 \"Just quit\" option."), PROGRAM_NAME));
750 pop_back_splash(msg);
760 second_connection.disconnect ();
761 point_one_second_connection.disconnect ();
762 point_oh_five_second_connection.disconnect ();
763 point_zero_one_second_connection.disconnect();
766 /* Save state before deleting the session, as that causes some
767 windows to be destroyed before their visible state can be
770 save_ardour_state ();
772 loading_message (string_compose (_("Please wait while %1 cleans up..."), PROGRAM_NAME));
775 // _session->set_deletion_in_progress ();
776 _session->set_clean ();
777 _session->remove_pending_capture_state ();
782 ArdourDialog::close_all_dialogs ();
788 ARDOUR_UI::ask_about_saving_session (const vector<string>& actions)
790 ArdourDialog window (_("Unsaved Session"));
791 Gtk::HBox dhbox; // the hbox for the image and text
792 Gtk::Label prompt_label;
793 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_WARNING, Gtk::ICON_SIZE_DIALOG));
797 assert (actions.size() >= 3);
799 window.add_button (actions[0], RESPONSE_REJECT);
800 window.add_button (actions[1], RESPONSE_APPLY);
801 window.add_button (actions[2], RESPONSE_ACCEPT);
803 window.set_default_response (RESPONSE_ACCEPT);
805 Gtk::Button noquit_button (msg);
806 noquit_button.set_name ("EditorGTKButton");
810 if (_session->snap_name() == _session->name()) {
811 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?"),
812 _session->snap_name());
814 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?"),
815 _session->snap_name());
818 prompt_label.set_text (prompt);
819 prompt_label.set_name (X_("PrompterLabel"));
820 prompt_label.set_alignment(ALIGN_LEFT, ALIGN_TOP);
822 dimage->set_alignment(ALIGN_CENTER, ALIGN_TOP);
823 dhbox.set_homogeneous (false);
824 dhbox.pack_start (*dimage, false, false, 5);
825 dhbox.pack_start (prompt_label, true, false, 5);
826 window.get_vbox()->pack_start (dhbox);
828 window.set_name (_("Prompter"));
829 window.set_position (Gtk::WIN_POS_MOUSE);
830 window.set_modal (true);
831 window.set_resizable (false);
837 window.set_keep_above (true);
840 ResponseType r = (ResponseType) window.run();
845 case RESPONSE_ACCEPT: // save and get out of here
847 case RESPONSE_APPLY: // get out of here
858 ARDOUR_UI::every_second ()
861 update_buffer_load ();
862 update_disk_space ();
863 update_timecode_format ();
868 ARDOUR_UI::every_point_one_seconds ()
870 shuttle_box->update_speed_display ();
871 RapidScreenUpdate(); /* EMIT_SIGNAL */
876 ARDOUR_UI::every_point_zero_one_seconds ()
878 // august 2007: actual update frequency: 40Hz, not 100Hz
880 SuperRapidScreenUpdate(); /* EMIT_SIGNAL */
885 ARDOUR_UI::update_sample_rate (framecnt_t)
889 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
891 if (!engine->connected()) {
893 snprintf (buf, sizeof (buf), "%s", _("disconnected"));
897 framecnt_t rate = engine->frame_rate();
899 if (fmod (rate, 1000.0) != 0.0) {
900 snprintf (buf, sizeof (buf), _("JACK: <span foreground=\"green\">%.1f kHz / %4.1f ms</span>"),
901 (float) rate/1000.0f,
902 (engine->frames_per_cycle() / (float) rate) * 1000.0f);
904 snprintf (buf, sizeof (buf), _("JACK: <span foreground=\"green\">%" PRId64 " kHz / %4.1f ms</span>"),
906 (engine->frames_per_cycle() / (float) rate) * 1000.0f);
910 sample_rate_label.set_markup (buf);
914 ARDOUR_UI::update_format ()
917 format_label.set_text ("");
922 s << _("File:") << X_(" <span foreground=\"green\">");
924 switch (_session->config.get_native_file_header_format ()) {
950 switch (_session->config.get_native_file_data_format ()) {
964 format_label.set_markup (s.str ());
968 ARDOUR_UI::update_cpu_load ()
972 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
973 should also be changed.
976 float const c = engine->get_cpu_load ();
977 snprintf (buf, sizeof (buf), _("DSP: <span foreground=\"%s\">%5.1f%%</span>"), c >= 90 ? X_("red") : X_("green"), c);
978 cpu_load_label.set_markup (buf);
982 ARDOUR_UI::update_buffer_load ()
986 uint32_t const playback = _session ? _session->playback_load () : 100;
987 uint32_t const capture = _session ? _session->capture_load () : 100;
989 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
990 should also be changed.
996 _("Buffers: <span foreground=\"green\">p:</span><span foreground=\"%s\">%" PRIu32 "%%</span> "
997 "<span foreground=\"green\">c:</span><span foreground=\"%s\">%" PRIu32 "%%</span>"),
998 playback <= 5 ? X_("red") : X_("green"),
1000 capture <= 5 ? X_("red") : X_("green"),
1004 buffer_load_label.set_markup (buf);
1006 buffer_load_label.set_text ("");
1011 ARDOUR_UI::count_recenabled_streams (Route& route)
1013 Track* track = dynamic_cast<Track*>(&route);
1014 if (track && track->record_enabled()) {
1015 rec_enabled_streams += track->n_inputs().n_total();
1020 ARDOUR_UI::update_disk_space()
1022 if (_session == 0) {
1026 boost::optional<framecnt_t> opt_frames = _session->available_capture_duration();
1028 framecnt_t fr = _session->frame_rate();
1031 /* Available space is unknown */
1032 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">Unknown</span>"));
1033 } else if (opt_frames.get_value_or (0) == max_framecnt) {
1034 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">24hrs+</span>"));
1036 rec_enabled_streams = 0;
1037 _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams);
1039 framecnt_t frames = opt_frames.get_value_or (0);
1041 if (rec_enabled_streams) {
1042 frames /= rec_enabled_streams;
1049 hrs = frames / (fr * 3600);
1052 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">>24 hrs</span>"));
1054 frames -= hrs * fr * 3600;
1055 mins = frames / (fr * 60);
1056 frames -= mins * fr * 60;
1059 bool const low = (hrs == 0 && mins <= 30);
1063 _("Disk: <span foreground=\"%s\">%02dh:%02dm:%02ds</span>"),
1064 low ? X_("red") : X_("green"),
1070 disk_space_label.set_markup (buf);
1074 ARDOUR_UI::update_timecode_format ()
1080 TimecodeSlave* tcslave;
1081 SyncSource sync_src = Config->get_sync_source();
1083 if ((sync_src == LTC || sync_src == MTC) && (tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
1084 matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
1089 snprintf (buf, sizeof (buf), S_("Timecode|TC: <span foreground=\"%s\">%s</span>"),
1090 matching ? X_("green") : X_("red"),
1091 Timecode::timecode_format_name (_session->config.get_timecode_format()).c_str());
1093 snprintf (buf, sizeof (buf), "TC: n/a");
1096 timecode_format_label.set_markup (buf);
1100 ARDOUR_UI::update_wall_clock ()
1107 tm_now = localtime (&now);
1109 sprintf (buf, "%02d:%02d", tm_now->tm_hour, tm_now->tm_min);
1110 wall_clock_label.set_text (buf);
1116 ARDOUR_UI::redisplay_recent_sessions ()
1118 std::vector<std::string> session_directories;
1119 RecentSessionsSorter cmp;
1121 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
1122 recent_session_model->clear ();
1124 ARDOUR::RecentSessions rs;
1125 ARDOUR::read_recent_sessions (rs);
1128 recent_session_display.set_model (recent_session_model);
1132 // sort them alphabetically
1133 sort (rs.begin(), rs.end(), cmp);
1135 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
1136 session_directories.push_back ((*i).second);
1139 for (vector<std::string>::const_iterator i = session_directories.begin();
1140 i != session_directories.end(); ++i)
1142 std::vector<std::string> state_file_paths;
1144 // now get available states for this session
1146 get_state_files_in_directory (*i, state_file_paths);
1148 vector<string*>* states;
1149 vector<const gchar*> item;
1150 string fullpath = *i;
1152 /* remove any trailing / */
1154 if (fullpath[fullpath.length() - 1] == '/') {
1155 fullpath = fullpath.substr (0, fullpath.length() - 1);
1158 /* check whether session still exists */
1159 if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
1160 /* session doesn't exist */
1164 /* now get available states for this session */
1166 if ((states = Session::possible_states (fullpath)) == 0) {
1167 /* no state file? */
1171 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
1173 Gtk::TreeModel::Row row = *(recent_session_model->append());
1175 row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath);
1176 row[recent_session_columns.fullpath] = fullpath;
1178 if (state_file_names.size() > 1) {
1182 for (std::vector<std::string>::iterator i2 = state_file_names.begin();
1183 i2 != state_file_names.end(); ++i2)
1186 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
1188 child_row[recent_session_columns.visible_name] = *i2;
1189 child_row[recent_session_columns.fullpath] = fullpath;
1194 recent_session_display.set_tooltip_column(1); // recent_session_columns.fullpath
1195 recent_session_display.set_model (recent_session_model);
1199 ARDOUR_UI::build_session_selector ()
1201 session_selector_window = new ArdourDialog (_("Recent Sessions"));
1203 Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow);
1205 session_selector_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1206 session_selector_window->add_button (Stock::OPEN, RESPONSE_ACCEPT);
1207 session_selector_window->set_default_response (RESPONSE_ACCEPT);
1208 recent_session_model = TreeStore::create (recent_session_columns);
1209 recent_session_display.set_model (recent_session_model);
1210 recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name);
1211 recent_session_display.set_headers_visible (false);
1212 recent_session_display.get_selection()->set_mode (SELECTION_BROWSE);
1213 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &ARDOUR_UI::recent_session_row_activated));
1215 scroller->add (recent_session_display);
1216 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1218 session_selector_window->set_name ("SessionSelectorWindow");
1219 session_selector_window->set_size_request (200, 400);
1220 session_selector_window->get_vbox()->pack_start (*scroller);
1222 recent_session_display.show();
1227 ARDOUR_UI::recent_session_row_activated (const TreePath& /*path*/, TreeViewColumn* /*col*/)
1229 session_selector_window->response (RESPONSE_ACCEPT);
1233 ARDOUR_UI::open_recent_session ()
1235 bool can_return = (_session != 0);
1237 if (session_selector_window == 0) {
1238 build_session_selector ();
1241 redisplay_recent_sessions ();
1245 session_selector_window->set_position (WIN_POS_MOUSE);
1247 ResponseType r = (ResponseType) session_selector_window->run ();
1250 case RESPONSE_ACCEPT:
1254 session_selector_window->hide();
1261 if (recent_session_display.get_selection()->count_selected_rows() == 0) {
1265 session_selector_window->hide();
1267 Gtk::TreeModel::iterator i = recent_session_display.get_selection()->get_selected();
1269 if (i == recent_session_model->children().end()) {
1273 std::string path = (*i)[recent_session_columns.fullpath];
1274 std::string state = (*i)[recent_session_columns.visible_name];
1276 _session_is_new = false;
1278 if (load_session (path, state) == 0) {
1287 ARDOUR_UI::check_audioengine ()
1290 if (!engine->connected()) {
1291 MessageDialog msg (string_compose (
1292 _("%1 is not connected to JACK\n"
1293 "You cannot open or close sessions in this condition"),
1295 pop_back_splash (msg);
1306 ARDOUR_UI::open_session ()
1308 if (!check_audioengine()) {
1313 /* popup selector window */
1315 if (open_session_selector == 0) {
1317 /* ardour sessions are folders */
1319 open_session_selector = new Gtk::FileChooserDialog (_("Open Session"), FILE_CHOOSER_ACTION_OPEN);
1320 open_session_selector->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1321 open_session_selector->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
1322 open_session_selector->set_default_response(Gtk::RESPONSE_ACCEPT);
1325 string session_parent_dir = Glib::path_get_dirname(_session->path());
1326 string::size_type last_dir_sep = session_parent_dir.rfind(G_DIR_SEPARATOR);
1327 session_parent_dir = session_parent_dir.substr(0, last_dir_sep);
1328 open_session_selector->set_current_folder(session_parent_dir);
1330 open_session_selector->set_current_folder(Config->get_default_session_parent_dir());
1333 open_session_selector->add_shortcut_folder (Config->get_default_session_parent_dir());
1335 FileFilter session_filter;
1336 session_filter.add_pattern ("*.ardour");
1337 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
1338 open_session_selector->add_filter (session_filter);
1339 open_session_selector->set_filter (session_filter);
1342 int response = open_session_selector->run();
1343 open_session_selector->hide ();
1346 case RESPONSE_ACCEPT:
1349 open_session_selector->hide();
1353 open_session_selector->hide();
1354 string session_path = open_session_selector->get_filename();
1358 if (session_path.length() > 0) {
1359 if (ARDOUR::find_session (session_path, path, name, isnew) == 0) {
1360 _session_is_new = isnew;
1361 load_session (path, name);
1368 ARDOUR_UI::session_add_mixed_track (const ChanCount& input, const ChanCount& output, RouteGroup* route_group,
1369 uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1371 list<boost::shared_ptr<MidiTrack> > tracks;
1373 if (_session == 0) {
1374 warning << _("You cannot add a track without a session already loaded.") << endmsg;
1379 tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template);
1381 if (tracks.size() != how_many) {
1382 if (how_many == 1) {
1383 error << _("could not create a new mixed track") << endmsg;
1385 error << string_compose (_("could not create %1 new mixed tracks"), how_many) << endmsg;
1391 MessageDialog msg (*editor,
1392 string_compose (_("There are insufficient JACK ports available\n\
1393 to create a new track or bus.\n\
1394 You should save %1, exit and\n\
1395 restart JACK with more ports."), PROGRAM_NAME));
1402 ARDOUR_UI::session_add_midi_route (bool disk, RouteGroup* route_group, uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1404 ChanCount one_midi_channel;
1405 one_midi_channel.set (DataType::MIDI, 1);
1408 session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, instrument);
1413 ARDOUR_UI::session_add_audio_route (
1415 int32_t input_channels,
1416 int32_t output_channels,
1417 ARDOUR::TrackMode mode,
1418 RouteGroup* route_group,
1420 string const & name_template
1423 list<boost::shared_ptr<AudioTrack> > tracks;
1426 if (_session == 0) {
1427 warning << _("You cannot add a track or bus without a session already loaded.") << endmsg;
1433 tracks = _session->new_audio_track (input_channels, output_channels, mode, route_group, how_many, name_template);
1435 if (tracks.size() != how_many) {
1436 if (how_many == 1) {
1437 error << _("could not create a new audio track") << endmsg;
1439 error << string_compose (_("could only create %1 of %2 new audio %3"),
1440 tracks.size(), how_many, (track ? _("tracks") : _("busses"))) << endmsg;
1446 routes = _session->new_audio_route (input_channels, output_channels, route_group, how_many, name_template);
1448 if (routes.size() != how_many) {
1449 if (how_many == 1) {
1450 error << _("could not create a new audio bus") << endmsg;
1452 error << string_compose (_("could not create %1 new audio busses"), how_many) << endmsg;
1459 MessageDialog msg (*editor,
1460 string_compose (_("There are insufficient JACK ports available\n\
1461 to create a new track or bus.\n\
1462 You should save %1, exit and\n\
1463 restart JACK with more ports."), PROGRAM_NAME));
1464 pop_back_splash (msg);
1470 ARDOUR_UI::transport_goto_start ()
1473 _session->goto_start();
1475 /* force displayed area in editor to start no matter
1476 what "follow playhead" setting is.
1480 editor->center_screen (_session->current_start_frame ());
1486 ARDOUR_UI::transport_goto_zero ()
1489 _session->request_locate (0);
1491 /* force displayed area in editor to start no matter
1492 what "follow playhead" setting is.
1496 editor->reset_x_origin (0);
1502 ARDOUR_UI::transport_goto_wallclock ()
1504 if (_session && editor) {
1511 localtime_r (&now, &tmnow);
1513 frames = tmnow.tm_hour * (60 * 60 * _session->frame_rate());
1514 frames += tmnow.tm_min * (60 * _session->frame_rate());
1515 frames += tmnow.tm_sec * _session->frame_rate();
1517 _session->request_locate (frames, _session->transport_rolling ());
1519 /* force displayed area in editor to start no matter
1520 what "follow playhead" setting is.
1524 editor->center_screen (frames);
1530 ARDOUR_UI::transport_goto_end ()
1533 framepos_t const frame = _session->current_end_frame();
1534 _session->request_locate (frame);
1536 /* force displayed area in editor to start no matter
1537 what "follow playhead" setting is.
1541 editor->center_screen (frame);
1547 ARDOUR_UI::transport_stop ()
1553 if (_session->is_auditioning()) {
1554 _session->cancel_audition ();
1558 _session->request_stop (false, true);
1562 ARDOUR_UI::transport_record (bool roll)
1566 switch (_session->record_status()) {
1567 case Session::Disabled:
1568 if (_session->ntracks() == 0) {
1569 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."));
1573 _session->maybe_enable_record ();
1578 case Session::Recording:
1580 _session->request_stop();
1582 _session->disable_record (false, true);
1586 case Session::Enabled:
1587 _session->disable_record (false, true);
1593 ARDOUR_UI::transport_roll ()
1599 if (_session->is_auditioning()) {
1604 if (_session->config.get_external_sync()) {
1605 switch (Config->get_sync_source()) {
1609 /* transport controlled by the master */
1615 bool rolling = _session->transport_rolling();
1617 if (_session->get_play_loop()) {
1618 /* XXX it is not possible to just leave seamless loop and keep
1619 playing at present (nov 4th 2009)
1621 if (!Config->get_seamless_loop()) {
1622 _session->request_play_loop (false, true);
1624 } else if (_session->get_play_range () && !Config->get_always_play_range()) {
1625 /* stop playing a range if we currently are */
1626 _session->request_play_range (0, true);
1630 _session->request_transport_speed (1.0f);
1635 ARDOUR_UI::get_smart_mode() const
1637 return ( editor->get_smart_mode() );
1642 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
1649 if (_session->is_auditioning()) {
1650 _session->cancel_audition ();
1654 if (_session->config.get_external_sync()) {
1655 switch (Config->get_sync_source()) {
1659 /* transport controlled by the master */
1664 bool rolling = _session->transport_rolling();
1665 bool affect_transport = true;
1667 if (rolling && roll_out_of_bounded_mode) {
1668 /* drop out of loop/range playback but leave transport rolling */
1669 if (_session->get_play_loop()) {
1670 if (Config->get_seamless_loop()) {
1671 /* the disk buffers contain copies of the loop - we can't
1672 just keep playing, so stop the transport. the user
1673 can restart as they wish.
1675 affect_transport = true;
1677 /* disk buffers are normal, so we can keep playing */
1678 affect_transport = false;
1680 _session->request_play_loop (false, true);
1681 } else if (_session->get_play_range ()) {
1682 affect_transport = false;
1683 _session->request_play_range (0, true);
1687 if (affect_transport) {
1689 _session->request_stop (with_abort, true);
1691 if ( Config->get_always_play_range() ) {
1692 _session->request_play_range (&editor->get_selection().time, true);
1695 _session->request_transport_speed (1.0f);
1701 ARDOUR_UI::toggle_session_auto_loop ()
1703 Location * looploc = _session->locations()->auto_loop_location();
1705 if (!_session || !looploc) {
1709 if (_session->get_play_loop()) {
1711 if (_session->transport_rolling()) {
1713 _session->request_locate (looploc->start(), true);
1714 _session->request_play_loop (false);
1717 _session->request_play_loop (false);
1720 _session->request_play_loop (true);
1723 //show the loop markers
1724 looploc->set_hidden (false, this);
1728 ARDOUR_UI::transport_play_selection ()
1734 editor->play_selection ();
1738 ARDOUR_UI::transport_play_preroll ()
1743 editor->play_with_preroll ();
1747 ARDOUR_UI::transport_rewind (int option)
1749 float current_transport_speed;
1752 current_transport_speed = _session->transport_speed();
1754 if (current_transport_speed >= 0.0f) {
1757 _session->request_transport_speed (-1.0f);
1760 _session->request_transport_speed (-4.0f);
1763 _session->request_transport_speed (-0.5f);
1768 _session->request_transport_speed (current_transport_speed * 1.5f);
1774 ARDOUR_UI::transport_forward (int option)
1780 float current_transport_speed = _session->transport_speed();
1782 if (current_transport_speed <= 0.0f) {
1785 _session->request_transport_speed (1.0f);
1788 _session->request_transport_speed (4.0f);
1791 _session->request_transport_speed (0.5f);
1796 _session->request_transport_speed (current_transport_speed * 1.5f);
1801 ARDOUR_UI::toggle_record_enable (uint32_t rid)
1807 boost::shared_ptr<Route> r;
1809 if ((r = _session->route_by_remote_id (rid)) != 0) {
1813 if ((t = dynamic_cast<Track*>(r.get())) != 0) {
1814 t->set_record_enabled (!t->record_enabled(), this);
1820 ARDOUR_UI::map_transport_state ()
1823 auto_loop_button.unset_active_state ();
1824 play_selection_button.unset_active_state ();
1825 roll_button.unset_active_state ();
1826 stop_button.set_active_state (Gtkmm2ext::ExplicitActive);
1830 shuttle_box->map_transport_state ();
1832 float sp = _session->transport_speed();
1838 if (_session->get_play_range()) {
1840 play_selection_button.set_active_state (Gtkmm2ext::ExplicitActive);
1841 roll_button.unset_active_state ();
1842 auto_loop_button.unset_active_state ();
1844 } else if (_session->get_play_loop ()) {
1846 auto_loop_button.set_active (true);
1847 play_selection_button.set_active (false);
1848 roll_button.set_active (false);
1852 roll_button.set_active (true);
1853 play_selection_button.set_active (false);
1854 auto_loop_button.set_active (false);
1857 if (Config->get_always_play_range()) {
1858 /* light up both roll and play-selection if they are joined */
1859 roll_button.set_active (true);
1860 play_selection_button.set_active (true);
1863 stop_button.set_active (false);
1867 stop_button.set_active (true);
1868 roll_button.set_active (false);
1869 play_selection_button.set_active (false);
1870 auto_loop_button.set_active (false);
1871 update_disk_space ();
1876 ARDOUR_UI::engine_stopped ()
1878 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_stopped)
1879 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, false);
1880 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, true);
1884 ARDOUR_UI::engine_running ()
1886 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_running)
1887 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, true);
1888 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, false);
1890 Glib::RefPtr<Action> action;
1891 const char* action_name = 0;
1893 switch (engine->frames_per_cycle()) {
1895 action_name = X_("JACKLatency32");
1898 action_name = X_("JACKLatency64");
1901 action_name = X_("JACKLatency128");
1904 action_name = X_("JACKLatency512");
1907 action_name = X_("JACKLatency1024");
1910 action_name = X_("JACKLatency2048");
1913 action_name = X_("JACKLatency4096");
1916 action_name = X_("JACKLatency8192");
1919 /* XXX can we do anything useful ? */
1925 action = ActionManager::get_action (X_("JACK"), action_name);
1928 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (action);
1929 ract->set_active ();
1935 ARDOUR_UI::engine_halted (const char* reason, bool free_reason)
1937 if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
1938 /* we can't rely on the original string continuing to exist when we are called
1939 again in the GUI thread, so make a copy and note that we need to
1942 char *copy = strdup (reason);
1943 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ARDOUR_UI::engine_halted, this, copy, true));
1947 ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, false);
1948 ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, true);
1950 update_sample_rate (0);
1954 /* if the reason is a non-empty string, it means that the backend was shutdown
1955 rather than just Ardour.
1958 if (strlen (reason)) {
1959 msgstr = string_compose (_("The audio backend (JACK) was shutdown because:\n\n%1"), reason);
1961 msgstr = string_compose (_("\
1962 JACK has either been shutdown or it\n\
1963 disconnected %1 because %1\n\
1964 was not fast enough. Try to restart\n\
1965 JACK, reconnect and save the session."), PROGRAM_NAME);
1968 MessageDialog msg (*editor, msgstr);
1969 pop_back_splash (msg);
1973 free (const_cast<char*> (reason));
1978 ARDOUR_UI::do_engine_start ()
1986 error << _("Unable to start the session running")
1996 ARDOUR_UI::update_clocks ()
1998 if (!editor || !editor->dragging_playhead()) {
1999 Clock (_session->audible_frame(), false, editor->get_preferred_edit_position()); /* EMIT_SIGNAL */
2004 ARDOUR_UI::start_clocking ()
2006 clock_signal_connection = RapidScreenUpdate.connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2010 ARDOUR_UI::stop_clocking ()
2012 clock_signal_connection.disconnect ();
2016 ARDOUR_UI::_blink (void *arg)
2018 ((ARDOUR_UI *) arg)->blink ();
2025 Blink (blink_on = !blink_on); /* EMIT_SIGNAL */
2029 ARDOUR_UI::start_blinking ()
2031 /* Start the blink signal. Everybody with a blinking widget
2032 uses Blink to drive the widget's state.
2035 if (blink_timeout_tag < 0) {
2037 blink_timeout_tag = g_timeout_add (240, _blink, this);
2042 ARDOUR_UI::stop_blinking ()
2044 if (blink_timeout_tag >= 0) {
2045 g_source_remove (blink_timeout_tag);
2046 blink_timeout_tag = -1;
2051 /** Ask the user for the name of a new snapshot and then take it.
2055 ARDOUR_UI::snapshot_session (bool switch_to_it)
2057 ArdourPrompter prompter (true);
2060 prompter.set_name ("Prompter");
2061 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2062 prompter.set_title (_("Take Snapshot"));
2063 prompter.set_prompt (_("Name of new snapshot"));
2065 if (!switch_to_it) {
2068 struct tm local_time;
2071 localtime_r (&n, &local_time);
2072 strftime (timebuf, sizeof(timebuf), "%FT%H.%M.%S", &local_time);
2073 prompter.set_initial_text (timebuf);
2077 switch (prompter.run()) {
2078 case RESPONSE_ACCEPT:
2080 prompter.get_result (snapname);
2082 bool do_save = (snapname.length() != 0);
2085 char illegal = Session::session_name_is_legal(snapname);
2087 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2088 "snapshot names may not contain a '%1' character"), illegal));
2094 vector<std::string> p;
2095 get_state_files_in_directory (_session->session_directory().root_path(), p);
2096 vector<string> n = get_file_names_no_extension (p);
2097 if (find (n.begin(), n.end(), snapname) != n.end()) {
2099 ArdourDialog confirm (_("Confirm Snapshot Overwrite"), true);
2100 Label m (_("A snapshot already exists with that name. Do you want to overwrite it?"));
2101 confirm.get_vbox()->pack_start (m, true, true);
2102 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2103 confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
2104 confirm.show_all ();
2105 switch (confirm.run()) {
2106 case RESPONSE_CANCEL:
2112 save_state (snapname, switch_to_it);
2122 /** Ask the user for a new session name and then rename the session to it.
2126 ARDOUR_UI::rename_session ()
2132 ArdourPrompter prompter (true);
2135 prompter.set_name ("Prompter");
2136 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2137 prompter.set_title (_("Rename Session"));
2138 prompter.set_prompt (_("New session name"));
2141 switch (prompter.run()) {
2142 case RESPONSE_ACCEPT:
2144 prompter.get_result (name);
2146 bool do_rename = (name.length() != 0);
2149 char illegal = Session::session_name_is_legal (name);
2152 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2153 "session names may not contain a '%1' character"), illegal));
2158 switch (_session->rename (name)) {
2160 MessageDialog msg (_("That name is already in use by another directory/folder. Please try again."));
2161 msg.set_position (WIN_POS_MOUSE);
2169 MessageDialog msg (_("Renaming this session failed.\nThings could be seriously messed up at this point"));
2170 msg.set_position (WIN_POS_MOUSE);
2186 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
2188 XMLNode* node = new XMLNode (X_("UI"));
2190 for (list<WindowProxyBase*>::iterator i = _window_proxies.begin(); i != _window_proxies.end(); ++i) {
2191 if (!(*i)->rc_configured()) {
2192 node->add_child_nocopy (*((*i)->get_state ()));
2196 node->add_child_nocopy (gui_object_state->get_state());
2198 _session->add_extra_xml (*node);
2200 save_state_canfail (name, switch_to_it);
2204 ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
2209 if (name.length() == 0) {
2210 name = _session->snap_name();
2213 if ((ret = _session->save_state (name, false, switch_to_it)) != 0) {
2218 save_ardour_state (); /* XXX cannot fail? yeah, right ... */
2223 ARDOUR_UI::primary_clock_value_changed ()
2226 _session->request_locate (primary_clock->current_time ());
2231 ARDOUR_UI::big_clock_value_changed ()
2234 _session->request_locate (big_clock->current_time ());
2239 ARDOUR_UI::secondary_clock_value_changed ()
2242 _session->request_locate (secondary_clock->current_time ());
2247 ARDOUR_UI::transport_rec_enable_blink (bool onoff)
2249 if (_session == 0) {
2253 if (_session->step_editing()) {
2257 Session::RecordState const r = _session->record_status ();
2258 bool const h = _session->have_rec_enabled_track ();
2260 if (r == Session::Enabled || (r == Session::Recording && !h)) {
2262 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2264 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
2266 } else if (r == Session::Recording && h) {
2267 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2269 rec_button.unset_active_state ();
2274 ARDOUR_UI::save_template ()
2276 ArdourPrompter prompter (true);
2279 if (!check_audioengine()) {
2283 prompter.set_name (X_("Prompter"));
2284 prompter.set_title (_("Save Template"));
2285 prompter.set_prompt (_("Name for template:"));
2286 prompter.set_initial_text(_session->name() + _("-template"));
2287 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2289 switch (prompter.run()) {
2290 case RESPONSE_ACCEPT:
2291 prompter.get_result (name);
2293 if (name.length()) {
2294 _session->save_template (name);
2304 ARDOUR_UI::edit_metadata ()
2306 SessionMetadataEditor dialog;
2307 dialog.set_session (_session);
2308 editor->ensure_float (dialog);
2313 ARDOUR_UI::import_metadata ()
2315 SessionMetadataImporter dialog;
2316 dialog.set_session (_session);
2317 editor->ensure_float (dialog);
2322 ARDOUR_UI::ask_about_loading_existing_session (const std::string& session_path)
2324 std::string str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
2326 MessageDialog msg (str,
2328 Gtk::MESSAGE_WARNING,
2329 Gtk::BUTTONS_YES_NO,
2333 msg.set_name (X_("OpenExistingDialog"));
2334 msg.set_title (_("Open Existing Session"));
2335 msg.set_wmclass (X_("existing_session"), PROGRAM_NAME);
2336 msg.set_position (Gtk::WIN_POS_MOUSE);
2337 pop_back_splash (msg);
2339 switch (msg.run()) {
2348 ARDOUR_UI::build_session_from_nsd (const std::string& session_path, const std::string& session_name)
2350 BusProfile bus_profile;
2352 if (Profile->get_sae()) {
2354 bus_profile.master_out_channels = 2;
2355 bus_profile.input_ac = AutoConnectPhysical;
2356 bus_profile.output_ac = AutoConnectMaster;
2357 bus_profile.requested_physical_in = 0; // use all available
2358 bus_profile.requested_physical_out = 0; // use all available
2362 /* get settings from advanced section of NSD */
2364 if (_startup->create_master_bus()) {
2365 bus_profile.master_out_channels = (uint32_t) _startup->master_channel_count();
2367 bus_profile.master_out_channels = 0;
2370 if (_startup->connect_inputs()) {
2371 bus_profile.input_ac = AutoConnectPhysical;
2373 bus_profile.input_ac = AutoConnectOption (0);
2376 bus_profile.output_ac = AutoConnectOption (0);
2378 if (_startup->connect_outputs ()) {
2379 if (_startup->connect_outs_to_master()) {
2380 bus_profile.output_ac = AutoConnectMaster;
2381 } else if (_startup->connect_outs_to_physical()) {
2382 bus_profile.output_ac = AutoConnectPhysical;
2386 bus_profile.requested_physical_in = (uint32_t) _startup->input_limit_count();
2387 bus_profile.requested_physical_out = (uint32_t) _startup->output_limit_count();
2390 if (build_session (session_path, session_name, bus_profile)) {
2398 ARDOUR_UI::idle_load (const std::string& path)
2401 if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
2402 /* /path/to/foo => /path/to/foo, foo */
2403 load_session (path, basename_nosuffix (path));
2405 /* /path/to/foo/foo.ardour => /path/to/foo, foo */
2406 load_session (Glib::path_get_dirname (path), basename_nosuffix (path));
2410 ARDOUR_COMMAND_LINE::session_name = path;
2414 /** @param quit_on_cancel true if exit() should be called if the user clicks `cancel' in the new session dialog */
2416 ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, string load_template)
2418 string session_name;
2419 string session_path;
2420 string template_name;
2422 bool likely_new = false;
2424 /* deal with any existing DIRTY session now, rather than later. don't
2425 * treat a non-dirty session this way, so that it stays visible
2426 * as we bring up the new session dialog.
2429 if (_session && _session->dirty()) {
2430 if (unload_session (false)) {
2431 /* unload cancelled by user */
2434 ARDOUR_COMMAND_LINE::session_name = "";
2437 if (!load_template.empty()) {
2438 should_be_new = true;
2439 template_name = load_template;
2444 if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
2446 /* if they named a specific statefile, use it, otherwise they are
2447 just giving a session folder, and we want to use it as is
2448 to find the session.
2451 string::size_type suffix = ARDOUR_COMMAND_LINE::session_name.find (statefile_suffix);
2453 if (suffix != string::npos) {
2454 session_path = Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name);
2455 session_name = ARDOUR_COMMAND_LINE::session_name.substr (0, suffix);
2456 session_name = Glib::path_get_basename (session_name);
2458 session_path = ARDOUR_COMMAND_LINE::session_name;
2459 session_name = Glib::path_get_basename (ARDOUR_COMMAND_LINE::session_name);
2467 _startup = new ArdourStartup (should_be_new, session_name, session_path, load_template);
2469 if (!_startup->ready_without_display()) {
2470 _startup->present ();
2475 switch (_startup->response()) {
2479 if (quit_on_cancel) {
2486 /* if we run the startup dialog again, offer more than just "new session" */
2488 should_be_new = false;
2490 session_name = _startup->session_name (likely_new);
2492 string::size_type suffix = session_name.find (statefile_suffix);
2494 if (suffix != string::npos) {
2495 session_name = session_name.substr (0, suffix);
2498 /* this shouldn't happen, but we catch it just in case it does */
2500 if (session_name.empty()) {
2504 if (_startup->use_session_template()) {
2505 template_name = _startup->session_template_name();
2506 _session_is_new = true;
2509 if (session_name[0] == G_DIR_SEPARATOR ||
2510 (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == G_DIR_SEPARATOR) ||
2511 (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == G_DIR_SEPARATOR)) {
2513 /* absolute path or cwd-relative path specified for session name: infer session folder
2514 from what was given.
2517 session_path = Glib::path_get_dirname (session_name);
2518 session_name = Glib::path_get_basename (session_name);
2522 session_path = _startup->session_folder();
2524 char illegal = Session::session_name_is_legal (session_name);
2527 MessageDialog msg (*_startup,
2528 string_compose (_("To ensure compatibility with various systems\n"
2529 "session names may not contain a '%1' character"),
2532 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2537 if (create_engine ()) {
2541 if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
2545 std::string existing = Glib::build_filename (session_path, session_name);
2547 if (!ask_about_loading_existing_session (existing)) {
2548 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2553 _session_is_new = false;
2559 pop_back_splash (*_startup);
2564 MessageDialog msg (string_compose (_("There is no existing session at \"%1\""), session_path));
2566 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2570 char illegal = Session::session_name_is_legal(session_name);
2572 pop_back_splash (*_startup);
2573 MessageDialog msg (*_startup, string_compose(_("To ensure compatibility with various systems\n"
2574 "session names may not contain a '%1' character"), illegal));
2576 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
2580 _session_is_new = true;
2583 if (likely_new && template_name.empty()) {
2585 ret = build_session_from_nsd (session_path, session_name);
2589 ret = load_session (session_path, session_name, template_name);
2592 /* not connected to the AudioEngine, so quit to avoid an infinite loop */
2596 if (!ARDOUR_COMMAND_LINE::immediate_save.empty()) {
2597 _session->save_state (ARDOUR_COMMAND_LINE::immediate_save, false);
2607 ARDOUR_UI::close_session()
2609 if (!check_audioengine()) {
2613 if (unload_session (true)) {
2617 ARDOUR_COMMAND_LINE::session_name = "";
2619 if (get_session_parameters (true, false)) {
2623 goto_editor_window ();
2626 /** @param snap_name Snapshot name (without .ardour suffix).
2627 * @return -2 if the load failed because we are not connected to the AudioEngine.
2630 ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name, std::string mix_template)
2632 Session *new_session;
2636 session_loaded = false;
2638 if (!check_audioengine()) {
2642 unload_status = unload_session ();
2644 if (unload_status < 0) {
2646 } else if (unload_status > 0) {
2651 loading_message (string_compose (_("Please wait while %1 loads your session"), PROGRAM_NAME));
2654 new_session = new Session (*engine, path, snap_name, 0, mix_template);
2657 /* this one is special */
2659 catch (AudioEngine::PortRegistrationFailure& err) {
2661 MessageDialog msg (err.what(),
2664 Gtk::BUTTONS_CLOSE);
2666 msg.set_title (_("Port Registration Error"));
2667 msg.set_secondary_text (_("Click the Close button to try again."));
2668 msg.set_position (Gtk::WIN_POS_CENTER);
2669 pop_back_splash (msg);
2672 int response = msg.run ();
2677 case RESPONSE_CANCEL:
2687 MessageDialog msg (string_compose(
2688 _("Session \"%1 (snapshot %2)\" did not load successfully"),
2694 msg.set_title (_("Loading Error"));
2695 msg.set_secondary_text (_("Click the Refresh button to try again."));
2696 msg.add_button (Stock::REFRESH, 1);
2697 msg.set_position (Gtk::WIN_POS_CENTER);
2698 pop_back_splash (msg);
2701 int response = msg.run ();
2716 list<string> const u = new_session->unknown_processors ();
2718 MissingPluginDialog d (_session, u);
2723 /* Now the session been created, add the transport controls */
2724 new_session->add_controllable(roll_controllable);
2725 new_session->add_controllable(stop_controllable);
2726 new_session->add_controllable(goto_start_controllable);
2727 new_session->add_controllable(goto_end_controllable);
2728 new_session->add_controllable(auto_loop_controllable);
2729 new_session->add_controllable(play_selection_controllable);
2730 new_session->add_controllable(rec_controllable);
2732 set_session (new_session);
2734 session_loaded = true;
2736 goto_editor_window ();
2739 _session->set_clean ();
2750 ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name, BusProfile& bus_profile)
2752 Session *new_session;
2755 if (!check_audioengine()) {
2759 session_loaded = false;
2761 x = unload_session ();
2769 _session_is_new = true;
2772 new_session = new Session (*engine, path, snap_name, &bus_profile);
2777 MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
2778 pop_back_splash (msg);
2783 /* Give the new session the default GUI state, if such things exist */
2786 n = Config->instant_xml (X_("Editor"));
2788 new_session->add_instant_xml (*n, false);
2790 n = Config->instant_xml (X_("Mixer"));
2792 new_session->add_instant_xml (*n, false);
2795 /* Put the playhead at 0 and scroll fully left */
2796 n = new_session->instant_xml (X_("Editor"));
2798 n->add_property (X_("playhead"), X_("0"));
2799 n->add_property (X_("left-frame"), X_("0"));
2802 set_session (new_session);
2804 session_loaded = true;
2806 new_session->save_state(new_session->name());
2812 ARDOUR_UI::launch_chat ()
2815 open_uri("http://webchat.freenode.net/?channels=ardour-osx");
2817 open_uri("http://webchat.freenode.net/?channels=ardour");
2822 ARDOUR_UI::show_about ()
2826 about->signal_response().connect (sigc::mem_fun (*this, &ARDOUR_UI::about_signal_response));
2829 about->set_transient_for(*editor);
2834 ARDOUR_UI::launch_manual ()
2836 PBD::open_uri("http://ardour.org/flossmanual");
2840 ARDOUR_UI::launch_reference ()
2842 PBD::open_uri ("http://ardour.org/refmanual");
2846 ARDOUR_UI::hide_about ()
2849 about->get_window()->set_cursor ();
2855 ARDOUR_UI::about_signal_response (int /*response*/)
2861 ARDOUR_UI::loading_message (const std::string& msg)
2863 if (ARDOUR_COMMAND_LINE::no_splash) {
2871 splash->message (msg);
2875 ARDOUR_UI::show_splash ()
2879 splash = new Splash;
2889 ARDOUR_UI::hide_splash ()
2896 ARDOUR_UI::display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
2897 const string& plural_msg, const string& singular_msg)
2901 removed = rep.paths.size();
2904 MessageDialog msgd (*editor,
2905 _("No files were ready for clean-up"),
2909 msgd.set_title (_("Clean-up"));
2910 msgd.set_secondary_text (_("If this seems suprising, \n\
2911 check for any existing snapshots.\n\
2912 These may still include regions that\n\
2913 require some unused files to continue to exist."));
2919 ArdourDialog results (_("Clean-up"), true, false);
2921 struct CleanupResultsModelColumns : public Gtk::TreeModel::ColumnRecord {
2922 CleanupResultsModelColumns() {
2926 Gtk::TreeModelColumn<std::string> visible_name;
2927 Gtk::TreeModelColumn<std::string> fullpath;
2931 CleanupResultsModelColumns results_columns;
2932 Glib::RefPtr<Gtk::ListStore> results_model;
2933 Gtk::TreeView results_display;
2935 results_model = ListStore::create (results_columns);
2936 results_display.set_model (results_model);
2937 results_display.append_column (list_title, results_columns.visible_name);
2939 results_display.set_name ("CleanupResultsList");
2940 results_display.set_headers_visible (true);
2941 results_display.set_headers_clickable (false);
2942 results_display.set_reorderable (false);
2944 Gtk::ScrolledWindow list_scroller;
2947 Gtk::HBox dhbox; // the hbox for the image and text
2948 Gtk::HBox ddhbox; // the hbox we eventually pack into the dialog's vbox
2949 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_INFO, Gtk::ICON_SIZE_DIALOG));
2951 dimage->set_alignment(ALIGN_LEFT, ALIGN_TOP);
2953 const string dead_directory = _session->session_directory().dead_path();
2956 %1 - number of files removed
2957 %2 - location of "dead"
2958 %3 - size of files affected
2959 %4 - prefix for "bytes" to produce sensible results (e.g. mega, kilo, giga)
2962 const char* bprefix;
2963 double space_adjusted = 0;
2965 if (rep.space < 1000) {
2967 space_adjusted = rep.space;
2968 } else if (rep.space < 1000000) {
2969 bprefix = _("kilo");
2970 space_adjusted = truncf((float)rep.space / 1000.0);
2971 } else if (rep.space < 1000000 * 1000) {
2972 bprefix = _("mega");
2973 space_adjusted = truncf((float)rep.space / (1000.0 * 1000.0));
2975 bprefix = _("giga");
2976 space_adjusted = truncf((float)rep.space / (1000.0 * 1000 * 1000.0));
2980 txt.set_markup (string_compose (plural_msg, removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
2982 txt.set_markup (string_compose (singular_msg, removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
2985 dhbox.pack_start (*dimage, true, false, 5);
2986 dhbox.pack_start (txt, true, false, 5);
2988 for (vector<string>::iterator i = rep.paths.begin(); i != rep.paths.end(); ++i) {
2989 TreeModel::Row row = *(results_model->append());
2990 row[results_columns.visible_name] = *i;
2991 row[results_columns.fullpath] = *i;
2994 list_scroller.add (results_display);
2995 list_scroller.set_size_request (-1, 150);
2996 list_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
2998 dvbox.pack_start (dhbox, true, false, 5);
2999 dvbox.pack_start (list_scroller, true, false, 5);
3000 ddhbox.pack_start (dvbox, true, false, 5);
3002 results.get_vbox()->pack_start (ddhbox, true, false, 5);
3003 results.add_button (Stock::CLOSE, RESPONSE_CLOSE);
3004 results.set_default_response (RESPONSE_CLOSE);
3005 results.set_position (Gtk::WIN_POS_MOUSE);
3007 results_display.show();
3008 list_scroller.show();
3015 //results.get_vbox()->show();
3016 results.set_resizable (false);
3023 ARDOUR_UI::cleanup ()
3025 if (_session == 0) {
3026 /* shouldn't happen: menu item is insensitive */
3031 MessageDialog checker (_("Are you sure you want to clean-up?"),
3033 Gtk::MESSAGE_QUESTION,
3036 checker.set_title (_("Clean-up"));
3038 checker.set_secondary_text(_("Clean-up is a destructive operation.\n\
3039 ALL undo/redo information will be lost if you clean-up.\n\
3040 Clean-up will move all unused files to a \"dead\" location."));
3042 checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3043 checker.add_button (_("Clean-up"), RESPONSE_ACCEPT);
3044 checker.set_default_response (RESPONSE_CANCEL);
3046 checker.set_name (_("CleanupDialog"));
3047 checker.set_wmclass (X_("ardour_cleanup"), PROGRAM_NAME);
3048 checker.set_position (Gtk::WIN_POS_MOUSE);
3050 switch (checker.run()) {
3051 case RESPONSE_ACCEPT:
3057 ARDOUR::CleanupReport rep;
3059 editor->prepare_for_cleanup ();
3061 /* do not allow flush until a session is reloaded */
3063 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
3065 act->set_sensitive (false);
3068 if (_session->cleanup_sources (rep)) {
3069 editor->finish_cleanup ();
3073 editor->finish_cleanup ();
3076 display_cleanup_results (rep,
3079 The following %1 files were not in use and \n\
3080 have been moved to: %2\n\n\
3081 After a restart of %5\n\n\
3082 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3083 will release an additional %3 %4bytes of disk space.\n"),
3085 The following file was not in use and \n\
3086 has been moved to: %2\n\n\
3087 After a restart of %5\n\n\
3088 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3089 will release an additional %3 %4bytes of disk space.\n"
3095 ARDOUR_UI::flush_trash ()
3097 if (_session == 0) {
3098 /* shouldn't happen: menu item is insensitive */
3102 ARDOUR::CleanupReport rep;
3104 if (_session->cleanup_trash_sources (rep)) {
3108 display_cleanup_results (rep,
3110 _("The following %1 files were deleted from %2,\n\
3111 releasing %3 %4bytes of disk space"),
3112 _("The following file was deleted from %2,\n\
3113 releasing %3 %4bytes of disk space"));
3117 ARDOUR_UI::add_route (Gtk::Window* float_window)
3125 if (add_route_dialog == 0) {
3126 add_route_dialog = new AddRouteDialog (_session);
3127 add_route_dialog->set_position (WIN_POS_MOUSE);
3129 add_route_dialog->set_transient_for (*float_window);
3133 if (add_route_dialog->is_visible()) {
3134 /* we're already doing this */
3138 ResponseType r = (ResponseType) add_route_dialog->run ();
3140 add_route_dialog->hide();
3143 case RESPONSE_ACCEPT:
3150 if ((count = add_route_dialog->count()) <= 0) {
3154 PBD::ScopedConnection idle_connection;
3157 ARDOUR::GUIIdle.connect (idle_connection, MISSING_INVALIDATOR, boost::bind (&Gtkmm2ext::UI::flush_pending, this), gui_context());
3160 string template_path = add_route_dialog->track_template();
3162 if (!template_path.empty()) {
3163 _session->new_route_from_template (count, template_path);
3167 ChanCount input_chan= add_route_dialog->channels ();
3168 ChanCount output_chan;
3169 string name_template = add_route_dialog->name_template ();
3170 PluginInfoPtr instrument = add_route_dialog->requested_instrument ();
3171 RouteGroup* route_group = add_route_dialog->route_group ();
3172 AutoConnectOption oac = Config->get_output_auto_connect();
3174 if (oac & AutoConnectMaster) {
3175 output_chan.set (DataType::AUDIO, (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan.n_audio()));
3176 output_chan.set (DataType::MIDI, 0);
3178 output_chan = input_chan;
3181 /* XXX do something with name template */
3183 switch (add_route_dialog->type_wanted()) {
3184 case AddRouteDialog::AudioTrack:
3185 session_add_audio_track (input_chan.n_audio(), output_chan.n_audio(), add_route_dialog->mode(), route_group, count, name_template);
3187 case AddRouteDialog::MidiTrack:
3188 session_add_midi_track (route_group, count, name_template, instrument);
3190 case AddRouteDialog::MixedTrack:
3191 session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, instrument);
3193 case AddRouteDialog::AudioBus:
3194 session_add_audio_bus (input_chan.n_audio(), output_chan.n_audio(), route_group, count, name_template);
3198 /* idle connection will end at scope end */
3202 ARDOUR_UI::mixer_settings () const
3207 node = _session->instant_xml(X_("Mixer"));
3209 node = Config->instant_xml(X_("Mixer"));
3213 node = new XMLNode (X_("Mixer"));
3220 ARDOUR_UI::editor_settings () const
3225 node = _session->instant_xml(X_("Editor"));
3227 node = Config->instant_xml(X_("Editor"));
3231 if (getenv("ARDOUR_INSTANT_XML_PATH")) {
3232 node = Config->instant_xml(getenv("ARDOUR_INSTANT_XML_PATH"));
3237 node = new XMLNode (X_("Editor"));
3244 ARDOUR_UI::keyboard_settings () const
3248 node = Config->extra_xml(X_("Keyboard"));
3251 node = new XMLNode (X_("Keyboard"));
3258 ARDOUR_UI::create_xrun_marker (framepos_t where)
3260 editor->mouse_add_new_marker (where, false, true);
3264 ARDOUR_UI::halt_on_xrun_message ()
3266 MessageDialog msg (*editor,
3267 _("Recording was stopped because your system could not keep up."));
3272 ARDOUR_UI::xrun_handler (framepos_t where)
3278 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::xrun_handler, where)
3280 if (_session && Config->get_create_xrun_marker() && _session->actively_recording()) {
3281 create_xrun_marker(where);
3284 if (_session && Config->get_stop_recording_on_xrun() && _session->actively_recording()) {
3285 halt_on_xrun_message ();
3290 ARDOUR_UI::disk_overrun_handler ()
3292 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_overrun_handler)
3294 if (!have_disk_speed_dialog_displayed) {
3295 have_disk_speed_dialog_displayed = true;
3296 MessageDialog* msg = new MessageDialog (*editor, string_compose (_("\
3297 The disk system on your computer\n\
3298 was not able to keep up with %1.\n\
3300 Specifically, it failed to write data to disk\n\
3301 quickly enough to keep up with recording.\n"), PROGRAM_NAME));
3302 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3308 ARDOUR_UI::disk_underrun_handler ()
3310 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_underrun_handler)
3312 if (!have_disk_speed_dialog_displayed) {
3313 have_disk_speed_dialog_displayed = true;
3314 MessageDialog* msg = new MessageDialog (
3315 *editor, string_compose (_("The disk system on your computer\n\
3316 was not able to keep up with %1.\n\
3318 Specifically, it failed to read data from disk\n\
3319 quickly enough to keep up with playback.\n"), PROGRAM_NAME));
3320 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
3326 ARDOUR_UI::disk_speed_dialog_gone (int /*ignored_response*/, MessageDialog* msg)
3328 have_disk_speed_dialog_displayed = false;
3333 ARDOUR_UI::session_dialog (std::string msg)
3335 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::session_dialog, msg)
3340 d = new MessageDialog (*editor, msg, false, MESSAGE_INFO, BUTTONS_OK, true);
3342 d = new MessageDialog (msg, false, MESSAGE_INFO, BUTTONS_OK, true);
3351 ARDOUR_UI::pending_state_dialog ()
3353 HBox* hbox = new HBox();
3354 Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
3355 ArdourDialog dialog (_("Crash Recovery"), true);
3356 Label message (string_compose (_("\
3357 This session appears to have been in\n\
3358 middle of recording when ardour or\n\
3359 the computer was shutdown.\n\
3361 %1 can recover any captured audio for\n\
3362 you, or it can ignore it. Please decide\n\
3363 what you would like to do.\n"), PROGRAM_NAME));
3364 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
3365 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
3366 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
3367 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
3368 dialog.add_button (_("Ignore crash data"), RESPONSE_REJECT);
3369 dialog.add_button (_("Recover from crash"), RESPONSE_ACCEPT);
3370 dialog.set_default_response (RESPONSE_ACCEPT);
3371 dialog.set_position (WIN_POS_CENTER);
3376 switch (dialog.run ()) {
3377 case RESPONSE_ACCEPT:
3385 ARDOUR_UI::sr_mismatch_dialog (framecnt_t desired, framecnt_t actual)
3387 HBox* hbox = new HBox();
3388 Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
3389 ArdourDialog dialog (_("Sample Rate Mismatch"), true);
3390 Label message (string_compose (_("\
3391 This session was created with a sample rate of %1 Hz, but\n\
3392 %2 is currently running at %3 Hz. If you load this session,\n\
3393 audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual));
3395 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
3396 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
3397 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
3398 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
3399 dialog.add_button (_("Do not load session"), RESPONSE_REJECT);
3400 dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT);
3401 dialog.set_default_response (RESPONSE_ACCEPT);
3402 dialog.set_position (WIN_POS_CENTER);
3407 switch (dialog.run ()) {
3408 case RESPONSE_ACCEPT:
3417 ARDOUR_UI::disconnect_from_jack ()
3420 if (engine->disconnect_from_jack ()) {
3421 MessageDialog msg (*editor, _("Could not disconnect from JACK"));
3425 update_sample_rate (0);
3430 ARDOUR_UI::reconnect_to_jack ()
3433 if (engine->reconnect_to_jack ()) {
3434 MessageDialog msg (*editor, _("Could not reconnect to JACK"));
3438 update_sample_rate (0);
3443 ARDOUR_UI::use_config ()
3445 XMLNode* node = Config->extra_xml (X_("TransportControllables"));
3447 set_transport_controllable_state (*node);
3452 ARDOUR_UI::update_transport_clocks (framepos_t pos)
3454 if (Config->get_primary_clock_delta_edit_cursor()) {
3455 primary_clock->set (pos, false, editor->get_preferred_edit_position());
3457 primary_clock->set (pos);
3460 if (Config->get_secondary_clock_delta_edit_cursor()) {
3461 secondary_clock->set (pos, false, editor->get_preferred_edit_position());
3463 secondary_clock->set (pos);
3466 if (big_clock_window->get()) {
3467 big_clock->set (pos);
3473 ARDOUR_UI::step_edit_status_change (bool yn)
3475 // XXX should really store pre-step edit status of things
3476 // we make insensitive
3479 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
3480 rec_button.set_sensitive (false);
3482 rec_button.unset_active_state ();;
3483 rec_button.set_sensitive (true);
3488 ARDOUR_UI::record_state_changed ()
3490 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);
3492 if (!_session || !big_clock_window->get()) {
3493 /* why bother - the clock isn't visible */
3497 if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
3498 big_clock->set_active (true);
3500 big_clock->set_active (false);
3505 ARDOUR_UI::first_idle ()
3508 _session->allow_auto_play (true);
3512 editor->first_idle();
3515 Keyboard::set_can_save_keybindings (true);
3520 ARDOUR_UI::store_clock_modes ()
3522 XMLNode* node = new XMLNode(X_("ClockModes"));
3524 for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
3525 XMLNode* child = new XMLNode (X_("Clock"));
3527 child->add_property (X_("name"), (*x)->name());
3528 child->add_property (X_("mode"), enum_2_string ((*x)->mode()));
3529 child->add_property (X_("on"), ((*x)->off() ? X_("no") : X_("yes")));
3531 node->add_child_nocopy (*child);
3534 _session->add_extra_xml (*node);
3535 _session->set_dirty ();
3538 ARDOUR_UI::TransportControllable::TransportControllable (std::string name, ARDOUR_UI& u, ToggleType tp)
3539 : Controllable (name), ui (u), type(tp)
3545 ARDOUR_UI::TransportControllable::set_value (double val)
3548 /* do nothing: these are radio-style actions */
3552 const char *action = 0;
3556 action = X_("Roll");
3559 action = X_("Stop");
3562 action = X_("GotoStart");
3565 action = X_("GotoEnd");
3568 action = X_("Loop");
3571 action = X_("PlaySelection");
3574 action = X_("Record");
3584 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", action);
3592 ARDOUR_UI::TransportControllable::get_value (void) const
3619 ARDOUR_UI::setup_profile ()
3621 if (gdk_screen_width() < 1200 || getenv ("ARDOUR_NARROW_SCREEN")) {
3622 Profile->set_small_screen ();
3625 if (getenv ("ARDOUR_SAE")) {
3626 Profile->set_sae ();
3627 Profile->set_single_package ();
3632 ARDOUR_UI::toggle_translations ()
3634 using namespace Glib;
3636 RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("EnableTranslation"));
3638 RefPtr<ToggleAction> ract = RefPtr<ToggleAction>::cast_dynamic (act);
3641 string i18n_killer = ARDOUR::translation_kill_path();
3643 bool already_enabled = !ARDOUR::translations_are_disabled ();
3645 if (ract->get_active ()) {
3646 /* we don't care about errors */
3647 int fd = ::open (i18n_killer.c_str(), O_RDONLY|O_CREAT, 0644);
3650 /* we don't care about errors */
3651 unlink (i18n_killer.c_str());
3654 if (already_enabled != ract->get_active()) {
3655 MessageDialog win (already_enabled ? _("Translations disabled") : _("Translations enabled"),
3657 Gtk::MESSAGE_WARNING,
3659 win.set_secondary_text (string_compose (_("You must restart %1 for this to take effect."), PROGRAM_NAME));
3660 win.set_position (Gtk::WIN_POS_CENTER);
3668 /** Add a window proxy to our list, so that its state will be saved.
3669 * This call also causes the window to be created and opened if its
3670 * state was saved as `visible'.
3673 ARDOUR_UI::add_window_proxy (WindowProxyBase* p)
3675 _window_proxies.push_back (p);
3679 /** Remove a window proxy from our list. Must be called if a WindowProxy
3680 * is deleted, to prevent hanging pointers.
3683 ARDOUR_UI::remove_window_proxy (WindowProxyBase* p)
3685 _window_proxies.remove (p);
3689 ARDOUR_UI::missing_file (Session*s, std::string str, DataType type)
3691 MissingFileDialog dialog (s, str, type);
3696 int result = dialog.run ();
3703 return 1; // quit entire session load
3706 result = dialog.get_action ();
3712 ARDOUR_UI::ambiguous_file (std::string file, std::string /*path*/, std::vector<std::string> hits)
3714 AmbiguousFileDialog dialog (file, hits);
3720 return dialog.get_which ();
3723 /** Allocate our thread-local buffers */
3725 ARDOUR_UI::get_process_buffers ()
3727 _process_thread->get_buffers ();
3730 /** Drop our thread-local buffers */
3732 ARDOUR_UI::drop_process_buffers ()
3734 _process_thread->drop_buffers ();
3738 ARDOUR_UI::feedback_detected ()
3740 _feedback_exists = true;
3744 ARDOUR_UI::successful_graph_sort ()
3746 _feedback_exists = false;
3750 ARDOUR_UI::midi_panic ()
3753 _session->midi_panic();