2 Copyright (C) 1999-2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "gtk2ardour-config.h"
22 #include "gtk2ardour-version.h"
31 #ifndef PLATFORM_WINDOWS
32 #include <sys/resource.h>
42 #include <glib/gstdio.h>
44 #include <gtkmm/messagedialog.h>
45 #include <gtkmm/accelmap.h>
47 #include "pbd/error.h"
48 #include "pbd/basename.h"
49 #include "pbd/compose.h"
50 #include "pbd/failed_constructor.h"
51 #include "pbd/enumwriter.h"
52 #include "pbd/memento_command.h"
53 #include "pbd/openuri.h"
54 #include "pbd/stl_delete.h"
55 #include "pbd/file_utils.h"
56 #include "pbd/localtime_r.h"
57 #include "pbd/pthread_utils.h"
59 #include "gtkmm2ext/application.h"
60 #include "gtkmm2ext/bindings.h"
61 #include "gtkmm2ext/gtk_ui.h"
62 #include "gtkmm2ext/utils.h"
63 #include "gtkmm2ext/click_box.h"
64 #include "gtkmm2ext/fastmeter.h"
65 #include "gtkmm2ext/popup.h"
66 #include "gtkmm2ext/window_title.h"
68 #include "ardour/ardour.h"
69 #include "ardour/audio_backend.h"
70 #include "ardour/audioengine.h"
71 #include "ardour/audiofilesource.h"
72 #include "ardour/automation_watch.h"
73 #include "ardour/diskstream.h"
74 #include "ardour/filename_extensions.h"
75 #include "ardour/filesystem_paths.h"
76 #include "ardour/port.h"
77 #include "ardour/plugin_manager.h"
78 #include "ardour/process_thread.h"
79 #include "ardour/profile.h"
80 #include "ardour/recent_sessions.h"
81 #include "ardour/session_directory.h"
82 #include "ardour/session_route.h"
83 #include "ardour/session_state_utils.h"
84 #include "ardour/session_utils.h"
85 #include "ardour/slave.h"
86 #include "ardour/system_exec.h"
88 #ifdef WINDOWS_VST_SUPPORT
91 #ifdef AUDIOUNIT_SUPPORT
92 #include "ardour/audio_unit.h"
95 #include "timecode/time.h"
97 typedef uint64_t microseconds_t;
102 #include "add_route_dialog.h"
103 #include "ambiguous_file_dialog.h"
104 #include "ardour_ui.h"
105 #include "audio_clock.h"
106 #include "big_clock_window.h"
107 #include "bundle_manager.h"
108 #include "engine_dialog.h"
109 #include "export_video_dialog.h"
110 #include "export_video_infobox.h"
111 #include "gain_meter.h"
112 #include "global_port_matrix.h"
113 #include "gui_object.h"
114 #include "gui_thread.h"
115 #include "keyboard.h"
116 #include "keyeditor.h"
117 #include "location_ui.h"
118 #include "main_clock.h"
119 #include "missing_file_dialog.h"
120 #include "missing_plugin_dialog.h"
121 #include "mixer_ui.h"
122 #include "mouse_cursors.h"
125 #include "pingback.h"
126 #include "processor_box.h"
127 #include "prompter.h"
128 #include "public_editor.h"
129 #include "rc_option_editor.h"
130 #include "route_time_axis.h"
131 #include "route_params_ui.h"
132 #include "save_as_dialog.h"
133 #include "session_dialog.h"
134 #include "session_metadata_dialog.h"
135 #include "session_option_editor.h"
136 #include "shuttle_control.h"
137 #include "speaker_dialog.h"
140 #include "theme_manager.h"
141 #include "time_axis_view_item.h"
144 #include "video_server_dialog.h"
145 #include "add_video_dialog.h"
146 #include "transcode_video_dialog.h"
150 using namespace ARDOUR;
151 using namespace ARDOUR_UI_UTILS;
153 using namespace Gtkmm2ext;
156 using namespace Editing;
158 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
160 sigc::signal<void, framepos_t, bool, framepos_t> ARDOUR_UI::Clock;
161 sigc::signal<void> ARDOUR_UI::CloseAllDialogs;
163 float ARDOUR_UI::ui_scale = 1.0;
166 ask_about_configuration_copy (string const & old_dir, string const & new_dir, int version)
168 MessageDialog msg (string_compose (_("%1 %2.x has discovered configuration files from %1 %3.x.\n\n"
169 "Would you like these files to be copied and used for %1 %2.x?\n\n"
170 "(This will require you to restart %1.)"),
171 PROGRAM_NAME, PROGRAM_VERSION, version),
172 false, /* no markup */
175 true /* modal, though it hardly matters since it is the only window */
178 msg.set_default_response (Gtk::RESPONSE_YES);
181 return (msg.run() == Gtk::RESPONSE_YES);
184 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir, UIConfiguration* uic)
186 : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
187 , ui_config (uic->post_gui_init ())
188 , session_loaded (false)
189 , gui_object_state (new GUIObjectState)
190 , primary_clock (new MainClock (X_("primary"), X_("transport"), true ))
191 , secondary_clock (new MainClock (X_("secondary"), X_("secondary"), false))
192 , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
194 , ignore_dual_punch (false)
199 , _mixer_on_top (false)
200 , first_time_engine_run (true)
201 , roll_controllable (new TransportControllable ("transport roll", *this, TransportControllable::Roll))
202 , stop_controllable (new TransportControllable ("transport stop", *this, TransportControllable::Stop))
203 , goto_start_controllable (new TransportControllable ("transport goto start", *this, TransportControllable::GotoStart))
204 , goto_end_controllable (new TransportControllable ("transport goto end", *this, TransportControllable::GotoEnd))
205 , auto_loop_controllable (new TransportControllable ("transport auto loop", *this, TransportControllable::AutoLoop))
206 , play_selection_controllable (new TransportControllable ("transport play selection", *this, TransportControllable::PlaySelection))
207 , rec_controllable (new TransportControllable ("transport rec-enable", *this, TransportControllable::RecordEnable))
208 , auto_return_button (ArdourButton::led_default_elements)
209 , follow_edits_button (ArdourButton::led_default_elements)
210 , auto_input_button (ArdourButton::led_default_elements)
211 , auditioning_alert_button (_("Audition"))
212 , solo_alert_button (_("Solo"))
213 , feedback_alert_button (_("Feedback"))
214 , error_alert_button ( ArdourButton::just_led_default_elements )
216 , editor_meter_peak_display()
217 , session_selector_window (0)
218 , open_session_selector (0)
219 , _numpad_locate_happening (false)
220 , _session_is_new (false)
221 , last_key_press_time (0)
224 , speaker_config_window (X_("speaker-config"), _("Speaker Configuration"))
225 , key_editor (X_("key-editor"), _("Key Bindings"))
226 , rc_option_editor (X_("rc-options-editor"), _("Preferences"))
227 , add_route_dialog (X_("add-routes"), _("Add Tracks/Busses"))
228 , about (X_("about"), _("About"))
229 , location_ui (X_("locations"), _("Locations"))
230 , route_params (X_("inspector"), _("Tracks and Busses"))
231 , audio_midi_setup (X_("audio-midi-setup"), _("Audio/MIDI Setup"))
232 , export_video_dialog (X_("video-export"), _("Video Export Dialog"))
233 , session_option_editor (X_("session-options-editor"), _("Properties"), boost::bind (&ARDOUR_UI::create_session_option_editor, this))
234 , add_video_dialog (X_("add-video"), _("Add Tracks/Busses"), boost::bind (&ARDOUR_UI::create_add_video_dialog, this))
235 , bundle_manager (X_("bundle-manager"), _("Bundle Manager"), boost::bind (&ARDOUR_UI::create_bundle_manager, this))
236 , big_clock_window (X_("big-clock"), _("Big Clock"), boost::bind (&ARDOUR_UI::create_big_clock_window, this))
237 , audio_port_matrix (X_("audio-connection-manager"), _("Audio Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::AUDIO))
238 , midi_port_matrix (X_("midi-connection-manager"), _("MIDI Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::MIDI))
239 , video_server_process (0)
241 , have_configure_timeout (false)
242 , last_configure_time (0)
244 , have_disk_speed_dialog_displayed (false)
245 , _status_bar_visibility (X_("status-bar"))
246 , _feedback_exists (false)
247 , _log_not_acknowledged (LogLevelNone)
249 Gtkmm2ext::init (localedir);
251 if (ARDOUR::handle_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) {
252 MessageDialog msg (string_compose (_("Your configuration files were copied. You can now restart %1."), PROGRAM_NAME), true);
254 /* configuration was modified, exit immediately */
258 if (theArdourUI == 0) {
262 ui_config->ParameterChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::parameter_changed));
263 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
264 ui_config->map_parameters (pc);
266 roll_button.set_controllable (roll_controllable);
267 stop_button.set_controllable (stop_controllable);
268 goto_start_button.set_controllable (goto_start_controllable);
269 goto_end_button.set_controllable (goto_end_controllable);
270 auto_loop_button.set_controllable (auto_loop_controllable);
271 play_selection_button.set_controllable (play_selection_controllable);
272 rec_button.set_controllable (rec_controllable);
274 roll_button.set_name ("transport button");
275 stop_button.set_name ("transport button");
276 goto_start_button.set_name ("transport button");
277 goto_end_button.set_name ("transport button");
278 auto_loop_button.set_name ("transport button");
279 play_selection_button.set_name ("transport button");
280 rec_button.set_name ("transport recenable button");
281 midi_panic_button.set_name ("transport button");
283 ARDOUR::Diskstream::DiskOverrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
284 ARDOUR::Diskstream::DiskUnderrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
286 ARDOUR::Session::VersionMismatch.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_format_mismatch, this, _1, _2), gui_context());
288 /* handle dialog requests */
290 ARDOUR::Session::Dialog.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_dialog, this, _1), gui_context());
292 /* handle pending state with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
294 ARDOUR::Session::AskAboutPendingState.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::pending_state_dialog, this));
296 /* handle Audio/MIDI setup when session requires it */
298 ARDOUR::Session::AudioEngineSetupRequired.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::do_audio_midi_setup, this, _1));
300 /* handle sr mismatch with a dialog (PROBLEM: needs to return a value and thus cannot be x-thread) */
302 ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
304 /* handle requests to quit (coming from JACK session) */
306 ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
308 /* tell the user about feedback */
310 ARDOUR::Session::FeedbackDetected.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::feedback_detected, this), gui_context ());
311 ARDOUR::Session::SuccessfulGraphSort.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::successful_graph_sort, this), gui_context ());
313 /* handle requests to deal with missing files */
315 ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3));
317 /* and ambiguous files */
319 ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2));
321 /* also plugin scan messages */
322 ARDOUR::PluginScanMessage.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::plugin_scan_dialog, this, _1, _2, _3), gui_context());
323 ARDOUR::PluginScanTimeout.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::plugin_scan_timeout, this, _1), gui_context());
325 ARDOUR::GUIIdle.connect (forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::gui_idle_handler, this), gui_context());
327 Config->ParameterChanged.connect ( forever_connections, MISSING_INVALIDATOR, boost::bind(&ARDOUR_UI::set_flat_buttons, this), gui_context() );
330 /* lets get this party started */
332 setup_gtk_ardour_enums ();
335 SessionEvent::create_per_thread_pool ("GUI", 512);
337 /* we like keyboards */
339 keyboard = new ArdourKeyboard(*this);
341 XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
343 keyboard->set_state (*node, Stateful::loading_state_version);
346 /* we don't like certain modifiers */
347 Bindings::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK);
351 TimeAxisViewItem::set_constant_heights ();
353 /* Set this up so that our window proxies can register actions */
355 ActionManager::init ();
357 /* The following must happen after ARDOUR::init() so that Config is set up */
359 const XMLNode* ui_xml = Config->extra_xml (X_("UI"));
362 key_editor.set_state (*ui_xml);
363 rc_option_editor.set_state (*ui_xml);
364 session_option_editor.set_state (*ui_xml);
365 speaker_config_window.set_state (*ui_xml);
366 about.set_state (*ui_xml);
367 add_route_dialog.set_state (*ui_xml);
368 add_video_dialog.set_state (*ui_xml);
369 route_params.set_state (*ui_xml);
370 bundle_manager.set_state (*ui_xml);
371 location_ui.set_state (*ui_xml);
372 big_clock_window.set_state (*ui_xml);
373 audio_port_matrix.set_state (*ui_xml);
374 midi_port_matrix.set_state (*ui_xml);
375 export_video_dialog.set_state (*ui_xml);
378 WM::Manager::instance().register_window (&key_editor);
379 WM::Manager::instance().register_window (&rc_option_editor);
380 WM::Manager::instance().register_window (&session_option_editor);
381 WM::Manager::instance().register_window (&speaker_config_window);
382 WM::Manager::instance().register_window (&about);
383 WM::Manager::instance().register_window (&add_route_dialog);
384 WM::Manager::instance().register_window (&add_video_dialog);
385 WM::Manager::instance().register_window (&route_params);
386 WM::Manager::instance().register_window (&audio_midi_setup);
387 WM::Manager::instance().register_window (&export_video_dialog);
388 WM::Manager::instance().register_window (&bundle_manager);
389 WM::Manager::instance().register_window (&location_ui);
390 WM::Manager::instance().register_window (&big_clock_window);
391 WM::Manager::instance().register_window (&audio_port_matrix);
392 WM::Manager::instance().register_window (&midi_port_matrix);
394 /* Trigger setting up the color scheme and loading the GTK RC file */
396 ARDOUR_UI::config()->load_rc_file (false);
398 _process_thread = new ProcessThread ();
399 _process_thread->init ();
401 DPIReset.connect (sigc::mem_fun (*this, &ARDOUR_UI::resize_text_widgets));
406 GlobalPortMatrixWindow*
407 ARDOUR_UI::create_global_port_matrix (ARDOUR::DataType type)
412 return new GlobalPortMatrixWindow (_session, type);
416 ARDOUR_UI::attach_to_engine ()
418 AudioEngine::instance()->Running.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_running, this), gui_context());
419 ARDOUR::Port::set_connecting_blocked (ARDOUR_COMMAND_LINE::no_connect_ports);
423 ARDOUR_UI::engine_stopped ()
425 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_stopped)
426 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, false);
427 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, true);
431 ARDOUR_UI::engine_running ()
433 if (first_time_engine_run) {
435 first_time_engine_run = false;
439 _session->reset_xrun_count ();
441 update_disk_space ();
443 update_xrun_count ();
444 update_sample_rate (AudioEngine::instance()->sample_rate());
445 update_timecode_format ();
449 ARDOUR_UI::engine_halted (const char* reason, bool free_reason)
451 if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
452 /* we can't rely on the original string continuing to exist when we are called
453 again in the GUI thread, so make a copy and note that we need to
456 char *copy = strdup (reason);
457 Gtkmm2ext::UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_halted, this, copy, true));
461 ActionManager::set_sensitive (ActionManager::engine_sensitive_actions, false);
462 ActionManager::set_sensitive (ActionManager::engine_opposite_sensitive_actions, true);
464 update_sample_rate (0);
468 /* if the reason is a non-empty string, it means that the backend was shutdown
469 rather than just Ardour.
472 if (strlen (reason)) {
473 msgstr = string_compose (_("The audio backend was shutdown because:\n\n%1"), reason);
475 msgstr = string_compose (_("\
476 The audio backend has either been shutdown or it\n\
477 disconnected %1 because %1\n\
478 was not fast enough. Try to restart\n\
479 the audio backend and save the session."), PROGRAM_NAME);
482 MessageDialog msg (*editor, msgstr);
483 pop_back_splash (msg);
487 free (const_cast<char*> (reason));
492 ARDOUR_UI::post_engine ()
494 /* Things to be done once (and once ONLY) after we have a backend running in the AudioEngine
496 #ifdef AUDIOUNIT_SUPPORT
498 if (AUPluginInfo::au_get_crashlog(au_msg)) {
499 popup_error(_("Audio Unit Plugin Scan Failed. Automatic AU scanning has been disabled. Please see the log window for further details."));
500 error << _("Audio Unit Plugin Scan Failed:") << endmsg;
501 info << au_msg << endmsg;
505 ARDOUR::init_post_engine ();
507 /* connect to important signals */
509 AudioEngine::instance()->Stopped.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::engine_stopped, this), gui_context());
510 AudioEngine::instance()->SampleRateChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
511 AudioEngine::instance()->BufferSizeChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_sample_rate, this, _1), gui_context());
512 AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
513 AudioEngine::instance()->BecameSilent.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::audioengine_became_silent, this), gui_context());
517 if (setup_windows ()) {
518 throw failed_constructor ();
521 /* Do this after setup_windows (), as that's when the _status_bar_visibility is created */
522 XMLNode* n = Config->extra_xml (X_("UI"));
524 _status_bar_visibility.set_state (*n);
527 check_memory_locking();
529 /* this is the first point at which all the keybindings are available */
531 if (ARDOUR_COMMAND_LINE::show_key_actions) {
532 vector<string> names;
533 vector<string> paths;
534 vector<string> tooltips;
536 vector<AccelKey> bindings;
538 ActionManager::get_all_actions (names, paths, tooltips, keys, bindings);
540 vector<string>::iterator n;
541 vector<string>::iterator k;
542 vector<string>::iterator p;
543 for (n = names.begin(), k = keys.begin(), p = paths.begin(); n != names.end(); ++n, ++k, ++p) {
544 cout << "Action: '" << (*n) << "' bound to '" << (*k) << "' Path: '" << (*p) << "'" << endl;
547 halt_connection.disconnect ();
548 AudioEngine::instance()->stop ();
552 /* this being a GUI and all, we want peakfiles */
554 AudioFileSource::set_build_peakfiles (true);
555 AudioFileSource::set_build_missing_peakfiles (true);
557 /* set default clock modes */
559 if (Profile->get_sae()) {
560 primary_clock->set_mode (AudioClock::BBT);
561 secondary_clock->set_mode (AudioClock::MinSec);
563 primary_clock->set_mode (AudioClock::Timecode);
564 secondary_clock->set_mode (AudioClock::BBT);
567 /* start the time-of-day-clock */
570 /* OS X provides a nearly-always visible wallclock, so don't be stupid */
571 update_wall_clock ();
572 Glib::signal_timeout().connect_seconds (sigc::mem_fun(*this, &ARDOUR_UI::update_wall_clock), 1);
577 Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
578 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
579 Config->map_parameters (pc);
581 ui_config->map_parameters (pc);
585 ARDOUR_UI::~ARDOUR_UI ()
587 ui_config->save_state();
591 if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
592 // don't bother at 'real' exit. the OS cleans up for us.
594 delete primary_clock;
595 delete secondary_clock;
596 delete _process_thread;
597 delete gui_object_state;
598 FastMeter::flush_pattern_cache ();
603 ARDOUR_UI::pop_back_splash (Gtk::Window& win)
605 if (Splash::instance()) {
606 Splash::instance()->pop_back_for (win);
611 ARDOUR_UI::configure_timeout ()
613 if (last_configure_time == 0) {
614 /* no configure events yet */
618 /* force a gap of 0.5 seconds since the last configure event
621 if (get_microseconds() - last_configure_time < 500000) {
624 have_configure_timeout = false;
625 save_ardour_state ();
631 ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
633 if (have_configure_timeout) {
634 last_configure_time = get_microseconds();
636 Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::configure_timeout), 100);
637 have_configure_timeout = true;
644 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
646 const XMLProperty* prop;
648 if ((prop = node.property ("roll")) != 0) {
649 roll_controllable->set_id (prop->value());
651 if ((prop = node.property ("stop")) != 0) {
652 stop_controllable->set_id (prop->value());
654 if ((prop = node.property ("goto-start")) != 0) {
655 goto_start_controllable->set_id (prop->value());
657 if ((prop = node.property ("goto-end")) != 0) {
658 goto_end_controllable->set_id (prop->value());
660 if ((prop = node.property ("auto-loop")) != 0) {
661 auto_loop_controllable->set_id (prop->value());
663 if ((prop = node.property ("play-selection")) != 0) {
664 play_selection_controllable->set_id (prop->value());
666 if ((prop = node.property ("rec")) != 0) {
667 rec_controllable->set_id (prop->value());
669 if ((prop = node.property ("shuttle")) != 0) {
670 shuttle_box->controllable()->set_id (prop->value());
675 ARDOUR_UI::get_transport_controllable_state ()
677 XMLNode* node = new XMLNode(X_("TransportControllables"));
680 roll_controllable->id().print (buf, sizeof (buf));
681 node->add_property (X_("roll"), buf);
682 stop_controllable->id().print (buf, sizeof (buf));
683 node->add_property (X_("stop"), buf);
684 goto_start_controllable->id().print (buf, sizeof (buf));
685 node->add_property (X_("goto_start"), buf);
686 goto_end_controllable->id().print (buf, sizeof (buf));
687 node->add_property (X_("goto_end"), buf);
688 auto_loop_controllable->id().print (buf, sizeof (buf));
689 node->add_property (X_("auto_loop"), buf);
690 play_selection_controllable->id().print (buf, sizeof (buf));
691 node->add_property (X_("play_selection"), buf);
692 rec_controllable->id().print (buf, sizeof (buf));
693 node->add_property (X_("rec"), buf);
694 shuttle_box->controllable()->id().print (buf, sizeof (buf));
695 node->add_property (X_("shuttle"), buf);
701 ARDOUR_UI::save_session_at_its_request (std::string snapshot_name)
704 _session->save_state (snapshot_name);
709 ARDOUR_UI::autosave_session ()
711 if (g_main_depth() > 1) {
712 /* inside a recursive main loop,
713 give up because we may not be able to
719 if (!Config->get_periodic_safety_backups()) {
724 _session->maybe_write_autosave();
731 ARDOUR_UI::update_autosave ()
733 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_autosave)
735 if (_session && _session->dirty()) {
736 if (_autosave_connection.connected()) {
737 _autosave_connection.disconnect();
740 _autosave_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &ARDOUR_UI::autosave_session),
741 Config->get_periodic_safety_backup_interval() * 1000);
744 if (_autosave_connection.connected()) {
745 _autosave_connection.disconnect();
751 ARDOUR_UI::check_announcements ()
754 string _annc_filename;
757 _annc_filename = PROGRAM_NAME "_announcements_osx_";
759 _annc_filename = PROGRAM_NAME "_announcements_linux_";
761 _annc_filename.append (VERSIONSTRING);
763 std::string path = Glib::build_filename (user_config_directory(), _annc_filename);
764 std::ifstream announce_file (path.c_str());
765 if ( announce_file.fail() )
766 _announce_string = "";
768 std::stringstream oss;
769 oss << announce_file.rdbuf();
770 _announce_string = oss.str();
773 pingback (VERSIONSTRING, path);
778 ARDOUR_UI::starting ()
780 Application* app = Application::instance ();
782 bool brand_new_user = ArdourStartup::required ();
784 app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish));
785 app->ShouldLoad.connect (sigc::mem_fun (*this, &ARDOUR_UI::load_from_application_api));
787 if (ARDOUR_COMMAND_LINE::check_announcements) {
788 check_announcements ();
793 /* we need to create this early because it may need to set the
794 * audio backend end up.
798 audio_midi_setup.get (true);
800 std::cerr << "audio-midi engine setup failed."<< std::endl;
804 if ((nsm_url = g_getenv ("NSM_URL")) != 0) {
805 nsm = new NSM_Client;
806 if (!nsm->init (nsm_url)) {
807 /* the ardour executable may have different names:
809 * waf's obj.target for distro versions: eg ardour4, ardourvst4
810 * Ardour4, Mixbus3 for bundled versions + full path on OSX & windows
811 * argv[0] does not apply since we need the wrapper-script (not the binary itself)
813 * The wrapper startup script should set the environment variable 'ARDOUR_SELF'
815 const char *process_name = g_getenv ("ARDOUR_SELF");
816 nsm->announce (PROGRAM_NAME, ":dirty:", process_name ? process_name : "ardour4");
819 // wait for announce reply from nsm server
820 for ( i = 0; i < 5000; ++i) {
824 if (nsm->is_active()) {
829 error << _("NSM server did not announce itself") << endmsg;
832 // wait for open command from nsm server
833 for ( i = 0; i < 5000; ++i) {
836 if (nsm->client_id ()) {
842 error << _("NSM: no client ID provided") << endmsg;
846 if (_session && nsm) {
847 _session->set_nsm_state( nsm->is_active() );
849 error << _("NSM: no session created") << endmsg;
853 // nsm requires these actions disabled
854 vector<string> action_names;
855 action_names.push_back("SaveAs");
856 action_names.push_back("Rename");
857 action_names.push_back("New");
858 action_names.push_back("Open");
859 action_names.push_back("Recent");
860 action_names.push_back("Close");
862 for (vector<string>::const_iterator n = action_names.begin(); n != action_names.end(); ++n) {
863 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), (*n).c_str());
865 act->set_sensitive (false);
872 error << _("NSM: initialization failed") << endmsg;
878 if (brand_new_user) {
883 switch (s.response ()) {
884 case Gtk::RESPONSE_OK:
891 #ifdef NO_PLUGIN_STATE
893 ARDOUR::RecentSessions rs;
894 ARDOUR::read_recent_sessions (rs);
896 string path = Glib::build_filename (user_config_directory(), ".iknowaboutfreeversion");
898 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS) && !rs.empty()) {
900 /* already used Ardour, have sessions ... warn about plugin state */
902 ArdourDialog d (_("Free/Demo Version Warning"), true);
904 Button b (string_compose (_("Subscribe and support development of %1"), PROGRAM_NAME));
905 CheckButton c (_("Don't warn me about this again"));
907 l.set_markup (string_compose (_("<span weight=\"bold\" size=\"large\">%1</span>\n\n<b>%2</b>\n\n<i>%3</i>\n\n%4"),
908 string_compose (_("This is a free/demo version of %1"), PROGRAM_NAME),
909 _("It will not restore OR save any plugin settings"),
910 _("If you load an existing session with plugin settings\n"
911 "they will not be used and will be lost."),
912 _("To get full access to updates without this limitation\n"
913 "consider becoming a subscriber for a low cost every month.")));
914 l.set_justify (JUSTIFY_CENTER);
916 b.signal_clicked().connect (mem_fun(*this, &ARDOUR_UI::launch_subscribe));
918 d.get_vbox()->pack_start (l, true, true);
919 d.get_vbox()->pack_start (b, false, false, 12);
920 d.get_vbox()->pack_start (c, false, false, 12);
922 d.add_button (_("Quit now"), RESPONSE_CANCEL);
923 d.add_button (string_compose (_("Continue using %1"), PROGRAM_NAME), RESPONSE_OK);
927 c.signal_toggled().connect (sigc::hide_return (sigc::bind (sigc::ptr_fun (toggle_file_existence), path)));
929 if (d.run () != RESPONSE_OK) {
935 /* go get a session */
937 const bool new_session_required = (ARDOUR_COMMAND_LINE::new_session || brand_new_user);
939 if (get_session_parameters (false, new_session_required, ARDOUR_COMMAND_LINE::load_template)) {
940 std::cerr << "Cannot get session parameters."<< std::endl;
947 goto_editor_window ();
949 WM::Manager::instance().show_visible ();
951 /* We have to do this here since goto_editor_window() ends up calling show_all() on the
952 * editor window, and we may want stuff to be hidden.
954 _status_bar_visibility.update ();
956 BootMessage (string_compose (_("%1 is ready for use"), PROGRAM_NAME));
961 ARDOUR_UI::check_memory_locking ()
963 #if defined(__APPLE__) || defined(PLATFORM_WINDOWS)
964 /* OS X doesn't support mlockall(2), and so testing for memory locking capability there is pointless */
968 XMLNode* memory_warning_node = Config->instant_xml (X_("no-memory-warning"));
970 if (AudioEngine::instance()->is_realtime() && memory_warning_node == 0) {
972 struct rlimit limits;
974 long pages, page_size;
976 size_t pages_len=sizeof(pages);
977 if ((page_size = getpagesize()) < 0 ||
978 sysctlbyname("hw.availpages", &pages, &pages_len, NULL, 0))
980 if ((page_size = sysconf (_SC_PAGESIZE)) < 0 ||(pages = sysconf (_SC_PHYS_PAGES)) < 0)
985 ram = (int64_t) pages * (int64_t) page_size;
988 if (getrlimit (RLIMIT_MEMLOCK, &limits)) {
992 if (limits.rlim_cur != RLIM_INFINITY) {
994 if (ram == 0 || ((double) limits.rlim_cur / ram) < 0.75) {
998 _("WARNING: Your system has a limit for maximum amount of locked memory. "
999 "This might cause %1 to run out of memory before your system "
1000 "runs out of memory. \n\n"
1001 "You can view the memory limit with 'ulimit -l', "
1002 "and it is normally controlled by %2"),
1005 X_("/etc/login.conf")
1007 X_(" /etc/security/limits.conf")
1011 msg.set_default_response (RESPONSE_OK);
1013 VBox* vbox = msg.get_vbox();
1015 CheckButton cb (_("Do not show this window again"));
1016 hbox.pack_start (cb, true, false);
1017 vbox->pack_start (hbox);
1022 pop_back_splash (msg);
1024 editor->ensure_float (msg);
1027 if (cb.get_active()) {
1028 XMLNode node (X_("no-memory-warning"));
1029 Config->add_instant_xml (node);
1034 #endif // !__APPLE__
1039 ARDOUR_UI::queue_finish ()
1041 Glib::signal_idle().connect (mem_fun (*this, &ARDOUR_UI::idle_finish));
1045 ARDOUR_UI::idle_finish ()
1048 return false; /* do not call again */
1055 ARDOUR_UI::instance()->video_timeline->sync_session_state();
1057 if (_session->dirty()) {
1058 vector<string> actions;
1059 actions.push_back (_("Don't quit"));
1060 actions.push_back (_("Just quit"));
1061 actions.push_back (_("Save and quit"));
1062 switch (ask_about_saving_session(actions)) {
1067 /* use the default name */
1068 if (save_state_canfail ("")) {
1069 /* failed - don't quit */
1070 MessageDialog msg (*editor,
1071 string_compose (_("\
1072 %1 was unable to save your session.\n\n\
1073 If you still wish to quit, please use the\n\n\
1074 \"Just quit\" option."), PROGRAM_NAME));
1075 pop_back_splash(msg);
1085 second_connection.disconnect ();
1086 point_one_second_connection.disconnect ();
1087 point_zero_something_second_connection.disconnect();
1088 fps_connection.disconnect();
1091 delete ARDOUR_UI::instance()->video_timeline;
1092 ARDOUR_UI::instance()->video_timeline = NULL;
1093 stop_video_server();
1095 /* Save state before deleting the session, as that causes some
1096 windows to be destroyed before their visible state can be
1099 save_ardour_state ();
1101 close_all_dialogs ();
1104 _session->set_clean ();
1105 _session->remove_pending_capture_state ();
1110 halt_connection.disconnect ();
1111 AudioEngine::instance()->stop ();
1112 #ifdef WINDOWS_VST_SUPPORT
1113 fst_stop_threading();
1119 ARDOUR_UI::ask_about_saving_session (const vector<string>& actions)
1121 ArdourDialog window (_("Unsaved Session"));
1122 Gtk::HBox dhbox; // the hbox for the image and text
1123 Gtk::Label prompt_label;
1124 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_WARNING, Gtk::ICON_SIZE_DIALOG));
1128 assert (actions.size() >= 3);
1130 window.add_button (actions[0], RESPONSE_REJECT);
1131 window.add_button (actions[1], RESPONSE_APPLY);
1132 window.add_button (actions[2], RESPONSE_ACCEPT);
1134 window.set_default_response (RESPONSE_ACCEPT);
1136 Gtk::Button noquit_button (msg);
1137 noquit_button.set_name ("EditorGTKButton");
1141 if (_session->snap_name() == _session->name()) {
1142 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?"),
1143 _session->snap_name());
1145 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?"),
1146 _session->snap_name());
1149 prompt_label.set_text (prompt);
1150 prompt_label.set_name (X_("PrompterLabel"));
1151 prompt_label.set_alignment(ALIGN_LEFT, ALIGN_TOP);
1153 dimage->set_alignment(ALIGN_CENTER, ALIGN_TOP);
1154 dhbox.set_homogeneous (false);
1155 dhbox.pack_start (*dimage, false, false, 5);
1156 dhbox.pack_start (prompt_label, true, false, 5);
1157 window.get_vbox()->pack_start (dhbox);
1159 window.set_name (_("Prompter"));
1160 window.set_modal (true);
1161 window.set_resizable (false);
1164 prompt_label.show();
1169 ResponseType r = (ResponseType) window.run();
1174 case RESPONSE_ACCEPT: // save and get out of here
1176 case RESPONSE_APPLY: // get out of here
1187 ARDOUR_UI::every_second ()
1190 update_xrun_count ();
1191 update_buffer_load ();
1192 update_disk_space ();
1193 update_timecode_format ();
1195 if (nsm && nsm->is_active ()) {
1198 if (!_was_dirty && _session->dirty ()) {
1202 else if (_was_dirty && !_session->dirty ()){
1210 ARDOUR_UI::every_point_one_seconds ()
1212 // TODO get rid of this..
1213 // ShuttleControl is updated directly via TransportStateChange signal
1217 ARDOUR_UI::every_point_zero_something_seconds ()
1219 // august 2007: actual update frequency: 25Hz (40ms), not 100Hz
1221 if (editor_meter && ARDOUR_UI::config()->get_show_editor_meter()) {
1222 float mpeak = editor_meter->update_meters();
1223 if (mpeak > editor_meter_max_peak) {
1224 if (mpeak >= ARDOUR_UI::config()->get_meter_peak()) {
1225 editor_meter_peak_display.set_active_state ( Gtkmm2ext::ExplicitActive );
1232 ARDOUR_UI::set_fps_timeout_connection ()
1234 unsigned int interval = 40;
1235 if (!_session) return;
1236 if (_session->timecode_frames_per_second() != 0) {
1237 /* ideally we'll use a select() to sleep and not accumulate
1238 * idle time to provide a regular periodic signal.
1239 * See linux_vst_gui_support.cc 'elapsed_time_ms'.
1240 * However, that'll require a dedicated thread and cross-thread
1241 * signals to the GUI Thread..
1243 interval = floor(500. /* update twice per FPS, since Glib::signal_timeout is very irregular */
1244 * _session->frame_rate() / _session->nominal_frame_rate()
1245 / _session->timecode_frames_per_second()
1247 #ifdef PLATFORM_WINDOWS
1248 // the smallest windows scheduler time-slice is ~15ms.
1249 // periodic GUI timeouts shorter than that will cause
1250 // WaitForSingleObject to spinlock (100% of one CPU Core)
1251 // and gtk never enters idle mode.
1252 // also changing timeBeginPeriod(1) does not affect that in
1253 // any beneficial way, so we just limit the max rate for now.
1254 interval = std::max(30u, interval); // at most ~33Hz.
1256 interval = std::max(8u, interval); // at most 120Hz.
1259 fps_connection.disconnect();
1260 Timers::set_fps_interval (interval);
1264 ARDOUR_UI::update_sample_rate (framecnt_t)
1268 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
1270 if (!AudioEngine::instance()->connected()) {
1272 snprintf (buf, sizeof (buf), "%s", _("Audio: <span foreground=\"red\">none</span>"));
1276 framecnt_t rate = AudioEngine::instance()->sample_rate();
1279 /* no sample rate available */
1280 snprintf (buf, sizeof (buf), "%s", _("Audio: <span foreground=\"red\">none</span>"));
1283 if (fmod (rate, 1000.0) != 0.0) {
1284 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"green\">%.1f kHz / %4.1f ms</span>"),
1285 (float) rate / 1000.0f,
1286 (AudioEngine::instance()->usecs_per_cycle() / 1000.0f));
1288 snprintf (buf, sizeof (buf), _("Audio: <span foreground=\"green\">%" PRId64 " kHz / %4.1f ms</span>"),
1290 (AudioEngine::instance()->usecs_per_cycle() / 1000.0f));
1294 sample_rate_label.set_markup (buf);
1298 ARDOUR_UI::update_format ()
1301 format_label.set_text ("");
1306 s << _("File:") << X_(" <span foreground=\"green\">");
1308 switch (_session->config.get_native_file_header_format ()) {
1334 switch (_session->config.get_native_file_data_format ()) {
1348 format_label.set_markup (s.str ());
1352 ARDOUR_UI::update_xrun_count ()
1356 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1357 should also be changed.
1361 const unsigned int x = _session->get_xrun_count ();
1363 snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">>10K</span>"), X_("red"));
1365 snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">%u</span>"), x > 0 ? X_("red") : X_("green"), x);
1368 snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">?</span>"), X_("yellow"));
1370 xrun_label.set_markup (buf);
1371 set_tip (xrun_label, _("Audio dropouts. Shift+click to reset"));
1375 ARDOUR_UI::update_cpu_load ()
1379 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1380 should also be changed.
1383 double const c = AudioEngine::instance()->get_dsp_load ();
1384 snprintf (buf, sizeof (buf), _("DSP: <span foreground=\"%s\">%5.1f%%</span>"), c >= 90 ? X_("red") : X_("green"), c);
1385 cpu_load_label.set_markup (buf);
1389 ARDOUR_UI::update_buffer_load ()
1393 uint32_t const playback = _session ? _session->playback_load () : 100;
1394 uint32_t const capture = _session ? _session->capture_load () : 100;
1396 /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
1397 should also be changed.
1403 _("Buffers: <span foreground=\"green\">p:</span><span foreground=\"%s\">%" PRIu32 "%%</span> "
1404 "<span foreground=\"green\">c:</span><span foreground=\"%s\">%" PRIu32 "%%</span>"),
1405 playback <= 5 ? X_("red") : X_("green"),
1407 capture <= 5 ? X_("red") : X_("green"),
1411 buffer_load_label.set_markup (buf);
1413 buffer_load_label.set_text ("");
1418 ARDOUR_UI::count_recenabled_streams (Route& route)
1420 Track* track = dynamic_cast<Track*>(&route);
1421 if (track && track->record_enabled()) {
1422 rec_enabled_streams += track->n_inputs().n_total();
1427 ARDOUR_UI::update_disk_space()
1429 if (_session == 0) {
1433 boost::optional<framecnt_t> opt_frames = _session->available_capture_duration();
1435 framecnt_t fr = _session->frame_rate();
1438 /* skip update - no SR available */
1443 /* Available space is unknown */
1444 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">Unknown</span>"));
1445 } else if (opt_frames.get_value_or (0) == max_framecnt) {
1446 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">24hrs+</span>"));
1448 rec_enabled_streams = 0;
1449 _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams, false);
1451 framecnt_t frames = opt_frames.get_value_or (0);
1453 if (rec_enabled_streams) {
1454 frames /= rec_enabled_streams;
1461 hrs = frames / (fr * 3600);
1464 snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">>24 hrs</span>"));
1466 frames -= hrs * fr * 3600;
1467 mins = frames / (fr * 60);
1468 frames -= mins * fr * 60;
1471 bool const low = (hrs == 0 && mins <= 30);
1475 _("Disk: <span foreground=\"%s\">%02dh:%02dm:%02ds</span>"),
1476 low ? X_("red") : X_("green"),
1482 disk_space_label.set_markup (buf);
1486 ARDOUR_UI::update_timecode_format ()
1492 TimecodeSlave* tcslave;
1493 SyncSource sync_src = Config->get_sync_source();
1495 if ((sync_src == LTC || sync_src == MTC) && (tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
1496 matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
1501 snprintf (buf, sizeof (buf), S_("Timecode|TC: <span foreground=\"%s\">%s</span>"),
1502 matching ? X_("green") : X_("red"),
1503 Timecode::timecode_format_name (_session->config.get_timecode_format()).c_str());
1505 snprintf (buf, sizeof (buf), "TC: n/a");
1508 timecode_format_label.set_markup (buf);
1512 ARDOUR_UI::update_wall_clock ()
1516 static int last_min = -1;
1519 tm_now = localtime (&now);
1520 if (last_min != tm_now->tm_min) {
1522 sprintf (buf, "%02d:%02d", tm_now->tm_hour, tm_now->tm_min);
1523 wall_clock_label.set_text (buf);
1524 last_min = tm_now->tm_min;
1531 ARDOUR_UI::redisplay_recent_sessions ()
1533 std::vector<std::string> session_directories;
1534 RecentSessionsSorter cmp;
1536 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
1537 recent_session_model->clear ();
1539 ARDOUR::RecentSessions rs;
1540 ARDOUR::read_recent_sessions (rs);
1543 recent_session_display.set_model (recent_session_model);
1547 // sort them alphabetically
1548 sort (rs.begin(), rs.end(), cmp);
1550 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
1551 session_directories.push_back ((*i).second);
1554 for (vector<std::string>::const_iterator i = session_directories.begin();
1555 i != session_directories.end(); ++i)
1557 std::vector<std::string> state_file_paths;
1559 // now get available states for this session
1561 get_state_files_in_directory (*i, state_file_paths);
1563 vector<string> states;
1564 vector<const gchar*> item;
1565 string fullpath = *i;
1567 /* remove any trailing / */
1569 if (fullpath[fullpath.length() - 1] == '/') {
1570 fullpath = fullpath.substr (0, fullpath.length() - 1);
1573 /* check whether session still exists */
1574 if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
1575 /* session doesn't exist */
1579 /* now get available states for this session */
1580 states = Session::possible_states (fullpath);
1582 if (states.empty()) {
1583 /* no state file? */
1587 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
1589 Gtk::TreeModel::Row row = *(recent_session_model->append());
1591 row[recent_session_columns.fullpath] = fullpath;
1592 row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath);
1594 if (state_file_names.size() > 1) {
1595 // multiple session files in the session directory - show the directory name.
1596 row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath);
1599 for (std::vector<std::string>::iterator i2 = state_file_names.begin();
1600 i2 != state_file_names.end(); ++i2)
1603 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
1605 child_row[recent_session_columns.visible_name] = *i2;
1606 child_row[recent_session_columns.fullpath] = fullpath;
1607 child_row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath);
1610 // only a single session file in the directory - show its actual name.
1611 row[recent_session_columns.visible_name] = state_file_names.front ();
1615 recent_session_display.set_tooltip_column(1); // recent_session_columns.tip
1616 recent_session_display.set_model (recent_session_model);
1620 ARDOUR_UI::build_session_selector ()
1622 session_selector_window = new ArdourDialog (_("Recent Sessions"));
1624 Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow);
1626 session_selector_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1627 session_selector_window->add_button (Stock::OPEN, RESPONSE_ACCEPT);
1628 session_selector_window->set_default_response (RESPONSE_ACCEPT);
1629 recent_session_model = TreeStore::create (recent_session_columns);
1630 recent_session_display.set_model (recent_session_model);
1631 recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name);
1632 recent_session_display.set_headers_visible (false);
1633 recent_session_display.get_selection()->set_mode (SELECTION_BROWSE);
1634 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &ARDOUR_UI::recent_session_row_activated));
1636 scroller->add (recent_session_display);
1637 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1639 session_selector_window->set_name ("SessionSelectorWindow");
1640 session_selector_window->set_size_request (200, 400);
1641 session_selector_window->get_vbox()->pack_start (*scroller);
1643 recent_session_display.show();
1648 ARDOUR_UI::recent_session_row_activated (const TreePath& /*path*/, TreeViewColumn* /*col*/)
1650 session_selector_window->response (RESPONSE_ACCEPT);
1654 ARDOUR_UI::open_recent_session ()
1656 bool can_return = (_session != 0);
1658 if (session_selector_window == 0) {
1659 build_session_selector ();
1662 redisplay_recent_sessions ();
1666 ResponseType r = (ResponseType) session_selector_window->run ();
1669 case RESPONSE_ACCEPT:
1673 session_selector_window->hide();
1680 if (recent_session_display.get_selection()->count_selected_rows() == 0) {
1684 session_selector_window->hide();
1686 Gtk::TreeModel::iterator i = recent_session_display.get_selection()->get_selected();
1688 if (i == recent_session_model->children().end()) {
1692 std::string path = (*i)[recent_session_columns.fullpath];
1693 std::string state = (*i)[recent_session_columns.visible_name];
1695 _session_is_new = false;
1697 if (load_session (path, state) == 0) {
1706 ARDOUR_UI::check_audioengine ()
1708 if (!AudioEngine::instance()->connected()) {
1709 MessageDialog msg (string_compose (
1710 _("%1 is not connected to any audio backend.\n"
1711 "You cannot open or close sessions in this condition"),
1713 pop_back_splash (msg);
1721 ARDOUR_UI::open_session ()
1723 if (!check_audioengine()) {
1728 /* popup selector window */
1730 if (open_session_selector == 0) {
1732 /* ardour sessions are folders */
1734 open_session_selector = new Gtk::FileChooserDialog (_("Open Session"), FILE_CHOOSER_ACTION_OPEN);
1735 open_session_selector->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1736 open_session_selector->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
1737 open_session_selector->set_default_response(Gtk::RESPONSE_ACCEPT);
1740 string session_parent_dir = Glib::path_get_dirname(_session->path());
1741 string::size_type last_dir_sep = session_parent_dir.rfind(G_DIR_SEPARATOR);
1742 session_parent_dir = session_parent_dir.substr(0, last_dir_sep);
1743 open_session_selector->set_current_folder(session_parent_dir);
1745 open_session_selector->set_current_folder(Config->get_default_session_parent_dir());
1748 string default_session_folder = Config->get_default_session_parent_dir();
1750 /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */
1751 open_session_selector->add_shortcut_folder (default_session_folder);
1753 catch (Glib::Error & e) {
1754 std::cerr << "open_session_selector->add_shortcut_folder (" << default_session_folder << ") threw Glib::Error " << e.what() << std::endl;
1757 FileFilter session_filter;
1758 session_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::statefile_suffix));
1759 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
1760 open_session_selector->add_filter (session_filter);
1761 open_session_selector->set_filter (session_filter);
1764 int response = open_session_selector->run();
1765 open_session_selector->hide ();
1768 case RESPONSE_ACCEPT:
1771 open_session_selector->hide();
1775 open_session_selector->hide();
1776 string session_path = open_session_selector->get_filename();
1780 if (session_path.length() > 0) {
1781 if (ARDOUR::find_session (session_path, path, name, isnew) == 0) {
1782 _session_is_new = isnew;
1783 load_session (path, name);
1790 ARDOUR_UI::session_add_mixed_track (const ChanCount& input, const ChanCount& output, RouteGroup* route_group,
1791 uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1793 list<boost::shared_ptr<MidiTrack> > tracks;
1795 if (_session == 0) {
1796 warning << _("You cannot add a track without a session already loaded.") << endmsg;
1801 tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template);
1803 if (tracks.size() != how_many) {
1804 error << string_compose(P_("could not create %1 new mixed track", "could not create %1 new mixed tracks", how_many), how_many) << endmsg;
1809 MessageDialog msg (*editor,
1810 string_compose (_("There are insufficient ports available\n\
1811 to create a new track or bus.\n\
1812 You should save %1, exit and\n\
1813 restart with more ports."), PROGRAM_NAME));
1820 ARDOUR_UI::session_add_midi_route (bool disk, RouteGroup* route_group, uint32_t how_many, const string& name_template, PluginInfoPtr instrument)
1822 ChanCount one_midi_channel;
1823 one_midi_channel.set (DataType::MIDI, 1);
1826 session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, instrument);
1831 ARDOUR_UI::session_add_audio_route (
1833 int32_t input_channels,
1834 int32_t output_channels,
1835 ARDOUR::TrackMode mode,
1836 RouteGroup* route_group,
1838 string const & name_template
1841 list<boost::shared_ptr<AudioTrack> > tracks;
1844 if (_session == 0) {
1845 warning << _("You cannot add a track or bus without a session already loaded.") << endmsg;
1851 tracks = _session->new_audio_track (input_channels, output_channels, mode, route_group, how_many, name_template);
1853 if (tracks.size() != how_many) {
1854 error << string_compose (P_("could not create %1 new audio track", "could not create %1 new audio tracks", how_many), how_many)
1860 routes = _session->new_audio_route (input_channels, output_channels, route_group, how_many, name_template);
1862 if (routes.size() != how_many) {
1863 error << string_compose (P_("could not create %1 new audio bus", "could not create %1 new audio busses", how_many), how_many)
1870 MessageDialog msg (*editor,
1871 string_compose (_("There are insufficient ports available\n\
1872 to create a new track or bus.\n\
1873 You should save %1, exit and\n\
1874 restart with more ports."), PROGRAM_NAME));
1875 pop_back_splash (msg);
1881 ARDOUR_UI::transport_goto_start ()
1884 _session->goto_start();
1886 /* force displayed area in editor to start no matter
1887 what "follow playhead" setting is.
1891 editor->center_screen (_session->current_start_frame ());
1897 ARDOUR_UI::transport_goto_zero ()
1900 _session->request_locate (0);
1902 /* force displayed area in editor to start no matter
1903 what "follow playhead" setting is.
1907 editor->reset_x_origin (0);
1913 ARDOUR_UI::transport_goto_wallclock ()
1915 if (_session && editor) {
1922 localtime_r (&now, &tmnow);
1924 int frame_rate = _session->frame_rate();
1926 if (frame_rate == 0) {
1927 /* no frame rate available */
1931 frames = tmnow.tm_hour * (60 * 60 * frame_rate);
1932 frames += tmnow.tm_min * (60 * frame_rate);
1933 frames += tmnow.tm_sec * frame_rate;
1935 _session->request_locate (frames, _session->transport_rolling ());
1937 /* force displayed area in editor to start no matter
1938 what "follow playhead" setting is.
1942 editor->center_screen (frames);
1948 ARDOUR_UI::transport_goto_end ()
1951 framepos_t const frame = _session->current_end_frame();
1952 _session->request_locate (frame);
1954 /* force displayed area in editor to start no matter
1955 what "follow playhead" setting is.
1959 editor->center_screen (frame);
1965 ARDOUR_UI::transport_stop ()
1971 if (_session->is_auditioning()) {
1972 _session->cancel_audition ();
1976 _session->request_stop (false, true);
1979 /** Check if any tracks are record enabled. If none are, record enable all of them.
1980 * @return true if track record-enabled status was changed, false otherwise.
1983 ARDOUR_UI::trx_record_enable_all_tracks ()
1989 boost::shared_ptr<RouteList> rl = _session->get_tracks ();
1990 bool none_record_enabled = true;
1992 for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
1993 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (*r);
1996 if (t->record_enabled()) {
1997 none_record_enabled = false;
2002 if (none_record_enabled) {
2003 _session->set_record_enabled (rl, true, Session::rt_cleanup);
2006 return none_record_enabled;
2010 ARDOUR_UI::transport_record (bool roll)
2013 switch (_session->record_status()) {
2014 case Session::Disabled:
2015 if (_session->ntracks() == 0) {
2016 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."));
2020 if (Profile->get_trx()) {
2021 roll = trx_record_enable_all_tracks ();
2023 _session->maybe_enable_record ();
2028 case Session::Recording:
2030 _session->request_stop();
2032 _session->disable_record (false, true);
2036 case Session::Enabled:
2037 _session->disable_record (false, true);
2043 ARDOUR_UI::transport_roll ()
2049 if (_session->is_auditioning()) {
2054 if (_session->config.get_external_sync()) {
2055 switch (Config->get_sync_source()) {
2059 /* transport controlled by the master */
2065 bool rolling = _session->transport_rolling();
2067 if (_session->get_play_loop()) {
2069 /* If loop playback is not a mode, then we should cancel
2070 it when this action is requested. If it is a mode
2071 we just leave it in place.
2074 if (!Config->get_loop_is_mode()) {
2075 /* XXX it is not possible to just leave seamless loop and keep
2076 playing at present (nov 4th 2009)
2078 if (!Config->get_seamless_loop()) {
2079 /* stop loop playback and stop rolling */
2080 _session->request_play_loop (false, true);
2081 } else if (rolling) {
2082 /* stop loop playback but keep rolling */
2083 _session->request_play_loop (false, false);
2087 } else if (_session->get_play_range () ) {
2088 /* stop playing a range if we currently are */
2089 _session->request_play_range (0, true);
2093 _session->request_transport_speed (1.0f);
2098 ARDOUR_UI::get_smart_mode() const
2100 return ( editor->get_smart_mode() );
2105 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
2111 if (_session->is_auditioning()) {
2112 _session->cancel_audition ();
2116 if (_session->config.get_external_sync()) {
2117 switch (Config->get_sync_source()) {
2121 /* transport controlled by the master */
2126 bool rolling = _session->transport_rolling();
2127 bool affect_transport = true;
2129 if (rolling && roll_out_of_bounded_mode) {
2130 /* drop out of loop/range playback but leave transport rolling */
2131 if (_session->get_play_loop()) {
2132 if (Config->get_seamless_loop()) {
2133 /* the disk buffers contain copies of the loop - we can't
2134 just keep playing, so stop the transport. the user
2135 can restart as they wish.
2137 affect_transport = true;
2139 /* disk buffers are normal, so we can keep playing */
2140 affect_transport = false;
2142 _session->request_play_loop (false, affect_transport);
2143 } else if (_session->get_play_range ()) {
2144 affect_transport = false;
2145 _session->request_play_range (0, true);
2149 if (affect_transport) {
2151 _session->request_stop (with_abort, true);
2153 if (ARDOUR_UI::config()->get_follow_edits() && ( editor->get_selection().time.front().start == _session->transport_frame() ) ) { //if playhead is exactly at the start of a range, we can assume it was placed there by follow_edits
2154 _session->request_play_range (&editor->get_selection().time, true);
2155 _session->set_requested_return_frame( editor->get_selection().time.front().start ); //force an auto-return here
2157 _session->request_transport_speed (1.0f);
2163 ARDOUR_UI::toggle_session_auto_loop ()
2165 Location * looploc = _session->locations()->auto_loop_location();
2167 if (!_session || !looploc) {
2171 if (_session->get_play_loop()) {
2173 /* looping enabled, our job is to disable it */
2175 _session->request_play_loop (false);
2179 /* looping not enabled, our job is to enable it.
2181 loop-is-NOT-mode: this action always starts the transport rolling.
2182 loop-IS-mode: this action simply sets the loop play mechanism, but
2183 does not start transport.
2185 if (Config->get_loop_is_mode()) {
2186 _session->request_play_loop (true, false);
2188 _session->request_play_loop (true, true);
2192 //show the loop markers
2193 looploc->set_hidden (false, this);
2197 ARDOUR_UI::transport_play_selection ()
2203 editor->play_selection ();
2207 ARDOUR_UI::transport_play_preroll ()
2212 editor->play_with_preroll ();
2216 ARDOUR_UI::transport_rewind (int option)
2218 float current_transport_speed;
2221 current_transport_speed = _session->transport_speed();
2223 if (current_transport_speed >= 0.0f) {
2226 _session->request_transport_speed (-1.0f);
2229 _session->request_transport_speed (-4.0f);
2232 _session->request_transport_speed (-0.5f);
2237 _session->request_transport_speed (current_transport_speed * 1.5f);
2243 ARDOUR_UI::transport_forward (int option)
2249 float current_transport_speed = _session->transport_speed();
2251 if (current_transport_speed <= 0.0f) {
2254 _session->request_transport_speed (1.0f);
2257 _session->request_transport_speed (4.0f);
2260 _session->request_transport_speed (0.5f);
2265 _session->request_transport_speed (current_transport_speed * 1.5f);
2270 ARDOUR_UI::toggle_record_enable (uint32_t rid)
2276 boost::shared_ptr<Route> r;
2278 if ((r = _session->route_by_remote_id (rid)) != 0) {
2282 if ((t = dynamic_cast<Track*>(r.get())) != 0) {
2283 t->set_record_enabled (!t->record_enabled(), this);
2289 ARDOUR_UI::map_transport_state ()
2292 auto_loop_button.unset_active_state ();
2293 play_selection_button.unset_active_state ();
2294 roll_button.unset_active_state ();
2295 stop_button.set_active_state (Gtkmm2ext::ExplicitActive);
2299 shuttle_box->map_transport_state ();
2301 float sp = _session->transport_speed();
2307 if (_session->get_play_range()) {
2309 play_selection_button.set_active_state (Gtkmm2ext::ExplicitActive);
2310 roll_button.unset_active_state ();
2311 auto_loop_button.unset_active_state ();
2313 } else if (_session->get_play_loop ()) {
2315 auto_loop_button.set_active (true);
2316 play_selection_button.set_active (false);
2317 if (Config->get_loop_is_mode()) {
2318 roll_button.set_active (true);
2320 roll_button.set_active (false);
2325 roll_button.set_active (true);
2326 play_selection_button.set_active (false);
2327 auto_loop_button.set_active (false);
2330 if (ARDOUR_UI::config()->get_follow_edits()) {
2331 /* light up both roll and play-selection if they are joined */
2332 roll_button.set_active (true);
2333 play_selection_button.set_active (true);
2336 stop_button.set_active (false);
2340 stop_button.set_active (true);
2341 roll_button.set_active (false);
2342 play_selection_button.set_active (false);
2343 if (Config->get_loop_is_mode ()) {
2344 auto_loop_button.set_active (_session->get_play_loop());
2346 auto_loop_button.set_active (false);
2348 update_disk_space ();
2353 ARDOUR_UI::blink_handler (bool blink_on)
2355 transport_rec_enable_blink (blink_on);
2356 solo_blink (blink_on);
2357 sync_blink (blink_on);
2358 audition_blink (blink_on);
2359 feedback_blink (blink_on);
2360 error_blink (blink_on);
2364 ARDOUR_UI::update_clocks ()
2366 if (!_session) return;
2368 if (editor && !editor->dragging_playhead()) {
2369 Clock (_session->audible_frame(), false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD)); /* EMIT_SIGNAL */
2374 ARDOUR_UI::start_clocking ()
2376 if (ui_config->get_super_rapid_clock_update()) {
2377 clock_signal_connection = Timers::fps_connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2379 clock_signal_connection = Timers::rapid_connect (sigc::mem_fun(*this, &ARDOUR_UI::update_clocks));
2384 ARDOUR_UI::stop_clocking ()
2386 clock_signal_connection.disconnect ();
2390 ARDOUR_UI::save_as_progress_update (float fraction, int64_t cnt, int64_t total, Gtk::Label* label, Gtk::ProgressBar* bar)
2394 snprintf (buf, sizeof (buf), _("Copied %" PRId64 " of %" PRId64), cnt, total);
2396 label->set_text (buf);
2397 bar->set_fraction (fraction);
2399 /* process events, redraws, etc. */
2401 while (gtk_events_pending()) {
2402 gtk_main_iteration ();
2405 return true; /* continue with save-as */
2409 ARDOUR_UI::save_session_as ()
2415 if (!save_as_dialog) {
2416 save_as_dialog = new SaveAsDialog;
2418 save_as_dialog->clear_name ();
2421 int response = save_as_dialog->run ();
2423 save_as_dialog->hide ();
2426 case Gtk::RESPONSE_OK:
2435 sa.new_parent_folder = save_as_dialog->new_parent_folder ();
2436 sa.new_name = save_as_dialog->new_name ();
2437 sa.switch_to = save_as_dialog->switch_to();
2438 sa.copy_media = save_as_dialog->copy_media();
2439 sa.copy_external = save_as_dialog->copy_external();
2440 sa.include_media = save_as_dialog->include_media ();
2442 /* Only bother with a progress dialog if we're going to copy
2443 media into the save-as target. Without that choice, this
2444 will be very fast because we're only talking about a few kB's to
2445 perhaps a couple of MB's of data.
2448 ArdourDialog progress_dialog (_("Save As"), true);
2450 if (sa.include_media && sa.copy_media) {
2453 Gtk::ProgressBar progress_bar;
2455 progress_dialog.get_vbox()->pack_start (label);
2456 progress_dialog.get_vbox()->pack_start (progress_bar);
2458 progress_bar.show ();
2460 /* this signal will be emitted from within this, the calling thread,
2461 * after every file is copied. It provides information on percentage
2462 * complete (in terms of total data to copy), the number of files
2463 * copied so far, and the total number to copy.
2468 sa.Progress.connect_same_thread (c, boost::bind (&ARDOUR_UI::save_as_progress_update, this, _1, _2, _3, &label, &progress_bar));
2470 progress_dialog.show_all ();
2471 progress_dialog.present ();
2474 if (_session->save_as (sa)) {
2476 MessageDialog msg (string_compose (_("Save As failed: %1"), sa.failure_message));
2480 if (!sa.include_media) {
2481 unload_session (false);
2482 load_session (sa.final_session_folder_name, sa.new_name);
2486 /** Ask the user for the name of a new snapshot and then take it.
2490 ARDOUR_UI::snapshot_session (bool switch_to_it)
2492 ArdourPrompter prompter (true);
2495 prompter.set_name ("Prompter");
2496 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2498 prompter.set_title (_("Save as..."));
2499 prompter.set_prompt (_("New session name"));
2501 prompter.set_title (_("Take Snapshot"));
2502 prompter.set_prompt (_("Name of new snapshot"));
2505 if (!switch_to_it) {
2508 struct tm local_time;
2511 localtime_r (&n, &local_time);
2512 strftime (timebuf, sizeof(timebuf), "%FT%H.%M.%S", &local_time);
2513 prompter.set_initial_text (timebuf);
2517 switch (prompter.run()) {
2518 case RESPONSE_ACCEPT:
2520 prompter.get_result (snapname);
2522 bool do_save = (snapname.length() != 0);
2525 char illegal = Session::session_name_is_legal(snapname);
2527 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2528 "snapshot names may not contain a '%1' character"), illegal));
2534 vector<std::string> p;
2535 get_state_files_in_directory (_session->session_directory().root_path(), p);
2536 vector<string> n = get_file_names_no_extension (p);
2537 if (find (n.begin(), n.end(), snapname) != n.end()) {
2539 ArdourDialog confirm (_("Confirm Snapshot Overwrite"), true);
2540 Label m (_("A snapshot already exists with that name. Do you want to overwrite it?"));
2541 confirm.get_vbox()->pack_start (m, true, true);
2542 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2543 confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
2544 confirm.show_all ();
2545 switch (confirm.run()) {
2546 case RESPONSE_CANCEL:
2552 save_state (snapname, switch_to_it);
2562 /** Ask the user for a new session name and then rename the session to it.
2566 ARDOUR_UI::rename_session ()
2572 ArdourPrompter prompter (true);
2575 prompter.set_name ("Prompter");
2576 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2577 prompter.set_title (_("Rename Session"));
2578 prompter.set_prompt (_("New session name"));
2581 switch (prompter.run()) {
2582 case RESPONSE_ACCEPT:
2584 prompter.get_result (name);
2586 bool do_rename = (name.length() != 0);
2589 char illegal = Session::session_name_is_legal (name);
2592 MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
2593 "session names may not contain a '%1' character"), illegal));
2598 switch (_session->rename (name)) {
2600 MessageDialog msg (_("That name is already in use by another directory/folder. Please try again."));
2601 msg.set_position (WIN_POS_MOUSE);
2609 MessageDialog msg (_("Renaming this session failed.\nThings could be seriously messed up at this point"));
2610 msg.set_position (WIN_POS_MOUSE);
2626 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
2628 XMLNode* node = new XMLNode (X_("UI"));
2630 WM::Manager::instance().add_state (*node);
2632 node->add_child_nocopy (gui_object_state->get_state());
2634 _session->add_extra_xml (*node);
2636 if (export_video_dialog) {
2637 _session->add_extra_xml (export_video_dialog->get_state());
2640 save_state_canfail (name, switch_to_it);
2644 ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
2649 if (name.length() == 0) {
2650 name = _session->snap_name();
2653 if ((ret = _session->save_state (name, false, switch_to_it)) != 0) {
2658 save_ardour_state (); /* XXX cannot fail? yeah, right ... */
2663 ARDOUR_UI::primary_clock_value_changed ()
2666 _session->request_locate (primary_clock->current_time ());
2671 ARDOUR_UI::big_clock_value_changed ()
2674 _session->request_locate (big_clock->current_time ());
2679 ARDOUR_UI::secondary_clock_value_changed ()
2682 _session->request_locate (secondary_clock->current_time ());
2687 ARDOUR_UI::transport_rec_enable_blink (bool onoff)
2689 if (_session == 0) {
2693 if (_session->step_editing()) {
2697 Session::RecordState const r = _session->record_status ();
2698 bool const h = _session->have_rec_enabled_track ();
2700 if (r == Session::Enabled || (r == Session::Recording && !h)) {
2702 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2704 rec_button.set_active_state (Gtkmm2ext::Off);
2706 } else if (r == Session::Recording && h) {
2707 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
2709 rec_button.unset_active_state ();
2714 ARDOUR_UI::save_template ()
2716 ArdourPrompter prompter (true);
2719 if (!check_audioengine()) {
2723 prompter.set_name (X_("Prompter"));
2724 prompter.set_title (_("Save Template"));
2725 prompter.set_prompt (_("Name for template:"));
2726 prompter.set_initial_text(_session->name() + _("-template"));
2727 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
2729 switch (prompter.run()) {
2730 case RESPONSE_ACCEPT:
2731 prompter.get_result (name);
2733 if (name.length()) {
2734 _session->save_template (name);
2744 ARDOUR_UI::edit_metadata ()
2746 SessionMetadataEditor dialog;
2747 dialog.set_session (_session);
2748 dialog.grab_focus ();
2753 ARDOUR_UI::import_metadata ()
2755 SessionMetadataImporter dialog;
2756 dialog.set_session (_session);
2761 ARDOUR_UI::ask_about_loading_existing_session (const std::string& session_path)
2763 std::string str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
2765 MessageDialog msg (str,
2767 Gtk::MESSAGE_WARNING,
2768 Gtk::BUTTONS_YES_NO,
2772 msg.set_name (X_("OpenExistingDialog"));
2773 msg.set_title (_("Open Existing Session"));
2774 msg.set_wmclass (X_("existing_session"), PROGRAM_NAME);
2775 msg.set_position (Gtk::WIN_POS_CENTER);
2776 pop_back_splash (msg);
2778 switch (msg.run()) {
2787 ARDOUR_UI::build_session_from_dialog (SessionDialog& sd, const std::string& session_path, const std::string& session_name)
2789 BusProfile bus_profile;
2791 if (nsm || Profile->get_sae()) {
2793 bus_profile.master_out_channels = 2;
2794 bus_profile.input_ac = AutoConnectPhysical;
2795 bus_profile.output_ac = AutoConnectMaster;
2796 bus_profile.requested_physical_in = 0; // use all available
2797 bus_profile.requested_physical_out = 0; // use all available
2801 /* get settings from advanced section of NSD */
2803 if (sd.create_master_bus()) {
2804 bus_profile.master_out_channels = (uint32_t) sd.master_channel_count();
2806 bus_profile.master_out_channels = 0;
2809 if (sd.connect_inputs()) {
2810 bus_profile.input_ac = AutoConnectPhysical;
2812 bus_profile.input_ac = AutoConnectOption (0);
2815 bus_profile.output_ac = AutoConnectOption (0);
2817 if (sd.connect_outputs ()) {
2818 if (sd.connect_outs_to_master()) {
2819 bus_profile.output_ac = AutoConnectMaster;
2820 } else if (sd.connect_outs_to_physical()) {
2821 bus_profile.output_ac = AutoConnectPhysical;
2825 bus_profile.requested_physical_in = (uint32_t) sd.input_limit_count();
2826 bus_profile.requested_physical_out = (uint32_t) sd.output_limit_count();
2829 if (build_session (session_path, session_name, bus_profile)) {
2837 ARDOUR_UI::load_from_application_api (const std::string& path)
2839 ARDOUR_COMMAND_LINE::session_name = path;
2841 if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
2842 /* /path/to/foo => /path/to/foo, foo */
2843 load_session (path, basename_nosuffix (path));
2845 /* /path/to/foo/foo.ardour => /path/to/foo, foo */
2846 load_session (Glib::path_get_dirname (path), basename_nosuffix (path));
2850 /** @param quit_on_cancel true if exit() should be called if the user clicks `cancel' in the new session dialog */
2852 ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, string load_template)
2854 string session_name;
2855 string session_path;
2856 string template_name;
2858 bool likely_new = false;
2859 bool cancel_not_quit;
2861 /* deal with any existing DIRTY session now, rather than later. don't
2862 * treat a non-dirty session this way, so that it stays visible
2863 * as we bring up the new session dialog.
2866 if (_session && ARDOUR_UI::instance()->video_timeline) {
2867 ARDOUR_UI::instance()->video_timeline->sync_session_state();
2870 /* if there is already a session, relabel the button
2871 on the SessionDialog so that we don't Quit directly
2873 cancel_not_quit = (_session != 0);
2875 if (_session && _session->dirty()) {
2876 if (unload_session (false)) {
2877 /* unload cancelled by user */
2880 ARDOUR_COMMAND_LINE::session_name = "";
2883 if (!load_template.empty()) {
2884 should_be_new = true;
2885 template_name = load_template;
2888 session_name = basename_nosuffix (ARDOUR_COMMAND_LINE::session_name);
2889 session_path = ARDOUR_COMMAND_LINE::session_name;
2891 if (!session_path.empty()) {
2892 if (Glib::file_test (session_path.c_str(), Glib::FILE_TEST_EXISTS)) {
2893 if (Glib::file_test (session_path.c_str(), Glib::FILE_TEST_IS_REGULAR)) {
2894 /* session/snapshot file, change path to be dir */
2895 session_path = Glib::path_get_dirname (session_path);
2900 SessionDialog session_dialog (should_be_new, session_name, session_path, load_template, cancel_not_quit);
2904 if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
2906 /* if they named a specific statefile, use it, otherwise they are
2907 just giving a session folder, and we want to use it as is
2908 to find the session.
2911 string::size_type suffix = ARDOUR_COMMAND_LINE::session_name.find (statefile_suffix);
2913 if (suffix != string::npos) {
2914 session_path = Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name);
2915 session_name = ARDOUR_COMMAND_LINE::session_name.substr (0, suffix);
2916 session_name = Glib::path_get_basename (session_name);
2918 session_path = ARDOUR_COMMAND_LINE::session_name;
2919 session_name = Glib::path_get_basename (ARDOUR_COMMAND_LINE::session_name);
2924 session_dialog.clear_given ();
2927 if (should_be_new || session_name.empty()) {
2928 /* need the dialog to get info from user */
2930 cerr << "run dialog\n";
2932 switch (session_dialog.run()) {
2933 case RESPONSE_ACCEPT:
2936 if (quit_on_cancel) {
2937 // JE - Currently (July 2014) this section can only get reached if the
2938 // user quits from the main 'Session Setup' dialog (i.e. reaching this
2939 // point does NOT indicate an abnormal termination). Therefore, let's
2940 // behave gracefully (i.e. let's do some cleanup) before we call exit()
2942 pthread_cancel_all ();
2950 session_dialog.hide ();
2953 /* if we run the startup dialog again, offer more than just "new session" */
2955 should_be_new = false;
2957 session_name = session_dialog.session_name (likely_new);
2958 session_path = session_dialog.session_folder ();
2964 string::size_type suffix = session_name.find (statefile_suffix);
2966 if (suffix != string::npos) {
2967 session_name = session_name.substr (0, suffix);
2970 /* this shouldn't happen, but we catch it just in case it does */
2972 if (session_name.empty()) {
2976 if (session_dialog.use_session_template()) {
2977 template_name = session_dialog.session_template_name();
2978 _session_is_new = true;
2981 if (session_name[0] == G_DIR_SEPARATOR ||
2982 #ifdef PLATFORM_WINDOWS
2983 (session_name.length() > 3 && session_name[1] == ':' && session_name[2] == G_DIR_SEPARATOR)
2985 (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == G_DIR_SEPARATOR) ||
2986 (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == G_DIR_SEPARATOR)
2991 /* absolute path or cwd-relative path specified for session name: infer session folder
2992 from what was given.
2995 session_path = Glib::path_get_dirname (session_name);
2996 session_name = Glib::path_get_basename (session_name);
3000 session_path = session_dialog.session_folder();
3002 char illegal = Session::session_name_is_legal (session_name);
3005 MessageDialog msg (session_dialog,
3006 string_compose (_("To ensure compatibility with various systems\n"
3007 "session names may not contain a '%1' character"),
3010 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
3015 if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
3018 if (likely_new && !nsm) {
3020 std::string existing = Glib::build_filename (session_path, session_name);
3022 if (!ask_about_loading_existing_session (existing)) {
3023 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
3028 _session_is_new = false;
3033 pop_back_splash (session_dialog);
3034 MessageDialog msg (string_compose (_("There is no existing session at \"%1\""), session_path));
3036 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
3040 char illegal = Session::session_name_is_legal(session_name);
3043 pop_back_splash (session_dialog);
3044 MessageDialog msg (session_dialog, string_compose(_("To ensure compatibility with various systems\n"
3045 "session names may not contain a '%1' character"), illegal));
3047 ARDOUR_COMMAND_LINE::session_name = ""; // cancel that
3051 _session_is_new = true;
3054 if (likely_new && template_name.empty()) {
3056 ret = build_session_from_dialog (session_dialog, session_path, session_name);
3060 ret = load_session (session_path, session_name, template_name);
3063 /* not connected to the AudioEngine, so quit to avoid an infinite loop */
3067 if (!ARDOUR_COMMAND_LINE::immediate_save.empty()) {
3068 _session->save_state (ARDOUR_COMMAND_LINE::immediate_save, false);
3072 /* clear this to avoid endless attempts to load the
3076 ARDOUR_COMMAND_LINE::session_name = "";
3084 ARDOUR_UI::close_session()
3086 if (!check_audioengine()) {
3090 if (unload_session (true)) {
3094 ARDOUR_COMMAND_LINE::session_name = "";
3096 if (get_session_parameters (true, false)) {
3100 goto_editor_window ();
3103 /** @param snap_name Snapshot name (without .ardour suffix).
3104 * @return -2 if the load failed because we are not connected to the AudioEngine.
3107 ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name, std::string mix_template)
3109 Session *new_session;
3114 unload_status = unload_session ();
3116 if (unload_status < 0) {
3118 } else if (unload_status > 0) {
3124 session_loaded = false;
3126 loading_message (string_compose (_("Please wait while %1 loads your session"), PROGRAM_NAME));
3129 new_session = new Session (*AudioEngine::instance(), path, snap_name, 0, mix_template);
3132 /* this one is special */
3134 catch (AudioEngine::PortRegistrationFailure& err) {
3136 MessageDialog msg (err.what(),
3139 Gtk::BUTTONS_CLOSE);
3141 msg.set_title (_("Port Registration Error"));
3142 msg.set_secondary_text (_("Click the Close button to try again."));
3143 msg.set_position (Gtk::WIN_POS_CENTER);
3144 pop_back_splash (msg);
3147 int response = msg.run ();
3152 case RESPONSE_CANCEL:
3162 MessageDialog msg (string_compose(
3163 _("Session \"%1 (snapshot %2)\" did not load successfully"),
3169 msg.set_title (_("Loading Error"));
3170 msg.set_position (Gtk::WIN_POS_CENTER);
3171 pop_back_splash (msg);
3180 list<string> const u = new_session->unknown_processors ();
3182 MissingPluginDialog d (_session, u);
3187 if (!new_session->writable()) {
3188 MessageDialog msg (_("This session has been opened in read-only mode.\n\nYou will not be able to record or save."),
3193 msg.set_title (_("Read-only Session"));
3194 msg.set_position (Gtk::WIN_POS_CENTER);
3195 pop_back_splash (msg);
3202 /* Now the session been created, add the transport controls */
3203 new_session->add_controllable(roll_controllable);
3204 new_session->add_controllable(stop_controllable);
3205 new_session->add_controllable(goto_start_controllable);
3206 new_session->add_controllable(goto_end_controllable);
3207 new_session->add_controllable(auto_loop_controllable);
3208 new_session->add_controllable(play_selection_controllable);
3209 new_session->add_controllable(rec_controllable);
3211 set_session (new_session);
3213 session_loaded = true;
3215 goto_editor_window ();
3218 _session->set_clean ();
3221 #ifdef WINDOWS_VST_SUPPORT
3222 fst_stop_threading();
3227 #ifdef WINDOWS_VST_SUPPORT
3228 fst_start_threading();
3237 ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name, BusProfile& bus_profile)
3239 Session *new_session;
3242 session_loaded = false;
3243 x = unload_session ();
3251 _session_is_new = true;
3254 new_session = new Session (*AudioEngine::instance(), path, snap_name, &bus_profile);
3259 MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
3260 pop_back_splash (msg);
3265 /* Give the new session the default GUI state, if such things exist */
3268 n = Config->instant_xml (X_("Editor"));
3270 n->remove_nodes_and_delete ("Selection"); // no not apply selection to new sessions.
3271 new_session->add_instant_xml (*n, false);
3273 n = Config->instant_xml (X_("Mixer"));
3275 new_session->add_instant_xml (*n, false);
3278 /* Put the playhead at 0 and scroll fully left */
3279 n = new_session->instant_xml (X_("Editor"));
3281 n->add_property (X_("playhead"), X_("0"));
3282 n->add_property (X_("left-frame"), X_("0"));
3285 set_session (new_session);
3287 session_loaded = true;
3289 new_session->save_state(new_session->name());
3295 ARDOUR_UI::launch_chat ()
3298 open_uri("http://webchat.freenode.net/?channels=ardour-osx");
3299 #elif defined PLATFORM_WINDOWS
3300 open_uri("http://webchat.freenode.net/?channels=ardour-windows");
3302 open_uri("http://webchat.freenode.net/?channels=ardour");
3307 ARDOUR_UI::launch_manual ()
3309 PBD::open_uri (Config->get_tutorial_manual_url());
3313 ARDOUR_UI::launch_reference ()
3315 PBD::open_uri (Config->get_reference_manual_url());
3319 ARDOUR_UI::launch_tracker ()
3321 PBD::open_uri ("http://tracker.ardour.org/bug_report_page.php");
3325 ARDOUR_UI::launch_subscribe ()
3327 PBD::open_uri ("https://community.ardour.org/s/subscribe");
3331 ARDOUR_UI::launch_cheat_sheet ()
3334 PBD::open_uri ("http://manual.ardour.org/files/a3_mnemonic_cheat_sheet_osx.pdf");
3336 PBD::open_uri ("http://manual.ardour.org/files/a3_mnemonic_cheatsheet.pdf");
3341 ARDOUR_UI::launch_website ()
3343 PBD::open_uri ("http://ardour.org");
3347 ARDOUR_UI::launch_website_dev ()
3349 PBD::open_uri ("http://ardour.org/development.html");
3353 ARDOUR_UI::launch_forums ()
3355 PBD::open_uri ("https://community.ardour.org/forums");
3359 ARDOUR_UI::launch_howto_report ()
3361 PBD::open_uri ("http://ardour.org/reporting_bugs");
3365 ARDOUR_UI::loading_message (const std::string& msg)
3367 if (ARDOUR_COMMAND_LINE::no_splash) {
3375 splash->message (msg);
3379 ARDOUR_UI::show_splash ()
3383 splash = new Splash;
3393 ARDOUR_UI::hide_splash ()
3400 ARDOUR_UI::display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title, const bool msg_delete)
3404 removed = rep.paths.size();
3407 MessageDialog msgd (*editor,
3408 _("No files were ready for clean-up"),
3412 msgd.set_title (_("Clean-up"));
3413 msgd.set_secondary_text (_("If this seems suprising, \n\
3414 check for any existing snapshots.\n\
3415 These may still include regions that\n\
3416 require some unused files to continue to exist."));
3422 ArdourDialog results (_("Clean-up"), true, false);
3424 struct CleanupResultsModelColumns : public Gtk::TreeModel::ColumnRecord {
3425 CleanupResultsModelColumns() {
3429 Gtk::TreeModelColumn<std::string> visible_name;
3430 Gtk::TreeModelColumn<std::string> fullpath;
3434 CleanupResultsModelColumns results_columns;
3435 Glib::RefPtr<Gtk::ListStore> results_model;
3436 Gtk::TreeView results_display;
3438 results_model = ListStore::create (results_columns);
3439 results_display.set_model (results_model);
3440 results_display.append_column (list_title, results_columns.visible_name);
3442 results_display.set_name ("CleanupResultsList");
3443 results_display.set_headers_visible (true);
3444 results_display.set_headers_clickable (false);
3445 results_display.set_reorderable (false);
3447 Gtk::ScrolledWindow list_scroller;
3450 Gtk::HBox dhbox; // the hbox for the image and text
3451 Gtk::HBox ddhbox; // the hbox we eventually pack into the dialog's vbox
3452 Gtk::Image* dimage = manage (new Gtk::Image(Stock::DIALOG_INFO, Gtk::ICON_SIZE_DIALOG));
3454 dimage->set_alignment(ALIGN_LEFT, ALIGN_TOP);
3456 const string dead_directory = _session->session_directory().dead_path();
3459 %1 - number of files removed
3460 %2 - location of "dead"
3461 %3 - size of files affected
3462 %4 - prefix for "bytes" to produce sensible results (e.g. mega, kilo, giga)
3465 const char* bprefix;
3466 double space_adjusted = 0;
3468 if (rep.space < 1000) {
3470 space_adjusted = rep.space;
3471 } else if (rep.space < 1000000) {
3472 bprefix = _("kilo");
3473 space_adjusted = floorf((float)rep.space / 1000.0);
3474 } else if (rep.space < 1000000 * 1000) {
3475 bprefix = _("mega");
3476 space_adjusted = floorf((float)rep.space / (1000.0 * 1000.0));
3478 bprefix = _("giga");
3479 space_adjusted = floorf((float)rep.space / (1000.0 * 1000 * 1000.0));
3483 txt.set_markup (string_compose (P_("\
3484 The following file was deleted from %2,\n\
3485 releasing %3 %4bytes of disk space", "\
3486 The following %1 files were deleted from %2,\n\
3487 releasing %3 %4bytes of disk space", removed),
3488 removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
3490 txt.set_markup (string_compose (P_("\
3491 The following file was not in use and \n\
3492 has been moved to: %2\n\n\
3493 After a restart of %5\n\n\
3494 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3495 will release an additional %3 %4bytes of disk space.\n", "\
3496 The following %1 files were not in use and \n\
3497 have been moved to: %2\n\n\
3498 After a restart of %5\n\n\
3499 <span face=\"mono\">Session -> Clean-up -> Flush Wastebasket</span>\n\n\
3500 will release an additional %3 %4bytes of disk space.\n", removed),
3501 removed, Glib::Markup::escape_text (dead_directory), space_adjusted, bprefix, PROGRAM_NAME));
3504 dhbox.pack_start (*dimage, true, false, 5);
3505 dhbox.pack_start (txt, true, false, 5);
3507 for (vector<string>::iterator i = rep.paths.begin(); i != rep.paths.end(); ++i) {
3508 TreeModel::Row row = *(results_model->append());
3509 row[results_columns.visible_name] = *i;
3510 row[results_columns.fullpath] = *i;
3513 list_scroller.add (results_display);
3514 list_scroller.set_size_request (-1, 150);
3515 list_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
3517 dvbox.pack_start (dhbox, true, false, 5);
3518 dvbox.pack_start (list_scroller, true, false, 5);
3519 ddhbox.pack_start (dvbox, true, false, 5);
3521 results.get_vbox()->pack_start (ddhbox, true, false, 5);
3522 results.add_button (Stock::CLOSE, RESPONSE_CLOSE);
3523 results.set_default_response (RESPONSE_CLOSE);
3524 results.set_position (Gtk::WIN_POS_MOUSE);
3526 results_display.show();
3527 list_scroller.show();
3534 //results.get_vbox()->show();
3535 results.set_resizable (false);
3542 ARDOUR_UI::cleanup ()
3544 if (_session == 0) {
3545 /* shouldn't happen: menu item is insensitive */
3550 MessageDialog checker (_("Are you sure you want to clean-up?"),
3552 Gtk::MESSAGE_QUESTION,
3555 checker.set_title (_("Clean-up"));
3557 checker.set_secondary_text(_("Clean-up is a destructive operation.\n\
3558 ALL undo/redo information will be lost if you clean-up.\n\
3559 Clean-up will move all unused files to a \"dead\" location."));
3561 checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3562 checker.add_button (_("Clean-up"), RESPONSE_ACCEPT);
3563 checker.set_default_response (RESPONSE_CANCEL);
3565 checker.set_name (_("CleanupDialog"));
3566 checker.set_wmclass (X_("ardour_cleanup"), PROGRAM_NAME);
3567 checker.set_position (Gtk::WIN_POS_MOUSE);
3569 switch (checker.run()) {
3570 case RESPONSE_ACCEPT:
3576 ARDOUR::CleanupReport rep;
3578 editor->prepare_for_cleanup ();
3580 /* do not allow flush until a session is reloaded */
3582 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
3584 act->set_sensitive (false);
3587 if (_session->cleanup_sources (rep)) {
3588 editor->finish_cleanup ();
3592 editor->finish_cleanup ();
3595 display_cleanup_results (rep, _("Cleaned Files"), false);
3599 ARDOUR_UI::flush_trash ()
3601 if (_session == 0) {
3602 /* shouldn't happen: menu item is insensitive */
3606 ARDOUR::CleanupReport rep;
3608 if (_session->cleanup_trash_sources (rep)) {
3612 display_cleanup_results (rep, _("deleted file"), true);
3616 ARDOUR_UI::setup_order_hint (AddRouteDialog::InsertAt place)
3618 uint32_t order_hint = UINT32_MAX;
3620 if (editor->get_selection().tracks.empty()) {
3625 we want the new routes to have their order keys set starting from
3626 the highest order key in the selection + 1 (if available).
3629 if (place == AddRouteDialog::AfterSelection) {
3630 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView*> (editor->get_selection().tracks.back());
3632 order_hint = rtav->route()->order_key();
3635 } else if (place == AddRouteDialog::BeforeSelection) {
3636 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView*> (editor->get_selection().tracks.front());
3638 order_hint = rtav->route()->order_key();
3640 } else if (place == AddRouteDialog::First) {
3643 /* leave order_hint at UINT32_MAX */
3646 if (order_hint == UINT32_MAX) {
3647 /** AddRouteDialog::Last or selection with first/last not a RouteTimeAxisView
3648 * not setting an order hint will place new routes last.
3653 _session->set_order_hint (order_hint);
3655 /* create a gap in the existing route order keys to accomodate new routes.*/
3656 boost::shared_ptr <RouteList> rd = _session->get_routes();
3657 for (RouteList::iterator ri = rd->begin(); ri != rd->end(); ++ri) {
3658 boost::shared_ptr<Route> rt (*ri);
3660 if (rt->is_monitor()) {
3664 if (rt->order_key () >= order_hint) {
3665 rt->set_order_key (rt->order_key () + add_route_dialog->count());
3671 ARDOUR_UI::add_route (Gtk::Window* /* ignored */)
3679 if (add_route_dialog->is_visible()) {
3680 /* we're already doing this */
3684 ResponseType r = (ResponseType) add_route_dialog->run ();
3686 add_route_dialog->hide();
3689 case RESPONSE_ACCEPT:
3696 if ((count = add_route_dialog->count()) <= 0) {
3700 setup_order_hint(add_route_dialog->insert_at());
3702 string template_path = add_route_dialog->track_template();
3703 DisplaySuspender ds;
3705 if (!template_path.empty()) {
3706 if (add_route_dialog->name_template_is_default()) {
3707 _session->new_route_from_template (count, template_path, string());
3709 _session->new_route_from_template (count, template_path, add_route_dialog->name_template());
3714 ChanCount input_chan= add_route_dialog->channels ();
3715 ChanCount output_chan;
3716 string name_template = add_route_dialog->name_template ();
3717 PluginInfoPtr instrument = add_route_dialog->requested_instrument ();
3718 RouteGroup* route_group = add_route_dialog->route_group ();
3719 AutoConnectOption oac = Config->get_output_auto_connect();
3721 if (oac & AutoConnectMaster) {
3722 output_chan.set (DataType::AUDIO, (_session->master_out() ? _session->master_out()->n_inputs().n_audio() : input_chan.n_audio()));
3723 output_chan.set (DataType::MIDI, 0);
3725 output_chan = input_chan;
3728 /* XXX do something with name template */
3730 switch (add_route_dialog->type_wanted()) {
3731 case AddRouteDialog::AudioTrack:
3732 session_add_audio_track (input_chan.n_audio(), output_chan.n_audio(), add_route_dialog->mode(), route_group, count, name_template);
3734 case AddRouteDialog::MidiTrack:
3735 session_add_midi_track (route_group, count, name_template, instrument);
3737 case AddRouteDialog::MixedTrack:
3738 session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, instrument);
3740 case AddRouteDialog::AudioBus:
3741 session_add_audio_bus (input_chan.n_audio(), output_chan.n_audio(), route_group, count, name_template);
3747 ARDOUR_UI::stop_video_server (bool ask_confirm)
3749 if (!video_server_process && ask_confirm) {
3750 warning << string_compose (_("Video-Server was not launched by %1. The request to stop it is ignored."), PROGRAM_NAME) << endmsg;
3752 if (video_server_process) {
3754 ArdourDialog confirm (_("Stop Video-Server"), true);
3755 Label m (_("Do you really want to stop the Video Server?"));
3756 confirm.get_vbox()->pack_start (m, true, true);
3757 confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3758 confirm.add_button (_("Yes, Stop It"), Gtk::RESPONSE_ACCEPT);
3759 confirm.show_all ();
3760 if (confirm.run() == RESPONSE_CANCEL) {
3764 delete video_server_process;
3765 video_server_process =0;
3770 ARDOUR_UI::start_video_server_menu (Gtk::Window* float_window)
3772 ARDOUR_UI::start_video_server( float_window, true);
3776 ARDOUR_UI::start_video_server (Gtk::Window* float_window, bool popup_msg)
3782 if (ARDOUR_UI::instance()->video_timeline->check_server()) {
3783 if (video_server_process) {
3784 popup_error(_("The Video Server is already started."));
3786 popup_error(_("An external Video Server is configured and can be reached. Not starting a new instance."));
3792 while (!ARDOUR_UI::instance()->video_timeline->check_server()) {
3794 warning << _("Could not connect to the Video Server. Start it or configure its access URL in Preferences.") << endmsg;
3796 VideoServerDialog *video_server_dialog = new VideoServerDialog (_session);
3798 video_server_dialog->set_transient_for (*float_window);
3801 if (!Config->get_show_video_server_dialog() && firsttime < 2) {
3802 video_server_dialog->hide();
3804 ResponseType r = (ResponseType) video_server_dialog->run ();
3805 video_server_dialog->hide();
3806 if (r != RESPONSE_ACCEPT) { return false; }
3807 if (video_server_dialog->show_again()) {
3808 Config->set_show_video_server_dialog(false);
3812 std::string icsd_exec = video_server_dialog->get_exec_path();
3813 std::string icsd_docroot = video_server_dialog->get_docroot();
3814 if (icsd_docroot.empty()) {
3815 #ifndef PLATFORM_WINDOWS
3816 icsd_docroot = X_("/");
3818 icsd_docroot = X_("C:\\");
3823 if (g_lstat (icsd_docroot.c_str(), &sb) != 0 || !S_ISDIR(sb.st_mode)) {
3824 warning << _("Specified docroot is not an existing directory.") << endmsg;
3827 #ifndef PLATFORM_WINDOWS
3828 if ( (g_lstat (icsd_exec.c_str(), &sb) != 0)
3829 || (sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) == 0 ) {
3830 warning << _("Given Video Server is not an executable file.") << endmsg;
3834 if ( (g_lstat (icsd_exec.c_str(), &sb) != 0)
3835 || (sb.st_mode & (S_IXUSR)) == 0 ) {
3836 warning << _("Given Video Server is not an executable file.") << endmsg;
3842 argp=(char**) calloc(9,sizeof(char*));
3843 argp[0] = strdup(icsd_exec.c_str());
3844 argp[1] = strdup("-P");
3845 argp[2] = (char*) calloc(16,sizeof(char)); snprintf(argp[2], 16, "%s", video_server_dialog->get_listenaddr().c_str());
3846 argp[3] = strdup("-p");
3847 argp[4] = (char*) calloc(6,sizeof(char)); snprintf(argp[4], 6, "%i", video_server_dialog->get_listenport());
3848 argp[5] = strdup("-C");
3849 argp[6] = (char*) calloc(6,sizeof(char)); snprintf(argp[6], 6, "%i", video_server_dialog->get_cachesize());
3850 argp[7] = strdup(icsd_docroot.c_str());
3852 stop_video_server();
3854 if (icsd_docroot == X_("/") || icsd_docroot == X_("C:\\")) {
3855 Config->set_video_advanced_setup(false);
3857 std::ostringstream osstream;
3858 osstream << "http://localhost:" << video_server_dialog->get_listenport() << "/";
3859 Config->set_video_server_url(osstream.str());
3860 Config->set_video_server_docroot(icsd_docroot);
3861 Config->set_video_advanced_setup(true);
3864 if (video_server_process) {
3865 delete video_server_process;
3868 video_server_process = new ARDOUR::SystemExec(icsd_exec, argp);
3869 if (video_server_process->start()) {
3870 warning << _("Cannot launch the video-server") << endmsg;
3873 int timeout = 120; // 6 sec
3874 while (!ARDOUR_UI::instance()->video_timeline->check_server()) {
3875 Glib::usleep (50000);
3877 if (--timeout <= 0 || !video_server_process->is_running()) break;
3880 warning << _("Video-server was started but does not respond to requests...") << endmsg;
3882 if (!ARDOUR_UI::instance()->video_timeline->check_server_docroot()) {
3883 delete video_server_process;
3884 video_server_process = 0;
3892 ARDOUR_UI::add_video (Gtk::Window* float_window)
3898 if (!start_video_server(float_window, false)) {
3899 warning << _("Could not connect to the Video Server. Start it or configure its access URL in Preferences.") << endmsg;
3904 add_video_dialog->set_transient_for (*float_window);
3907 if (add_video_dialog->is_visible()) {
3908 /* we're already doing this */
3912 ResponseType r = (ResponseType) add_video_dialog->run ();
3913 add_video_dialog->hide();
3914 if (r != RESPONSE_ACCEPT) { return; }
3916 bool local_file, orig_local_file;
3917 std::string path = add_video_dialog->file_name(local_file);
3919 std::string orig_path = path;
3920 orig_local_file = local_file;
3922 bool auto_set_session_fps = add_video_dialog->auto_set_session_fps();
3924 if (local_file && !Glib::file_test(path, Glib::FILE_TEST_EXISTS)) {
3925 warning << string_compose(_("could not open %1"), path) << endmsg;
3928 if (!local_file && path.length() == 0) {
3929 warning << _("no video-file selected") << endmsg;
3933 switch (add_video_dialog->import_option()) {
3934 case VTL_IMPORT_TRANSCODE:
3936 TranscodeVideoDialog *transcode_video_dialog;
3937 transcode_video_dialog = new TranscodeVideoDialog (_session, path);
3938 ResponseType r = (ResponseType) transcode_video_dialog->run ();
3939 transcode_video_dialog->hide();
3940 if (r != RESPONSE_ACCEPT) {
3941 delete transcode_video_dialog;
3944 if (!transcode_video_dialog->get_audiofile().empty()) {
3945 editor->embed_audio_from_video(
3946 transcode_video_dialog->get_audiofile(),
3947 video_timeline->get_offset(),
3948 (transcode_video_dialog->import_option() != VTL_IMPORT_NO_VIDEO)
3951 switch (transcode_video_dialog->import_option()) {
3952 case VTL_IMPORT_TRANSCODED:
3953 path = transcode_video_dialog->get_filename();
3956 case VTL_IMPORT_REFERENCE:
3959 delete transcode_video_dialog;
3962 delete transcode_video_dialog;
3966 case VTL_IMPORT_NONE:
3970 /* strip _session->session_directory().video_path() from video file if possible */
3971 if (local_file && !path.compare(0, _session->session_directory().video_path().size(), _session->session_directory().video_path())) {
3972 path=path.substr(_session->session_directory().video_path().size());
3973 if (path.at(0) == G_DIR_SEPARATOR) {
3974 path=path.substr(1);
3978 video_timeline->set_update_session_fps(auto_set_session_fps);
3979 if (video_timeline->video_file_info(path, local_file)) {
3980 XMLNode* node = new XMLNode(X_("Videotimeline"));
3981 node->add_property (X_("Filename"), path);
3982 node->add_property (X_("AutoFPS"), auto_set_session_fps?X_("1"):X_("0"));
3983 node->add_property (X_("LocalFile"), local_file?X_("1"):X_("0"));
3984 if (orig_local_file) {
3985 node->add_property (X_("OriginalVideoFile"), orig_path);
3987 node->remove_property (X_("OriginalVideoFile"));
3989 _session->add_extra_xml (*node);
3990 _session->set_dirty ();
3992 _session->maybe_update_session_range(
3993 std::max(video_timeline->get_offset(), (ARDOUR::frameoffset_t) 0),
3994 std::max(video_timeline->get_offset() + video_timeline->get_duration(), (ARDOUR::frameoffset_t) 0));
3997 if (add_video_dialog->launch_xjadeo() && local_file) {
3998 editor->set_xjadeo_sensitive(true);
3999 editor->toggle_xjadeo_proc(1);
4001 editor->toggle_xjadeo_proc(0);
4003 editor->toggle_ruler_video(true);
4008 ARDOUR_UI::remove_video ()
4010 video_timeline->close_session();
4011 editor->toggle_ruler_video(false);
4014 video_timeline->set_offset_locked(false);
4015 video_timeline->set_offset(0);
4017 /* delete session state */
4018 XMLNode* node = new XMLNode(X_("Videotimeline"));
4019 _session->add_extra_xml(*node);
4020 node = new XMLNode(X_("Videomonitor"));
4021 _session->add_extra_xml(*node);
4022 node = new XMLNode(X_("Videoexport"));
4023 _session->add_extra_xml(*node);
4024 stop_video_server();
4028 ARDOUR_UI::flush_videotimeline_cache (bool localcacheonly)
4030 if (localcacheonly) {
4031 video_timeline->vmon_update();
4033 video_timeline->flush_cache();
4035 editor->queue_visual_videotimeline_update();
4039 ARDOUR_UI::export_video (bool range)
4041 if (ARDOUR::Config->get_show_video_export_info()) {
4042 ExportVideoInfobox infobox (_session);
4043 Gtk::ResponseType rv = (Gtk::ResponseType) infobox.run();
4044 if (infobox.show_again()) {
4045 ARDOUR::Config->set_show_video_export_info(false);
4048 case GTK_RESPONSE_YES:
4049 PBD::open_uri (ARDOUR::Config->get_reference_manual_url() + "/video-timeline/operations/#export");
4055 export_video_dialog->set_session (_session);
4056 export_video_dialog->apply_state(editor->get_selection().time, range);
4057 export_video_dialog->run ();
4058 export_video_dialog->hide ();
4062 ARDOUR_UI::mixer_settings () const
4067 node = _session->instant_xml(X_("Mixer"));
4069 node = Config->instant_xml(X_("Mixer"));
4073 node = new XMLNode (X_("Mixer"));
4080 ARDOUR_UI::editor_settings () const
4085 node = _session->instant_xml(X_("Editor"));
4087 node = Config->instant_xml(X_("Editor"));
4091 if (getenv("ARDOUR_INSTANT_XML_PATH")) {
4092 node = Config->instant_xml(getenv("ARDOUR_INSTANT_XML_PATH"));
4097 node = new XMLNode (X_("Editor"));
4104 ARDOUR_UI::keyboard_settings () const
4108 node = Config->extra_xml(X_("Keyboard"));
4111 node = new XMLNode (X_("Keyboard"));
4118 ARDOUR_UI::create_xrun_marker (framepos_t where)
4121 Location *location = new Location (*_session, where, where, _("xrun"), Location::IsMark);
4122 _session->locations()->add (location);
4127 ARDOUR_UI::halt_on_xrun_message ()
4129 cerr << "HALT on xrun\n";
4130 MessageDialog msg (*editor, _("Recording was stopped because your system could not keep up."));
4135 ARDOUR_UI::xrun_handler (framepos_t where)
4141 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::xrun_handler, where)
4143 if (_session && Config->get_create_xrun_marker() && _session->actively_recording()) {
4144 create_xrun_marker(where);
4147 if (_session && Config->get_stop_recording_on_xrun() && _session->actively_recording()) {
4148 halt_on_xrun_message ();
4153 ARDOUR_UI::disk_overrun_handler ()
4155 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_overrun_handler)
4157 if (!have_disk_speed_dialog_displayed) {
4158 have_disk_speed_dialog_displayed = true;
4159 MessageDialog* msg = new MessageDialog (*editor, string_compose (_("\
4160 The disk system on your computer\n\
4161 was not able to keep up with %1.\n\
4163 Specifically, it failed to write data to disk\n\
4164 quickly enough to keep up with recording.\n"), PROGRAM_NAME));
4165 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
4171 /* TODO: this is getting elaborate enough to warrant being split into a dedicated class */
4172 static MessageDialog *scan_dlg = NULL;
4173 static ProgressBar *scan_pbar = NULL;
4174 static HBox *scan_tbox = NULL;
4177 ARDOUR_UI::cancel_plugin_scan ()
4179 PluginManager::instance().cancel_plugin_scan();
4183 ARDOUR_UI::cancel_plugin_timeout ()
4185 PluginManager::instance().cancel_plugin_timeout();
4190 ARDOUR_UI::plugin_scan_timeout (int timeout)
4192 if (!scan_dlg || !scan_dlg->is_mapped() || !scan_pbar) {
4196 scan_pbar->set_fraction ((float) timeout / (float) Config->get_vst_scan_timeout());
4205 ARDOUR_UI::plugin_scan_dialog (std::string type, std::string plugin, bool can_cancel)
4207 if (type == X_("closeme") && !(scan_dlg && scan_dlg->is_mapped())) {
4211 const bool cancelled = PluginManager::instance().cancelled();
4212 if (type != X_("closeme") && !ui_config->get_show_plugin_scan_window()) {
4213 if (cancelled && scan_dlg->is_mapped()) {
4218 if (cancelled || !can_cancel) {
4223 static Gtk::Button *cancel_button;
4224 static Gtk::Button *timeout_button;
4226 scan_dlg = new MessageDialog("", false, MESSAGE_INFO, BUTTONS_NONE); // TODO manage
4227 VBox* vbox = scan_dlg->get_vbox();
4228 vbox->set_size_request(400,-1);
4229 scan_dlg->set_title (_("Scanning for plugins"));
4231 cancel_button = manage(new Gtk::Button(_("Cancel plugin scan")));
4232 cancel_button->set_name ("EditorGTKButton");
4233 cancel_button->signal_clicked().connect ( mem_fun (*this, &ARDOUR_UI::cancel_plugin_scan) );
4234 cancel_button->show();
4236 scan_dlg->get_vbox()->pack_start ( *cancel_button, PACK_SHRINK);
4238 scan_tbox = manage( new HBox() );
4240 timeout_button = manage(new Gtk::Button(_("Stop Timeout")));
4241 timeout_button->set_name ("EditorGTKButton");
4242 timeout_button->signal_clicked().connect ( mem_fun (*this, &ARDOUR_UI::cancel_plugin_timeout) );
4243 timeout_button->show();
4245 scan_pbar = manage(new ProgressBar());
4246 scan_pbar->set_orientation(Gtk::PROGRESS_RIGHT_TO_LEFT);
4247 scan_pbar->set_text(_("Scan Timeout"));
4250 scan_tbox->pack_start (*scan_pbar, PACK_EXPAND_WIDGET, 4);
4251 scan_tbox->pack_start (*timeout_button, PACK_SHRINK, 4);
4253 scan_dlg->get_vbox()->pack_start (*scan_tbox, PACK_SHRINK, 4);
4256 assert(scan_dlg && scan_tbox && cancel_button);
4258 if (type == X_("closeme")) {
4261 scan_dlg->set_message(type + ": " + Glib::path_get_basename(plugin));
4264 if (!can_cancel || !cancelled) {
4267 cancel_button->set_sensitive(can_cancel && !cancelled);
4273 ARDOUR_UI::gui_idle_handler ()
4276 /* due to idle calls, gtk_events_pending() may always return true */
4277 while (gtk_events_pending() && --timeout) {
4278 gtk_main_iteration ();
4283 ARDOUR_UI::disk_underrun_handler ()
4285 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::disk_underrun_handler)
4287 if (!have_disk_speed_dialog_displayed) {
4288 have_disk_speed_dialog_displayed = true;
4289 MessageDialog* msg = new MessageDialog (
4290 *editor, string_compose (_("The disk system on your computer\n\
4291 was not able to keep up with %1.\n\
4293 Specifically, it failed to read data from disk\n\
4294 quickly enough to keep up with playback.\n"), PROGRAM_NAME));
4295 msg->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::disk_speed_dialog_gone), msg));
4301 ARDOUR_UI::disk_speed_dialog_gone (int /*ignored_response*/, MessageDialog* msg)
4303 have_disk_speed_dialog_displayed = false;
4308 ARDOUR_UI::session_dialog (std::string msg)
4310 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::session_dialog, msg)
4315 d = new MessageDialog (*editor, msg, false, MESSAGE_INFO, BUTTONS_OK, true);
4317 d = new MessageDialog (msg, false, MESSAGE_INFO, BUTTONS_OK, true);
4326 ARDOUR_UI::pending_state_dialog ()
4328 HBox* hbox = manage (new HBox());
4329 Image* image = manage (new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG));
4330 ArdourDialog dialog (_("Crash Recovery"), true);
4331 Label message (string_compose (_("\
4332 This session appears to have been in the\n\
4333 middle of recording when %1 or\n\
4334 the computer was shutdown.\n\
4336 %1 can recover any captured audio for\n\
4337 you, or it can ignore it. Please decide\n\
4338 what you would like to do.\n"), PROGRAM_NAME));
4339 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
4340 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
4341 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
4342 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
4343 dialog.add_button (_("Ignore crash data"), RESPONSE_REJECT);
4344 dialog.add_button (_("Recover from crash"), RESPONSE_ACCEPT);
4345 dialog.set_default_response (RESPONSE_ACCEPT);
4346 dialog.set_position (WIN_POS_CENTER);
4351 switch (dialog.run ()) {
4352 case RESPONSE_ACCEPT:
4360 ARDOUR_UI::sr_mismatch_dialog (framecnt_t desired, framecnt_t actual)
4362 HBox* hbox = new HBox();
4363 Image* image = new Image (Stock::DIALOG_WARNING, ICON_SIZE_DIALOG);
4364 ArdourDialog dialog (_("Sample Rate Mismatch"), true);
4365 Label message (string_compose (_("\
4366 This session was created with a sample rate of %1 Hz, but\n\
4367 %2 is currently running at %3 Hz. If you load this session,\n\
4368 audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual));
4370 image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
4371 hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
4372 hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
4373 dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
4374 dialog.add_button (_("Do not load session"), RESPONSE_REJECT);
4375 dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT);
4376 dialog.set_default_response (RESPONSE_ACCEPT);
4377 dialog.set_position (WIN_POS_CENTER);
4382 switch (dialog.run()) {
4383 case RESPONSE_ACCEPT:
4393 ARDOUR_UI::disconnect_from_engine ()
4395 /* drop connection to AudioEngine::Halted so that we don't act
4396 * as if the engine unexpectedly shut down
4399 halt_connection.disconnect ();
4401 if (AudioEngine::instance()->stop ()) {
4402 MessageDialog msg (*editor, _("Could not disconnect from Audio/MIDI engine"));
4406 AudioEngine::instance()->Halted.connect_same_thread (halt_connection, boost::bind (&ARDOUR_UI::engine_halted, this, _1, false));
4409 update_sample_rate (0);
4414 ARDOUR_UI::reconnect_to_engine ()
4416 if (AudioEngine::instance()->start ()) {
4417 // TODO somehow make this the topmost window (above any dialogs currently visible)
4419 MessageDialog msg (*editor, _("Could not reconnect to the Audio/MIDI engine"));
4422 MessageDialog msg (_("Could not reconnect to the Audio/MIDI engine"));
4428 update_sample_rate (0);
4433 ARDOUR_UI::use_config ()
4435 XMLNode* node = Config->extra_xml (X_("TransportControllables"));
4437 set_transport_controllable_state (*node);
4442 ARDOUR_UI::update_transport_clocks (framepos_t pos)
4444 if (ui_config->get_primary_clock_delta_edit_cursor()) {
4445 primary_clock->set (pos, false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD));
4447 primary_clock->set (pos);
4450 if (ui_config->get_secondary_clock_delta_edit_cursor()) {
4451 secondary_clock->set (pos, false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD));
4453 secondary_clock->set (pos);
4456 if (big_clock_window) {
4457 big_clock->set (pos);
4459 ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor(pos);
4463 ARDOUR_UI::step_edit_status_change (bool yn)
4465 // XXX should really store pre-step edit status of things
4466 // we make insensitive
4469 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
4470 rec_button.set_sensitive (false);
4472 rec_button.unset_active_state ();;
4473 rec_button.set_sensitive (true);
4478 ARDOUR_UI::record_state_changed ()
4480 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);
4482 if (!_session || !big_clock_window) {
4483 /* why bother - the clock isn't visible */
4487 if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
4488 big_clock->set_active (true);
4490 big_clock->set_active (false);
4495 ARDOUR_UI::first_idle ()
4498 _session->allow_auto_play (true);
4502 editor->first_idle();
4505 Keyboard::set_can_save_keybindings (true);
4510 ARDOUR_UI::store_clock_modes ()
4512 XMLNode* node = new XMLNode(X_("ClockModes"));
4514 for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
4515 XMLNode* child = new XMLNode (X_("Clock"));
4517 child->add_property (X_("name"), (*x)->name());
4518 child->add_property (X_("mode"), enum_2_string ((*x)->mode()));
4519 child->add_property (X_("on"), ((*x)->off() ? X_("no") : X_("yes")));
4521 node->add_child_nocopy (*child);
4524 _session->add_extra_xml (*node);
4525 _session->set_dirty ();
4528 ARDOUR_UI::TransportControllable::TransportControllable (std::string name, ARDOUR_UI& u, ToggleType tp)
4529 : Controllable (name), ui (u), type(tp)
4535 ARDOUR_UI::TransportControllable::set_value (double val)
4538 /* do nothing: these are radio-style actions */
4542 const char *action = 0;
4546 action = X_("Roll");
4549 action = X_("Stop");
4552 action = X_("GotoStart");
4555 action = X_("GotoEnd");
4558 action = X_("Loop");
4561 action = X_("PlaySelection");
4564 action = X_("Record");
4574 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", action);
4582 ARDOUR_UI::TransportControllable::get_value (void) const
4609 ARDOUR_UI::setup_profile ()
4611 if (gdk_screen_width() < 1200 || getenv ("ARDOUR_NARROW_SCREEN")) {
4612 Profile->set_small_screen ();
4615 if (g_getenv ("ARDOUR_SAE")) {
4616 Profile->set_sae ();
4617 Profile->set_single_package ();
4620 if (g_getenv ("TRX")) {
4621 Profile->set_trx ();
4624 if (g_getenv ("MIXBUS")) {
4625 Profile->set_mixbus ();
4630 ARDOUR_UI::missing_file (Session*s, std::string str, DataType type)
4632 MissingFileDialog dialog (s, str, type);
4637 int result = dialog.run ();
4644 return 1; // quit entire session load
4647 result = dialog.get_action ();
4653 ARDOUR_UI::ambiguous_file (std::string file, std::vector<std::string> hits)
4655 AmbiguousFileDialog dialog (file, hits);
4661 return dialog.get_which ();
4664 /** Allocate our thread-local buffers */
4666 ARDOUR_UI::get_process_buffers ()
4668 _process_thread->get_buffers ();
4671 /** Drop our thread-local buffers */
4673 ARDOUR_UI::drop_process_buffers ()
4675 _process_thread->drop_buffers ();
4679 ARDOUR_UI::feedback_detected ()
4681 _feedback_exists = true;
4685 ARDOUR_UI::successful_graph_sort ()
4687 _feedback_exists = false;
4691 ARDOUR_UI::midi_panic ()
4694 _session->midi_panic();
4699 ARDOUR_UI::session_format_mismatch (std::string xml_path, std::string backup_path)
4701 const char* start_big = "<span size=\"x-large\" weight=\"bold\">";
4702 const char* end_big = "</span>";
4703 const char* start_mono = "<tt>";
4704 const char* end_mono = "</tt>";
4706 MessageDialog msg (string_compose (_("%4This is a session from an older version of %3%5\n\n"
4707 "%3 has copied the old session file\n\n%6%1%7\n\nto\n\n%6%2%7\n\n"
4708 "From now on, use the -2000 version with older versions of %3"),
4709 xml_path, backup_path, PROGRAM_NAME,
4711 start_mono, end_mono), true);
4718 ARDOUR_UI::reset_peak_display ()
4720 if (!_session || !_session->master_out() || !editor_meter) return;
4721 editor_meter->clear_meters();
4722 editor_meter_max_peak = -INFINITY;
4723 editor_meter_peak_display.set_active_state ( Gtkmm2ext::Off );
4727 ARDOUR_UI::reset_group_peak_display (RouteGroup* group)
4729 if (!_session || !_session->master_out()) return;
4730 if (group == _session->master_out()->route_group()) {
4731 reset_peak_display ();
4736 ARDOUR_UI::reset_route_peak_display (Route* route)
4738 if (!_session || !_session->master_out()) return;
4739 if (_session->master_out().get() == route) {
4740 reset_peak_display ();
4745 ARDOUR_UI::do_audio_midi_setup (uint32_t desired_sample_rate)
4747 audio_midi_setup->set_desired_sample_rate (desired_sample_rate);
4748 audio_midi_setup->set_position (WIN_POS_CENTER);
4750 switch (audio_midi_setup->run()) {
4751 case Gtk::RESPONSE_OK:
4753 case Gtk::RESPONSE_APPLY:
4762 ARDOUR_UI::transport_numpad_timeout ()
4764 _numpad_locate_happening = false;
4765 if (_numpad_timeout_connection.connected() )
4766 _numpad_timeout_connection.disconnect();
4771 ARDOUR_UI::transport_numpad_decimal ()
4773 _numpad_timeout_connection.disconnect();
4775 if (_numpad_locate_happening) {
4776 if (editor) editor->goto_nth_marker(_pending_locate_num - 1);
4777 _numpad_locate_happening = false;
4779 _pending_locate_num = 0;
4780 _numpad_locate_happening = true;
4781 _numpad_timeout_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::transport_numpad_timeout), 2*1000);
4786 ARDOUR_UI::transport_numpad_event (int num)
4788 if ( _numpad_locate_happening ) {
4789 _pending_locate_num = _pending_locate_num*10 + num;
4792 case 0: toggle_roll(false, false); break;
4793 case 1: transport_rewind(1); break;
4794 case 2: transport_forward(1); break;
4795 case 3: transport_record(true); break;
4796 case 4: toggle_session_auto_loop(); break;
4797 case 5: transport_record(false); toggle_session_auto_loop(); break;
4798 case 6: toggle_punch(); break;
4799 case 7: toggle_click(); break;
4800 case 8: toggle_auto_return(); break;
4801 case 9: toggle_follow_edits(); break;
4807 ARDOUR_UI::set_flat_buttons ()
4809 CairoWidget::set_flat_buttons( config()->get_flat_buttons() );
4813 ARDOUR_UI::audioengine_became_silent ()
4815 MessageDialog msg (string_compose (_("This is a free/demo copy of %1. It has just switched to silent mode."), PROGRAM_NAME),
4817 Gtk::MESSAGE_WARNING,
4821 msg.set_title (string_compose (_("%1 is now silent"), PROGRAM_NAME));
4823 Gtk::Label pay_label (string_compose (_("Please consider paying for a copy of %1 - you can pay whatever you want."), PROGRAM_NAME));
4824 Gtk::Label subscribe_label (_("Better yet become a subscriber - subscriptions start at US$1 per month."));
4825 Gtk::Button pay_button (_("Pay for a copy (via the web)"));
4826 Gtk::Button subscribe_button (_("Become a subscriber (via the web)"));
4827 Gtk::HBox pay_button_box;
4828 Gtk::HBox subscribe_button_box;
4830 pay_button_box.pack_start (pay_button, true, false);
4831 subscribe_button_box.pack_start (subscribe_button, true, false);
4833 bool (*openuri)(const char*) = PBD::open_uri; /* this forces selection of the const char* variant of PBD::open_uri(), which we need to avoid ambiguity below */
4835 pay_button.signal_clicked().connect (sigc::hide_return (sigc::bind (sigc::ptr_fun (openuri), (const char*) "https://ardour.org/download")));
4836 subscribe_button.signal_clicked().connect (sigc::hide_return (sigc::bind (sigc::ptr_fun (openuri), (const char*) "https://community.ardour.org/s/subscribe")));
4838 msg.get_vbox()->pack_start (pay_label);
4839 msg.get_vbox()->pack_start (pay_button_box);
4840 msg.get_vbox()->pack_start (subscribe_label);
4841 msg.get_vbox()->pack_start (subscribe_button_box);
4843 msg.get_vbox()->show_all ();
4845 msg.add_button (_("Remain silent"), Gtk::RESPONSE_CANCEL);
4846 msg.add_button (_("Save and quit"), Gtk::RESPONSE_NO);
4847 msg.add_button (_("Give me more time"), Gtk::RESPONSE_YES);
4852 case Gtk::RESPONSE_YES:
4853 AudioEngine::instance()->reset_silence_countdown ();
4856 case Gtk::RESPONSE_NO:
4858 save_state_canfail ("");
4862 case Gtk::RESPONSE_CANCEL:
4864 /* don't reset, save session and exit */
4870 ARDOUR_UI::hide_application ()
4872 Application::instance ()-> hide ();