2 Copyright (C) 2000-2009 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.
20 /* Note: public Editor methods are documented in public_editor.h */
22 #define __STDC_LIMIT_MACROS 1
31 #include "ardour_ui.h"
33 * ardour_ui.h include was moved to the top of the list
34 * due to a conflicting definition of 'Style' between
35 * Apple's MacTypes.h and BarController.
38 #include <boost/none.hpp>
40 #include <sigc++/bind.h>
42 #include "pbd/convert.h"
43 #include "pbd/error.h"
44 #include "pbd/enumwriter.h"
45 #include "pbd/memento_command.h"
46 #include "pbd/unknown_type.h"
48 #include <glibmm/miscutils.h>
49 #include <gtkmm/image.h>
50 #include <gdkmm/color.h>
51 #include <gdkmm/bitmap.h>
53 #include <gtkmm2ext/grouped_buttons.h>
54 #include <gtkmm2ext/gtk_ui.h>
55 #include <gtkmm2ext/tearoff.h>
56 #include <gtkmm2ext/utils.h>
57 #include <gtkmm2ext/window_title.h>
58 #include <gtkmm2ext/choice.h>
59 #include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
61 #include "ardour/audio_diskstream.h"
62 #include "ardour/audio_track.h"
63 #include "ardour/audioplaylist.h"
64 #include "ardour/audioregion.h"
65 #include "ardour/location.h"
66 #include "ardour/midi_region.h"
67 #include "ardour/plugin_manager.h"
68 #include "ardour/profile.h"
69 #include "ardour/route_group.h"
70 #include "ardour/session_directory.h"
71 #include "ardour/session_route.h"
72 #include "ardour/session_state_utils.h"
73 #include "ardour/tempo.h"
74 #include "ardour/utils.h"
75 #include "ardour/session_playlists.h"
77 #include "control_protocol/control_protocol.h"
82 #include "playlist_selector.h"
83 #include "audio_region_view.h"
84 #include "rgb_macros.h"
85 #include "selection.h"
86 #include "audio_streamview.h"
87 #include "time_axis_view.h"
88 #include "audio_time_axis.h"
90 #include "crossfade_view.h"
91 #include "canvas-noevent-text.h"
93 #include "public_editor.h"
94 #include "crossfade_edit.h"
95 #include "canvas_impl.h"
98 #include "gui_thread.h"
99 #include "simpleline.h"
100 #include "rhythm_ferret.h"
102 #include "tempo_lines.h"
103 #include "analysis_window.h"
104 #include "bundle_manager.h"
105 #include "global_port_matrix.h"
106 #include "editor_drag.h"
107 #include "editor_group_tabs.h"
108 #include "automation_time_axis.h"
109 #include "editor_routes.h"
110 #include "midi_time_axis.h"
111 #include "mixer_strip.h"
112 #include "editor_route_groups.h"
113 #include "editor_regions.h"
114 #include "editor_locations.h"
115 #include "editor_snapshots.h"
120 #include "imageframe_socket_handler.h"
124 using namespace ARDOUR;
127 using namespace Glib;
128 using namespace Gtkmm2ext;
129 using namespace Editing;
131 using PBD::internationalize;
133 using Gtkmm2ext::Keyboard;
135 const double Editor::timebar_height = 15.0;
137 #include "editor_xpms"
139 static const gchar *_snap_type_strings[] = {
141 N_("Timecode Frames"),
142 N_("Timecode Seconds"),
143 N_("Timecode Minutes"),
161 static const gchar *_snap_mode_strings[] = {
168 static const gchar *_edit_point_strings[] = {
175 static const gchar *_zoom_focus_strings[] = {
185 #ifdef USE_RUBBERBAND
186 static const gchar *_rb_opt_strings[] = {
189 N_("Balanced multitimbral mixture"),
190 N_("Unpitched percussion with stable notes"),
191 N_("Crisp monophonic instrumental"),
192 N_("Unpitched solo percussion"),
197 /* Soundfile drag-n-drop */
199 Gdk::Cursor* Editor::cross_hair_cursor = 0;
200 Gdk::Cursor* Editor::selector_cursor = 0;
201 Gdk::Cursor* Editor::trimmer_cursor = 0;
202 Gdk::Cursor* Editor::grabber_cursor = 0;
203 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
204 Gdk::Cursor* Editor::zoom_cursor = 0;
205 Gdk::Cursor* Editor::time_fx_cursor = 0;
206 Gdk::Cursor* Editor::fader_cursor = 0;
207 Gdk::Cursor* Editor::speaker_cursor = 0;
208 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
209 Gdk::Cursor* Editor::midi_select_cursor = 0;
210 Gdk::Cursor* Editor::midi_resize_cursor = 0;
211 Gdk::Cursor* Editor::midi_erase_cursor = 0;
212 Gdk::Cursor* Editor::wait_cursor = 0;
213 Gdk::Cursor* Editor::timebar_cursor = 0;
214 Gdk::Cursor* Editor::transparent_cursor = 0;
217 show_me_the_size (Requisition* r, const char* what)
219 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
223 /* time display buttons */
224 : minsec_label (_("Mins:Secs"))
225 , bbt_label (_("Bars:Beats"))
226 , timecode_label (_("Timecode"))
227 , frame_label (_("Samples"))
228 , tempo_label (_("Tempo"))
229 , meter_label (_("Meter"))
230 , mark_label (_("Location Markers"))
231 , range_mark_label (_("Range Markers"))
232 , transport_mark_label (_("Loop/Punch Ranges"))
233 , cd_mark_label (_("CD Markers"))
234 , edit_packer (4, 4, true)
236 /* the values here don't matter: layout widgets
237 reset them as needed.
240 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
241 , horizontal_adjustment (0.0, 0.0, 20.0, 1200.0)
243 /* tool bar related */
245 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
247 , toolbar_selection_clock_table (2,3)
249 , automation_mode_button (_("mode"))
250 , global_automation_button (_("automation"))
252 , midi_panic_button (_("Panic"))
255 , image_socket_listener(0)
260 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
261 , meters_running(false)
262 , _pending_locate_request (false)
267 /* we are a singleton */
269 PublicEditor::_instance = this;
273 selection = new Selection (this);
274 cut_buffer = new Selection (this);
276 clicked_regionview = 0;
277 clicked_axisview = 0;
278 clicked_routeview = 0;
279 clicked_crossfadeview = 0;
280 clicked_control_point = 0;
281 last_update_frame = 0;
283 current_mixer_strip = 0;
284 current_bbt_points = 0;
287 snap_type_strings = I18N (_snap_type_strings);
288 snap_mode_strings = I18N (_snap_mode_strings);
289 zoom_focus_strings = I18N (_zoom_focus_strings);
290 edit_point_strings = I18N (_edit_point_strings);
291 #ifdef USE_RUBBERBAND
292 rb_opt_strings = I18N (_rb_opt_strings);
295 snap_threshold = 5.0;
296 bbt_beat_subdivision = 4;
299 last_autoscroll_x = 0;
300 last_autoscroll_y = 0;
301 autoscroll_active = false;
302 autoscroll_timeout_tag = -1;
303 interthread_progress_window = 0;
308 current_interthread_info = 0;
309 _show_measures = true;
310 _show_waveforms_recording = true;
311 show_gain_after_trim = false;
312 verbose_cursor_on = true;
313 last_item_entered = 0;
314 last_item_entered_n = 0;
316 have_pending_keyboard_selection = false;
317 _follow_playhead = true;
318 _xfade_visibility = true;
319 editor_ruler_menu = 0;
320 no_ruler_shown_update = false;
322 start_end_marker_menu = 0;
323 range_marker_menu = 0;
324 marker_menu_item = 0;
326 transport_marker_menu = 0;
327 new_transport_marker_menu = 0;
328 editor_mixer_strip_width = Wide;
329 show_editor_mixer_when_tracks_arrive = false;
330 region_edit_menu_split_multichannel_item = 0;
331 region_edit_menu_split_item = 0;
334 current_stepping_trackview = 0;
336 entered_regionview = 0;
338 clear_entered_track = false;
339 _new_regionviews_show_envelope = false;
342 button_release_can_deselect = true;
343 _dragging_playhead = false;
344 _dragging_edit_point = false;
345 select_new_marker = false;
348 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
349 _global_port_matrix[*i] = 0;
351 allow_vertical_scroll = false;
352 no_save_visual = false;
355 scrubbing_direction = 0;
359 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
360 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
361 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
362 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
363 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
365 _edit_point = EditAtMouse;
366 _internal_editing = false;
367 current_canvas_cursor = 0;
369 frames_per_unit = 2048; /* too early to use reset_zoom () */
371 zoom_focus = ZoomFocusLeft;
372 set_zoom_focus (ZoomFocusLeft);
373 zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
375 bbt_label.set_name ("EditorTimeButton");
376 bbt_label.set_size_request (-1, (int)timebar_height);
377 bbt_label.set_alignment (1.0, 0.5);
378 bbt_label.set_padding (5,0);
380 bbt_label.set_no_show_all();
381 minsec_label.set_name ("EditorTimeButton");
382 minsec_label.set_size_request (-1, (int)timebar_height);
383 minsec_label.set_alignment (1.0, 0.5);
384 minsec_label.set_padding (5,0);
385 minsec_label.hide ();
386 minsec_label.set_no_show_all();
387 timecode_label.set_name ("EditorTimeButton");
388 timecode_label.set_size_request (-1, (int)timebar_height);
389 timecode_label.set_alignment (1.0, 0.5);
390 timecode_label.set_padding (5,0);
391 timecode_label.hide ();
392 timecode_label.set_no_show_all();
393 frame_label.set_name ("EditorTimeButton");
394 frame_label.set_size_request (-1, (int)timebar_height);
395 frame_label.set_alignment (1.0, 0.5);
396 frame_label.set_padding (5,0);
398 frame_label.set_no_show_all();
400 tempo_label.set_name ("EditorTimeButton");
401 tempo_label.set_size_request (-1, (int)timebar_height);
402 tempo_label.set_alignment (1.0, 0.5);
403 tempo_label.set_padding (5,0);
405 tempo_label.set_no_show_all();
406 meter_label.set_name ("EditorTimeButton");
407 meter_label.set_size_request (-1, (int)timebar_height);
408 meter_label.set_alignment (1.0, 0.5);
409 meter_label.set_padding (5,0);
411 meter_label.set_no_show_all();
412 mark_label.set_name ("EditorTimeButton");
413 mark_label.set_size_request (-1, (int)timebar_height);
414 mark_label.set_alignment (1.0, 0.5);
415 mark_label.set_padding (5,0);
417 mark_label.set_no_show_all();
418 cd_mark_label.set_name ("EditorTimeButton");
419 cd_mark_label.set_size_request (-1, (int)timebar_height);
420 cd_mark_label.set_alignment (1.0, 0.5);
421 cd_mark_label.set_padding (5,0);
422 cd_mark_label.hide();
423 cd_mark_label.set_no_show_all();
424 range_mark_label.set_name ("EditorTimeButton");
425 range_mark_label.set_size_request (-1, (int)timebar_height);
426 range_mark_label.set_alignment (1.0, 0.5);
427 range_mark_label.set_padding (5,0);
428 range_mark_label.hide();
429 range_mark_label.set_no_show_all();
430 transport_mark_label.set_name ("EditorTimeButton");
431 transport_mark_label.set_size_request (-1, (int)timebar_height);
432 transport_mark_label.set_alignment (1.0, 0.5);
433 transport_mark_label.set_padding (5,0);
434 transport_mark_label.hide();
435 transport_mark_label.set_no_show_all();
437 initialize_rulers ();
438 initialize_canvas ();
439 _summary = new EditorSummary (this);
441 selection->TimeChanged.connect (sigc::mem_fun(*this, &Editor::time_selection_changed));
442 selection->TracksChanged.connect (sigc::mem_fun(*this, &Editor::track_selection_changed));
443 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (sigc::mem_fun(*this, &Editor::region_selection_changed));
444 selection->PointsChanged.connect (sigc::mem_fun(*this, &Editor::point_selection_changed));
445 selection->MarkersChanged.connect (sigc::mem_fun(*this, &Editor::marker_selection_changed));
447 edit_controls_vbox.set_spacing (0);
448 horizontal_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
449 vertical_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::tie_vertical_scrolling), true);
450 track_canvas->signal_map_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_map_handler));
452 HBox* h = manage (new HBox);
453 _group_tabs = new EditorGroupTabs (this);
454 h->pack_start (*_group_tabs, PACK_SHRINK);
455 h->pack_start (edit_controls_vbox);
456 controls_layout.add (*h);
458 ARDOUR_UI::instance()->tooltips().set_tip (*_group_tabs, _("Groups: context-click for possible operations"));
460 controls_layout.set_name ("EditControlsBase");
461 controls_layout.add_events (Gdk::SCROLL_MASK);
462 controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false);
464 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
465 controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
466 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
470 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
471 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
472 0.0, 1.0, 100.0, 1.0));
473 pad_line_1->property_color_rgba() = 0xFF0000FF;
477 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
478 time_canvas_vbox.set_size_request (-1, -1);
480 ruler_label_event_box.add (ruler_label_vbox);
481 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
482 ruler_label_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
484 time_button_event_box.add (time_button_vbox);
485 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
486 time_button_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
488 /* these enable us to have a dedicated window (for cursor setting, etc.)
489 for the canvas areas.
492 track_canvas_event_box.add (*track_canvas);
494 time_canvas_event_box.add (time_canvas_vbox);
495 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
497 edit_packer.set_col_spacings (0);
498 edit_packer.set_row_spacings (0);
499 edit_packer.set_homogeneous (false);
500 edit_packer.set_border_width (0);
501 edit_packer.set_name ("EditorWindow");
503 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
504 /* labels for the rulers */
505 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
506 /* labels for the marker "tracks" */
507 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
509 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
511 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
513 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
515 bottom_hbox.set_border_width (2);
516 bottom_hbox.set_spacing (3);
518 _route_groups = new EditorRouteGroups (this);
519 _routes = new EditorRoutes (this);
520 _regions = new EditorRegions (this);
521 _snapshots = new EditorSnapshots (this);
522 _locations = new EditorLocations (this);
526 nlabel = manage (new Label (_("Regions")));
527 nlabel->set_angle (-90);
528 the_notebook.append_page (_regions->widget (), *nlabel);
529 nlabel = manage (new Label (_("Tracks/Busses")));
530 nlabel->set_angle (-90);
531 the_notebook.append_page (_routes->widget (), *nlabel);
532 nlabel = manage (new Label (_("Snapshots")));
533 nlabel->set_angle (-90);
534 the_notebook.append_page (_snapshots->widget (), *nlabel);
535 nlabel = manage (new Label (_("Route Groups")));
536 nlabel->set_angle (-90);
537 the_notebook.append_page (_route_groups->widget (), *nlabel);
538 nlabel = manage (new Label (_("Ranges & Marks")));
539 nlabel->set_angle (-90);
540 the_notebook.append_page (_locations->widget (), *nlabel);
542 the_notebook.set_show_tabs (true);
543 the_notebook.set_scrollable (true);
544 the_notebook.popup_disable ();
545 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
546 the_notebook.show_all ();
548 post_maximal_editor_width = 0;
549 post_maximal_pane_position = 0;
551 VPaned *editor_summary_pane = manage(new VPaned());
552 editor_summary_pane->pack1(edit_packer);
554 Button* summary_arrows_left_left = manage (new Button);
555 summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
556 summary_arrows_left_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
557 Button* summary_arrows_left_right = manage (new Button);
558 summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
559 summary_arrows_left_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
560 VBox* summary_arrows_left = manage (new VBox);
561 summary_arrows_left->pack_start (*summary_arrows_left_left);
562 summary_arrows_left->pack_start (*summary_arrows_left_right);
564 Button* summary_arrows_right_left = manage (new Button);
565 summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
566 summary_arrows_right_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
567 Button* summary_arrows_right_right = manage (new Button);
568 summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
569 summary_arrows_right_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
570 VBox* summary_arrows_right = manage (new VBox);
571 summary_arrows_right->pack_start (*summary_arrows_right_left);
572 summary_arrows_right->pack_start (*summary_arrows_right_right);
574 Frame* summary_frame = manage (new Frame);
575 summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
576 summary_frame->add (*_summary);
577 summary_frame->show ();
579 _summary_hbox.pack_start (*summary_arrows_left, false, false);
580 _summary_hbox.pack_start (*summary_frame, true, true);
581 _summary_hbox.pack_start (*summary_arrows_right, false, false);
583 editor_summary_pane->pack2 (_summary_hbox);
585 edit_pane.pack1 (*editor_summary_pane, true, true);
586 edit_pane.pack2 (the_notebook, false, true);
588 edit_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
590 top_hbox.pack_start (toolbar_frame, false, true);
592 HBox *hbox = manage (new HBox);
593 hbox->pack_start (edit_pane, true, true);
595 global_vpacker.pack_start (top_hbox, false, false);
596 global_vpacker.pack_start (*hbox, true, true);
598 global_hpacker.pack_start (global_vpacker, true, true);
600 set_name ("EditorWindow");
601 add_accel_group (ActionManager::ui_manager->get_accel_group());
603 status_bar_hpacker.show ();
605 vpacker.pack_end (status_bar_hpacker, false, false);
606 vpacker.pack_end (global_hpacker, true, true);
608 /* register actions now so that set_state() can find them and set toggles/checks etc */
613 setup_midi_toolbar ();
615 _snap_type = SnapToBeat;
616 set_snap_to (_snap_type);
617 _snap_mode = SnapOff;
618 set_snap_mode (_snap_mode);
619 set_mouse_mode (MouseObject, true);
620 set_edit_point_preference (EditAtMouse, true);
622 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
623 set_state (*node, Stateful::loading_state_version);
625 _playlist_selector = new PlaylistSelector();
626 _playlist_selector->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
628 RegionView::RegionViewGoingAway.connect (*this, ui_bind (&Editor::catch_vanishing_regionview, this, _1), gui_context());
632 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
633 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
635 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
636 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
638 nudge_forward_button.set_name ("TransportButton");
639 nudge_backward_button.set_name ("TransportButton");
641 fade_context_menu.set_name ("ArdourContextMenu");
643 /* icons, titles, WM stuff */
645 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
646 Glib::RefPtr<Gdk::Pixbuf> icon;
648 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
649 window_icons.push_back (icon);
651 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
652 window_icons.push_back (icon);
654 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
655 window_icons.push_back (icon);
657 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
658 window_icons.push_back (icon);
660 if (!window_icons.empty()) {
661 set_icon_list (window_icons);
662 set_default_icon_list (window_icons);
665 WindowTitle title(Glib::get_application_name());
666 title += _("Editor");
667 set_title (title.get_string());
668 set_wmclass (X_("ardour_editor"), "Ardour");
671 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
673 signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
674 signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
676 /* allow external control surfaces/protocols to do various things */
678 ControlProtocol::ZoomToSession.connect (*this, boost::bind (&Editor::temporal_zoom_session, this), gui_context());
679 ControlProtocol::ZoomIn.connect (*this, boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
680 ControlProtocol::ZoomOut.connect (*this, boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
681 ControlProtocol::ScrollTimeline.connect (*this, ui_bind (&Editor::control_scroll, this, _1), gui_context());
682 BasicUI::AccessAction.connect (*this, ui_bind (&Editor::access_action, this, _1, _2), gui_context());
684 /* problematic: has to return a value and thus cannot be x-thread */
686 Session::AskAboutPlaylistDeletion.connect_same_thread (*this, boost::bind (&Editor::playlist_deletion_dialog, this, _1));
688 Config->ParameterChanged.connect (*this, ui_bind (&Editor::parameter_changed, this, _1), gui_context());
690 TimeAxisView::CatchDeletion.connect (*this, ui_bind (&Editor::timeaxisview_deleted, this, _1), gui_context());
692 _last_normalization_value = 0;
701 if(image_socket_listener) {
702 if(image_socket_listener->is_connected())
704 image_socket_listener->close_connection() ;
707 delete image_socket_listener ;
708 image_socket_listener = 0 ;
713 delete _route_groups;
719 Editor::add_toplevel_controls (Container& cont)
721 vpacker.pack_start (cont, false, false);
726 Editor::catch_vanishing_regionview (RegionView *rv)
728 /* note: the selection will take care of the vanishing
729 audioregionview by itself.
732 if (_drag && rv->get_canvas_group() == _drag->item() && !_drag->ending()) {
738 if (clicked_regionview == rv) {
739 clicked_regionview = 0;
742 if (entered_regionview == rv) {
743 set_entered_regionview (0);
748 Editor::set_entered_regionview (RegionView* rv)
750 if (rv == entered_regionview) {
754 if (entered_regionview) {
755 entered_regionview->exited ();
758 if ((entered_regionview = rv) != 0) {
759 entered_regionview->entered ();
764 Editor::set_entered_track (TimeAxisView* tav)
767 entered_track->exited ();
770 if ((entered_track = tav) != 0) {
771 entered_track->entered ();
776 Editor::show_window ()
778 if (! is_visible ()) {
781 /* re-hide editor list if necessary */
782 editor_list_button_toggled ();
784 /* re-hide summary widget if necessary */
785 parameter_changed ("show-summary");
787 parameter_changed ("show-edit-group-tabs");
789 /* now reset all audio_time_axis heights, because widgets might need
795 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
796 tv = (static_cast<TimeAxisView*>(*i));
805 Editor::instant_save ()
807 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
812 _session->add_instant_xml(get_state());
814 Config->add_instant_xml(get_state());
819 Editor::zoom_adjustment_changed ()
825 double fpu = zoom_range_clock.current_duration() / _canvas_width;
829 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
830 } else if (fpu > _session->current_end_frame() / _canvas_width) {
831 fpu = _session->current_end_frame() / _canvas_width;
832 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
839 Editor::control_scroll (float fraction)
841 ENSURE_GUI_THREAD (*this, &Editor::control_scroll, fraction)
847 double step = fraction * current_page_frames();
850 _control_scroll_target is an optional<T>
852 it acts like a pointer to an nframes64_t, with
853 a operator conversion to boolean to check
854 that it has a value could possibly use
855 playhead_cursor->current_frame to store the
856 value and a boolean in the class to know
857 when it's out of date
860 if (!_control_scroll_target) {
861 _control_scroll_target = _session->transport_frame();
862 _dragging_playhead = true;
865 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
866 *_control_scroll_target = 0;
867 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
868 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
870 *_control_scroll_target += (nframes64_t) floor (step);
873 /* move visuals, we'll catch up with it later */
875 playhead_cursor->set_position (*_control_scroll_target);
876 UpdateAllTransportClocks (*_control_scroll_target);
878 if (*_control_scroll_target > (current_page_frames() / 2)) {
879 /* try to center PH in window */
880 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
886 Now we do a timeout to actually bring the session to the right place
887 according to the playhead. This is to avoid reading disk buffers on every
888 call to control_scroll, which is driven by ScrollTimeline and therefore
889 probably by a control surface wheel which can generate lots of events.
891 /* cancel the existing timeout */
893 control_scroll_connection.disconnect ();
895 /* add the next timeout */
897 control_scroll_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
901 Editor::deferred_control_scroll (nframes64_t /*target*/)
903 _session->request_locate (*_control_scroll_target, _session->transport_rolling());
904 // reset for next stream
905 _control_scroll_target = boost::none;
906 _dragging_playhead = false;
911 Editor::access_action (std::string action_group, std::string action_item)
917 ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
920 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
930 Editor::on_realize ()
932 Window::on_realize ();
937 Editor::start_scrolling ()
939 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
940 (sigc::mem_fun(*this, &Editor::update_current_screen));
945 Editor::stop_scrolling ()
947 scroll_connection.disconnect ();
951 Editor::map_position_change (nframes64_t frame)
953 ENSURE_GUI_THREAD (*this, &Editor::map_position_change, frame)
955 if (_session == 0 || !_follow_playhead) {
959 center_screen (frame);
960 playhead_cursor->set_position (frame);
964 Editor::center_screen (nframes64_t frame)
966 double page = _canvas_width * frames_per_unit;
968 /* if we're off the page, then scroll.
971 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
972 center_screen_internal (frame, page);
977 Editor::center_screen_internal (nframes64_t frame, float page)
982 frame -= (nframes64_t) page;
987 reset_x_origin (frame);
991 Editor::handle_new_duration ()
997 ENSURE_GUI_THREAD (*this, &Editor::handle_new_duration)
998 nframes64_t new_end = _session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1000 horizontal_adjustment.set_upper (new_end / frames_per_unit);
1001 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1003 if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
1004 horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
1006 //cerr << "Editor::handle_new_duration () called ha v:l:u:ps:lcf = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << endl;//DEBUG
1010 Editor::update_title ()
1012 ENSURE_GUI_THREAD (*this, &Editor::update_title)
1015 bool dirty = _session->dirty();
1017 string session_name;
1019 if (_session->snap_name() != _session->name()) {
1020 session_name = _session->snap_name();
1022 session_name = _session->name();
1026 session_name = "*" + session_name;
1029 WindowTitle title(session_name);
1030 title += Glib::get_application_name();
1031 set_title (title.get_string());
1036 Editor::set_session (Session *t)
1038 SessionHandlePtr::set_session (t);
1044 zoom_range_clock.set_session (_session);
1045 _playlist_selector->set_session (_session);
1046 nudge_clock.set_session (_session);
1047 _summary->set_session (_session);
1048 _group_tabs->set_session (_session);
1049 _route_groups->set_session (_session);
1050 _regions->set_session (_session);
1051 _snapshots->set_session (_session);
1052 _routes->set_session (_session);
1053 _locations->set_session (_session);
1055 if (rhythm_ferret) {
1056 rhythm_ferret->set_session (_session);
1059 if (analysis_window) {
1060 analysis_window->set_session (_session);
1064 sfbrowser->set_session (_session);
1067 compute_fixed_ruler_scale ();
1069 /* there are never any selected regions at startup */
1071 sensitize_the_right_region_actions (false);
1073 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1074 set_state (*node, Stateful::loading_state_version);
1076 /* catch up with the playhead */
1078 _session->request_locate (playhead_cursor->current_frame);
1082 /* These signals can all be emitted by a non-GUI thread. Therefore the
1083 handlers for them must not attempt to directly interact with the GUI,
1084 but use Gtkmm2ext::UI::instance()->call_slot();
1087 _session->TransportStateChange.connect (_session_connections, boost::bind (&Editor::map_transport_state, this), gui_context());
1088 _session->PositionChanged.connect (_session_connections, ui_bind (&Editor::map_position_change, this, _1), gui_context());
1089 _session->RouteAdded.connect (_session_connections, ui_bind (&Editor::handle_new_route, this, _1), gui_context());
1090 _session->DurationChanged.connect (_session_connections, boost::bind (&Editor::handle_new_duration, this), gui_context());
1091 _session->DirtyChanged.connect (_session_connections, boost::bind (&Editor::update_title, this), gui_context());
1092 _session->TimecodeOffsetChanged.connect (_session_connections, boost::bind (&Editor::update_just_timecode, this), gui_context());
1093 _session->tempo_map().StateChanged.connect (_session_connections, ui_bind (&Editor::tempo_map_changed, this, _1), gui_context());
1094 _session->Located.connect (_session_connections, boost::bind (&Editor::located, this), gui_context());
1095 _session->config.ParameterChanged.connect (_session_connections, ui_bind (&Editor::parameter_changed, this, _1), gui_context());
1096 _session->StateSaved.connect (_session_connections, ui_bind (&Editor::session_state_saved, this, _1), gui_context());
1097 _session->locations()->added.connect (_session_connections, ui_bind (&Editor::add_new_location, this, _1), gui_context());
1098 _session->locations()->removed.connect (_session_connections, ui_bind (&Editor::location_gone, this, _1), gui_context());
1099 _session->locations()->changed.connect (_session_connections, boost::bind (&Editor::refresh_location_display, this), gui_context());
1100 _session->locations()->StateChanged.connect (_session_connections, ui_bind (&Editor::refresh_location_display_s, this, _1), gui_context());
1101 _session->locations()->end_location()->changed.connect (_session_connections, ui_bind (&Editor::end_location_changed, this, _1), gui_context());
1102 _session->history().Changed.connect (_session_connections, boost::bind (&Editor::history_changed, this), gui_context());
1104 if (Profile->get_sae()) {
1109 nframes_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
1110 nudge_clock.set_mode(AudioClock::BBT);
1111 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1114 nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
1117 playhead_cursor->canvas_item.show ();
1119 Location* loc = _session->locations()->auto_loop_location();
1121 loc = new Location (0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1122 if (loc->start() == loc->end()) {
1123 loc->set_end (loc->start() + 1);
1125 _session->locations()->add (loc, false);
1126 _session->set_auto_loop_location (loc);
1129 loc->set_name (_("Loop"));
1132 loc = _session->locations()->auto_punch_location();
1134 loc = new Location (0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1135 if (loc->start() == loc->end()) {
1136 loc->set_end (loc->start() + 1);
1138 _session->locations()->add (loc, false);
1139 _session->set_auto_punch_location (loc);
1142 loc->set_name (_("Punch"));
1145 boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
1146 Config->map_parameters (pc);
1147 _session->config.map_parameters (pc);
1149 refresh_location_display ();
1150 handle_new_duration ();
1152 restore_ruler_visibility ();
1153 //tempo_map_changed (Change (0));
1154 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1156 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1157 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1162 switch (_snap_type) {
1163 case SnapToRegionStart:
1164 case SnapToRegionEnd:
1165 case SnapToRegionSync:
1166 case SnapToRegionBoundary:
1167 build_region_boundary_cache ();
1174 /* register for undo history */
1175 _session->register_with_memento_command_factory(_id, this);
1181 Editor::build_cursors ()
1183 using namespace Gdk;
1185 Gdk::Color mbg ("#000000" ); /* Black */
1186 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1189 RefPtr<Bitmap> source, mask;
1190 source = Bitmap::create (mag_bits, mag_width, mag_height);
1191 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1192 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1195 Gdk::Color fbg ("#ffffff" );
1196 Gdk::Color ffg ("#000000" );
1199 RefPtr<Bitmap> source, mask;
1201 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1202 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1203 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1207 RefPtr<Bitmap> source, mask;
1208 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1209 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1210 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1214 RefPtr<Bitmap> bits;
1215 char pix[4] = { 0, 0, 0, 0 };
1216 bits = Bitmap::create (pix, 2, 2);
1218 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1222 RefPtr<Bitmap> bits;
1223 char pix[4] = { 0, 0, 0, 0 };
1224 bits = Bitmap::create (pix, 2, 2);
1226 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1230 grabber_cursor = new Gdk::Cursor (HAND2);
1233 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1234 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1237 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1238 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1239 selector_cursor = new Gdk::Cursor (XTERM);
1240 time_fx_cursor = new Gdk::Cursor (SIZING);
1241 wait_cursor = new Gdk::Cursor (WATCH);
1242 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1243 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1244 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1245 midi_resize_cursor = new Gdk::Cursor (SIZING);
1246 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1249 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1251 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1253 using namespace Menu_Helpers;
1254 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1257 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1261 MenuList& items (fade_context_menu.items());
1265 switch (item_type) {
1267 case FadeInHandleItem:
1268 if (arv->audio_region()->fade_in_active()) {
1269 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), false)));
1271 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), true)));
1274 items.push_back (SeparatorElem());
1276 if (Profile->get_sae()) {
1277 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1278 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1280 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1281 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1282 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1283 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1284 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1290 case FadeOutHandleItem:
1291 if (arv->audio_region()->fade_out_active()) {
1292 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), false)));
1294 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), true)));
1297 items.push_back (SeparatorElem());
1299 if (Profile->get_sae()) {
1300 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1301 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1303 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1304 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1305 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1306 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1307 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1313 fatal << _("programming error: ")
1314 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1319 fade_context_menu.popup (button, time);
1323 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1325 using namespace Menu_Helpers;
1326 Menu* (Editor::*build_menu_function)(nframes64_t);
1329 switch (item_type) {
1331 case RegionViewName:
1332 case RegionViewNameHighlight:
1333 if (with_selection) {
1334 build_menu_function = &Editor::build_track_selection_context_menu;
1336 build_menu_function = &Editor::build_track_region_context_menu;
1341 if (with_selection) {
1342 build_menu_function = &Editor::build_track_selection_context_menu;
1344 build_menu_function = &Editor::build_track_context_menu;
1348 case CrossfadeViewItem:
1349 build_menu_function = &Editor::build_track_crossfade_context_menu;
1353 if (clicked_routeview->get_diskstream()) {
1354 build_menu_function = &Editor::build_track_context_menu;
1356 build_menu_function = &Editor::build_track_bus_context_menu;
1361 /* probably shouldn't happen but if it does, we don't care */
1365 menu = (this->*build_menu_function)(frame);
1366 menu->set_name ("ArdourContextMenu");
1368 /* now handle specific situations */
1370 switch (item_type) {
1372 case RegionViewName:
1373 case RegionViewNameHighlight:
1374 if (!with_selection) {
1375 if (region_edit_menu_split_item) {
1376 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1377 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1379 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1383 if (region_edit_menu_split_multichannel_item) {
1384 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1385 // GTK2FIX find the action, change its sensitivity
1386 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1388 // GTK2FIX see above
1389 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1398 case CrossfadeViewItem:
1405 /* probably shouldn't happen but if it does, we don't care */
1409 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1411 /* Bounce to disk */
1413 using namespace Menu_Helpers;
1414 MenuList& edit_items = menu->items();
1416 edit_items.push_back (SeparatorElem());
1418 switch (clicked_routeview->audio_track()->freeze_state()) {
1419 case AudioTrack::NoFreeze:
1420 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1423 case AudioTrack::Frozen:
1424 edit_items.push_back (MenuElem (_("Unfreeze"), sigc::mem_fun(*this, &Editor::unfreeze_route)));
1427 case AudioTrack::UnFrozen:
1428 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1434 if (item_type == StreamItem && clicked_routeview) {
1435 clicked_routeview->build_underlay_menu(menu);
1438 menu->popup (button, time);
1442 Editor::build_track_context_menu (nframes64_t)
1444 using namespace Menu_Helpers;
1446 MenuList& edit_items = track_context_menu.items();
1449 add_dstream_context_items (edit_items);
1450 return &track_context_menu;
1454 Editor::build_track_bus_context_menu (nframes64_t)
1456 using namespace Menu_Helpers;
1458 MenuList& edit_items = track_context_menu.items();
1461 add_bus_context_items (edit_items);
1462 return &track_context_menu;
1466 Editor::build_track_region_context_menu (nframes64_t frame)
1468 using namespace Menu_Helpers;
1469 MenuList& edit_items = track_region_context_menu.items();
1472 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1475 boost::shared_ptr<Diskstream> ds;
1476 boost::shared_ptr<Playlist> pl;
1478 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1479 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1481 if (selection->regions.size() > 1) {
1482 // there's already a multiple selection: just add a
1483 // single region context menu that will act on all
1485 boost::shared_ptr<Region> dummy_region; // = NULL
1486 add_region_context_items (rtv->view(), dummy_region, edit_items);
1488 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1489 add_region_context_items (rtv->view(), (*i), edit_items);
1497 add_dstream_context_items (edit_items);
1499 return &track_region_context_menu;
1503 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1505 using namespace Menu_Helpers;
1506 MenuList& edit_items = track_crossfade_context_menu.items();
1507 edit_items.clear ();
1509 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1512 boost::shared_ptr<Diskstream> ds;
1513 boost::shared_ptr<Playlist> pl;
1514 boost::shared_ptr<AudioPlaylist> apl;
1516 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1518 Playlist::RegionList* regions = pl->regions_at (frame);
1519 AudioPlaylist::Crossfades xfades;
1521 apl->crossfades_at (frame, xfades);
1523 bool many = xfades.size() > 1;
1525 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1526 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1529 if (selection->regions.size() > 1) {
1530 // there's already a multiple selection: just add a
1531 // single region context menu that will act on all
1533 boost::shared_ptr<Region> dummy_region; // = NULL
1534 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1536 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1537 add_region_context_items (atv->audio_view(), (*i), edit_items);
1544 add_dstream_context_items (edit_items);
1546 return &track_crossfade_context_menu;
1550 Editor::analyze_region_selection()
1552 if (analysis_window == 0) {
1553 analysis_window = new AnalysisWindow();
1556 analysis_window->set_session(_session);
1558 analysis_window->show_all();
1561 analysis_window->set_regionmode();
1562 analysis_window->analyze();
1564 analysis_window->present();
1568 Editor::analyze_range_selection()
1570 if (analysis_window == 0) {
1571 analysis_window = new AnalysisWindow();
1574 analysis_window->set_session(_session);
1576 analysis_window->show_all();
1579 analysis_window->set_rangemode();
1580 analysis_window->analyze();
1582 analysis_window->present();
1586 Editor::build_track_selection_context_menu (nframes64_t)
1588 using namespace Menu_Helpers;
1589 MenuList& edit_items = track_selection_context_menu.items();
1590 edit_items.clear ();
1592 add_selection_context_items (edit_items);
1593 // edit_items.push_back (SeparatorElem());
1594 // add_dstream_context_items (edit_items);
1596 return &track_selection_context_menu;
1599 /** Add context menu items relevant to crossfades.
1600 * @param edit_items List to add the items to.
1603 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1605 using namespace Menu_Helpers;
1606 Menu *xfade_menu = manage (new Menu);
1607 MenuList& items = xfade_menu->items();
1608 xfade_menu->set_name ("ArdourContextMenu");
1611 if (xfade->active()) {
1617 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1618 items.push_back (MenuElem (_("Edit"), sigc::bind (sigc::mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1620 if (xfade->can_follow_overlap()) {
1622 if (xfade->following_overlap()) {
1623 str = _("Convert to short");
1625 str = _("Convert to full");
1628 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1632 str = xfade->out()->name();
1634 str += xfade->in()->name();
1636 str = _("Crossfade");
1639 edit_items.push_back (MenuElem (str, *xfade_menu));
1640 edit_items.push_back (SeparatorElem());
1644 Editor::xfade_edit_left_region ()
1646 if (clicked_crossfadeview) {
1647 clicked_crossfadeview->left_view.show_region_editor ();
1652 Editor::xfade_edit_right_region ()
1654 if (clicked_crossfadeview) {
1655 clicked_crossfadeview->right_view.show_region_editor ();
1660 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1662 using namespace Menu_Helpers;
1663 Gtk::MenuItem* foo_item;
1664 Menu *region_menu = manage (new Menu);
1665 MenuList& items = region_menu->items();
1666 region_menu->set_name ("ArdourContextMenu");
1668 boost::shared_ptr<AudioRegion> ar;
1669 boost::shared_ptr<MidiRegion> mr;
1672 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1673 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1675 /* when this particular menu pops up, make the relevant region
1679 region_menu->signal_map_event().connect (
1680 sigc::bind (sigc::mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1682 items.push_back (MenuElem (_("Rename"), sigc::mem_fun(*this, &Editor::rename_region)));
1683 if (mr && internal_editing()) {
1684 items.push_back (MenuElem (_("List editor..."), sigc::mem_fun(*this, &Editor::show_midi_list_editor)));
1686 items.push_back (MenuElem (_("Region editor"), sigc::mem_fun(*this, &Editor::edit_region)));
1690 items.push_back (MenuElem (_("Raise to top layer"), sigc::mem_fun(*this, &Editor::raise_region_to_top)));
1691 items.push_back (MenuElem (_("Lower to bottom layer"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom)));
1692 items.push_back (SeparatorElem());
1693 items.push_back (MenuElem (_("Define sync point"), sigc::mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1694 if (_edit_point == EditAtMouse) {
1695 items.back ().set_sensitive (false);
1697 items.push_back (MenuElem (_("Remove sync point"), sigc::mem_fun(*this, &Editor::remove_region_sync)));
1698 items.push_back (SeparatorElem());
1700 items.push_back (MenuElem (_("Audition"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1701 items.push_back (MenuElem (_("Export"), sigc::mem_fun(*this, &Editor::export_region)));
1702 items.push_back (MenuElem (_("Bounce"), sigc::mem_fun(*this, &Editor::bounce_region_selection)));
1705 items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_region_selection)));
1708 items.push_back (SeparatorElem());
1710 sigc::connection fooc;
1711 boost::shared_ptr<Region> region_to_check;
1714 region_to_check = region;
1716 region_to_check = selection->regions.front()->region();
1719 items.push_back (CheckMenuElem (_("Lock")));
1720 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1721 if (region_to_check->locked()) {
1722 region_lock_item->set_active();
1724 region_lock_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_lock));
1726 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1727 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1729 switch (region_to_check->positional_lock_style()) {
1730 case Region::MusicTime:
1731 bbt_glue_item->set_active (true);
1734 bbt_glue_item->set_active (false);
1738 bbt_glue_item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1740 items.push_back (CheckMenuElem (_("Mute")));
1741 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1742 fooc = region_mute_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_mute));
1743 if (region_to_check->muted()) {
1745 region_mute_item->set_active();
1749 if (!Profile->get_sae()) {
1750 items.push_back (CheckMenuElem (_("Opaque")));
1751 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1752 fooc = region_opaque_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_opaque));
1753 if (region_to_check->opaque()) {
1755 region_opaque_item->set_active();
1760 items.push_back (CheckMenuElem (_("Original position"), sigc::mem_fun(*this, &Editor::naturalize)));
1761 if (region_to_check->at_natural_position()) {
1762 items.back().set_sensitive (false);
1765 items.push_back (SeparatorElem());
1769 RegionView* rv = sv->find_view (ar);
1770 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1772 if (!Profile->get_sae()) {
1773 items.push_back (MenuElem (_("Reset Envelope"), sigc::mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1775 items.push_back (CheckMenuElem (_("Envelope Visible")));
1776 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1777 fooc = region_envelope_visible_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1778 if (arv->envelope_visible()) {
1780 region_envelope_visible_item->set_active (true);
1784 items.push_back (CheckMenuElem (_("Envelope Active")));
1785 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1786 fooc = region_envelope_active_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_active));
1788 if (ar->envelope_active()) {
1790 region_envelope_active_item->set_active (true);
1794 items.push_back (SeparatorElem());
1797 items.push_back (MenuElem (_("Normalize"), sigc::mem_fun(*this, &Editor::normalize_region)));
1798 if (ar->scale_amplitude() != 1) {
1799 items.push_back (MenuElem (_("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_scale_amplitude)));
1803 items.push_back (MenuElem (_("Quantize"), sigc::mem_fun(*this, &Editor::quantize_region)));
1804 items.push_back (SeparatorElem());
1807 items.push_back (MenuElem (_("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence)));
1808 items.push_back (MenuElem (_("Reverse"), sigc::mem_fun(*this, &Editor::reverse_region)));
1809 items.push_back (SeparatorElem());
1811 /* range related stuff */
1813 items.push_back (MenuElem (_("Add Single Range"), sigc::mem_fun (*this, &Editor::add_location_from_audio_region)));
1814 items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_locations_from_audio_region)));
1815 if (selection->regions.size() < 2) {
1816 items.back().set_sensitive (false);
1819 items.push_back (MenuElem (_("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region)));
1820 items.push_back (SeparatorElem());
1824 Menu *nudge_menu = manage (new Menu());
1825 MenuList& nudge_items = nudge_menu->items();
1826 nudge_menu->set_name ("ArdourContextMenu");
1828 nudge_items.push_back (MenuElem (_("Nudge fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_forward), false, false))));
1829 nudge_items.push_back (MenuElem (_("Nudge bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_backward), false, false))));
1830 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (sigc::mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1831 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (sigc::mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1833 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1834 items.push_back (SeparatorElem());
1836 Menu *trim_menu = manage (new Menu);
1837 MenuList& trim_items = trim_menu->items();
1838 trim_menu->set_name ("ArdourContextMenu");
1840 trim_items.push_back (MenuElem (_("Start to edit point"), sigc::mem_fun(*this, &Editor::trim_region_from_edit_point)));
1841 foo_item = &trim_items.back();
1842 if (_edit_point == EditAtMouse) {
1843 foo_item->set_sensitive (false);
1845 trim_items.push_back (MenuElem (_("Edit point to end"), sigc::mem_fun(*this, &Editor::trim_region_to_edit_point)));
1846 foo_item = &trim_items.back();
1847 if (_edit_point == EditAtMouse) {
1848 foo_item->set_sensitive (false);
1850 trim_items.push_back (MenuElem (_("Trim To Loop"), sigc::mem_fun(*this, &Editor::trim_region_to_loop)));
1851 trim_items.push_back (MenuElem (_("Trim To Punch"), sigc::mem_fun(*this, &Editor::trim_region_to_punch)));
1853 items.push_back (MenuElem (_("Trim"), *trim_menu));
1854 items.push_back (SeparatorElem());
1856 items.push_back (MenuElem (_("Split"), (sigc::mem_fun(*this, &Editor::split))));
1857 region_edit_menu_split_item = &items.back();
1859 if (_edit_point == EditAtMouse) {
1860 region_edit_menu_split_item->set_sensitive (false);
1863 items.push_back (MenuElem (_("Make mono regions"), (sigc::mem_fun(*this, &Editor::split_multichannel_region))));
1864 region_edit_menu_split_multichannel_item = &items.back();
1866 items.push_back (MenuElem (_("Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false))));
1867 items.push_back (MenuElem (_("Multi-Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), true))));
1868 items.push_back (MenuElem (_("Fill Track"), (sigc::mem_fun(*this, &Editor::region_fill_track))));
1869 items.push_back (SeparatorElem());
1870 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::remove_selected_regions)));
1872 /* OK, stick the region submenu at the top of the list, and then add
1876 /* we have to hack up the region name because "_" has a special
1877 meaning for menu titles.
1880 string::size_type pos = 0;
1881 string menu_item_name = (region) ? region->name() : _("Selected regions");
1883 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1884 menu_item_name.replace (pos, 1, "__");
1888 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1889 edit_items.push_back (SeparatorElem());
1892 /** Add context menu items relevant to selection ranges.
1893 * @param edit_items List to add the items to.
1896 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1898 using namespace Menu_Helpers;
1900 edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
1901 edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
1903 edit_items.push_back (SeparatorElem());
1904 edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
1906 if (!selection->regions.empty()) {
1907 edit_items.push_back (SeparatorElem());
1908 edit_items.push_back (MenuElem (_("Extend Range to End of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1909 edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1912 edit_items.push_back (SeparatorElem());
1913 edit_items.push_back (MenuElem (_("Silence Range"), sigc::mem_fun(*this, &Editor::separate_region_from_selection)));
1914 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
1916 edit_items.push_back (SeparatorElem());
1917 edit_items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1919 edit_items.push_back (SeparatorElem());
1920 edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false)));
1921 edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
1923 edit_items.push_back (SeparatorElem());
1924 edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
1926 edit_items.push_back (SeparatorElem());
1927 edit_items.push_back (MenuElem (_("Crop Region to Range"), sigc::mem_fun(*this, &Editor::crop_region_to_selection)));
1928 edit_items.push_back (MenuElem (_("Fill Range with Region"), sigc::mem_fun(*this, &Editor::region_fill_selection)));
1929 edit_items.push_back (MenuElem (_("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false)));
1931 edit_items.push_back (SeparatorElem());
1932 edit_items.push_back (MenuElem (_("Consolidate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1933 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1934 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1935 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1936 edit_items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_range)));
1941 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1943 using namespace Menu_Helpers;
1947 Menu *play_menu = manage (new Menu);
1948 MenuList& play_items = play_menu->items();
1949 play_menu->set_name ("ArdourContextMenu");
1951 play_items.push_back (MenuElem (_("Play from edit point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
1952 play_items.push_back (MenuElem (_("Play from start"), sigc::mem_fun(*this, &Editor::play_from_start)));
1953 play_items.push_back (MenuElem (_("Play region"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1954 play_items.push_back (SeparatorElem());
1955 play_items.push_back (MenuElem (_("Loop Region"), sigc::mem_fun(*this, &Editor::loop_selected_region)));
1957 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1961 Menu *select_menu = manage (new Menu);
1962 MenuList& select_items = select_menu->items();
1963 select_menu->set_name ("ArdourContextMenu");
1965 select_items.push_back (MenuElem (_("Select All in track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1966 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
1967 select_items.push_back (MenuElem (_("Invert selection in track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
1968 select_items.push_back (MenuElem (_("Invert selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
1969 select_items.push_back (SeparatorElem());
1970 select_items.push_back (MenuElem (_("Set range to loop range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop)));
1971 select_items.push_back (MenuElem (_("Set range to punch range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch)));
1972 select_items.push_back (SeparatorElem());
1973 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1974 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1975 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1976 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1977 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
1978 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
1979 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
1981 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1985 Menu *cutnpaste_menu = manage (new Menu);
1986 MenuList& cutnpaste_items = cutnpaste_menu->items();
1987 cutnpaste_menu->set_name ("ArdourContextMenu");
1989 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
1990 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
1991 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
1993 cutnpaste_items.push_back (SeparatorElem());
1995 cutnpaste_items.push_back (MenuElem (_("Align"), sigc::bind (sigc::mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
1996 cutnpaste_items.push_back (MenuElem (_("Align Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
1998 cutnpaste_items.push_back (SeparatorElem());
2000 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2002 /* Adding new material */
2004 edit_items.push_back (SeparatorElem());
2005 edit_items.push_back (MenuElem (_("Insert Selected Region"), sigc::bind (sigc::mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2006 edit_items.push_back (MenuElem (_("Insert Existing Media"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2010 Menu *nudge_menu = manage (new Menu());
2011 MenuList& nudge_items = nudge_menu->items();
2012 nudge_menu->set_name ("ArdourContextMenu");
2014 edit_items.push_back (SeparatorElem());
2015 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2016 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2017 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2018 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2020 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2024 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2026 using namespace Menu_Helpers;
2030 Menu *play_menu = manage (new Menu);
2031 MenuList& play_items = play_menu->items();
2032 play_menu->set_name ("ArdourContextMenu");
2034 play_items.push_back (MenuElem (_("Play from edit point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
2035 play_items.push_back (MenuElem (_("Play from start"), sigc::mem_fun(*this, &Editor::play_from_start)));
2036 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2040 Menu *select_menu = manage (new Menu);
2041 MenuList& select_items = select_menu->items();
2042 select_menu->set_name ("ArdourContextMenu");
2044 select_items.push_back (MenuElem (_("Select All in track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2045 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
2046 select_items.push_back (MenuElem (_("Invert selection in track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
2047 select_items.push_back (MenuElem (_("Invert selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
2048 select_items.push_back (SeparatorElem());
2049 select_items.push_back (MenuElem (_("Select all after edit point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2050 select_items.push_back (MenuElem (_("Select all before edit point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2051 select_items.push_back (MenuElem (_("Select all after playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2052 select_items.push_back (MenuElem (_("Select all before playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2054 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2058 Menu *cutnpaste_menu = manage (new Menu);
2059 MenuList& cutnpaste_items = cutnpaste_menu->items();
2060 cutnpaste_menu->set_name ("ArdourContextMenu");
2062 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2063 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2064 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2066 Menu *nudge_menu = manage (new Menu());
2067 MenuList& nudge_items = nudge_menu->items();
2068 nudge_menu->set_name ("ArdourContextMenu");
2070 edit_items.push_back (SeparatorElem());
2071 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2072 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2073 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2074 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2076 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2080 Editor::snap_type() const
2086 Editor::snap_mode() const
2092 Editor::set_snap_to (SnapType st)
2094 unsigned int snap_ind = (unsigned int)st;
2098 if (snap_ind > snap_type_strings.size() - 1) {
2100 _snap_type = (SnapType)snap_ind;
2103 string str = snap_type_strings[snap_ind];
2105 if (str != snap_type_selector.get_active_text()) {
2106 snap_type_selector.set_active_text (str);
2111 switch (_snap_type) {
2112 case SnapToAThirtysecondBeat:
2113 case SnapToASixteenthBeat:
2114 case SnapToAEighthBeat:
2115 case SnapToAQuarterBeat:
2116 case SnapToAThirdBeat:
2117 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2118 update_tempo_based_rulers ();
2121 case SnapToRegionStart:
2122 case SnapToRegionEnd:
2123 case SnapToRegionSync:
2124 case SnapToRegionBoundary:
2125 build_region_boundary_cache ();
2135 Editor::set_snap_mode (SnapMode mode)
2138 string str = snap_mode_strings[(int)mode];
2140 if (str != snap_mode_selector.get_active_text ()) {
2141 snap_mode_selector.set_active_text (str);
2147 Editor::set_edit_point_preference (EditPoint ep, bool force)
2149 bool changed = (_edit_point != ep);
2152 string str = edit_point_strings[(int)ep];
2154 if (str != edit_point_selector.get_active_text ()) {
2155 edit_point_selector.set_active_text (str);
2158 set_canvas_cursor ();
2160 if (!force && !changed) {
2164 const char* action=NULL;
2166 switch (_edit_point) {
2167 case EditAtPlayhead:
2168 action = "edit-at-playhead";
2170 case EditAtSelectedMarker:
2171 action = "edit-at-marker";
2174 action = "edit-at-mouse";
2178 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2180 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2184 bool in_track_canvas;
2186 if (!mouse_frame (foo, in_track_canvas)) {
2187 in_track_canvas = false;
2190 reset_canvas_action_sensitivity (in_track_canvas);
2196 Editor::set_state (const XMLNode& node, int /*version*/)
2198 const XMLProperty* prop;
2200 int x, y, xoff, yoff;
2203 if ((prop = node.property ("id")) != 0) {
2204 _id = prop->value ();
2207 g.base_width = default_width;
2208 g.base_height = default_height;
2214 if ((geometry = find_named_node (node, "geometry")) != 0) {
2218 if ((prop = geometry->property("x_size")) == 0) {
2219 prop = geometry->property ("x-size");
2222 g.base_width = atoi(prop->value());
2224 if ((prop = geometry->property("y_size")) == 0) {
2225 prop = geometry->property ("y-size");
2228 g.base_height = atoi(prop->value());
2231 if ((prop = geometry->property ("x_pos")) == 0) {
2232 prop = geometry->property ("x-pos");
2235 x = atoi (prop->value());
2238 if ((prop = geometry->property ("y_pos")) == 0) {
2239 prop = geometry->property ("y-pos");
2242 y = atoi (prop->value());
2245 if ((prop = geometry->property ("x_off")) == 0) {
2246 prop = geometry->property ("x-off");
2249 xoff = atoi (prop->value());
2251 if ((prop = geometry->property ("y_off")) == 0) {
2252 prop = geometry->property ("y-off");
2255 yoff = atoi (prop->value());
2259 set_default_size (g.base_width, g.base_height);
2262 if (_session && (prop = node.property ("playhead"))) {
2263 nframes64_t pos = atol (prop->value().c_str());
2264 playhead_cursor->set_position (pos);
2266 playhead_cursor->set_position (0);
2269 if ((prop = node.property ("mixer-width"))) {
2270 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2273 if ((prop = node.property ("zoom-focus"))) {
2274 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2277 if ((prop = node.property ("zoom"))) {
2278 reset_zoom (PBD::atof (prop->value()));
2281 if ((prop = node.property ("snap-to"))) {
2282 set_snap_to ((SnapType) atoi (prop->value()));
2285 if ((prop = node.property ("snap-mode"))) {
2286 set_snap_mode ((SnapMode) atoi (prop->value()));
2289 if ((prop = node.property ("mouse-mode"))) {
2290 MouseMode m = str2mousemode(prop->value());
2291 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2292 set_mouse_mode (m, true);
2294 mouse_mode = MouseGain; /* lie, to force the mode switch */
2295 set_mouse_mode (MouseObject, true);
2298 if ((prop = node.property ("left-frame")) != 0){
2300 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
2301 reset_x_origin (pos);
2302 /* this hack prevents the initial call to update_current_screen() from doing re-centering on the playhead */
2303 last_update_frame = pos;
2307 if ((prop = node.property ("internal-edit"))) {
2308 bool yn = string_is_affirmative (prop->value());
2309 RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit"));
2311 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2312 tact->set_active (!yn);
2313 tact->set_active (yn);
2317 if ((prop = node.property ("edit-point"))) {
2318 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2321 if ((prop = node.property ("show-waveforms-recording"))) {
2322 bool yn = string_is_affirmative (prop->value());
2323 _show_waveforms_recording = !yn;
2324 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2326 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2327 /* do it twice to force the change */
2328 tact->set_active (!yn);
2329 tact->set_active (yn);
2333 if ((prop = node.property ("show-measures"))) {
2334 bool yn = string_is_affirmative (prop->value());
2335 _show_measures = !yn;
2336 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2338 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2339 /* do it twice to force the change */
2340 tact->set_active (!yn);
2341 tact->set_active (yn);
2345 if ((prop = node.property ("follow-playhead"))) {
2346 bool yn = string_is_affirmative (prop->value());
2347 set_follow_playhead (yn);
2348 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2350 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2351 if (tact->get_active() != yn) {
2352 tact->set_active (yn);
2357 if ((prop = node.property ("region-list-sort-type"))) {
2358 _regions->reset_sort_type (str2regionlistsorttype(prop->value()), true);
2361 if ((prop = node.property ("xfades-visible"))) {
2362 bool yn = string_is_affirmative (prop->value());
2363 _xfade_visibility = !yn;
2364 // set_xfade_visibility (yn);
2367 if ((prop = node.property ("show-editor-mixer"))) {
2369 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2372 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2373 bool yn = string_is_affirmative (prop->value());
2375 /* do it twice to force the change */
2377 tact->set_active (!yn);
2378 tact->set_active (yn);
2382 if ((prop = node.property ("show-editor-list"))) {
2384 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2388 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2389 bool yn = string_is_affirmative (prop->value());
2391 /* do it twice to force the change */
2393 tact->set_active (!yn);
2394 tact->set_active (yn);
2403 Editor::get_state ()
2405 XMLNode* node = new XMLNode ("Editor");
2408 _id.print (buf, sizeof (buf));
2409 node->add_property ("id", buf);
2411 if (is_realized()) {
2412 Glib::RefPtr<Gdk::Window> win = get_window();
2414 int x, y, xoff, yoff, width, height;
2415 win->get_root_origin(x, y);
2416 win->get_position(xoff, yoff);
2417 win->get_size(width, height);
2419 XMLNode* geometry = new XMLNode ("geometry");
2421 snprintf(buf, sizeof(buf), "%d", width);
2422 geometry->add_property("x-size", string(buf));
2423 snprintf(buf, sizeof(buf), "%d", height);
2424 geometry->add_property("y-size", string(buf));
2425 snprintf(buf, sizeof(buf), "%d", x);
2426 geometry->add_property("x-pos", string(buf));
2427 snprintf(buf, sizeof(buf), "%d", y);
2428 geometry->add_property("y-pos", string(buf));
2429 snprintf(buf, sizeof(buf), "%d", xoff);
2430 geometry->add_property("x-off", string(buf));
2431 snprintf(buf, sizeof(buf), "%d", yoff);
2432 geometry->add_property("y-off", string(buf));
2433 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2434 geometry->add_property("edit_pane_pos", string(buf));
2436 node->add_child_nocopy (*geometry);
2439 maybe_add_mixer_strip_width (*node);
2441 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2442 node->add_property ("zoom-focus", buf);
2443 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2444 node->add_property ("zoom", buf);
2445 snprintf (buf, sizeof(buf), "%d", (int) _snap_type);
2446 node->add_property ("snap-to", buf);
2447 snprintf (buf, sizeof(buf), "%d", (int) _snap_mode);
2448 node->add_property ("snap-mode", buf);
2450 node->add_property ("edit-point", enum_2_string (_edit_point));
2452 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2453 node->add_property ("playhead", buf);
2454 snprintf (buf, sizeof (buf), "%" PRIi64, leftmost_frame);
2455 node->add_property ("left-frame", buf);
2457 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2458 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2459 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2460 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2461 node->add_property ("region-list-sort-type", enum2str (_regions->sort_type ()));
2462 node->add_property ("mouse-mode", enum2str(mouse_mode));
2463 node->add_property ("internal-edit", _internal_editing ? "yes" : "no");
2465 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2467 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2468 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2471 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2473 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2474 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2482 /** @param y y offset from the top of all trackviews.
2483 * @return pair: TimeAxisView that y is over, layer index.
2484 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2485 * in stacked region display mode, otherwise 0.
2487 std::pair<TimeAxisView *, layer_t>
2488 Editor::trackview_by_y_position (double y)
2490 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2492 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2498 return std::make_pair ( (TimeAxisView *) 0, 0);
2501 /** Snap a position to the grid, if appropriate, taking into account current
2502 * grid settings and also the state of any snap modifier keys that may be pressed.
2503 * @param start Position to snap.
2504 * @param event Event to get current key modifier information from, or 0.
2507 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2509 if (!_session || !event) {
2513 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2514 if (_snap_mode == SnapOff) {
2515 snap_to_internal (start, direction, for_mark);
2518 if (_snap_mode != SnapOff) {
2519 snap_to_internal (start, direction, for_mark);
2525 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2527 if (!_session || _snap_mode == SnapOff) {
2531 snap_to_internal (start, direction, for_mark);
2535 Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
2537 const nframes64_t one_timecode_second = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
2538 nframes64_t one_timecode_minute = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
2540 switch (_snap_type) {
2541 case SnapToTimecodeFrame:
2542 if (((direction == 0) && (fmod((double)start, (double)_session->frames_per_timecode_frame()) > (_session->frames_per_timecode_frame() / 2))) || (direction > 0)) {
2543 start = (nframes64_t) (ceil ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2545 start = (nframes64_t) (floor ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2549 case SnapToTimecodeSeconds:
2550 if (_session->timecode_offset_negative())
2552 start += _session->timecode_offset ();
2554 start -= _session->timecode_offset ();
2556 if (((direction == 0) && (start % one_timecode_second > one_timecode_second / 2)) || direction > 0) {
2557 start = (nframes64_t) ceil ((double) start / one_timecode_second) * one_timecode_second;
2559 start = (nframes64_t) floor ((double) start / one_timecode_second) * one_timecode_second;
2562 if (_session->timecode_offset_negative())
2564 start -= _session->timecode_offset ();
2566 start += _session->timecode_offset ();
2570 case SnapToTimecodeMinutes:
2571 if (_session->timecode_offset_negative())
2573 start += _session->timecode_offset ();
2575 start -= _session->timecode_offset ();
2577 if (((direction == 0) && (start % one_timecode_minute > one_timecode_minute / 2)) || direction > 0) {
2578 start = (nframes64_t) ceil ((double) start / one_timecode_minute) * one_timecode_minute;
2580 start = (nframes64_t) floor ((double) start / one_timecode_minute) * one_timecode_minute;
2582 if (_session->timecode_offset_negative())
2584 start -= _session->timecode_offset ();
2586 start += _session->timecode_offset ();
2590 fatal << "Editor::smpte_snap_to_internal() called with non-timecode snap type!" << endmsg;
2596 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2598 const nframes64_t one_second = _session->frame_rate();
2599 const nframes64_t one_minute = _session->frame_rate() * 60;
2600 nframes64_t presnap = start;
2604 switch (_snap_type) {
2605 case SnapToTimecodeFrame:
2606 case SnapToTimecodeSeconds:
2607 case SnapToTimecodeMinutes:
2608 return timecode_snap_to_internal (start, direction, for_mark);
2611 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2612 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2614 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2619 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2620 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2622 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2627 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2628 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2630 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2635 start = _session->tempo_map().round_to_bar (start, direction);
2639 start = _session->tempo_map().round_to_beat (start, direction);
2642 case SnapToAThirtysecondBeat:
2643 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2646 case SnapToASixteenthBeat:
2647 start = _session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2650 case SnapToAEighthBeat:
2651 start = _session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2654 case SnapToAQuarterBeat:
2655 start = _session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2658 case SnapToAThirdBeat:
2659 start = _session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2667 _session->locations()->marks_either_side (start, before, after);
2669 if (before == max_frames) {
2671 } else if (after == max_frames) {
2673 } else if (before != max_frames && after != max_frames) {
2674 /* have before and after */
2675 if ((start - before) < (after - start)) {
2684 case SnapToRegionStart:
2685 case SnapToRegionEnd:
2686 case SnapToRegionSync:
2687 case SnapToRegionBoundary:
2688 if (!region_boundary_cache.empty()) {
2690 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2691 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2693 if (direction > 0) {
2694 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2696 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2699 if (next != region_boundary_cache.begin ()) {
2704 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2705 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2707 if (start > (p + n) / 2) {
2716 switch (_snap_mode) {
2722 if (presnap > start) {
2723 if (presnap > (start + unit_to_frame(snap_threshold))) {
2727 } else if (presnap < start) {
2728 if (presnap < (start - unit_to_frame(snap_threshold))) {
2734 /* handled at entry */
2742 Editor::setup_toolbar ()
2746 /* Mode Buttons (tool selection) */
2748 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2749 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2750 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2751 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2752 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2753 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2754 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2756 HBox* mode_box = manage(new HBox);
2757 mode_box->set_border_width (2);
2758 mode_box->set_spacing(4);
2759 mouse_mode_button_box.set_spacing(1);
2760 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2761 if (!Profile->get_sae()) {
2762 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2764 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2765 if (!Profile->get_sae()) {
2766 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2768 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2769 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2770 mouse_mode_button_box.pack_start(internal_edit_button, true, true);
2771 mouse_mode_button_box.set_homogeneous(true);
2773 vector<string> edit_mode_strings;
2774 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2775 if (!Profile->get_sae()) {
2776 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2778 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2780 edit_mode_selector.set_name ("EditModeSelector");
2781 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2782 edit_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_mode_selection_done));
2784 mode_box->pack_start(edit_mode_selector);
2785 mode_box->pack_start(mouse_mode_button_box);
2787 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2788 mouse_mode_tearoff->set_name ("MouseModeBase");
2789 mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &mouse_mode_tearoff->tearoff_window()), false);
2791 if (Profile->get_sae()) {
2792 mouse_mode_tearoff->set_can_be_torn_off (false);
2795 mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2796 &mouse_mode_tearoff->tearoff_window()));
2797 mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2798 &mouse_mode_tearoff->tearoff_window(), 1));
2799 mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2800 &mouse_mode_tearoff->tearoff_window()));
2801 mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2802 &mouse_mode_tearoff->tearoff_window(), 1));
2804 mouse_move_button.set_mode (false);
2805 mouse_select_button.set_mode (false);
2806 mouse_gain_button.set_mode (false);
2807 mouse_zoom_button.set_mode (false);
2808 mouse_timefx_button.set_mode (false);
2809 mouse_audition_button.set_mode (false);
2811 mouse_move_button.set_name ("MouseModeButton");
2812 mouse_select_button.set_name ("MouseModeButton");
2813 mouse_gain_button.set_name ("MouseModeButton");
2814 mouse_zoom_button.set_name ("MouseModeButton");
2815 mouse_timefx_button.set_name ("MouseModeButton");
2816 mouse_audition_button.set_name ("MouseModeButton");
2818 internal_edit_button.set_name ("MouseModeButton");
2820 mouse_move_button.unset_flags (CAN_FOCUS);
2821 mouse_select_button.unset_flags (CAN_FOCUS);
2822 mouse_gain_button.unset_flags (CAN_FOCUS);
2823 mouse_zoom_button.unset_flags (CAN_FOCUS);
2824 mouse_timefx_button.unset_flags (CAN_FOCUS);
2825 mouse_audition_button.unset_flags (CAN_FOCUS);
2826 internal_edit_button.unset_flags (CAN_FOCUS);
2830 zoom_box.set_spacing (1);
2831 zoom_box.set_border_width (0);
2833 zoom_in_button.set_name ("EditorTimeButton");
2834 zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_BUTTON))));
2835 zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
2836 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2838 zoom_out_button.set_name ("EditorTimeButton");
2839 zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_BUTTON))));
2840 zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
2841 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2843 zoom_out_full_button.set_name ("EditorTimeButton");
2844 zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_BUTTON))));
2845 zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
2846 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2848 zoom_focus_selector.set_name ("ZoomFocusSelector");
2849 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2850 zoom_focus_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done));
2851 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2853 zoom_box.pack_start (zoom_out_button, false, false);
2854 zoom_box.pack_start (zoom_in_button, false, false);
2855 zoom_box.pack_start (zoom_out_full_button, false, false);
2857 /* Track zoom buttons */
2858 tav_expand_button.set_name ("TrackHeightButton");
2859 tav_expand_button.set_size_request(-1,20);
2860 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2861 tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
2862 ARDOUR_UI::instance()->tooltips().set_tip (tav_expand_button, _("Expand Tracks"));
2864 tav_shrink_button.set_name ("TrackHeightButton");
2865 tav_shrink_button.set_size_request(-1,20);
2866 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2867 tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
2868 ARDOUR_UI::instance()->tooltips().set_tip (tav_shrink_button, _("Shrink Tracks"));
2870 track_zoom_box.set_spacing (1);
2871 track_zoom_box.set_border_width (0);
2873 track_zoom_box.pack_start (tav_shrink_button, false, false);
2874 track_zoom_box.pack_start (tav_expand_button, false, false);
2876 HBox* zbc = manage (new HBox);
2877 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2878 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2879 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2880 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2882 snap_box.set_spacing (1);
2883 snap_box.set_border_width (2);
2885 snap_type_selector.set_name ("SnapTypeSelector");
2886 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2887 snap_type_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_type_selection_done));
2888 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2890 snap_mode_selector.set_name ("SnapModeSelector");
2891 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2892 snap_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_mode_selection_done));
2893 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2895 edit_point_selector.set_name ("EditPointSelector");
2896 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2897 edit_point_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_point_selection_done));
2898 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2900 snap_box.pack_start (snap_mode_selector, false, false);
2901 snap_box.pack_start (snap_type_selector, false, false);
2902 snap_box.pack_start (edit_point_selector, false, false);
2906 HBox *nudge_box = manage (new HBox);
2907 nudge_box->set_spacing(1);
2908 nudge_box->set_border_width (2);
2910 nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
2911 nudge_backward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_backward_release), false);
2913 nudge_box->pack_start (nudge_backward_button, false, false);
2914 nudge_box->pack_start (nudge_forward_button, false, false);
2915 nudge_box->pack_start (nudge_clock, false, false);
2918 /* Pack everything in... */
2920 HBox* hbox = manage (new HBox);
2921 hbox->set_spacing(10);
2923 tools_tearoff = manage (new TearOff (*hbox));
2924 tools_tearoff->set_name ("MouseModeBase");
2925 tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &tools_tearoff->tearoff_window()), false);
2927 if (Profile->get_sae()) {
2928 tools_tearoff->set_can_be_torn_off (false);
2931 tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2932 &tools_tearoff->tearoff_window()));
2933 tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2934 &tools_tearoff->tearoff_window(), 0));
2935 tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2936 &tools_tearoff->tearoff_window()));
2937 tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2938 &tools_tearoff->tearoff_window(), 0));
2940 toolbar_hbox.set_spacing (10);
2941 toolbar_hbox.set_border_width (1);
2943 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2944 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2946 hbox->pack_start (snap_box, false, false);
2947 hbox->pack_start (*nudge_box, false, false);
2948 hbox->pack_start (panic_box, false, false);
2952 toolbar_base.set_name ("ToolBarBase");
2953 toolbar_base.add (toolbar_hbox);
2955 toolbar_frame.set_shadow_type (SHADOW_OUT);
2956 toolbar_frame.set_name ("BaseFrame");
2957 toolbar_frame.add (toolbar_base);
2961 Editor::midi_panic ()
2963 cerr << "MIDI panic\n";
2966 _session->midi_panic();
2971 Editor::setup_midi_toolbar ()
2975 /* Midi sound notes */
2976 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
2977 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
2978 ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes"));
2979 midi_sound_notes.unset_flags (CAN_FOCUS);
2983 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
2984 midi_panic_button.set_name("MidiPanicButton");
2985 ARDOUR_UI::instance()->tooltips().set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
2986 act->connect_proxy (midi_panic_button);
2988 panic_box.pack_start (midi_sound_notes , true, true);
2989 panic_box.pack_start (midi_panic_button, true, true);
2993 Editor::convert_drop_to_paths (
2994 vector<ustring>& paths,
2995 const RefPtr<Gdk::DragContext>& /*context*/,
2998 const SelectionData& data,
3002 if (_session == 0) {
3006 vector<ustring> uris = data.get_uris();
3010 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3011 are actually URI lists. So do it by hand.
3014 if (data.get_target() != "text/plain") {
3018 /* Parse the "uri-list" format that Nautilus provides,
3019 where each pathname is delimited by \r\n.
3021 THERE MAY BE NO NULL TERMINATING CHAR!!!
3024 ustring txt = data.get_text();
3028 p = (const char *) malloc (txt.length() + 1);
3029 txt.copy ((char *) p, txt.length(), 0);
3030 ((char*)p)[txt.length()] = '\0';
3036 while (g_ascii_isspace (*p))
3040 while (*q && (*q != '\n') && (*q != '\r')) {
3047 while (q > p && g_ascii_isspace (*q))
3052 uris.push_back (ustring (p, q - p + 1));
3056 p = strchr (p, '\n');
3068 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3070 if ((*i).substr (0,7) == "file://") {
3073 PBD::url_decode (p);
3075 // scan forward past three slashes
3077 ustring::size_type slashcnt = 0;
3078 ustring::size_type n = 0;
3079 ustring::iterator x = p.begin();
3081 while (slashcnt < 3 && x != p.end()) {
3084 } else if (slashcnt == 3) {
3091 if (slashcnt != 3 || x == p.end()) {
3092 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3096 paths.push_back (p.substr (n - 1));
3104 Editor::new_tempo_section ()
3110 Editor::map_transport_state ()
3112 ENSURE_GUI_THREAD (*this, &Editor::map_transport_state)
3114 if (_session->transport_stopped()) {
3115 have_pending_keyboard_selection = false;
3118 update_loop_range_view (true);
3123 Editor::State::State (PublicEditor const * e)
3125 selection = new Selection (e);
3128 Editor::State::~State ()
3134 Editor::begin_reversible_command (string name)
3137 before = &get_state();
3138 _session->begin_reversible_command (name);
3143 Editor::commit_reversible_command ()
3146 _session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3151 Editor::set_route_group_solo (Route& route, bool yn)
3153 RouteGroup *route_group;
3155 if ((route_group = route.route_group()) != 0) {
3156 route_group->apply (&Route::set_solo, yn, this);
3158 route.set_solo (yn, this);
3163 Editor::set_route_group_mute (Route& route, bool yn)
3165 RouteGroup *route_group = 0;
3167 if ((route_group == route.route_group()) != 0) {
3168 route_group->apply (&Route::set_mute, yn, this);
3170 route.set_mute (yn, this);
3175 Editor::history_changed ()
3179 if (undo_action && _session) {
3180 if (_session->undo_depth() == 0) {
3183 label = string_compose(_("Undo (%1)"), _session->next_undo());
3185 undo_action->property_label() = label;
3188 if (redo_action && _session) {
3189 if (_session->redo_depth() == 0) {
3192 label = string_compose(_("Redo (%1)"), _session->next_redo());
3194 redo_action->property_label() = label;
3199 Editor::duplicate_dialog (bool with_dialog)
3203 if (mouse_mode == MouseRange) {
3204 if (selection->time.length() == 0) {
3210 get_regions_for_action (rs);
3212 if (mouse_mode != MouseRange) {
3221 ArdourDialog win ("Duplicate");
3222 Label label (_("Number of Duplications:"));
3223 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3224 SpinButton spinner (adjustment, 0.0, 1);
3227 win.get_vbox()->set_spacing (12);
3228 win.get_vbox()->pack_start (hbox);
3229 hbox.set_border_width (6);
3230 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3232 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3233 place, visually. so do this by hand.
3236 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3237 spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3238 spinner.grab_focus();
3244 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3245 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3246 win.set_default_response (RESPONSE_ACCEPT);
3248 win.set_position (WIN_POS_MOUSE);
3250 spinner.grab_focus ();
3252 switch (win.run ()) {
3253 case RESPONSE_ACCEPT:
3259 times = adjustment.get_value();
3262 if (mouse_mode == MouseRange) {
3263 duplicate_selection (times);
3265 duplicate_some_regions (rs, times);
3270 Editor::show_verbose_canvas_cursor ()
3272 verbose_canvas_cursor->raise_to_top();
3273 verbose_canvas_cursor->show();
3274 verbose_cursor_visible = true;
3278 Editor::hide_verbose_canvas_cursor ()
3280 verbose_canvas_cursor->hide();
3281 verbose_cursor_visible = false;
3285 Editor::clamp_verbose_cursor_x (double x)
3290 x = min (_canvas_width - 200.0, x);
3296 Editor::clamp_verbose_cursor_y (double y)
3298 if (y < canvas_timebars_vsize) {
3299 y = canvas_timebars_vsize;
3301 y = min (_canvas_height - 50, y);
3307 Editor::show_verbose_canvas_cursor_with (const string & txt)
3309 verbose_canvas_cursor->property_text() = txt.c_str();
3314 track_canvas->get_pointer (x, y);
3315 track_canvas->window_to_world (x, y, wx, wy);
3317 /* don't get too close to the edge */
3318 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3319 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3321 show_verbose_canvas_cursor ();
3325 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3327 verbose_canvas_cursor->property_text() = txt.c_str();
3328 /* don't get too close to the edge */
3329 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3330 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3334 Editor::set_verbose_canvas_cursor_text (const string & txt)
3336 verbose_canvas_cursor->property_text() = txt.c_str();
3340 Editor::set_edit_mode (EditMode m)
3342 Config->set_edit_mode (m);
3346 Editor::cycle_edit_mode ()
3348 switch (Config->get_edit_mode()) {
3350 if (Profile->get_sae()) {
3351 Config->set_edit_mode (Lock);
3353 Config->set_edit_mode (Splice);
3357 Config->set_edit_mode (Lock);
3360 Config->set_edit_mode (Slide);
3366 Editor::edit_mode_selection_done ()
3368 if (_session == 0) {
3372 string choice = edit_mode_selector.get_active_text();
3373 EditMode mode = Slide;
3375 if (choice == _("Splice Edit")) {
3377 } else if (choice == _("Slide Edit")) {
3379 } else if (choice == _("Lock Edit")) {
3383 Config->set_edit_mode (mode);
3387 Editor::snap_type_selection_done ()
3389 string choice = snap_type_selector.get_active_text();
3390 SnapType snaptype = SnapToBeat;
3392 if (choice == _("Beats/3")) {
3393 snaptype = SnapToAThirdBeat;
3394 } else if (choice == _("Beats/4")) {
3395 snaptype = SnapToAQuarterBeat;
3396 } else if (choice == _("Beats/8")) {
3397 snaptype = SnapToAEighthBeat;
3398 } else if (choice == _("Beats/16")) {
3399 snaptype = SnapToASixteenthBeat;
3400 } else if (choice == _("Beats/32")) {
3401 snaptype = SnapToAThirtysecondBeat;
3402 } else if (choice == _("Beats")) {
3403 snaptype = SnapToBeat;
3404 } else if (choice == _("Bars")) {
3405 snaptype = SnapToBar;
3406 } else if (choice == _("Marks")) {
3407 snaptype = SnapToMark;
3408 } else if (choice == _("Region starts")) {
3409 snaptype = SnapToRegionStart;
3410 } else if (choice == _("Region ends")) {
3411 snaptype = SnapToRegionEnd;
3412 } else if (choice == _("Region bounds")) {
3413 snaptype = SnapToRegionBoundary;
3414 } else if (choice == _("Region syncs")) {
3415 snaptype = SnapToRegionSync;
3416 } else if (choice == _("CD Frames")) {
3417 snaptype = SnapToCDFrame;
3418 } else if (choice == _("Timecode Frames")) {
3419 snaptype = SnapToTimecodeFrame;
3420 } else if (choice == _("Timecode Seconds")) {
3421 snaptype = SnapToTimecodeSeconds;
3422 } else if (choice == _("Timecode Minutes")) {
3423 snaptype = SnapToTimecodeMinutes;
3424 } else if (choice == _("Seconds")) {
3425 snaptype = SnapToSeconds;
3426 } else if (choice == _("Minutes")) {
3427 snaptype = SnapToMinutes;
3430 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3432 ract->set_active ();
3437 Editor::snap_mode_selection_done ()
3439 string choice = snap_mode_selector.get_active_text();
3440 SnapMode mode = SnapNormal;
3442 if (choice == _("No Grid")) {
3444 } else if (choice == _("Grid")) {
3446 } else if (choice == _("Magnetic")) {
3447 mode = SnapMagnetic;
3450 RefPtr<RadioAction> ract = snap_mode_action (mode);
3453 ract->set_active (true);
3458 Editor::cycle_edit_point (bool with_marker)
3460 switch (_edit_point) {
3462 set_edit_point_preference (EditAtPlayhead);
3464 case EditAtPlayhead:
3466 set_edit_point_preference (EditAtSelectedMarker);
3468 set_edit_point_preference (EditAtMouse);
3471 case EditAtSelectedMarker:
3472 set_edit_point_preference (EditAtMouse);
3478 Editor::edit_point_selection_done ()
3480 string choice = edit_point_selector.get_active_text();
3481 EditPoint ep = EditAtSelectedMarker;
3483 if (choice == _("Marker")) {
3484 set_edit_point_preference (EditAtSelectedMarker);
3485 } else if (choice == _("Playhead")) {
3486 set_edit_point_preference (EditAtPlayhead);
3488 set_edit_point_preference (EditAtMouse);
3491 RefPtr<RadioAction> ract = edit_point_action (ep);
3494 ract->set_active (true);
3499 Editor::zoom_focus_selection_done ()
3501 string choice = zoom_focus_selector.get_active_text();
3502 ZoomFocus focus_type = ZoomFocusLeft;
3504 if (choice == _("Left")) {
3505 focus_type = ZoomFocusLeft;
3506 } else if (choice == _("Right")) {
3507 focus_type = ZoomFocusRight;
3508 } else if (choice == _("Center")) {
3509 focus_type = ZoomFocusCenter;
3510 } else if (choice == _("Playhead")) {
3511 focus_type = ZoomFocusPlayhead;
3512 } else if (choice == _("Mouse")) {
3513 focus_type = ZoomFocusMouse;
3514 } else if (choice == _("Edit point")) {
3515 focus_type = ZoomFocusEdit;
3518 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3521 ract->set_active ();
3526 Editor::edit_controls_button_release (GdkEventButton* ev)
3528 if (Keyboard::is_context_menu_event (ev)) {
3529 ARDOUR_UI::instance()->add_route (this);
3535 Editor::mouse_select_button_release (GdkEventButton* ev)
3537 /* this handles just right-clicks */
3539 if (ev->button != 3) {
3547 Editor::set_zoom_focus (ZoomFocus f)
3549 string str = zoom_focus_strings[(int)f];
3551 if (str != zoom_focus_selector.get_active_text()) {
3552 zoom_focus_selector.set_active_text (str);
3555 if (zoom_focus != f) {
3558 ZoomFocusChanged (); /* EMIT_SIGNAL */
3565 Editor::ensure_float (Window& win)
3567 win.set_transient_for (*this);
3571 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3573 /* recover or initialize pane positions. do this here rather than earlier because
3574 we don't want the positions to change the child allocations, which they seem to do.
3580 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3582 static int32_t done;
3585 width = default_width;
3586 height = default_height;
3588 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3590 if ((prop = geometry->property ("x_size")) == 0) {
3591 prop = geometry->property ("x-size");
3594 width = atoi (prop->value());
3596 if ((prop = geometry->property ("y_size")) == 0) {
3597 prop = geometry->property ("y-size");
3600 height = atoi (prop->value());
3604 if (which == static_cast<Paned*> (&edit_pane)) {
3610 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3611 /* initial allocation is 90% to canvas, 10% to notebook */
3612 pos = (int) floor (alloc.get_width() * 0.90f);
3613 snprintf (buf, sizeof(buf), "%d", pos);
3615 pos = atoi (prop->value());
3618 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3619 edit_pane.set_position (pos);
3620 pre_maximal_pane_position = pos;
3626 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3628 cerr << "remove tearoff\n";
3630 if (tools_tearoff->torn_off() &&
3631 mouse_mode_tearoff->torn_off()) {
3632 top_hbox.remove (toolbar_frame);
3637 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3639 cerr << "reattach tearoff\n";
3640 if (toolbar_frame.get_parent() == 0) {
3641 top_hbox.pack_end (toolbar_frame);
3646 Editor::set_show_measures (bool yn)
3648 if (_show_measures != yn) {
3651 if ((_show_measures = yn) == true) {
3653 tempo_lines->show();
3661 Editor::toggle_follow_playhead ()
3663 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3665 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3666 set_follow_playhead (tact->get_active());
3671 Editor::set_follow_playhead (bool yn)
3673 if (_follow_playhead != yn) {
3674 if ((_follow_playhead = yn) == true) {
3676 update_current_screen ();
3683 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3685 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3687 xfade->set_active (!xfade->active());
3692 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3694 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3696 xfade->set_follow_overlap (!xfade->following_overlap());
3701 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3703 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3709 CrossfadeEditor cew (_session, xfade, xfade->fade_in().get_min_y(), 1.0);
3713 switch (cew.run ()) {
3714 case RESPONSE_ACCEPT:
3721 xfade->StateChanged (Change (~0));
3725 Editor::playlist_selector () const
3727 return *_playlist_selector;
3731 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3735 switch (_snap_type) {
3740 case SnapToAThirtysecondBeat:
3744 case SnapToASixteenthBeat:
3748 case SnapToAEighthBeat:
3752 case SnapToAQuarterBeat:
3756 case SnapToAThirdBeat:
3762 return _session->tempo_map().meter_at (position).beats_per_bar();
3767 case SnapToTimecodeFrame:
3768 case SnapToTimecodeSeconds:
3769 case SnapToTimecodeMinutes:
3772 case SnapToRegionStart:
3773 case SnapToRegionEnd:
3774 case SnapToRegionSync:
3775 case SnapToRegionBoundary:
3785 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3789 ret = nudge_clock.current_duration (pos);
3790 next = ret + 1; /* XXXX fix me */
3796 Editor::end_location_changed (Location* location)
3798 ENSURE_GUI_THREAD (*this, &Editor::end_location_changed, location)
3799 //reset_scrolling_region ();
3800 nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
3801 horizontal_adjustment.set_upper (session_span / frames_per_unit);
3805 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3807 ArdourDialog dialog ("playlist deletion dialog");
3808 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3809 "If left alone, no audio files used by it will be cleaned.\n"
3810 "If deleted, audio files used by it alone by will cleaned."),
3813 dialog.set_position (WIN_POS_CENTER);
3814 dialog.get_vbox()->pack_start (label);
3818 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3819 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3820 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3822 switch (dialog.run ()) {
3823 case RESPONSE_ACCEPT:
3824 /* delete the playlist */
3828 case RESPONSE_REJECT:
3829 /* keep the playlist */
3841 Editor::audio_region_selection_covers (nframes64_t where)
3843 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3844 if ((*a)->region()->covers (where)) {
3853 Editor::prepare_for_cleanup ()
3855 cut_buffer->clear_regions ();
3856 cut_buffer->clear_playlists ();
3858 selection->clear_regions ();
3859 selection->clear_playlists ();
3861 _regions->suspend_redisplay ();
3865 Editor::finish_cleanup ()
3867 _regions->resume_redisplay ();
3871 Editor::transport_loop_location()
3874 return _session->locations()->auto_loop_location();
3881 Editor::transport_punch_location()
3884 return _session->locations()->auto_punch_location();
3891 Editor::control_layout_scroll (GdkEventScroll* ev)
3893 if (Keyboard::some_magic_widget_has_focus()) {
3897 switch (ev->direction) {
3899 scroll_tracks_up_line ();
3903 case GDK_SCROLL_DOWN:
3904 scroll_tracks_down_line ();
3908 /* no left/right handling yet */
3916 Editor::session_state_saved (string snap_name)
3918 ENSURE_GUI_THREAD (*this, &Editor::session_state_saved, snap_name);
3921 _snapshots->redisplay ();
3925 Editor::maximise_editing_space ()
3927 mouse_mode_tearoff->set_visible (false);
3928 tools_tearoff->set_visible (false);
3930 pre_maximal_pane_position = edit_pane.get_position();
3931 pre_maximal_editor_width = this->get_width();
3933 if(post_maximal_pane_position == 0) {
3934 post_maximal_pane_position = edit_pane.get_width();
3939 if(post_maximal_editor_width) {
3940 edit_pane.set_position (post_maximal_pane_position -
3941 abs(post_maximal_editor_width - pre_maximal_editor_width));
3943 edit_pane.set_position (post_maximal_pane_position);
3948 Editor::restore_editing_space ()
3950 // user changed width of pane during fullscreen
3952 if(post_maximal_pane_position != edit_pane.get_position()) {
3953 post_maximal_pane_position = edit_pane.get_position();
3958 mouse_mode_tearoff->set_visible (true);
3959 tools_tearoff->set_visible (true);
3960 post_maximal_editor_width = this->get_width();
3962 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
3966 * Make new playlists for a given track and also any others that belong
3967 * to the same active route group with the `edit' property.
3972 Editor::new_playlists (TimeAxisView* v)
3974 begin_reversible_command (_("new playlists"));
3975 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
3976 _session->playlists->get (playlists);
3977 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, RouteGroup::Edit);
3978 commit_reversible_command ();
3982 * Use a copy of the current playlist for a given track and also any others that belong
3983 * to the same active route group with the `edit' property.
3988 Editor::copy_playlists (TimeAxisView* v)
3990 begin_reversible_command (_("copy playlists"));
3991 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
3992 _session->playlists->get (playlists);
3993 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, RouteGroup::Edit);
3994 commit_reversible_command ();
3997 /** Clear the current playlist for a given track and also any others that belong
3998 * to the same active route group with the `edit' property.
4003 Editor::clear_playlists (TimeAxisView* v)
4005 begin_reversible_command (_("clear playlists"));
4006 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4007 _session->playlists->get (playlists);
4008 mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, RouteGroup::Edit);
4009 commit_reversible_command ();
4013 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4015 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4019 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4021 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4025 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4027 atv.clear_playlist ();
4031 Editor::on_key_press_event (GdkEventKey* ev)
4033 return key_press_focus_accelerator_handler (*this, ev);
4037 Editor::on_key_release_event (GdkEventKey* ev)
4039 return Gtk::Window::on_key_release_event (ev);
4040 // return key_press_focus_accelerator_handler (*this, ev);
4044 Editor::reset_x_origin (nframes64_t frame)
4046 //cerr << "resetting x origin" << endl;
4047 queue_visual_change (frame);
4051 Editor::reset_y_origin (double y)
4053 queue_visual_change_y (y);
4057 Editor::reset_zoom (double fpu)
4059 queue_visual_change (fpu);
4063 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4065 //cerr << "Editor::reposition_and_zoom () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
4066 reset_x_origin (frame);
4069 if (!no_save_visual) {
4070 undo_visual_stack.push_back (current_visual_state(false));
4074 Editor::VisualState*
4075 Editor::current_visual_state (bool with_tracks)
4077 VisualState* vs = new VisualState;
4078 vs->y_position = vertical_adjustment.get_value();
4079 vs->frames_per_unit = frames_per_unit;
4080 vs->leftmost_frame = leftmost_frame;
4081 vs->zoom_focus = zoom_focus;
4084 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4085 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4093 Editor::undo_visual_state ()
4095 if (undo_visual_stack.empty()) {
4099 VisualState* vs = undo_visual_stack.back();
4100 undo_visual_stack.pop_back();
4101 use_visual_state (*vs);
4102 redo_visual_stack.push_back (vs);
4106 Editor::redo_visual_state ()
4108 if (redo_visual_stack.empty()) {
4112 VisualState* vs = redo_visual_stack.back();
4113 redo_visual_stack.pop_back();
4114 use_visual_state (*vs);
4115 undo_visual_stack.push_back (vs);
4119 Editor::swap_visual_state ()
4121 if (undo_visual_stack.empty()) {
4122 redo_visual_state ();
4124 undo_visual_state ();
4129 Editor::use_visual_state (VisualState& vs)
4131 no_save_visual = true;
4133 _routes->suspend_redisplay ();
4135 vertical_adjustment.set_value (vs.y_position);
4137 set_zoom_focus (vs.zoom_focus);
4138 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4140 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4141 TrackViewList::iterator t;
4143 /* check if the track still exists - it could have been deleted */
4145 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4146 (*t)->set_state (*(i->second), Stateful::loading_state_version);
4151 if (!vs.track_states.empty()) {
4152 _routes->update_visibility ();
4155 _routes->resume_redisplay ();
4157 no_save_visual = false;
4161 Editor::set_frames_per_unit (double fpu)
4163 /* this is the core function that controls the zoom level of the canvas. it is called
4164 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4167 if (fpu == frames_per_unit) {
4176 /* don't allow zooms that fit more than the maximum number
4177 of frames into an 800 pixel wide space.
4180 if (max_frames / fpu < 800.0) {
4185 tempo_lines->tempo_map_changed();
4187 frames_per_unit = fpu;
4192 Editor::post_zoom ()
4194 nframes64_t cef = 0;
4196 // convert fpu to frame count
4198 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4200 if (frames_per_unit != zoom_range_clock.current_duration()) {
4201 zoom_range_clock.set (frames);
4204 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4205 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4206 (*i)->reshow_selection (selection->time);
4210 leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4212 ZoomChanged (); /* EMIT_SIGNAL */
4215 cef = _session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
4217 horizontal_adjustment.set_upper (cef / frames_per_unit);
4219 //reset_scrolling_region ();
4221 if (playhead_cursor) {
4222 playhead_cursor->set_position (playhead_cursor->current_frame);
4225 refresh_location_display();
4226 _summary->set_overlays_dirty ();
4232 Editor::queue_visual_change (nframes64_t where)
4234 pending_visual_change.add (VisualChange::TimeOrigin);
4236 /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
4240 if (_session && (where > _session->current_end_frame())) {
4241 horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
4244 pending_visual_change.time_origin = where;
4246 ensure_visual_change_idle_handler ();
4250 Editor::queue_visual_change (double fpu)
4252 pending_visual_change.add (VisualChange::ZoomLevel);
4253 pending_visual_change.frames_per_unit = fpu;
4255 ensure_visual_change_idle_handler ();
4259 Editor::queue_visual_change_y (double y)
4261 pending_visual_change.add (VisualChange::YOrigin);
4262 pending_visual_change.y_origin = y;
4264 ensure_visual_change_idle_handler ();
4268 Editor::ensure_visual_change_idle_handler ()
4270 if (pending_visual_change.idle_handler_id < 0) {
4271 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4276 Editor::_idle_visual_changer (void* arg)
4278 return static_cast<Editor*>(arg)->idle_visual_changer ();
4282 Editor::idle_visual_changer ()
4284 VisualChange::Type p = pending_visual_change.pending;
4285 pending_visual_change.pending = (VisualChange::Type) 0;
4287 double last_time_origin = horizontal_adjustment.get_value();
4289 if (p & VisualChange::ZoomLevel) {
4290 set_frames_per_unit (pending_visual_change.frames_per_unit);
4292 compute_fixed_ruler_scale ();
4293 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4294 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4295 update_tempo_based_rulers ();
4297 if (p & VisualChange::TimeOrigin) {
4298 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4300 if (p & VisualChange::YOrigin) {
4301 vertical_adjustment.set_value (pending_visual_change.y_origin);
4304 nframes64_t csf=0, cef=0;
4305 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4308 csf = _session->current_start_frame();
4309 cef = _session->current_end_frame();
4312 /* if we seek beyond the current end of the canvas, move the end */
4315 if (last_time_origin == horizontal_adjustment.get_value() ) {
4316 /* changed signal not emitted */
4317 update_fixed_rulers ();
4318 redisplay_tempo (true);
4321 if (current_time_origin != pending_visual_change.time_origin) {
4322 cef += current_page_frames() / 10; // Add a little extra so we can see the end marker
4323 horizontal_adjustment.set_upper (cef / frames_per_unit);
4324 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4326 update_fixed_rulers();
4327 redisplay_tempo (true);
4330 _summary->set_overlays_dirty ();
4332 // cerr << "Editor::idle_visual_changer () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
4333 pending_visual_change.idle_handler_id = -1;
4334 return 0; /* this is always a one-shot call */
4337 struct EditorOrderTimeAxisSorter {
4338 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4339 return a->order () < b->order ();
4344 Editor::sort_track_selection (TrackViewList* sel)
4346 EditorOrderTimeAxisSorter cmp;
4351 selection->tracks.sort (cmp);
4356 Editor::get_preferred_edit_position (bool ignore_playhead)
4359 nframes64_t where = 0;
4360 EditPoint ep = _edit_point;
4362 if (entered_marker) {
4363 return entered_marker->position();
4366 if (ignore_playhead && ep == EditAtPlayhead) {
4367 ep = EditAtSelectedMarker;
4371 case EditAtPlayhead:
4372 where = _session->audible_frame();
4375 case EditAtSelectedMarker:
4376 if (!selection->markers.empty()) {
4378 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4381 where = loc->start();
4392 if (!mouse_frame (where, ignored)) {
4393 /* XXX not right but what can we do ? */
4404 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4406 if (!_session) return;
4408 begin_reversible_command (cmd);
4412 if ((tll = transport_loop_location()) == 0) {
4413 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4414 XMLNode &before = _session->locations()->get_state();
4415 _session->locations()->add (loc, true);
4416 _session->set_auto_loop_location (loc);
4417 XMLNode &after = _session->locations()->get_state();
4418 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4420 XMLNode &before = tll->get_state();
4421 tll->set_hidden (false, this);
4422 tll->set (start, end);
4423 XMLNode &after = tll->get_state();
4424 _session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4427 commit_reversible_command ();
4431 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4433 if (!_session) return;
4435 begin_reversible_command (cmd);
4439 if ((tpl = transport_punch_location()) == 0) {
4440 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4441 XMLNode &before = _session->locations()->get_state();
4442 _session->locations()->add (loc, true);
4443 _session->set_auto_loop_location (loc);
4444 XMLNode &after = _session->locations()->get_state();
4445 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4448 XMLNode &before = tpl->get_state();
4449 tpl->set_hidden (false, this);
4450 tpl->set (start, end);
4451 XMLNode &after = tpl->get_state();
4452 _session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4455 commit_reversible_command ();
4458 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4459 * @param rs List to which found regions are added.
4460 * @param where Time to look at.
4461 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4464 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4466 const TrackViewList* tracks;
4469 tracks = &track_views;
4474 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4475 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4477 boost::shared_ptr<Diskstream> ds;
4478 boost::shared_ptr<Playlist> pl;
4480 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4482 Playlist::RegionList* regions = pl->regions_at (
4483 (nframes64_t) floor ( (double)where * ds->speed()));
4485 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4486 RegionView* rv = rtv->view()->find_view (*i);
4499 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4501 const TrackViewList* tracks;
4504 tracks = &track_views;
4509 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4510 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4512 boost::shared_ptr<Diskstream> ds;
4513 boost::shared_ptr<Playlist> pl;
4515 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4517 Playlist::RegionList* regions = pl->regions_touched (
4518 (nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4520 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4522 RegionView* rv = rtv->view()->find_view (*i);
4535 /** Find all regions which are either:
4537 * - the entered_regionview (if allow_entered == true) or
4538 * - under the preferred edit position AND on a selected track, or on a track
4539 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4540 * @param rs Returned region list.
4541 * @param allow_entered true to include the entered_regionview in the list.
4544 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4546 /* Start with selected regions */
4547 rs = selection->regions;
4549 /* Add the entered_regionview, if requested */
4550 if (allow_entered && entered_regionview) {
4551 rs.add (entered_regionview);
4554 if (allow_edit_position) {
4556 TrackViewList tracks = selection->tracks;
4558 /* tracks is currently the set of selected tracks; add any other tracks that
4559 * have regions that are in the same edit-activated route group as one of
4561 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4563 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4564 if (g && g->active_property (RouteGroup::Edit)) {
4565 tracks.add (axis_views_from_routes (g->route_list()));
4570 if (!tracks.empty()) {
4571 /* now find regions that are at the edit position on those tracks */
4572 nframes64_t const where = get_preferred_edit_position ();
4573 get_regions_at (rs, where, tracks);
4579 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4581 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4583 RouteTimeAxisView* tatv;
4585 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4587 boost::shared_ptr<Playlist> pl;
4588 vector<boost::shared_ptr<Region> > results;
4590 boost::shared_ptr<Diskstream> ds;
4592 if ((ds = tatv->get_diskstream()) == 0) {
4597 if ((pl = (ds->playlist())) != 0) {
4598 pl->get_region_list_equivalent_regions (region, results);
4601 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4602 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4603 regions.push_back (marv);
4612 Editor::show_rhythm_ferret ()
4614 if (rhythm_ferret == 0) {
4615 rhythm_ferret = new RhythmFerret(*this);
4618 rhythm_ferret->set_session (_session);
4619 rhythm_ferret->show ();
4620 rhythm_ferret->present ();
4624 Editor::show_global_port_matrix (ARDOUR::DataType t)
4626 if (_global_port_matrix[t] == 0) {
4627 _global_port_matrix[t] = new GlobalPortMatrixWindow (_session, t);
4630 _global_port_matrix[t]->show ();
4634 Editor::first_idle ()
4636 MessageDialog* dialog = 0;
4638 if (track_views.size() > 1) {
4639 dialog = new MessageDialog (*this,
4640 _("Please wait while Ardour loads visual data"),
4645 ARDOUR_UI::instance()->flush_pending ();
4648 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4652 // first idle adds route children (automation tracks), so we need to redisplay here
4653 _routes->redisplay ();
4661 _idle_resizer (gpointer arg)
4663 return ((Editor*)arg)->idle_resize ();
4667 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4669 if (resize_idle_id < 0) {
4670 resize_idle_id = g_idle_add (_idle_resizer, this);
4671 _pending_resize_amount = 0;
4674 /* make a note of the smallest resulting height, so that we can clamp the
4675 lower limit at TimeAxisView::hSmall */
4677 int32_t min_resulting = INT32_MAX;
4679 _pending_resize_amount += h;
4680 _pending_resize_view = view;
4682 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4684 if (selection->tracks.contains (_pending_resize_view)) {
4685 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4686 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4690 if (min_resulting < 0) {
4695 if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
4696 _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
4700 /** Handle pending resizing of tracks */
4702 Editor::idle_resize ()
4704 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4706 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4707 selection->tracks.contains (_pending_resize_view)) {
4709 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4710 if (*i != _pending_resize_view) {
4711 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4717 _group_tabs->set_dirty ();
4718 resize_idle_id = -1;
4726 ENSURE_GUI_THREAD (*this, &Editor::located)
4728 _pending_locate_request = false;
4732 Editor::region_view_added (RegionView *)
4734 _summary->set_dirty ();
4738 Editor::streamview_height_changed ()
4740 _summary->set_dirty ();
4744 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
4746 TrackViewList::const_iterator j = track_views.begin ();
4747 while (j != track_views.end()) {
4748 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4749 if (rtv && rtv->route() == r) {
4760 Editor::axis_views_from_routes (boost::shared_ptr<RouteList> r) const
4764 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
4765 TimeAxisView* tv = axis_view_from_route (*i);
4776 Editor::handle_new_route (RouteList& routes)
4778 ENSURE_GUI_THREAD (*this, &Editor::handle_new_route, routes)
4780 RouteTimeAxisView *rtv;
4781 list<RouteTimeAxisView*> new_views;
4783 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4784 boost::shared_ptr<Route> route = (*x);
4786 if (route->is_hidden()) {
4790 DataType dt = route->input()->default_type();
4792 if (dt == ARDOUR::DataType::AUDIO) {
4793 rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
4794 } else if (dt == ARDOUR::DataType::MIDI) {
4795 rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
4797 throw unknown_type();
4800 new_views.push_back (rtv);
4801 track_views.push_back (rtv);
4803 rtv->effective_gain_display ();
4805 rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
4806 rtv->view()->HeightChanged.connect (sigc::mem_fun (*this, &Editor::streamview_height_changed));
4809 _routes->routes_added (new_views);
4811 if (show_editor_mixer_when_tracks_arrive) {
4812 show_editor_mixer (true);
4815 editor_list_button.set_sensitive (true);
4817 _summary->set_dirty ();
4821 Editor::timeaxisview_deleted (TimeAxisView *tv)
4823 if (_session && _session->deletion_in_progress()) {
4824 /* the situation is under control */
4828 ENSURE_GUI_THREAD (*this, &Editor::timeaxisview_deleted, tv);
4831 _routes->route_removed (tv);
4833 if (tv == entered_track) {
4837 /* remove it from the list of track views */
4839 TrackViewList::iterator i;
4841 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4842 i = track_views.erase (i);
4845 /* update whatever the current mixer strip is displaying, if revelant */
4847 boost::shared_ptr<Route> route;
4848 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv);
4851 route = rtav->route ();
4854 if (current_mixer_strip && current_mixer_strip->route() == route) {
4856 TimeAxisView* next_tv;
4858 if (track_views.empty()) {
4860 } else if (i == track_views.end()) {
4861 next_tv = track_views.front();
4868 set_selected_mixer_strip (*next_tv);
4870 /* make the editor mixer strip go away setting the
4871 * button to inactive (which also unticks the menu option)
4874 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
4880 Editor::hide_track_in_display (TimeAxisView& tv, bool /*temponly*/)
4882 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
4884 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
4885 // this will hide the mixer strip
4886 set_selected_mixer_strip (tv);
4889 _routes->hide_track_in_display (tv);
4893 Editor::sync_track_view_list_and_routes ()
4895 track_views = TrackViewList (_routes->views ());
4897 _summary->set_dirty ();
4898 _group_tabs->set_dirty ();
4900 return false; // do not call again (until needed)
4904 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
4906 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4912 Editor::get_route_view_by_id (PBD::ID& id)
4914 RouteTimeAxisView* v;
4916 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4917 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
4918 if(v->route()->id() == id) {
4928 Editor::fit_route_group (RouteGroup *g)
4930 TrackViewList ts = axis_views_from_routes (g->route_list ());
4935 Editor::consider_auditioning (boost::shared_ptr<Region> region)
4937 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
4940 _session->cancel_audition ();
4944 if (_session->is_auditioning()) {
4945 _session->cancel_audition ();
4946 if (r == last_audition_region) {
4951 _session->audition_region (r);
4952 last_audition_region = r;
4957 Editor::hide_a_region (boost::shared_ptr<Region> r)
4959 r->set_hidden (true);
4963 Editor::remove_a_region (boost::shared_ptr<Region> r)
4965 _session->remove_region_from_region_list (r);
4969 Editor::audition_region_from_region_list ()
4971 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::consider_auditioning));
4975 Editor::hide_region_from_region_list ()
4977 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::hide_a_region));
4981 Editor::start_step_editing ()
4983 step_edit_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::check_step_edit), 20);
4987 Editor::stop_step_editing ()
4989 step_edit_connection.disconnect ();
4993 Editor::check_step_edit ()
4995 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4996 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
4998 mtv->check_step_edit ();
5002 return true; // do it again, till we stop
5006 Editor::horizontal_scroll_left ()
5008 double x = leftmost_position() - current_page_frames() / 5;
5017 Editor::horizontal_scroll_right ()
5019 reset_x_origin (leftmost_position() + current_page_frames() / 5);