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"),
162 static const gchar *_snap_mode_strings[] = {
169 static const gchar *_edit_point_strings[] = {
176 static const gchar *_zoom_focus_strings[] = {
186 #ifdef USE_RUBBERBAND
187 static const gchar *_rb_opt_strings[] = {
190 N_("Balanced multitimbral mixture"),
191 N_("Unpitched percussion with stable notes"),
192 N_("Crisp monophonic instrumental"),
193 N_("Unpitched solo percussion"),
198 /* Soundfile drag-n-drop */
200 Gdk::Cursor* Editor::cross_hair_cursor = 0;
201 Gdk::Cursor* Editor::selector_cursor = 0;
202 Gdk::Cursor* Editor::trimmer_cursor = 0;
203 Gdk::Cursor* Editor::grabber_cursor = 0;
204 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
205 Gdk::Cursor* Editor::zoom_cursor = 0;
206 Gdk::Cursor* Editor::time_fx_cursor = 0;
207 Gdk::Cursor* Editor::fader_cursor = 0;
208 Gdk::Cursor* Editor::speaker_cursor = 0;
209 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
210 Gdk::Cursor* Editor::midi_select_cursor = 0;
211 Gdk::Cursor* Editor::midi_resize_cursor = 0;
212 Gdk::Cursor* Editor::midi_erase_cursor = 0;
213 Gdk::Cursor* Editor::wait_cursor = 0;
214 Gdk::Cursor* Editor::timebar_cursor = 0;
215 Gdk::Cursor* Editor::transparent_cursor = 0;
218 show_me_the_size (Requisition* r, const char* what)
220 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
225 pane_size_watcher (Paned* pane)
227 /* if the handle of a pane vanishes into (at least) the tabs of a notebook,
228 it is no longer accessible. so stop that. this doesn't happen on X11,
229 just the quartz backend.
234 int max_width_of_lhs = GTK_WIDGET(pane->gobj())->allocation.width - 25;
236 gint pos = pane->get_position ();
238 if (pos > max_width_of_lhs) {
239 pane->set_position (max_width_of_lhs);
245 : _join_object_range_state (JOIN_OBJECT_RANGE_NONE)
247 /* time display buttons */
248 , minsec_label (_("Mins:Secs"))
249 , bbt_label (_("Bars:Beats"))
250 , timecode_label (_("Timecode"))
251 , frame_label (_("Samples"))
252 , tempo_label (_("Tempo"))
253 , meter_label (_("Meter"))
254 , mark_label (_("Location Markers"))
255 , range_mark_label (_("Range Markers"))
256 , transport_mark_label (_("Loop/Punch Ranges"))
257 , cd_mark_label (_("CD Markers"))
258 , edit_packer (4, 4, true)
260 /* the values here don't matter: layout widgets
261 reset them as needed.
264 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
265 , horizontal_adjustment (0.0, 0.0, 20.0, 1200.0)
267 /* tool bar related */
269 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
271 , toolbar_selection_clock_table (2,3)
273 , automation_mode_button (_("mode"))
274 , global_automation_button (_("automation"))
276 , midi_panic_button (_("Panic"))
279 , image_socket_listener(0)
284 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
285 , meters_running(false)
286 , _pending_locate_request (false)
287 , _pending_initial_locate (false)
292 /* we are a singleton */
294 PublicEditor::_instance = this;
298 selection = new Selection (this);
299 cut_buffer = new Selection (this);
301 clicked_regionview = 0;
302 clicked_axisview = 0;
303 clicked_routeview = 0;
304 clicked_crossfadeview = 0;
305 clicked_control_point = 0;
306 last_update_frame = 0;
307 _drags = new DragManager (this);
308 current_mixer_strip = 0;
309 current_bbt_points = 0;
312 snap_type_strings = I18N (_snap_type_strings);
313 snap_mode_strings = I18N (_snap_mode_strings);
314 zoom_focus_strings = I18N (_zoom_focus_strings);
315 edit_point_strings = I18N (_edit_point_strings);
316 #ifdef USE_RUBBERBAND
317 rb_opt_strings = I18N (_rb_opt_strings);
320 snap_threshold = 5.0;
321 bbt_beat_subdivision = 4;
324 last_autoscroll_x = 0;
325 last_autoscroll_y = 0;
326 autoscroll_active = false;
327 autoscroll_timeout_tag = -1;
332 current_interthread_info = 0;
333 _show_measures = true;
334 show_gain_after_trim = false;
335 verbose_cursor_on = true;
336 last_item_entered = 0;
337 last_item_entered_n = 0;
339 have_pending_keyboard_selection = false;
340 _follow_playhead = true;
341 _stationary_playhead = false;
342 _xfade_visibility = true;
343 editor_ruler_menu = 0;
344 no_ruler_shown_update = false;
346 session_range_marker_menu = 0;
347 range_marker_menu = 0;
348 marker_menu_item = 0;
350 transport_marker_menu = 0;
351 new_transport_marker_menu = 0;
352 editor_mixer_strip_width = Wide;
353 show_editor_mixer_when_tracks_arrive = false;
354 region_edit_menu_split_multichannel_item = 0;
355 region_edit_menu_split_item = 0;
358 current_stepping_trackview = 0;
360 entered_regionview = 0;
362 clear_entered_track = false;
365 button_release_can_deselect = true;
366 _dragging_playhead = false;
367 _dragging_edit_point = false;
368 select_new_marker = false;
371 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
372 _global_port_matrix[*i] = 0;
374 allow_vertical_scroll = false;
375 no_save_visual = false;
378 scrubbing_direction = 0;
382 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
383 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
384 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
385 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
386 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
388 _edit_point = EditAtMouse;
389 _internal_editing = false;
390 current_canvas_cursor = 0;
392 frames_per_unit = 2048; /* too early to use reset_zoom () */
394 zoom_focus = ZoomFocusLeft;
395 set_zoom_focus (ZoomFocusLeft);
396 zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
398 bbt_label.set_name ("EditorTimeButton");
399 bbt_label.set_size_request (-1, (int)timebar_height);
400 bbt_label.set_alignment (1.0, 0.5);
401 bbt_label.set_padding (5,0);
403 bbt_label.set_no_show_all();
404 minsec_label.set_name ("EditorTimeButton");
405 minsec_label.set_size_request (-1, (int)timebar_height);
406 minsec_label.set_alignment (1.0, 0.5);
407 minsec_label.set_padding (5,0);
408 minsec_label.hide ();
409 minsec_label.set_no_show_all();
410 timecode_label.set_name ("EditorTimeButton");
411 timecode_label.set_size_request (-1, (int)timebar_height);
412 timecode_label.set_alignment (1.0, 0.5);
413 timecode_label.set_padding (5,0);
414 timecode_label.hide ();
415 timecode_label.set_no_show_all();
416 frame_label.set_name ("EditorTimeButton");
417 frame_label.set_size_request (-1, (int)timebar_height);
418 frame_label.set_alignment (1.0, 0.5);
419 frame_label.set_padding (5,0);
421 frame_label.set_no_show_all();
423 tempo_label.set_name ("EditorTimeButton");
424 tempo_label.set_size_request (-1, (int)timebar_height);
425 tempo_label.set_alignment (1.0, 0.5);
426 tempo_label.set_padding (5,0);
428 tempo_label.set_no_show_all();
429 meter_label.set_name ("EditorTimeButton");
430 meter_label.set_size_request (-1, (int)timebar_height);
431 meter_label.set_alignment (1.0, 0.5);
432 meter_label.set_padding (5,0);
434 meter_label.set_no_show_all();
435 mark_label.set_name ("EditorTimeButton");
436 mark_label.set_size_request (-1, (int)timebar_height);
437 mark_label.set_alignment (1.0, 0.5);
438 mark_label.set_padding (5,0);
440 mark_label.set_no_show_all();
441 cd_mark_label.set_name ("EditorTimeButton");
442 cd_mark_label.set_size_request (-1, (int)timebar_height);
443 cd_mark_label.set_alignment (1.0, 0.5);
444 cd_mark_label.set_padding (5,0);
445 cd_mark_label.hide();
446 cd_mark_label.set_no_show_all();
447 range_mark_label.set_name ("EditorTimeButton");
448 range_mark_label.set_size_request (-1, (int)timebar_height);
449 range_mark_label.set_alignment (1.0, 0.5);
450 range_mark_label.set_padding (5,0);
451 range_mark_label.hide();
452 range_mark_label.set_no_show_all();
453 transport_mark_label.set_name ("EditorTimeButton");
454 transport_mark_label.set_size_request (-1, (int)timebar_height);
455 transport_mark_label.set_alignment (1.0, 0.5);
456 transport_mark_label.set_padding (5,0);
457 transport_mark_label.hide();
458 transport_mark_label.set_no_show_all();
460 initialize_rulers ();
461 initialize_canvas ();
462 _summary = new EditorSummary (this);
464 selection->TimeChanged.connect (sigc::mem_fun(*this, &Editor::time_selection_changed));
465 selection->TracksChanged.connect (sigc::mem_fun(*this, &Editor::track_selection_changed));
466 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (sigc::mem_fun(*this, &Editor::region_selection_changed));
467 selection->PointsChanged.connect (sigc::mem_fun(*this, &Editor::point_selection_changed));
468 selection->MarkersChanged.connect (sigc::mem_fun(*this, &Editor::marker_selection_changed));
470 edit_controls_vbox.set_spacing (0);
471 horizontal_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
472 vertical_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::tie_vertical_scrolling), true);
473 track_canvas->signal_map_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_map_handler));
475 HBox* h = manage (new HBox);
476 _group_tabs = new EditorGroupTabs (this);
477 h->pack_start (*_group_tabs, PACK_SHRINK);
478 h->pack_start (edit_controls_vbox);
479 controls_layout.add (*h);
481 controls_layout.set_name ("EditControlsBase");
482 controls_layout.add_events (Gdk::SCROLL_MASK);
483 controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false);
485 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
486 controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
487 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
491 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
492 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
493 0.0, 1.0, 100.0, 1.0));
494 pad_line_1->property_color_rgba() = 0xFF0000FF;
498 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
499 time_canvas_vbox.set_size_request (-1, -1);
501 ruler_label_event_box.add (ruler_label_vbox);
502 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
503 ruler_label_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
505 time_button_event_box.add (time_button_vbox);
506 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
507 time_button_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
509 /* these enable us to have a dedicated window (for cursor setting, etc.)
510 for the canvas areas.
513 track_canvas_event_box.add (*track_canvas);
515 time_canvas_event_box.add (time_canvas_vbox);
516 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
518 edit_packer.set_col_spacings (0);
519 edit_packer.set_row_spacings (0);
520 edit_packer.set_homogeneous (false);
521 edit_packer.set_border_width (0);
522 edit_packer.set_name ("EditorWindow");
524 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
525 /* labels for the rulers */
526 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
527 /* labels for the marker "tracks" */
528 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
530 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
532 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
534 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
536 bottom_hbox.set_border_width (2);
537 bottom_hbox.set_spacing (3);
539 _route_groups = new EditorRouteGroups (this);
540 _routes = new EditorRoutes (this);
541 _regions = new EditorRegions (this);
542 _snapshots = new EditorSnapshots (this);
543 _locations = new EditorLocations (this);
547 nlabel = manage (new Label (_("Regions")));
548 nlabel->set_angle (-90);
549 the_notebook.append_page (_regions->widget (), *nlabel);
550 nlabel = manage (new Label (_("Tracks/Busses")));
551 nlabel->set_angle (-90);
552 the_notebook.append_page (_routes->widget (), *nlabel);
553 nlabel = manage (new Label (_("Snapshots")));
554 nlabel->set_angle (-90);
555 the_notebook.append_page (_snapshots->widget (), *nlabel);
556 nlabel = manage (new Label (_("Route Groups")));
557 nlabel->set_angle (-90);
558 the_notebook.append_page (_route_groups->widget (), *nlabel);
559 nlabel = manage (new Label (_("Ranges & Marks")));
560 nlabel->set_angle (-90);
561 the_notebook.append_page (_locations->widget (), *nlabel);
563 the_notebook.set_show_tabs (true);
564 the_notebook.set_scrollable (true);
565 the_notebook.popup_disable ();
566 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
567 the_notebook.show_all ();
569 post_maximal_editor_width = 0;
570 post_maximal_pane_position = 0;
572 VPaned *editor_summary_pane = manage(new VPaned());
573 editor_summary_pane->pack1(edit_packer);
575 Button* summary_arrows_left_left = manage (new Button);
576 summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
577 summary_arrows_left_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
578 Button* summary_arrows_left_right = manage (new Button);
579 summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
580 summary_arrows_left_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
581 VBox* summary_arrows_left = manage (new VBox);
582 summary_arrows_left->pack_start (*summary_arrows_left_left);
583 summary_arrows_left->pack_start (*summary_arrows_left_right);
585 Button* summary_arrows_right_left = manage (new Button);
586 summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
587 summary_arrows_right_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
588 Button* summary_arrows_right_right = manage (new Button);
589 summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
590 summary_arrows_right_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
591 VBox* summary_arrows_right = manage (new VBox);
592 summary_arrows_right->pack_start (*summary_arrows_right_left);
593 summary_arrows_right->pack_start (*summary_arrows_right_right);
595 Frame* summary_frame = manage (new Frame);
596 summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
597 summary_frame->add (*_summary);
598 summary_frame->show ();
600 _summary_hbox.pack_start (*summary_arrows_left, false, false);
601 _summary_hbox.pack_start (*summary_frame, true, true);
602 _summary_hbox.pack_start (*summary_arrows_right, false, false);
604 editor_summary_pane->pack2 (_summary_hbox);
606 edit_pane.pack1 (*editor_summary_pane, true, true);
607 edit_pane.pack2 (the_notebook, false, true);
609 edit_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
611 Glib::PropertyProxy<int> proxy = edit_pane.property_position();
612 proxy.signal_changed().connect (bind (sigc::ptr_fun (pane_size_watcher), static_cast<Paned*> (&edit_pane)));
614 top_hbox.pack_start (toolbar_frame, false, true);
616 HBox *hbox = manage (new HBox);
617 hbox->pack_start (edit_pane, true, true);
619 global_vpacker.pack_start (top_hbox, false, false);
620 global_vpacker.pack_start (*hbox, true, true);
622 global_hpacker.pack_start (global_vpacker, true, true);
624 set_name ("EditorWindow");
625 add_accel_group (ActionManager::ui_manager->get_accel_group());
627 status_bar_hpacker.show ();
629 vpacker.pack_end (status_bar_hpacker, false, false);
630 vpacker.pack_end (global_hpacker, true, true);
632 /* register actions now so that set_state() can find them and set toggles/checks etc */
637 setup_midi_toolbar ();
639 _snap_type = SnapToBeat;
640 set_snap_to (_snap_type);
641 _snap_mode = SnapOff;
642 set_snap_mode (_snap_mode);
643 set_mouse_mode (MouseObject, true);
644 set_edit_point_preference (EditAtMouse, true);
646 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
647 set_state (*node, Stateful::loading_state_version);
649 _playlist_selector = new PlaylistSelector();
650 _playlist_selector->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
652 RegionView::RegionViewGoingAway.connect (*this, invalidator (*this), ui_bind (&Editor::catch_vanishing_regionview, this, _1), gui_context());
656 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
657 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
659 nudge_forward_button.set_name ("TransportButton");
660 nudge_backward_button.set_name ("TransportButton");
662 fade_context_menu.set_name ("ArdourContextMenu");
664 /* icons, titles, WM stuff */
666 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
667 Glib::RefPtr<Gdk::Pixbuf> icon;
669 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
670 window_icons.push_back (icon);
672 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
673 window_icons.push_back (icon);
675 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
676 window_icons.push_back (icon);
678 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
679 window_icons.push_back (icon);
681 if (!window_icons.empty()) {
682 set_icon_list (window_icons);
683 set_default_icon_list (window_icons);
686 WindowTitle title(Glib::get_application_name());
687 title += _("Editor");
688 set_title (title.get_string());
689 set_wmclass (X_("ardour_editor"), "Ardour");
692 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
694 signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
695 signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
697 /* allow external control surfaces/protocols to do various things */
699 ControlProtocol::ZoomToSession.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_session, this), gui_context());
700 ControlProtocol::ZoomIn.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
701 ControlProtocol::ZoomOut.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
702 ControlProtocol::ScrollTimeline.connect (*this, invalidator (*this), ui_bind (&Editor::control_scroll, this, _1), gui_context());
703 BasicUI::AccessAction.connect (*this, invalidator (*this), ui_bind (&Editor::access_action, this, _1, _2), gui_context());
705 /* problematic: has to return a value and thus cannot be x-thread */
707 Session::AskAboutPlaylistDeletion.connect_same_thread (*this, boost::bind (&Editor::playlist_deletion_dialog, this, _1));
709 Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
711 TimeAxisView::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&Editor::timeaxisview_deleted, this, _1), gui_context());
713 _last_normalization_value = 0;
722 if(image_socket_listener) {
723 if(image_socket_listener->is_connected())
725 image_socket_listener->close_connection() ;
728 delete image_socket_listener ;
729 image_socket_listener = 0 ;
734 delete _route_groups;
740 Editor::add_toplevel_controls (Container& cont)
742 vpacker.pack_start (cont, false, false);
747 Editor::catch_vanishing_regionview (RegionView *rv)
749 /* note: the selection will take care of the vanishing
750 audioregionview by itself.
753 if (_drags->active() && _drags->have_item (rv->get_canvas_group()) && !_drags->ending()) {
757 if (clicked_regionview == rv) {
758 clicked_regionview = 0;
761 if (entered_regionview == rv) {
762 set_entered_regionview (0);
767 Editor::set_entered_regionview (RegionView* rv)
769 if (rv == entered_regionview) {
773 if (entered_regionview) {
774 entered_regionview->exited ();
777 if ((entered_regionview = rv) != 0) {
778 entered_regionview->entered ();
783 Editor::set_entered_track (TimeAxisView* tav)
786 entered_track->exited ();
789 if ((entered_track = tav) != 0) {
790 entered_track->entered ();
795 Editor::show_window ()
797 if (! is_visible ()) {
800 /* re-hide editor list if necessary */
801 editor_list_button_toggled ();
803 /* re-hide summary widget if necessary */
804 parameter_changed ("show-summary");
806 parameter_changed ("show-edit-group-tabs");
808 /* now reset all audio_time_axis heights, because widgets might need
814 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
815 tv = (static_cast<TimeAxisView*>(*i));
819 reset_zoom (frames_per_unit);
826 Editor::instant_save ()
828 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
833 _session->add_instant_xml(get_state());
835 Config->add_instant_xml(get_state());
840 Editor::zoom_adjustment_changed ()
846 double fpu = zoom_range_clock.current_duration() / _canvas_width;
850 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
851 } else if (fpu > _session->current_end_frame() / _canvas_width) {
852 fpu = _session->current_end_frame() / _canvas_width;
853 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
860 Editor::control_scroll (float fraction)
862 ENSURE_GUI_THREAD (*this, &Editor::control_scroll, fraction)
868 double step = fraction * current_page_frames();
871 _control_scroll_target is an optional<T>
873 it acts like a pointer to an nframes64_t, with
874 a operator conversion to boolean to check
875 that it has a value could possibly use
876 playhead_cursor->current_frame to store the
877 value and a boolean in the class to know
878 when it's out of date
881 if (!_control_scroll_target) {
882 _control_scroll_target = _session->transport_frame();
883 _dragging_playhead = true;
886 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
887 *_control_scroll_target = 0;
888 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
889 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
891 *_control_scroll_target += (nframes64_t) floor (step);
894 /* move visuals, we'll catch up with it later */
896 playhead_cursor->set_position (*_control_scroll_target);
897 UpdateAllTransportClocks (*_control_scroll_target);
899 if (*_control_scroll_target > (current_page_frames() / 2)) {
900 /* try to center PH in window */
901 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
907 Now we do a timeout to actually bring the session to the right place
908 according to the playhead. This is to avoid reading disk buffers on every
909 call to control_scroll, which is driven by ScrollTimeline and therefore
910 probably by a control surface wheel which can generate lots of events.
912 /* cancel the existing timeout */
914 control_scroll_connection.disconnect ();
916 /* add the next timeout */
918 control_scroll_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
922 Editor::deferred_control_scroll (nframes64_t /*target*/)
924 _session->request_locate (*_control_scroll_target, _session->transport_rolling());
925 // reset for next stream
926 _control_scroll_target = boost::none;
927 _dragging_playhead = false;
932 Editor::access_action (std::string action_group, std::string action_item)
938 ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
941 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
949 Editor::on_realize ()
951 Window::on_realize ();
956 Editor::map_position_change (nframes64_t frame)
958 ENSURE_GUI_THREAD (*this, &Editor::map_position_change, frame)
960 if (_session == 0 || !_follow_playhead) {
964 center_screen (frame);
965 playhead_cursor->set_position (frame);
969 Editor::center_screen (nframes64_t frame)
971 double page = _canvas_width * frames_per_unit;
973 /* if we're off the page, then scroll.
976 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
977 center_screen_internal (frame, page);
982 Editor::center_screen_internal (nframes64_t frame, float page)
987 frame -= (nframes64_t) page;
992 reset_x_origin (frame);
996 Editor::handle_new_duration ()
1002 ENSURE_GUI_THREAD (*this, &Editor::handle_new_duration)
1003 nframes64_t new_end = _session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1005 horizontal_adjustment.set_upper (new_end / frames_per_unit);
1006 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1008 if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
1009 horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
1011 //cerr << "Editor::handle_new_duration () called ha v:l:u:ps:lcf = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << endl;//DEBUG
1015 Editor::update_title ()
1017 ENSURE_GUI_THREAD (*this, &Editor::update_title)
1020 bool dirty = _session->dirty();
1022 string session_name;
1024 if (_session->snap_name() != _session->name()) {
1025 session_name = _session->snap_name();
1027 session_name = _session->name();
1031 session_name = "*" + session_name;
1034 WindowTitle title(session_name);
1035 title += Glib::get_application_name();
1036 set_title (title.get_string());
1041 Editor::set_session (Session *t)
1043 SessionHandlePtr::set_session (t);
1049 zoom_range_clock.set_session (_session);
1050 _playlist_selector->set_session (_session);
1051 nudge_clock.set_session (_session);
1052 _summary->set_session (_session);
1053 _group_tabs->set_session (_session);
1054 _route_groups->set_session (_session);
1055 _regions->set_session (_session);
1056 _snapshots->set_session (_session);
1057 _routes->set_session (_session);
1058 _locations->set_session (_session);
1060 if (rhythm_ferret) {
1061 rhythm_ferret->set_session (_session);
1064 if (analysis_window) {
1065 analysis_window->set_session (_session);
1069 sfbrowser->set_session (_session);
1072 compute_fixed_ruler_scale ();
1074 /* there are never any selected regions at startup */
1075 sensitize_the_right_region_actions (false);
1077 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1078 set_state (*node, Stateful::loading_state_version);
1080 /* catch up with the playhead */
1082 _session->request_locate (playhead_cursor->current_frame);
1083 _pending_initial_locate = true;
1087 /* These signals can all be emitted by a non-GUI thread. Therefore the
1088 handlers for them must not attempt to directly interact with the GUI,
1089 but use Gtkmm2ext::UI::instance()->call_slot();
1092 _session->TransportStateChange.connect (_session_connections, invalidator (*this), boost::bind (&Editor::map_transport_state, this), gui_context());
1093 _session->PositionChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::map_position_change, this, _1), gui_context());
1094 _session->RouteAdded.connect (_session_connections, invalidator (*this), ui_bind (&Editor::handle_new_route, this, _1), gui_context());
1095 _session->DurationChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::handle_new_duration, this), gui_context());
1096 _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_title, this), gui_context());
1097 _session->TimecodeOffsetChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_just_timecode, this), gui_context());
1098 _session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::tempo_map_changed, this, _1), gui_context());
1099 _session->Located.connect (_session_connections, invalidator (*this), boost::bind (&Editor::located, this), gui_context());
1100 _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
1101 _session->StateSaved.connect (_session_connections, invalidator (*this), ui_bind (&Editor::session_state_saved, this, _1), gui_context());
1102 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&Editor::add_new_location, this, _1), gui_context());
1103 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&Editor::location_gone, this, _1), gui_context());
1104 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::refresh_location_display, this), gui_context());
1105 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::refresh_location_display_s, this, _1), gui_context());
1106 _session->locations()->session_range_location()->changed.connect (_session_connections, invalidator (*this), ui_bind (&Editor::session_range_location_changed, this, _1), gui_context());
1107 _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context());
1109 if (Profile->get_sae()) {
1114 nframes_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
1115 nudge_clock.set_mode(AudioClock::BBT);
1116 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1119 nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
1122 playhead_cursor->canvas_item.show ();
1124 Location* loc = _session->locations()->auto_loop_location();
1126 loc = new Location (0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1127 if (loc->start() == loc->end()) {
1128 loc->set_end (loc->start() + 1);
1130 _session->locations()->add (loc, false);
1131 _session->set_auto_loop_location (loc);
1134 loc->set_name (_("Loop"));
1137 loc = _session->locations()->auto_punch_location();
1139 loc = new Location (0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1140 if (loc->start() == loc->end()) {
1141 loc->set_end (loc->start() + 1);
1143 _session->locations()->add (loc, false);
1144 _session->set_auto_punch_location (loc);
1147 loc->set_name (_("Punch"));
1150 boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
1151 Config->map_parameters (pc);
1152 _session->config.map_parameters (pc);
1154 refresh_location_display ();
1155 handle_new_duration ();
1157 restore_ruler_visibility ();
1158 //tempo_map_changed (PropertyChange (0));
1159 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1161 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1162 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1165 super_rapid_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
1166 sigc::mem_fun (*this, &Editor::super_rapid_screen_update)
1169 switch (_snap_type) {
1170 case SnapToRegionStart:
1171 case SnapToRegionEnd:
1172 case SnapToRegionSync:
1173 case SnapToRegionBoundary:
1174 build_region_boundary_cache ();
1181 /* register for undo history */
1182 _session->register_with_memento_command_factory(_id, this);
1184 start_updating_meters ();
1188 Editor::build_cursors ()
1190 using namespace Gdk;
1192 Gdk::Color mbg ("#000000" ); /* Black */
1193 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1196 RefPtr<Bitmap> source, mask;
1197 source = Bitmap::create (mag_bits, mag_width, mag_height);
1198 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1199 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1202 Gdk::Color fbg ("#ffffff" );
1203 Gdk::Color ffg ("#000000" );
1206 RefPtr<Bitmap> source, mask;
1208 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1209 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1210 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1214 RefPtr<Bitmap> source, mask;
1215 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1216 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1217 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1221 RefPtr<Bitmap> bits;
1222 char pix[4] = { 0, 0, 0, 0 };
1223 bits = Bitmap::create (pix, 2, 2);
1225 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1229 RefPtr<Bitmap> bits;
1230 char pix[4] = { 0, 0, 0, 0 };
1231 bits = Bitmap::create (pix, 2, 2);
1233 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1237 grabber_cursor = new Gdk::Cursor (HAND2);
1240 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1241 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1244 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1245 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1246 selector_cursor = new Gdk::Cursor (XTERM);
1247 time_fx_cursor = new Gdk::Cursor (SIZING);
1248 wait_cursor = new Gdk::Cursor (WATCH);
1249 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1250 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1251 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1252 midi_resize_cursor = new Gdk::Cursor (SIZING);
1253 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1256 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1258 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1260 using namespace Menu_Helpers;
1261 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1264 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1268 MenuList& items (fade_context_menu.items());
1272 switch (item_type) {
1274 case FadeInHandleItem:
1275 if (arv->audio_region()->fade_in_active()) {
1276 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), false)));
1278 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), true)));
1281 items.push_back (SeparatorElem());
1283 if (Profile->get_sae()) {
1284 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1285 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1287 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1288 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1289 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1290 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1291 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1297 case FadeOutHandleItem:
1298 if (arv->audio_region()->fade_out_active()) {
1299 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), false)));
1301 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), true)));
1304 items.push_back (SeparatorElem());
1306 if (Profile->get_sae()) {
1307 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1308 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1310 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1311 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1312 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1313 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1314 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1320 fatal << _("programming error: ")
1321 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1326 fade_context_menu.popup (button, time);
1330 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1332 using namespace Menu_Helpers;
1333 Menu* (Editor::*build_menu_function)(nframes64_t);
1336 switch (item_type) {
1338 case RegionViewName:
1339 case RegionViewNameHighlight:
1340 if (with_selection) {
1341 build_menu_function = &Editor::build_track_selection_context_menu;
1343 build_menu_function = &Editor::build_track_region_context_menu;
1348 if (with_selection) {
1349 build_menu_function = &Editor::build_track_selection_context_menu;
1351 build_menu_function = &Editor::build_track_context_menu;
1355 case CrossfadeViewItem:
1356 build_menu_function = &Editor::build_track_crossfade_context_menu;
1360 if (clicked_routeview->track()) {
1361 build_menu_function = &Editor::build_track_context_menu;
1363 build_menu_function = &Editor::build_track_bus_context_menu;
1368 /* probably shouldn't happen but if it does, we don't care */
1372 menu = (this->*build_menu_function)(frame);
1373 menu->set_name ("ArdourContextMenu");
1375 /* now handle specific situations */
1377 switch (item_type) {
1379 case RegionViewName:
1380 case RegionViewNameHighlight:
1381 if (!with_selection) {
1382 if (region_edit_menu_split_item) {
1383 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1384 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1386 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1389 if (region_edit_menu_split_multichannel_item) {
1390 if (clicked_regionview && clicked_regionview->region()->n_channels() > 1) {
1391 region_edit_menu_split_multichannel_item->set_sensitive (true);
1393 region_edit_menu_split_multichannel_item->set_sensitive (false);
1402 case CrossfadeViewItem:
1409 /* probably shouldn't happen but if it does, we don't care */
1413 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1415 /* Bounce to disk */
1417 using namespace Menu_Helpers;
1418 MenuList& edit_items = menu->items();
1420 edit_items.push_back (SeparatorElem());
1422 switch (clicked_routeview->audio_track()->freeze_state()) {
1423 case AudioTrack::NoFreeze:
1424 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1427 case AudioTrack::Frozen:
1428 edit_items.push_back (MenuElem (_("Unfreeze"), sigc::mem_fun(*this, &Editor::unfreeze_route)));
1431 case AudioTrack::UnFrozen:
1432 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1438 if (item_type == StreamItem && clicked_routeview) {
1439 clicked_routeview->build_underlay_menu(menu);
1442 menu->popup (button, time);
1446 Editor::build_track_context_menu (nframes64_t)
1448 using namespace Menu_Helpers;
1450 MenuList& edit_items = track_context_menu.items();
1453 add_dstream_context_items (edit_items);
1454 return &track_context_menu;
1458 Editor::build_track_bus_context_menu (nframes64_t)
1460 using namespace Menu_Helpers;
1462 MenuList& edit_items = track_context_menu.items();
1465 add_bus_context_items (edit_items);
1466 return &track_context_menu;
1470 Editor::build_track_region_context_menu (nframes64_t frame)
1472 using namespace Menu_Helpers;
1473 MenuList& edit_items = track_region_context_menu.items();
1476 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1479 boost::shared_ptr<Track> tr;
1480 boost::shared_ptr<Playlist> pl;
1482 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
1483 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * tr->speed()));
1485 if (selection->regions.size() > 1) {
1486 // there's already a multiple selection: just add a
1487 // single region context menu that will act on all
1489 boost::shared_ptr<Region> dummy_region; // = NULL
1490 add_region_context_items (rtv->view(), dummy_region, edit_items);
1492 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1493 add_region_context_items (rtv->view(), (*i), edit_items);
1501 add_dstream_context_items (edit_items);
1503 return &track_region_context_menu;
1507 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1509 using namespace Menu_Helpers;
1510 MenuList& edit_items = track_crossfade_context_menu.items();
1511 edit_items.clear ();
1513 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1516 boost::shared_ptr<Track> tr;
1517 boost::shared_ptr<Playlist> pl;
1518 boost::shared_ptr<AudioPlaylist> apl;
1520 if ((tr = atv->track()) && ((pl = tr->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1522 Playlist::RegionList* regions = pl->regions_at (frame);
1523 AudioPlaylist::Crossfades xfades;
1525 apl->crossfades_at (frame, xfades);
1527 bool many = xfades.size() > 1;
1529 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1530 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1533 if (selection->regions.size() > 1) {
1534 // there's already a multiple selection: just add a
1535 // single region context menu that will act on all
1537 boost::shared_ptr<Region> dummy_region; // = NULL
1538 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1540 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1541 add_region_context_items (atv->audio_view(), (*i), edit_items);
1548 add_dstream_context_items (edit_items);
1550 return &track_crossfade_context_menu;
1554 Editor::analyze_region_selection()
1556 if (analysis_window == 0) {
1557 analysis_window = new AnalysisWindow();
1560 analysis_window->set_session(_session);
1562 analysis_window->show_all();
1565 analysis_window->set_regionmode();
1566 analysis_window->analyze();
1568 analysis_window->present();
1572 Editor::analyze_range_selection()
1574 if (analysis_window == 0) {
1575 analysis_window = new AnalysisWindow();
1578 analysis_window->set_session(_session);
1580 analysis_window->show_all();
1583 analysis_window->set_rangemode();
1584 analysis_window->analyze();
1586 analysis_window->present();
1590 Editor::build_track_selection_context_menu (nframes64_t)
1592 using namespace Menu_Helpers;
1593 MenuList& edit_items = track_selection_context_menu.items();
1594 edit_items.clear ();
1596 add_selection_context_items (edit_items);
1597 // edit_items.push_back (SeparatorElem());
1598 // add_dstream_context_items (edit_items);
1600 return &track_selection_context_menu;
1603 /** Add context menu items relevant to crossfades.
1604 * @param edit_items List to add the items to.
1607 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1609 using namespace Menu_Helpers;
1610 Menu *xfade_menu = manage (new Menu);
1611 MenuList& items = xfade_menu->items();
1612 xfade_menu->set_name ("ArdourContextMenu");
1615 if (xfade->active()) {
1621 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1622 items.push_back (MenuElem (_("Edit"), sigc::bind (sigc::mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1624 if (xfade->can_follow_overlap()) {
1626 if (xfade->following_overlap()) {
1627 str = _("Convert to Short");
1629 str = _("Convert to Full");
1632 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1636 str = xfade->out()->name();
1638 str += xfade->in()->name();
1640 str = _("Crossfade");
1643 edit_items.push_back (MenuElem (str, *xfade_menu));
1644 edit_items.push_back (SeparatorElem());
1648 Editor::xfade_edit_left_region ()
1650 if (clicked_crossfadeview) {
1651 clicked_crossfadeview->left_view.show_region_editor ();
1656 Editor::xfade_edit_right_region ()
1658 if (clicked_crossfadeview) {
1659 clicked_crossfadeview->right_view.show_region_editor ();
1664 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1666 using namespace Menu_Helpers;
1667 Gtk::MenuItem* foo_item;
1668 Menu *region_menu = manage (new Menu);
1669 MenuList& items = region_menu->items();
1670 region_menu->set_name ("ArdourContextMenu");
1672 boost::shared_ptr<AudioRegion> ar;
1673 boost::shared_ptr<MidiRegion> mr;
1676 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1677 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1679 /* when this particular menu pops up, make the relevant region
1683 region_menu->signal_map_event().connect (
1684 sigc::bind (sigc::mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1686 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::rename_region)));
1687 if (mr && internal_editing()) {
1688 items.push_back (MenuElem (_("List editor..."), sigc::mem_fun(*this, &Editor::show_midi_list_editor)));
1690 items.push_back (MenuElem (_("Region Properties..."), sigc::mem_fun(*this, &Editor::edit_region)));
1694 items.push_back (MenuElem (_("Raise to Top Layer"), sigc::mem_fun(*this, &Editor::raise_region_to_top)));
1695 items.push_back (MenuElem (_("Lower to Bottom Layer"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom)));
1696 items.push_back (SeparatorElem());
1697 items.push_back (MenuElem (_("Define Sync Point"), sigc::mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1698 if (_edit_point == EditAtMouse) {
1699 items.back ().set_sensitive (false);
1701 items.push_back (MenuElem (_("Remove Sync Point"), sigc::mem_fun(*this, &Editor::remove_region_sync)));
1702 items.push_back (SeparatorElem());
1704 items.push_back (MenuElem (_("Audition"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1705 items.push_back (MenuElem (_("Export..."), sigc::mem_fun(*this, &Editor::export_region)));
1706 items.push_back (MenuElem (_("Bounce"), sigc::mem_fun(*this, &Editor::bounce_region_selection)));
1709 items.push_back (MenuElem (_("Spectral Analysis..."), sigc::mem_fun(*this, &Editor::analyze_region_selection)));
1712 items.push_back (SeparatorElem());
1714 sigc::connection fooc;
1715 boost::shared_ptr<Region> region_to_check;
1718 region_to_check = region;
1720 region_to_check = selection->regions.front()->region();
1723 items.push_back (CheckMenuElem (_("Lock")));
1724 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1725 if (region_to_check->locked()) {
1726 region_lock_item->set_active();
1728 region_lock_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_lock));
1730 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
1731 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1733 switch (region_to_check->positional_lock_style()) {
1734 case Region::MusicTime:
1735 bbt_glue_item->set_active (true);
1738 bbt_glue_item->set_active (false);
1742 bbt_glue_item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1744 items.push_back (CheckMenuElem (_("Mute")));
1745 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1746 fooc = region_mute_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_mute));
1747 if (region_to_check->muted()) {
1749 region_mute_item->set_active();
1753 items.push_back (MenuElem (_("Transpose..."), mem_fun(*this, &Editor::pitch_shift_regions)));
1755 if (!Profile->get_sae()) {
1756 items.push_back (CheckMenuElem (_("Opaque")));
1757 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1758 fooc = region_opaque_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_opaque));
1759 if (region_to_check->opaque()) {
1761 region_opaque_item->set_active();
1766 items.push_back (CheckMenuElem (_("Original Position"), sigc::mem_fun(*this, &Editor::naturalize)));
1767 if (region_to_check->at_natural_position()) {
1768 items.back().set_sensitive (false);
1771 items.push_back (SeparatorElem());
1775 RegionView* rv = sv->find_view (ar);
1776 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1778 if (!Profile->get_sae()) {
1779 items.push_back (MenuElem (_("Reset Envelope"), sigc::mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1781 items.push_back (CheckMenuElem (_("Envelope Visible")));
1782 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1783 fooc = region_envelope_visible_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1784 if (arv->envelope_visible()) {
1786 region_envelope_visible_item->set_active (true);
1790 items.push_back (CheckMenuElem (_("Envelope Active")));
1791 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1792 fooc = region_envelope_active_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_active));
1794 if (ar->envelope_active()) {
1796 region_envelope_active_item->set_active (true);
1800 items.push_back (SeparatorElem());
1803 items.push_back (MenuElem (_("Normalize..."), sigc::mem_fun(*this, &Editor::normalize_region)));
1804 if (ar->scale_amplitude() != 1) {
1805 items.push_back (MenuElem (_("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_scale_amplitude)));
1809 items.push_back (MenuElem (_("Quantize"), sigc::mem_fun(*this, &Editor::quantize_region)));
1810 items.push_back (SeparatorElem());
1813 items.push_back (MenuElem (_("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence)));
1814 items.push_back (MenuElem (_("Reverse"), sigc::mem_fun(*this, &Editor::reverse_region)));
1815 items.push_back (SeparatorElem());
1817 /* range related stuff */
1819 items.push_back (MenuElem (_("Add Single Range"), sigc::mem_fun (*this, &Editor::add_location_from_audio_region)));
1820 items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_locations_from_audio_region)));
1821 if (selection->regions.size() < 2) {
1822 items.back().set_sensitive (false);
1825 items.push_back (MenuElem (_("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region)));
1826 items.push_back (SeparatorElem());
1830 Menu *nudge_menu = manage (new Menu());
1831 MenuList& nudge_items = nudge_menu->items();
1832 nudge_menu->set_name ("ArdourContextMenu");
1834 nudge_items.push_back (MenuElem (_("Nudge Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_forward), false, false))));
1835 nudge_items.push_back (MenuElem (_("Nudge Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_backward), false, false))));
1836 nudge_items.push_back (MenuElem (_("Nudge Forward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1837 nudge_items.push_back (MenuElem (_("Nudge Backward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1839 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1840 items.push_back (SeparatorElem());
1842 Menu *trim_menu = manage (new Menu);
1843 MenuList& trim_items = trim_menu->items();
1844 trim_menu->set_name ("ArdourContextMenu");
1846 trim_items.push_back (MenuElem (_("Start to Edit Point"), sigc::mem_fun(*this, &Editor::trim_region_from_edit_point)));
1847 foo_item = &trim_items.back();
1848 if (_edit_point == EditAtMouse) {
1849 foo_item->set_sensitive (false);
1851 trim_items.push_back (MenuElem (_("Edit Point to End"), sigc::mem_fun(*this, &Editor::trim_region_to_edit_point)));
1852 foo_item = &trim_items.back();
1853 if (_edit_point == EditAtMouse) {
1854 foo_item->set_sensitive (false);
1856 trim_items.push_back (MenuElem (_("Trim to Loop"), sigc::mem_fun(*this, &Editor::trim_region_to_loop)));
1857 trim_items.push_back (MenuElem (_("Trim to Punch"), sigc::mem_fun(*this, &Editor::trim_region_to_punch)));
1859 items.push_back (MenuElem (_("Trim"), *trim_menu));
1860 items.push_back (SeparatorElem());
1862 items.push_back (MenuElem (_("Split"), (sigc::mem_fun(*this, &Editor::split))));
1863 region_edit_menu_split_item = &items.back();
1865 if (_edit_point == EditAtMouse) {
1866 region_edit_menu_split_item->set_sensitive (false);
1869 items.push_back (MenuElem (_("Make Mono Regions"), (sigc::mem_fun(*this, &Editor::split_multichannel_region))));
1870 region_edit_menu_split_multichannel_item = &items.back();
1872 items.push_back (MenuElem (_("Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false))));
1873 items.push_back (MenuElem (_("Multi-Duplicate..."), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), true))));
1874 items.push_back (MenuElem (_("Fill Track"), (sigc::mem_fun(*this, &Editor::region_fill_track))));
1875 items.push_back (SeparatorElem());
1876 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::remove_selected_regions)));
1878 /* OK, stick the region submenu at the top of the list, and then add
1882 /* we have to hack up the region name because "_" has a special
1883 meaning for menu titles.
1886 string::size_type pos = 0;
1887 string menu_item_name = (region) ? region->name() : _("Selected Regions");
1889 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1890 menu_item_name.replace (pos, 1, "__");
1894 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1895 edit_items.push_back (SeparatorElem());
1898 /** Add context menu items relevant to selection ranges.
1899 * @param edit_items List to add the items to.
1902 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1904 using namespace Menu_Helpers;
1906 edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
1907 edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
1909 edit_items.push_back (SeparatorElem());
1910 edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
1912 if (!selection->regions.empty()) {
1913 edit_items.push_back (SeparatorElem());
1914 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)));
1915 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)));
1918 edit_items.push_back (SeparatorElem());
1919 edit_items.push_back (MenuElem (_("Silence Range"), sigc::mem_fun(*this, &Editor::separate_region_from_selection)));
1920 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
1922 edit_items.push_back (SeparatorElem());
1923 edit_items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1925 edit_items.push_back (SeparatorElem());
1926 edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false)));
1927 edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
1929 edit_items.push_back (SeparatorElem());
1930 edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
1932 edit_items.push_back (SeparatorElem());
1933 edit_items.push_back (MenuElem (_("Crop Region to Range"), sigc::mem_fun(*this, &Editor::crop_region_to_selection)));
1934 edit_items.push_back (MenuElem (_("Fill Range with Region"), sigc::mem_fun(*this, &Editor::region_fill_selection)));
1935 edit_items.push_back (MenuElem (_("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false)));
1937 edit_items.push_back (SeparatorElem());
1938 edit_items.push_back (MenuElem (_("Consolidate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1939 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1940 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1941 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1942 edit_items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_range)));
1947 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1949 using namespace Menu_Helpers;
1953 Menu *play_menu = manage (new Menu);
1954 MenuList& play_items = play_menu->items();
1955 play_menu->set_name ("ArdourContextMenu");
1957 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
1958 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
1959 play_items.push_back (MenuElem (_("Play Region"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1960 play_items.push_back (SeparatorElem());
1961 play_items.push_back (MenuElem (_("Loop Region"), sigc::mem_fun(*this, &Editor::loop_selected_region)));
1963 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1967 Menu *select_menu = manage (new Menu);
1968 MenuList& select_items = select_menu->items();
1969 select_menu->set_name ("ArdourContextMenu");
1971 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1972 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
1973 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
1974 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
1975 select_items.push_back (SeparatorElem());
1976 select_items.push_back (MenuElem (_("Set Range to Loop Range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop)));
1977 select_items.push_back (MenuElem (_("Set Range to Punch Range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch)));
1978 select_items.push_back (SeparatorElem());
1979 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1980 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1981 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1982 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1983 select_items.push_back (MenuElem (_("Select All Between Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
1984 select_items.push_back (MenuElem (_("Select All Within Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
1985 select_items.push_back (MenuElem (_("Select Range Between Playhead and Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
1987 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1991 Menu *cutnpaste_menu = manage (new Menu);
1992 MenuList& cutnpaste_items = cutnpaste_menu->items();
1993 cutnpaste_menu->set_name ("ArdourContextMenu");
1995 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
1996 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
1997 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
1999 cutnpaste_items.push_back (SeparatorElem());
2001 cutnpaste_items.push_back (MenuElem (_("Align"), sigc::bind (sigc::mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2002 cutnpaste_items.push_back (MenuElem (_("Align Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2004 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2006 /* Adding new material */
2008 edit_items.push_back (SeparatorElem());
2009 edit_items.push_back (MenuElem (_("Insert Selected Region"), sigc::bind (sigc::mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2010 edit_items.push_back (MenuElem (_("Insert Existing Media"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2014 Menu *nudge_menu = manage (new Menu());
2015 MenuList& nudge_items = nudge_menu->items();
2016 nudge_menu->set_name ("ArdourContextMenu");
2018 edit_items.push_back (SeparatorElem());
2019 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2020 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2021 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2022 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2024 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2028 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2030 using namespace Menu_Helpers;
2034 Menu *play_menu = manage (new Menu);
2035 MenuList& play_items = play_menu->items();
2036 play_menu->set_name ("ArdourContextMenu");
2038 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
2039 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
2040 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2044 Menu *select_menu = manage (new Menu);
2045 MenuList& select_items = select_menu->items();
2046 select_menu->set_name ("ArdourContextMenu");
2048 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2049 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
2050 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
2051 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
2052 select_items.push_back (SeparatorElem());
2053 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2054 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2055 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2056 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2058 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2062 Menu *cutnpaste_menu = manage (new Menu);
2063 MenuList& cutnpaste_items = cutnpaste_menu->items();
2064 cutnpaste_menu->set_name ("ArdourContextMenu");
2066 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2067 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2068 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2070 Menu *nudge_menu = manage (new Menu());
2071 MenuList& nudge_items = nudge_menu->items();
2072 nudge_menu->set_name ("ArdourContextMenu");
2074 edit_items.push_back (SeparatorElem());
2075 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2076 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2077 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2078 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2080 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2084 Editor::snap_type() const
2090 Editor::snap_mode() const
2096 Editor::set_snap_to (SnapType st)
2098 unsigned int snap_ind = (unsigned int)st;
2102 if (snap_ind > snap_type_strings.size() - 1) {
2104 _snap_type = (SnapType)snap_ind;
2107 string str = snap_type_strings[snap_ind];
2109 if (str != snap_type_selector.get_active_text()) {
2110 snap_type_selector.set_active_text (str);
2115 switch (_snap_type) {
2116 case SnapToAThirtysecondBeat:
2117 case SnapToASixteenthBeat:
2118 case SnapToAEighthBeat:
2119 case SnapToAQuarterBeat:
2120 case SnapToAThirdBeat:
2121 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2122 update_tempo_based_rulers ();
2125 case SnapToRegionStart:
2126 case SnapToRegionEnd:
2127 case SnapToRegionSync:
2128 case SnapToRegionBoundary:
2129 build_region_boundary_cache ();
2139 Editor::set_snap_mode (SnapMode mode)
2142 string str = snap_mode_strings[(int)mode];
2144 if (str != snap_mode_selector.get_active_text ()) {
2145 snap_mode_selector.set_active_text (str);
2151 Editor::set_edit_point_preference (EditPoint ep, bool force)
2153 bool changed = (_edit_point != ep);
2156 string str = edit_point_strings[(int)ep];
2158 if (str != edit_point_selector.get_active_text ()) {
2159 edit_point_selector.set_active_text (str);
2162 set_canvas_cursor ();
2164 if (!force && !changed) {
2168 const char* action=NULL;
2170 switch (_edit_point) {
2171 case EditAtPlayhead:
2172 action = "edit-at-playhead";
2174 case EditAtSelectedMarker:
2175 action = "edit-at-marker";
2178 action = "edit-at-mouse";
2182 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2184 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2188 bool in_track_canvas;
2190 if (!mouse_frame (foo, in_track_canvas)) {
2191 in_track_canvas = false;
2194 reset_canvas_action_sensitivity (in_track_canvas);
2200 Editor::set_state (const XMLNode& node, int /*version*/)
2202 const XMLProperty* prop;
2204 int x, y, xoff, yoff;
2207 if ((prop = node.property ("id")) != 0) {
2208 _id = prop->value ();
2211 g.base_width = default_width;
2212 g.base_height = default_height;
2218 if ((geometry = find_named_node (node, "geometry")) != 0) {
2222 if ((prop = geometry->property("x_size")) == 0) {
2223 prop = geometry->property ("x-size");
2226 g.base_width = atoi(prop->value());
2228 if ((prop = geometry->property("y_size")) == 0) {
2229 prop = geometry->property ("y-size");
2232 g.base_height = atoi(prop->value());
2235 if ((prop = geometry->property ("x_pos")) == 0) {
2236 prop = geometry->property ("x-pos");
2239 x = atoi (prop->value());
2242 if ((prop = geometry->property ("y_pos")) == 0) {
2243 prop = geometry->property ("y-pos");
2246 y = atoi (prop->value());
2249 if ((prop = geometry->property ("x_off")) == 0) {
2250 prop = geometry->property ("x-off");
2253 xoff = atoi (prop->value());
2255 if ((prop = geometry->property ("y_off")) == 0) {
2256 prop = geometry->property ("y-off");
2259 yoff = atoi (prop->value());
2263 set_default_size (g.base_width, g.base_height);
2266 if (_session && (prop = node.property ("playhead"))) {
2268 sscanf (prop->value().c_str(), "%" PRIi64, &pos);
2269 playhead_cursor->set_position (pos);
2271 playhead_cursor->set_position (0);
2274 if ((prop = node.property ("mixer-width"))) {
2275 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2278 if ((prop = node.property ("zoom-focus"))) {
2279 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2282 if ((prop = node.property ("zoom"))) {
2283 reset_zoom (PBD::atof (prop->value()));
2286 if ((prop = node.property ("snap-to"))) {
2287 set_snap_to ((SnapType) atoi (prop->value()));
2290 if ((prop = node.property ("snap-mode"))) {
2291 set_snap_mode ((SnapMode) atoi (prop->value()));
2294 if ((prop = node.property ("mouse-mode"))) {
2295 MouseMode m = str2mousemode(prop->value());
2296 set_mouse_mode (m, true);
2298 set_mouse_mode (MouseObject, true);
2301 if ((prop = node.property ("left-frame")) != 0){
2303 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
2304 reset_x_origin (pos);
2308 if ((prop = node.property ("y-origin")) != 0) {
2309 reset_y_origin (atof (prop->value ()));
2312 if ((prop = node.property ("internal-edit"))) {
2313 bool yn = string_is_affirmative (prop->value());
2314 RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit"));
2316 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2317 tact->set_active (!yn);
2318 tact->set_active (yn);
2322 if ((prop = node.property ("join-object-range"))) {
2323 join_object_range_button.set_active (string_is_affirmative (prop->value ()));
2326 if ((prop = node.property ("edit-point"))) {
2327 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2330 if ((prop = node.property ("show-measures"))) {
2331 bool yn = string_is_affirmative (prop->value());
2332 _show_measures = !yn;
2333 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2335 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2336 /* do it twice to force the change */
2337 tact->set_active (!yn);
2338 tact->set_active (yn);
2342 if ((prop = node.property ("follow-playhead"))) {
2343 bool yn = string_is_affirmative (prop->value());
2344 set_follow_playhead (yn);
2345 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2347 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2348 if (tact->get_active() != yn) {
2349 tact->set_active (yn);
2354 if ((prop = node.property ("stationary-playhead"))) {
2355 bool yn = (prop->value() == "yes");
2356 set_stationary_playhead (yn);
2357 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
2359 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2360 if (tact->get_active() != yn) {
2361 tact->set_active (yn);
2366 if ((prop = node.property ("region-list-sort-type"))) {
2367 RegionListSortType st;
2368 _regions->reset_sort_type ((RegionListSortType) string_2_enum (prop->value(), st), true);
2371 if ((prop = node.property ("xfades-visible"))) {
2372 bool yn = string_is_affirmative (prop->value());
2373 _xfade_visibility = !yn;
2374 // set_xfade_visibility (yn);
2377 if ((prop = node.property ("show-editor-mixer"))) {
2379 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2382 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2383 bool yn = string_is_affirmative (prop->value());
2385 /* do it twice to force the change */
2387 tact->set_active (!yn);
2388 tact->set_active (yn);
2392 if ((prop = node.property ("show-editor-list"))) {
2394 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2398 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2399 bool yn = string_is_affirmative (prop->value());
2401 /* do it twice to force the change */
2403 tact->set_active (!yn);
2404 tact->set_active (yn);
2408 if ((prop = node.property (X_("editor-list-page")))) {
2409 the_notebook.set_current_page (atoi (prop->value ()));
2412 if ((prop = node.property (X_("editor-pane-position")))) {
2413 edit_pane.set_position (atoi (prop->value ()));
2420 Editor::get_state ()
2422 XMLNode* node = new XMLNode ("Editor");
2425 _id.print (buf, sizeof (buf));
2426 node->add_property ("id", buf);
2428 if (is_realized()) {
2429 Glib::RefPtr<Gdk::Window> win = get_window();
2431 int x, y, xoff, yoff, width, height;
2432 win->get_root_origin(x, y);
2433 win->get_position(xoff, yoff);
2434 win->get_size(width, height);
2436 XMLNode* geometry = new XMLNode ("geometry");
2438 snprintf(buf, sizeof(buf), "%d", width);
2439 geometry->add_property("x-size", string(buf));
2440 snprintf(buf, sizeof(buf), "%d", height);
2441 geometry->add_property("y-size", string(buf));
2442 snprintf(buf, sizeof(buf), "%d", x);
2443 geometry->add_property("x-pos", string(buf));
2444 snprintf(buf, sizeof(buf), "%d", y);
2445 geometry->add_property("y-pos", string(buf));
2446 snprintf(buf, sizeof(buf), "%d", xoff);
2447 geometry->add_property("x-off", string(buf));
2448 snprintf(buf, sizeof(buf), "%d", yoff);
2449 geometry->add_property("y-off", string(buf));
2450 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2451 geometry->add_property("edit_pane_pos", string(buf));
2453 node->add_child_nocopy (*geometry);
2456 maybe_add_mixer_strip_width (*node);
2458 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2459 node->add_property ("zoom-focus", buf);
2460 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2461 node->add_property ("zoom", buf);
2462 snprintf (buf, sizeof(buf), "%d", (int) _snap_type);
2463 node->add_property ("snap-to", buf);
2464 snprintf (buf, sizeof(buf), "%d", (int) _snap_mode);
2465 node->add_property ("snap-mode", buf);
2467 node->add_property ("edit-point", enum_2_string (_edit_point));
2469 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2470 node->add_property ("playhead", buf);
2471 snprintf (buf, sizeof (buf), "%" PRIi64, leftmost_frame);
2472 node->add_property ("left-frame", buf);
2473 snprintf (buf, sizeof (buf), "%f", vertical_adjustment.get_value ());
2474 node->add_property ("y-origin", buf);
2476 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2477 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2478 node->add_property ("stationary-playhead", _stationary_playhead ? "yes" : "no");
2479 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2480 node->add_property ("region-list-sort-type", enum_2_string (_regions->sort_type ()));
2481 node->add_property ("mouse-mode", enum2str(mouse_mode));
2482 node->add_property ("internal-edit", _internal_editing ? "yes" : "no");
2483 node->add_property ("join-object-range", join_object_range_button.get_active () ? "yes" : "no");
2485 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2487 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2488 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2491 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2493 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2494 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2497 snprintf (buf, sizeof (buf), "%d", the_notebook.get_current_page ());
2498 node->add_property (X_("editor-list-page"), buf);
2500 snprintf (buf, sizeof (buf), "%d", edit_pane.get_position ());
2501 node->add_property (X_("editor-pane-position"), buf);
2508 /** @param y y offset from the top of all trackviews.
2509 * @return pair: TimeAxisView that y is over, layer index.
2510 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2511 * in stacked region display mode, otherwise 0.
2513 std::pair<TimeAxisView *, layer_t>
2514 Editor::trackview_by_y_position (double y)
2516 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2518 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2524 return std::make_pair ( (TimeAxisView *) 0, 0);
2527 /** Snap a position to the grid, if appropriate, taking into account current
2528 * grid settings and also the state of any snap modifier keys that may be pressed.
2529 * @param start Position to snap.
2530 * @param event Event to get current key modifier information from, or 0.
2533 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2535 if (!_session || !event) {
2539 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2540 if (_snap_mode == SnapOff) {
2541 snap_to_internal (start, direction, for_mark);
2544 if (_snap_mode != SnapOff) {
2545 snap_to_internal (start, direction, for_mark);
2551 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2553 if (!_session || _snap_mode == SnapOff) {
2557 snap_to_internal (start, direction, for_mark);
2561 Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
2563 const nframes64_t one_timecode_second = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
2564 nframes64_t one_timecode_minute = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
2566 switch (_snap_type) {
2567 case SnapToTimecodeFrame:
2568 if (((direction == 0) && (fmod((double)start, (double)_session->frames_per_timecode_frame()) > (_session->frames_per_timecode_frame() / 2))) || (direction > 0)) {
2569 start = (nframes64_t) (ceil ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2571 start = (nframes64_t) (floor ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2575 case SnapToTimecodeSeconds:
2576 if (_session->timecode_offset_negative())
2578 start += _session->timecode_offset ();
2580 start -= _session->timecode_offset ();
2582 if (((direction == 0) && (start % one_timecode_second > one_timecode_second / 2)) || direction > 0) {
2583 start = (nframes64_t) ceil ((double) start / one_timecode_second) * one_timecode_second;
2585 start = (nframes64_t) floor ((double) start / one_timecode_second) * one_timecode_second;
2588 if (_session->timecode_offset_negative())
2590 start -= _session->timecode_offset ();
2592 start += _session->timecode_offset ();
2596 case SnapToTimecodeMinutes:
2597 if (_session->timecode_offset_negative())
2599 start += _session->timecode_offset ();
2601 start -= _session->timecode_offset ();
2603 if (((direction == 0) && (start % one_timecode_minute > one_timecode_minute / 2)) || direction > 0) {
2604 start = (nframes64_t) ceil ((double) start / one_timecode_minute) * one_timecode_minute;
2606 start = (nframes64_t) floor ((double) start / one_timecode_minute) * one_timecode_minute;
2608 if (_session->timecode_offset_negative())
2610 start -= _session->timecode_offset ();
2612 start += _session->timecode_offset ();
2616 fatal << "Editor::smpte_snap_to_internal() called with non-timecode snap type!" << endmsg;
2622 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2624 const nframes64_t one_second = _session->frame_rate();
2625 const nframes64_t one_minute = _session->frame_rate() * 60;
2626 nframes64_t presnap = start;
2630 switch (_snap_type) {
2631 case SnapToTimecodeFrame:
2632 case SnapToTimecodeSeconds:
2633 case SnapToTimecodeMinutes:
2634 return timecode_snap_to_internal (start, direction, for_mark);
2637 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2638 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2640 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2645 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2646 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2648 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2653 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2654 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2656 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2661 start = _session->tempo_map().round_to_bar (start, direction);
2665 start = _session->tempo_map().round_to_beat (start, direction);
2668 case SnapToAThirtysecondBeat:
2669 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2672 case SnapToASixteenthBeat:
2673 start = _session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2676 case SnapToAEighthBeat:
2677 start = _session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2680 case SnapToAQuarterBeat:
2681 start = _session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2684 case SnapToAThirdBeat:
2685 start = _session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2693 _session->locations()->marks_either_side (start, before, after);
2695 if (before == max_frames) {
2697 } else if (after == max_frames) {
2699 } else if (before != max_frames && after != max_frames) {
2700 /* have before and after */
2701 if ((start - before) < (after - start)) {
2710 case SnapToRegionStart:
2711 case SnapToRegionEnd:
2712 case SnapToRegionSync:
2713 case SnapToRegionBoundary:
2714 if (!region_boundary_cache.empty()) {
2716 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2717 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2719 if (direction > 0) {
2720 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2722 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2725 if (next != region_boundary_cache.begin ()) {
2730 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2731 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2733 if (start > (p + n) / 2) {
2742 switch (_snap_mode) {
2748 if (presnap > start) {
2749 if (presnap > (start + unit_to_frame(snap_threshold))) {
2753 } else if (presnap < start) {
2754 if (presnap < (start - unit_to_frame(snap_threshold))) {
2760 /* handled at entry */
2768 Editor::setup_toolbar ()
2772 /* Mode Buttons (tool selection) */
2774 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2775 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2776 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2777 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2778 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2779 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2780 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2781 join_object_range_button.set_relief(Gtk::RELIEF_NONE);
2783 HBox* mode_box = manage(new HBox);
2784 mode_box->set_border_width (2);
2785 mode_box->set_spacing(4);
2787 /* table containing mode buttons */
2789 HBox* mouse_mode_button_box = manage (new HBox ());
2791 if (Profile->get_sae()) {
2792 mouse_mode_button_box->pack_start (mouse_move_button);
2794 mouse_mode_button_box->pack_start (mouse_move_button);
2795 mouse_mode_button_box->pack_start (join_object_range_button);
2796 mouse_mode_button_box->pack_start (mouse_select_button);
2799 mouse_mode_button_box->pack_start (mouse_zoom_button);
2801 if (!Profile->get_sae()) {
2802 mouse_mode_button_box->pack_start (mouse_gain_button);
2805 mouse_mode_button_box->pack_start (mouse_timefx_button);
2806 mouse_mode_button_box->pack_start (mouse_audition_button);
2807 mouse_mode_button_box->pack_start (internal_edit_button);
2809 vector<string> edit_mode_strings;
2810 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2811 if (!Profile->get_sae()) {
2812 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2814 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2816 edit_mode_selector.set_name ("EditModeSelector");
2817 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2818 edit_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_mode_selection_done));
2820 mode_box->pack_start (edit_mode_selector);
2821 mode_box->pack_start (*mouse_mode_button_box);
2823 _mouse_mode_tearoff = manage (new TearOff (*mode_box));
2824 _mouse_mode_tearoff->set_name ("MouseModeBase");
2825 _mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_mouse_mode_tearoff->tearoff_window()), false);
2827 if (Profile->get_sae()) {
2828 _mouse_mode_tearoff->set_can_be_torn_off (false);
2831 _mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2832 &_mouse_mode_tearoff->tearoff_window()));
2833 _mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2834 &_mouse_mode_tearoff->tearoff_window(), 1));
2835 _mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2836 &_mouse_mode_tearoff->tearoff_window()));
2837 _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2838 &_mouse_mode_tearoff->tearoff_window(), 1));
2840 mouse_move_button.set_mode (false);
2841 mouse_select_button.set_mode (false);
2842 mouse_gain_button.set_mode (false);
2843 mouse_zoom_button.set_mode (false);
2844 mouse_timefx_button.set_mode (false);
2845 mouse_audition_button.set_mode (false);
2846 join_object_range_button.set_mode (false);
2848 mouse_move_button.set_name ("MouseModeButton");
2849 mouse_select_button.set_name ("MouseModeButton");
2850 mouse_gain_button.set_name ("MouseModeButton");
2851 mouse_zoom_button.set_name ("MouseModeButton");
2852 mouse_timefx_button.set_name ("MouseModeButton");
2853 mouse_audition_button.set_name ("MouseModeButton");
2854 internal_edit_button.set_name ("MouseModeButton");
2855 join_object_range_button.set_name ("MouseModeButton");
2857 mouse_move_button.unset_flags (CAN_FOCUS);
2858 mouse_select_button.unset_flags (CAN_FOCUS);
2859 mouse_gain_button.unset_flags (CAN_FOCUS);
2860 mouse_zoom_button.unset_flags (CAN_FOCUS);
2861 mouse_timefx_button.unset_flags (CAN_FOCUS);
2862 mouse_audition_button.unset_flags (CAN_FOCUS);
2863 internal_edit_button.unset_flags (CAN_FOCUS);
2864 join_object_range_button.unset_flags (CAN_FOCUS);
2868 zoom_box.set_spacing (1);
2869 zoom_box.set_border_width (0);
2871 zoom_in_button.set_name ("EditorTimeButton");
2872 zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_MENU))));
2873 zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
2875 zoom_out_button.set_name ("EditorTimeButton");
2876 zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_MENU))));
2877 zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
2879 zoom_out_full_button.set_name ("EditorTimeButton");
2880 zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_MENU))));
2881 zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
2883 zoom_focus_selector.set_name ("ZoomFocusSelector");
2884 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2885 zoom_focus_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done));
2887 zoom_box.pack_start (zoom_out_button, false, false);
2888 zoom_box.pack_start (zoom_in_button, false, false);
2889 zoom_box.pack_start (zoom_out_full_button, false, false);
2891 /* Track zoom buttons */
2892 tav_expand_button.set_name ("TrackHeightButton");
2893 tav_expand_button.set_size_request(-1,20);
2894 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2895 tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
2897 tav_shrink_button.set_name ("TrackHeightButton");
2898 tav_shrink_button.set_size_request(-1,20);
2899 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2900 tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
2902 track_zoom_box.set_spacing (1);
2903 track_zoom_box.set_border_width (0);
2905 track_zoom_box.pack_start (tav_shrink_button, false, false);
2906 track_zoom_box.pack_start (tav_expand_button, false, false);
2908 HBox* zbc = manage (new HBox);
2909 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2910 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2911 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2912 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2914 snap_box.set_spacing (1);
2915 snap_box.set_border_width (2);
2917 snap_type_selector.set_name ("SnapTypeSelector");
2918 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2919 snap_type_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_type_selection_done));
2921 snap_mode_selector.set_name ("SnapModeSelector");
2922 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2923 snap_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_mode_selection_done));
2925 edit_point_selector.set_name ("EditPointSelector");
2926 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2927 edit_point_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_point_selection_done));
2929 snap_box.pack_start (snap_mode_selector, false, false);
2930 snap_box.pack_start (snap_type_selector, false, false);
2931 snap_box.pack_start (edit_point_selector, false, false);
2935 HBox *nudge_box = manage (new HBox);
2936 nudge_box->set_spacing(1);
2937 nudge_box->set_border_width (2);
2939 nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
2940 nudge_backward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_backward_release), false);
2942 nudge_box->pack_start (nudge_backward_button, false, false);
2943 nudge_box->pack_start (nudge_forward_button, false, false);
2944 nudge_box->pack_start (nudge_clock, false, false);
2947 /* Pack everything in... */
2949 HBox* hbox = manage (new HBox);
2950 hbox->set_spacing(10);
2952 _tools_tearoff = manage (new TearOff (*hbox));
2953 _tools_tearoff->set_name ("MouseModeBase");
2954 _tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_tools_tearoff->tearoff_window()), false);
2956 if (Profile->get_sae()) {
2957 _tools_tearoff->set_can_be_torn_off (false);
2960 _tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2961 &_tools_tearoff->tearoff_window()));
2962 _tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2963 &_tools_tearoff->tearoff_window(), 0));
2964 _tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2965 &_tools_tearoff->tearoff_window()));
2966 _tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2967 &_tools_tearoff->tearoff_window(), 0));
2969 toolbar_hbox.set_spacing (10);
2970 toolbar_hbox.set_border_width (1);
2972 toolbar_hbox.pack_start (*_mouse_mode_tearoff, false, false);
2973 toolbar_hbox.pack_start (*_tools_tearoff, false, false);
2975 hbox->pack_start (snap_box, false, false);
2976 hbox->pack_start (*nudge_box, false, false);
2977 hbox->pack_start (panic_box, false, false);
2981 toolbar_base.set_name ("ToolBarBase");
2982 toolbar_base.add (toolbar_hbox);
2984 toolbar_frame.set_shadow_type (SHADOW_OUT);
2985 toolbar_frame.set_name ("BaseFrame");
2986 toolbar_frame.add (toolbar_base);
2990 Editor::setup_tooltips ()
2992 ARDOUR_UI::instance()->set_tip (mouse_move_button, _("Select/Move Objects"));
2993 ARDOUR_UI::instance()->set_tip (mouse_select_button, _("Select/Move Ranges"));
2994 ARDOUR_UI::instance()->set_tip (mouse_gain_button, _("Draw Gain Automation"));
2995 ARDOUR_UI::instance()->set_tip (mouse_zoom_button, _("Select Zoom Range"));
2996 ARDOUR_UI::instance()->set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2997 ARDOUR_UI::instance()->set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2998 ARDOUR_UI::instance()->set_tip (join_object_range_button, _("Select/Move Objects or Ranges"));
2999 ARDOUR_UI::instance()->set_tip (internal_edit_button, _("Edit Region Contents (e.g. notes)"));
3000 ARDOUR_UI::instance()->set_tip (*_group_tabs, _("Groups: context-click for possible operations"));
3001 ARDOUR_UI::instance()->set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
3002 ARDOUR_UI::instance()->set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
3003 ARDOUR_UI::instance()->set_tip (zoom_in_button, _("Zoom In"));
3004 ARDOUR_UI::instance()->set_tip (zoom_out_button, _("Zoom Out"));
3005 ARDOUR_UI::instance()->set_tip (zoom_out_full_button, _("Zoom to Session"));
3006 ARDOUR_UI::instance()->set_tip (zoom_focus_selector, _("Zoom focus"));
3007 ARDOUR_UI::instance()->set_tip (tav_expand_button, _("Expand Tracks"));
3008 ARDOUR_UI::instance()->set_tip (tav_shrink_button, _("Shrink Tracks"));
3009 ARDOUR_UI::instance()->set_tip (snap_type_selector, _("Snap/Grid Units"));
3010 ARDOUR_UI::instance()->set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3011 ARDOUR_UI::instance()->set_tip (edit_point_selector, _("Edit point"));
3012 ARDOUR_UI::instance()->set_tip (midi_sound_notes, _("Sound Notes"));
3013 ARDOUR_UI::instance()->set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
3017 Editor::midi_panic ()
3019 cerr << "MIDI panic\n";
3022 _session->midi_panic();
3027 Editor::setup_midi_toolbar ()
3031 /* Midi sound notes */
3032 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3033 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3034 midi_sound_notes.unset_flags (CAN_FOCUS);
3038 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
3039 midi_panic_button.set_name("MidiPanicButton");
3040 act->connect_proxy (midi_panic_button);
3042 panic_box.pack_start (midi_sound_notes , true, true);
3043 panic_box.pack_start (midi_panic_button, true, true);
3047 Editor::convert_drop_to_paths (
3048 vector<ustring>& paths,
3049 const RefPtr<Gdk::DragContext>& /*context*/,
3052 const SelectionData& data,
3056 if (_session == 0) {
3060 vector<ustring> uris = data.get_uris();
3064 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3065 are actually URI lists. So do it by hand.
3068 if (data.get_target() != "text/plain") {
3072 /* Parse the "uri-list" format that Nautilus provides,
3073 where each pathname is delimited by \r\n.
3075 THERE MAY BE NO NULL TERMINATING CHAR!!!
3078 ustring txt = data.get_text();
3082 p = (const char *) malloc (txt.length() + 1);
3083 txt.copy ((char *) p, txt.length(), 0);
3084 ((char*)p)[txt.length()] = '\0';
3090 while (g_ascii_isspace (*p))
3094 while (*q && (*q != '\n') && (*q != '\r')) {
3101 while (q > p && g_ascii_isspace (*q))
3106 uris.push_back (ustring (p, q - p + 1));
3110 p = strchr (p, '\n');
3122 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3124 if ((*i).substr (0,7) == "file://") {
3127 PBD::url_decode (p);
3129 // scan forward past three slashes
3131 ustring::size_type slashcnt = 0;
3132 ustring::size_type n = 0;
3133 ustring::iterator x = p.begin();
3135 while (slashcnt < 3 && x != p.end()) {
3138 } else if (slashcnt == 3) {
3145 if (slashcnt != 3 || x == p.end()) {
3146 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3150 paths.push_back (p.substr (n - 1));
3158 Editor::new_tempo_section ()
3164 Editor::map_transport_state ()
3166 ENSURE_GUI_THREAD (*this, &Editor::map_transport_state)
3168 if (_session && _session->transport_stopped()) {
3169 have_pending_keyboard_selection = false;
3172 update_loop_range_view (true);
3177 Editor::State::State (PublicEditor const * e)
3179 selection = new Selection (e);
3182 Editor::State::~State ()
3188 Editor::begin_reversible_command (string name)
3191 _session->begin_reversible_command (name);
3196 Editor::commit_reversible_command ()
3199 _session->commit_reversible_command ();
3204 Editor::set_route_group_solo (Route& route, bool yn)
3206 RouteGroup *route_group;
3208 if ((route_group = route.route_group()) != 0) {
3209 route_group->apply (&Route::set_solo, yn, this);
3211 route.set_solo (yn, this);
3216 Editor::set_route_group_mute (Route& route, bool yn)
3218 RouteGroup *route_group = 0;
3220 if ((route_group = route.route_group()) != 0) {
3221 route_group->apply (&Route::set_mute, yn, this);
3223 route.set_mute (yn, this);
3228 Editor::history_changed ()
3232 if (undo_action && _session) {
3233 if (_session->undo_depth() == 0) {
3236 label = string_compose(_("Undo (%1)"), _session->next_undo());
3238 undo_action->property_label() = label;
3241 if (redo_action && _session) {
3242 if (_session->redo_depth() == 0) {
3245 label = string_compose(_("Redo (%1)"), _session->next_redo());
3247 redo_action->property_label() = label;
3252 Editor::duplicate_dialog (bool with_dialog)
3256 if (mouse_mode == MouseRange) {
3257 if (selection->time.length() == 0) {
3263 get_regions_for_action (rs);
3265 if (mouse_mode != MouseRange) {
3274 ArdourDialog win (_("Duplicate"));
3275 Label label (_("Number of duplications:"));
3276 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3277 SpinButton spinner (adjustment, 0.0, 1);
3280 win.get_vbox()->set_spacing (12);
3281 win.get_vbox()->pack_start (hbox);
3282 hbox.set_border_width (6);
3283 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3285 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3286 place, visually. so do this by hand.
3289 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3290 spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3291 spinner.grab_focus();
3297 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3298 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3299 win.set_default_response (RESPONSE_ACCEPT);
3301 win.set_position (WIN_POS_MOUSE);
3303 spinner.grab_focus ();
3305 switch (win.run ()) {
3306 case RESPONSE_ACCEPT:
3312 times = adjustment.get_value();
3315 if (mouse_mode == MouseRange) {
3316 duplicate_selection (times);
3318 duplicate_some_regions (rs, times);
3323 Editor::show_verbose_canvas_cursor ()
3325 verbose_canvas_cursor->raise_to_top();
3326 verbose_canvas_cursor->show();
3327 verbose_cursor_visible = true;
3331 Editor::hide_verbose_canvas_cursor ()
3333 verbose_canvas_cursor->hide();
3334 verbose_cursor_visible = false;
3338 Editor::clamp_verbose_cursor_x (double x)
3343 x = min (_canvas_width - 200.0, x);
3349 Editor::clamp_verbose_cursor_y (double y)
3351 if (y < canvas_timebars_vsize) {
3352 y = canvas_timebars_vsize;
3354 y = min (_canvas_height - 50, y);
3360 Editor::show_verbose_canvas_cursor_with (const string & txt)
3362 verbose_canvas_cursor->property_text() = txt.c_str();
3367 track_canvas->get_pointer (x, y);
3368 track_canvas->window_to_world (x, y, wx, wy);
3370 /* don't get too close to the edge */
3371 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3372 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3374 show_verbose_canvas_cursor ();
3378 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3380 verbose_canvas_cursor->property_text() = txt.c_str();
3381 /* don't get too close to the edge */
3382 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3383 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3387 Editor::set_verbose_canvas_cursor_text (const string & txt)
3389 verbose_canvas_cursor->property_text() = txt.c_str();
3393 Editor::set_edit_mode (EditMode m)
3395 Config->set_edit_mode (m);
3399 Editor::cycle_edit_mode ()
3401 switch (Config->get_edit_mode()) {
3403 if (Profile->get_sae()) {
3404 Config->set_edit_mode (Lock);
3406 Config->set_edit_mode (Splice);
3410 Config->set_edit_mode (Lock);
3413 Config->set_edit_mode (Slide);
3419 Editor::edit_mode_selection_done ()
3421 if (_session == 0) {
3425 string choice = edit_mode_selector.get_active_text();
3426 EditMode mode = Slide;
3428 if (choice == _("Splice Edit")) {
3430 } else if (choice == _("Slide Edit")) {
3432 } else if (choice == _("Lock Edit")) {
3436 Config->set_edit_mode (mode);
3440 Editor::snap_type_selection_done ()
3442 string choice = snap_type_selector.get_active_text();
3443 SnapType snaptype = SnapToBeat;
3445 if (choice == _("Beats/3")) {
3446 snaptype = SnapToAThirdBeat;
3447 } else if (choice == _("Beats/4")) {
3448 snaptype = SnapToAQuarterBeat;
3449 } else if (choice == _("Beats/8")) {
3450 snaptype = SnapToAEighthBeat;
3451 } else if (choice == _("Beats/16")) {
3452 snaptype = SnapToASixteenthBeat;
3453 } else if (choice == _("Beats/32")) {
3454 snaptype = SnapToAThirtysecondBeat;
3455 } else if (choice == _("Beats")) {
3456 snaptype = SnapToBeat;
3457 } else if (choice == _("Bars")) {
3458 snaptype = SnapToBar;
3459 } else if (choice == _("Marks")) {
3460 snaptype = SnapToMark;
3461 } else if (choice == _("Region starts")) {
3462 snaptype = SnapToRegionStart;
3463 } else if (choice == _("Region ends")) {
3464 snaptype = SnapToRegionEnd;
3465 } else if (choice == _("Region bounds")) {
3466 snaptype = SnapToRegionBoundary;
3467 } else if (choice == _("Region syncs")) {
3468 snaptype = SnapToRegionSync;
3469 } else if (choice == _("CD Frames")) {
3470 snaptype = SnapToCDFrame;
3471 } else if (choice == _("Timecode Frames")) {
3472 snaptype = SnapToTimecodeFrame;
3473 } else if (choice == _("Timecode Seconds")) {
3474 snaptype = SnapToTimecodeSeconds;
3475 } else if (choice == _("Timecode Minutes")) {
3476 snaptype = SnapToTimecodeMinutes;
3477 } else if (choice == _("Seconds")) {
3478 snaptype = SnapToSeconds;
3479 } else if (choice == _("Minutes")) {
3480 snaptype = SnapToMinutes;
3483 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3485 ract->set_active ();
3490 Editor::snap_mode_selection_done ()
3492 string choice = snap_mode_selector.get_active_text();
3493 SnapMode mode = SnapNormal;
3495 if (choice == _("No Grid")) {
3497 } else if (choice == _("Grid")) {
3499 } else if (choice == _("Magnetic")) {
3500 mode = SnapMagnetic;
3503 RefPtr<RadioAction> ract = snap_mode_action (mode);
3506 ract->set_active (true);
3511 Editor::cycle_edit_point (bool with_marker)
3513 switch (_edit_point) {
3515 set_edit_point_preference (EditAtPlayhead);
3517 case EditAtPlayhead:
3519 set_edit_point_preference (EditAtSelectedMarker);
3521 set_edit_point_preference (EditAtMouse);
3524 case EditAtSelectedMarker:
3525 set_edit_point_preference (EditAtMouse);
3531 Editor::edit_point_selection_done ()
3533 string choice = edit_point_selector.get_active_text();
3534 EditPoint ep = EditAtSelectedMarker;
3536 if (choice == _("Marker")) {
3537 set_edit_point_preference (EditAtSelectedMarker);
3538 } else if (choice == _("Playhead")) {
3539 set_edit_point_preference (EditAtPlayhead);
3541 set_edit_point_preference (EditAtMouse);
3544 RefPtr<RadioAction> ract = edit_point_action (ep);
3547 ract->set_active (true);
3552 Editor::zoom_focus_selection_done ()
3554 string choice = zoom_focus_selector.get_active_text();
3555 ZoomFocus focus_type = ZoomFocusLeft;
3557 if (choice == _("Left")) {
3558 focus_type = ZoomFocusLeft;
3559 } else if (choice == _("Right")) {
3560 focus_type = ZoomFocusRight;
3561 } else if (choice == _("Center")) {
3562 focus_type = ZoomFocusCenter;
3563 } else if (choice == _("Playhead")) {
3564 focus_type = ZoomFocusPlayhead;
3565 } else if (choice == _("Mouse")) {
3566 focus_type = ZoomFocusMouse;
3567 } else if (choice == _("Edit point")) {
3568 focus_type = ZoomFocusEdit;
3571 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3574 ract->set_active ();
3579 Editor::edit_controls_button_release (GdkEventButton* ev)
3581 if (Keyboard::is_context_menu_event (ev)) {
3582 ARDOUR_UI::instance()->add_route (this);
3588 Editor::mouse_select_button_release (GdkEventButton* ev)
3590 /* this handles just right-clicks */
3592 if (ev->button != 3) {
3600 Editor::set_zoom_focus (ZoomFocus f)
3602 string str = zoom_focus_strings[(int)f];
3604 if (str != zoom_focus_selector.get_active_text()) {
3605 zoom_focus_selector.set_active_text (str);
3608 if (zoom_focus != f) {
3611 ZoomFocusChanged (); /* EMIT_SIGNAL */
3618 Editor::ensure_float (Window& win)
3620 win.set_transient_for (*this);
3624 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3626 /* recover or initialize pane positions. do this here rather than earlier because
3627 we don't want the positions to change the child allocations, which they seem to do.
3633 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3635 static int32_t done;
3638 width = default_width;
3639 height = default_height;
3641 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3643 if ((prop = geometry->property ("x_size")) == 0) {
3644 prop = geometry->property ("x-size");
3647 width = atoi (prop->value());
3649 if ((prop = geometry->property ("y_size")) == 0) {
3650 prop = geometry->property ("y-size");
3653 height = atoi (prop->value());
3657 if (which == static_cast<Paned*> (&edit_pane)) {
3663 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3664 /* initial allocation is 90% to canvas, 10% to notebook */
3665 pos = (int) floor (alloc.get_width() * 0.90f);
3666 snprintf (buf, sizeof(buf), "%d", pos);
3668 pos = atoi (prop->value());
3671 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3672 edit_pane.set_position (pos);
3673 pre_maximal_pane_position = pos;
3679 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3681 if (_tools_tearoff->torn_off() && _mouse_mode_tearoff->torn_off()) {
3682 top_hbox.remove (toolbar_frame);
3687 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3689 if (toolbar_frame.get_parent() == 0) {
3690 top_hbox.pack_end (toolbar_frame);
3695 Editor::set_show_measures (bool yn)
3697 if (_show_measures != yn) {
3700 if ((_show_measures = yn) == true) {
3702 tempo_lines->show();
3710 Editor::toggle_follow_playhead ()
3712 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3714 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3715 set_follow_playhead (tact->get_active());
3720 Editor::set_follow_playhead (bool yn)
3722 if (_follow_playhead != yn) {
3723 if ((_follow_playhead = yn) == true) {
3725 reset_x_origin_to_follow_playhead ();
3732 Editor::toggle_stationary_playhead ()
3734 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
3736 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3737 set_stationary_playhead (tact->get_active());
3742 Editor::set_stationary_playhead (bool yn)
3744 if (_stationary_playhead != yn) {
3745 if ((_stationary_playhead = yn) == true) {
3747 // FIXME need a 3.0 equivalent of this 2.X call
3748 // update_current_screen ();
3755 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3757 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3759 xfade->set_active (!xfade->active());
3764 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3766 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3768 xfade->set_follow_overlap (!xfade->following_overlap());
3773 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3775 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3781 CrossfadeEditor cew (_session, xfade, xfade->fade_in().get_min_y(), 1.0);
3785 switch (cew.run ()) {
3786 case RESPONSE_ACCEPT:
3793 PropertyChange all_crossfade_properties;
3794 all_crossfade_properties.add (ARDOUR::Properties::active);
3795 all_crossfade_properties.add (ARDOUR::Properties::follow_overlap);
3796 xfade->PropertyChanged (all_crossfade_properties);
3800 Editor::playlist_selector () const
3802 return *_playlist_selector;
3806 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3810 switch (_snap_type) {
3815 case SnapToAThirtysecondBeat:
3819 case SnapToASixteenthBeat:
3823 case SnapToAEighthBeat:
3827 case SnapToAQuarterBeat:
3831 case SnapToAThirdBeat:
3837 return _session->tempo_map().meter_at (position).beats_per_bar();
3842 case SnapToTimecodeFrame:
3843 case SnapToTimecodeSeconds:
3844 case SnapToTimecodeMinutes:
3847 case SnapToRegionStart:
3848 case SnapToRegionEnd:
3849 case SnapToRegionSync:
3850 case SnapToRegionBoundary:
3860 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3864 ret = nudge_clock.current_duration (pos);
3865 next = ret + 1; /* XXXX fix me */
3871 Editor::session_range_location_changed (Location* location)
3873 ENSURE_GUI_THREAD (*this, &Editor::session_range_location_changed, location)
3874 //reset_scrolling_region ();
3875 nframes64_t const session_span = location->end() + (nframes64_t) floorf (current_page_frames() * 0.10f);
3876 horizontal_adjustment.set_upper (session_span / frames_per_unit);
3880 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3882 ArdourDialog dialog ("playlist deletion dialog");
3883 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3884 "If left alone, no audio files used by it will be cleaned.\n"
3885 "If deleted, audio files used by it alone by will cleaned."),
3888 dialog.set_position (WIN_POS_CENTER);
3889 dialog.get_vbox()->pack_start (label);
3893 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3894 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3895 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3897 switch (dialog.run ()) {
3898 case RESPONSE_ACCEPT:
3899 /* delete the playlist */
3903 case RESPONSE_REJECT:
3904 /* keep the playlist */
3916 Editor::audio_region_selection_covers (nframes64_t where)
3918 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3919 if ((*a)->region()->covers (where)) {
3928 Editor::prepare_for_cleanup ()
3930 cut_buffer->clear_regions ();
3931 cut_buffer->clear_playlists ();
3933 selection->clear_regions ();
3934 selection->clear_playlists ();
3936 _regions->suspend_redisplay ();
3940 Editor::finish_cleanup ()
3942 _regions->resume_redisplay ();
3946 Editor::transport_loop_location()
3949 return _session->locations()->auto_loop_location();
3956 Editor::transport_punch_location()
3959 return _session->locations()->auto_punch_location();
3966 Editor::control_layout_scroll (GdkEventScroll* ev)
3968 if (Keyboard::some_magic_widget_has_focus()) {
3972 switch (ev->direction) {
3974 scroll_tracks_up_line ();
3978 case GDK_SCROLL_DOWN:
3979 scroll_tracks_down_line ();
3983 /* no left/right handling yet */
3991 Editor::session_state_saved (string snap_name)
3993 ENSURE_GUI_THREAD (*this, &Editor::session_state_saved, snap_name);
3996 _snapshots->redisplay ();
4000 Editor::maximise_editing_space ()
4002 _mouse_mode_tearoff->set_visible (false);
4003 _tools_tearoff->set_visible (false);
4005 pre_maximal_pane_position = edit_pane.get_position();
4006 pre_maximal_editor_width = this->get_width();
4008 if(post_maximal_pane_position == 0) {
4009 post_maximal_pane_position = edit_pane.get_width();
4014 if(post_maximal_editor_width) {
4015 edit_pane.set_position (post_maximal_pane_position -
4016 abs(post_maximal_editor_width - pre_maximal_editor_width));
4018 edit_pane.set_position (post_maximal_pane_position);
4023 Editor::restore_editing_space ()
4025 // user changed width of pane during fullscreen
4027 if(post_maximal_pane_position != edit_pane.get_position()) {
4028 post_maximal_pane_position = edit_pane.get_position();
4033 _mouse_mode_tearoff->set_visible (true);
4034 _tools_tearoff->set_visible (true);
4035 post_maximal_editor_width = this->get_width();
4037 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4041 * Make new playlists for a given track and also any others that belong
4042 * to the same active route group with the `edit' property.
4047 Editor::new_playlists (TimeAxisView* v)
4049 begin_reversible_command (_("new playlists"));
4050 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4051 _session->playlists->get (playlists);
4052 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4053 commit_reversible_command ();
4057 * Use a copy of the current playlist for a given track and also any others that belong
4058 * to the same active route group with the `edit' property.
4063 Editor::copy_playlists (TimeAxisView* v)
4065 begin_reversible_command (_("copy playlists"));
4066 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4067 _session->playlists->get (playlists);
4068 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4069 commit_reversible_command ();
4072 /** Clear the current playlist for a given track and also any others that belong
4073 * to the same active route group with the `edit' property.
4078 Editor::clear_playlists (TimeAxisView* v)
4080 begin_reversible_command (_("clear playlists"));
4081 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4082 _session->playlists->get (playlists);
4083 mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, ARDOUR::Properties::edit.property_id);
4084 commit_reversible_command ();
4088 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4090 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4094 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4096 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4100 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4102 atv.clear_playlist ();
4106 Editor::on_key_press_event (GdkEventKey* ev)
4108 return key_press_focus_accelerator_handler (*this, ev);
4112 Editor::on_key_release_event (GdkEventKey* ev)
4114 return Gtk::Window::on_key_release_event (ev);
4115 // return key_press_focus_accelerator_handler (*this, ev);
4118 /** Queue up a change to the viewport x origin.
4119 * @param frame New x origin.
4122 Editor::reset_x_origin (nframes64_t frame)
4124 queue_visual_change (frame);
4128 Editor::reset_y_origin (double y)
4130 queue_visual_change_y (y);
4134 Editor::reset_zoom (double fpu)
4136 queue_visual_change (fpu);
4140 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4142 //cerr << "Editor::reposition_and_zoom () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
4143 reset_x_origin (frame);
4146 if (!no_save_visual) {
4147 undo_visual_stack.push_back (current_visual_state(false));
4151 Editor::VisualState*
4152 Editor::current_visual_state (bool with_tracks)
4154 VisualState* vs = new VisualState;
4155 vs->y_position = vertical_adjustment.get_value();
4156 vs->frames_per_unit = frames_per_unit;
4157 vs->leftmost_frame = leftmost_frame;
4158 vs->zoom_focus = zoom_focus;
4161 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4162 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4170 Editor::undo_visual_state ()
4172 if (undo_visual_stack.empty()) {
4176 redo_visual_stack.push_back (current_visual_state());
4178 VisualState* vs = undo_visual_stack.back();
4179 undo_visual_stack.pop_back();
4180 use_visual_state (*vs);
4184 Editor::redo_visual_state ()
4186 if (redo_visual_stack.empty()) {
4190 undo_visual_stack.push_back (current_visual_state());
4192 VisualState* vs = redo_visual_stack.back();
4193 redo_visual_stack.pop_back();
4194 use_visual_state (*vs);
4198 Editor::swap_visual_state ()
4200 if (undo_visual_stack.empty()) {
4201 redo_visual_state ();
4203 undo_visual_state ();
4208 Editor::use_visual_state (VisualState& vs)
4210 no_save_visual = true;
4212 _routes->suspend_redisplay ();
4214 vertical_adjustment.set_value (vs.y_position);
4216 set_zoom_focus (vs.zoom_focus);
4217 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4219 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4220 TrackViewList::iterator t;
4222 /* check if the track still exists - it could have been deleted */
4224 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4225 (*t)->set_state (*(i->second), Stateful::loading_state_version);
4230 if (!vs.track_states.empty()) {
4231 _routes->update_visibility ();
4234 _routes->resume_redisplay ();
4236 no_save_visual = false;
4240 Editor::set_frames_per_unit (double fpu)
4242 /* this is the core function that controls the zoom level of the canvas. it is called
4243 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4246 if (fpu == frames_per_unit) {
4255 /* don't allow zooms that fit more than the maximum number
4256 of frames into an 800 pixel wide space.
4259 if (max_frames / fpu < 800.0) {
4264 tempo_lines->tempo_map_changed();
4266 frames_per_unit = fpu;
4271 Editor::post_zoom ()
4273 nframes64_t cef = 0;
4275 // convert fpu to frame count
4277 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4279 if (frames_per_unit != zoom_range_clock.current_duration()) {
4280 zoom_range_clock.set (frames);
4283 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4284 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4285 (*i)->reshow_selection (selection->time);
4289 leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4291 ZoomChanged (); /* EMIT_SIGNAL */
4294 cef = _session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
4296 horizontal_adjustment.set_upper (cef / frames_per_unit);
4298 //reset_scrolling_region ();
4300 if (playhead_cursor) {
4301 playhead_cursor->set_position (playhead_cursor->current_frame);
4304 refresh_location_display();
4305 _summary->set_overlays_dirty ();
4311 Editor::queue_visual_change (nframes64_t where)
4313 pending_visual_change.add (VisualChange::TimeOrigin);
4315 /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
4319 if (_session && (where > _session->current_end_frame())) {
4320 horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
4323 pending_visual_change.time_origin = where;
4325 ensure_visual_change_idle_handler ();
4329 Editor::queue_visual_change (double fpu)
4331 pending_visual_change.add (VisualChange::ZoomLevel);
4332 pending_visual_change.frames_per_unit = fpu;
4334 ensure_visual_change_idle_handler ();
4338 Editor::queue_visual_change_y (double y)
4340 pending_visual_change.add (VisualChange::YOrigin);
4341 pending_visual_change.y_origin = y;
4343 ensure_visual_change_idle_handler ();
4347 Editor::ensure_visual_change_idle_handler ()
4349 if (pending_visual_change.idle_handler_id < 0) {
4350 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4355 Editor::_idle_visual_changer (void* arg)
4357 return static_cast<Editor*>(arg)->idle_visual_changer ();
4361 Editor::idle_visual_changer ()
4363 VisualChange::Type p = pending_visual_change.pending;
4364 pending_visual_change.pending = (VisualChange::Type) 0;
4366 double last_time_origin = horizontal_adjustment.get_value();
4368 if (p & VisualChange::ZoomLevel) {
4369 set_frames_per_unit (pending_visual_change.frames_per_unit);
4371 compute_fixed_ruler_scale ();
4372 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4373 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4374 update_tempo_based_rulers ();
4376 if (p & VisualChange::TimeOrigin) {
4377 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4379 if (p & VisualChange::YOrigin) {
4380 vertical_adjustment.set_value (pending_visual_change.y_origin);
4383 if (last_time_origin == horizontal_adjustment.get_value()) {
4384 /* changed signal not emitted */
4385 update_fixed_rulers ();
4386 redisplay_tempo (true);
4389 _summary->set_overlays_dirty ();
4391 // cerr << "Editor::idle_visual_changer () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
4392 pending_visual_change.idle_handler_id = -1;
4393 return 0; /* this is always a one-shot call */
4396 struct EditorOrderTimeAxisSorter {
4397 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4398 return a->order () < b->order ();
4403 Editor::sort_track_selection (TrackViewList* sel)
4405 EditorOrderTimeAxisSorter cmp;
4410 selection->tracks.sort (cmp);
4415 Editor::get_preferred_edit_position (bool ignore_playhead)
4418 nframes64_t where = 0;
4419 EditPoint ep = _edit_point;
4421 if (entered_marker) {
4422 return entered_marker->position();
4425 if (ignore_playhead && ep == EditAtPlayhead) {
4426 ep = EditAtSelectedMarker;
4430 case EditAtPlayhead:
4431 where = _session->audible_frame();
4434 case EditAtSelectedMarker:
4435 if (!selection->markers.empty()) {
4437 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4440 where = loc->start();
4451 if (!mouse_frame (where, ignored)) {
4452 /* XXX not right but what can we do ? */
4463 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4465 if (!_session) return;
4467 begin_reversible_command (cmd);
4471 if ((tll = transport_loop_location()) == 0) {
4472 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4473 XMLNode &before = _session->locations()->get_state();
4474 _session->locations()->add (loc, true);
4475 _session->set_auto_loop_location (loc);
4476 XMLNode &after = _session->locations()->get_state();
4477 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4479 XMLNode &before = tll->get_state();
4480 tll->set_hidden (false, this);
4481 tll->set (start, end);
4482 XMLNode &after = tll->get_state();
4483 _session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4486 commit_reversible_command ();
4490 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4492 if (!_session) return;
4494 begin_reversible_command (cmd);
4498 if ((tpl = transport_punch_location()) == 0) {
4499 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4500 XMLNode &before = _session->locations()->get_state();
4501 _session->locations()->add (loc, true);
4502 _session->set_auto_loop_location (loc);
4503 XMLNode &after = _session->locations()->get_state();
4504 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4507 XMLNode &before = tpl->get_state();
4508 tpl->set_hidden (false, this);
4509 tpl->set (start, end);
4510 XMLNode &after = tpl->get_state();
4511 _session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4514 commit_reversible_command ();
4517 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4518 * @param rs List to which found regions are added.
4519 * @param where Time to look at.
4520 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4523 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4525 const TrackViewList* tracks;
4528 tracks = &track_views;
4533 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4534 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4536 boost::shared_ptr<Track> tr;
4537 boost::shared_ptr<Playlist> pl;
4539 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4541 Playlist::RegionList* regions = pl->regions_at (
4542 (nframes64_t) floor ( (double)where * tr->speed()));
4544 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4545 RegionView* rv = rtv->view()->find_view (*i);
4558 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4560 const TrackViewList* tracks;
4563 tracks = &track_views;
4568 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4569 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4571 boost::shared_ptr<Track> tr;
4572 boost::shared_ptr<Playlist> pl;
4574 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4576 Playlist::RegionList* regions = pl->regions_touched (
4577 (nframes64_t) floor ( (double)where * tr->speed()), max_frames);
4579 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4581 RegionView* rv = rtv->view()->find_view (*i);
4594 /** Find all regions which are either:
4596 * - the entered_regionview (if allow_entered == true) or
4597 * - under the preferred edit position AND on a selected track, or on a track
4598 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4599 * @param rs Returned region list.
4600 * @param allow_entered true to include the entered_regionview in the list.
4603 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4605 /* Start with selected regions */
4606 rs = selection->regions;
4608 /* Add the entered_regionview, if requested */
4609 if (allow_entered && entered_regionview) {
4610 rs.add (entered_regionview);
4613 if (allow_edit_position) {
4615 TrackViewList tracks = selection->tracks;
4617 /* tracks is currently the set of selected tracks; add any other tracks that
4618 * have regions that are in the same edit-activated route group as one of
4620 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4622 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4623 if (g && g->is_active() && g->is_edit()) {
4624 tracks.add (axis_views_from_routes (g->route_list()));
4629 if (!tracks.empty()) {
4630 /* now find regions that are at the edit position on those tracks */
4631 nframes64_t const where = get_preferred_edit_position ();
4632 get_regions_at (rs, where, tracks);
4638 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4640 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4642 RouteTimeAxisView* tatv;
4644 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4646 boost::shared_ptr<Playlist> pl;
4647 vector<boost::shared_ptr<Region> > results;
4649 boost::shared_ptr<Track> tr;
4651 if ((tr = tatv->track()) == 0) {
4656 if ((pl = (tr->playlist())) != 0) {
4657 pl->get_region_list_equivalent_regions (region, results);
4660 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4661 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4662 regions.push_back (marv);
4671 Editor::show_rhythm_ferret ()
4673 if (rhythm_ferret == 0) {
4674 rhythm_ferret = new RhythmFerret(*this);
4677 rhythm_ferret->set_session (_session);
4678 rhythm_ferret->show ();
4679 rhythm_ferret->present ();
4683 Editor::show_global_port_matrix (ARDOUR::DataType t)
4685 if (_global_port_matrix[t] == 0) {
4686 _global_port_matrix[t] = new GlobalPortMatrixWindow (_session, t);
4689 _global_port_matrix[t]->show ();
4693 Editor::first_idle ()
4695 MessageDialog* dialog = 0;
4697 if (track_views.size() > 1) {
4698 dialog = new MessageDialog (*this,
4699 string_compose (_("Please wait while %1 loads visual data"), PROGRAM_NAME),
4704 ARDOUR_UI::instance()->flush_pending ();
4707 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4711 // first idle adds route children (automation tracks), so we need to redisplay here
4712 _routes->redisplay ();
4720 Editor::_idle_resize (gpointer arg)
4722 return ((Editor*)arg)->idle_resize ();
4726 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4728 if (resize_idle_id < 0) {
4729 resize_idle_id = g_idle_add (_idle_resize, this);
4730 _pending_resize_amount = 0;
4733 /* make a note of the smallest resulting height, so that we can clamp the
4734 lower limit at TimeAxisView::hSmall */
4736 int32_t min_resulting = INT32_MAX;
4738 _pending_resize_amount += h;
4739 _pending_resize_view = view;
4741 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4743 if (selection->tracks.contains (_pending_resize_view)) {
4744 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4745 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4749 if (min_resulting < 0) {
4754 if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
4755 _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
4759 /** Handle pending resizing of tracks */
4761 Editor::idle_resize ()
4763 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4765 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4766 selection->tracks.contains (_pending_resize_view)) {
4768 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4769 if (*i != _pending_resize_view) {
4770 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4775 _pending_resize_amount = 0;
4777 _group_tabs->set_dirty ();
4778 resize_idle_id = -1;
4786 ENSURE_GUI_THREAD (*this, &Editor::located);
4788 playhead_cursor->set_position (_session->audible_frame ());
4789 if (_follow_playhead && !_pending_initial_locate) {
4790 reset_x_origin_to_follow_playhead ();
4793 _pending_locate_request = false;
4794 _pending_initial_locate = false;
4798 Editor::region_view_added (RegionView *)
4800 _summary->set_dirty ();
4804 Editor::streamview_height_changed ()
4806 _summary->set_dirty ();
4810 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
4812 TrackViewList::const_iterator j = track_views.begin ();
4813 while (j != track_views.end()) {
4814 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4815 if (rtv && rtv->route() == r) {
4826 Editor::axis_views_from_routes (boost::shared_ptr<RouteList> r) const
4830 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
4831 TimeAxisView* tv = axis_view_from_route (*i);
4842 Editor::handle_new_route (RouteList& routes)
4844 ENSURE_GUI_THREAD (*this, &Editor::handle_new_route, routes)
4846 RouteTimeAxisView *rtv;
4847 list<RouteTimeAxisView*> new_views;
4849 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4850 boost::shared_ptr<Route> route = (*x);
4852 if (route->is_hidden() || route->is_monitor()) {
4856 DataType dt = route->input()->default_type();
4858 if (dt == ARDOUR::DataType::AUDIO) {
4859 rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
4860 } else if (dt == ARDOUR::DataType::MIDI) {
4861 rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
4863 throw unknown_type();
4866 new_views.push_back (rtv);
4867 track_views.push_back (rtv);
4869 rtv->effective_gain_display ();
4871 rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
4872 rtv->view()->HeightChanged.connect (sigc::mem_fun (*this, &Editor::streamview_height_changed));
4875 _routes->routes_added (new_views);
4877 if (show_editor_mixer_when_tracks_arrive) {
4878 show_editor_mixer (true);
4881 editor_list_button.set_sensitive (true);
4883 _summary->set_dirty ();
4887 Editor::timeaxisview_deleted (TimeAxisView *tv)
4889 if (_session && _session->deletion_in_progress()) {
4890 /* the situation is under control */
4894 ENSURE_GUI_THREAD (*this, &Editor::timeaxisview_deleted, tv);
4897 _routes->route_removed (tv);
4899 if (tv == entered_track) {
4903 /* remove it from the list of track views */
4905 TrackViewList::iterator i;
4907 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4908 i = track_views.erase (i);
4911 /* update whatever the current mixer strip is displaying, if revelant */
4913 boost::shared_ptr<Route> route;
4914 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv);
4917 route = rtav->route ();
4920 if (current_mixer_strip && current_mixer_strip->route() == route) {
4922 TimeAxisView* next_tv;
4924 if (track_views.empty()) {
4926 } else if (i == track_views.end()) {
4927 next_tv = track_views.front();
4934 set_selected_mixer_strip (*next_tv);
4936 /* make the editor mixer strip go away setting the
4937 * button to inactive (which also unticks the menu option)
4940 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
4946 Editor::hide_track_in_display (TimeAxisView& tv, bool /*temponly*/)
4948 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
4950 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
4951 // this will hide the mixer strip
4952 set_selected_mixer_strip (tv);
4955 _routes->hide_track_in_display (tv);
4959 Editor::sync_track_view_list_and_routes ()
4961 track_views = TrackViewList (_routes->views ());
4963 _summary->set_dirty ();
4964 _group_tabs->set_dirty ();
4966 return false; // do not call again (until needed)
4970 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
4972 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4978 Editor::get_route_view_by_id (PBD::ID& id)
4980 RouteTimeAxisView* v;
4982 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4983 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
4984 if(v->route()->id() == id) {
4994 Editor::fit_route_group (RouteGroup *g)
4996 TrackViewList ts = axis_views_from_routes (g->route_list ());
5001 Editor::consider_auditioning (boost::shared_ptr<Region> region)
5003 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
5006 _session->cancel_audition ();
5010 if (_session->is_auditioning()) {
5011 _session->cancel_audition ();
5012 if (r == last_audition_region) {
5017 _session->audition_region (r);
5018 last_audition_region = r;
5023 Editor::hide_a_region (boost::shared_ptr<Region> r)
5025 r->set_hidden (true);
5029 Editor::show_a_region (boost::shared_ptr<Region> r)
5031 r->set_hidden (false);
5035 Editor::audition_region_from_region_list ()
5037 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::consider_auditioning));
5041 Editor::hide_region_from_region_list ()
5043 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::hide_a_region));
5047 Editor::show_region_in_region_list ()
5049 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::show_a_region));
5053 Editor::start_step_editing ()
5055 step_edit_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::check_step_edit), 20);
5059 Editor::stop_step_editing ()
5061 step_edit_connection.disconnect ();
5065 Editor::check_step_edit ()
5067 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5068 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
5070 mtv->check_step_edit ();
5074 return true; // do it again, till we stop
5078 Editor::horizontal_scroll_left ()
5080 double x = leftmost_position() - current_page_frames() / 5;
5089 Editor::horizontal_scroll_right ()
5091 reset_x_origin (leftmost_position() + current_page_frames() / 5);
5094 /** Queue a change for the Editor viewport x origin to follow the playhead */
5096 Editor::reset_x_origin_to_follow_playhead ()
5098 nframes64_t const frame = playhead_cursor->current_frame;
5100 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
5102 if (_session->transport_speed() < 0) {
5104 if (frame > (current_page_frames() / 2)) {
5105 center_screen (frame-(current_page_frames()/2));
5107 center_screen (current_page_frames()/2);
5112 if (frame < leftmost_frame) {
5115 if (_session->transport_rolling()) {
5116 /* rolling; end up with the playhead at the right of the page */
5117 l = frame - current_page_frames ();
5119 /* not rolling: end up with the playhead 3/4 of the way along the page */
5120 l = frame - (3 * current_page_frames() / 4);
5127 center_screen_internal (l + (current_page_frames() / 2), current_page_frames ());
5130 if (_session->transport_rolling()) {
5131 /* rolling: end up with the playhead on the left of the page */
5132 center_screen_internal (frame + (current_page_frames() / 2), current_page_frames ());
5134 /* not rolling: end up with the playhead 1/4 of the way along the page */
5135 center_screen_internal (frame + (current_page_frames() / 4), current_page_frames ());
5143 Editor::super_rapid_screen_update ()
5145 if (!_session || !_session->engine().running()) {
5149 /* METERING / MIXER STRIPS */
5151 /* update track meters, if required */
5152 if (is_mapped() && meters_running) {
5153 RouteTimeAxisView* rtv;
5154 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5155 if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5156 rtv->fast_update ();
5161 /* and any current mixer strip */
5162 if (current_mixer_strip) {
5163 current_mixer_strip->fast_update ();
5166 /* PLAYHEAD AND VIEWPORT */
5168 nframes64_t const frame = _session->audible_frame();
5170 /* There are a few reasons why we might not update the playhead / viewport stuff:
5172 * 1. we don't update things when there's a pending locate request, otherwise
5173 * when the editor requests a locate there is a chance that this method
5174 * will move the playhead before the locate request is processed, causing
5176 * 2. if we're not rolling, there's nothing to do here (locates are handled elsewhere).
5177 * 3. if we're still at the same frame that we were last time, there's nothing to do.
5180 if (!_pending_locate_request && _session->transport_speed() != 0 && frame != last_update_frame) {
5182 last_update_frame = frame;
5184 if (!_dragging_playhead) {
5185 playhead_cursor->set_position (frame);
5188 if (!_stationary_playhead) {
5190 if (!_dragging_playhead && _follow_playhead && _session->requested_return_frame() < 0) {
5191 reset_x_origin_to_follow_playhead ();
5196 /* don't do continuous scroll till the new position is in the rightmost quarter of the
5200 // FIXME DO SOMETHING THAT WORKS HERE - this is 2.X code
5201 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
5202 if (target <= 0.0) {
5205 if (fabs(target - current) < current_page_frames() / frames_per_unit) {
5206 target = (target * 0.15) + (current * 0.85);
5212 horizontal_adjustment.set_value (current);
5221 Editor::session_going_away ()
5223 _have_idled = false;
5225 _session_connections.drop_connections ();
5227 super_rapid_screen_update_connection.disconnect ();
5229 selection->clear ();
5230 cut_buffer->clear ();
5232 clicked_regionview = 0;
5233 clicked_axisview = 0;
5234 clicked_routeview = 0;
5235 clicked_crossfadeview = 0;
5236 entered_regionview = 0;
5238 last_update_frame = 0;
5241 playhead_cursor->canvas_item.hide ();
5243 /* rip everything out of the list displays */
5247 _route_groups->clear ();
5249 /* do this first so that deleting a track doesn't reset cms to null
5250 and thus cause a leak.
5253 if (current_mixer_strip) {
5254 if (current_mixer_strip->get_parent() != 0) {
5255 global_hpacker.remove (*current_mixer_strip);
5257 delete current_mixer_strip;
5258 current_mixer_strip = 0;
5261 /* delete all trackviews */
5263 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5266 track_views.clear ();
5268 zoom_range_clock.set_session (0);
5269 nudge_clock.set_session (0);
5271 editor_list_button.set_active(false);
5272 editor_list_button.set_sensitive(false);
5274 /* clear tempo/meter rulers */
5275 remove_metric_marks ();
5277 clear_marker_display ();
5279 delete current_bbt_points;
5280 current_bbt_points = 0;
5282 /* get rid of any existing editor mixer strip */
5284 WindowTitle title(Glib::get_application_name());
5285 title += _("Editor");
5287 set_title (title.get_string());
5289 SessionHandlePtr::session_going_away ();
5294 Editor::show_editor_list (bool yn)
5297 the_notebook.show();
5299 the_notebook.hide();