2 * Copyright (C) 2005-2007 Doug McLain <doug@nostar.net>
3 * Copyright (C) 2005-2017 Tim Mayberry <mojofunk@gmail.com>
4 * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
6 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
7 * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
8 * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
9 * Copyright (C) 2008-2010 Sakari Bergen <sakari.bergen@beatwaves.net>
10 * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
11 * Copyright (C) 2013-2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
12 * Copyright (C) 2013-2016 John Emmas <john@creativepost.co.uk>
13 * Copyright (C) 2013-2016 Nick Mainsbridge <mainsbridge@gmail.com>
14 * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
15 * Copyright (C) 2015 André Nusser <andre.nusser@googlemail.com>
16 * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
17 * Copyright (C) 2017 Johannes Mueller <github@johannes-mueller.org>
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include "gtk2ardour-config.h"
36 #include "gtk2ardour-version.h"
46 #ifndef PLATFORM_WINDOWS
47 #include <sys/resource.h>
51 #include <sys/types.h>
52 #include <sys/sysctl.h>
62 #include "pbd/gstdio_compat.h"
64 #include <gtkmm/accelmap.h>
65 #include <gtkmm/messagedialog.h>
66 #include <gtkmm/stock.h>
67 #include <gtkmm/uimanager.h>
69 #include "pbd/error.h"
70 #include "pbd/basename.h"
71 #include "pbd/compose.h"
72 #include "pbd/convert.h"
73 #include "pbd/failed_constructor.h"
74 #include "pbd/file_archive.h"
75 #include "pbd/enumwriter.h"
76 #include "pbd/memento_command.h"
77 #include "pbd/openuri.h"
78 #include "pbd/stl_delete.h"
79 #include "pbd/types_convert.h"
80 #include "pbd/unwind.h"
81 #include "pbd/file_utils.h"
82 #include "pbd/localtime_r.h"
83 #include "pbd/pthread_utils.h"
84 #include "pbd/replace_all.h"
85 #include "pbd/scoped_file_descriptor.h"
86 #include "pbd/xml++.h"
88 #include "gtkmm2ext/application.h"
89 #include "gtkmm2ext/bindings.h"
90 #include "gtkmm2ext/gtk_ui.h"
91 #include "gtkmm2ext/utils.h"
92 #include "gtkmm2ext/window_title.h"
94 #include "widgets/fastmeter.h"
95 #include "widgets/prompter.h"
96 #include "widgets/tooltips.h"
98 #include "ardour/ardour.h"
99 #include "ardour/audio_backend.h"
100 #include "ardour/audio_track.h"
101 #include "ardour/audioengine.h"
102 #include "ardour/audiofilesource.h"
103 #include "ardour/automation_watch.h"
104 #include "ardour/disk_reader.h"
105 #include "ardour/disk_writer.h"
106 #include "ardour/filename_extensions.h"
107 #include "ardour/filesystem_paths.h"
108 #include "ardour/ltc_file_reader.h"
109 #include "ardour/monitor_control.h"
110 #include "ardour/midi_track.h"
111 #include "ardour/port.h"
112 #include "ardour/plugin_manager.h"
113 #include "ardour/process_thread.h"
114 #include "ardour/profile.h"
115 #include "ardour/recent_sessions.h"
116 #include "ardour/record_enable_control.h"
117 #include "ardour/revision.h"
118 #include "ardour/session_directory.h"
119 #include "ardour/session_route.h"
120 #include "ardour/session_state_utils.h"
121 #include "ardour/session_utils.h"
122 #include "ardour/source_factory.h"
123 #include "ardour/transport_master.h"
124 #include "ardour/transport_master_manager.h"
125 #include "ardour/system_exec.h"
126 #include "ardour/track.h"
127 #include "ardour/vca_manager.h"
128 #include "ardour/utils.h"
130 #include "LuaBridge/LuaBridge.h"
132 #ifdef WINDOWS_VST_SUPPORT
135 #ifdef AUDIOUNIT_SUPPORT
136 #include "ardour/audio_unit.h"
139 // fix for OSX (nsm.h has a check function, AU/Apple defines check)
144 #include "temporal/time.h"
146 typedef uint64_t microseconds_t;
150 #include "enums_convert.h"
152 #include "add_route_dialog.h"
153 #include "ambiguous_file_dialog.h"
154 #include "ardour_message.h"
155 #include "ardour_ui.h"
156 #include "audio_clock.h"
157 #include "audio_region_view.h"
158 #include "big_clock_window.h"
159 #include "big_transport_window.h"
160 #include "bundle_manager.h"
161 #include "duplicate_routes_dialog.h"
163 #include "engine_dialog.h"
164 #include "export_video_dialog.h"
165 #include "export_video_infobox.h"
166 #include "gain_meter.h"
167 #include "global_port_matrix.h"
168 #include "gui_object.h"
169 #include "gui_thread.h"
170 #include "idleometer.h"
171 #include "keyboard.h"
172 #include "keyeditor.h"
173 #include "location_ui.h"
174 #include "lua_script_manager.h"
175 #include "luawindow.h"
176 #include "main_clock.h"
177 #include "missing_file_dialog.h"
178 #include "missing_plugin_dialog.h"
179 #include "mixer_ui.h"
180 #include "meterbridge.h"
181 #include "meter_patterns.h"
182 #include "mouse_cursors.h"
185 #include "pingback.h"
186 #include "plugin_dspload_window.h"
187 #include "processor_box.h"
188 #include "public_editor.h"
189 #include "rc_option_editor.h"
190 #include "route_time_axis.h"
191 #include "route_params_ui.h"
192 #include "save_as_dialog.h"
193 #include "save_template_dialog.h"
194 #include "script_selector.h"
195 #include "session_archive_dialog.h"
196 #include "session_dialog.h"
197 #include "session_metadata_dialog.h"
198 #include "session_option_editor.h"
199 #include "speaker_dialog.h"
201 #include "template_dialog.h"
202 #include "time_axis_view_item.h"
203 #include "time_info_box.h"
205 #include "transport_masters_dialog.h"
207 #include "utils_videotl.h"
208 #include "video_server_dialog.h"
209 #include "virtual_keyboard_window.h"
210 #include "add_video_dialog.h"
211 #include "transcode_video_dialog.h"
213 #include "pbd/i18n.h"
215 using namespace ARDOUR;
216 using namespace ARDOUR_UI_UTILS;
218 using namespace Gtkmm2ext;
219 using namespace ArdourWidgets;
222 using namespace Editing;
224 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
226 sigc::signal<void, samplepos_t> ARDOUR_UI::Clock;
227 sigc::signal<void> ARDOUR_UI::CloseAllDialogs;
230 ask_about_configuration_copy (string const & old_dir, string const & new_dir, int version)
232 ArdourMessageDialog msg (string_compose (
233 _("%1 %2.x has discovered configuration files from %1 %3.x.\n\n"
234 "Would you like these files to be copied and used for %1 %2.x?\n\n"
235 "(This will require you to restart %1.)"),
236 PROGRAM_NAME, PROGRAM_VERSION, version),
237 false, /* no markup */
240 true /* modal, though it hardly matters since it is the only window */
243 msg.set_default_response (Gtk::RESPONSE_YES);
246 return (msg.run() == Gtk::RESPONSE_YES);
250 libxml_generic_error_func (void* /* parsing_context*/,
258 vsnprintf (buf, sizeof (buf), msg, ap);
259 error << buf << endmsg;
264 libxml_structured_error_func (void* /* parsing_context*/,
272 replace_all (msg, "\n", "");
275 if (err->file && err->line) {
276 error << X_("XML error: ") << msg << " in " << err->file << " at line " << err->line;
279 error << ':' << err->int2;
284 error << X_("XML error: ") << msg << endmsg;
290 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
291 : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp)
292 , session_load_in_progress (false)
293 , gui_object_state (new GUIObjectState)
294 , primary_clock (new MainClock (X_("primary"), X_("transport"), true ))
295 , secondary_clock (new MainClock (X_("secondary"), X_("secondary"), false))
296 , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
298 , ignore_dual_punch (false)
299 , main_window_visibility (0)
304 , _mixer_on_top (false)
305 , _shared_popup_menu (0)
307 , secondary_clock_spacer (0)
308 , auto_input_button (ArdourButton::led_default_elements)
309 , latency_disable_button (ArdourButton::led_default_elements)
311 , auto_return_button (ArdourButton::led_default_elements)
312 , follow_edits_button (ArdourButton::led_default_elements)
313 , auditioning_alert_button (_("Audition"))
314 , solo_alert_button (_("Solo"))
315 , feedback_alert_button (_("Feedback"))
316 , error_alert_button ( ArdourButton::just_led_default_elements )
317 , editor_meter_peak_display()
319 , _numpad_locate_happening (false)
320 , _session_is_new (false)
321 , last_key_press_time (0)
325 , rc_option_editor (0)
326 , speaker_config_window (X_("speaker-config"), _("Speaker Configuration"))
327 , add_route_dialog (X_("add-routes"), _("Add Tracks/Busses"))
328 , about (X_("about"), _("About"))
329 , location_ui (X_("locations"), S_("Ranges|Locations"))
330 , route_params (X_("inspector"), _("Tracks and Busses"))
331 , audio_midi_setup (X_("audio-midi-setup"), _("Audio/MIDI Setup"))
332 , export_video_dialog (X_("video-export"), _("Video Export Dialog"))
333 , lua_script_window (X_("script-manager"), _("Script Manager"))
334 , idleometer (X_("idle-o-meter"), _("Idle'o'Meter"))
335 , plugin_dsp_load_window (X_("plugin-dsp-load"), _("Plugin DSP Load"))
336 , transport_masters_window (X_("transport-masters"), _("Transport Masters"))
337 , session_option_editor (X_("session-options-editor"), _("Properties"), boost::bind (&ARDOUR_UI::create_session_option_editor, this))
338 , add_video_dialog (X_("add-video"), _("Add Video"), boost::bind (&ARDOUR_UI::create_add_video_dialog, this))
339 , bundle_manager (X_("bundle-manager"), _("Bundle Manager"), boost::bind (&ARDOUR_UI::create_bundle_manager, this))
340 , big_clock_window (X_("big-clock"), _("Big Clock"), boost::bind (&ARDOUR_UI::create_big_clock_window, this))
341 , big_transport_window (X_("big-transport"), _("Transport Controls"), boost::bind (&ARDOUR_UI::create_big_transport_window, this))
342 , virtual_keyboard_window (X_("virtual-keyboard"), _("Virtual Keyboard"), boost::bind (&ARDOUR_UI::create_virtual_keyboard_window, this))
343 , audio_port_matrix (X_("audio-connection-manager"), _("Audio Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::AUDIO))
344 , midi_port_matrix (X_("midi-connection-manager"), _("MIDI Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::MIDI))
345 , key_editor (X_("key-editor"), _("Keyboard Shortcuts"), boost::bind (&ARDOUR_UI::create_key_editor, this))
346 , video_server_process (0)
347 , have_configure_timeout (false)
348 , last_configure_time (0)
350 , have_disk_speed_dialog_displayed (false)
351 , _status_bar_visibility (X_("status-bar"))
352 , _feedback_exists (false)
353 , _log_not_acknowledged (LogLevelNone)
354 , duplicate_routes_dialog (0)
355 , editor_visibility_button (S_("Window|Editor"))
356 , mixer_visibility_button (S_("Window|Mixer"))
357 , prefs_visibility_button (S_("Window|Preferences"))
359 Gtkmm2ext::init (localedir);
361 UIConfiguration::instance().post_gui_init ();
363 if (ARDOUR::handle_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) {
365 /* "touch" the been-here-before path now that config has been migrated */
366 PBD::ScopedFileDescriptor fout (g_open (been_here_before_path ().c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));
368 ArdourMessageDialog msg (string_compose (_("Your configuration files were copied. You can now restart %1."), PROGRAM_NAME), true);
370 /* configuration was modified, exit immediately */
371 _exit (EXIT_SUCCESS);
375 if (theArdourUI == 0) {
379 /* track main window visibility */
381 main_window_visibility = new VisibilityTracker (_main_window);
383 /* stop libxml from spewing to stdout/stderr */
385 xmlSetGenericErrorFunc (this, libxml_generic_error_func);
386 xmlSetStructuredErrorFunc (this, libxml_structured_error_func);
388 /* Set this up early */
390 ActionManager::init ();
392 /* we like keyboards */
394 keyboard = new ArdourKeyboard(*this);
396 XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
398 keyboard->set_state (*node, Stateful::loading_state_version);
401 /* actions do not need to be defined when we load keybindings. They
402 * will be lazily discovered. But bindings do need to exist when we
403 * create windows/tabs with their own binding sets.
406 keyboard->setup_keybindings ();
408 if ((global_bindings = Bindings::get_bindings (X_("Global"))) == 0) {
409 error << _("Global keybindings are missing") << endmsg;
414 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::parameter_changed));
415 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
416 UIConfiguration::instance().map_parameters (pc);
418 transport_ctrl.setup (this);
420 ARDOUR::DiskWriter::Overrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
421 ARDOUR::DiskReader::Underrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
423 ARDOUR::Session::VersionMismatch.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_format_mismatch, this, _1, _2), gui_context());
425 /* handle dialog requests */
427 ARDOUR::Session::Dialog.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_dialog, this, _1), gui_context());
429 /* handle pending state with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
431 ARDOUR::Session::AskAboutPendingState.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::pending_state_dialog, this));
433 /* handle sr mismatch with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
435 ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
437 /* handle sr mismatch with a dialog - cross-thread from engine */
438 ARDOUR::Session::NotifyAboutSampleRateMismatch.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::sr_mismatch_message, this, _1, _2), gui_context ());
440 /* handle requests to quit (coming from JACK session) */
442 ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
444 /* tell the user about feedback */
446 ARDOUR::Session::FeedbackDetected.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::feedback_detected, this), gui_context ());
447 ARDOUR::Session::SuccessfulGraphSort.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::successful_graph_sort, this), gui_context ());
449 /* indicate global latency compensation en/disable */
450 ARDOUR::Latent::DisableSwitchChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::latency_switch_changed, this), gui_context ());
452 /* handle requests to deal with missing files */
454 ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3));
456 /* and ambiguous files */
458 ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2));
460 ARDOUR::GUIIdle.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::gui_idle_handler, this), gui_context());
462 Config->ParameterChanged.connect ( forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::set_flat_buttons, this), gui_context() );
465 theme_changed.connect (sigc::mem_fun(*this, &ARDOUR_UI::on_theme_changed));
466 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::on_theme_changed));
467 UIConfiguration::instance().DPIReset.connect (sigc::mem_fun (*this, &ARDOUR_UI::on_theme_changed));
469 /* lets get this party started */
471 setup_gtk_ardour_enums ();
474 SessionEvent::create_per_thread_pool ("GUI", 4096);
476 UIConfiguration::instance().reset_dpi ();
478 TimeAxisViewItem::set_constant_heights ();
480 /* The following must happen after ARDOUR::init() so that Config is set up */
482 const XMLNode* ui_xml = Config->extra_xml (X_("UI"));
485 key_editor.set_state (*ui_xml, 0);
486 session_option_editor.set_state (*ui_xml, 0);
487 speaker_config_window.set_state (*ui_xml, 0);
488 about.set_state (*ui_xml, 0);
489 add_route_dialog.set_state (*ui_xml, 0);
490 add_video_dialog.set_state (*ui_xml, 0);
491 route_params.set_state (*ui_xml, 0);
492 bundle_manager.set_state (*ui_xml, 0);
493 location_ui.set_state (*ui_xml, 0);
494 big_clock_window.set_state (*ui_xml, 0);
495 big_transport_window.set_state (*ui_xml, 0);
496 virtual_keyboard_window.set_state (*ui_xml, 0);
497 audio_port_matrix.set_state (*ui_xml, 0);
498 midi_port_matrix.set_state (*ui_xml, 0);
499 export_video_dialog.set_state (*ui_xml, 0);
500 lua_script_window.set_state (*ui_xml, 0);
501 idleometer.set_state (*ui_xml, 0);
502 plugin_dsp_load_window.set_state (*ui_xml, 0);
503 transport_masters_window.set_state (*ui_xml, 0);
506 /* Separate windows */
508 WM::Manager::instance().register_window (&key_editor);
509 WM::Manager::instance().register_window (&session_option_editor);
510 WM::Manager::instance().register_window (&speaker_config_window);
511 WM::Manager::instance().register_window (&about);
512 WM::Manager::instance().register_window (&add_route_dialog);
513 WM::Manager::instance().register_window (&add_video_dialog);
514 WM::Manager::instance().register_window (&route_params);
515 WM::Manager::instance().register_window (&audio_midi_setup);
516 WM::Manager::instance().register_window (&export_video_dialog);
517 WM::Manager::instance().register_window (&lua_script_window);
518 WM::Manager::instance().register_window (&bundle_manager);
519 WM::Manager::instance().register_window (&location_ui);
520 WM::Manager::instance().register_window (&big_clock_window);
521 WM::Manager::instance().register_window (&big_transport_window);
522 WM::Manager::instance().register_window (&virtual_keyboard_window);
523 WM::Manager::instance().register_window (&audio_port_matrix);
524 WM::Manager::instance().register_window (&midi_port_matrix);
525 WM::Manager::instance().register_window (&idleometer);
526 WM::Manager::instance().register_window (&plugin_dsp_load_window);
527 WM::Manager::instance().register_window (&transport_masters_window);
529 /* do not retain position for add route dialog */
530 add_route_dialog.set_state_mask (WindowProxy::Size);
532 /* Trigger setting up the color scheme and loading the GTK RC file */
534 UIConfiguration::instance().load_rc_file (false);
536 _process_thread = new ProcessThread ();
538 ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
541 GlobalPortMatrixWindow*
542 ARDOUR_UI::create_global_port_matrix (ARDOUR::DataType type)
547 return new GlobalPortMatrixWindow (_session, type);
551 ARDOUR_UI::attach_to_engine ()
553 AudioEngine::instance()->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this, _1), gui_context());
558 ARDOUR_UI::engine_stopped ()
560 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_stopped)
561 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, false);
562 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, true);
563 update_sample_rate (0);
568 ARDOUR_UI::engine_running (uint32_t cnt)
575 _session->reset_xrun_count ();
577 update_disk_space ();
579 update_sample_rate (AudioEngine::instance()->sample_rate());
580 update_timecode_format ();
581 update_peak_thread_work ();
582 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, true);
583 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, false);
587 ARDOUR_UI::engine_halted (const char* reason, bool free_reason)
589 if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
590 /* we can't rely on the original string continuing to exist when we are called
591 again in the GUI thread, so make a copy and note that we need to
594 char *copy = strdup (reason);
595 Gtkmm2ext::UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_halted, this, copy, true));
599 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, false);
600 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, true);
602 update_sample_rate (0);
606 /* if the reason is a non-empty string, it means that the backend was shutdown
607 rather than just Ardour.
610 if (strlen (reason)) {
611 msgstr = string_compose (_("The audio backend was shutdown because:\n\n%1"), reason);
613 msgstr = string_compose (_("\
614 The audio backend has either been shutdown or it\n\
615 disconnected %1 because %1\n\
616 was not fast enough. Try to restart\n\
617 the audio backend and save the session."), PROGRAM_NAME);
620 ArdourMessageDialog msg (_main_window, msgstr);
624 free (const_cast<char*> (reason));
629 ARDOUR_UI::post_engine ()
631 /* Things to be done once (and once ONLY) after we have a backend running in the AudioEngine
633 #ifdef AUDIOUNIT_SUPPORT
635 if (AUPluginInfo::au_get_crashlog(au_msg)) {
636 popup_error(_("Audio Unit Plugin Scan Failed. Automatic AU scanning has been disabled. Please see the log window for further details."));
637 error << _("Audio Unit Plugin Scan Failed:") << endmsg;
638 info << au_msg << endmsg;
642 /* connect to important signals */
644 AudioEngine::instance()->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
645 AudioEngine::instance()->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
646 AudioEngine::instance()->BufferSizeChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
647 AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
648 AudioEngine::instance()->BecameSilent.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::audioengine_became_silent, this), gui_context());
650 if (setup_windows ()) {
651 throw failed_constructor ();
654 transport_ctrl.map_actions ();
656 /* Do this after setup_windows (), as that's when the _status_bar_visibility is created */
657 XMLNode* n = Config->extra_xml (X_("UI"));
659 _status_bar_visibility.set_state (*n);
662 check_memory_locking();
664 /* this is the first point at which all the possible actions are
665 * available, because some of the available actions are dependent on
666 * aspects of the engine/backend.
669 if (ARDOUR_COMMAND_LINE::show_key_actions) {
671 Bindings::save_all_bindings_as_html (sstr);
673 if (sstr.str().empty()) {
680 if ((fd = g_file_open_tmp ("akprintXXXXXX.html", &file_name, &err)) < 0) {
682 error << string_compose (_("Could not open temporary file to print bindings (%1)"), err->message) << endmsg;
688 #ifdef PLATFORM_WINDOWS
694 if (!g_file_set_contents (file_name, sstr.str().c_str(), sstr.str().size(), &err)) {
695 #ifndef PLATFORM_WINDOWS
698 g_unlink (file_name);
700 error << string_compose (_("Could not save bindings to file (%1)"), err->message) << endmsg;
706 #ifndef PLATFORM_WINDOWS
710 PBD::open_uri (string_compose ("file:///%1", file_name));
712 halt_connection.disconnect ();
713 AudioEngine::instance()->stop ();
718 if (ARDOUR_COMMAND_LINE::show_actions) {
721 vector<string> paths;
722 vector<string> labels;
723 vector<string> tooltips;
725 vector<Glib::RefPtr<Gtk::Action> > actions;
726 string ver_in = revision;
727 string ver = ver_in.substr(0, ver_in.find("-"));
730 output << "\n<h2>Menu actions</h2>" << endl;
731 output << "<p>\n Every single menu item in " << PROGRAM_NAME << "'s GUI is accessible by control" << endl;
732 output << " surfaces or scripts.\n</p>\n" << endl;
733 output << "<p>\n The list below shows all available values of <em>action-name</em> as of" << endl;
734 output << " " << PROGRAM_NAME << " " << ver << ". You can get the current list at any" << endl;
735 output << " time by running " << PROGRAM_NAME << " with the -A flag.\n</p>\n" << endl;
736 output << "<table class=\"dl\">\n <thead>" << endl;
737 output << " <tr><th>Action Name</th><th>Menu Name</th></tr>" << endl;
738 output << " </thead>\n <tbody>" << endl;
740 ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
742 vector<string>::iterator p;
743 vector<string>::iterator l;
745 for (p = paths.begin(), l = labels.begin(); p != paths.end(); ++p, ++l) {
746 output << " <tr><th><kbd class=\"osc\">" << *p << "</kbd></th><td>" << *l << "</td></tr>" << endl;
748 output << " </tbody>\n </table>" << endl;
750 // output this mess to a browser for easiest X-platform use
751 // it is not pretty HTML, but it works and it's main purpose
752 // is to create raw html to fit in Ardour's manual with no editing
757 if ((fd = g_file_open_tmp ("list-of-menu-actionsXXXXXX.html", &file_name, &err)) < 0) {
759 error << string_compose (_("Could not open temporary file to print bindings (%1)"), err->message) << endmsg;
765 #ifdef PLATFORM_WINDOWS
771 if (!g_file_set_contents (file_name, output.str().c_str(), output.str().size(), &err)) {
772 #ifndef PLATFORM_WINDOWS
775 g_unlink (file_name);
777 error << string_compose (_("Could not save bindings to file (%1)"), err->message) << endmsg;
783 #ifndef PLATFORM_WINDOWS
787 PBD::open_uri (string_compose ("file:///%1", file_name));
789 halt_connection.disconnect ();
790 AudioEngine::instance()->stop ();
794 /* this being a GUI and all, we want peakfiles */
796 AudioFileSource::set_build_peakfiles (true);
797 AudioFileSource::set_build_missing_peakfiles (true);
799 /* set default clock modes */
801 primary_clock->set_mode (AudioClock::Timecode);
802 secondary_clock->set_mode (AudioClock::BBT);
804 /* start the time-of-day-clock */
807 /* OS X provides a nearly-always visible wallclock, so don't be stupid */
808 update_wall_clock ();
809 Glib::signal_timeout().connect_seconds (sigc::mem_fun(*this, &ARDOUR_UI::update_wall_clock), 1);
814 Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
815 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
816 Config->map_parameters (pc);
818 UIConfiguration::instance().map_parameters (pc);
822 ARDOUR_UI::~ARDOUR_UI ()
824 UIConfiguration::instance().save_state();
826 ARDOUR_UI_UTILS::inhibit_screensaver (false);
830 if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
831 // don't bother at 'real' exit. the OS cleans up for us.
832 delete big_clock; big_clock = 0;
833 delete primary_clock; primary_clock = 0;
834 delete secondary_clock; secondary_clock = 0;
835 delete _process_thread; _process_thread = 0;
836 delete time_info_box; time_info_box = 0;
837 delete meterbridge; meterbridge = 0;
838 delete luawindow; luawindow = 0;
839 delete editor; editor = 0;
840 delete mixer; mixer = 0;
841 delete rc_option_editor; rc_option_editor = 0; // failed to wrap object warning
843 delete gui_object_state; gui_object_state = 0;
844 delete _shared_popup_menu ; _shared_popup_menu = 0;
845 delete main_window_visibility;
846 FastMeter::flush_pattern_cache ();
847 ArdourFader::flush_pattern_cache ();
851 /* Small trick to flush main-thread event pool.
852 * Other thread-pools are destroyed at pthread_exit(),
853 * but tmain thread termination is too late to trigger Pool::~Pool()
855 SessionEvent* ev = new SessionEvent (SessionEvent::SetTransportSpeed, SessionEvent::Clear, SessionEvent::Immediate, 0, 0); // get the pool reference, values don't matter since the event is never queued.
856 delete ev->event_pool();
861 ARDOUR_UI::configure_timeout ()
863 if (last_configure_time == 0) {
864 /* no configure events yet */
868 /* force a gap of 0.5 seconds since the last configure event
871 if (get_microseconds() - last_configure_time < 500000) {
874 have_configure_timeout = false;
875 save_ardour_state ();
881 ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
883 if (have_configure_timeout) {
884 last_configure_time = get_microseconds();
886 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::configure_timeout), 100);
887 have_configure_timeout = true;
894 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
898 if (node.get_property ("roll", str)){
899 roll_controllable->set_id (str);
901 if (node.get_property ("stop", str)) {
902 stop_controllable->set_id (str);
904 if (node.get_property ("goto-start", str)) {
905 goto_start_controllable->set_id (str);
907 if (node.get_property ("goto-end", str)) {
908 goto_end_controllable->set_id (str);
910 if (node.get_property ("auto-loop", str)) {
911 auto_loop_controllable->set_id (str);
913 if (node.get_property ("play-selection", str)) {
914 play_selection_controllable->set_id (str);
916 if (node.get_property ("rec", str)) {
917 rec_controllable->set_id (str);
919 if (node.get_property ("shuttle", str)) {
920 shuttle_box.controllable()->set_id (str);
925 ARDOUR_UI::get_transport_controllable_state ()
927 XMLNode* node = new XMLNode(X_("TransportControllables"));
929 node->set_property (X_("roll"), roll_controllable->id());
930 node->set_property (X_("stop"), stop_controllable->id());
931 node->set_property (X_("goto-start"), goto_start_controllable->id());
932 node->set_property (X_("goto-end"), goto_end_controllable->id());
933 node->set_property (X_("auto-loop"), auto_loop_controllable->id());
934 node->set_property (X_("play-selection"), play_selection_controllable->id());
935 node->set_property (X_("rec"), rec_controllable->id());
936 node->set_property (X_("shuttle"), shuttle_box.controllable()->id());
942 ARDOUR_UI::session_dirty_changed ()
949 ARDOUR_UI::update_autosave ()
951 if (_session && _session->dirty()) {
952 if (_autosave_connection.connected()) {
953 _autosave_connection.disconnect();
956 _autosave_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &ARDOUR_UI::autosave_session),
957 Config->get_periodic_safety_backup_interval() * 1000);
960 if (_autosave_connection.connected()) {
961 _autosave_connection.disconnect();
967 ARDOUR_UI::queue_finish ()
969 Glib::signal_idle().connect (mem_fun (*this, &ARDOUR_UI::idle_finish));
973 ARDOUR_UI::idle_finish ()
976 return false; /* do not call again */
983 ARDOUR_UI::instance()->video_timeline->sync_session_state();
985 if (_session->dirty()) {
986 vector<string> actions;
987 actions.push_back (_("Don't quit"));
988 actions.push_back (_("Just quit"));
989 actions.push_back (_("Save and quit"));
990 switch (ask_about_saving_session(actions)) {
995 /* use the default name */
996 if (save_state_canfail ("")) {
997 /* failed - don't quit */
998 ArdourMessageDialog msg (_main_window,
1000 %1 was unable to save your session.\n\n\
1001 If you still wish to quit, please use the\n\n\
1002 \"Just quit\" option."), PROGRAM_NAME));
1012 second_connection.disconnect ();
1013 point_one_second_connection.disconnect ();
1014 point_zero_something_second_connection.disconnect();
1015 fps_connection.disconnect();
1018 delete ARDOUR_UI::instance()->video_timeline;
1019 ARDOUR_UI::instance()->video_timeline = NULL;
1020 stop_video_server();
1022 /* Save state before deleting the session, as that causes some
1023 windows to be destroyed before their visible state can be
1026 save_ardour_state ();
1028 if (key_editor.get (false)) {
1029 key_editor->disconnect ();
1032 close_all_dialogs ();
1035 _session->set_clean ();
1040 halt_connection.disconnect ();
1041 AudioEngine::instance()->stop ();
1042 #ifdef WINDOWS_VST_SUPPORT
1043 fst_stop_threading();
1049 ARDOUR_UI::every_second ()
1052 update_disk_space ();
1053 update_timecode_format ();
1054 update_peak_thread_work ();
1056 if (nsm && nsm->is_active ()) {
1059 if (!_was_dirty && _session->dirty ()) {
1063 else if (_was_dirty && !_session->dirty ()){
1071 ARDOUR_UI::every_point_one_seconds ()
1073 if (editor) editor->build_region_boundary_cache();
1077 ARDOUR_UI::every_point_zero_something_seconds ()
1079 // august 2007: actual update frequency: 25Hz (40ms), not 100Hz
1081 if (editor_meter && UIConfiguration::instance().get_show_editor_meter() && editor_meter_peak_display.is_mapped ()) {
1082 float mpeak = editor_meter->update_meters();
1083 if (mpeak > editor_meter_max_peak) {
1084 if (mpeak >= UIConfiguration::instance().get_meter_peak()) {
1085 editor_meter_peak_display.set_active_state ( Gtkmm2ext::ExplicitActive );
1092 ARDOUR_UI::set_fps_timeout_connection ()
1094 unsigned int interval = 40;
1095 if (!_session) return;
1096 if (_session->timecode_frames_per_second() != 0) {
1097 /* ideally we'll use a select() to sleep and not accumulate
1098 * idle time to provide a regular periodic signal.
1099 * See linux_vst_gui_support.cc 'elapsed_time_ms'.
1100 * However, that'll require a dedicated thread and cross-thread
1101 * signals to the GUI Thread..
1103 interval = floor(500. /* update twice per FPS, since Glib::signal_timeout is very irregular */
1104 * _session->sample_rate() / _session->nominal_sample_rate()
1105 / _session->timecode_frames_per_second()
1107 #ifdef PLATFORM_WINDOWS
1108 // the smallest windows scheduler time-slice is ~15ms.
1109 // periodic GUI timeouts shorter than that will cause
1110 // WaitForSingleObject to spinlock (100% of one CPU Core)
1111 // and gtk never enters idle mode.
1112 // also changing timeBeginPeriod(1) does not affect that in
1113 // any beneficial way, so we just limit the max rate for now.
1114 interval = std::max(30u, interval); // at most ~33Hz.
1116 interval = std::max(8u, interval); // at most 120Hz.
1119 fps_connection.disconnect();
1120 Timers::set_fps_interval (interval);
1124 ARDOUR_UI::update_sample_rate (samplecnt_t)
1128 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
1130 if (!AudioEngine::instance()->running()) {
1132 snprintf (buf, sizeof (buf), "%s", _("Audio: <span foreground=\"red\">none</span>"));
1136 samplecnt_t rate = AudioEngine::instance()->sample_rate();
1139 /* no sample rate available */
1140 snprintf (buf, sizeof (buf), "%s", _("Audio: <span foreground=\"red\">none</span>"));
1143 if (fmod (rate, 1000.0) != 0.0) {
1144 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"green\">%.1f kHz / %4.1f ms</span>"),
1145 (float) rate / 1000.0f,
1146 (AudioEngine::instance()->usecs_per_cycle() / 1000.0f));
1148 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"green\">%" PRId64 " kHz / %4.1f ms</span>"),
1150 (AudioEngine::instance()->usecs_per_cycle() / 1000.0f));
1154 sample_rate_label.set_markup (buf);
1158 ARDOUR_UI::update_format ()
1161 format_label.set_text ("");
1166 s << _("File:") << X_(" <span foreground=\"green\">");
1168 switch (_session->config.get_native_file_header_format ()) {
1203 switch (_session->config.get_native_file_data_format ()) {
1217 format_label.set_markup (s.str ());
1221 ARDOUR_UI::update_cpu_load ()
1223 const unsigned int x = _session ? _session->get_xrun_count () : 0;
1224 double const c = AudioEngine::instance()->get_dsp_load ();
1226 const char* const bg = c > 90 ? " background=\"red\"" : "";
1230 snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span> (>10k)", bg, c);
1232 snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span> (%d)", bg, c, x);
1234 snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span>", bg, c);
1237 dsp_load_label.set_markup (buf);
1240 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k\n%s"), c, _("Shift+Click to clear xruns."));
1242 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: %u\n%s"), c, x, _("Shift+Click to clear xruns."));
1244 snprintf (buf, sizeof (buf), _("DSP: %.1f%%"), c);
1247 ArdourWidgets::set_tooltip (dsp_load_label, buf);
1251 ARDOUR_UI::update_peak_thread_work ()
1254 const int c = SourceFactory::peak_work_queue_length ();
1256 snprintf (buf, sizeof (buf), _("PkBld: <span foreground=\"%s\">%d</span>"), c >= 2 ? X_("red") : X_("green"), c);
1257 peak_thread_work_label.set_markup (buf);
1259 peak_thread_work_label.set_markup (X_(""));
1264 ARDOUR_UI::count_recenabled_streams (Route& route)
1266 Track* track = dynamic_cast<Track*>(&route);
1267 if (track && track->rec_enable_control()->get_value()) {
1268 rec_enabled_streams += track->n_inputs().n_total();
1273 ARDOUR_UI::format_disk_space_label (float remain_sec)
1275 if (remain_sec < 0) {
1276 disk_space_label.set_text (_("N/A"));
1277 ArdourWidgets::set_tooltip (disk_space_label, _("Unknown"));
1283 int sec = floor (remain_sec);
1284 int hrs = sec / 3600;
1285 int mins = (sec / 60) % 60;
1286 int secs = sec % 60;
1287 snprintf (buf, sizeof(buf), _("%02dh:%02dm:%02ds"), hrs, mins, secs);
1288 ArdourWidgets::set_tooltip (disk_space_label, buf);
1290 if (remain_sec > 86400) {
1291 disk_space_label.set_text (_("Rec: >24h"));
1293 } else if (remain_sec > 32400 /* 9 hours */) {
1294 snprintf (buf, sizeof (buf), "Rec: %.0fh", remain_sec / 3600.f);
1295 } else if (remain_sec > 5940 /* 99 mins */) {
1296 snprintf (buf, sizeof (buf), "Rec: %.1fh", remain_sec / 3600.f);
1298 snprintf (buf, sizeof (buf), "Rec: %.0fm", remain_sec / 60.f);
1300 disk_space_label.set_text (buf);
1305 ARDOUR_UI::update_disk_space()
1307 if (_session == 0) {
1308 format_disk_space_label (-1);
1312 boost::optional<samplecnt_t> opt_samples = _session->available_capture_duration();
1313 samplecnt_t fr = _session->sample_rate();
1316 /* skip update - no SR available */
1317 format_disk_space_label (-1);
1322 /* Available space is unknown */
1323 format_disk_space_label (-1);
1324 } else if (opt_samples.value_or (0) == max_samplecnt) {
1325 format_disk_space_label (max_samplecnt);
1327 rec_enabled_streams = 0;
1328 _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams, false);
1330 samplecnt_t samples = opt_samples.value_or (0);
1332 if (rec_enabled_streams) {
1333 samples /= rec_enabled_streams;
1336 format_disk_space_label (samples / (float)fr);
1342 ARDOUR_UI::update_timecode_format ()
1348 boost::shared_ptr<TimecodeTransportMaster> tcmaster;
1349 boost::shared_ptr<TransportMaster> tm = TransportMasterManager::instance().current();
1351 if ((tm->type() == LTC || tm->type() == MTC) && (tcmaster = boost::dynamic_pointer_cast<TimecodeTransportMaster>(tm)) != 0) {
1352 matching = (tcmaster->apparent_timecode_format() == _session->config.get_timecode_format());
1357 snprintf (buf, sizeof (buf), S_("Timecode|TC: <span foreground=\"%s\">%s</span>"),
1358 matching ? X_("green") : X_("red"),
1359 Timecode::timecode_format_name (_session->config.get_timecode_format()).c_str());
1361 snprintf (buf, sizeof (buf), "TC: n/a");
1364 timecode_format_label.set_markup (buf);
1368 ARDOUR_UI::update_wall_clock ()
1372 static int last_min = -1;
1375 tm_now = localtime (&now);
1376 if (last_min != tm_now->tm_min) {
1378 sprintf (buf, "%02d:%02d", tm_now->tm_hour, tm_now->tm_min);
1379 wall_clock_label.set_text (buf);
1380 last_min = tm_now->tm_min;
1387 ARDOUR_UI::session_add_mixed_track (
1388 const ChanCount& input,
1389 const ChanCount& output,
1390 RouteGroup* route_group,
1392 const string& name_template,
1394 PluginInfoPtr instrument,
1395 Plugin::PresetRecord* pset,
1396 ARDOUR::PresentationInfo::order_t order)
1400 if (Profile->get_mixbus ()) {
1405 list<boost::shared_ptr<MidiTrack> > tracks;
1406 tracks = _session->new_midi_track (input, output, strict_io, instrument, pset, route_group, how_many, name_template, order, ARDOUR::Normal);
1408 if (tracks.size() != how_many) {
1409 error << string_compose(P_("could not create %1 new mixed track", "could not create %1 new mixed tracks", how_many), how_many) << endmsg;
1414 display_insufficient_ports_message ();
1420 ARDOUR_UI::session_add_midi_bus (
1421 RouteGroup* route_group,
1423 const string& name_template,
1425 PluginInfoPtr instrument,
1426 Plugin::PresetRecord* pset,
1427 ARDOUR::PresentationInfo::order_t order)
1429 if (_session == 0) {
1430 warning << _("You cannot add a track without a session already loaded.") << endmsg;
1434 if (Profile->get_mixbus ()) {
1440 routes = _session->new_midi_route (route_group, how_many, name_template, strict_io, instrument, pset, PresentationInfo::MidiBus, order);
1441 if (routes.size() != how_many) {
1442 error << string_compose(P_("could not create %1 new Midi Bus", "could not create %1 new Midi Busses", how_many), how_many) << endmsg;
1447 display_insufficient_ports_message ();
1453 ARDOUR_UI::session_add_midi_route (
1455 RouteGroup* route_group,
1457 const string& name_template,
1459 PluginInfoPtr instrument,
1460 Plugin::PresetRecord* pset,
1461 ARDOUR::PresentationInfo::order_t order)
1463 ChanCount one_midi_channel;
1464 one_midi_channel.set (DataType::MIDI, 1);
1467 session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, strict_io, instrument, pset, order);
1469 session_add_midi_bus (route_group, how_many, name_template, strict_io, instrument, pset, order);
1474 ARDOUR_UI::session_add_audio_route (
1476 int32_t input_channels,
1477 int32_t output_channels,
1478 ARDOUR::TrackMode mode,
1479 RouteGroup* route_group,
1481 string const & name_template,
1483 ARDOUR::PresentationInfo::order_t order)
1485 list<boost::shared_ptr<AudioTrack> > tracks;
1492 tracks = _session->new_audio_track (input_channels, output_channels, route_group, how_many, name_template, order, mode);
1494 if (tracks.size() != how_many) {
1495 error << string_compose (P_("could not create %1 new audio track", "could not create %1 new audio tracks", how_many), how_many)
1501 routes = _session->new_audio_route (input_channels, output_channels, route_group, how_many, name_template, PresentationInfo::AudioBus, order);
1503 if (routes.size() != how_many) {
1504 error << string_compose (P_("could not create %1 new audio bus", "could not create %1 new audio busses", how_many), how_many)
1511 display_insufficient_ports_message ();
1516 for (list<boost::shared_ptr<AudioTrack> >::iterator i = tracks.begin(); i != tracks.end(); ++i) {
1517 (*i)->set_strict_io (true);
1519 for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
1520 (*i)->set_strict_io (true);
1526 ARDOUR_UI::session_add_foldback_bus (int32_t channels, uint32_t how_many, string const & name_template)
1533 routes = _session->new_audio_route (channels, channels, 0, how_many, name_template, PresentationInfo::FoldbackBus, -1);
1535 if (routes.size() != how_many) {
1536 error << string_compose (P_("could not create %1 new foldback bus", "could not create %1 new foldback busses", how_many), how_many)
1542 display_insufficient_ports_message ();
1548 ARDOUR_UI::display_insufficient_ports_message ()
1550 ArdourMessageDialog msg (_main_window,
1551 string_compose (_("There are insufficient ports available\n\
1552 to create a new track or bus.\n\
1553 You should save %1, exit and\n\
1554 restart with more ports."), PROGRAM_NAME));
1559 ARDOUR_UI::transport_goto_start ()
1562 _session->goto_start ();
1564 /* force displayed area in editor to start no matter
1565 what "follow playhead" setting is.
1569 editor->center_screen (_session->current_start_sample ());
1575 ARDOUR_UI::transport_goto_zero ()
1578 _session->request_locate (0);
1580 /* force displayed area in editor to start no matter
1581 what "follow playhead" setting is.
1585 editor->reset_x_origin (0);
1591 ARDOUR_UI::transport_goto_wallclock ()
1593 if (_session && editor) {
1597 samplepos_t samples;
1600 localtime_r (&now, &tmnow);
1602 samplecnt_t sample_rate = _session->sample_rate();
1604 if (sample_rate == 0) {
1605 /* no frame rate available */
1609 samples = tmnow.tm_hour * (60 * 60 * sample_rate);
1610 samples += tmnow.tm_min * (60 * sample_rate);
1611 samples += tmnow.tm_sec * sample_rate;
1613 _session->request_locate (samples, _session->transport_rolling ());
1615 /* force displayed area in editor to start no matter
1616 what "follow playhead" setting is.
1620 editor->center_screen (samples);
1626 ARDOUR_UI::transport_goto_end ()
1629 samplepos_t const sample = _session->current_end_sample();
1630 _session->request_locate (sample);
1632 /* force displayed area in editor to start no matter
1633 what "follow playhead" setting is.
1637 editor->center_screen (sample);
1643 ARDOUR_UI::transport_stop ()
1649 if (_session->is_auditioning()) {
1650 _session->cancel_audition ();
1654 _session->request_stop (false, true);
1657 /** Check if any tracks are record enabled. If none are, record enable all of them.
1658 * @return true if track record-enabled status was changed, false otherwise.
1661 ARDOUR_UI::trx_record_enable_all_tracks ()
1667 boost::shared_ptr<RouteList> rl = _session->get_tracks ();
1668 bool none_record_enabled = true;
1670 for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
1671 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (*r);
1674 if (t->rec_enable_control()->get_value()) {
1675 none_record_enabled = false;
1680 if (none_record_enabled) {
1681 _session->set_controls (route_list_to_control_list (rl, &Stripable::rec_enable_control), 1.0, Controllable::NoGroup);
1684 return none_record_enabled;
1688 ARDOUR_UI::transport_record (bool roll)
1691 switch (_session->record_status()) {
1692 case Session::Disabled:
1693 if (_session->ntracks() == 0) {
1694 ArdourMessageDialog msg (_main_window, _("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."));
1698 _session->maybe_enable_record ();
1703 case Session::Recording:
1705 _session->request_stop();
1707 _session->disable_record (false, true);
1711 case Session::Enabled:
1715 _session->disable_record (false, true);
1722 ARDOUR_UI::transport_roll ()
1728 if (_session->is_auditioning()) {
1732 if (_session->config.get_external_sync()) {
1733 switch (TransportMasterManager::instance().current()->type()) {
1737 /* transport controlled by the master */
1742 bool rolling = _session->transport_rolling();
1744 if (_session->get_play_loop()) {
1746 /* If loop playback is not a mode, then we should cancel
1747 it when this action is requested. If it is a mode
1748 we just leave it in place.
1751 if (!Config->get_loop_is_mode()) {
1752 /* stop loop playback but keep transport state */
1753 _session->request_play_loop (false, false);
1756 } else if (_session->get_play_range () ) {
1757 /* stop playing a range if we currently are */
1758 _session->request_play_range (0, true);
1762 _session->request_transport_speed (1.0f);
1767 ARDOUR_UI::get_smart_mode() const
1769 return ( editor->get_smart_mode() );
1774 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
1780 if (_session->is_auditioning()) {
1781 _session->cancel_audition ();
1785 if (_session->config.get_external_sync()) {
1786 switch (TransportMasterManager::instance().current()->type()) {
1790 /* transport controlled by the master */
1795 bool rolling = _session->transport_rolling();
1799 if (roll_out_of_bounded_mode) {
1800 /* drop out of loop/range playback but leave transport rolling */
1802 if (_session->get_play_loop()) {
1804 if (_session->actively_recording()) {
1805 /* actually stop transport because
1806 otherwise the captured data will make
1809 _session->request_play_loop (false, true);
1812 _session->request_play_loop (false, false);
1815 } else if (_session->get_play_range ()) {
1817 _session->request_cancel_play_range ();
1821 _session->request_stop (with_abort, true);
1824 } else { /* not rolling */
1826 if (with_abort) { /* with_abort == true means the command was intended to stop transport, not start. */
1830 if (_session->get_play_loop() && Config->get_loop_is_mode()) {
1831 _session->request_locate (_session->locations()->auto_loop_location()->start(), true);
1833 if (UIConfiguration::instance().get_follow_edits()) {
1834 list<AudioRange>& range = editor->get_selection().time;
1835 if (range.front().start == _session->transport_sample()) { // if playhead is exactly at the start of a range, we assume it was placed there by follow_edits
1836 _session->request_play_range (&range, true);
1837 _session->set_requested_return_sample (range.front().start); //force an auto-return here
1840 _session->request_transport_speed (1.0f);
1846 ARDOUR_UI::toggle_session_auto_loop ()
1852 Location * looploc = _session->locations()->auto_loop_location();
1858 if (_session->get_play_loop()) {
1860 /* looping enabled, our job is to disable it */
1862 _session->request_play_loop (false);
1866 /* looping not enabled, our job is to enable it.
1868 loop-is-NOT-mode: this action always starts the transport rolling.
1869 loop-IS-mode: this action simply sets the loop play mechanism, but
1870 does not start transport.
1872 if (Config->get_loop_is_mode()) {
1873 _session->request_play_loop (true, false);
1875 _session->request_play_loop (true, true);
1879 //show the loop markers
1880 looploc->set_hidden (false, this);
1884 ARDOUR_UI::transport_play_selection ()
1890 editor->play_selection ();
1894 ARDOUR_UI::transport_play_preroll ()
1899 editor->play_with_preroll ();
1903 ARDOUR_UI::transport_rec_preroll ()
1908 editor->rec_with_preroll ();
1912 ARDOUR_UI::transport_rec_count_in ()
1917 editor->rec_with_count_in ();
1921 ARDOUR_UI::transport_rewind (int option)
1923 float current_transport_speed;
1926 current_transport_speed = _session->transport_speed();
1928 if (current_transport_speed >= 0.0f) {
1931 _session->request_transport_speed (-1.0f);
1934 _session->request_transport_speed (-4.0f);
1937 _session->request_transport_speed (-0.5f);
1942 _session->request_transport_speed (current_transport_speed * 1.5f);
1948 ARDOUR_UI::transport_forward (int option)
1954 float current_transport_speed = _session->transport_speed();
1956 if (current_transport_speed <= 0.0f) {
1959 _session->request_transport_speed (1.0f);
1962 _session->request_transport_speed (4.0f);
1965 _session->request_transport_speed (0.5f);
1970 _session->request_transport_speed (current_transport_speed * 1.5f);
1975 ARDOUR_UI::toggle_record_enable (uint16_t rid)
1981 boost::shared_ptr<Route> r;
1983 if ((r = _session->get_remote_nth_route (rid)) != 0) {
1985 boost::shared_ptr<Track> t;
1987 if ((t = boost::dynamic_pointer_cast<Track>(r)) != 0) {
1988 t->rec_enable_control()->set_value (!t->rec_enable_control()->get_value(), Controllable::UseGroup);
1994 ARDOUR_UI::map_transport_state ()
1997 layered_button.set_sensitive (false);
1998 if (UIConfiguration::instance().get_screen_saver_mode () == InhibitWhileRecording) {
1999 inhibit_screensaver (false);
2004 shuttle_box.map_transport_state ();
2006 float sp = _session->transport_speed();
2009 layered_button.set_sensitive (!_session->actively_recording ());
2011 layered_button.set_sensitive (true);
2012 update_disk_space ();
2014 if (UIConfiguration::instance().get_screen_saver_mode () == InhibitWhileRecording) {
2015 inhibit_screensaver (_session->actively_recording ());
2020 ARDOUR_UI::blink_handler (bool blink_on)
2022 sync_blink (blink_on);
2024 if (!UIConfiguration::instance().get_blink_alert_indicators()) {
2027 error_blink (blink_on);
2028 solo_blink (blink_on);
2029 audition_blink (blink_on);
2030 feedback_blink (blink_on);
2034 ARDOUR_UI::update_clocks ()
2036 if (!_session) return;
2038 if (editor && !editor->dragging_playhead()) {
2039 Clock (_session->audible_sample()); /* EMIT_SIGNAL */
2044 ARDOUR_UI::start_clocking ()
2046 if (UIConfiguration::instance().get_super_rapid_clock_update()) {
2047 clock_signal_connection = Timers::fps_connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2049 clock_signal_connection = Timers::rapid_connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2054 ARDOUR_UI::stop_clocking ()
2056 clock_signal_connection.disconnect ();
2060 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
2062 if (!_session || _session->deletion_in_progress()) {
2066 XMLNode* node = new XMLNode (X_("UI"));
2068 WM::Manager::instance().add_state (*node);
2070 node->add_child_nocopy (gui_object_state->get_state());
2072 _session->add_extra_xml (*node);
2074 if (export_video_dialog) {
2075 _session->add_extra_xml (export_video_dialog->get_state());
2078 save_state_canfail (name, switch_to_it);
2082 ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
2087 if ((ret = _session->save_state (name, false, switch_to_it)) != 0) {
2092 save_ardour_state (); /* XXX cannot fail? yeah, right ... */
2097 ARDOUR_UI::primary_clock_value_changed ()
2100 _session->request_locate (primary_clock->current_time ());
2105 ARDOUR_UI::big_clock_value_changed ()
2108 _session->request_locate (big_clock->current_time ());
2113 ARDOUR_UI::secondary_clock_value_changed ()
2116 _session->request_locate (secondary_clock->current_time ());
2120 ARDOUR_UI::save_template_dialog_response (int response, SaveTemplateDialog* d)
2122 if (response == RESPONSE_ACCEPT) {
2123 const string name = d->get_template_name ();
2124 const string desc = d->get_description ();
2126 int failed = _session->save_template (name, desc);
2128 if (failed == -2) { /* file already exists. */
2129 bool overwrite = overwrite_file_dialog (*d,
2130 _("Confirm Template Overwrite"),
2131 _("A template already exists with that name. Do you want to overwrite it?"));
2134 _session->save_template (name, desc, true);
2146 ARDOUR_UI::save_template ()
2148 if (!check_audioengine (_main_window)) {
2152 const std::string desc = SessionMetadata::Metadata()->description ();
2153 SaveTemplateDialog* d = new SaveTemplateDialog (_session->name (), desc);
2154 d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::save_template_dialog_response), d));
2158 void ARDOUR_UI::manage_templates ()
2165 ARDOUR_UI::edit_metadata ()
2167 SessionMetadataEditor dialog;
2168 dialog.set_session (_session);
2169 dialog.grab_focus ();
2174 ARDOUR_UI::import_metadata ()
2176 SessionMetadataImporter dialog;
2177 dialog.set_session (_session);
2181 static void _lua_print (std::string s) {
2183 std::cout << "LuaInstance: " << s << "\n";
2185 PBD::info << "LuaInstance: " << s << endmsg;
2188 std::map<std::string, std::string>
2189 ARDOUR_UI::route_setup_info (const std::string& script_path)
2191 std::map<std::string, std::string> rv;
2193 if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
2198 lua.Print.connect (&_lua_print);
2201 lua_State* L = lua.getState();
2202 LuaInstance::register_classes (L);
2203 LuaBindings::set_session (L, _session);
2204 luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
2205 lua_setglobal (L, "Editor");
2207 lua.do_command ("function ardour () end");
2208 lua.do_file (script_path);
2211 luabridge::LuaRef fn = luabridge::getGlobal (L, "route_setup");
2212 if (!fn.isFunction ()) {
2215 luabridge::LuaRef rs = fn ();
2216 if (!rs.isTable ()) {
2219 for (luabridge::Iterator i(rs); !i.isNil (); ++i) {
2220 if (!i.key().isString()) {
2223 std::string key = i.key().tostring();
2224 if (i.value().isString() || i.value().isNumber() || i.value().isBoolean()) {
2225 rv[key] = i.value().tostring();
2228 } catch (luabridge::LuaException const& e) {
2229 cerr << "LuaException:" << e.what () << endl;
2235 ARDOUR_UI::meta_route_setup (const std::string& script_path)
2237 if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
2240 assert (add_route_dialog);
2243 if ((count = add_route_dialog->count()) <= 0) {
2248 lua.Print.connect (&_lua_print);
2251 lua_State* L = lua.getState();
2252 LuaInstance::register_classes (L);
2253 LuaBindings::set_session (L, _session);
2254 luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
2255 lua_setglobal (L, "Editor");
2257 lua.do_command ("function ardour () end");
2258 lua.do_file (script_path);
2260 luabridge::LuaRef args (luabridge::newTable (L));
2262 args["name"] = add_route_dialog->name_template ();
2263 args["insert_at"] = translate_order (add_route_dialog->insert_at());
2264 args["group"] = add_route_dialog->route_group ();
2265 args["strict_io"] = add_route_dialog->use_strict_io ();
2266 args["instrument"] = add_route_dialog->requested_instrument ();
2267 args["track_mode"] = add_route_dialog->mode ();
2268 args["channels"] = add_route_dialog->channel_count ();
2269 args["how_many"] = count;
2272 luabridge::LuaRef fn = luabridge::getGlobal (L, "factory");
2273 if (fn.isFunction()) {
2276 } catch (luabridge::LuaException const& e) {
2277 cerr << "LuaException:" << e.what () << endl;
2279 display_insufficient_ports_message ();
2284 ARDOUR_UI::meta_session_setup (const std::string& script_path)
2286 if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
2291 lua.Print.connect (&_lua_print);
2294 lua_State* L = lua.getState();
2295 LuaInstance::register_classes (L);
2296 LuaBindings::set_session (L, _session);
2297 luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
2298 lua_setglobal (L, "Editor");
2300 lua.do_command ("function ardour () end");
2301 lua.do_file (script_path);
2304 luabridge::LuaRef fn = luabridge::getGlobal (L, "factory");
2305 if (fn.isFunction()) {
2308 } catch (luabridge::LuaException const& e) {
2309 cerr << "LuaException:" << e.what () << endl;
2311 display_insufficient_ports_message ();
2316 ARDOUR_UI::display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title, const bool msg_delete)
2320 removed = rep.paths.size();
2323 ArdourMessageDialog msgd (_main_window,
2324 _("No files were ready for clean-up"),
2328 msgd.set_title (_("Clean-up"));
2329 msgd.set_secondary_text (_("If this seems surprising, \n\
2330 check for any existing snapshots.\n\
2331 These may still include regions that\n\
2332 require some unused files to continue to exist."));
2338 ArdourDialog results (_("Clean-up"), true, false);
2340 struct CleanupResultsModelColumns : public Gtk::TreeModel::ColumnRecord {
2341 CleanupResultsModelColumns() {
2345 Gtk::TreeModelColumn<std::string> visible_name;
2346 Gtk::TreeModelColumn<std::string> fullpath;
2350 CleanupResultsModelColumns results_columns;
2351 Glib::RefPtr<Gtk::ListStore> results_model;
2352 Gtk::TreeView results_display;
2354 results_model = ListStore::create (results_columns);
2355 results_display.set_model (results_model);
2356 results_display.append_column (list_title, results_columns.visible_name);
2358 results_display.set_name ("CleanupResultsList");
2359 results_display.set_headers_visible (true);
2360 results_display.set_headers_clickable (false);
2361 results_display.set_reorderable (false);
2363 Gtk::ScrolledWindow list_scroller;
2366 Gtk::HBox dhbox; // the hbox for the image and text
2367 Gtk::HBox ddhbox; // the hbox we eventually pack into the dialog's vbox
2368 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_INFO, Gtk::ICON_SIZE_DIALOG));
2370 dimage->set_alignment(ALIGN_LEFT, ALIGN_TOP);
2372 const string dead_directory = _session->session_directory().dead_path();
2375 %1 - number of files removed
2376 %2 - location of "dead"
2377 %3 - size of files affected
2378 %4 - prefix for "bytes" to produce sensible results (e.g. mega, kilo, giga)
2381 const char* bprefix;
2382 double space_adjusted = 0;
2384 if (rep.space < 1000) {
2386 space_adjusted = rep.space;
2387 } else if (rep.space < 1000000) {
2388 bprefix = _("kilo");
2389 space_adjusted = floorf((float)rep.space / 1000.0);
2390 } else if (rep.space < 1000000 * 1000) {
2391 bprefix = _("mega");
2392 space_adjusted = floorf((float)rep.space / (1000.0 * 1000.0));
2394 bprefix = _("giga");
2395 space_adjusted = floorf((float)rep.space / (1000.0 * 1000 * 1000.0));
2399 txt.set_markup (string_compose (P_("\
2400 The following file was deleted from %2,\n\
2401 releasing %3 %4bytes of disk space", "\
2402 The following %1 files were deleted from %2,\n\
2403 releasing %3 %4bytes of disk space", removed),
2404 removed, Gtkmm2ext::markup_escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
2406 txt.set_markup (string_compose (P_("\
2407 The following file was not in use and \n\
2408 has been moved to: %2\n\n\
2409 After a restart of %5\n\n\
2410 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
2411 will release an additional %3 %4bytes of disk space.\n", "\
2412 The following %1 files were not in use and \n\
2413 have been moved to: %2\n\n\
2414 After a restart of %5\n\n\
2415 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
2416 will release an additional %3 %4bytes of disk space.\n", removed),
2417 removed, Gtkmm2ext::markup_escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
2420 dhbox.pack_start (*dimage, true, false, 5);
2421 dhbox.pack_start (txt, true, false, 5);
2423 for (vector<string>::iterator i = rep.paths.begin(); i != rep.paths.end(); ++i) {
2424 TreeModel::Row row = *(results_model->append());
2425 row[results_columns.visible_name] = *i;
2426 row[results_columns.fullpath] = *i;
2429 list_scroller.add (results_display);
2430 list_scroller.set_size_request (-1, 150);
2431 list_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
2433 dvbox.pack_start (dhbox, true, false, 5);
2434 dvbox.pack_start (list_scroller, true, false, 5);
2435 ddhbox.pack_start (dvbox, true, false, 5);
2437 results.get_vbox()->pack_start (ddhbox, true, false, 5);
2438 results.add_button (Stock::CLOSE, RESPONSE_CLOSE);
2439 results.set_default_response (RESPONSE_CLOSE);
2440 results.set_position (Gtk::WIN_POS_MOUSE);
2442 results_display.show();
2443 list_scroller.show();
2450 //results.get_vbox()->show();
2451 results.set_resizable (false);
2458 ARDOUR_UI::cleanup ()
2460 if (_session == 0) {
2461 /* shouldn't happen: menu item is insensitive */
2466 ArdourMessageDialog checker (_("Are you sure you want to clean-up?"),
2468 Gtk::MESSAGE_QUESTION,
2471 checker.set_title (_("Clean-up"));
2473 checker.set_secondary_text(_("Clean-up is a destructive operation.\n\
2474 ALL undo/redo information will be lost if you clean-up.\n\
2475 Clean-up will move all unused files to a \"dead\" location."));
2477 checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
2478 checker.add_button (_("Clean-up"), RESPONSE_ACCEPT);
2479 checker.set_default_response (RESPONSE_CANCEL);
2481 checker.set_name (_("CleanupDialog"));
2482 checker.set_wmclass (X_("ardour_cleanup"), PROGRAM_NAME);
2483 checker.set_position (Gtk::WIN_POS_MOUSE);
2485 switch (checker.run()) {
2486 case RESPONSE_ACCEPT:
2493 ARDOUR::CleanupReport rep;
2495 editor->prepare_for_cleanup ();
2497 /* do not allow flush until a session is reloaded */
2498 ActionManager::get_action (X_("Main"), X_("FlushWastebasket"))->set_sensitive (false);
2500 if (_session->cleanup_sources (rep)) {
2501 editor->finish_cleanup ();
2505 editor->finish_cleanup ();
2507 display_cleanup_results (rep, _("Cleaned Files"), false);
2511 ARDOUR_UI::flush_trash ()
2513 if (_session == 0) {
2514 /* shouldn't happen: menu item is insensitive */
2518 ARDOUR::CleanupReport rep;
2520 if (_session->cleanup_trash_sources (rep)) {
2524 display_cleanup_results (rep, _("deleted file"), true);
2528 ARDOUR_UI::cleanup_peakfiles ()
2530 if (_session == 0) {
2531 /* shouldn't happen: menu item is insensitive */
2535 if (! _session->can_cleanup_peakfiles ()) {
2539 // get all region-views in this session
2541 TrackViewList empty;
2543 editor->get_regions_after(rs, (samplepos_t) 0, empty);
2544 std::list<RegionView*> views = rs.by_layer();
2546 // remove displayed audio-region-views waveforms
2547 for (list<RegionView*>::iterator i = views.begin(); i != views.end(); ++i) {
2548 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*i);
2549 if (!arv) { continue ; }
2550 arv->delete_waves();
2553 // cleanup peak files:
2554 // - stop pending peakfile threads
2555 // - close peakfiles if any
2556 // - remove peak dir in session
2557 // - setup peakfiles (background thread)
2558 _session->cleanup_peakfiles ();
2560 // re-add waves to ARV
2561 for (list<RegionView*>::iterator i = views.begin(); i != views.end(); ++i) {
2562 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*i);
2563 if (!arv) { continue ; }
2564 arv->create_waves();
2568 PresentationInfo::order_t
2569 ARDOUR_UI::translate_order (RouteDialogs::InsertAt place)
2571 if (editor->get_selection().tracks.empty()) {
2572 return place == RouteDialogs::First ? 0 : PresentationInfo::max_order;
2575 PresentationInfo::order_t order_hint = PresentationInfo::max_order;
2578 we want the new routes to have their order keys set starting from
2579 the highest order key in the selection + 1 (if available).
2582 if (place == RouteDialogs::AfterSelection) {
2583 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView*> (editor->get_selection().tracks.back());
2585 order_hint = rtav->route()->presentation_info().order();
2588 } else if (place == RouteDialogs::BeforeSelection) {
2589 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView*> (editor->get_selection().tracks.front());
2591 order_hint = rtav->route()->presentation_info().order();
2593 } else if (place == RouteDialogs::First) {
2596 /* leave order_hint at max_order */
2603 ARDOUR_UI::start_duplicate_routes ()
2605 if (!duplicate_routes_dialog) {
2606 duplicate_routes_dialog = new DuplicateRouteDialog;
2609 if (duplicate_routes_dialog->restart (_session)) {
2613 duplicate_routes_dialog->present ();
2617 ARDOUR_UI::add_route ()
2619 if (!add_route_dialog.get (false)) {
2620 add_route_dialog->signal_response().connect (sigc::mem_fun (*this, &ARDOUR_UI::add_route_dialog_response));
2627 if (add_route_dialog->is_visible()) {
2628 /* we're already doing this */
2632 add_route_dialog->set_position (WIN_POS_MOUSE);
2633 add_route_dialog->present();
2637 ARDOUR_UI::add_route_dialog_response (int r)
2640 warning << _("You cannot add tracks or busses without a session already loaded.") << endmsg;
2644 if (!AudioEngine::instance()->running ()) {
2646 case AddRouteDialog::Add:
2647 case AddRouteDialog::AddAndClose:
2652 add_route_dialog->ArdourDialog::on_response (r);
2653 ARDOUR_UI_UTILS::engine_is_running ();
2660 case AddRouteDialog::Add:
2661 add_route_dialog->reset_name_edited ();
2663 case AddRouteDialog::AddAndClose:
2664 add_route_dialog->ArdourDialog::on_response (r);
2667 add_route_dialog->ArdourDialog::on_response (r);
2671 std::string template_path = add_route_dialog->get_template_path();
2672 if (!template_path.empty() && template_path.substr (0, 11) == "urn:ardour:") {
2673 meta_route_setup (template_path.substr (11));
2677 if ((count = add_route_dialog->count()) <= 0) {
2681 PresentationInfo::order_t order = translate_order (add_route_dialog->insert_at());
2682 const string name_template = add_route_dialog->name_template ();
2683 DisplaySuspender ds;
2685 if (!template_path.empty ()) {
2686 if (add_route_dialog->name_template_is_default ()) {
2687 _session->new_route_from_template (count, order, template_path, string ());
2689 _session->new_route_from_template (count, order, template_path, name_template);
2694 ChanCount input_chan= add_route_dialog->channels ();
2695 ChanCount output_chan;
2696 PluginInfoPtr instrument = add_route_dialog->requested_instrument ();
2697 RouteGroup* route_group = add_route_dialog->route_group ();
2698 AutoConnectOption oac = Config->get_output_auto_connect();
2699 bool strict_io = add_route_dialog->use_strict_io ();
2701 if (oac & AutoConnectMaster) {
2702 output_chan.set (DataType::AUDIO, (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan.n_audio()));
2703 output_chan.set (DataType::MIDI, 0);
2705 output_chan = input_chan;
2708 /* XXX do something with name template */
2710 Session::ProcessorChangeBlocker pcb (_session);
2712 switch (add_route_dialog->type_wanted()) {
2713 case AddRouteDialog::AudioTrack:
2714 session_add_audio_route (true, input_chan.n_audio(), output_chan.n_audio(), add_route_dialog->mode(), route_group, count, name_template, strict_io, order);
2716 case AddRouteDialog::MidiTrack:
2717 session_add_midi_route (true, route_group, count, name_template, strict_io, instrument, 0, order);
2719 case AddRouteDialog::MixedTrack:
2720 session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, strict_io, instrument, 0, order);
2722 case AddRouteDialog::AudioBus:
2723 session_add_audio_route (false, input_chan.n_audio(), output_chan.n_audio(), ARDOUR::Normal, route_group, count, name_template, strict_io, order);
2725 case AddRouteDialog::MidiBus:
2726 session_add_midi_bus (route_group, count, name_template, strict_io, instrument, 0, order);
2728 case AddRouteDialog::VCAMaster:
2729 _session->vca_manager().create_vca (count, name_template);
2731 case AddRouteDialog::FoldbackBus:
2732 session_add_foldback_bus (input_chan.n_audio(), count, name_template);
2733 ActionManager::get_toggle_action (X_("Mixer"), X_("ToggleFoldbackStrip"))->set_active (true);
2739 ARDOUR_UI::disk_overrun_handler ()
2741 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_overrun_handler)
2743 if (!have_disk_speed_dialog_displayed) {
2744 have_disk_speed_dialog_displayed = true;
2745 ArdourMessageDialog* msg = new ArdourMessageDialog (_main_window, string_compose (_("\
2746 The disk system on your computer\n\
2747 was not able to keep up with %1.\n\
2749 Specifically, it failed to write data to disk\n\
2750 quickly enough to keep up with recording.\n"), PROGRAM_NAME));
2751 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
2757 ARDOUR_UI::gui_idle_handler ()
2760 /* due to idle calls, gtk_events_pending() may always return true */
2761 while (gtk_events_pending() && --timeout) {
2762 gtk_main_iteration ();
2767 ARDOUR_UI::disk_underrun_handler ()
2769 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_underrun_handler)
2771 if (!have_disk_speed_dialog_displayed) {
2772 have_disk_speed_dialog_displayed = true;
2773 ArdourMessageDialog* msg = new ArdourMessageDialog (
2774 _main_window, string_compose (_("The disk system on your computer\n\
2775 was not able to keep up with %1.\n\
2777 Specifically, it failed to read data from disk\n\
2778 quickly enough to keep up with playback.\n"), PROGRAM_NAME));
2779 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
2785 ARDOUR_UI::disk_speed_dialog_gone (int /*ignored_response*/, MessageDialog* msg)
2787 have_disk_speed_dialog_displayed = false;
2792 ARDOUR_UI::session_dialog (std::string msg)
2794 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::session_dialog, msg)
2795 ArdourMessageDialog d (msg, false, MESSAGE_INFO, BUTTONS_OK, true);
2800 ARDOUR_UI::pending_state_dialog ()
2802 HBox* hbox = manage (new HBox());
2803 Image* image = manage (new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG));
2804 ArdourDialog dialog (_("Crash Recovery"), true);
2805 Label message (string_compose (_("\
2806 This session appears to have been in the\n\
2807 middle of recording when %1 or\n\
2808 the computer was shutdown.\n\
2810 %1 can recover any captured audio for\n\
2811 you, or it can ignore it. Please decide\n\
2812 what you would like to do.\n"), PROGRAM_NAME));
2813 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
2814 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
2815 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
2816 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
2817 dialog.add_button (_("Ignore crash data"), RESPONSE_REJECT);
2818 dialog.add_button (_("Recover from crash"), RESPONSE_ACCEPT);
2819 dialog.set_default_response (RESPONSE_ACCEPT);
2820 dialog.set_position (WIN_POS_CENTER);
2825 switch (dialog.run ()) {
2826 case RESPONSE_ACCEPT:
2834 ARDOUR_UI::store_clock_modes ()
2836 if (session_load_in_progress) {
2837 /* Do not overwrite clock modes while loading them (with a session) */
2841 XMLNode* node = new XMLNode(X_("ClockModes"));
2843 for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
2844 XMLNode* child = new XMLNode (X_("Clock"));
2846 child->set_property (X_("name"), (*x)->name());
2847 child->set_property (X_("mode"), (*x)->mode());
2848 child->set_property (X_("on"), (*x)->on());
2850 node->add_child_nocopy (*child);
2853 _session->add_extra_xml (*node);
2854 _session->set_dirty ();
2857 /** Allocate our thread-local buffers */
2859 ARDOUR_UI::get_process_buffers ()
2861 _process_thread->get_buffers ();
2864 /** Drop our thread-local buffers */
2866 ARDOUR_UI::drop_process_buffers ()
2868 _process_thread->drop_buffers ();
2872 ARDOUR_UI::feedback_detected ()
2874 _feedback_exists = true;
2878 ARDOUR_UI::successful_graph_sort ()
2880 _feedback_exists = false;
2884 ARDOUR_UI::midi_panic ()
2887 _session->midi_panic();
2892 ARDOUR_UI::reset_peak_display ()
2894 if (!_session || !_session->master_out() || !editor_meter) return;
2895 editor_meter->clear_meters();
2896 editor_meter_max_peak = -INFINITY;
2897 editor_meter_peak_display.set_active_state ( Gtkmm2ext::Off );
2901 ARDOUR_UI::reset_group_peak_display (RouteGroup* group)
2903 if (!_session || !_session->master_out()) return;
2904 if (group == _session->master_out()->route_group()) {
2905 reset_peak_display ();
2910 ARDOUR_UI::reset_route_peak_display (Route* route)
2912 if (!_session || !_session->master_out()) return;
2913 if (_session->master_out().get() == route) {
2914 reset_peak_display ();
2919 ARDOUR_UI::hide_application ()
2921 Application::instance ()-> hide ();
2925 ARDOUR_UI::setup_toplevel_window (Gtk::Window& window, const string& name, void* owner)
2927 /* icons, titles, WM stuff */
2929 static list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
2931 if (window_icons.empty()) {
2932 Glib::RefPtr<Gdk::Pixbuf> icon;
2933 if ((icon = ::get_icon (PROGRAM_NAME "-icon_16px"))) {
2934 window_icons.push_back (icon);
2936 if ((icon = ::get_icon (PROGRAM_NAME "-icon_22px"))) {
2937 window_icons.push_back (icon);
2939 if ((icon = ::get_icon (PROGRAM_NAME "-icon_32px"))) {
2940 window_icons.push_back (icon);
2942 if ((icon = ::get_icon (PROGRAM_NAME "-icon_48px"))) {
2943 window_icons.push_back (icon);
2947 if (!window_icons.empty()) {
2948 window.set_default_icon_list (window_icons);
2951 Gtkmm2ext::WindowTitle title (Glib::get_application_name());
2953 if (!name.empty()) {
2957 window.set_title (title.get_string());
2958 window.set_wmclass (string_compose (X_("%1_%1"), downcase (std::string(PROGRAM_NAME)), downcase (name)), PROGRAM_NAME);
2960 window.set_flags (CAN_FOCUS);
2961 window.add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
2963 /* This is a hack to ensure that GTK-accelerators continue to
2964 * work. Once we switch over to entirely native bindings, this will be
2965 * unnecessary and should be removed
2967 window.add_accel_group (ActionManager::ui_manager->get_accel_group());
2969 window.signal_configure_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::configure_handler));
2970 window.signal_window_state_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbed_window_state_event_handler), owner));
2971 window.signal_key_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_event_handler), &window), false);
2972 window.signal_key_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_event_handler), &window), false);