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"
76 #include "ardour/audioengine.h"
78 #include "control_protocol/control_protocol.h"
83 #include "playlist_selector.h"
84 #include "audio_region_view.h"
85 #include "rgb_macros.h"
86 #include "selection.h"
87 #include "audio_streamview.h"
88 #include "time_axis_view.h"
89 #include "audio_time_axis.h"
91 #include "crossfade_view.h"
92 #include "canvas-noevent-text.h"
94 #include "public_editor.h"
95 #include "crossfade_edit.h"
96 #include "canvas_impl.h"
99 #include "gui_thread.h"
100 #include "simpleline.h"
101 #include "rhythm_ferret.h"
103 #include "tempo_lines.h"
104 #include "analysis_window.h"
105 #include "bundle_manager.h"
106 #include "global_port_matrix.h"
107 #include "editor_drag.h"
108 #include "editor_group_tabs.h"
109 #include "automation_time_axis.h"
110 #include "editor_routes.h"
111 #include "midi_time_axis.h"
112 #include "mixer_strip.h"
113 #include "editor_route_groups.h"
114 #include "editor_regions.h"
115 #include "editor_locations.h"
116 #include "editor_snapshots.h"
121 #include "imageframe_socket_handler.h"
125 using namespace ARDOUR;
128 using namespace Glib;
129 using namespace Gtkmm2ext;
130 using namespace Editing;
132 using PBD::internationalize;
134 using Gtkmm2ext::Keyboard;
136 const double Editor::timebar_height = 15.0;
138 #include "editor_xpms"
140 static const gchar *_snap_type_strings[] = {
142 N_("Timecode Frames"),
143 N_("Timecode Seconds"),
144 N_("Timecode Minutes"),
171 static const gchar *_snap_mode_strings[] = {
178 static const gchar *_edit_point_strings[] = {
185 static const gchar *_zoom_focus_strings[] = {
195 #ifdef USE_RUBBERBAND
196 static const gchar *_rb_opt_strings[] = {
199 N_("Balanced multitimbral mixture"),
200 N_("Unpitched percussion with stable notes"),
201 N_("Crisp monophonic instrumental"),
202 N_("Unpitched solo percussion"),
207 /* Soundfile drag-n-drop */
209 Gdk::Cursor* Editor::cross_hair_cursor = 0;
210 Gdk::Cursor* Editor::selector_cursor = 0;
211 Gdk::Cursor* Editor::trimmer_cursor = 0;
212 Gdk::Cursor* Editor::grabber_cursor = 0;
213 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
214 Gdk::Cursor* Editor::zoom_cursor = 0;
215 Gdk::Cursor* Editor::time_fx_cursor = 0;
216 Gdk::Cursor* Editor::fader_cursor = 0;
217 Gdk::Cursor* Editor::speaker_cursor = 0;
218 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
219 Gdk::Cursor* Editor::midi_select_cursor = 0;
220 Gdk::Cursor* Editor::midi_resize_cursor = 0;
221 Gdk::Cursor* Editor::midi_erase_cursor = 0;
222 Gdk::Cursor* Editor::wait_cursor = 0;
223 Gdk::Cursor* Editor::timebar_cursor = 0;
224 Gdk::Cursor* Editor::transparent_cursor = 0;
227 show_me_the_size (Requisition* r, const char* what)
229 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
234 pane_size_watcher (Paned* pane)
236 /* if the handle of a pane vanishes into (at least) the tabs of a notebook,
237 it is no longer accessible. so stop that. this doesn't happen on X11,
238 just the quartz backend.
243 int max_width_of_lhs = GTK_WIDGET(pane->gobj())->allocation.width - 25;
245 gint pos = pane->get_position ();
247 if (pos > max_width_of_lhs) {
248 pane->set_position (max_width_of_lhs);
254 : _join_object_range_state (JOIN_OBJECT_RANGE_NONE)
256 /* time display buttons */
257 , minsec_label (_("Mins:Secs"))
258 , bbt_label (_("Bars:Beats"))
259 , timecode_label (_("Timecode"))
260 , frame_label (_("Samples"))
261 , tempo_label (_("Tempo"))
262 , meter_label (_("Meter"))
263 , mark_label (_("Location Markers"))
264 , range_mark_label (_("Range Markers"))
265 , transport_mark_label (_("Loop/Punch Ranges"))
266 , cd_mark_label (_("CD Markers"))
267 , edit_packer (4, 4, true)
269 /* the values here don't matter: layout widgets
270 reset them as needed.
273 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
275 /* tool bar related */
277 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
279 , toolbar_selection_clock_table (2,3)
281 , automation_mode_button (_("mode"))
282 , global_automation_button (_("automation"))
284 , midi_panic_button (_("Panic"))
287 , image_socket_listener(0)
292 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
293 , meters_running(false)
294 , _pending_locate_request (false)
295 , _pending_initial_locate (false)
300 /* we are a singleton */
302 PublicEditor::_instance = this;
306 selection = new Selection (this);
307 cut_buffer = new Selection (this);
309 clicked_regionview = 0;
310 clicked_axisview = 0;
311 clicked_routeview = 0;
312 clicked_crossfadeview = 0;
313 clicked_control_point = 0;
314 last_update_frame = 0;
315 _drags = new DragManager (this);
316 current_mixer_strip = 0;
317 current_bbt_points = 0;
320 snap_type_strings = I18N (_snap_type_strings);
321 snap_mode_strings = I18N (_snap_mode_strings);
322 zoom_focus_strings = I18N (_zoom_focus_strings);
323 edit_point_strings = I18N (_edit_point_strings);
324 #ifdef USE_RUBBERBAND
325 rb_opt_strings = I18N (_rb_opt_strings);
328 snap_threshold = 5.0;
329 bbt_beat_subdivision = 4;
332 last_autoscroll_x = 0;
333 last_autoscroll_y = 0;
334 autoscroll_active = false;
335 autoscroll_timeout_tag = -1;
340 current_interthread_info = 0;
341 _show_measures = true;
342 show_gain_after_trim = false;
343 verbose_cursor_on = true;
344 last_item_entered = 0;
345 last_item_entered_n = 0;
347 have_pending_keyboard_selection = false;
348 _follow_playhead = true;
349 _stationary_playhead = false;
350 _xfade_visibility = true;
351 editor_ruler_menu = 0;
352 no_ruler_shown_update = false;
354 session_range_marker_menu = 0;
355 range_marker_menu = 0;
356 marker_menu_item = 0;
357 tempo_or_meter_marker_menu = 0;
358 transport_marker_menu = 0;
359 new_transport_marker_menu = 0;
360 editor_mixer_strip_width = Wide;
361 show_editor_mixer_when_tracks_arrive = false;
362 region_edit_menu_split_multichannel_item = 0;
363 region_edit_menu_split_item = 0;
366 current_stepping_trackview = 0;
368 entered_regionview = 0;
370 clear_entered_track = false;
373 button_release_can_deselect = true;
374 _dragging_playhead = false;
375 _dragging_edit_point = false;
376 select_new_marker = false;
379 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
380 _global_port_matrix[*i] = 0;
382 allow_vertical_scroll = false;
383 no_save_visual = false;
386 scrubbing_direction = 0;
390 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
391 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
392 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
393 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
394 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
396 _edit_point = EditAtMouse;
397 _internal_editing = false;
398 current_canvas_cursor = 0;
400 frames_per_unit = 2048; /* too early to use reset_zoom () */
402 zoom_focus = ZoomFocusLeft;
403 set_zoom_focus (ZoomFocusLeft);
404 zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
406 bbt_label.set_name ("EditorTimeButton");
407 bbt_label.set_size_request (-1, (int)timebar_height);
408 bbt_label.set_alignment (1.0, 0.5);
409 bbt_label.set_padding (5,0);
411 bbt_label.set_no_show_all();
412 minsec_label.set_name ("EditorTimeButton");
413 minsec_label.set_size_request (-1, (int)timebar_height);
414 minsec_label.set_alignment (1.0, 0.5);
415 minsec_label.set_padding (5,0);
416 minsec_label.hide ();
417 minsec_label.set_no_show_all();
418 timecode_label.set_name ("EditorTimeButton");
419 timecode_label.set_size_request (-1, (int)timebar_height);
420 timecode_label.set_alignment (1.0, 0.5);
421 timecode_label.set_padding (5,0);
422 timecode_label.hide ();
423 timecode_label.set_no_show_all();
424 frame_label.set_name ("EditorTimeButton");
425 frame_label.set_size_request (-1, (int)timebar_height);
426 frame_label.set_alignment (1.0, 0.5);
427 frame_label.set_padding (5,0);
429 frame_label.set_no_show_all();
431 tempo_label.set_name ("EditorTimeButton");
432 tempo_label.set_size_request (-1, (int)timebar_height);
433 tempo_label.set_alignment (1.0, 0.5);
434 tempo_label.set_padding (5,0);
436 tempo_label.set_no_show_all();
437 meter_label.set_name ("EditorTimeButton");
438 meter_label.set_size_request (-1, (int)timebar_height);
439 meter_label.set_alignment (1.0, 0.5);
440 meter_label.set_padding (5,0);
442 meter_label.set_no_show_all();
443 mark_label.set_name ("EditorTimeButton");
444 mark_label.set_size_request (-1, (int)timebar_height);
445 mark_label.set_alignment (1.0, 0.5);
446 mark_label.set_padding (5,0);
448 mark_label.set_no_show_all();
449 cd_mark_label.set_name ("EditorTimeButton");
450 cd_mark_label.set_size_request (-1, (int)timebar_height);
451 cd_mark_label.set_alignment (1.0, 0.5);
452 cd_mark_label.set_padding (5,0);
453 cd_mark_label.hide();
454 cd_mark_label.set_no_show_all();
455 range_mark_label.set_name ("EditorTimeButton");
456 range_mark_label.set_size_request (-1, (int)timebar_height);
457 range_mark_label.set_alignment (1.0, 0.5);
458 range_mark_label.set_padding (5,0);
459 range_mark_label.hide();
460 range_mark_label.set_no_show_all();
461 transport_mark_label.set_name ("EditorTimeButton");
462 transport_mark_label.set_size_request (-1, (int)timebar_height);
463 transport_mark_label.set_alignment (1.0, 0.5);
464 transport_mark_label.set_padding (5,0);
465 transport_mark_label.hide();
466 transport_mark_label.set_no_show_all();
468 initialize_rulers ();
469 initialize_canvas ();
470 _summary = new EditorSummary (this);
472 selection->TimeChanged.connect (sigc::mem_fun(*this, &Editor::time_selection_changed));
473 selection->TracksChanged.connect (sigc::mem_fun(*this, &Editor::track_selection_changed));
474 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (sigc::mem_fun(*this, &Editor::region_selection_changed));
475 selection->PointsChanged.connect (sigc::mem_fun(*this, &Editor::point_selection_changed));
476 selection->MarkersChanged.connect (sigc::mem_fun(*this, &Editor::marker_selection_changed));
478 edit_controls_vbox.set_spacing (0);
479 vertical_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::tie_vertical_scrolling), true);
480 track_canvas->signal_map_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_map_handler));
482 HBox* h = manage (new HBox);
483 _group_tabs = new EditorGroupTabs (this);
484 h->pack_start (*_group_tabs, PACK_SHRINK);
485 h->pack_start (edit_controls_vbox);
486 controls_layout.add (*h);
488 controls_layout.set_name ("EditControlsBase");
489 controls_layout.add_events (Gdk::SCROLL_MASK);
490 controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false);
492 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
493 controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
494 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
498 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
499 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
500 0.0, 1.0, 100.0, 1.0));
501 pad_line_1->property_color_rgba() = 0xFF0000FF;
505 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
506 time_canvas_vbox.set_size_request (-1, -1);
508 ruler_label_event_box.add (ruler_label_vbox);
509 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
510 ruler_label_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
512 time_button_event_box.add (time_button_vbox);
513 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
514 time_button_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
516 /* these enable us to have a dedicated window (for cursor setting, etc.)
517 for the canvas areas.
520 track_canvas_event_box.add (*track_canvas);
522 time_canvas_event_box.add (time_canvas_vbox);
523 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
525 edit_packer.set_col_spacings (0);
526 edit_packer.set_row_spacings (0);
527 edit_packer.set_homogeneous (false);
528 edit_packer.set_border_width (0);
529 edit_packer.set_name ("EditorWindow");
531 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
532 /* labels for the rulers */
533 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
534 /* labels for the marker "tracks" */
535 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
537 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
539 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
541 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
543 bottom_hbox.set_border_width (2);
544 bottom_hbox.set_spacing (3);
546 _route_groups = new EditorRouteGroups (this);
547 _routes = new EditorRoutes (this);
548 _regions = new EditorRegions (this);
549 _snapshots = new EditorSnapshots (this);
550 _locations = new EditorLocations (this);
554 nlabel = manage (new Label (_("Regions")));
555 nlabel->set_angle (-90);
556 the_notebook.append_page (_regions->widget (), *nlabel);
557 nlabel = manage (new Label (_("Tracks & Busses")));
558 nlabel->set_angle (-90);
559 the_notebook.append_page (_routes->widget (), *nlabel);
560 nlabel = manage (new Label (_("Snapshots")));
561 nlabel->set_angle (-90);
562 the_notebook.append_page (_snapshots->widget (), *nlabel);
563 nlabel = manage (new Label (_("Route Groups")));
564 nlabel->set_angle (-90);
565 the_notebook.append_page (_route_groups->widget (), *nlabel);
566 nlabel = manage (new Label (_("Ranges & Marks")));
567 nlabel->set_angle (-90);
568 the_notebook.append_page (_locations->widget (), *nlabel);
570 the_notebook.set_show_tabs (true);
571 the_notebook.set_scrollable (true);
572 the_notebook.popup_disable ();
573 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
574 the_notebook.show_all ();
576 post_maximal_editor_width = 0;
577 post_maximal_horizontal_pane_position = 0;
578 post_maximal_editor_height = 0;
579 post_maximal_vertical_pane_position = 0;
581 editor_summary_pane.pack1(edit_packer);
583 Button* summary_arrows_left_left = manage (new Button);
584 summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
585 summary_arrows_left_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
586 Button* summary_arrows_left_right = manage (new Button);
587 summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
588 summary_arrows_left_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
589 VBox* summary_arrows_left = manage (new VBox);
590 summary_arrows_left->pack_start (*summary_arrows_left_left);
591 summary_arrows_left->pack_start (*summary_arrows_left_right);
593 Button* summary_arrows_right_left = manage (new Button);
594 summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
595 summary_arrows_right_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
596 Button* summary_arrows_right_right = manage (new Button);
597 summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
598 summary_arrows_right_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
599 VBox* summary_arrows_right = manage (new VBox);
600 summary_arrows_right->pack_start (*summary_arrows_right_left);
601 summary_arrows_right->pack_start (*summary_arrows_right_right);
603 Frame* summary_frame = manage (new Frame);
604 summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
605 summary_frame->add (*_summary);
606 summary_frame->show ();
608 _summary_hbox.pack_start (*summary_arrows_left, false, false);
609 _summary_hbox.pack_start (*summary_frame, true, true);
610 _summary_hbox.pack_start (*summary_arrows_right, false, false);
612 editor_summary_pane.pack2 (_summary_hbox);
614 edit_pane.pack1 (editor_summary_pane, true, true);
615 edit_pane.pack2 (the_notebook, false, true);
617 editor_summary_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&editor_summary_pane)));
619 /* XXX: editor_summary_pane might need similar special OS X treatment to the edit_pane */
621 edit_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
623 Glib::PropertyProxy<int> proxy = edit_pane.property_position();
624 proxy.signal_changed().connect (bind (sigc::ptr_fun (pane_size_watcher), static_cast<Paned*> (&edit_pane)));
626 top_hbox.pack_start (toolbar_frame, false, true);
628 HBox *hbox = manage (new HBox);
629 hbox->pack_start (edit_pane, true, true);
631 global_vpacker.pack_start (top_hbox, false, false);
632 global_vpacker.pack_start (*hbox, true, true);
634 global_hpacker.pack_start (global_vpacker, true, true);
636 set_name ("EditorWindow");
637 add_accel_group (ActionManager::ui_manager->get_accel_group());
639 status_bar_hpacker.show ();
641 vpacker.pack_end (status_bar_hpacker, false, false);
642 vpacker.pack_end (global_hpacker, true, true);
644 /* register actions now so that set_state() can find them and set toggles/checks etc */
649 setup_midi_toolbar ();
651 _snap_type = SnapToBeat;
652 set_snap_to (_snap_type);
653 _snap_mode = SnapOff;
654 set_snap_mode (_snap_mode);
655 set_mouse_mode (MouseObject, true);
656 set_edit_point_preference (EditAtMouse, true);
658 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
659 set_state (*node, Stateful::loading_state_version);
661 _playlist_selector = new PlaylistSelector();
662 _playlist_selector->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
664 RegionView::RegionViewGoingAway.connect (*this, invalidator (*this), ui_bind (&Editor::catch_vanishing_regionview, this, _1), gui_context());
668 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
669 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
671 nudge_forward_button.set_name ("TransportButton");
672 nudge_backward_button.set_name ("TransportButton");
674 fade_context_menu.set_name ("ArdourContextMenu");
676 /* icons, titles, WM stuff */
678 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
679 Glib::RefPtr<Gdk::Pixbuf> icon;
681 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
682 window_icons.push_back (icon);
684 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
685 window_icons.push_back (icon);
687 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
688 window_icons.push_back (icon);
690 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
691 window_icons.push_back (icon);
693 if (!window_icons.empty()) {
694 set_icon_list (window_icons);
695 set_default_icon_list (window_icons);
698 WindowTitle title(Glib::get_application_name());
699 title += _("Editor");
700 set_title (title.get_string());
701 set_wmclass (X_("ardour_editor"), "Ardour");
704 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
706 signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
707 signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
709 /* allow external control surfaces/protocols to do various things */
711 ControlProtocol::ZoomToSession.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_session, this), gui_context());
712 ControlProtocol::ZoomIn.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
713 ControlProtocol::ZoomOut.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
714 ControlProtocol::ScrollTimeline.connect (*this, invalidator (*this), ui_bind (&Editor::control_scroll, this, _1), gui_context());
715 BasicUI::AccessAction.connect (*this, invalidator (*this), ui_bind (&Editor::access_action, this, _1, _2), gui_context());
717 /* problematic: has to return a value and thus cannot be x-thread */
719 Session::AskAboutPlaylistDeletion.connect_same_thread (*this, boost::bind (&Editor::playlist_deletion_dialog, this, _1));
721 Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
723 TimeAxisView::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&Editor::timeaxisview_deleted, this, _1), gui_context());
725 _last_normalization_value = 0;
734 if(image_socket_listener) {
735 if(image_socket_listener->is_connected())
737 image_socket_listener->close_connection() ;
740 delete image_socket_listener ;
741 image_socket_listener = 0 ;
746 delete _route_groups;
752 Editor::add_toplevel_controls (Container& cont)
754 vpacker.pack_start (cont, false, false);
759 Editor::catch_vanishing_regionview (RegionView *rv)
761 /* note: the selection will take care of the vanishing
762 audioregionview by itself.
765 if (_drags->active() && _drags->have_item (rv->get_canvas_group()) && !_drags->ending()) {
769 if (clicked_regionview == rv) {
770 clicked_regionview = 0;
773 if (entered_regionview == rv) {
774 set_entered_regionview (0);
779 Editor::set_entered_regionview (RegionView* rv)
781 if (rv == entered_regionview) {
785 if (entered_regionview) {
786 entered_regionview->exited ();
789 if ((entered_regionview = rv) != 0) {
790 entered_regionview->entered ();
795 Editor::set_entered_track (TimeAxisView* tav)
798 entered_track->exited ();
801 if ((entered_track = tav) != 0) {
802 entered_track->entered ();
807 Editor::show_window ()
809 if (! is_visible ()) {
812 /* re-hide editor list if necessary */
813 editor_list_button_toggled ();
815 /* re-hide summary widget if necessary */
816 parameter_changed ("show-summary");
818 parameter_changed ("show-edit-group-tabs");
820 /* now reset all audio_time_axis heights, because widgets might need
826 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
827 tv = (static_cast<TimeAxisView*>(*i));
831 reset_zoom (frames_per_unit);
838 Editor::instant_save ()
840 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
845 _session->add_instant_xml(get_state());
847 Config->add_instant_xml(get_state());
852 Editor::zoom_adjustment_changed ()
858 double fpu = zoom_range_clock.current_duration() / _canvas_width;
862 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
863 } else if (fpu > _session->current_end_frame() / _canvas_width) {
864 fpu = _session->current_end_frame() / _canvas_width;
865 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
872 Editor::control_scroll (float fraction)
874 ENSURE_GUI_THREAD (*this, &Editor::control_scroll, fraction)
880 double step = fraction * current_page_frames();
883 _control_scroll_target is an optional<T>
885 it acts like a pointer to an nframes64_t, with
886 a operator conversion to boolean to check
887 that it has a value could possibly use
888 playhead_cursor->current_frame to store the
889 value and a boolean in the class to know
890 when it's out of date
893 if (!_control_scroll_target) {
894 _control_scroll_target = _session->transport_frame();
895 _dragging_playhead = true;
898 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
899 *_control_scroll_target = 0;
900 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
901 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
903 *_control_scroll_target += (nframes64_t) floor (step);
906 /* move visuals, we'll catch up with it later */
908 playhead_cursor->set_position (*_control_scroll_target);
909 UpdateAllTransportClocks (*_control_scroll_target);
911 if (*_control_scroll_target > (current_page_frames() / 2)) {
912 /* try to center PH in window */
913 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
919 Now we do a timeout to actually bring the session to the right place
920 according to the playhead. This is to avoid reading disk buffers on every
921 call to control_scroll, which is driven by ScrollTimeline and therefore
922 probably by a control surface wheel which can generate lots of events.
924 /* cancel the existing timeout */
926 control_scroll_connection.disconnect ();
928 /* add the next timeout */
930 control_scroll_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
934 Editor::deferred_control_scroll (nframes64_t /*target*/)
936 _session->request_locate (*_control_scroll_target, _session->transport_rolling());
937 // reset for next stream
938 _control_scroll_target = boost::none;
939 _dragging_playhead = false;
944 Editor::access_action (std::string action_group, std::string action_item)
950 ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
953 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
961 Editor::on_realize ()
963 Window::on_realize ();
968 Editor::map_position_change (nframes64_t frame)
970 ENSURE_GUI_THREAD (*this, &Editor::map_position_change, frame)
972 if (_session == 0 || !_follow_playhead) {
976 center_screen (frame);
977 playhead_cursor->set_position (frame);
981 Editor::center_screen (nframes64_t frame)
983 double page = _canvas_width * frames_per_unit;
985 /* if we're off the page, then scroll.
988 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
989 center_screen_internal (frame, page);
994 Editor::center_screen_internal (nframes64_t frame, float page)
999 frame -= (nframes64_t) page;
1004 reset_x_origin (frame);
1009 Editor::update_title ()
1011 ENSURE_GUI_THREAD (*this, &Editor::update_title)
1014 bool dirty = _session->dirty();
1016 string session_name;
1018 if (_session->snap_name() != _session->name()) {
1019 session_name = _session->snap_name();
1021 session_name = _session->name();
1025 session_name = "*" + session_name;
1028 WindowTitle title(session_name);
1029 title += Glib::get_application_name();
1030 set_title (title.get_string());
1035 Editor::set_session (Session *t)
1037 SessionHandlePtr::set_session (t);
1043 zoom_range_clock.set_session (_session);
1044 _playlist_selector->set_session (_session);
1045 nudge_clock.set_session (_session);
1046 _summary->set_session (_session);
1047 _group_tabs->set_session (_session);
1048 _route_groups->set_session (_session);
1049 _regions->set_session (_session);
1050 _snapshots->set_session (_session);
1051 _routes->set_session (_session);
1052 _locations->set_session (_session);
1054 if (rhythm_ferret) {
1055 rhythm_ferret->set_session (_session);
1058 if (analysis_window) {
1059 analysis_window->set_session (_session);
1063 sfbrowser->set_session (_session);
1066 compute_fixed_ruler_scale ();
1068 /* there are never any selected regions at startup */
1069 sensitize_the_right_region_actions (false);
1071 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1072 set_state (*node, Stateful::loading_state_version);
1074 /* catch up with the playhead */
1076 _session->request_locate (playhead_cursor->current_frame);
1077 _pending_initial_locate = true;
1081 /* These signals can all be emitted by a non-GUI thread. Therefore the
1082 handlers for them must not attempt to directly interact with the GUI,
1083 but use Gtkmm2ext::UI::instance()->call_slot();
1086 _session->TransportStateChange.connect (_session_connections, invalidator (*this), boost::bind (&Editor::map_transport_state, this), gui_context());
1087 _session->PositionChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::map_position_change, this, _1), gui_context());
1088 _session->RouteAdded.connect (_session_connections, invalidator (*this), ui_bind (&Editor::handle_new_route, this, _1), gui_context());
1089 _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_title, this), gui_context());
1090 _session->TimecodeOffsetChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_just_timecode, this), gui_context());
1091 _session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::tempo_map_changed, this, _1), gui_context());
1092 _session->Located.connect (_session_connections, invalidator (*this), boost::bind (&Editor::located, this), gui_context());
1093 _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
1094 _session->StateSaved.connect (_session_connections, invalidator (*this), ui_bind (&Editor::session_state_saved, this, _1), gui_context());
1095 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&Editor::add_new_location, this, _1), gui_context());
1096 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&Editor::location_gone, this, _1), gui_context());
1097 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::refresh_location_display, this), gui_context());
1098 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::refresh_location_display_s, this, _1), gui_context());
1099 _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context());
1101 if (Profile->get_sae()) {
1106 nframes_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
1107 nudge_clock.set_mode(AudioClock::BBT);
1108 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1111 nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
1114 playhead_cursor->canvas_item.show ();
1116 Location* loc = _session->locations()->auto_loop_location();
1118 loc = new Location (0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1119 if (loc->start() == loc->end()) {
1120 loc->set_end (loc->start() + 1);
1122 _session->locations()->add (loc, false);
1123 _session->set_auto_loop_location (loc);
1126 loc->set_name (_("Loop"));
1129 loc = _session->locations()->auto_punch_location();
1131 loc = new Location (0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1132 if (loc->start() == loc->end()) {
1133 loc->set_end (loc->start() + 1);
1135 _session->locations()->add (loc, false);
1136 _session->set_auto_punch_location (loc);
1139 loc->set_name (_("Punch"));
1142 boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
1143 Config->map_parameters (pc);
1144 _session->config.map_parameters (pc);
1146 refresh_location_display ();
1148 restore_ruler_visibility ();
1149 //tempo_map_changed (PropertyChange (0));
1150 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1152 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1153 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1156 super_rapid_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
1157 sigc::mem_fun (*this, &Editor::super_rapid_screen_update)
1160 switch (_snap_type) {
1161 case SnapToRegionStart:
1162 case SnapToRegionEnd:
1163 case SnapToRegionSync:
1164 case SnapToRegionBoundary:
1165 build_region_boundary_cache ();
1172 /* register for undo history */
1173 _session->register_with_memento_command_factory(_id, this);
1175 start_updating_meters ();
1179 Editor::build_cursors ()
1181 using namespace Gdk;
1183 Gdk::Color mbg ("#000000" ); /* Black */
1184 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1187 RefPtr<Bitmap> source, mask;
1188 source = Bitmap::create (mag_bits, mag_width, mag_height);
1189 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1190 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1193 Gdk::Color fbg ("#ffffff" );
1194 Gdk::Color ffg ("#000000" );
1197 RefPtr<Bitmap> source, mask;
1199 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1200 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1201 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1205 RefPtr<Bitmap> source, mask;
1206 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1207 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1208 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1212 RefPtr<Bitmap> bits;
1213 char pix[4] = { 0, 0, 0, 0 };
1214 bits = Bitmap::create (pix, 2, 2);
1216 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1220 RefPtr<Bitmap> bits;
1221 char pix[4] = { 0, 0, 0, 0 };
1222 bits = Bitmap::create (pix, 2, 2);
1224 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1228 grabber_cursor = new Gdk::Cursor (HAND2);
1231 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1232 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1235 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1236 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1237 selector_cursor = new Gdk::Cursor (XTERM);
1238 time_fx_cursor = new Gdk::Cursor (SIZING);
1239 wait_cursor = new Gdk::Cursor (WATCH);
1240 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1241 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1242 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1243 midi_resize_cursor = new Gdk::Cursor (SIZING);
1244 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1247 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1249 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1251 using namespace Menu_Helpers;
1252 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1255 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1259 MenuList& items (fade_context_menu.items());
1263 switch (item_type) {
1265 case FadeInHandleItem:
1266 if (arv->audio_region()->fade_in_active()) {
1267 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), false)));
1269 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), true)));
1272 items.push_back (SeparatorElem());
1274 if (Profile->get_sae()) {
1275 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1276 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1278 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1279 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1280 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1281 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1282 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1288 case FadeOutHandleItem:
1289 if (arv->audio_region()->fade_out_active()) {
1290 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), false)));
1292 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), true)));
1295 items.push_back (SeparatorElem());
1297 if (Profile->get_sae()) {
1298 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1299 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1301 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1302 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1303 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1304 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1305 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1311 fatal << _("programming error: ")
1312 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1317 fade_context_menu.popup (button, time);
1321 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1323 using namespace Menu_Helpers;
1324 Menu* (Editor::*build_menu_function)(nframes64_t);
1327 switch (item_type) {
1329 case RegionViewName:
1330 case RegionViewNameHighlight:
1331 if (with_selection) {
1332 build_menu_function = &Editor::build_track_selection_context_menu;
1334 build_menu_function = &Editor::build_track_region_context_menu;
1339 if (with_selection) {
1340 build_menu_function = &Editor::build_track_selection_context_menu;
1342 build_menu_function = &Editor::build_track_context_menu;
1346 case CrossfadeViewItem:
1347 build_menu_function = &Editor::build_track_crossfade_context_menu;
1351 if (clicked_routeview->track()) {
1352 build_menu_function = &Editor::build_track_context_menu;
1354 build_menu_function = &Editor::build_track_bus_context_menu;
1359 /* probably shouldn't happen but if it does, we don't care */
1363 menu = (this->*build_menu_function)(frame);
1364 menu->set_name ("ArdourContextMenu");
1366 /* now handle specific situations */
1368 switch (item_type) {
1370 case RegionViewName:
1371 case RegionViewNameHighlight:
1372 if (!with_selection) {
1373 if (region_edit_menu_split_item) {
1374 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1375 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1377 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1380 if (region_edit_menu_split_multichannel_item) {
1381 if (clicked_regionview && clicked_regionview->region()->n_channels() > 1) {
1382 region_edit_menu_split_multichannel_item->set_sensitive (true);
1384 region_edit_menu_split_multichannel_item->set_sensitive (false);
1393 case CrossfadeViewItem:
1400 /* probably shouldn't happen but if it does, we don't care */
1404 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1406 /* Bounce to disk */
1408 using namespace Menu_Helpers;
1409 MenuList& edit_items = menu->items();
1411 edit_items.push_back (SeparatorElem());
1413 switch (clicked_routeview->audio_track()->freeze_state()) {
1414 case AudioTrack::NoFreeze:
1415 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1418 case AudioTrack::Frozen:
1419 edit_items.push_back (MenuElem (_("Unfreeze"), sigc::mem_fun(*this, &Editor::unfreeze_route)));
1422 case AudioTrack::UnFrozen:
1423 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1429 if (item_type == StreamItem && clicked_routeview) {
1430 clicked_routeview->build_underlay_menu(menu);
1433 menu->popup (button, time);
1437 Editor::build_track_context_menu (nframes64_t)
1439 using namespace Menu_Helpers;
1441 MenuList& edit_items = track_context_menu.items();
1444 add_dstream_context_items (edit_items);
1445 return &track_context_menu;
1449 Editor::build_track_bus_context_menu (nframes64_t)
1451 using namespace Menu_Helpers;
1453 MenuList& edit_items = track_context_menu.items();
1456 add_bus_context_items (edit_items);
1457 return &track_context_menu;
1461 Editor::build_track_region_context_menu (nframes64_t frame)
1463 using namespace Menu_Helpers;
1464 MenuList& edit_items = track_region_context_menu.items();
1467 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1470 boost::shared_ptr<Track> tr;
1471 boost::shared_ptr<Playlist> pl;
1473 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
1474 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * tr->speed()));
1476 if (selection->regions.size() > 1) {
1477 // there's already a multiple selection: just add a
1478 // single region context menu that will act on all
1480 boost::shared_ptr<Region> dummy_region; // = NULL
1481 add_region_context_items (rtv->view(), dummy_region, edit_items);
1483 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1484 add_region_context_items (rtv->view(), (*i), edit_items);
1492 add_dstream_context_items (edit_items);
1494 return &track_region_context_menu;
1498 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1500 using namespace Menu_Helpers;
1501 MenuList& edit_items = track_crossfade_context_menu.items();
1502 edit_items.clear ();
1504 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1507 boost::shared_ptr<Track> tr;
1508 boost::shared_ptr<Playlist> pl;
1509 boost::shared_ptr<AudioPlaylist> apl;
1511 if ((tr = atv->track()) && ((pl = tr->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1513 Playlist::RegionList* regions = pl->regions_at (frame);
1514 AudioPlaylist::Crossfades xfades;
1516 apl->crossfades_at (frame, xfades);
1518 bool many = xfades.size() > 1;
1520 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1521 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1524 if (selection->regions.size() > 1) {
1525 // there's already a multiple selection: just add a
1526 // single region context menu that will act on all
1528 boost::shared_ptr<Region> dummy_region; // = NULL
1529 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1531 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1532 add_region_context_items (atv->audio_view(), (*i), edit_items);
1539 add_dstream_context_items (edit_items);
1541 return &track_crossfade_context_menu;
1545 Editor::analyze_region_selection()
1547 if (analysis_window == 0) {
1548 analysis_window = new AnalysisWindow();
1551 analysis_window->set_session(_session);
1553 analysis_window->show_all();
1556 analysis_window->set_regionmode();
1557 analysis_window->analyze();
1559 analysis_window->present();
1563 Editor::analyze_range_selection()
1565 if (analysis_window == 0) {
1566 analysis_window = new AnalysisWindow();
1569 analysis_window->set_session(_session);
1571 analysis_window->show_all();
1574 analysis_window->set_rangemode();
1575 analysis_window->analyze();
1577 analysis_window->present();
1581 Editor::build_track_selection_context_menu (nframes64_t)
1583 using namespace Menu_Helpers;
1584 MenuList& edit_items = track_selection_context_menu.items();
1585 edit_items.clear ();
1587 add_selection_context_items (edit_items);
1588 // edit_items.push_back (SeparatorElem());
1589 // add_dstream_context_items (edit_items);
1591 return &track_selection_context_menu;
1594 /** Add context menu items relevant to crossfades.
1595 * @param edit_items List to add the items to.
1598 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1600 using namespace Menu_Helpers;
1601 Menu *xfade_menu = manage (new Menu);
1602 MenuList& items = xfade_menu->items();
1603 xfade_menu->set_name ("ArdourContextMenu");
1606 if (xfade->active()) {
1612 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1613 items.push_back (MenuElem (_("Edit"), sigc::bind (sigc::mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1615 if (xfade->can_follow_overlap()) {
1617 if (xfade->following_overlap()) {
1618 str = _("Convert to Short");
1620 str = _("Convert to Full");
1623 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1627 str = xfade->out()->name();
1629 str += xfade->in()->name();
1631 str = _("Crossfade");
1634 edit_items.push_back (MenuElem (str, *xfade_menu));
1635 edit_items.push_back (SeparatorElem());
1639 Editor::xfade_edit_left_region ()
1641 if (clicked_crossfadeview) {
1642 clicked_crossfadeview->left_view.show_region_editor ();
1647 Editor::xfade_edit_right_region ()
1649 if (clicked_crossfadeview) {
1650 clicked_crossfadeview->right_view.show_region_editor ();
1655 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1657 using namespace Menu_Helpers;
1658 Gtk::MenuItem* foo_item;
1659 Menu *region_menu = manage (new Menu);
1660 MenuList& items = region_menu->items();
1661 region_menu->set_name ("ArdourContextMenu");
1663 boost::shared_ptr<AudioRegion> ar;
1664 boost::shared_ptr<MidiRegion> mr;
1667 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1668 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1670 /* when this particular menu pops up, make the relevant region
1674 region_menu->signal_map_event().connect (
1675 sigc::bind (sigc::mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1677 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::rename_region)));
1679 items.push_back (MenuElem (_("List Editor..."), sigc::mem_fun(*this, &Editor::show_midi_list_editor)));
1681 items.push_back (MenuElem (_("Region Properties..."), sigc::mem_fun(*this, &Editor::edit_region)));
1684 items.push_back (MenuElem (_("Raise to Top Layer"), sigc::mem_fun(*this, &Editor::raise_region_to_top)));
1685 items.push_back (MenuElem (_("Lower to Bottom Layer"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom)));
1686 items.push_back (SeparatorElem());
1687 items.push_back (MenuElem (_("Define Sync Point"), sigc::mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1688 if (_edit_point == EditAtMouse) {
1689 items.back ().set_sensitive (false);
1691 items.push_back (MenuElem (_("Remove Sync Point"), sigc::mem_fun(*this, &Editor::remove_region_sync)));
1692 items.push_back (SeparatorElem());
1694 items.push_back (MenuElem (_("Audition"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1695 items.push_back (MenuElem (_("Export..."), sigc::mem_fun(*this, &Editor::export_region)));
1696 items.push_back (MenuElem (_("Bounce"), sigc::mem_fun(*this, &Editor::bounce_region_selection)));
1699 items.push_back (MenuElem (_("Spectral Analysis..."), sigc::mem_fun(*this, &Editor::analyze_region_selection)));
1702 items.push_back (SeparatorElem());
1704 sigc::connection fooc;
1705 boost::shared_ptr<Region> region_to_check;
1708 region_to_check = region;
1710 region_to_check = selection->regions.front()->region();
1713 items.push_back (CheckMenuElem (_("Lock")));
1714 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1715 if (region_to_check->locked()) {
1716 region_lock_item->set_active();
1718 region_lock_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_lock));
1720 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
1721 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1723 switch (region_to_check->positional_lock_style()) {
1724 case Region::MusicTime:
1725 bbt_glue_item->set_active (true);
1728 bbt_glue_item->set_active (false);
1732 bbt_glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_region_lock_style));
1734 items.push_back (CheckMenuElem (_("Mute")));
1735 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1736 fooc = region_mute_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_mute));
1737 if (region_to_check->muted()) {
1739 region_mute_item->set_active();
1743 items.push_back (MenuElem (_("Transpose..."), mem_fun(*this, &Editor::pitch_shift_regions)));
1745 if (!Profile->get_sae()) {
1746 items.push_back (CheckMenuElem (_("Opaque")));
1747 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1748 fooc = region_opaque_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_opaque));
1749 if (region_to_check->opaque()) {
1751 region_opaque_item->set_active();
1756 items.push_back (CheckMenuElem (_("Original Position"), sigc::mem_fun(*this, &Editor::naturalize)));
1757 if (region_to_check->at_natural_position()) {
1758 items.back().set_sensitive (false);
1761 items.push_back (SeparatorElem());
1765 RegionView* rv = sv->find_view (ar);
1766 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1768 if (!Profile->get_sae()) {
1769 items.push_back (MenuElem (_("Reset Envelope"), sigc::mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1771 items.push_back (CheckMenuElem (_("Envelope Visible")));
1772 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1773 fooc = region_envelope_visible_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1774 if (arv->envelope_visible()) {
1776 region_envelope_visible_item->set_active (true);
1780 items.push_back (CheckMenuElem (_("Envelope Active")));
1781 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1782 fooc = region_envelope_active_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_active));
1784 if (ar->envelope_active()) {
1786 region_envelope_active_item->set_active (true);
1790 items.push_back (SeparatorElem());
1793 items.push_back (MenuElem (_("Normalize..."), sigc::mem_fun(*this, &Editor::normalize_region)));
1794 if (ar->scale_amplitude() != 1) {
1795 items.push_back (MenuElem (_("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_scale_amplitude)));
1799 items.push_back (MenuElem (_("Quantize"), sigc::mem_fun(*this, &Editor::quantize_region)));
1800 items.push_back (MenuElem (_("Fork"), sigc::mem_fun(*this, &Editor::fork_region)));
1801 items.push_back (SeparatorElem());
1804 items.push_back (MenuElem (_("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence)));
1805 items.push_back (MenuElem (_("Reverse"), sigc::mem_fun(*this, &Editor::reverse_region)));
1806 items.push_back (SeparatorElem());
1808 /* range related stuff */
1810 items.push_back (MenuElem (_("Add Single Range"), sigc::mem_fun (*this, &Editor::add_location_from_audio_region)));
1811 items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_locations_from_audio_region)));
1812 if (selection->regions.size() < 2) {
1813 items.back().set_sensitive (false);
1816 items.push_back (MenuElem (_("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region)));
1817 items.push_back (SeparatorElem());
1821 Menu *nudge_menu = manage (new Menu());
1822 MenuList& nudge_items = nudge_menu->items();
1823 nudge_menu->set_name ("ArdourContextMenu");
1825 nudge_items.push_back (MenuElem (_("Nudge Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_forward), false, false))));
1826 nudge_items.push_back (MenuElem (_("Nudge Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_backward), false, false))));
1827 nudge_items.push_back (MenuElem (_("Nudge Forward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1828 nudge_items.push_back (MenuElem (_("Nudge Backward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1830 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1831 items.push_back (SeparatorElem());
1833 Menu *trim_menu = manage (new Menu);
1834 MenuList& trim_items = trim_menu->items();
1835 trim_menu->set_name ("ArdourContextMenu");
1837 trim_items.push_back (MenuElem (_("Start to Edit Point"), sigc::mem_fun(*this, &Editor::trim_region_from_edit_point)));
1838 foo_item = &trim_items.back();
1839 if (_edit_point == EditAtMouse) {
1840 foo_item->set_sensitive (false);
1842 trim_items.push_back (MenuElem (_("Edit Point to End"), sigc::mem_fun(*this, &Editor::trim_region_to_edit_point)));
1843 foo_item = &trim_items.back();
1844 if (_edit_point == EditAtMouse) {
1845 foo_item->set_sensitive (false);
1847 trim_items.push_back (MenuElem (_("Trim to Loop"), sigc::mem_fun(*this, &Editor::trim_region_to_loop)));
1848 trim_items.push_back (MenuElem (_("Trim to Punch"), sigc::mem_fun(*this, &Editor::trim_region_to_punch)));
1850 items.push_back (MenuElem (_("Trim"), *trim_menu));
1851 items.push_back (SeparatorElem());
1853 items.push_back (MenuElem (_("Split"), (sigc::mem_fun(*this, &Editor::split))));
1854 region_edit_menu_split_item = &items.back();
1856 if (_edit_point == EditAtMouse) {
1857 region_edit_menu_split_item->set_sensitive (false);
1860 items.push_back (MenuElem (_("Make Mono Regions"), (sigc::mem_fun(*this, &Editor::split_multichannel_region))));
1861 region_edit_menu_split_multichannel_item = &items.back();
1863 items.push_back (MenuElem (_("Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false))));
1864 items.push_back (MenuElem (_("Multi-Duplicate..."), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), true))));
1865 items.push_back (MenuElem (_("Fill Track"), (sigc::mem_fun(*this, &Editor::region_fill_track))));
1866 items.push_back (SeparatorElem());
1867 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::remove_selected_regions)));
1869 /* OK, stick the region submenu at the top of the list, and then add
1873 /* we have to hack up the region name because "_" has a special
1874 meaning for menu titles.
1877 string::size_type pos = 0;
1878 string menu_item_name = (region) ? region->name() : _("Selected Regions");
1880 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1881 menu_item_name.replace (pos, 1, "__");
1885 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1886 edit_items.push_back (SeparatorElem());
1889 /** Add context menu items relevant to selection ranges.
1890 * @param edit_items List to add the items to.
1893 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1895 using namespace Menu_Helpers;
1897 edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
1898 edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
1900 edit_items.push_back (SeparatorElem());
1901 edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
1903 if (!selection->regions.empty()) {
1904 edit_items.push_back (SeparatorElem());
1905 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)));
1906 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)));
1909 edit_items.push_back (SeparatorElem());
1910 edit_items.push_back (MenuElem (_("Silence Range"), sigc::mem_fun(*this, &Editor::separate_region_from_selection)));
1911 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
1913 edit_items.push_back (SeparatorElem());
1914 edit_items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1916 edit_items.push_back (SeparatorElem());
1917 edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false)));
1918 edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
1920 edit_items.push_back (SeparatorElem());
1921 edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
1923 edit_items.push_back (SeparatorElem());
1924 edit_items.push_back (MenuElem (_("Crop Region to Range"), sigc::mem_fun(*this, &Editor::crop_region_to_selection)));
1925 edit_items.push_back (MenuElem (_("Fill Range with Region"), sigc::mem_fun(*this, &Editor::region_fill_selection)));
1926 edit_items.push_back (MenuElem (_("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false)));
1928 edit_items.push_back (SeparatorElem());
1929 edit_items.push_back (MenuElem (_("Consolidate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1930 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1931 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1932 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1933 edit_items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_selection)));
1938 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1940 using namespace Menu_Helpers;
1944 Menu *play_menu = manage (new Menu);
1945 MenuList& play_items = play_menu->items();
1946 play_menu->set_name ("ArdourContextMenu");
1948 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
1949 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
1950 play_items.push_back (MenuElem (_("Play Region"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1951 play_items.push_back (SeparatorElem());
1952 play_items.push_back (MenuElem (_("Loop Region"), sigc::mem_fun(*this, &Editor::loop_selected_region)));
1954 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1958 Menu *select_menu = manage (new Menu);
1959 MenuList& select_items = select_menu->items();
1960 select_menu->set_name ("ArdourContextMenu");
1962 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1963 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
1964 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
1965 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
1966 select_items.push_back (SeparatorElem());
1967 select_items.push_back (MenuElem (_("Set Range to Loop Range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop)));
1968 select_items.push_back (MenuElem (_("Set Range to Punch Range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch)));
1969 select_items.push_back (SeparatorElem());
1970 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1971 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1972 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1973 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1974 select_items.push_back (MenuElem (_("Select All Between Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
1975 select_items.push_back (MenuElem (_("Select All Within Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
1976 select_items.push_back (MenuElem (_("Select Range Between Playhead and Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
1978 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1982 Menu *cutnpaste_menu = manage (new Menu);
1983 MenuList& cutnpaste_items = cutnpaste_menu->items();
1984 cutnpaste_menu->set_name ("ArdourContextMenu");
1986 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
1987 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
1988 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
1990 cutnpaste_items.push_back (SeparatorElem());
1992 cutnpaste_items.push_back (MenuElem (_("Align"), sigc::bind (sigc::mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
1993 cutnpaste_items.push_back (MenuElem (_("Align Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
1995 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
1997 /* Adding new material */
1999 edit_items.push_back (SeparatorElem());
2000 edit_items.push_back (MenuElem (_("Insert Selected Region"), sigc::bind (sigc::mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2001 edit_items.push_back (MenuElem (_("Insert Existing Media"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2005 Menu *nudge_menu = manage (new Menu());
2006 MenuList& nudge_items = nudge_menu->items();
2007 nudge_menu->set_name ("ArdourContextMenu");
2009 edit_items.push_back (SeparatorElem());
2010 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2011 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2012 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2013 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2015 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2019 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2021 using namespace Menu_Helpers;
2025 Menu *play_menu = manage (new Menu);
2026 MenuList& play_items = play_menu->items();
2027 play_menu->set_name ("ArdourContextMenu");
2029 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
2030 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
2031 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2035 Menu *select_menu = manage (new Menu);
2036 MenuList& select_items = select_menu->items();
2037 select_menu->set_name ("ArdourContextMenu");
2039 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2040 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
2041 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
2042 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
2043 select_items.push_back (SeparatorElem());
2044 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2045 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2046 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2047 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2049 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2053 Menu *cutnpaste_menu = manage (new Menu);
2054 MenuList& cutnpaste_items = cutnpaste_menu->items();
2055 cutnpaste_menu->set_name ("ArdourContextMenu");
2057 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2058 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2059 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2061 Menu *nudge_menu = manage (new Menu());
2062 MenuList& nudge_items = nudge_menu->items();
2063 nudge_menu->set_name ("ArdourContextMenu");
2065 edit_items.push_back (SeparatorElem());
2066 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2067 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2068 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2069 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2071 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2075 Editor::snap_type() const
2081 Editor::snap_mode() const
2087 Editor::set_snap_to (SnapType st)
2089 unsigned int snap_ind = (unsigned int)st;
2093 if (snap_ind > snap_type_strings.size() - 1) {
2095 _snap_type = (SnapType)snap_ind;
2098 string str = snap_type_strings[snap_ind];
2100 if (str != snap_type_selector.get_active_text()) {
2101 snap_type_selector.set_active_text (str);
2106 switch (_snap_type) {
2107 case SnapToBeatDiv32:
2108 case SnapToBeatDiv28:
2109 case SnapToBeatDiv24:
2110 case SnapToBeatDiv16:
2111 case SnapToBeatDiv14:
2112 case SnapToBeatDiv12:
2113 case SnapToBeatDiv10:
2114 case SnapToBeatDiv8:
2115 case SnapToBeatDiv7:
2116 case SnapToBeatDiv6:
2117 case SnapToBeatDiv5:
2118 case SnapToBeatDiv4:
2119 case SnapToBeatDiv3:
2120 case SnapToBeatDiv2:
2121 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2122 update_tempo_based_rulers ();
2125 case SnapToRegionStart:
2126 case SnapToRegionEnd:
2127 case SnapToRegionSync:
2128 case SnapToRegionBoundary:
2129 build_region_boundary_cache ();
2137 SnapChanged (); /* EMIT SIGNAL */
2141 Editor::set_snap_mode (SnapMode mode)
2144 string str = snap_mode_strings[(int)mode];
2146 if (str != snap_mode_selector.get_active_text ()) {
2147 snap_mode_selector.set_active_text (str);
2153 Editor::set_edit_point_preference (EditPoint ep, bool force)
2155 bool changed = (_edit_point != ep);
2158 string str = edit_point_strings[(int)ep];
2160 if (str != edit_point_selector.get_active_text ()) {
2161 edit_point_selector.set_active_text (str);
2164 set_canvas_cursor ();
2166 if (!force && !changed) {
2170 const char* action=NULL;
2172 switch (_edit_point) {
2173 case EditAtPlayhead:
2174 action = "edit-at-playhead";
2176 case EditAtSelectedMarker:
2177 action = "edit-at-marker";
2180 action = "edit-at-mouse";
2184 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2186 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2190 bool in_track_canvas;
2192 if (!mouse_frame (foo, in_track_canvas)) {
2193 in_track_canvas = false;
2196 reset_canvas_action_sensitivity (in_track_canvas);
2202 Editor::set_state (const XMLNode& node, int /*version*/)
2204 const XMLProperty* prop;
2206 int x, y, xoff, yoff;
2209 if ((prop = node.property ("id")) != 0) {
2210 _id = prop->value ();
2213 g.base_width = default_width;
2214 g.base_height = default_height;
2220 if ((geometry = find_named_node (node, "geometry")) != 0) {
2224 if ((prop = geometry->property("x_size")) == 0) {
2225 prop = geometry->property ("x-size");
2228 g.base_width = atoi(prop->value());
2230 if ((prop = geometry->property("y_size")) == 0) {
2231 prop = geometry->property ("y-size");
2234 g.base_height = atoi(prop->value());
2237 if ((prop = geometry->property ("x_pos")) == 0) {
2238 prop = geometry->property ("x-pos");
2241 x = atoi (prop->value());
2244 if ((prop = geometry->property ("y_pos")) == 0) {
2245 prop = geometry->property ("y-pos");
2248 y = atoi (prop->value());
2251 if ((prop = geometry->property ("x_off")) == 0) {
2252 prop = geometry->property ("x-off");
2255 xoff = atoi (prop->value());
2257 if ((prop = geometry->property ("y_off")) == 0) {
2258 prop = geometry->property ("y-off");
2261 yoff = atoi (prop->value());
2265 set_default_size (g.base_width, g.base_height);
2268 if (_session && (prop = node.property ("playhead"))) {
2270 sscanf (prop->value().c_str(), "%" PRIi64, &pos);
2271 playhead_cursor->set_position (pos);
2273 playhead_cursor->set_position (0);
2276 if ((prop = node.property ("mixer-width"))) {
2277 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2280 if ((prop = node.property ("zoom-focus"))) {
2281 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2284 if ((prop = node.property ("zoom"))) {
2285 reset_zoom (PBD::atof (prop->value()));
2288 if ((prop = node.property ("snap-to"))) {
2289 set_snap_to ((SnapType) atoi (prop->value()));
2292 if ((prop = node.property ("snap-mode"))) {
2293 set_snap_mode ((SnapMode) atoi (prop->value()));
2296 if ((prop = node.property ("mouse-mode"))) {
2297 MouseMode m = str2mousemode(prop->value());
2298 set_mouse_mode (m, true);
2300 set_mouse_mode (MouseObject, true);
2303 if ((prop = node.property ("left-frame")) != 0){
2305 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
2306 reset_x_origin (pos);
2310 if ((prop = node.property ("y-origin")) != 0) {
2311 reset_y_origin (atof (prop->value ()));
2314 if ((prop = node.property ("internal-edit"))) {
2315 bool yn = string_is_affirmative (prop->value());
2316 RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit"));
2318 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2319 tact->set_active (!yn);
2320 tact->set_active (yn);
2324 if ((prop = node.property ("join-object-range"))) {
2325 join_object_range_button.set_active (string_is_affirmative (prop->value ()));
2328 if ((prop = node.property ("edit-point"))) {
2329 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2332 if ((prop = node.property ("show-measures"))) {
2333 bool yn = string_is_affirmative (prop->value());
2334 _show_measures = !yn;
2335 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2337 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2338 /* do it twice to force the change */
2339 tact->set_active (!yn);
2340 tact->set_active (yn);
2344 if ((prop = node.property ("follow-playhead"))) {
2345 bool yn = string_is_affirmative (prop->value());
2346 set_follow_playhead (yn);
2347 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2349 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2350 if (tact->get_active() != yn) {
2351 tact->set_active (yn);
2356 if ((prop = node.property ("stationary-playhead"))) {
2357 bool yn = (prop->value() == "yes");
2358 set_stationary_playhead (yn);
2359 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
2361 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2362 if (tact->get_active() != yn) {
2363 tact->set_active (yn);
2368 if ((prop = node.property ("region-list-sort-type"))) {
2369 RegionListSortType st;
2370 _regions->reset_sort_type ((RegionListSortType) string_2_enum (prop->value(), st), true);
2373 if ((prop = node.property ("xfades-visible"))) {
2374 bool yn = string_is_affirmative (prop->value());
2375 _xfade_visibility = !yn;
2376 // set_xfade_visibility (yn);
2379 if ((prop = node.property ("show-editor-mixer"))) {
2381 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2384 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2385 bool yn = string_is_affirmative (prop->value());
2387 /* do it twice to force the change */
2389 tact->set_active (!yn);
2390 tact->set_active (yn);
2394 if ((prop = node.property ("show-editor-list"))) {
2396 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2400 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2401 bool yn = string_is_affirmative (prop->value());
2403 /* do it twice to force the change */
2405 tact->set_active (!yn);
2406 tact->set_active (yn);
2410 if ((prop = node.property (X_("editor-list-page")))) {
2411 the_notebook.set_current_page (atoi (prop->value ()));
2418 Editor::get_state ()
2420 XMLNode* node = new XMLNode ("Editor");
2423 _id.print (buf, sizeof (buf));
2424 node->add_property ("id", buf);
2426 if (is_realized()) {
2427 Glib::RefPtr<Gdk::Window> win = get_window();
2429 int x, y, xoff, yoff, width, height;
2430 win->get_root_origin(x, y);
2431 win->get_position(xoff, yoff);
2432 win->get_size(width, height);
2434 XMLNode* geometry = new XMLNode ("geometry");
2436 snprintf(buf, sizeof(buf), "%d", width);
2437 geometry->add_property("x-size", string(buf));
2438 snprintf(buf, sizeof(buf), "%d", height);
2439 geometry->add_property("y-size", string(buf));
2440 snprintf(buf, sizeof(buf), "%d", x);
2441 geometry->add_property("x-pos", string(buf));
2442 snprintf(buf, sizeof(buf), "%d", y);
2443 geometry->add_property("y-pos", string(buf));
2444 snprintf(buf, sizeof(buf), "%d", xoff);
2445 geometry->add_property("x-off", string(buf));
2446 snprintf(buf, sizeof(buf), "%d", yoff);
2447 geometry->add_property("y-off", string(buf));
2448 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2449 geometry->add_property("edit-horizontal-pane-pos", string(buf));
2450 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&editor_summary_pane)->gobj()));
2451 geometry->add_property("edit-vertical-pane-pos", string(buf));
2453 node->add_child_nocopy (*geometry);
2456 maybe_add_mixer_strip_width (*node);
2458 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2459 node->add_property ("zoom-focus", buf);
2460 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2461 node->add_property ("zoom", buf);
2462 snprintf (buf, sizeof(buf), "%d", (int) _snap_type);
2463 node->add_property ("snap-to", buf);
2464 snprintf (buf, sizeof(buf), "%d", (int) _snap_mode);
2465 node->add_property ("snap-mode", buf);
2467 node->add_property ("edit-point", enum_2_string (_edit_point));
2469 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2470 node->add_property ("playhead", buf);
2471 snprintf (buf, sizeof (buf), "%" PRIi64, leftmost_frame);
2472 node->add_property ("left-frame", buf);
2473 snprintf (buf, sizeof (buf), "%f", vertical_adjustment.get_value ());
2474 node->add_property ("y-origin", buf);
2476 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2477 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2478 node->add_property ("stationary-playhead", _stationary_playhead ? "yes" : "no");
2479 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2480 node->add_property ("region-list-sort-type", enum_2_string (_regions->sort_type ()));
2481 node->add_property ("mouse-mode", enum2str(mouse_mode));
2482 node->add_property ("internal-edit", _internal_editing ? "yes" : "no");
2483 node->add_property ("join-object-range", join_object_range_button.get_active () ? "yes" : "no");
2485 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2487 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2488 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2491 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2493 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2494 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2497 snprintf (buf, sizeof (buf), "%d", the_notebook.get_current_page ());
2498 node->add_property (X_("editor-list-page"), buf);
2505 /** @param y y offset from the top of all trackviews.
2506 * @return pair: TimeAxisView that y is over, layer index.
2507 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2508 * in stacked region display mode, otherwise 0.
2510 std::pair<TimeAxisView *, layer_t>
2511 Editor::trackview_by_y_position (double y)
2513 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2515 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2521 return std::make_pair ( (TimeAxisView *) 0, 0);
2524 /** Snap a position to the grid, if appropriate, taking into account current
2525 * grid settings and also the state of any snap modifier keys that may be pressed.
2526 * @param start Position to snap.
2527 * @param event Event to get current key modifier information from, or 0.
2530 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2532 if (!_session || !event) {
2536 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2537 if (_snap_mode == SnapOff) {
2538 snap_to_internal (start, direction, for_mark);
2541 if (_snap_mode != SnapOff) {
2542 snap_to_internal (start, direction, for_mark);
2548 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2550 if (!_session || _snap_mode == SnapOff) {
2554 snap_to_internal (start, direction, for_mark);
2558 Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
2560 const nframes64_t one_timecode_second = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
2561 nframes64_t one_timecode_minute = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
2563 switch (_snap_type) {
2564 case SnapToTimecodeFrame:
2565 if (((direction == 0) && (fmod((double)start, (double)_session->frames_per_timecode_frame()) > (_session->frames_per_timecode_frame() / 2))) || (direction > 0)) {
2566 start = (nframes64_t) (ceil ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2568 start = (nframes64_t) (floor ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2572 case SnapToTimecodeSeconds:
2573 if (_session->timecode_offset_negative())
2575 start += _session->timecode_offset ();
2577 start -= _session->timecode_offset ();
2579 if (((direction == 0) && (start % one_timecode_second > one_timecode_second / 2)) || direction > 0) {
2580 start = (nframes64_t) ceil ((double) start / one_timecode_second) * one_timecode_second;
2582 start = (nframes64_t) floor ((double) start / one_timecode_second) * one_timecode_second;
2585 if (_session->timecode_offset_negative())
2587 start -= _session->timecode_offset ();
2589 start += _session->timecode_offset ();
2593 case SnapToTimecodeMinutes:
2594 if (_session->timecode_offset_negative())
2596 start += _session->timecode_offset ();
2598 start -= _session->timecode_offset ();
2600 if (((direction == 0) && (start % one_timecode_minute > one_timecode_minute / 2)) || direction > 0) {
2601 start = (nframes64_t) ceil ((double) start / one_timecode_minute) * one_timecode_minute;
2603 start = (nframes64_t) floor ((double) start / one_timecode_minute) * one_timecode_minute;
2605 if (_session->timecode_offset_negative())
2607 start -= _session->timecode_offset ();
2609 start += _session->timecode_offset ();
2613 fatal << "Editor::smpte_snap_to_internal() called with non-timecode snap type!" << endmsg;
2619 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2621 const nframes64_t one_second = _session->frame_rate();
2622 const nframes64_t one_minute = _session->frame_rate() * 60;
2623 nframes64_t presnap = start;
2627 switch (_snap_type) {
2628 case SnapToTimecodeFrame:
2629 case SnapToTimecodeSeconds:
2630 case SnapToTimecodeMinutes:
2631 return timecode_snap_to_internal (start, direction, for_mark);
2634 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2635 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2637 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2642 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2643 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2645 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2650 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2651 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2653 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2658 start = _session->tempo_map().round_to_bar (start, direction);
2662 start = _session->tempo_map().round_to_beat (start, direction);
2665 case SnapToBeatDiv32:
2666 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2668 case SnapToBeatDiv28:
2669 start = _session->tempo_map().round_to_beat_subdivision (start, 28, direction);
2671 case SnapToBeatDiv24:
2672 start = _session->tempo_map().round_to_beat_subdivision (start, 24, direction);
2674 case SnapToBeatDiv16:
2675 start = _session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2677 case SnapToBeatDiv14:
2678 start = _session->tempo_map().round_to_beat_subdivision (start, 14, direction);
2680 case SnapToBeatDiv12:
2681 start = _session->tempo_map().round_to_beat_subdivision (start, 12, direction);
2683 case SnapToBeatDiv10:
2684 start = _session->tempo_map().round_to_beat_subdivision (start, 10, direction);
2686 case SnapToBeatDiv8:
2687 start = _session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2689 case SnapToBeatDiv7:
2690 start = _session->tempo_map().round_to_beat_subdivision (start, 7, direction);
2692 case SnapToBeatDiv6:
2693 start = _session->tempo_map().round_to_beat_subdivision (start, 6, direction);
2695 case SnapToBeatDiv5:
2696 start = _session->tempo_map().round_to_beat_subdivision (start, 5, direction);
2698 case SnapToBeatDiv4:
2699 start = _session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2701 case SnapToBeatDiv3:
2702 start = _session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2704 case SnapToBeatDiv2:
2705 start = _session->tempo_map().round_to_beat_subdivision (start, 2, direction);
2713 _session->locations()->marks_either_side (start, before, after);
2715 if (before == max_frames) {
2717 } else if (after == max_frames) {
2719 } else if (before != max_frames && after != max_frames) {
2720 /* have before and after */
2721 if ((start - before) < (after - start)) {
2730 case SnapToRegionStart:
2731 case SnapToRegionEnd:
2732 case SnapToRegionSync:
2733 case SnapToRegionBoundary:
2734 if (!region_boundary_cache.empty()) {
2736 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2737 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2739 if (direction > 0) {
2740 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2742 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2745 if (next != region_boundary_cache.begin ()) {
2750 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2751 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2753 if (start > (p + n) / 2) {
2762 switch (_snap_mode) {
2768 if (presnap > start) {
2769 if (presnap > (start + unit_to_frame(snap_threshold))) {
2773 } else if (presnap < start) {
2774 if (presnap < (start - unit_to_frame(snap_threshold))) {
2780 /* handled at entry */
2788 Editor::setup_toolbar ()
2792 /* Mode Buttons (tool selection) */
2794 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2795 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2796 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2797 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2798 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2799 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2800 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2801 join_object_range_button.set_relief(Gtk::RELIEF_NONE);
2803 HBox* mode_box = manage(new HBox);
2804 mode_box->set_border_width (2);
2805 mode_box->set_spacing(4);
2807 /* table containing mode buttons */
2809 HBox* mouse_mode_button_box = manage (new HBox ());
2811 if (Profile->get_sae()) {
2812 mouse_mode_button_box->pack_start (mouse_move_button);
2814 mouse_mode_button_box->pack_start (mouse_move_button);
2815 mouse_mode_button_box->pack_start (join_object_range_button);
2816 mouse_mode_button_box->pack_start (mouse_select_button);
2819 mouse_mode_button_box->pack_start (mouse_zoom_button);
2821 if (!Profile->get_sae()) {
2822 mouse_mode_button_box->pack_start (mouse_gain_button);
2825 mouse_mode_button_box->pack_start (mouse_timefx_button);
2826 mouse_mode_button_box->pack_start (mouse_audition_button);
2827 mouse_mode_button_box->pack_start (internal_edit_button);
2829 vector<string> edit_mode_strings;
2830 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2831 if (!Profile->get_sae()) {
2832 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2834 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2836 edit_mode_selector.set_name ("EditModeSelector");
2837 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2838 edit_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_mode_selection_done));
2840 mode_box->pack_start (edit_mode_selector);
2841 mode_box->pack_start (*mouse_mode_button_box);
2843 _mouse_mode_tearoff = manage (new TearOff (*mode_box));
2844 _mouse_mode_tearoff->set_name ("MouseModeBase");
2845 _mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_mouse_mode_tearoff->tearoff_window()), false);
2847 if (Profile->get_sae()) {
2848 _mouse_mode_tearoff->set_can_be_torn_off (false);
2851 _mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2852 &_mouse_mode_tearoff->tearoff_window()));
2853 _mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2854 &_mouse_mode_tearoff->tearoff_window(), 1));
2855 _mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2856 &_mouse_mode_tearoff->tearoff_window()));
2857 _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2858 &_mouse_mode_tearoff->tearoff_window(), 1));
2860 mouse_move_button.set_mode (false);
2861 mouse_select_button.set_mode (false);
2862 mouse_gain_button.set_mode (false);
2863 mouse_zoom_button.set_mode (false);
2864 mouse_timefx_button.set_mode (false);
2865 mouse_audition_button.set_mode (false);
2866 join_object_range_button.set_mode (false);
2868 mouse_move_button.set_name ("MouseModeButton");
2869 mouse_select_button.set_name ("MouseModeButton");
2870 mouse_gain_button.set_name ("MouseModeButton");
2871 mouse_zoom_button.set_name ("MouseModeButton");
2872 mouse_timefx_button.set_name ("MouseModeButton");
2873 mouse_audition_button.set_name ("MouseModeButton");
2874 internal_edit_button.set_name ("MouseModeButton");
2875 join_object_range_button.set_name ("MouseModeButton");
2877 mouse_move_button.unset_flags (CAN_FOCUS);
2878 mouse_select_button.unset_flags (CAN_FOCUS);
2879 mouse_gain_button.unset_flags (CAN_FOCUS);
2880 mouse_zoom_button.unset_flags (CAN_FOCUS);
2881 mouse_timefx_button.unset_flags (CAN_FOCUS);
2882 mouse_audition_button.unset_flags (CAN_FOCUS);
2883 internal_edit_button.unset_flags (CAN_FOCUS);
2884 join_object_range_button.unset_flags (CAN_FOCUS);
2888 zoom_box.set_spacing (1);
2889 zoom_box.set_border_width (0);
2891 zoom_in_button.set_name ("EditorTimeButton");
2892 zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_MENU))));
2893 zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
2895 zoom_out_button.set_name ("EditorTimeButton");
2896 zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_MENU))));
2897 zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
2899 zoom_out_full_button.set_name ("EditorTimeButton");
2900 zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_MENU))));
2901 zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
2903 zoom_focus_selector.set_name ("ZoomFocusSelector");
2904 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2905 zoom_focus_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done));
2907 zoom_box.pack_start (zoom_out_button, false, false);
2908 zoom_box.pack_start (zoom_in_button, false, false);
2909 zoom_box.pack_start (zoom_out_full_button, false, false);
2911 /* Track zoom buttons */
2912 tav_expand_button.set_name ("TrackHeightButton");
2913 tav_expand_button.set_size_request(-1,20);
2914 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2915 tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
2917 tav_shrink_button.set_name ("TrackHeightButton");
2918 tav_shrink_button.set_size_request(-1,20);
2919 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2920 tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
2922 track_zoom_box.set_spacing (1);
2923 track_zoom_box.set_border_width (0);
2925 track_zoom_box.pack_start (tav_shrink_button, false, false);
2926 track_zoom_box.pack_start (tav_expand_button, false, false);
2928 HBox* zbc = manage (new HBox);
2929 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2930 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2931 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2932 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2934 snap_box.set_spacing (1);
2935 snap_box.set_border_width (2);
2937 snap_type_selector.set_name ("SnapTypeSelector");
2938 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2939 snap_type_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_type_selection_done));
2941 snap_mode_selector.set_name ("SnapModeSelector");
2942 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2943 snap_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_mode_selection_done));
2945 edit_point_selector.set_name ("EditPointSelector");
2946 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2947 edit_point_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_point_selection_done));
2949 snap_box.pack_start (snap_mode_selector, false, false);
2950 snap_box.pack_start (snap_type_selector, false, false);
2951 snap_box.pack_start (edit_point_selector, false, false);
2955 HBox *nudge_box = manage (new HBox);
2956 nudge_box->set_spacing(1);
2957 nudge_box->set_border_width (2);
2959 nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
2960 nudge_backward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_backward_release), false);
2962 nudge_box->pack_start (nudge_backward_button, false, false);
2963 nudge_box->pack_start (nudge_forward_button, false, false);
2964 nudge_box->pack_start (nudge_clock, false, false);
2967 /* Pack everything in... */
2969 HBox* hbox = manage (new HBox);
2970 hbox->set_spacing(10);
2972 _tools_tearoff = manage (new TearOff (*hbox));
2973 _tools_tearoff->set_name ("MouseModeBase");
2974 _tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_tools_tearoff->tearoff_window()), false);
2976 if (Profile->get_sae()) {
2977 _tools_tearoff->set_can_be_torn_off (false);
2980 _tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2981 &_tools_tearoff->tearoff_window()));
2982 _tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2983 &_tools_tearoff->tearoff_window(), 0));
2984 _tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2985 &_tools_tearoff->tearoff_window()));
2986 _tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2987 &_tools_tearoff->tearoff_window(), 0));
2989 toolbar_hbox.set_spacing (10);
2990 toolbar_hbox.set_border_width (1);
2992 toolbar_hbox.pack_start (*_mouse_mode_tearoff, false, false);
2993 toolbar_hbox.pack_start (*_tools_tearoff, false, false);
2995 hbox->pack_start (snap_box, false, false);
2996 hbox->pack_start (*nudge_box, false, false);
2997 hbox->pack_start (panic_box, false, false);
3001 toolbar_base.set_name ("ToolBarBase");
3002 toolbar_base.add (toolbar_hbox);
3004 toolbar_frame.set_shadow_type (SHADOW_OUT);
3005 toolbar_frame.set_name ("BaseFrame");
3006 toolbar_frame.add (toolbar_base);
3010 Editor::setup_tooltips ()
3012 ARDOUR_UI::instance()->set_tip (mouse_move_button, _("Select/Move Objects"));
3013 ARDOUR_UI::instance()->set_tip (mouse_gain_button, _("Draw Gain Automation"));
3014 ARDOUR_UI::instance()->set_tip (mouse_zoom_button, _("Select Zoom Range"));
3015 ARDOUR_UI::instance()->set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
3016 ARDOUR_UI::instance()->set_tip (mouse_audition_button, _("Listen to Specific Regions"));
3017 ARDOUR_UI::instance()->set_tip (join_object_range_button, _("Select/Move Objects or Ranges"));
3018 ARDOUR_UI::instance()->set_tip (internal_edit_button, _("Edit Region Contents (e.g. notes)"));
3019 ARDOUR_UI::instance()->set_tip (*_group_tabs, _("Groups: context-click for possible operations"));
3020 ARDOUR_UI::instance()->set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
3021 ARDOUR_UI::instance()->set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
3022 ARDOUR_UI::instance()->set_tip (zoom_in_button, _("Zoom In"));
3023 ARDOUR_UI::instance()->set_tip (zoom_out_button, _("Zoom Out"));
3024 ARDOUR_UI::instance()->set_tip (zoom_out_full_button, _("Zoom to Session"));
3025 ARDOUR_UI::instance()->set_tip (zoom_focus_selector, _("Zoom focus"));
3026 ARDOUR_UI::instance()->set_tip (tav_expand_button, _("Expand Tracks"));
3027 ARDOUR_UI::instance()->set_tip (tav_shrink_button, _("Shrink Tracks"));
3028 ARDOUR_UI::instance()->set_tip (snap_type_selector, _("Snap/Grid Units"));
3029 ARDOUR_UI::instance()->set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3030 ARDOUR_UI::instance()->set_tip (edit_point_selector, _("Edit point"));
3031 ARDOUR_UI::instance()->set_tip (midi_sound_notes, _("Sound Notes"));
3032 ARDOUR_UI::instance()->set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
3036 Editor::midi_panic ()
3038 cerr << "MIDI panic\n";
3041 _session->midi_panic();
3046 Editor::setup_midi_toolbar ()
3050 /* Midi sound notes */
3051 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3052 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3053 midi_sound_notes.unset_flags (CAN_FOCUS);
3057 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
3058 midi_panic_button.set_name("MidiPanicButton");
3059 act->connect_proxy (midi_panic_button);
3061 panic_box.pack_start (midi_sound_notes , true, true);
3062 panic_box.pack_start (midi_panic_button, true, true);
3066 Editor::convert_drop_to_paths (
3067 vector<ustring>& paths,
3068 const RefPtr<Gdk::DragContext>& /*context*/,
3071 const SelectionData& data,
3075 if (_session == 0) {
3079 vector<ustring> uris = data.get_uris();
3083 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3084 are actually URI lists. So do it by hand.
3087 if (data.get_target() != "text/plain") {
3091 /* Parse the "uri-list" format that Nautilus provides,
3092 where each pathname is delimited by \r\n.
3094 THERE MAY BE NO NULL TERMINATING CHAR!!!
3097 ustring txt = data.get_text();
3101 p = (const char *) malloc (txt.length() + 1);
3102 txt.copy ((char *) p, txt.length(), 0);
3103 ((char*)p)[txt.length()] = '\0';
3109 while (g_ascii_isspace (*p))
3113 while (*q && (*q != '\n') && (*q != '\r')) {
3120 while (q > p && g_ascii_isspace (*q))
3125 uris.push_back (ustring (p, q - p + 1));
3129 p = strchr (p, '\n');
3141 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3143 if ((*i).substr (0,7) == "file://") {
3146 PBD::url_decode (p);
3148 // scan forward past three slashes
3150 ustring::size_type slashcnt = 0;
3151 ustring::size_type n = 0;
3152 ustring::iterator x = p.begin();
3154 while (slashcnt < 3 && x != p.end()) {
3157 } else if (slashcnt == 3) {
3164 if (slashcnt != 3 || x == p.end()) {
3165 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3169 paths.push_back (p.substr (n - 1));
3177 Editor::new_tempo_section ()
3183 Editor::map_transport_state ()
3185 ENSURE_GUI_THREAD (*this, &Editor::map_transport_state)
3187 if (_session && _session->transport_stopped()) {
3188 have_pending_keyboard_selection = false;
3191 update_loop_range_view (true);
3196 Editor::State::State (PublicEditor const * e)
3198 selection = new Selection (e);
3201 Editor::State::~State ()
3207 Editor::begin_reversible_command (string name)
3210 _session->begin_reversible_command (name);
3215 Editor::commit_reversible_command ()
3218 _session->commit_reversible_command ();
3223 Editor::set_route_group_solo (Route& route, bool yn)
3225 RouteGroup *route_group;
3227 if ((route_group = route.route_group()) != 0) {
3228 route_group->apply (&Route::set_solo, yn, this);
3230 route.set_solo (yn, this);
3235 Editor::set_route_group_mute (Route& route, bool yn)
3237 RouteGroup *route_group = 0;
3239 if ((route_group = route.route_group()) != 0) {
3240 route_group->apply (&Route::set_mute, yn, this);
3242 route.set_mute (yn, this);
3247 Editor::history_changed ()
3251 if (undo_action && _session) {
3252 if (_session->undo_depth() == 0) {
3255 label = string_compose(_("Undo (%1)"), _session->next_undo());
3257 undo_action->property_label() = label;
3260 if (redo_action && _session) {
3261 if (_session->redo_depth() == 0) {
3264 label = string_compose(_("Redo (%1)"), _session->next_redo());
3266 redo_action->property_label() = label;
3271 Editor::duplicate_dialog (bool with_dialog)
3275 if (mouse_mode == MouseRange) {
3276 if (selection->time.length() == 0) {
3282 get_regions_for_action (rs);
3284 if (mouse_mode != MouseRange) {
3293 ArdourDialog win (_("Duplicate"));
3294 Label label (_("Number of duplications:"));
3295 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3296 SpinButton spinner (adjustment, 0.0, 1);
3299 win.get_vbox()->set_spacing (12);
3300 win.get_vbox()->pack_start (hbox);
3301 hbox.set_border_width (6);
3302 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3304 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3305 place, visually. so do this by hand.
3308 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3309 spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3310 spinner.grab_focus();
3316 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3317 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3318 win.set_default_response (RESPONSE_ACCEPT);
3320 win.set_position (WIN_POS_MOUSE);
3322 spinner.grab_focus ();
3324 switch (win.run ()) {
3325 case RESPONSE_ACCEPT:
3331 times = adjustment.get_value();
3334 if (mouse_mode == MouseRange) {
3335 duplicate_selection (times);
3337 duplicate_some_regions (rs, times);
3342 Editor::show_verbose_canvas_cursor ()
3344 verbose_canvas_cursor->raise_to_top();
3345 verbose_canvas_cursor->show();
3346 verbose_cursor_visible = true;
3350 Editor::hide_verbose_canvas_cursor ()
3352 verbose_canvas_cursor->hide();
3353 verbose_cursor_visible = false;
3357 Editor::clamp_verbose_cursor_x (double x)
3362 x = min (_canvas_width - 200.0, x);
3368 Editor::clamp_verbose_cursor_y (double y)
3370 if (y < canvas_timebars_vsize) {
3371 y = canvas_timebars_vsize;
3373 y = min (_canvas_height - 50, y);
3379 Editor::show_verbose_canvas_cursor_with (const string & txt)
3381 verbose_canvas_cursor->property_text() = txt.c_str();
3386 track_canvas->get_pointer (x, y);
3387 track_canvas->window_to_world (x, y, wx, wy);
3389 /* don't get too close to the edge */
3390 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3391 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3393 show_verbose_canvas_cursor ();
3397 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3399 verbose_canvas_cursor->property_text() = txt.c_str();
3400 /* don't get too close to the edge */
3401 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3402 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3406 Editor::set_verbose_canvas_cursor_text (const string & txt)
3408 verbose_canvas_cursor->property_text() = txt.c_str();
3412 Editor::set_edit_mode (EditMode m)
3414 Config->set_edit_mode (m);
3418 Editor::cycle_edit_mode ()
3420 switch (Config->get_edit_mode()) {
3422 if (Profile->get_sae()) {
3423 Config->set_edit_mode (Lock);
3425 Config->set_edit_mode (Splice);
3429 Config->set_edit_mode (Lock);
3432 Config->set_edit_mode (Slide);
3438 Editor::edit_mode_selection_done ()
3440 if (_session == 0) {
3444 string choice = edit_mode_selector.get_active_text();
3445 EditMode mode = Slide;
3447 if (choice == _("Splice Edit")) {
3449 } else if (choice == _("Slide Edit")) {
3451 } else if (choice == _("Lock Edit")) {
3455 Config->set_edit_mode (mode);
3459 Editor::snap_type_selection_done ()
3461 string choice = snap_type_selector.get_active_text();
3462 SnapType snaptype = SnapToBeat;
3464 if (choice == _("Beats/2")) {
3465 snaptype = SnapToBeatDiv2;
3466 } else if (choice == _("Beats/3")) {
3467 snaptype = SnapToBeatDiv3;
3468 } else if (choice == _("Beats/4")) {
3469 snaptype = SnapToBeatDiv4;
3470 } else if (choice == _("Beats/5")) {
3471 snaptype = SnapToBeatDiv5;
3472 } else if (choice == _("Beats/6")) {
3473 snaptype = SnapToBeatDiv6;
3474 } else if (choice == _("Beats/7")) {
3475 snaptype = SnapToBeatDiv7;
3476 } else if (choice == _("Beats/8")) {
3477 snaptype = SnapToBeatDiv8;
3478 } else if (choice == _("Beats/10")) {
3479 snaptype = SnapToBeatDiv10;
3480 } else if (choice == _("Beats/12")) {
3481 snaptype = SnapToBeatDiv12;
3482 } else if (choice == _("Beats/14")) {
3483 snaptype = SnapToBeatDiv14;
3484 } else if (choice == _("Beats/16")) {
3485 snaptype = SnapToBeatDiv16;
3486 } else if (choice == _("Beats/24")) {
3487 snaptype = SnapToBeatDiv24;
3488 } else if (choice == _("Beats/28")) {
3489 snaptype = SnapToBeatDiv28;
3490 } else if (choice == _("Beats/32")) {
3491 snaptype = SnapToBeatDiv32;
3492 } else if (choice == _("Beats")) {
3493 snaptype = SnapToBeat;
3494 } else if (choice == _("Bars")) {
3495 snaptype = SnapToBar;
3496 } else if (choice == _("Marks")) {
3497 snaptype = SnapToMark;
3498 } else if (choice == _("Region starts")) {
3499 snaptype = SnapToRegionStart;
3500 } else if (choice == _("Region ends")) {
3501 snaptype = SnapToRegionEnd;
3502 } else if (choice == _("Region bounds")) {
3503 snaptype = SnapToRegionBoundary;
3504 } else if (choice == _("Region syncs")) {
3505 snaptype = SnapToRegionSync;
3506 } else if (choice == _("CD Frames")) {
3507 snaptype = SnapToCDFrame;
3508 } else if (choice == _("Timecode Frames")) {
3509 snaptype = SnapToTimecodeFrame;
3510 } else if (choice == _("Timecode Seconds")) {
3511 snaptype = SnapToTimecodeSeconds;
3512 } else if (choice == _("Timecode Minutes")) {
3513 snaptype = SnapToTimecodeMinutes;
3514 } else if (choice == _("Seconds")) {
3515 snaptype = SnapToSeconds;
3516 } else if (choice == _("Minutes")) {
3517 snaptype = SnapToMinutes;
3520 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3522 ract->set_active ();
3527 Editor::snap_mode_selection_done ()
3529 string choice = snap_mode_selector.get_active_text();
3530 SnapMode mode = SnapNormal;
3532 if (choice == _("No Grid")) {
3534 } else if (choice == _("Grid")) {
3536 } else if (choice == _("Magnetic")) {
3537 mode = SnapMagnetic;
3540 RefPtr<RadioAction> ract = snap_mode_action (mode);
3543 ract->set_active (true);
3548 Editor::cycle_edit_point (bool with_marker)
3550 switch (_edit_point) {
3552 set_edit_point_preference (EditAtPlayhead);
3554 case EditAtPlayhead:
3556 set_edit_point_preference (EditAtSelectedMarker);
3558 set_edit_point_preference (EditAtMouse);
3561 case EditAtSelectedMarker:
3562 set_edit_point_preference (EditAtMouse);
3568 Editor::edit_point_selection_done ()
3570 string choice = edit_point_selector.get_active_text();
3571 EditPoint ep = EditAtSelectedMarker;
3573 if (choice == _("Marker")) {
3574 set_edit_point_preference (EditAtSelectedMarker);
3575 } else if (choice == _("Playhead")) {
3576 set_edit_point_preference (EditAtPlayhead);
3578 set_edit_point_preference (EditAtMouse);
3581 RefPtr<RadioAction> ract = edit_point_action (ep);
3584 ract->set_active (true);
3589 Editor::zoom_focus_selection_done ()
3591 string choice = zoom_focus_selector.get_active_text();
3592 ZoomFocus focus_type = ZoomFocusLeft;
3594 if (choice == _("Left")) {
3595 focus_type = ZoomFocusLeft;
3596 } else if (choice == _("Right")) {
3597 focus_type = ZoomFocusRight;
3598 } else if (choice == _("Center")) {
3599 focus_type = ZoomFocusCenter;
3600 } else if (choice == _("Playhead")) {
3601 focus_type = ZoomFocusPlayhead;
3602 } else if (choice == _("Mouse")) {
3603 focus_type = ZoomFocusMouse;
3604 } else if (choice == _("Edit point")) {
3605 focus_type = ZoomFocusEdit;
3608 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3611 ract->set_active ();
3616 Editor::edit_controls_button_release (GdkEventButton* ev)
3618 if (Keyboard::is_context_menu_event (ev)) {
3619 ARDOUR_UI::instance()->add_route (this);
3625 Editor::mouse_select_button_release (GdkEventButton* ev)
3627 /* this handles just right-clicks */
3629 if (ev->button != 3) {
3637 Editor::set_zoom_focus (ZoomFocus f)
3639 string str = zoom_focus_strings[(int)f];
3641 if (str != zoom_focus_selector.get_active_text()) {
3642 zoom_focus_selector.set_active_text (str);
3645 if (zoom_focus != f) {
3648 ZoomFocusChanged (); /* EMIT_SIGNAL */
3655 Editor::ensure_float (Window& win)
3657 win.set_transient_for (*this);
3661 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3663 /* recover or initialize pane positions. do this here rather than earlier because
3664 we don't want the positions to change the child allocations, which they seem to do.
3670 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3682 width = default_width;
3683 height = default_height;
3685 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3687 prop = geometry->property ("x-size");
3689 width = atoi (prop->value());
3691 prop = geometry->property ("y-size");
3693 height = atoi (prop->value());
3697 if (which == static_cast<Paned*> (&edit_pane)) {
3699 if (done & Horizontal) {
3703 if (!geometry || (prop = geometry->property ("edit-horizontal-pane-pos")) == 0) {
3704 /* initial allocation is 90% to canvas, 10% to notebook */
3705 pos = (int) floor (alloc.get_width() * 0.90f);
3706 snprintf (buf, sizeof(buf), "%d", pos);
3708 pos = atoi (prop->value());
3711 if (GTK_WIDGET(edit_pane.gobj())->allocation.width > pos) {
3712 edit_pane.set_position (pos);
3713 pre_maximal_horizontal_pane_position = pos;
3716 done = (Pane) (done | Horizontal);
3718 } else if (which == static_cast<Paned*> (&editor_summary_pane)) {
3720 if (done & Vertical) {
3724 if (!geometry || (prop = geometry->property ("edit-vertical-pane-pos")) == 0) {
3725 /* initial allocation is 90% to canvas, 10% to summary */
3726 pos = (int) floor (alloc.get_height() * 0.90f);
3727 snprintf (buf, sizeof(buf), "%d", pos);
3729 pos = atoi (prop->value());
3732 if (GTK_WIDGET(editor_summary_pane.gobj())->allocation.height > pos) {
3733 editor_summary_pane.set_position (pos);
3734 pre_maximal_vertical_pane_position = pos;
3737 done = (Pane) (done | Vertical);
3742 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3744 if (_tools_tearoff->torn_off() && _mouse_mode_tearoff->torn_off()) {
3745 top_hbox.remove (toolbar_frame);
3750 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3752 if (toolbar_frame.get_parent() == 0) {
3753 top_hbox.pack_end (toolbar_frame);
3758 Editor::set_show_measures (bool yn)
3760 if (_show_measures != yn) {
3763 if ((_show_measures = yn) == true) {
3765 tempo_lines->show();
3773 Editor::toggle_follow_playhead ()
3775 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3777 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3778 set_follow_playhead (tact->get_active());
3783 Editor::set_follow_playhead (bool yn)
3785 if (_follow_playhead != yn) {
3786 if ((_follow_playhead = yn) == true) {
3788 reset_x_origin_to_follow_playhead ();
3795 Editor::toggle_stationary_playhead ()
3797 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
3799 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3800 set_stationary_playhead (tact->get_active());
3805 Editor::set_stationary_playhead (bool yn)
3807 if (_stationary_playhead != yn) {
3808 if ((_stationary_playhead = yn) == true) {
3810 // FIXME need a 3.0 equivalent of this 2.X call
3811 // update_current_screen ();
3818 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3820 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3822 xfade->set_active (!xfade->active());
3827 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3829 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3831 xfade->set_follow_overlap (!xfade->following_overlap());
3836 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3838 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3844 CrossfadeEditor cew (_session, xfade, xfade->fade_in().get_min_y(), 1.0);
3848 switch (cew.run ()) {
3849 case RESPONSE_ACCEPT:
3856 PropertyChange all_crossfade_properties;
3857 all_crossfade_properties.add (ARDOUR::Properties::active);
3858 all_crossfade_properties.add (ARDOUR::Properties::follow_overlap);
3859 xfade->PropertyChanged (all_crossfade_properties);
3863 Editor::playlist_selector () const
3865 return *_playlist_selector;
3869 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3873 switch (_snap_type) {
3878 case SnapToBeatDiv32:
3881 case SnapToBeatDiv28:
3884 case SnapToBeatDiv24:
3887 case SnapToBeatDiv16:
3890 case SnapToBeatDiv14:
3893 case SnapToBeatDiv12:
3896 case SnapToBeatDiv10:
3899 case SnapToBeatDiv8:
3902 case SnapToBeatDiv7:
3905 case SnapToBeatDiv6:
3908 case SnapToBeatDiv5:
3911 case SnapToBeatDiv4:
3914 case SnapToBeatDiv3:
3917 case SnapToBeatDiv2:
3923 return _session->tempo_map().meter_at (position).beats_per_bar();
3928 case SnapToTimecodeFrame:
3929 case SnapToTimecodeSeconds:
3930 case SnapToTimecodeMinutes:
3933 case SnapToRegionStart:
3934 case SnapToRegionEnd:
3935 case SnapToRegionSync:
3936 case SnapToRegionBoundary:
3946 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3950 ret = nudge_clock.current_duration (pos);
3951 next = ret + 1; /* XXXX fix me */
3957 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3959 ArdourDialog dialog (_("Playlist Deletion"));
3960 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3961 "If left alone, no audio files used by it will be cleaned.\n"
3962 "If deleted, audio files used by it alone by will cleaned."),
3965 dialog.set_position (WIN_POS_CENTER);
3966 dialog.get_vbox()->pack_start (label);
3970 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3971 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3972 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3974 switch (dialog.run ()) {
3975 case RESPONSE_ACCEPT:
3976 /* delete the playlist */
3980 case RESPONSE_REJECT:
3981 /* keep the playlist */
3993 Editor::audio_region_selection_covers (nframes64_t where)
3995 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3996 if ((*a)->region()->covers (where)) {
4005 Editor::prepare_for_cleanup ()
4007 cut_buffer->clear_regions ();
4008 cut_buffer->clear_playlists ();
4010 selection->clear_regions ();
4011 selection->clear_playlists ();
4013 _regions->suspend_redisplay ();
4017 Editor::finish_cleanup ()
4019 _regions->resume_redisplay ();
4023 Editor::transport_loop_location()
4026 return _session->locations()->auto_loop_location();
4033 Editor::transport_punch_location()
4036 return _session->locations()->auto_punch_location();
4043 Editor::control_layout_scroll (GdkEventScroll* ev)
4045 if (Keyboard::some_magic_widget_has_focus()) {
4049 switch (ev->direction) {
4051 scroll_tracks_up_line ();
4055 case GDK_SCROLL_DOWN:
4056 scroll_tracks_down_line ();
4060 /* no left/right handling yet */
4068 Editor::session_state_saved (string snap_name)
4070 ENSURE_GUI_THREAD (*this, &Editor::session_state_saved, snap_name);
4073 _snapshots->redisplay ();
4077 Editor::maximise_editing_space ()
4079 _mouse_mode_tearoff->set_visible (false);
4080 _tools_tearoff->set_visible (false);
4082 pre_maximal_horizontal_pane_position = edit_pane.get_position ();
4083 pre_maximal_vertical_pane_position = editor_summary_pane.get_position ();
4084 pre_maximal_editor_width = this->get_width ();
4085 pre_maximal_editor_height = this->get_height ();
4087 if (post_maximal_horizontal_pane_position == 0) {
4088 post_maximal_horizontal_pane_position = edit_pane.get_width();
4091 if (post_maximal_vertical_pane_position == 0) {
4092 post_maximal_vertical_pane_position = editor_summary_pane.get_height();
4097 if (post_maximal_editor_width) {
4098 edit_pane.set_position (post_maximal_horizontal_pane_position -
4099 abs(post_maximal_editor_width - pre_maximal_editor_width));
4101 edit_pane.set_position (post_maximal_horizontal_pane_position);
4104 if (post_maximal_editor_height) {
4105 editor_summary_pane.set_position (post_maximal_vertical_pane_position -
4106 abs(post_maximal_editor_height - pre_maximal_editor_height));
4108 editor_summary_pane.set_position (post_maximal_vertical_pane_position);
4113 Editor::restore_editing_space ()
4115 // user changed width/height of panes during fullscreen
4117 if (post_maximal_horizontal_pane_position != edit_pane.get_position()) {
4118 post_maximal_horizontal_pane_position = edit_pane.get_position();
4121 if (post_maximal_vertical_pane_position != editor_summary_pane.get_position()) {
4122 post_maximal_vertical_pane_position = editor_summary_pane.get_position();
4127 _mouse_mode_tearoff->set_visible (true);
4128 _tools_tearoff->set_visible (true);
4129 post_maximal_editor_width = this->get_width();
4130 post_maximal_editor_height = this->get_height();
4132 edit_pane.set_position (pre_maximal_horizontal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4133 editor_summary_pane.set_position (pre_maximal_vertical_pane_position + abs(this->get_height() - pre_maximal_editor_height));
4137 * Make new playlists for a given track and also any others that belong
4138 * to the same active route group with the `edit' property.
4143 Editor::new_playlists (TimeAxisView* v)
4145 begin_reversible_command (_("new playlists"));
4146 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4147 _session->playlists->get (playlists);
4148 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4149 commit_reversible_command ();
4153 * Use a copy of the current playlist for a given track and also any others that belong
4154 * to the same active route group with the `edit' property.
4159 Editor::copy_playlists (TimeAxisView* v)
4161 begin_reversible_command (_("copy playlists"));
4162 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4163 _session->playlists->get (playlists);
4164 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4165 commit_reversible_command ();
4168 /** Clear the current playlist for a given track and also any others that belong
4169 * to the same active route group with the `edit' property.
4174 Editor::clear_playlists (TimeAxisView* v)
4176 begin_reversible_command (_("clear playlists"));
4177 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4178 _session->playlists->get (playlists);
4179 mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, ARDOUR::Properties::edit.property_id);
4180 commit_reversible_command ();
4184 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4186 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4190 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4192 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4196 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4198 atv.clear_playlist ();
4202 Editor::on_key_press_event (GdkEventKey* ev)
4204 return key_press_focus_accelerator_handler (*this, ev);
4208 Editor::on_key_release_event (GdkEventKey* ev)
4210 return Gtk::Window::on_key_release_event (ev);
4211 // return key_press_focus_accelerator_handler (*this, ev);
4214 /** Queue up a change to the viewport x origin.
4215 * @param frame New x origin.
4218 Editor::reset_x_origin (nframes64_t frame)
4220 queue_visual_change (frame);
4224 Editor::reset_y_origin (double y)
4226 queue_visual_change_y (y);
4230 Editor::reset_zoom (double fpu)
4232 queue_visual_change (fpu);
4236 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4238 reset_x_origin (frame);
4241 if (!no_save_visual) {
4242 undo_visual_stack.push_back (current_visual_state(false));
4246 Editor::VisualState*
4247 Editor::current_visual_state (bool with_tracks)
4249 VisualState* vs = new VisualState;
4250 vs->y_position = vertical_adjustment.get_value();
4251 vs->frames_per_unit = frames_per_unit;
4252 vs->leftmost_frame = leftmost_frame;
4253 vs->zoom_focus = zoom_focus;
4256 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4257 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4265 Editor::undo_visual_state ()
4267 if (undo_visual_stack.empty()) {
4271 redo_visual_stack.push_back (current_visual_state());
4273 VisualState* vs = undo_visual_stack.back();
4274 undo_visual_stack.pop_back();
4275 use_visual_state (*vs);
4279 Editor::redo_visual_state ()
4281 if (redo_visual_stack.empty()) {
4285 undo_visual_stack.push_back (current_visual_state());
4287 VisualState* vs = redo_visual_stack.back();
4288 redo_visual_stack.pop_back();
4289 use_visual_state (*vs);
4293 Editor::swap_visual_state ()
4295 if (undo_visual_stack.empty()) {
4296 redo_visual_state ();
4298 undo_visual_state ();
4303 Editor::use_visual_state (VisualState& vs)
4305 no_save_visual = true;
4307 _routes->suspend_redisplay ();
4309 vertical_adjustment.set_value (vs.y_position);
4311 set_zoom_focus (vs.zoom_focus);
4312 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4314 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4315 TrackViewList::iterator t;
4317 /* check if the track still exists - it could have been deleted */
4319 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4320 (*t)->set_state (*(i->second), Stateful::loading_state_version);
4325 if (!vs.track_states.empty()) {
4326 _routes->update_visibility ();
4329 _routes->resume_redisplay ();
4331 no_save_visual = false;
4335 Editor::set_frames_per_unit (double fpu)
4337 /* this is the core function that controls the zoom level of the canvas. it is called
4338 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4341 if (fpu == frames_per_unit) {
4350 /* don't allow zooms that fit more than the maximum number
4351 of frames into an 800 pixel wide space.
4354 if (max_frames / fpu < 800.0) {
4359 tempo_lines->tempo_map_changed();
4361 frames_per_unit = fpu;
4366 Editor::post_zoom ()
4368 // convert fpu to frame count
4370 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4372 if (frames_per_unit != zoom_range_clock.current_duration()) {
4373 zoom_range_clock.set (frames);
4376 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4377 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4378 (*i)->reshow_selection (selection->time);
4382 ZoomChanged (); /* EMIT_SIGNAL */
4384 //reset_scrolling_region ();
4386 if (playhead_cursor) {
4387 playhead_cursor->set_position (playhead_cursor->current_frame);
4390 refresh_location_display();
4391 _summary->set_overlays_dirty ();
4397 Editor::queue_visual_change (nframes64_t where)
4399 pending_visual_change.add (VisualChange::TimeOrigin);
4400 pending_visual_change.time_origin = where;
4401 ensure_visual_change_idle_handler ();
4405 Editor::queue_visual_change (double fpu)
4407 pending_visual_change.add (VisualChange::ZoomLevel);
4408 pending_visual_change.frames_per_unit = fpu;
4410 ensure_visual_change_idle_handler ();
4414 Editor::queue_visual_change_y (double y)
4416 pending_visual_change.add (VisualChange::YOrigin);
4417 pending_visual_change.y_origin = y;
4419 ensure_visual_change_idle_handler ();
4423 Editor::ensure_visual_change_idle_handler ()
4425 if (pending_visual_change.idle_handler_id < 0) {
4426 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4431 Editor::_idle_visual_changer (void* arg)
4433 return static_cast<Editor*>(arg)->idle_visual_changer ();
4437 Editor::idle_visual_changer ()
4439 VisualChange::Type p = pending_visual_change.pending;
4440 pending_visual_change.pending = (VisualChange::Type) 0;
4442 double last_time_origin = horizontal_position ();
4444 if (p & VisualChange::ZoomLevel) {
4445 set_frames_per_unit (pending_visual_change.frames_per_unit);
4447 compute_fixed_ruler_scale ();
4448 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4449 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4450 update_tempo_based_rulers ();
4452 if (p & VisualChange::TimeOrigin) {
4453 set_horizontal_position (pending_visual_change.time_origin / frames_per_unit);
4455 if (p & VisualChange::YOrigin) {
4456 vertical_adjustment.set_value (pending_visual_change.y_origin);
4459 if (last_time_origin == horizontal_position ()) {
4460 /* changed signal not emitted */
4461 update_fixed_rulers ();
4462 redisplay_tempo (true);
4465 _summary->set_overlays_dirty ();
4467 pending_visual_change.idle_handler_id = -1;
4468 return 0; /* this is always a one-shot call */
4471 struct EditorOrderTimeAxisSorter {
4472 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4473 return a->order () < b->order ();
4478 Editor::sort_track_selection (TrackViewList* sel)
4480 EditorOrderTimeAxisSorter cmp;
4485 selection->tracks.sort (cmp);
4490 Editor::get_preferred_edit_position (bool ignore_playhead)
4493 nframes64_t where = 0;
4494 EditPoint ep = _edit_point;
4496 if (entered_marker) {
4497 return entered_marker->position();
4500 if (ignore_playhead && ep == EditAtPlayhead) {
4501 ep = EditAtSelectedMarker;
4505 case EditAtPlayhead:
4506 where = _session->audible_frame();
4509 case EditAtSelectedMarker:
4510 if (!selection->markers.empty()) {
4512 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4515 where = loc->start();
4526 if (!mouse_frame (where, ignored)) {
4527 /* XXX not right but what can we do ? */
4538 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4540 if (!_session) return;
4542 begin_reversible_command (cmd);
4546 if ((tll = transport_loop_location()) == 0) {
4547 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4548 XMLNode &before = _session->locations()->get_state();
4549 _session->locations()->add (loc, true);
4550 _session->set_auto_loop_location (loc);
4551 XMLNode &after = _session->locations()->get_state();
4552 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4554 XMLNode &before = tll->get_state();
4555 tll->set_hidden (false, this);
4556 tll->set (start, end);
4557 XMLNode &after = tll->get_state();
4558 _session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4561 commit_reversible_command ();
4565 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4567 if (!_session) return;
4569 begin_reversible_command (cmd);
4573 if ((tpl = transport_punch_location()) == 0) {
4574 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4575 XMLNode &before = _session->locations()->get_state();
4576 _session->locations()->add (loc, true);
4577 _session->set_auto_loop_location (loc);
4578 XMLNode &after = _session->locations()->get_state();
4579 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4582 XMLNode &before = tpl->get_state();
4583 tpl->set_hidden (false, this);
4584 tpl->set (start, end);
4585 XMLNode &after = tpl->get_state();
4586 _session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4589 commit_reversible_command ();
4592 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4593 * @param rs List to which found regions are added.
4594 * @param where Time to look at.
4595 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4598 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4600 const TrackViewList* tracks;
4603 tracks = &track_views;
4608 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4609 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4611 boost::shared_ptr<Track> tr;
4612 boost::shared_ptr<Playlist> pl;
4614 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4616 Playlist::RegionList* regions = pl->regions_at (
4617 (nframes64_t) floor ( (double)where * tr->speed()));
4619 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4620 RegionView* rv = rtv->view()->find_view (*i);
4633 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4635 const TrackViewList* tracks;
4638 tracks = &track_views;
4643 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4644 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4646 boost::shared_ptr<Track> tr;
4647 boost::shared_ptr<Playlist> pl;
4649 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4651 Playlist::RegionList* regions = pl->regions_touched (
4652 (nframes64_t) floor ( (double)where * tr->speed()), max_frames);
4654 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4656 RegionView* rv = rtv->view()->find_view (*i);
4669 /** Find all regions which are either:
4671 * - the entered_regionview (if allow_entered == true) or
4672 * - under the preferred edit position AND on a selected track, or on a track
4673 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4674 * @param rs Returned region list.
4675 * @param allow_entered true to include the entered_regionview in the list.
4678 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4680 /* Start with selected regions */
4681 rs = selection->regions;
4683 /* Add the entered_regionview, if requested */
4684 if (allow_entered && entered_regionview) {
4685 rs.add (entered_regionview);
4688 if (allow_edit_position) {
4690 TrackViewList tracks = selection->tracks;
4692 /* tracks is currently the set of selected tracks; add any other tracks that
4693 * have regions that are in the same edit-activated route group as one of
4695 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4697 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4698 if (g && g->is_active() && g->is_edit()) {
4699 tracks.add (axis_views_from_routes (g->route_list()));
4704 if (!tracks.empty()) {
4705 /* now find regions that are at the edit position on those tracks */
4706 nframes64_t const where = get_preferred_edit_position ();
4707 get_regions_at (rs, where, tracks);
4713 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4715 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4717 RouteTimeAxisView* tatv;
4719 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4721 boost::shared_ptr<Playlist> pl;
4722 vector<boost::shared_ptr<Region> > results;
4724 boost::shared_ptr<Track> tr;
4726 if ((tr = tatv->track()) == 0) {
4731 if ((pl = (tr->playlist())) != 0) {
4732 pl->get_region_list_equivalent_regions (region, results);
4735 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4736 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4737 regions.push_back (marv);
4746 Editor::show_rhythm_ferret ()
4748 if (rhythm_ferret == 0) {
4749 rhythm_ferret = new RhythmFerret(*this);
4752 rhythm_ferret->set_session (_session);
4753 rhythm_ferret->show ();
4754 rhythm_ferret->present ();
4758 Editor::show_global_port_matrix (ARDOUR::DataType t)
4760 if (_global_port_matrix[t] == 0) {
4761 _global_port_matrix[t] = new GlobalPortMatrixWindow (_session, t);
4764 _global_port_matrix[t]->show ();
4768 Editor::first_idle ()
4770 MessageDialog* dialog = 0;
4772 if (track_views.size() > 1) {
4773 dialog = new MessageDialog (*this,
4774 string_compose (_("Please wait while %1 loads visual data"), PROGRAM_NAME),
4779 ARDOUR_UI::instance()->flush_pending ();
4782 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4786 // first idle adds route children (automation tracks), so we need to redisplay here
4787 _routes->redisplay ();
4795 Editor::_idle_resize (gpointer arg)
4797 return ((Editor*)arg)->idle_resize ();
4801 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4803 if (resize_idle_id < 0) {
4804 resize_idle_id = g_idle_add (_idle_resize, this);
4805 _pending_resize_amount = 0;
4808 /* make a note of the smallest resulting height, so that we can clamp the
4809 lower limit at TimeAxisView::hSmall */
4811 int32_t min_resulting = INT32_MAX;
4813 _pending_resize_amount += h;
4814 _pending_resize_view = view;
4816 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4818 if (selection->tracks.contains (_pending_resize_view)) {
4819 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4820 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4824 if (min_resulting < 0) {
4829 if (uint32_t (min_resulting) < TimeAxisView::preset_height (HeightSmall)) {
4830 _pending_resize_amount += TimeAxisView::preset_height (HeightSmall) - min_resulting;
4834 /** Handle pending resizing of tracks */
4836 Editor::idle_resize ()
4838 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4840 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4841 selection->tracks.contains (_pending_resize_view)) {
4843 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4844 if (*i != _pending_resize_view) {
4845 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4850 _pending_resize_amount = 0;
4852 _group_tabs->set_dirty ();
4853 resize_idle_id = -1;
4861 ENSURE_GUI_THREAD (*this, &Editor::located);
4863 playhead_cursor->set_position (_session->audible_frame ());
4864 if (_follow_playhead && !_pending_initial_locate) {
4865 reset_x_origin_to_follow_playhead ();
4868 _pending_locate_request = false;
4869 _pending_initial_locate = false;
4873 Editor::region_view_added (RegionView *)
4875 _summary->set_dirty ();
4879 Editor::streamview_height_changed ()
4881 _summary->set_dirty ();
4885 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
4887 TrackViewList::const_iterator j = track_views.begin ();
4888 while (j != track_views.end()) {
4889 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4890 if (rtv && rtv->route() == r) {
4901 Editor::axis_views_from_routes (boost::shared_ptr<RouteList> r) const
4905 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
4906 TimeAxisView* tv = axis_view_from_route (*i);
4917 Editor::handle_new_route (RouteList& routes)
4919 ENSURE_GUI_THREAD (*this, &Editor::handle_new_route, routes)
4921 RouteTimeAxisView *rtv;
4922 list<RouteTimeAxisView*> new_views;
4924 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4925 boost::shared_ptr<Route> route = (*x);
4927 if (route->is_hidden() || route->is_monitor()) {
4931 DataType dt = route->input()->default_type();
4933 if (dt == ARDOUR::DataType::AUDIO) {
4934 rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
4935 } else if (dt == ARDOUR::DataType::MIDI) {
4936 rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
4938 throw unknown_type();
4941 new_views.push_back (rtv);
4942 track_views.push_back (rtv);
4944 rtv->effective_gain_display ();
4946 rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
4947 rtv->view()->HeightChanged.connect (sigc::mem_fun (*this, &Editor::streamview_height_changed));
4950 _routes->routes_added (new_views);
4952 if (show_editor_mixer_when_tracks_arrive) {
4953 show_editor_mixer (true);
4956 editor_list_button.set_sensitive (true);
4958 _summary->set_dirty ();
4962 Editor::timeaxisview_deleted (TimeAxisView *tv)
4964 if (_session && _session->deletion_in_progress()) {
4965 /* the situation is under control */
4969 ENSURE_GUI_THREAD (*this, &Editor::timeaxisview_deleted, tv);
4972 _routes->route_removed (tv);
4974 if (tv == entered_track) {
4978 /* remove it from the list of track views */
4980 TrackViewList::iterator i;
4982 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4983 i = track_views.erase (i);
4986 /* update whatever the current mixer strip is displaying, if revelant */
4988 boost::shared_ptr<Route> route;
4989 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv);
4992 route = rtav->route ();
4995 if (current_mixer_strip && current_mixer_strip->route() == route) {
4997 TimeAxisView* next_tv;
4999 if (track_views.empty()) {
5001 } else if (i == track_views.end()) {
5002 next_tv = track_views.front();
5009 set_selected_mixer_strip (*next_tv);
5011 /* make the editor mixer strip go away setting the
5012 * button to inactive (which also unticks the menu option)
5015 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
5021 Editor::hide_track_in_display (TimeAxisView* tv, bool /*temponly*/)
5023 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
5025 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
5026 // this will hide the mixer strip
5027 set_selected_mixer_strip (*tv);
5030 _routes->hide_track_in_display (*tv);
5034 Editor::sync_track_view_list_and_routes ()
5036 track_views = TrackViewList (_routes->views ());
5038 _summary->set_dirty ();
5039 _group_tabs->set_dirty ();
5041 return false; // do not call again (until needed)
5045 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
5047 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5053 Editor::get_route_view_by_id (PBD::ID& id)
5055 RouteTimeAxisView* v;
5057 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5058 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5059 if(v->route()->id() == id) {
5069 Editor::fit_route_group (RouteGroup *g)
5071 TrackViewList ts = axis_views_from_routes (g->route_list ());
5076 Editor::consider_auditioning (boost::shared_ptr<Region> region)
5078 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
5081 _session->cancel_audition ();
5085 if (_session->is_auditioning()) {
5086 _session->cancel_audition ();
5087 if (r == last_audition_region) {
5092 _session->audition_region (r);
5093 last_audition_region = r;
5098 Editor::hide_a_region (boost::shared_ptr<Region> r)
5100 r->set_hidden (true);
5104 Editor::show_a_region (boost::shared_ptr<Region> r)
5106 r->set_hidden (false);
5110 Editor::audition_region_from_region_list ()
5112 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::consider_auditioning));
5116 Editor::hide_region_from_region_list ()
5118 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::hide_a_region));
5122 Editor::show_region_in_region_list ()
5124 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::show_a_region));
5128 Editor::start_step_editing ()
5130 step_edit_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::check_step_edit), 20);
5134 Editor::stop_step_editing ()
5136 step_edit_connection.disconnect ();
5140 Editor::check_step_edit ()
5142 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5143 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
5145 mtv->check_step_edit ();
5149 return true; // do it again, till we stop
5153 Editor::horizontal_scroll_left ()
5155 double x = leftmost_position() - current_page_frames() / 5;
5164 Editor::horizontal_scroll_right ()
5166 reset_x_origin (leftmost_position() + current_page_frames() / 5);
5169 /** Queue a change for the Editor viewport x origin to follow the playhead */
5171 Editor::reset_x_origin_to_follow_playhead ()
5173 nframes64_t const frame = playhead_cursor->current_frame;
5175 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
5177 if (_session->transport_speed() < 0) {
5179 if (frame > (current_page_frames() / 2)) {
5180 center_screen (frame-(current_page_frames()/2));
5182 center_screen (current_page_frames()/2);
5187 if (frame < leftmost_frame) {
5190 if (_session->transport_rolling()) {
5191 /* rolling; end up with the playhead at the right of the page */
5192 l = frame - current_page_frames ();
5194 /* not rolling: end up with the playhead 3/4 of the way along the page */
5195 l = frame - (3 * current_page_frames() / 4);
5202 center_screen_internal (l + (current_page_frames() / 2), current_page_frames ());
5205 if (_session->transport_rolling()) {
5206 /* rolling: end up with the playhead on the left of the page */
5207 center_screen_internal (frame + (current_page_frames() / 2), current_page_frames ());
5209 /* not rolling: end up with the playhead 1/4 of the way along the page */
5210 center_screen_internal (frame + (current_page_frames() / 4), current_page_frames ());
5218 Editor::super_rapid_screen_update ()
5220 if (!_session || !_session->engine().running()) {
5224 /* METERING / MIXER STRIPS */
5226 /* update track meters, if required */
5227 if (is_mapped() && meters_running) {
5228 RouteTimeAxisView* rtv;
5229 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5230 if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5231 rtv->fast_update ();
5236 /* and any current mixer strip */
5237 if (current_mixer_strip) {
5238 current_mixer_strip->fast_update ();
5241 /* PLAYHEAD AND VIEWPORT */
5243 nframes64_t const frame = _session->audible_frame();
5245 /* There are a few reasons why we might not update the playhead / viewport stuff:
5247 * 1. we don't update things when there's a pending locate request, otherwise
5248 * when the editor requests a locate there is a chance that this method
5249 * will move the playhead before the locate request is processed, causing
5251 * 2. if we're not rolling, there's nothing to do here (locates are handled elsewhere).
5252 * 3. if we're still at the same frame that we were last time, there's nothing to do.
5255 if (!_pending_locate_request && _session->transport_speed() != 0 && frame != last_update_frame) {
5257 last_update_frame = frame;
5259 if (!_dragging_playhead) {
5260 playhead_cursor->set_position (frame);
5263 if (!_stationary_playhead) {
5265 if (!_dragging_playhead && _follow_playhead && _session->requested_return_frame() < 0) {
5266 reset_x_origin_to_follow_playhead ();
5271 /* don't do continuous scroll till the new position is in the rightmost quarter of the
5275 // FIXME DO SOMETHING THAT WORKS HERE - this is 2.X code
5276 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
5277 if (target <= 0.0) {
5280 if (fabs(target - current) < current_page_frames() / frames_per_unit) {
5281 target = (target * 0.15) + (current * 0.85);
5287 set_horizontal_position (current);
5296 Editor::session_going_away ()
5298 _have_idled = false;
5300 _session_connections.drop_connections ();
5302 super_rapid_screen_update_connection.disconnect ();
5304 selection->clear ();
5305 cut_buffer->clear ();
5307 clicked_regionview = 0;
5308 clicked_axisview = 0;
5309 clicked_routeview = 0;
5310 clicked_crossfadeview = 0;
5311 entered_regionview = 0;
5313 last_update_frame = 0;
5316 playhead_cursor->canvas_item.hide ();
5318 /* rip everything out of the list displays */
5322 _route_groups->clear ();
5324 /* do this first so that deleting a track doesn't reset cms to null
5325 and thus cause a leak.
5328 if (current_mixer_strip) {
5329 if (current_mixer_strip->get_parent() != 0) {
5330 global_hpacker.remove (*current_mixer_strip);
5332 delete current_mixer_strip;
5333 current_mixer_strip = 0;
5336 /* delete all trackviews */
5338 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5341 track_views.clear ();
5343 zoom_range_clock.set_session (0);
5344 nudge_clock.set_session (0);
5346 editor_list_button.set_active(false);
5347 editor_list_button.set_sensitive(false);
5349 /* clear tempo/meter rulers */
5350 remove_metric_marks ();
5352 clear_marker_display ();
5354 delete current_bbt_points;
5355 current_bbt_points = 0;
5357 /* get rid of any existing editor mixer strip */
5359 WindowTitle title(Glib::get_application_name());
5360 title += _("Editor");
5362 set_title (title.get_string());
5364 SessionHandlePtr::session_going_away ();
5369 Editor::show_editor_list (bool yn)
5372 the_notebook.show();
5374 the_notebook.hide();