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"),
170 static const gchar *_snap_mode_strings[] = {
177 static const gchar *_edit_point_strings[] = {
184 static const gchar *_zoom_focus_strings[] = {
194 #ifdef USE_RUBBERBAND
195 static const gchar *_rb_opt_strings[] = {
198 N_("Balanced multitimbral mixture"),
199 N_("Unpitched percussion with stable notes"),
200 N_("Crisp monophonic instrumental"),
201 N_("Unpitched solo percussion"),
206 /* Soundfile drag-n-drop */
208 Gdk::Cursor* Editor::cross_hair_cursor = 0;
209 Gdk::Cursor* Editor::selector_cursor = 0;
210 Gdk::Cursor* Editor::trimmer_cursor = 0;
211 Gdk::Cursor* Editor::grabber_cursor = 0;
212 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
213 Gdk::Cursor* Editor::zoom_cursor = 0;
214 Gdk::Cursor* Editor::time_fx_cursor = 0;
215 Gdk::Cursor* Editor::fader_cursor = 0;
216 Gdk::Cursor* Editor::speaker_cursor = 0;
217 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
218 Gdk::Cursor* Editor::midi_select_cursor = 0;
219 Gdk::Cursor* Editor::midi_resize_cursor = 0;
220 Gdk::Cursor* Editor::midi_erase_cursor = 0;
221 Gdk::Cursor* Editor::wait_cursor = 0;
222 Gdk::Cursor* Editor::timebar_cursor = 0;
223 Gdk::Cursor* Editor::transparent_cursor = 0;
226 show_me_the_size (Requisition* r, const char* what)
228 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
233 pane_size_watcher (Paned* pane)
235 /* if the handle of a pane vanishes into (at least) the tabs of a notebook,
236 it is no longer accessible. so stop that. this doesn't happen on X11,
237 just the quartz backend.
242 int max_width_of_lhs = GTK_WIDGET(pane->gobj())->allocation.width - 25;
244 gint pos = pane->get_position ();
246 if (pos > max_width_of_lhs) {
247 pane->set_position (max_width_of_lhs);
253 : _join_object_range_state (JOIN_OBJECT_RANGE_NONE)
255 /* time display buttons */
256 , minsec_label (_("Mins:Secs"))
257 , bbt_label (_("Bars:Beats"))
258 , timecode_label (_("Timecode"))
259 , frame_label (_("Samples"))
260 , tempo_label (_("Tempo"))
261 , meter_label (_("Meter"))
262 , mark_label (_("Location Markers"))
263 , range_mark_label (_("Range Markers"))
264 , transport_mark_label (_("Loop/Punch Ranges"))
265 , cd_mark_label (_("CD Markers"))
266 , edit_packer (4, 4, true)
268 /* the values here don't matter: layout widgets
269 reset them as needed.
272 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
274 /* tool bar related */
276 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
278 , toolbar_selection_clock_table (2,3)
280 , automation_mode_button (_("mode"))
281 , global_automation_button (_("automation"))
283 , midi_panic_button (_("Panic"))
286 , image_socket_listener(0)
291 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
292 , meters_running(false)
293 , _pending_locate_request (false)
294 , _pending_initial_locate (false)
299 /* we are a singleton */
301 PublicEditor::_instance = this;
305 selection = new Selection (this);
306 cut_buffer = new Selection (this);
308 clicked_regionview = 0;
309 clicked_axisview = 0;
310 clicked_routeview = 0;
311 clicked_crossfadeview = 0;
312 clicked_control_point = 0;
313 last_update_frame = 0;
314 _drags = new DragManager (this);
315 current_mixer_strip = 0;
316 current_bbt_points = 0;
319 snap_type_strings = I18N (_snap_type_strings);
320 snap_mode_strings = I18N (_snap_mode_strings);
321 zoom_focus_strings = I18N (_zoom_focus_strings);
322 edit_point_strings = I18N (_edit_point_strings);
323 #ifdef USE_RUBBERBAND
324 rb_opt_strings = I18N (_rb_opt_strings);
327 snap_threshold = 5.0;
328 bbt_beat_subdivision = 4;
331 last_autoscroll_x = 0;
332 last_autoscroll_y = 0;
333 autoscroll_active = false;
334 autoscroll_timeout_tag = -1;
339 current_interthread_info = 0;
340 _show_measures = true;
341 show_gain_after_trim = false;
342 verbose_cursor_on = true;
343 last_item_entered = 0;
344 last_item_entered_n = 0;
346 have_pending_keyboard_selection = false;
347 _follow_playhead = true;
348 _stationary_playhead = false;
349 _xfade_visibility = true;
350 editor_ruler_menu = 0;
351 no_ruler_shown_update = false;
353 session_range_marker_menu = 0;
354 range_marker_menu = 0;
355 marker_menu_item = 0;
356 tempo_or_meter_marker_menu = 0;
357 transport_marker_menu = 0;
358 new_transport_marker_menu = 0;
359 editor_mixer_strip_width = Wide;
360 show_editor_mixer_when_tracks_arrive = false;
361 region_edit_menu_split_multichannel_item = 0;
362 region_edit_menu_split_item = 0;
365 current_stepping_trackview = 0;
367 entered_regionview = 0;
369 clear_entered_track = false;
372 button_release_can_deselect = true;
373 _dragging_playhead = false;
374 _dragging_edit_point = false;
375 select_new_marker = false;
378 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
379 _global_port_matrix[*i] = 0;
381 allow_vertical_scroll = false;
382 no_save_visual = false;
385 scrubbing_direction = 0;
389 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
390 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
391 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
392 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
393 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
395 _edit_point = EditAtMouse;
396 _internal_editing = false;
397 current_canvas_cursor = 0;
399 frames_per_unit = 2048; /* too early to use reset_zoom () */
401 zoom_focus = ZoomFocusLeft;
402 set_zoom_focus (ZoomFocusLeft);
403 zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
405 bbt_label.set_name ("EditorTimeButton");
406 bbt_label.set_size_request (-1, (int)timebar_height);
407 bbt_label.set_alignment (1.0, 0.5);
408 bbt_label.set_padding (5,0);
410 bbt_label.set_no_show_all();
411 minsec_label.set_name ("EditorTimeButton");
412 minsec_label.set_size_request (-1, (int)timebar_height);
413 minsec_label.set_alignment (1.0, 0.5);
414 minsec_label.set_padding (5,0);
415 minsec_label.hide ();
416 minsec_label.set_no_show_all();
417 timecode_label.set_name ("EditorTimeButton");
418 timecode_label.set_size_request (-1, (int)timebar_height);
419 timecode_label.set_alignment (1.0, 0.5);
420 timecode_label.set_padding (5,0);
421 timecode_label.hide ();
422 timecode_label.set_no_show_all();
423 frame_label.set_name ("EditorTimeButton");
424 frame_label.set_size_request (-1, (int)timebar_height);
425 frame_label.set_alignment (1.0, 0.5);
426 frame_label.set_padding (5,0);
428 frame_label.set_no_show_all();
430 tempo_label.set_name ("EditorTimeButton");
431 tempo_label.set_size_request (-1, (int)timebar_height);
432 tempo_label.set_alignment (1.0, 0.5);
433 tempo_label.set_padding (5,0);
435 tempo_label.set_no_show_all();
436 meter_label.set_name ("EditorTimeButton");
437 meter_label.set_size_request (-1, (int)timebar_height);
438 meter_label.set_alignment (1.0, 0.5);
439 meter_label.set_padding (5,0);
441 meter_label.set_no_show_all();
442 mark_label.set_name ("EditorTimeButton");
443 mark_label.set_size_request (-1, (int)timebar_height);
444 mark_label.set_alignment (1.0, 0.5);
445 mark_label.set_padding (5,0);
447 mark_label.set_no_show_all();
448 cd_mark_label.set_name ("EditorTimeButton");
449 cd_mark_label.set_size_request (-1, (int)timebar_height);
450 cd_mark_label.set_alignment (1.0, 0.5);
451 cd_mark_label.set_padding (5,0);
452 cd_mark_label.hide();
453 cd_mark_label.set_no_show_all();
454 range_mark_label.set_name ("EditorTimeButton");
455 range_mark_label.set_size_request (-1, (int)timebar_height);
456 range_mark_label.set_alignment (1.0, 0.5);
457 range_mark_label.set_padding (5,0);
458 range_mark_label.hide();
459 range_mark_label.set_no_show_all();
460 transport_mark_label.set_name ("EditorTimeButton");
461 transport_mark_label.set_size_request (-1, (int)timebar_height);
462 transport_mark_label.set_alignment (1.0, 0.5);
463 transport_mark_label.set_padding (5,0);
464 transport_mark_label.hide();
465 transport_mark_label.set_no_show_all();
467 initialize_rulers ();
468 initialize_canvas ();
469 _summary = new EditorSummary (this);
471 selection->TimeChanged.connect (sigc::mem_fun(*this, &Editor::time_selection_changed));
472 selection->TracksChanged.connect (sigc::mem_fun(*this, &Editor::track_selection_changed));
473 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (sigc::mem_fun(*this, &Editor::region_selection_changed));
474 selection->PointsChanged.connect (sigc::mem_fun(*this, &Editor::point_selection_changed));
475 selection->MarkersChanged.connect (sigc::mem_fun(*this, &Editor::marker_selection_changed));
477 edit_controls_vbox.set_spacing (0);
478 vertical_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::tie_vertical_scrolling), true);
479 track_canvas->signal_map_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_map_handler));
481 HBox* h = manage (new HBox);
482 _group_tabs = new EditorGroupTabs (this);
483 h->pack_start (*_group_tabs, PACK_SHRINK);
484 h->pack_start (edit_controls_vbox);
485 controls_layout.add (*h);
487 controls_layout.set_name ("EditControlsBase");
488 controls_layout.add_events (Gdk::SCROLL_MASK);
489 controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false);
491 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
492 controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
493 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
497 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
498 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
499 0.0, 1.0, 100.0, 1.0));
500 pad_line_1->property_color_rgba() = 0xFF0000FF;
504 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
505 time_canvas_vbox.set_size_request (-1, -1);
507 ruler_label_event_box.add (ruler_label_vbox);
508 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
509 ruler_label_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
511 time_button_event_box.add (time_button_vbox);
512 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
513 time_button_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
515 /* these enable us to have a dedicated window (for cursor setting, etc.)
516 for the canvas areas.
519 track_canvas_event_box.add (*track_canvas);
521 time_canvas_event_box.add (time_canvas_vbox);
522 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
524 edit_packer.set_col_spacings (0);
525 edit_packer.set_row_spacings (0);
526 edit_packer.set_homogeneous (false);
527 edit_packer.set_border_width (0);
528 edit_packer.set_name ("EditorWindow");
530 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
531 /* labels for the rulers */
532 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
533 /* labels for the marker "tracks" */
534 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
536 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
538 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
540 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
542 bottom_hbox.set_border_width (2);
543 bottom_hbox.set_spacing (3);
545 _route_groups = new EditorRouteGroups (this);
546 _routes = new EditorRoutes (this);
547 _regions = new EditorRegions (this);
548 _snapshots = new EditorSnapshots (this);
549 _locations = new EditorLocations (this);
553 nlabel = manage (new Label (_("Regions")));
554 nlabel->set_angle (-90);
555 the_notebook.append_page (_regions->widget (), *nlabel);
556 nlabel = manage (new Label (_("Tracks & Busses")));
557 nlabel->set_angle (-90);
558 the_notebook.append_page (_routes->widget (), *nlabel);
559 nlabel = manage (new Label (_("Snapshots")));
560 nlabel->set_angle (-90);
561 the_notebook.append_page (_snapshots->widget (), *nlabel);
562 nlabel = manage (new Label (_("Route Groups")));
563 nlabel->set_angle (-90);
564 the_notebook.append_page (_route_groups->widget (), *nlabel);
565 nlabel = manage (new Label (_("Ranges & Marks")));
566 nlabel->set_angle (-90);
567 the_notebook.append_page (_locations->widget (), *nlabel);
569 the_notebook.set_show_tabs (true);
570 the_notebook.set_scrollable (true);
571 the_notebook.popup_disable ();
572 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
573 the_notebook.show_all ();
575 post_maximal_editor_width = 0;
576 post_maximal_pane_position = 0;
578 VPaned *editor_summary_pane = manage(new VPaned());
579 editor_summary_pane->pack1(edit_packer);
581 Button* summary_arrows_left_left = manage (new Button);
582 summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
583 summary_arrows_left_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
584 Button* summary_arrows_left_right = manage (new Button);
585 summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
586 summary_arrows_left_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
587 VBox* summary_arrows_left = manage (new VBox);
588 summary_arrows_left->pack_start (*summary_arrows_left_left);
589 summary_arrows_left->pack_start (*summary_arrows_left_right);
591 Button* summary_arrows_right_left = manage (new Button);
592 summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
593 summary_arrows_right_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
594 Button* summary_arrows_right_right = manage (new Button);
595 summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
596 summary_arrows_right_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
597 VBox* summary_arrows_right = manage (new VBox);
598 summary_arrows_right->pack_start (*summary_arrows_right_left);
599 summary_arrows_right->pack_start (*summary_arrows_right_right);
601 Frame* summary_frame = manage (new Frame);
602 summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
603 summary_frame->add (*_summary);
604 summary_frame->show ();
606 _summary_hbox.pack_start (*summary_arrows_left, false, false);
607 _summary_hbox.pack_start (*summary_frame, true, true);
608 _summary_hbox.pack_start (*summary_arrows_right, false, false);
610 editor_summary_pane->pack2 (_summary_hbox);
612 edit_pane.pack1 (*editor_summary_pane, true, true);
613 edit_pane.pack2 (the_notebook, false, true);
615 edit_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
617 Glib::PropertyProxy<int> proxy = edit_pane.property_position();
618 proxy.signal_changed().connect (bind (sigc::ptr_fun (pane_size_watcher), static_cast<Paned*> (&edit_pane)));
620 top_hbox.pack_start (toolbar_frame, false, true);
622 HBox *hbox = manage (new HBox);
623 hbox->pack_start (edit_pane, true, true);
625 global_vpacker.pack_start (top_hbox, false, false);
626 global_vpacker.pack_start (*hbox, true, true);
628 global_hpacker.pack_start (global_vpacker, true, true);
630 set_name ("EditorWindow");
631 add_accel_group (ActionManager::ui_manager->get_accel_group());
633 status_bar_hpacker.show ();
635 vpacker.pack_end (status_bar_hpacker, false, false);
636 vpacker.pack_end (global_hpacker, true, true);
638 /* register actions now so that set_state() can find them and set toggles/checks etc */
643 setup_midi_toolbar ();
645 _snap_type = SnapToBeat;
646 set_snap_to (_snap_type);
647 _snap_mode = SnapOff;
648 set_snap_mode (_snap_mode);
649 set_mouse_mode (MouseObject, true);
650 set_edit_point_preference (EditAtMouse, true);
652 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
653 set_state (*node, Stateful::loading_state_version);
655 _playlist_selector = new PlaylistSelector();
656 _playlist_selector->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
658 RegionView::RegionViewGoingAway.connect (*this, invalidator (*this), ui_bind (&Editor::catch_vanishing_regionview, this, _1), gui_context());
662 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
663 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
665 nudge_forward_button.set_name ("TransportButton");
666 nudge_backward_button.set_name ("TransportButton");
668 fade_context_menu.set_name ("ArdourContextMenu");
670 /* icons, titles, WM stuff */
672 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
673 Glib::RefPtr<Gdk::Pixbuf> icon;
675 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
676 window_icons.push_back (icon);
678 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
679 window_icons.push_back (icon);
681 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
682 window_icons.push_back (icon);
684 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
685 window_icons.push_back (icon);
687 if (!window_icons.empty()) {
688 set_icon_list (window_icons);
689 set_default_icon_list (window_icons);
692 WindowTitle title(Glib::get_application_name());
693 title += _("Editor");
694 set_title (title.get_string());
695 set_wmclass (X_("ardour_editor"), "Ardour");
698 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
700 signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
701 signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
703 /* allow external control surfaces/protocols to do various things */
705 ControlProtocol::ZoomToSession.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_session, this), gui_context());
706 ControlProtocol::ZoomIn.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
707 ControlProtocol::ZoomOut.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
708 ControlProtocol::ScrollTimeline.connect (*this, invalidator (*this), ui_bind (&Editor::control_scroll, this, _1), gui_context());
709 BasicUI::AccessAction.connect (*this, invalidator (*this), ui_bind (&Editor::access_action, this, _1, _2), gui_context());
711 /* problematic: has to return a value and thus cannot be x-thread */
713 Session::AskAboutPlaylistDeletion.connect_same_thread (*this, boost::bind (&Editor::playlist_deletion_dialog, this, _1));
715 Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
717 TimeAxisView::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&Editor::timeaxisview_deleted, this, _1), gui_context());
719 _last_normalization_value = 0;
728 if(image_socket_listener) {
729 if(image_socket_listener->is_connected())
731 image_socket_listener->close_connection() ;
734 delete image_socket_listener ;
735 image_socket_listener = 0 ;
740 delete _route_groups;
746 Editor::add_toplevel_controls (Container& cont)
748 vpacker.pack_start (cont, false, false);
753 Editor::catch_vanishing_regionview (RegionView *rv)
755 /* note: the selection will take care of the vanishing
756 audioregionview by itself.
759 if (_drags->active() && _drags->have_item (rv->get_canvas_group()) && !_drags->ending()) {
763 if (clicked_regionview == rv) {
764 clicked_regionview = 0;
767 if (entered_regionview == rv) {
768 set_entered_regionview (0);
773 Editor::set_entered_regionview (RegionView* rv)
775 if (rv == entered_regionview) {
779 if (entered_regionview) {
780 entered_regionview->exited ();
783 if ((entered_regionview = rv) != 0) {
784 entered_regionview->entered ();
789 Editor::set_entered_track (TimeAxisView* tav)
792 entered_track->exited ();
795 if ((entered_track = tav) != 0) {
796 entered_track->entered ();
801 Editor::show_window ()
803 if (! is_visible ()) {
806 /* re-hide editor list if necessary */
807 editor_list_button_toggled ();
809 /* re-hide summary widget if necessary */
810 parameter_changed ("show-summary");
812 parameter_changed ("show-edit-group-tabs");
814 /* now reset all audio_time_axis heights, because widgets might need
820 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
821 tv = (static_cast<TimeAxisView*>(*i));
825 reset_zoom (frames_per_unit);
832 Editor::instant_save ()
834 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
839 _session->add_instant_xml(get_state());
841 Config->add_instant_xml(get_state());
846 Editor::zoom_adjustment_changed ()
852 double fpu = zoom_range_clock.current_duration() / _canvas_width;
856 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
857 } else if (fpu > _session->current_end_frame() / _canvas_width) {
858 fpu = _session->current_end_frame() / _canvas_width;
859 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
866 Editor::control_scroll (float fraction)
868 ENSURE_GUI_THREAD (*this, &Editor::control_scroll, fraction)
874 double step = fraction * current_page_frames();
877 _control_scroll_target is an optional<T>
879 it acts like a pointer to an nframes64_t, with
880 a operator conversion to boolean to check
881 that it has a value could possibly use
882 playhead_cursor->current_frame to store the
883 value and a boolean in the class to know
884 when it's out of date
887 if (!_control_scroll_target) {
888 _control_scroll_target = _session->transport_frame();
889 _dragging_playhead = true;
892 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
893 *_control_scroll_target = 0;
894 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
895 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
897 *_control_scroll_target += (nframes64_t) floor (step);
900 /* move visuals, we'll catch up with it later */
902 playhead_cursor->set_position (*_control_scroll_target);
903 UpdateAllTransportClocks (*_control_scroll_target);
905 if (*_control_scroll_target > (current_page_frames() / 2)) {
906 /* try to center PH in window */
907 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
913 Now we do a timeout to actually bring the session to the right place
914 according to the playhead. This is to avoid reading disk buffers on every
915 call to control_scroll, which is driven by ScrollTimeline and therefore
916 probably by a control surface wheel which can generate lots of events.
918 /* cancel the existing timeout */
920 control_scroll_connection.disconnect ();
922 /* add the next timeout */
924 control_scroll_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
928 Editor::deferred_control_scroll (nframes64_t /*target*/)
930 _session->request_locate (*_control_scroll_target, _session->transport_rolling());
931 // reset for next stream
932 _control_scroll_target = boost::none;
933 _dragging_playhead = false;
938 Editor::access_action (std::string action_group, std::string action_item)
944 ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
947 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
955 Editor::on_realize ()
957 Window::on_realize ();
962 Editor::map_position_change (nframes64_t frame)
964 ENSURE_GUI_THREAD (*this, &Editor::map_position_change, frame)
966 if (_session == 0 || !_follow_playhead) {
970 center_screen (frame);
971 playhead_cursor->set_position (frame);
975 Editor::center_screen (nframes64_t frame)
977 double page = _canvas_width * frames_per_unit;
979 /* if we're off the page, then scroll.
982 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
983 center_screen_internal (frame, page);
988 Editor::center_screen_internal (nframes64_t frame, float page)
993 frame -= (nframes64_t) page;
998 reset_x_origin (frame);
1003 Editor::update_title ()
1005 ENSURE_GUI_THREAD (*this, &Editor::update_title)
1008 bool dirty = _session->dirty();
1010 string session_name;
1012 if (_session->snap_name() != _session->name()) {
1013 session_name = _session->snap_name();
1015 session_name = _session->name();
1019 session_name = "*" + session_name;
1022 WindowTitle title(session_name);
1023 title += Glib::get_application_name();
1024 set_title (title.get_string());
1029 Editor::set_session (Session *t)
1031 SessionHandlePtr::set_session (t);
1037 zoom_range_clock.set_session (_session);
1038 _playlist_selector->set_session (_session);
1039 nudge_clock.set_session (_session);
1040 _summary->set_session (_session);
1041 _group_tabs->set_session (_session);
1042 _route_groups->set_session (_session);
1043 _regions->set_session (_session);
1044 _snapshots->set_session (_session);
1045 _routes->set_session (_session);
1046 _locations->set_session (_session);
1048 if (rhythm_ferret) {
1049 rhythm_ferret->set_session (_session);
1052 if (analysis_window) {
1053 analysis_window->set_session (_session);
1057 sfbrowser->set_session (_session);
1060 compute_fixed_ruler_scale ();
1062 /* there are never any selected regions at startup */
1063 sensitize_the_right_region_actions (false);
1065 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1066 set_state (*node, Stateful::loading_state_version);
1068 /* catch up with the playhead */
1070 _session->request_locate (playhead_cursor->current_frame);
1071 _pending_initial_locate = true;
1075 /* These signals can all be emitted by a non-GUI thread. Therefore the
1076 handlers for them must not attempt to directly interact with the GUI,
1077 but use Gtkmm2ext::UI::instance()->call_slot();
1080 _session->TransportStateChange.connect (_session_connections, invalidator (*this), boost::bind (&Editor::map_transport_state, this), gui_context());
1081 _session->PositionChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::map_position_change, this, _1), gui_context());
1082 _session->RouteAdded.connect (_session_connections, invalidator (*this), ui_bind (&Editor::handle_new_route, this, _1), gui_context());
1083 _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_title, this), gui_context());
1084 _session->TimecodeOffsetChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_just_timecode, this), gui_context());
1085 _session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::tempo_map_changed, this, _1), gui_context());
1086 _session->Located.connect (_session_connections, invalidator (*this), boost::bind (&Editor::located, this), gui_context());
1087 _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
1088 _session->StateSaved.connect (_session_connections, invalidator (*this), ui_bind (&Editor::session_state_saved, this, _1), gui_context());
1089 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&Editor::add_new_location, this, _1), gui_context());
1090 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&Editor::location_gone, this, _1), gui_context());
1091 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::refresh_location_display, this), gui_context());
1092 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::refresh_location_display_s, this, _1), gui_context());
1093 _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context());
1095 if (Profile->get_sae()) {
1100 nframes_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
1101 nudge_clock.set_mode(AudioClock::BBT);
1102 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1105 nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
1108 playhead_cursor->canvas_item.show ();
1110 Location* loc = _session->locations()->auto_loop_location();
1112 loc = new Location (0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1113 if (loc->start() == loc->end()) {
1114 loc->set_end (loc->start() + 1);
1116 _session->locations()->add (loc, false);
1117 _session->set_auto_loop_location (loc);
1120 loc->set_name (_("Loop"));
1123 loc = _session->locations()->auto_punch_location();
1125 loc = new Location (0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1126 if (loc->start() == loc->end()) {
1127 loc->set_end (loc->start() + 1);
1129 _session->locations()->add (loc, false);
1130 _session->set_auto_punch_location (loc);
1133 loc->set_name (_("Punch"));
1136 boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
1137 Config->map_parameters (pc);
1138 _session->config.map_parameters (pc);
1140 refresh_location_display ();
1142 restore_ruler_visibility ();
1143 //tempo_map_changed (PropertyChange (0));
1144 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1146 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1147 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1150 super_rapid_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
1151 sigc::mem_fun (*this, &Editor::super_rapid_screen_update)
1154 switch (_snap_type) {
1155 case SnapToRegionStart:
1156 case SnapToRegionEnd:
1157 case SnapToRegionSync:
1158 case SnapToRegionBoundary:
1159 build_region_boundary_cache ();
1166 /* register for undo history */
1167 _session->register_with_memento_command_factory(_id, this);
1169 start_updating_meters ();
1173 Editor::build_cursors ()
1175 using namespace Gdk;
1177 Gdk::Color mbg ("#000000" ); /* Black */
1178 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1181 RefPtr<Bitmap> source, mask;
1182 source = Bitmap::create (mag_bits, mag_width, mag_height);
1183 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1184 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1187 Gdk::Color fbg ("#ffffff" );
1188 Gdk::Color ffg ("#000000" );
1191 RefPtr<Bitmap> source, mask;
1193 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1194 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1195 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1199 RefPtr<Bitmap> source, mask;
1200 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1201 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1202 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1206 RefPtr<Bitmap> bits;
1207 char pix[4] = { 0, 0, 0, 0 };
1208 bits = Bitmap::create (pix, 2, 2);
1210 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1214 RefPtr<Bitmap> bits;
1215 char pix[4] = { 0, 0, 0, 0 };
1216 bits = Bitmap::create (pix, 2, 2);
1218 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1222 grabber_cursor = new Gdk::Cursor (HAND2);
1225 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1226 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1229 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1230 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1231 selector_cursor = new Gdk::Cursor (XTERM);
1232 time_fx_cursor = new Gdk::Cursor (SIZING);
1233 wait_cursor = new Gdk::Cursor (WATCH);
1234 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1235 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1236 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1237 midi_resize_cursor = new Gdk::Cursor (SIZING);
1238 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1241 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1243 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1245 using namespace Menu_Helpers;
1246 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1249 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1253 MenuList& items (fade_context_menu.items());
1257 switch (item_type) {
1259 case FadeInHandleItem:
1260 if (arv->audio_region()->fade_in_active()) {
1261 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), false)));
1263 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), true)));
1266 items.push_back (SeparatorElem());
1268 if (Profile->get_sae()) {
1269 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1270 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1272 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1273 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1274 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1275 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1276 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1282 case FadeOutHandleItem:
1283 if (arv->audio_region()->fade_out_active()) {
1284 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), false)));
1286 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), true)));
1289 items.push_back (SeparatorElem());
1291 if (Profile->get_sae()) {
1292 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1293 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1295 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1296 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1297 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1298 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1299 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1305 fatal << _("programming error: ")
1306 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1311 fade_context_menu.popup (button, time);
1315 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1317 using namespace Menu_Helpers;
1318 Menu* (Editor::*build_menu_function)(nframes64_t);
1321 switch (item_type) {
1323 case RegionViewName:
1324 case RegionViewNameHighlight:
1325 if (with_selection) {
1326 build_menu_function = &Editor::build_track_selection_context_menu;
1328 build_menu_function = &Editor::build_track_region_context_menu;
1333 if (with_selection) {
1334 build_menu_function = &Editor::build_track_selection_context_menu;
1336 build_menu_function = &Editor::build_track_context_menu;
1340 case CrossfadeViewItem:
1341 build_menu_function = &Editor::build_track_crossfade_context_menu;
1345 if (clicked_routeview->track()) {
1346 build_menu_function = &Editor::build_track_context_menu;
1348 build_menu_function = &Editor::build_track_bus_context_menu;
1353 /* probably shouldn't happen but if it does, we don't care */
1357 menu = (this->*build_menu_function)(frame);
1358 menu->set_name ("ArdourContextMenu");
1360 /* now handle specific situations */
1362 switch (item_type) {
1364 case RegionViewName:
1365 case RegionViewNameHighlight:
1366 if (!with_selection) {
1367 if (region_edit_menu_split_item) {
1368 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1369 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1371 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1374 if (region_edit_menu_split_multichannel_item) {
1375 if (clicked_regionview && clicked_regionview->region()->n_channels() > 1) {
1376 region_edit_menu_split_multichannel_item->set_sensitive (true);
1378 region_edit_menu_split_multichannel_item->set_sensitive (false);
1387 case CrossfadeViewItem:
1394 /* probably shouldn't happen but if it does, we don't care */
1398 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1400 /* Bounce to disk */
1402 using namespace Menu_Helpers;
1403 MenuList& edit_items = menu->items();
1405 edit_items.push_back (SeparatorElem());
1407 switch (clicked_routeview->audio_track()->freeze_state()) {
1408 case AudioTrack::NoFreeze:
1409 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1412 case AudioTrack::Frozen:
1413 edit_items.push_back (MenuElem (_("Unfreeze"), sigc::mem_fun(*this, &Editor::unfreeze_route)));
1416 case AudioTrack::UnFrozen:
1417 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1423 if (item_type == StreamItem && clicked_routeview) {
1424 clicked_routeview->build_underlay_menu(menu);
1427 menu->popup (button, time);
1431 Editor::build_track_context_menu (nframes64_t)
1433 using namespace Menu_Helpers;
1435 MenuList& edit_items = track_context_menu.items();
1438 add_dstream_context_items (edit_items);
1439 return &track_context_menu;
1443 Editor::build_track_bus_context_menu (nframes64_t)
1445 using namespace Menu_Helpers;
1447 MenuList& edit_items = track_context_menu.items();
1450 add_bus_context_items (edit_items);
1451 return &track_context_menu;
1455 Editor::build_track_region_context_menu (nframes64_t frame)
1457 using namespace Menu_Helpers;
1458 MenuList& edit_items = track_region_context_menu.items();
1461 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1464 boost::shared_ptr<Track> tr;
1465 boost::shared_ptr<Playlist> pl;
1467 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
1468 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * tr->speed()));
1470 if (selection->regions.size() > 1) {
1471 // there's already a multiple selection: just add a
1472 // single region context menu that will act on all
1474 boost::shared_ptr<Region> dummy_region; // = NULL
1475 add_region_context_items (rtv->view(), dummy_region, edit_items);
1477 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1478 add_region_context_items (rtv->view(), (*i), edit_items);
1486 add_dstream_context_items (edit_items);
1488 return &track_region_context_menu;
1492 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1494 using namespace Menu_Helpers;
1495 MenuList& edit_items = track_crossfade_context_menu.items();
1496 edit_items.clear ();
1498 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1501 boost::shared_ptr<Track> tr;
1502 boost::shared_ptr<Playlist> pl;
1503 boost::shared_ptr<AudioPlaylist> apl;
1505 if ((tr = atv->track()) && ((pl = tr->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1507 Playlist::RegionList* regions = pl->regions_at (frame);
1508 AudioPlaylist::Crossfades xfades;
1510 apl->crossfades_at (frame, xfades);
1512 bool many = xfades.size() > 1;
1514 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1515 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1518 if (selection->regions.size() > 1) {
1519 // there's already a multiple selection: just add a
1520 // single region context menu that will act on all
1522 boost::shared_ptr<Region> dummy_region; // = NULL
1523 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1525 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1526 add_region_context_items (atv->audio_view(), (*i), edit_items);
1533 add_dstream_context_items (edit_items);
1535 return &track_crossfade_context_menu;
1539 Editor::analyze_region_selection()
1541 if (analysis_window == 0) {
1542 analysis_window = new AnalysisWindow();
1545 analysis_window->set_session(_session);
1547 analysis_window->show_all();
1550 analysis_window->set_regionmode();
1551 analysis_window->analyze();
1553 analysis_window->present();
1557 Editor::analyze_range_selection()
1559 if (analysis_window == 0) {
1560 analysis_window = new AnalysisWindow();
1563 analysis_window->set_session(_session);
1565 analysis_window->show_all();
1568 analysis_window->set_rangemode();
1569 analysis_window->analyze();
1571 analysis_window->present();
1575 Editor::build_track_selection_context_menu (nframes64_t)
1577 using namespace Menu_Helpers;
1578 MenuList& edit_items = track_selection_context_menu.items();
1579 edit_items.clear ();
1581 add_selection_context_items (edit_items);
1582 // edit_items.push_back (SeparatorElem());
1583 // add_dstream_context_items (edit_items);
1585 return &track_selection_context_menu;
1588 /** Add context menu items relevant to crossfades.
1589 * @param edit_items List to add the items to.
1592 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1594 using namespace Menu_Helpers;
1595 Menu *xfade_menu = manage (new Menu);
1596 MenuList& items = xfade_menu->items();
1597 xfade_menu->set_name ("ArdourContextMenu");
1600 if (xfade->active()) {
1606 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1607 items.push_back (MenuElem (_("Edit"), sigc::bind (sigc::mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1609 if (xfade->can_follow_overlap()) {
1611 if (xfade->following_overlap()) {
1612 str = _("Convert to Short");
1614 str = _("Convert to Full");
1617 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1621 str = xfade->out()->name();
1623 str += xfade->in()->name();
1625 str = _("Crossfade");
1628 edit_items.push_back (MenuElem (str, *xfade_menu));
1629 edit_items.push_back (SeparatorElem());
1633 Editor::xfade_edit_left_region ()
1635 if (clicked_crossfadeview) {
1636 clicked_crossfadeview->left_view.show_region_editor ();
1641 Editor::xfade_edit_right_region ()
1643 if (clicked_crossfadeview) {
1644 clicked_crossfadeview->right_view.show_region_editor ();
1649 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1651 using namespace Menu_Helpers;
1652 Gtk::MenuItem* foo_item;
1653 Menu *region_menu = manage (new Menu);
1654 MenuList& items = region_menu->items();
1655 region_menu->set_name ("ArdourContextMenu");
1657 boost::shared_ptr<AudioRegion> ar;
1658 boost::shared_ptr<MidiRegion> mr;
1661 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1662 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1664 /* when this particular menu pops up, make the relevant region
1668 region_menu->signal_map_event().connect (
1669 sigc::bind (sigc::mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1671 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::rename_region)));
1672 if (mr && internal_editing()) {
1673 items.push_back (MenuElem (_("List editor..."), sigc::mem_fun(*this, &Editor::show_midi_list_editor)));
1675 items.push_back (MenuElem (_("Region Properties..."), sigc::mem_fun(*this, &Editor::edit_region)));
1679 items.push_back (MenuElem (_("Raise to Top Layer"), sigc::mem_fun(*this, &Editor::raise_region_to_top)));
1680 items.push_back (MenuElem (_("Lower to Bottom Layer"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom)));
1681 items.push_back (SeparatorElem());
1682 items.push_back (MenuElem (_("Define Sync Point"), sigc::mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1683 if (_edit_point == EditAtMouse) {
1684 items.back ().set_sensitive (false);
1686 items.push_back (MenuElem (_("Remove Sync Point"), sigc::mem_fun(*this, &Editor::remove_region_sync)));
1687 items.push_back (SeparatorElem());
1689 items.push_back (MenuElem (_("Audition"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1690 items.push_back (MenuElem (_("Export..."), sigc::mem_fun(*this, &Editor::export_region)));
1691 items.push_back (MenuElem (_("Bounce"), sigc::mem_fun(*this, &Editor::bounce_region_selection)));
1694 items.push_back (MenuElem (_("Spectral Analysis..."), sigc::mem_fun(*this, &Editor::analyze_region_selection)));
1697 items.push_back (SeparatorElem());
1699 sigc::connection fooc;
1700 boost::shared_ptr<Region> region_to_check;
1703 region_to_check = region;
1705 region_to_check = selection->regions.front()->region();
1708 items.push_back (CheckMenuElem (_("Lock")));
1709 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1710 if (region_to_check->locked()) {
1711 region_lock_item->set_active();
1713 region_lock_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_lock));
1715 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
1716 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1718 switch (region_to_check->positional_lock_style()) {
1719 case Region::MusicTime:
1720 bbt_glue_item->set_active (true);
1723 bbt_glue_item->set_active (false);
1727 bbt_glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_region_lock_style));
1729 items.push_back (CheckMenuElem (_("Mute")));
1730 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1731 fooc = region_mute_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_mute));
1732 if (region_to_check->muted()) {
1734 region_mute_item->set_active();
1738 items.push_back (MenuElem (_("Transpose..."), mem_fun(*this, &Editor::pitch_shift_regions)));
1740 if (!Profile->get_sae()) {
1741 items.push_back (CheckMenuElem (_("Opaque")));
1742 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1743 fooc = region_opaque_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_opaque));
1744 if (region_to_check->opaque()) {
1746 region_opaque_item->set_active();
1751 items.push_back (CheckMenuElem (_("Original Position"), sigc::mem_fun(*this, &Editor::naturalize)));
1752 if (region_to_check->at_natural_position()) {
1753 items.back().set_sensitive (false);
1756 items.push_back (SeparatorElem());
1760 RegionView* rv = sv->find_view (ar);
1761 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1763 if (!Profile->get_sae()) {
1764 items.push_back (MenuElem (_("Reset Envelope"), sigc::mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1766 items.push_back (CheckMenuElem (_("Envelope Visible")));
1767 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1768 fooc = region_envelope_visible_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1769 if (arv->envelope_visible()) {
1771 region_envelope_visible_item->set_active (true);
1775 items.push_back (CheckMenuElem (_("Envelope Active")));
1776 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1777 fooc = region_envelope_active_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_active));
1779 if (ar->envelope_active()) {
1781 region_envelope_active_item->set_active (true);
1785 items.push_back (SeparatorElem());
1788 items.push_back (MenuElem (_("Normalize..."), sigc::mem_fun(*this, &Editor::normalize_region)));
1789 if (ar->scale_amplitude() != 1) {
1790 items.push_back (MenuElem (_("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_scale_amplitude)));
1794 items.push_back (MenuElem (_("Quantize"), sigc::mem_fun(*this, &Editor::quantize_region)));
1795 items.push_back (MenuElem (_("Fork"), sigc::mem_fun(*this, &Editor::fork_region)));
1796 items.push_back (SeparatorElem());
1799 items.push_back (MenuElem (_("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence)));
1800 items.push_back (MenuElem (_("Reverse"), sigc::mem_fun(*this, &Editor::reverse_region)));
1801 items.push_back (SeparatorElem());
1803 /* range related stuff */
1805 items.push_back (MenuElem (_("Add Single Range"), sigc::mem_fun (*this, &Editor::add_location_from_audio_region)));
1806 items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_locations_from_audio_region)));
1807 if (selection->regions.size() < 2) {
1808 items.back().set_sensitive (false);
1811 items.push_back (MenuElem (_("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region)));
1812 items.push_back (SeparatorElem());
1816 Menu *nudge_menu = manage (new Menu());
1817 MenuList& nudge_items = nudge_menu->items();
1818 nudge_menu->set_name ("ArdourContextMenu");
1820 nudge_items.push_back (MenuElem (_("Nudge Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_forward), false, false))));
1821 nudge_items.push_back (MenuElem (_("Nudge Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_backward), false, false))));
1822 nudge_items.push_back (MenuElem (_("Nudge Forward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1823 nudge_items.push_back (MenuElem (_("Nudge Backward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1825 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1826 items.push_back (SeparatorElem());
1828 Menu *trim_menu = manage (new Menu);
1829 MenuList& trim_items = trim_menu->items();
1830 trim_menu->set_name ("ArdourContextMenu");
1832 trim_items.push_back (MenuElem (_("Start to Edit Point"), sigc::mem_fun(*this, &Editor::trim_region_from_edit_point)));
1833 foo_item = &trim_items.back();
1834 if (_edit_point == EditAtMouse) {
1835 foo_item->set_sensitive (false);
1837 trim_items.push_back (MenuElem (_("Edit Point to End"), sigc::mem_fun(*this, &Editor::trim_region_to_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 (_("Trim to Loop"), sigc::mem_fun(*this, &Editor::trim_region_to_loop)));
1843 trim_items.push_back (MenuElem (_("Trim to Punch"), sigc::mem_fun(*this, &Editor::trim_region_to_punch)));
1845 items.push_back (MenuElem (_("Trim"), *trim_menu));
1846 items.push_back (SeparatorElem());
1848 items.push_back (MenuElem (_("Split"), (sigc::mem_fun(*this, &Editor::split))));
1849 region_edit_menu_split_item = &items.back();
1851 if (_edit_point == EditAtMouse) {
1852 region_edit_menu_split_item->set_sensitive (false);
1855 items.push_back (MenuElem (_("Make Mono Regions"), (sigc::mem_fun(*this, &Editor::split_multichannel_region))));
1856 region_edit_menu_split_multichannel_item = &items.back();
1858 items.push_back (MenuElem (_("Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false))));
1859 items.push_back (MenuElem (_("Multi-Duplicate..."), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), true))));
1860 items.push_back (MenuElem (_("Fill Track"), (sigc::mem_fun(*this, &Editor::region_fill_track))));
1861 items.push_back (SeparatorElem());
1862 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::remove_selected_regions)));
1864 /* OK, stick the region submenu at the top of the list, and then add
1868 /* we have to hack up the region name because "_" has a special
1869 meaning for menu titles.
1872 string::size_type pos = 0;
1873 string menu_item_name = (region) ? region->name() : _("Selected Regions");
1875 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1876 menu_item_name.replace (pos, 1, "__");
1880 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1881 edit_items.push_back (SeparatorElem());
1884 /** Add context menu items relevant to selection ranges.
1885 * @param edit_items List to add the items to.
1888 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1890 using namespace Menu_Helpers;
1892 edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
1893 edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
1895 edit_items.push_back (SeparatorElem());
1896 edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
1898 if (!selection->regions.empty()) {
1899 edit_items.push_back (SeparatorElem());
1900 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)));
1901 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)));
1904 edit_items.push_back (SeparatorElem());
1905 edit_items.push_back (MenuElem (_("Silence Range"), sigc::mem_fun(*this, &Editor::separate_region_from_selection)));
1906 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
1908 edit_items.push_back (SeparatorElem());
1909 edit_items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1911 edit_items.push_back (SeparatorElem());
1912 edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false)));
1913 edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
1915 edit_items.push_back (SeparatorElem());
1916 edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
1918 edit_items.push_back (SeparatorElem());
1919 edit_items.push_back (MenuElem (_("Crop Region to Range"), sigc::mem_fun(*this, &Editor::crop_region_to_selection)));
1920 edit_items.push_back (MenuElem (_("Fill Range with Region"), sigc::mem_fun(*this, &Editor::region_fill_selection)));
1921 edit_items.push_back (MenuElem (_("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false)));
1923 edit_items.push_back (SeparatorElem());
1924 edit_items.push_back (MenuElem (_("Consolidate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1925 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1926 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1927 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1928 edit_items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_range)));
1933 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1935 using namespace Menu_Helpers;
1939 Menu *play_menu = manage (new Menu);
1940 MenuList& play_items = play_menu->items();
1941 play_menu->set_name ("ArdourContextMenu");
1943 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
1944 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
1945 play_items.push_back (MenuElem (_("Play Region"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1946 play_items.push_back (SeparatorElem());
1947 play_items.push_back (MenuElem (_("Loop Region"), sigc::mem_fun(*this, &Editor::loop_selected_region)));
1949 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1953 Menu *select_menu = manage (new Menu);
1954 MenuList& select_items = select_menu->items();
1955 select_menu->set_name ("ArdourContextMenu");
1957 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1958 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
1959 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
1960 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
1961 select_items.push_back (SeparatorElem());
1962 select_items.push_back (MenuElem (_("Set Range to Loop Range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop)));
1963 select_items.push_back (MenuElem (_("Set Range to Punch Range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch)));
1964 select_items.push_back (SeparatorElem());
1965 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1966 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1967 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1968 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1969 select_items.push_back (MenuElem (_("Select All Between Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
1970 select_items.push_back (MenuElem (_("Select All Within Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
1971 select_items.push_back (MenuElem (_("Select Range Between Playhead and Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
1973 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1977 Menu *cutnpaste_menu = manage (new Menu);
1978 MenuList& cutnpaste_items = cutnpaste_menu->items();
1979 cutnpaste_menu->set_name ("ArdourContextMenu");
1981 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
1982 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
1983 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
1985 cutnpaste_items.push_back (SeparatorElem());
1987 cutnpaste_items.push_back (MenuElem (_("Align"), sigc::bind (sigc::mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
1988 cutnpaste_items.push_back (MenuElem (_("Align Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
1990 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
1992 /* Adding new material */
1994 edit_items.push_back (SeparatorElem());
1995 edit_items.push_back (MenuElem (_("Insert Selected Region"), sigc::bind (sigc::mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
1996 edit_items.push_back (MenuElem (_("Insert Existing Media"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2000 Menu *nudge_menu = manage (new Menu());
2001 MenuList& nudge_items = nudge_menu->items();
2002 nudge_menu->set_name ("ArdourContextMenu");
2004 edit_items.push_back (SeparatorElem());
2005 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2006 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2007 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2008 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2010 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2014 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2016 using namespace Menu_Helpers;
2020 Menu *play_menu = manage (new Menu);
2021 MenuList& play_items = play_menu->items();
2022 play_menu->set_name ("ArdourContextMenu");
2024 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
2025 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
2026 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2030 Menu *select_menu = manage (new Menu);
2031 MenuList& select_items = select_menu->items();
2032 select_menu->set_name ("ArdourContextMenu");
2034 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2035 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
2036 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
2037 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
2038 select_items.push_back (SeparatorElem());
2039 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2040 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2041 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2042 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2044 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2048 Menu *cutnpaste_menu = manage (new Menu);
2049 MenuList& cutnpaste_items = cutnpaste_menu->items();
2050 cutnpaste_menu->set_name ("ArdourContextMenu");
2052 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2053 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2054 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2056 Menu *nudge_menu = manage (new Menu());
2057 MenuList& nudge_items = nudge_menu->items();
2058 nudge_menu->set_name ("ArdourContextMenu");
2060 edit_items.push_back (SeparatorElem());
2061 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2062 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2063 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2064 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2066 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2070 Editor::snap_type() const
2076 Editor::snap_mode() const
2082 Editor::set_snap_to (SnapType st)
2084 unsigned int snap_ind = (unsigned int)st;
2088 if (snap_ind > snap_type_strings.size() - 1) {
2090 _snap_type = (SnapType)snap_ind;
2093 string str = snap_type_strings[snap_ind];
2095 if (str != snap_type_selector.get_active_text()) {
2096 snap_type_selector.set_active_text (str);
2101 switch (_snap_type) {
2102 case SnapToBeatDiv32:
2103 case SnapToBeatDiv28:
2104 case SnapToBeatDiv24:
2105 case SnapToBeatDiv16:
2106 case SnapToBeatDiv14:
2107 case SnapToBeatDiv12:
2108 case SnapToBeatDiv10:
2109 case SnapToBeatDiv8:
2110 case SnapToBeatDiv7:
2111 case SnapToBeatDiv6:
2112 case SnapToBeatDiv5:
2113 case SnapToBeatDiv4:
2114 case SnapToBeatDiv3:
2115 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2116 update_tempo_based_rulers ();
2119 case SnapToRegionStart:
2120 case SnapToRegionEnd:
2121 case SnapToRegionSync:
2122 case SnapToRegionBoundary:
2123 build_region_boundary_cache ();
2133 Editor::set_snap_mode (SnapMode mode)
2136 string str = snap_mode_strings[(int)mode];
2138 if (str != snap_mode_selector.get_active_text ()) {
2139 snap_mode_selector.set_active_text (str);
2145 Editor::set_edit_point_preference (EditPoint ep, bool force)
2147 bool changed = (_edit_point != ep);
2150 string str = edit_point_strings[(int)ep];
2152 if (str != edit_point_selector.get_active_text ()) {
2153 edit_point_selector.set_active_text (str);
2156 set_canvas_cursor ();
2158 if (!force && !changed) {
2162 const char* action=NULL;
2164 switch (_edit_point) {
2165 case EditAtPlayhead:
2166 action = "edit-at-playhead";
2168 case EditAtSelectedMarker:
2169 action = "edit-at-marker";
2172 action = "edit-at-mouse";
2176 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2178 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2182 bool in_track_canvas;
2184 if (!mouse_frame (foo, in_track_canvas)) {
2185 in_track_canvas = false;
2188 reset_canvas_action_sensitivity (in_track_canvas);
2194 Editor::set_state (const XMLNode& node, int /*version*/)
2196 const XMLProperty* prop;
2198 int x, y, xoff, yoff;
2201 if ((prop = node.property ("id")) != 0) {
2202 _id = prop->value ();
2205 g.base_width = default_width;
2206 g.base_height = default_height;
2212 if ((geometry = find_named_node (node, "geometry")) != 0) {
2216 if ((prop = geometry->property("x_size")) == 0) {
2217 prop = geometry->property ("x-size");
2220 g.base_width = atoi(prop->value());
2222 if ((prop = geometry->property("y_size")) == 0) {
2223 prop = geometry->property ("y-size");
2226 g.base_height = atoi(prop->value());
2229 if ((prop = geometry->property ("x_pos")) == 0) {
2230 prop = geometry->property ("x-pos");
2233 x = atoi (prop->value());
2236 if ((prop = geometry->property ("y_pos")) == 0) {
2237 prop = geometry->property ("y-pos");
2240 y = atoi (prop->value());
2243 if ((prop = geometry->property ("x_off")) == 0) {
2244 prop = geometry->property ("x-off");
2247 xoff = atoi (prop->value());
2249 if ((prop = geometry->property ("y_off")) == 0) {
2250 prop = geometry->property ("y-off");
2253 yoff = atoi (prop->value());
2257 set_default_size (g.base_width, g.base_height);
2260 if (_session && (prop = node.property ("playhead"))) {
2262 sscanf (prop->value().c_str(), "%" PRIi64, &pos);
2263 playhead_cursor->set_position (pos);
2265 playhead_cursor->set_position (0);
2268 if ((prop = node.property ("mixer-width"))) {
2269 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2272 if ((prop = node.property ("zoom-focus"))) {
2273 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2276 if ((prop = node.property ("zoom"))) {
2277 reset_zoom (PBD::atof (prop->value()));
2280 if ((prop = node.property ("snap-to"))) {
2281 set_snap_to ((SnapType) atoi (prop->value()));
2284 if ((prop = node.property ("snap-mode"))) {
2285 set_snap_mode ((SnapMode) atoi (prop->value()));
2288 if ((prop = node.property ("mouse-mode"))) {
2289 MouseMode m = str2mousemode(prop->value());
2290 set_mouse_mode (m, true);
2292 set_mouse_mode (MouseObject, true);
2295 if ((prop = node.property ("left-frame")) != 0){
2297 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
2298 reset_x_origin (pos);
2302 if ((prop = node.property ("y-origin")) != 0) {
2303 reset_y_origin (atof (prop->value ()));
2306 if ((prop = node.property ("internal-edit"))) {
2307 bool yn = string_is_affirmative (prop->value());
2308 RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit"));
2310 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2311 tact->set_active (!yn);
2312 tact->set_active (yn);
2316 if ((prop = node.property ("join-object-range"))) {
2317 join_object_range_button.set_active (string_is_affirmative (prop->value ()));
2320 if ((prop = node.property ("edit-point"))) {
2321 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2324 if ((prop = node.property ("show-measures"))) {
2325 bool yn = string_is_affirmative (prop->value());
2326 _show_measures = !yn;
2327 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2329 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2330 /* do it twice to force the change */
2331 tact->set_active (!yn);
2332 tact->set_active (yn);
2336 if ((prop = node.property ("follow-playhead"))) {
2337 bool yn = string_is_affirmative (prop->value());
2338 set_follow_playhead (yn);
2339 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2341 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2342 if (tact->get_active() != yn) {
2343 tact->set_active (yn);
2348 if ((prop = node.property ("stationary-playhead"))) {
2349 bool yn = (prop->value() == "yes");
2350 set_stationary_playhead (yn);
2351 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
2353 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2354 if (tact->get_active() != yn) {
2355 tact->set_active (yn);
2360 if ((prop = node.property ("region-list-sort-type"))) {
2361 RegionListSortType st;
2362 _regions->reset_sort_type ((RegionListSortType) string_2_enum (prop->value(), st), true);
2365 if ((prop = node.property ("xfades-visible"))) {
2366 bool yn = string_is_affirmative (prop->value());
2367 _xfade_visibility = !yn;
2368 // set_xfade_visibility (yn);
2371 if ((prop = node.property ("show-editor-mixer"))) {
2373 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2376 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2377 bool yn = string_is_affirmative (prop->value());
2379 /* do it twice to force the change */
2381 tact->set_active (!yn);
2382 tact->set_active (yn);
2386 if ((prop = node.property ("show-editor-list"))) {
2388 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2392 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2393 bool yn = string_is_affirmative (prop->value());
2395 /* do it twice to force the change */
2397 tact->set_active (!yn);
2398 tact->set_active (yn);
2402 if ((prop = node.property (X_("editor-list-page")))) {
2403 the_notebook.set_current_page (atoi (prop->value ()));
2406 if ((prop = node.property (X_("editor-pane-position")))) {
2407 edit_pane.set_position (atoi (prop->value ()));
2414 Editor::get_state ()
2416 XMLNode* node = new XMLNode ("Editor");
2419 _id.print (buf, sizeof (buf));
2420 node->add_property ("id", buf);
2422 if (is_realized()) {
2423 Glib::RefPtr<Gdk::Window> win = get_window();
2425 int x, y, xoff, yoff, width, height;
2426 win->get_root_origin(x, y);
2427 win->get_position(xoff, yoff);
2428 win->get_size(width, height);
2430 XMLNode* geometry = new XMLNode ("geometry");
2432 snprintf(buf, sizeof(buf), "%d", width);
2433 geometry->add_property("x-size", string(buf));
2434 snprintf(buf, sizeof(buf), "%d", height);
2435 geometry->add_property("y-size", string(buf));
2436 snprintf(buf, sizeof(buf), "%d", x);
2437 geometry->add_property("x-pos", string(buf));
2438 snprintf(buf, sizeof(buf), "%d", y);
2439 geometry->add_property("y-pos", string(buf));
2440 snprintf(buf, sizeof(buf), "%d", xoff);
2441 geometry->add_property("x-off", string(buf));
2442 snprintf(buf, sizeof(buf), "%d", yoff);
2443 geometry->add_property("y-off", string(buf));
2444 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2445 geometry->add_property("edit_pane_pos", string(buf));
2447 node->add_child_nocopy (*geometry);
2450 maybe_add_mixer_strip_width (*node);
2452 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2453 node->add_property ("zoom-focus", buf);
2454 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2455 node->add_property ("zoom", buf);
2456 snprintf (buf, sizeof(buf), "%d", (int) _snap_type);
2457 node->add_property ("snap-to", buf);
2458 snprintf (buf, sizeof(buf), "%d", (int) _snap_mode);
2459 node->add_property ("snap-mode", buf);
2461 node->add_property ("edit-point", enum_2_string (_edit_point));
2463 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2464 node->add_property ("playhead", buf);
2465 snprintf (buf, sizeof (buf), "%" PRIi64, leftmost_frame);
2466 node->add_property ("left-frame", buf);
2467 snprintf (buf, sizeof (buf), "%f", vertical_adjustment.get_value ());
2468 node->add_property ("y-origin", buf);
2470 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2471 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2472 node->add_property ("stationary-playhead", _stationary_playhead ? "yes" : "no");
2473 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2474 node->add_property ("region-list-sort-type", enum_2_string (_regions->sort_type ()));
2475 node->add_property ("mouse-mode", enum2str(mouse_mode));
2476 node->add_property ("internal-edit", _internal_editing ? "yes" : "no");
2477 node->add_property ("join-object-range", join_object_range_button.get_active () ? "yes" : "no");
2479 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2481 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2482 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2485 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2487 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2488 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2491 snprintf (buf, sizeof (buf), "%d", the_notebook.get_current_page ());
2492 node->add_property (X_("editor-list-page"), buf);
2494 snprintf (buf, sizeof (buf), "%d", edit_pane.get_position ());
2495 node->add_property (X_("editor-pane-position"), buf);
2502 /** @param y y offset from the top of all trackviews.
2503 * @return pair: TimeAxisView that y is over, layer index.
2504 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2505 * in stacked region display mode, otherwise 0.
2507 std::pair<TimeAxisView *, layer_t>
2508 Editor::trackview_by_y_position (double y)
2510 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2512 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2518 return std::make_pair ( (TimeAxisView *) 0, 0);
2521 /** Snap a position to the grid, if appropriate, taking into account current
2522 * grid settings and also the state of any snap modifier keys that may be pressed.
2523 * @param start Position to snap.
2524 * @param event Event to get current key modifier information from, or 0.
2527 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2529 if (!_session || !event) {
2533 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2534 if (_snap_mode == SnapOff) {
2535 snap_to_internal (start, direction, for_mark);
2538 if (_snap_mode != SnapOff) {
2539 snap_to_internal (start, direction, for_mark);
2545 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2547 if (!_session || _snap_mode == SnapOff) {
2551 snap_to_internal (start, direction, for_mark);
2555 Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
2557 const nframes64_t one_timecode_second = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
2558 nframes64_t one_timecode_minute = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
2560 switch (_snap_type) {
2561 case SnapToTimecodeFrame:
2562 if (((direction == 0) && (fmod((double)start, (double)_session->frames_per_timecode_frame()) > (_session->frames_per_timecode_frame() / 2))) || (direction > 0)) {
2563 start = (nframes64_t) (ceil ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2565 start = (nframes64_t) (floor ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2569 case SnapToTimecodeSeconds:
2570 if (_session->timecode_offset_negative())
2572 start += _session->timecode_offset ();
2574 start -= _session->timecode_offset ();
2576 if (((direction == 0) && (start % one_timecode_second > one_timecode_second / 2)) || direction > 0) {
2577 start = (nframes64_t) ceil ((double) start / one_timecode_second) * one_timecode_second;
2579 start = (nframes64_t) floor ((double) start / one_timecode_second) * one_timecode_second;
2582 if (_session->timecode_offset_negative())
2584 start -= _session->timecode_offset ();
2586 start += _session->timecode_offset ();
2590 case SnapToTimecodeMinutes:
2591 if (_session->timecode_offset_negative())
2593 start += _session->timecode_offset ();
2595 start -= _session->timecode_offset ();
2597 if (((direction == 0) && (start % one_timecode_minute > one_timecode_minute / 2)) || direction > 0) {
2598 start = (nframes64_t) ceil ((double) start / one_timecode_minute) * one_timecode_minute;
2600 start = (nframes64_t) floor ((double) start / one_timecode_minute) * one_timecode_minute;
2602 if (_session->timecode_offset_negative())
2604 start -= _session->timecode_offset ();
2606 start += _session->timecode_offset ();
2610 fatal << "Editor::smpte_snap_to_internal() called with non-timecode snap type!" << endmsg;
2616 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2618 const nframes64_t one_second = _session->frame_rate();
2619 const nframes64_t one_minute = _session->frame_rate() * 60;
2620 nframes64_t presnap = start;
2624 switch (_snap_type) {
2625 case SnapToTimecodeFrame:
2626 case SnapToTimecodeSeconds:
2627 case SnapToTimecodeMinutes:
2628 return timecode_snap_to_internal (start, direction, for_mark);
2631 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2632 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2634 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2639 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2640 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2642 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2647 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2648 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2650 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2655 start = _session->tempo_map().round_to_bar (start, direction);
2659 start = _session->tempo_map().round_to_beat (start, direction);
2662 case SnapToBeatDiv28:
2663 start = _session->tempo_map().round_to_beat_subdivision (start, 28, direction);
2666 case SnapToBeatDiv24:
2667 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2669 case SnapToBeatDiv14:
2670 start = _session->tempo_map().round_to_beat_subdivision (start, 14, direction);
2672 case SnapToBeatDiv12:
2673 start = _session->tempo_map().round_to_beat_subdivision (start, 12, direction);
2675 case SnapToBeatDiv10:
2676 start = _session->tempo_map().round_to_beat_subdivision (start, 10, direction);
2678 case SnapToBeatDiv7:
2679 start = _session->tempo_map().round_to_beat_subdivision (start, 7, direction);
2681 case SnapToBeatDiv6:
2682 start = _session->tempo_map().round_to_beat_subdivision (start, 6, direction);
2684 case SnapToBeatDiv5:
2685 start = _session->tempo_map().round_to_beat_subdivision (start, 5, direction);
2687 case SnapToBeatDiv32:
2688 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2690 case SnapToBeatDiv16:
2691 start = _session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2693 case SnapToBeatDiv8:
2694 start = _session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2696 case SnapToBeatDiv4:
2697 start = _session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2699 case SnapToBeatDiv3:
2700 start = _session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2708 _session->locations()->marks_either_side (start, before, after);
2710 if (before == max_frames) {
2712 } else if (after == max_frames) {
2714 } else if (before != max_frames && after != max_frames) {
2715 /* have before and after */
2716 if ((start - before) < (after - start)) {
2725 case SnapToRegionStart:
2726 case SnapToRegionEnd:
2727 case SnapToRegionSync:
2728 case SnapToRegionBoundary:
2729 if (!region_boundary_cache.empty()) {
2731 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2732 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2734 if (direction > 0) {
2735 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2737 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2740 if (next != region_boundary_cache.begin ()) {
2745 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2746 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2748 if (start > (p + n) / 2) {
2757 switch (_snap_mode) {
2763 if (presnap > start) {
2764 if (presnap > (start + unit_to_frame(snap_threshold))) {
2768 } else if (presnap < start) {
2769 if (presnap < (start - unit_to_frame(snap_threshold))) {
2775 /* handled at entry */
2783 Editor::setup_toolbar ()
2787 /* Mode Buttons (tool selection) */
2789 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2790 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2791 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2792 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2793 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2794 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2795 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2796 join_object_range_button.set_relief(Gtk::RELIEF_NONE);
2798 HBox* mode_box = manage(new HBox);
2799 mode_box->set_border_width (2);
2800 mode_box->set_spacing(4);
2802 /* table containing mode buttons */
2804 HBox* mouse_mode_button_box = manage (new HBox ());
2806 if (Profile->get_sae()) {
2807 mouse_mode_button_box->pack_start (mouse_move_button);
2809 mouse_mode_button_box->pack_start (mouse_move_button);
2810 mouse_mode_button_box->pack_start (join_object_range_button);
2811 mouse_mode_button_box->pack_start (mouse_select_button);
2814 mouse_mode_button_box->pack_start (mouse_zoom_button);
2816 if (!Profile->get_sae()) {
2817 mouse_mode_button_box->pack_start (mouse_gain_button);
2820 mouse_mode_button_box->pack_start (mouse_timefx_button);
2821 mouse_mode_button_box->pack_start (mouse_audition_button);
2822 mouse_mode_button_box->pack_start (internal_edit_button);
2824 vector<string> edit_mode_strings;
2825 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2826 if (!Profile->get_sae()) {
2827 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2829 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2831 edit_mode_selector.set_name ("EditModeSelector");
2832 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2833 edit_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_mode_selection_done));
2835 mode_box->pack_start (edit_mode_selector);
2836 mode_box->pack_start (*mouse_mode_button_box);
2838 _mouse_mode_tearoff = manage (new TearOff (*mode_box));
2839 _mouse_mode_tearoff->set_name ("MouseModeBase");
2840 _mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_mouse_mode_tearoff->tearoff_window()), false);
2842 if (Profile->get_sae()) {
2843 _mouse_mode_tearoff->set_can_be_torn_off (false);
2846 _mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2847 &_mouse_mode_tearoff->tearoff_window()));
2848 _mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2849 &_mouse_mode_tearoff->tearoff_window(), 1));
2850 _mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2851 &_mouse_mode_tearoff->tearoff_window()));
2852 _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2853 &_mouse_mode_tearoff->tearoff_window(), 1));
2855 mouse_move_button.set_mode (false);
2856 mouse_select_button.set_mode (false);
2857 mouse_gain_button.set_mode (false);
2858 mouse_zoom_button.set_mode (false);
2859 mouse_timefx_button.set_mode (false);
2860 mouse_audition_button.set_mode (false);
2861 join_object_range_button.set_mode (false);
2863 mouse_move_button.set_name ("MouseModeButton");
2864 mouse_select_button.set_name ("MouseModeButton");
2865 mouse_gain_button.set_name ("MouseModeButton");
2866 mouse_zoom_button.set_name ("MouseModeButton");
2867 mouse_timefx_button.set_name ("MouseModeButton");
2868 mouse_audition_button.set_name ("MouseModeButton");
2869 internal_edit_button.set_name ("MouseModeButton");
2870 join_object_range_button.set_name ("MouseModeButton");
2872 mouse_move_button.unset_flags (CAN_FOCUS);
2873 mouse_select_button.unset_flags (CAN_FOCUS);
2874 mouse_gain_button.unset_flags (CAN_FOCUS);
2875 mouse_zoom_button.unset_flags (CAN_FOCUS);
2876 mouse_timefx_button.unset_flags (CAN_FOCUS);
2877 mouse_audition_button.unset_flags (CAN_FOCUS);
2878 internal_edit_button.unset_flags (CAN_FOCUS);
2879 join_object_range_button.unset_flags (CAN_FOCUS);
2883 zoom_box.set_spacing (1);
2884 zoom_box.set_border_width (0);
2886 zoom_in_button.set_name ("EditorTimeButton");
2887 zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_MENU))));
2888 zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
2890 zoom_out_button.set_name ("EditorTimeButton");
2891 zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_MENU))));
2892 zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
2894 zoom_out_full_button.set_name ("EditorTimeButton");
2895 zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_MENU))));
2896 zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
2898 zoom_focus_selector.set_name ("ZoomFocusSelector");
2899 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2900 zoom_focus_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done));
2902 zoom_box.pack_start (zoom_out_button, false, false);
2903 zoom_box.pack_start (zoom_in_button, false, false);
2904 zoom_box.pack_start (zoom_out_full_button, false, false);
2906 /* Track zoom buttons */
2907 tav_expand_button.set_name ("TrackHeightButton");
2908 tav_expand_button.set_size_request(-1,20);
2909 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2910 tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
2912 tav_shrink_button.set_name ("TrackHeightButton");
2913 tav_shrink_button.set_size_request(-1,20);
2914 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2915 tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
2917 track_zoom_box.set_spacing (1);
2918 track_zoom_box.set_border_width (0);
2920 track_zoom_box.pack_start (tav_shrink_button, false, false);
2921 track_zoom_box.pack_start (tav_expand_button, false, false);
2923 HBox* zbc = manage (new HBox);
2924 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2925 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2926 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2927 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2929 snap_box.set_spacing (1);
2930 snap_box.set_border_width (2);
2932 snap_type_selector.set_name ("SnapTypeSelector");
2933 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2934 snap_type_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_type_selection_done));
2936 snap_mode_selector.set_name ("SnapModeSelector");
2937 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2938 snap_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_mode_selection_done));
2940 edit_point_selector.set_name ("EditPointSelector");
2941 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2942 edit_point_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_point_selection_done));
2944 snap_box.pack_start (snap_mode_selector, false, false);
2945 snap_box.pack_start (snap_type_selector, false, false);
2946 snap_box.pack_start (edit_point_selector, false, false);
2950 HBox *nudge_box = manage (new HBox);
2951 nudge_box->set_spacing(1);
2952 nudge_box->set_border_width (2);
2954 nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
2955 nudge_backward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_backward_release), false);
2957 nudge_box->pack_start (nudge_backward_button, false, false);
2958 nudge_box->pack_start (nudge_forward_button, false, false);
2959 nudge_box->pack_start (nudge_clock, false, false);
2962 /* Pack everything in... */
2964 HBox* hbox = manage (new HBox);
2965 hbox->set_spacing(10);
2967 _tools_tearoff = manage (new TearOff (*hbox));
2968 _tools_tearoff->set_name ("MouseModeBase");
2969 _tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_tools_tearoff->tearoff_window()), false);
2971 if (Profile->get_sae()) {
2972 _tools_tearoff->set_can_be_torn_off (false);
2975 _tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2976 &_tools_tearoff->tearoff_window()));
2977 _tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2978 &_tools_tearoff->tearoff_window(), 0));
2979 _tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2980 &_tools_tearoff->tearoff_window()));
2981 _tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2982 &_tools_tearoff->tearoff_window(), 0));
2984 toolbar_hbox.set_spacing (10);
2985 toolbar_hbox.set_border_width (1);
2987 toolbar_hbox.pack_start (*_mouse_mode_tearoff, false, false);
2988 toolbar_hbox.pack_start (*_tools_tearoff, false, false);
2990 hbox->pack_start (snap_box, false, false);
2991 hbox->pack_start (*nudge_box, false, false);
2992 hbox->pack_start (panic_box, false, false);
2996 toolbar_base.set_name ("ToolBarBase");
2997 toolbar_base.add (toolbar_hbox);
2999 toolbar_frame.set_shadow_type (SHADOW_OUT);
3000 toolbar_frame.set_name ("BaseFrame");
3001 toolbar_frame.add (toolbar_base);
3005 Editor::setup_tooltips ()
3007 ARDOUR_UI::instance()->set_tip (mouse_move_button, _("Select/Move Objects"));
3008 ARDOUR_UI::instance()->set_tip (mouse_gain_button, _("Draw Gain Automation"));
3009 ARDOUR_UI::instance()->set_tip (mouse_zoom_button, _("Select Zoom Range"));
3010 ARDOUR_UI::instance()->set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
3011 ARDOUR_UI::instance()->set_tip (mouse_audition_button, _("Listen to Specific Regions"));
3012 ARDOUR_UI::instance()->set_tip (join_object_range_button, _("Select/Move Objects or Ranges"));
3013 ARDOUR_UI::instance()->set_tip (internal_edit_button, _("Edit Region Contents (e.g. notes)"));
3014 ARDOUR_UI::instance()->set_tip (*_group_tabs, _("Groups: context-click for possible operations"));
3015 ARDOUR_UI::instance()->set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
3016 ARDOUR_UI::instance()->set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
3017 ARDOUR_UI::instance()->set_tip (zoom_in_button, _("Zoom In"));
3018 ARDOUR_UI::instance()->set_tip (zoom_out_button, _("Zoom Out"));
3019 ARDOUR_UI::instance()->set_tip (zoom_out_full_button, _("Zoom to Session"));
3020 ARDOUR_UI::instance()->set_tip (zoom_focus_selector, _("Zoom focus"));
3021 ARDOUR_UI::instance()->set_tip (tav_expand_button, _("Expand Tracks"));
3022 ARDOUR_UI::instance()->set_tip (tav_shrink_button, _("Shrink Tracks"));
3023 ARDOUR_UI::instance()->set_tip (snap_type_selector, _("Snap/Grid Units"));
3024 ARDOUR_UI::instance()->set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3025 ARDOUR_UI::instance()->set_tip (edit_point_selector, _("Edit point"));
3026 ARDOUR_UI::instance()->set_tip (midi_sound_notes, _("Sound Notes"));
3027 ARDOUR_UI::instance()->set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
3031 Editor::midi_panic ()
3033 cerr << "MIDI panic\n";
3036 _session->midi_panic();
3041 Editor::setup_midi_toolbar ()
3045 /* Midi sound notes */
3046 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3047 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3048 midi_sound_notes.unset_flags (CAN_FOCUS);
3052 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
3053 midi_panic_button.set_name("MidiPanicButton");
3054 act->connect_proxy (midi_panic_button);
3056 panic_box.pack_start (midi_sound_notes , true, true);
3057 panic_box.pack_start (midi_panic_button, true, true);
3061 Editor::convert_drop_to_paths (
3062 vector<ustring>& paths,
3063 const RefPtr<Gdk::DragContext>& /*context*/,
3066 const SelectionData& data,
3070 if (_session == 0) {
3074 vector<ustring> uris = data.get_uris();
3078 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3079 are actually URI lists. So do it by hand.
3082 if (data.get_target() != "text/plain") {
3086 /* Parse the "uri-list" format that Nautilus provides,
3087 where each pathname is delimited by \r\n.
3089 THERE MAY BE NO NULL TERMINATING CHAR!!!
3092 ustring txt = data.get_text();
3096 p = (const char *) malloc (txt.length() + 1);
3097 txt.copy ((char *) p, txt.length(), 0);
3098 ((char*)p)[txt.length()] = '\0';
3104 while (g_ascii_isspace (*p))
3108 while (*q && (*q != '\n') && (*q != '\r')) {
3115 while (q > p && g_ascii_isspace (*q))
3120 uris.push_back (ustring (p, q - p + 1));
3124 p = strchr (p, '\n');
3136 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3138 if ((*i).substr (0,7) == "file://") {
3141 PBD::url_decode (p);
3143 // scan forward past three slashes
3145 ustring::size_type slashcnt = 0;
3146 ustring::size_type n = 0;
3147 ustring::iterator x = p.begin();
3149 while (slashcnt < 3 && x != p.end()) {
3152 } else if (slashcnt == 3) {
3159 if (slashcnt != 3 || x == p.end()) {
3160 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3164 paths.push_back (p.substr (n - 1));
3172 Editor::new_tempo_section ()
3178 Editor::map_transport_state ()
3180 ENSURE_GUI_THREAD (*this, &Editor::map_transport_state)
3182 if (_session && _session->transport_stopped()) {
3183 have_pending_keyboard_selection = false;
3186 update_loop_range_view (true);
3191 Editor::State::State (PublicEditor const * e)
3193 selection = new Selection (e);
3196 Editor::State::~State ()
3202 Editor::begin_reversible_command (string name)
3205 _session->begin_reversible_command (name);
3210 Editor::commit_reversible_command ()
3213 _session->commit_reversible_command ();
3218 Editor::set_route_group_solo (Route& route, bool yn)
3220 RouteGroup *route_group;
3222 if ((route_group = route.route_group()) != 0) {
3223 route_group->apply (&Route::set_solo, yn, this);
3225 route.set_solo (yn, this);
3230 Editor::set_route_group_mute (Route& route, bool yn)
3232 RouteGroup *route_group = 0;
3234 if ((route_group = route.route_group()) != 0) {
3235 route_group->apply (&Route::set_mute, yn, this);
3237 route.set_mute (yn, this);
3242 Editor::history_changed ()
3246 if (undo_action && _session) {
3247 if (_session->undo_depth() == 0) {
3250 label = string_compose(_("Undo (%1)"), _session->next_undo());
3252 undo_action->property_label() = label;
3255 if (redo_action && _session) {
3256 if (_session->redo_depth() == 0) {
3259 label = string_compose(_("Redo (%1)"), _session->next_redo());
3261 redo_action->property_label() = label;
3266 Editor::duplicate_dialog (bool with_dialog)
3270 if (mouse_mode == MouseRange) {
3271 if (selection->time.length() == 0) {
3277 get_regions_for_action (rs);
3279 if (mouse_mode != MouseRange) {
3288 ArdourDialog win (_("Duplicate"));
3289 Label label (_("Number of duplications:"));
3290 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3291 SpinButton spinner (adjustment, 0.0, 1);
3294 win.get_vbox()->set_spacing (12);
3295 win.get_vbox()->pack_start (hbox);
3296 hbox.set_border_width (6);
3297 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3299 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3300 place, visually. so do this by hand.
3303 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3304 spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3305 spinner.grab_focus();
3311 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3312 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3313 win.set_default_response (RESPONSE_ACCEPT);
3315 win.set_position (WIN_POS_MOUSE);
3317 spinner.grab_focus ();
3319 switch (win.run ()) {
3320 case RESPONSE_ACCEPT:
3326 times = adjustment.get_value();
3329 if (mouse_mode == MouseRange) {
3330 duplicate_selection (times);
3332 duplicate_some_regions (rs, times);
3337 Editor::show_verbose_canvas_cursor ()
3339 verbose_canvas_cursor->raise_to_top();
3340 verbose_canvas_cursor->show();
3341 verbose_cursor_visible = true;
3345 Editor::hide_verbose_canvas_cursor ()
3347 verbose_canvas_cursor->hide();
3348 verbose_cursor_visible = false;
3352 Editor::clamp_verbose_cursor_x (double x)
3357 x = min (_canvas_width - 200.0, x);
3363 Editor::clamp_verbose_cursor_y (double y)
3365 if (y < canvas_timebars_vsize) {
3366 y = canvas_timebars_vsize;
3368 y = min (_canvas_height - 50, y);
3374 Editor::show_verbose_canvas_cursor_with (const string & txt)
3376 verbose_canvas_cursor->property_text() = txt.c_str();
3381 track_canvas->get_pointer (x, y);
3382 track_canvas->window_to_world (x, y, wx, wy);
3384 /* don't get too close to the edge */
3385 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3386 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3388 show_verbose_canvas_cursor ();
3392 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3394 verbose_canvas_cursor->property_text() = txt.c_str();
3395 /* don't get too close to the edge */
3396 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3397 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3401 Editor::set_verbose_canvas_cursor_text (const string & txt)
3403 verbose_canvas_cursor->property_text() = txt.c_str();
3407 Editor::set_edit_mode (EditMode m)
3409 Config->set_edit_mode (m);
3413 Editor::cycle_edit_mode ()
3415 switch (Config->get_edit_mode()) {
3417 if (Profile->get_sae()) {
3418 Config->set_edit_mode (Lock);
3420 Config->set_edit_mode (Splice);
3424 Config->set_edit_mode (Lock);
3427 Config->set_edit_mode (Slide);
3433 Editor::edit_mode_selection_done ()
3435 if (_session == 0) {
3439 string choice = edit_mode_selector.get_active_text();
3440 EditMode mode = Slide;
3442 if (choice == _("Splice Edit")) {
3444 } else if (choice == _("Slide Edit")) {
3446 } else if (choice == _("Lock Edit")) {
3450 Config->set_edit_mode (mode);
3454 Editor::snap_type_selection_done ()
3456 string choice = snap_type_selector.get_active_text();
3457 SnapType snaptype = SnapToBeat;
3459 if (choice == _("Beats/3")) {
3460 snaptype = SnapToBeatDiv3;
3461 } else if (choice == _("Beats/4")) {
3462 snaptype = SnapToBeatDiv4;
3463 } else if (choice == _("Beats/8")) {
3464 snaptype = SnapToBeatDiv8;
3465 } else if (choice == _("Beats/16")) {
3466 snaptype = SnapToBeatDiv16;
3467 } else if (choice == _("Beats/32")) {
3468 snaptype = SnapToBeatDiv32;
3469 } else if (choice == _("Beats/5")) {
3470 snaptype = SnapToBeatDiv5;
3471 } else if (choice == _("Beats/6")) {
3472 snaptype = SnapToBeatDiv6;
3473 } else if (choice == _("Beats/7")) {
3474 snaptype = SnapToBeatDiv7;
3475 } else if (choice == _("Beats/10")) {
3476 snaptype = SnapToBeatDiv10;
3477 } else if (choice == _("Beats/12")) {
3478 snaptype = SnapToBeatDiv12;
3479 } else if (choice == _("Beats/14")) {
3480 snaptype = SnapToBeatDiv14;
3481 } else if (choice == _("Beats/24")) {
3482 snaptype = SnapToBeatDiv24;
3483 } else if (choice == _("Beats/28")) {
3484 snaptype = SnapToBeatDiv28;
3485 } else if (choice == _("Beats")) {
3486 snaptype = SnapToBeat;
3487 } else if (choice == _("Bars")) {
3488 snaptype = SnapToBar;
3489 } else if (choice == _("Marks")) {
3490 snaptype = SnapToMark;
3491 } else if (choice == _("Region starts")) {
3492 snaptype = SnapToRegionStart;
3493 } else if (choice == _("Region ends")) {
3494 snaptype = SnapToRegionEnd;
3495 } else if (choice == _("Region bounds")) {
3496 snaptype = SnapToRegionBoundary;
3497 } else if (choice == _("Region syncs")) {
3498 snaptype = SnapToRegionSync;
3499 } else if (choice == _("CD Frames")) {
3500 snaptype = SnapToCDFrame;
3501 } else if (choice == _("Timecode Frames")) {
3502 snaptype = SnapToTimecodeFrame;
3503 } else if (choice == _("Timecode Seconds")) {
3504 snaptype = SnapToTimecodeSeconds;
3505 } else if (choice == _("Timecode Minutes")) {
3506 snaptype = SnapToTimecodeMinutes;
3507 } else if (choice == _("Seconds")) {
3508 snaptype = SnapToSeconds;
3509 } else if (choice == _("Minutes")) {
3510 snaptype = SnapToMinutes;
3513 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3515 ract->set_active ();
3520 Editor::snap_mode_selection_done ()
3522 string choice = snap_mode_selector.get_active_text();
3523 SnapMode mode = SnapNormal;
3525 if (choice == _("No Grid")) {
3527 } else if (choice == _("Grid")) {
3529 } else if (choice == _("Magnetic")) {
3530 mode = SnapMagnetic;
3533 RefPtr<RadioAction> ract = snap_mode_action (mode);
3536 ract->set_active (true);
3541 Editor::cycle_edit_point (bool with_marker)
3543 switch (_edit_point) {
3545 set_edit_point_preference (EditAtPlayhead);
3547 case EditAtPlayhead:
3549 set_edit_point_preference (EditAtSelectedMarker);
3551 set_edit_point_preference (EditAtMouse);
3554 case EditAtSelectedMarker:
3555 set_edit_point_preference (EditAtMouse);
3561 Editor::edit_point_selection_done ()
3563 string choice = edit_point_selector.get_active_text();
3564 EditPoint ep = EditAtSelectedMarker;
3566 if (choice == _("Marker")) {
3567 set_edit_point_preference (EditAtSelectedMarker);
3568 } else if (choice == _("Playhead")) {
3569 set_edit_point_preference (EditAtPlayhead);
3571 set_edit_point_preference (EditAtMouse);
3574 RefPtr<RadioAction> ract = edit_point_action (ep);
3577 ract->set_active (true);
3582 Editor::zoom_focus_selection_done ()
3584 string choice = zoom_focus_selector.get_active_text();
3585 ZoomFocus focus_type = ZoomFocusLeft;
3587 if (choice == _("Left")) {
3588 focus_type = ZoomFocusLeft;
3589 } else if (choice == _("Right")) {
3590 focus_type = ZoomFocusRight;
3591 } else if (choice == _("Center")) {
3592 focus_type = ZoomFocusCenter;
3593 } else if (choice == _("Playhead")) {
3594 focus_type = ZoomFocusPlayhead;
3595 } else if (choice == _("Mouse")) {
3596 focus_type = ZoomFocusMouse;
3597 } else if (choice == _("Edit point")) {
3598 focus_type = ZoomFocusEdit;
3601 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3604 ract->set_active ();
3609 Editor::edit_controls_button_release (GdkEventButton* ev)
3611 if (Keyboard::is_context_menu_event (ev)) {
3612 ARDOUR_UI::instance()->add_route (this);
3618 Editor::mouse_select_button_release (GdkEventButton* ev)
3620 /* this handles just right-clicks */
3622 if (ev->button != 3) {
3630 Editor::set_zoom_focus (ZoomFocus f)
3632 string str = zoom_focus_strings[(int)f];
3634 if (str != zoom_focus_selector.get_active_text()) {
3635 zoom_focus_selector.set_active_text (str);
3638 if (zoom_focus != f) {
3641 ZoomFocusChanged (); /* EMIT_SIGNAL */
3648 Editor::ensure_float (Window& win)
3650 win.set_transient_for (*this);
3654 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3656 /* recover or initialize pane positions. do this here rather than earlier because
3657 we don't want the positions to change the child allocations, which they seem to do.
3663 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3665 static int32_t done;
3668 width = default_width;
3669 height = default_height;
3671 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3673 if ((prop = geometry->property ("x_size")) == 0) {
3674 prop = geometry->property ("x-size");
3677 width = atoi (prop->value());
3679 if ((prop = geometry->property ("y_size")) == 0) {
3680 prop = geometry->property ("y-size");
3683 height = atoi (prop->value());
3687 if (which == static_cast<Paned*> (&edit_pane)) {
3693 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3694 /* initial allocation is 90% to canvas, 10% to notebook */
3695 pos = (int) floor (alloc.get_width() * 0.90f);
3696 snprintf (buf, sizeof(buf), "%d", pos);
3698 pos = atoi (prop->value());
3701 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3702 edit_pane.set_position (pos);
3703 pre_maximal_pane_position = pos;
3709 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3711 if (_tools_tearoff->torn_off() && _mouse_mode_tearoff->torn_off()) {
3712 top_hbox.remove (toolbar_frame);
3717 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3719 if (toolbar_frame.get_parent() == 0) {
3720 top_hbox.pack_end (toolbar_frame);
3725 Editor::set_show_measures (bool yn)
3727 if (_show_measures != yn) {
3730 if ((_show_measures = yn) == true) {
3732 tempo_lines->show();
3740 Editor::toggle_follow_playhead ()
3742 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3744 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3745 set_follow_playhead (tact->get_active());
3750 Editor::set_follow_playhead (bool yn)
3752 if (_follow_playhead != yn) {
3753 if ((_follow_playhead = yn) == true) {
3755 reset_x_origin_to_follow_playhead ();
3762 Editor::toggle_stationary_playhead ()
3764 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
3766 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3767 set_stationary_playhead (tact->get_active());
3772 Editor::set_stationary_playhead (bool yn)
3774 if (_stationary_playhead != yn) {
3775 if ((_stationary_playhead = yn) == true) {
3777 // FIXME need a 3.0 equivalent of this 2.X call
3778 // update_current_screen ();
3785 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3787 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3789 xfade->set_active (!xfade->active());
3794 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3796 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3798 xfade->set_follow_overlap (!xfade->following_overlap());
3803 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3805 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3811 CrossfadeEditor cew (_session, xfade, xfade->fade_in().get_min_y(), 1.0);
3815 switch (cew.run ()) {
3816 case RESPONSE_ACCEPT:
3823 PropertyChange all_crossfade_properties;
3824 all_crossfade_properties.add (ARDOUR::Properties::active);
3825 all_crossfade_properties.add (ARDOUR::Properties::follow_overlap);
3826 xfade->PropertyChanged (all_crossfade_properties);
3830 Editor::playlist_selector () const
3832 return *_playlist_selector;
3836 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3840 switch (_snap_type) {
3845 case SnapToBeatDiv28:
3848 case SnapToBeatDiv24:
3851 case SnapToBeatDiv14:
3854 case SnapToBeatDiv12:
3857 case SnapToBeatDiv10:
3860 case SnapToBeatDiv7:
3863 case SnapToBeatDiv6:
3866 case SnapToBeatDiv5:
3870 case SnapToBeatDiv32:
3874 case SnapToBeatDiv16:
3878 case SnapToBeatDiv8:
3882 case SnapToBeatDiv4:
3886 case SnapToBeatDiv3:
3892 return _session->tempo_map().meter_at (position).beats_per_bar();
3897 case SnapToTimecodeFrame:
3898 case SnapToTimecodeSeconds:
3899 case SnapToTimecodeMinutes:
3902 case SnapToRegionStart:
3903 case SnapToRegionEnd:
3904 case SnapToRegionSync:
3905 case SnapToRegionBoundary:
3915 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3919 ret = nudge_clock.current_duration (pos);
3920 next = ret + 1; /* XXXX fix me */
3926 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3928 ArdourDialog dialog (_("Playlist Deletion"));
3929 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3930 "If left alone, no audio files used by it will be cleaned.\n"
3931 "If deleted, audio files used by it alone by will cleaned."),
3934 dialog.set_position (WIN_POS_CENTER);
3935 dialog.get_vbox()->pack_start (label);
3939 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3940 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3941 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3943 switch (dialog.run ()) {
3944 case RESPONSE_ACCEPT:
3945 /* delete the playlist */
3949 case RESPONSE_REJECT:
3950 /* keep the playlist */
3962 Editor::audio_region_selection_covers (nframes64_t where)
3964 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3965 if ((*a)->region()->covers (where)) {
3974 Editor::prepare_for_cleanup ()
3976 cut_buffer->clear_regions ();
3977 cut_buffer->clear_playlists ();
3979 selection->clear_regions ();
3980 selection->clear_playlists ();
3982 _regions->suspend_redisplay ();
3986 Editor::finish_cleanup ()
3988 _regions->resume_redisplay ();
3992 Editor::transport_loop_location()
3995 return _session->locations()->auto_loop_location();
4002 Editor::transport_punch_location()
4005 return _session->locations()->auto_punch_location();
4012 Editor::control_layout_scroll (GdkEventScroll* ev)
4014 if (Keyboard::some_magic_widget_has_focus()) {
4018 switch (ev->direction) {
4020 scroll_tracks_up_line ();
4024 case GDK_SCROLL_DOWN:
4025 scroll_tracks_down_line ();
4029 /* no left/right handling yet */
4037 Editor::session_state_saved (string snap_name)
4039 ENSURE_GUI_THREAD (*this, &Editor::session_state_saved, snap_name);
4042 _snapshots->redisplay ();
4046 Editor::maximise_editing_space ()
4048 _mouse_mode_tearoff->set_visible (false);
4049 _tools_tearoff->set_visible (false);
4051 pre_maximal_pane_position = edit_pane.get_position();
4052 pre_maximal_editor_width = this->get_width();
4054 if(post_maximal_pane_position == 0) {
4055 post_maximal_pane_position = edit_pane.get_width();
4060 if(post_maximal_editor_width) {
4061 edit_pane.set_position (post_maximal_pane_position -
4062 abs(post_maximal_editor_width - pre_maximal_editor_width));
4064 edit_pane.set_position (post_maximal_pane_position);
4069 Editor::restore_editing_space ()
4071 // user changed width of pane during fullscreen
4073 if(post_maximal_pane_position != edit_pane.get_position()) {
4074 post_maximal_pane_position = edit_pane.get_position();
4079 _mouse_mode_tearoff->set_visible (true);
4080 _tools_tearoff->set_visible (true);
4081 post_maximal_editor_width = this->get_width();
4083 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4087 * Make new playlists for a given track and also any others that belong
4088 * to the same active route group with the `edit' property.
4093 Editor::new_playlists (TimeAxisView* v)
4095 begin_reversible_command (_("new playlists"));
4096 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4097 _session->playlists->get (playlists);
4098 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4099 commit_reversible_command ();
4103 * Use a copy of the current playlist for a given track and also any others that belong
4104 * to the same active route group with the `edit' property.
4109 Editor::copy_playlists (TimeAxisView* v)
4111 begin_reversible_command (_("copy playlists"));
4112 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4113 _session->playlists->get (playlists);
4114 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4115 commit_reversible_command ();
4118 /** Clear the current playlist for a given track and also any others that belong
4119 * to the same active route group with the `edit' property.
4124 Editor::clear_playlists (TimeAxisView* v)
4126 begin_reversible_command (_("clear playlists"));
4127 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4128 _session->playlists->get (playlists);
4129 mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, ARDOUR::Properties::edit.property_id);
4130 commit_reversible_command ();
4134 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4136 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4140 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4142 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4146 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4148 atv.clear_playlist ();
4152 Editor::on_key_press_event (GdkEventKey* ev)
4154 return key_press_focus_accelerator_handler (*this, ev);
4158 Editor::on_key_release_event (GdkEventKey* ev)
4160 return Gtk::Window::on_key_release_event (ev);
4161 // return key_press_focus_accelerator_handler (*this, ev);
4164 /** Queue up a change to the viewport x origin.
4165 * @param frame New x origin.
4168 Editor::reset_x_origin (nframes64_t frame)
4170 queue_visual_change (frame);
4174 Editor::reset_y_origin (double y)
4176 queue_visual_change_y (y);
4180 Editor::reset_zoom (double fpu)
4182 queue_visual_change (fpu);
4186 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4188 reset_x_origin (frame);
4191 if (!no_save_visual) {
4192 undo_visual_stack.push_back (current_visual_state(false));
4196 Editor::VisualState*
4197 Editor::current_visual_state (bool with_tracks)
4199 VisualState* vs = new VisualState;
4200 vs->y_position = vertical_adjustment.get_value();
4201 vs->frames_per_unit = frames_per_unit;
4202 vs->leftmost_frame = leftmost_frame;
4203 vs->zoom_focus = zoom_focus;
4206 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4207 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4215 Editor::undo_visual_state ()
4217 if (undo_visual_stack.empty()) {
4221 redo_visual_stack.push_back (current_visual_state());
4223 VisualState* vs = undo_visual_stack.back();
4224 undo_visual_stack.pop_back();
4225 use_visual_state (*vs);
4229 Editor::redo_visual_state ()
4231 if (redo_visual_stack.empty()) {
4235 undo_visual_stack.push_back (current_visual_state());
4237 VisualState* vs = redo_visual_stack.back();
4238 redo_visual_stack.pop_back();
4239 use_visual_state (*vs);
4243 Editor::swap_visual_state ()
4245 if (undo_visual_stack.empty()) {
4246 redo_visual_state ();
4248 undo_visual_state ();
4253 Editor::use_visual_state (VisualState& vs)
4255 no_save_visual = true;
4257 _routes->suspend_redisplay ();
4259 vertical_adjustment.set_value (vs.y_position);
4261 set_zoom_focus (vs.zoom_focus);
4262 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4264 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4265 TrackViewList::iterator t;
4267 /* check if the track still exists - it could have been deleted */
4269 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4270 (*t)->set_state (*(i->second), Stateful::loading_state_version);
4275 if (!vs.track_states.empty()) {
4276 _routes->update_visibility ();
4279 _routes->resume_redisplay ();
4281 no_save_visual = false;
4285 Editor::set_frames_per_unit (double fpu)
4287 /* this is the core function that controls the zoom level of the canvas. it is called
4288 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4291 if (fpu == frames_per_unit) {
4300 /* don't allow zooms that fit more than the maximum number
4301 of frames into an 800 pixel wide space.
4304 if (max_frames / fpu < 800.0) {
4309 tempo_lines->tempo_map_changed();
4311 frames_per_unit = fpu;
4316 Editor::post_zoom ()
4318 // convert fpu to frame count
4320 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4322 if (frames_per_unit != zoom_range_clock.current_duration()) {
4323 zoom_range_clock.set (frames);
4326 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4327 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4328 (*i)->reshow_selection (selection->time);
4332 ZoomChanged (); /* EMIT_SIGNAL */
4334 //reset_scrolling_region ();
4336 if (playhead_cursor) {
4337 playhead_cursor->set_position (playhead_cursor->current_frame);
4340 refresh_location_display();
4341 _summary->set_overlays_dirty ();
4347 Editor::queue_visual_change (nframes64_t where)
4349 pending_visual_change.add (VisualChange::TimeOrigin);
4350 pending_visual_change.time_origin = where;
4351 ensure_visual_change_idle_handler ();
4355 Editor::queue_visual_change (double fpu)
4357 pending_visual_change.add (VisualChange::ZoomLevel);
4358 pending_visual_change.frames_per_unit = fpu;
4360 ensure_visual_change_idle_handler ();
4364 Editor::queue_visual_change_y (double y)
4366 pending_visual_change.add (VisualChange::YOrigin);
4367 pending_visual_change.y_origin = y;
4369 ensure_visual_change_idle_handler ();
4373 Editor::ensure_visual_change_idle_handler ()
4375 if (pending_visual_change.idle_handler_id < 0) {
4376 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4381 Editor::_idle_visual_changer (void* arg)
4383 return static_cast<Editor*>(arg)->idle_visual_changer ();
4387 Editor::idle_visual_changer ()
4389 VisualChange::Type p = pending_visual_change.pending;
4390 pending_visual_change.pending = (VisualChange::Type) 0;
4392 double last_time_origin = horizontal_position ();
4394 if (p & VisualChange::ZoomLevel) {
4395 set_frames_per_unit (pending_visual_change.frames_per_unit);
4397 compute_fixed_ruler_scale ();
4398 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4399 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4400 update_tempo_based_rulers ();
4402 if (p & VisualChange::TimeOrigin) {
4403 set_horizontal_position (pending_visual_change.time_origin / frames_per_unit);
4405 if (p & VisualChange::YOrigin) {
4406 vertical_adjustment.set_value (pending_visual_change.y_origin);
4409 if (last_time_origin == horizontal_position ()) {
4410 /* changed signal not emitted */
4411 update_fixed_rulers ();
4412 redisplay_tempo (true);
4415 _summary->set_overlays_dirty ();
4417 pending_visual_change.idle_handler_id = -1;
4418 return 0; /* this is always a one-shot call */
4421 struct EditorOrderTimeAxisSorter {
4422 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4423 return a->order () < b->order ();
4428 Editor::sort_track_selection (TrackViewList* sel)
4430 EditorOrderTimeAxisSorter cmp;
4435 selection->tracks.sort (cmp);
4440 Editor::get_preferred_edit_position (bool ignore_playhead)
4443 nframes64_t where = 0;
4444 EditPoint ep = _edit_point;
4446 if (entered_marker) {
4447 return entered_marker->position();
4450 if (ignore_playhead && ep == EditAtPlayhead) {
4451 ep = EditAtSelectedMarker;
4455 case EditAtPlayhead:
4456 where = _session->audible_frame();
4459 case EditAtSelectedMarker:
4460 if (!selection->markers.empty()) {
4462 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4465 where = loc->start();
4476 if (!mouse_frame (where, ignored)) {
4477 /* XXX not right but what can we do ? */
4488 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4490 if (!_session) return;
4492 begin_reversible_command (cmd);
4496 if ((tll = transport_loop_location()) == 0) {
4497 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4498 XMLNode &before = _session->locations()->get_state();
4499 _session->locations()->add (loc, true);
4500 _session->set_auto_loop_location (loc);
4501 XMLNode &after = _session->locations()->get_state();
4502 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4504 XMLNode &before = tll->get_state();
4505 tll->set_hidden (false, this);
4506 tll->set (start, end);
4507 XMLNode &after = tll->get_state();
4508 _session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4511 commit_reversible_command ();
4515 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4517 if (!_session) return;
4519 begin_reversible_command (cmd);
4523 if ((tpl = transport_punch_location()) == 0) {
4524 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4525 XMLNode &before = _session->locations()->get_state();
4526 _session->locations()->add (loc, true);
4527 _session->set_auto_loop_location (loc);
4528 XMLNode &after = _session->locations()->get_state();
4529 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4532 XMLNode &before = tpl->get_state();
4533 tpl->set_hidden (false, this);
4534 tpl->set (start, end);
4535 XMLNode &after = tpl->get_state();
4536 _session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4539 commit_reversible_command ();
4542 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4543 * @param rs List to which found regions are added.
4544 * @param where Time to look at.
4545 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4548 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4550 const TrackViewList* tracks;
4553 tracks = &track_views;
4558 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4559 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4561 boost::shared_ptr<Track> tr;
4562 boost::shared_ptr<Playlist> pl;
4564 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4566 Playlist::RegionList* regions = pl->regions_at (
4567 (nframes64_t) floor ( (double)where * tr->speed()));
4569 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4570 RegionView* rv = rtv->view()->find_view (*i);
4583 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4585 const TrackViewList* tracks;
4588 tracks = &track_views;
4593 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4594 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4596 boost::shared_ptr<Track> tr;
4597 boost::shared_ptr<Playlist> pl;
4599 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4601 Playlist::RegionList* regions = pl->regions_touched (
4602 (nframes64_t) floor ( (double)where * tr->speed()), max_frames);
4604 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4606 RegionView* rv = rtv->view()->find_view (*i);
4619 /** Find all regions which are either:
4621 * - the entered_regionview (if allow_entered == true) or
4622 * - under the preferred edit position AND on a selected track, or on a track
4623 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4624 * @param rs Returned region list.
4625 * @param allow_entered true to include the entered_regionview in the list.
4628 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4630 /* Start with selected regions */
4631 rs = selection->regions;
4633 /* Add the entered_regionview, if requested */
4634 if (allow_entered && entered_regionview) {
4635 rs.add (entered_regionview);
4638 if (allow_edit_position) {
4640 TrackViewList tracks = selection->tracks;
4642 /* tracks is currently the set of selected tracks; add any other tracks that
4643 * have regions that are in the same edit-activated route group as one of
4645 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4647 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4648 if (g && g->is_active() && g->is_edit()) {
4649 tracks.add (axis_views_from_routes (g->route_list()));
4654 if (!tracks.empty()) {
4655 /* now find regions that are at the edit position on those tracks */
4656 nframes64_t const where = get_preferred_edit_position ();
4657 get_regions_at (rs, where, tracks);
4663 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4665 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4667 RouteTimeAxisView* tatv;
4669 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4671 boost::shared_ptr<Playlist> pl;
4672 vector<boost::shared_ptr<Region> > results;
4674 boost::shared_ptr<Track> tr;
4676 if ((tr = tatv->track()) == 0) {
4681 if ((pl = (tr->playlist())) != 0) {
4682 pl->get_region_list_equivalent_regions (region, results);
4685 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4686 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4687 regions.push_back (marv);
4696 Editor::show_rhythm_ferret ()
4698 if (rhythm_ferret == 0) {
4699 rhythm_ferret = new RhythmFerret(*this);
4702 rhythm_ferret->set_session (_session);
4703 rhythm_ferret->show ();
4704 rhythm_ferret->present ();
4708 Editor::show_global_port_matrix (ARDOUR::DataType t)
4710 if (_global_port_matrix[t] == 0) {
4711 _global_port_matrix[t] = new GlobalPortMatrixWindow (_session, t);
4714 _global_port_matrix[t]->show ();
4718 Editor::first_idle ()
4720 MessageDialog* dialog = 0;
4722 if (track_views.size() > 1) {
4723 dialog = new MessageDialog (*this,
4724 string_compose (_("Please wait while %1 loads visual data"), PROGRAM_NAME),
4729 ARDOUR_UI::instance()->flush_pending ();
4732 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4736 // first idle adds route children (automation tracks), so we need to redisplay here
4737 _routes->redisplay ();
4745 Editor::_idle_resize (gpointer arg)
4747 return ((Editor*)arg)->idle_resize ();
4751 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4753 if (resize_idle_id < 0) {
4754 resize_idle_id = g_idle_add (_idle_resize, this);
4755 _pending_resize_amount = 0;
4758 /* make a note of the smallest resulting height, so that we can clamp the
4759 lower limit at TimeAxisView::hSmall */
4761 int32_t min_resulting = INT32_MAX;
4763 _pending_resize_amount += h;
4764 _pending_resize_view = view;
4766 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4768 if (selection->tracks.contains (_pending_resize_view)) {
4769 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4770 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4774 if (min_resulting < 0) {
4779 if (uint32_t (min_resulting) < TimeAxisView::preset_height (HeightSmall)) {
4780 _pending_resize_amount += TimeAxisView::preset_height (HeightSmall) - min_resulting;
4784 /** Handle pending resizing of tracks */
4786 Editor::idle_resize ()
4788 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4790 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4791 selection->tracks.contains (_pending_resize_view)) {
4793 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4794 if (*i != _pending_resize_view) {
4795 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4800 _pending_resize_amount = 0;
4802 _group_tabs->set_dirty ();
4803 resize_idle_id = -1;
4811 ENSURE_GUI_THREAD (*this, &Editor::located);
4813 playhead_cursor->set_position (_session->audible_frame ());
4814 if (_follow_playhead && !_pending_initial_locate) {
4815 reset_x_origin_to_follow_playhead ();
4818 _pending_locate_request = false;
4819 _pending_initial_locate = false;
4823 Editor::region_view_added (RegionView *)
4825 _summary->set_dirty ();
4829 Editor::streamview_height_changed ()
4831 _summary->set_dirty ();
4835 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
4837 TrackViewList::const_iterator j = track_views.begin ();
4838 while (j != track_views.end()) {
4839 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4840 if (rtv && rtv->route() == r) {
4851 Editor::axis_views_from_routes (boost::shared_ptr<RouteList> r) const
4855 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
4856 TimeAxisView* tv = axis_view_from_route (*i);
4867 Editor::handle_new_route (RouteList& routes)
4869 ENSURE_GUI_THREAD (*this, &Editor::handle_new_route, routes)
4871 RouteTimeAxisView *rtv;
4872 list<RouteTimeAxisView*> new_views;
4874 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4875 boost::shared_ptr<Route> route = (*x);
4877 if (route->is_hidden() || route->is_monitor()) {
4881 DataType dt = route->input()->default_type();
4883 if (dt == ARDOUR::DataType::AUDIO) {
4884 rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
4885 } else if (dt == ARDOUR::DataType::MIDI) {
4886 rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
4888 throw unknown_type();
4891 new_views.push_back (rtv);
4892 track_views.push_back (rtv);
4894 rtv->effective_gain_display ();
4896 rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
4897 rtv->view()->HeightChanged.connect (sigc::mem_fun (*this, &Editor::streamview_height_changed));
4900 _routes->routes_added (new_views);
4902 if (show_editor_mixer_when_tracks_arrive) {
4903 show_editor_mixer (true);
4906 editor_list_button.set_sensitive (true);
4908 _summary->set_dirty ();
4912 Editor::timeaxisview_deleted (TimeAxisView *tv)
4914 if (_session && _session->deletion_in_progress()) {
4915 /* the situation is under control */
4919 ENSURE_GUI_THREAD (*this, &Editor::timeaxisview_deleted, tv);
4922 _routes->route_removed (tv);
4924 if (tv == entered_track) {
4928 /* remove it from the list of track views */
4930 TrackViewList::iterator i;
4932 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4933 i = track_views.erase (i);
4936 /* update whatever the current mixer strip is displaying, if revelant */
4938 boost::shared_ptr<Route> route;
4939 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv);
4942 route = rtav->route ();
4945 if (current_mixer_strip && current_mixer_strip->route() == route) {
4947 TimeAxisView* next_tv;
4949 if (track_views.empty()) {
4951 } else if (i == track_views.end()) {
4952 next_tv = track_views.front();
4959 set_selected_mixer_strip (*next_tv);
4961 /* make the editor mixer strip go away setting the
4962 * button to inactive (which also unticks the menu option)
4965 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
4971 Editor::hide_track_in_display (TimeAxisView* tv, bool /*temponly*/)
4973 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
4975 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
4976 // this will hide the mixer strip
4977 set_selected_mixer_strip (*tv);
4980 _routes->hide_track_in_display (*tv);
4984 Editor::sync_track_view_list_and_routes ()
4986 track_views = TrackViewList (_routes->views ());
4988 _summary->set_dirty ();
4989 _group_tabs->set_dirty ();
4991 return false; // do not call again (until needed)
4995 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
4997 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5003 Editor::get_route_view_by_id (PBD::ID& id)
5005 RouteTimeAxisView* v;
5007 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5008 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5009 if(v->route()->id() == id) {
5019 Editor::fit_route_group (RouteGroup *g)
5021 TrackViewList ts = axis_views_from_routes (g->route_list ());
5026 Editor::consider_auditioning (boost::shared_ptr<Region> region)
5028 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
5031 _session->cancel_audition ();
5035 if (_session->is_auditioning()) {
5036 _session->cancel_audition ();
5037 if (r == last_audition_region) {
5042 _session->audition_region (r);
5043 last_audition_region = r;
5048 Editor::hide_a_region (boost::shared_ptr<Region> r)
5050 r->set_hidden (true);
5054 Editor::show_a_region (boost::shared_ptr<Region> r)
5056 r->set_hidden (false);
5060 Editor::audition_region_from_region_list ()
5062 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::consider_auditioning));
5066 Editor::hide_region_from_region_list ()
5068 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::hide_a_region));
5072 Editor::show_region_in_region_list ()
5074 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::show_a_region));
5078 Editor::start_step_editing ()
5080 step_edit_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::check_step_edit), 20);
5084 Editor::stop_step_editing ()
5086 step_edit_connection.disconnect ();
5090 Editor::check_step_edit ()
5092 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5093 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
5095 mtv->check_step_edit ();
5099 return true; // do it again, till we stop
5103 Editor::horizontal_scroll_left ()
5105 double x = leftmost_position() - current_page_frames() / 5;
5114 Editor::horizontal_scroll_right ()
5116 reset_x_origin (leftmost_position() + current_page_frames() / 5);
5119 /** Queue a change for the Editor viewport x origin to follow the playhead */
5121 Editor::reset_x_origin_to_follow_playhead ()
5123 nframes64_t const frame = playhead_cursor->current_frame;
5125 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
5127 if (_session->transport_speed() < 0) {
5129 if (frame > (current_page_frames() / 2)) {
5130 center_screen (frame-(current_page_frames()/2));
5132 center_screen (current_page_frames()/2);
5137 if (frame < leftmost_frame) {
5140 if (_session->transport_rolling()) {
5141 /* rolling; end up with the playhead at the right of the page */
5142 l = frame - current_page_frames ();
5144 /* not rolling: end up with the playhead 3/4 of the way along the page */
5145 l = frame - (3 * current_page_frames() / 4);
5152 center_screen_internal (l + (current_page_frames() / 2), current_page_frames ());
5155 if (_session->transport_rolling()) {
5156 /* rolling: end up with the playhead on the left of the page */
5157 center_screen_internal (frame + (current_page_frames() / 2), current_page_frames ());
5159 /* not rolling: end up with the playhead 1/4 of the way along the page */
5160 center_screen_internal (frame + (current_page_frames() / 4), current_page_frames ());
5168 Editor::super_rapid_screen_update ()
5170 if (!_session || !_session->engine().running()) {
5174 /* METERING / MIXER STRIPS */
5176 /* update track meters, if required */
5177 if (is_mapped() && meters_running) {
5178 RouteTimeAxisView* rtv;
5179 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5180 if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5181 rtv->fast_update ();
5186 /* and any current mixer strip */
5187 if (current_mixer_strip) {
5188 current_mixer_strip->fast_update ();
5191 /* PLAYHEAD AND VIEWPORT */
5193 nframes64_t const frame = _session->audible_frame();
5195 /* There are a few reasons why we might not update the playhead / viewport stuff:
5197 * 1. we don't update things when there's a pending locate request, otherwise
5198 * when the editor requests a locate there is a chance that this method
5199 * will move the playhead before the locate request is processed, causing
5201 * 2. if we're not rolling, there's nothing to do here (locates are handled elsewhere).
5202 * 3. if we're still at the same frame that we were last time, there's nothing to do.
5205 if (!_pending_locate_request && _session->transport_speed() != 0 && frame != last_update_frame) {
5207 last_update_frame = frame;
5209 if (!_dragging_playhead) {
5210 playhead_cursor->set_position (frame);
5213 if (!_stationary_playhead) {
5215 if (!_dragging_playhead && _follow_playhead && _session->requested_return_frame() < 0) {
5216 reset_x_origin_to_follow_playhead ();
5221 /* don't do continuous scroll till the new position is in the rightmost quarter of the
5225 // FIXME DO SOMETHING THAT WORKS HERE - this is 2.X code
5226 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
5227 if (target <= 0.0) {
5230 if (fabs(target - current) < current_page_frames() / frames_per_unit) {
5231 target = (target * 0.15) + (current * 0.85);
5237 set_horizontal_position (current);
5246 Editor::session_going_away ()
5248 _have_idled = false;
5250 _session_connections.drop_connections ();
5252 super_rapid_screen_update_connection.disconnect ();
5254 selection->clear ();
5255 cut_buffer->clear ();
5257 clicked_regionview = 0;
5258 clicked_axisview = 0;
5259 clicked_routeview = 0;
5260 clicked_crossfadeview = 0;
5261 entered_regionview = 0;
5263 last_update_frame = 0;
5266 playhead_cursor->canvas_item.hide ();
5268 /* rip everything out of the list displays */
5272 _route_groups->clear ();
5274 /* do this first so that deleting a track doesn't reset cms to null
5275 and thus cause a leak.
5278 if (current_mixer_strip) {
5279 if (current_mixer_strip->get_parent() != 0) {
5280 global_hpacker.remove (*current_mixer_strip);
5282 delete current_mixer_strip;
5283 current_mixer_strip = 0;
5286 /* delete all trackviews */
5288 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5291 track_views.clear ();
5293 zoom_range_clock.set_session (0);
5294 nudge_clock.set_session (0);
5296 editor_list_button.set_active(false);
5297 editor_list_button.set_sensitive(false);
5299 /* clear tempo/meter rulers */
5300 remove_metric_marks ();
5302 clear_marker_display ();
5304 delete current_bbt_points;
5305 current_bbt_points = 0;
5307 /* get rid of any existing editor mixer strip */
5309 WindowTitle title(Glib::get_application_name());
5310 title += _("Editor");
5312 set_title (title.get_string());
5314 SessionHandlePtr::session_going_away ();
5319 Editor::show_editor_list (bool yn)
5322 the_notebook.show();
5324 the_notebook.hide();