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 <boost/none.hpp>
33 #include <sigc++/bind.h>
35 #include "pbd/convert.h"
36 #include "pbd/error.h"
37 #include "pbd/enumwriter.h"
38 #include "pbd/memento_command.h"
39 #include "pbd/unknown_type.h"
41 #include <glibmm/miscutils.h>
42 #include <gtkmm/image.h>
43 #include <gdkmm/color.h>
44 #include <gdkmm/bitmap.h>
46 #include <gtkmm2ext/grouped_buttons.h>
47 #include <gtkmm2ext/gtk_ui.h>
48 #include <gtkmm2ext/tearoff.h>
49 #include <gtkmm2ext/utils.h>
50 #include <gtkmm2ext/window_title.h>
51 #include <gtkmm2ext/choice.h>
52 #include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
54 #include "ardour/audio_diskstream.h"
55 #include "ardour/audio_track.h"
56 #include "ardour/audioplaylist.h"
57 #include "ardour/audioregion.h"
58 #include "ardour/location.h"
59 #include "ardour/midi_region.h"
60 #include "ardour/plugin_manager.h"
61 #include "ardour/profile.h"
62 #include "ardour/route_group.h"
63 #include "ardour/session_directory.h"
64 #include "ardour/session_route.h"
65 #include "ardour/session_state_utils.h"
66 #include "ardour/tempo.h"
67 #include "ardour/utils.h"
69 #include "control_protocol/control_protocol.h"
71 #include "ardour_ui.h"
75 #include "playlist_selector.h"
76 #include "audio_region_view.h"
77 #include "rgb_macros.h"
78 #include "selection.h"
79 #include "audio_streamview.h"
80 #include "time_axis_view.h"
81 #include "audio_time_axis.h"
83 #include "crossfade_view.h"
85 #include "public_editor.h"
86 #include "crossfade_edit.h"
87 #include "canvas_impl.h"
90 #include "gui_thread.h"
91 #include "simpleline.h"
92 #include "rhythm_ferret.h"
94 #include "tempo_lines.h"
95 #include "analysis_window.h"
96 #include "bundle_manager.h"
97 #include "global_port_matrix.h"
98 #include "editor_drag.h"
99 #include "editor_group_tabs.h"
100 #include "automation_time_axis.h"
101 #include "editor_routes.h"
102 #include "midi_time_axis.h"
103 #include "mixer_strip.h"
104 #include "editor_route_groups.h"
105 #include "editor_regions.h"
106 #include "editor_snapshots.h"
111 #include "imageframe_socket_handler.h"
115 using namespace sigc;
116 using namespace ARDOUR;
119 using namespace Glib;
120 using namespace Gtkmm2ext;
121 using namespace Editing;
123 using PBD::internationalize;
126 const double Editor::timebar_height = 15.0;
128 #include "editor_xpms"
130 static const gchar *_snap_type_strings[] = {
152 static const gchar *_snap_mode_strings[] = {
159 static const gchar *_edit_point_strings[] = {
166 static const gchar *_zoom_focus_strings[] = {
176 #ifdef USE_RUBBERBAND
177 static const gchar *_rb_opt_strings[] = {
180 N_("Balanced multitimbral mixture"),
181 N_("Unpitched percussion with stable notes"),
182 N_("Crisp monophonic instrumental"),
183 N_("Unpitched solo percussion"),
188 /* Soundfile drag-n-drop */
190 Gdk::Cursor* Editor::cross_hair_cursor = 0;
191 Gdk::Cursor* Editor::selector_cursor = 0;
192 Gdk::Cursor* Editor::trimmer_cursor = 0;
193 Gdk::Cursor* Editor::grabber_cursor = 0;
194 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
195 Gdk::Cursor* Editor::zoom_cursor = 0;
196 Gdk::Cursor* Editor::time_fx_cursor = 0;
197 Gdk::Cursor* Editor::fader_cursor = 0;
198 Gdk::Cursor* Editor::speaker_cursor = 0;
199 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
200 Gdk::Cursor* Editor::midi_select_cursor = 0;
201 Gdk::Cursor* Editor::midi_resize_cursor = 0;
202 Gdk::Cursor* Editor::midi_erase_cursor = 0;
203 Gdk::Cursor* Editor::wait_cursor = 0;
204 Gdk::Cursor* Editor::timebar_cursor = 0;
205 Gdk::Cursor* Editor::transparent_cursor = 0;
208 show_me_the_size (Requisition* r, const char* what)
210 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
214 /* time display buttons */
215 : minsec_label (_("Mins:Secs"))
216 , bbt_label (_("Bars:Beats"))
217 , smpte_label (_("Timecode"))
218 , frame_label (_("Samples"))
219 , tempo_label (_("Tempo"))
220 , meter_label (_("Meter"))
221 , mark_label (_("Location Markers"))
222 , range_mark_label (_("Range Markers"))
223 , transport_mark_label (_("Loop/Punch Ranges"))
224 , cd_mark_label (_("CD Markers"))
225 , edit_packer (4, 4, true)
227 /* the values here don't matter: layout widgets
228 reset them as needed.
231 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
232 , horizontal_adjustment (0.0, 0.0, 20.0, 1200.0)
234 /* tool bar related */
236 , edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true)
237 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true)
239 , toolbar_selection_clock_table (2,3)
241 , automation_mode_button (_("mode"))
242 , global_automation_button (_("automation"))
244 , midi_panic_button (_("Panic"))
247 , image_socket_listener(0)
252 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true)
253 , meters_running(false)
254 , _pending_locate_request (false)
259 /* we are a singleton */
261 PublicEditor::_instance = this;
266 selection = new Selection (this);
267 cut_buffer = new Selection (this);
269 clicked_regionview = 0;
270 clicked_axisview = 0;
271 clicked_routeview = 0;
272 clicked_crossfadeview = 0;
273 clicked_control_point = 0;
274 last_update_frame = 0;
276 current_mixer_strip = 0;
277 current_bbt_points = 0;
280 snap_type_strings = I18N (_snap_type_strings);
281 snap_mode_strings = I18N (_snap_mode_strings);
282 zoom_focus_strings = I18N (_zoom_focus_strings);
283 edit_point_strings = I18N (_edit_point_strings);
284 #ifdef USE_RUBBERBAND
285 rb_opt_strings = I18N (_rb_opt_strings);
288 snap_threshold = 5.0;
289 bbt_beat_subdivision = 4;
292 last_autoscroll_x = 0;
293 last_autoscroll_y = 0;
294 autoscroll_active = false;
295 autoscroll_timeout_tag = -1;
296 interthread_progress_window = 0;
301 current_interthread_info = 0;
302 _show_measures = true;
303 _show_waveforms_recording = true;
304 show_gain_after_trim = false;
305 verbose_cursor_on = true;
306 route_removal = false;
307 last_item_entered = 0;
308 last_item_entered_n = 0;
310 have_pending_keyboard_selection = false;
311 _follow_playhead = true;
312 _xfade_visibility = true;
313 editor_ruler_menu = 0;
314 no_ruler_shown_update = false;
316 start_end_marker_menu = 0;
317 range_marker_menu = 0;
318 marker_menu_item = 0;
320 transport_marker_menu = 0;
321 new_transport_marker_menu = 0;
322 editor_mixer_strip_width = Wide;
323 show_editor_mixer_when_tracks_arrive = false;
324 region_edit_menu_split_multichannel_item = 0;
325 region_edit_menu_split_item = 0;
328 current_stepping_trackview = 0;
330 entered_regionview = 0;
332 clear_entered_track = false;
333 _new_regionviews_show_envelope = false;
336 button_release_can_deselect = true;
337 _dragging_playhead = false;
338 _dragging_edit_point = false;
339 _dragging_hscrollbar = false;
340 select_new_marker = false;
341 zoomed_to_region = false;
344 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
345 _global_port_matrix[*i] = 0;
347 allow_vertical_scroll = false;
348 no_save_visual = false;
351 scrubbing_direction = 0;
355 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
356 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
357 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
358 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
359 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
361 _edit_point = EditAtMouse;
362 _internal_editing = false;
363 current_canvas_cursor = 0;
365 frames_per_unit = 2048; /* too early to use reset_zoom () */
366 reset_hscrollbar_stepping ();
368 zoom_focus = ZoomFocusLeft;
369 set_zoom_focus (ZoomFocusLeft);
370 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
372 bbt_label.set_name ("EditorTimeButton");
373 bbt_label.set_size_request (-1, (int)timebar_height);
374 bbt_label.set_alignment (1.0, 0.5);
375 bbt_label.set_padding (5,0);
377 bbt_label.set_no_show_all();
378 minsec_label.set_name ("EditorTimeButton");
379 minsec_label.set_size_request (-1, (int)timebar_height);
380 minsec_label.set_alignment (1.0, 0.5);
381 minsec_label.set_padding (5,0);
382 minsec_label.hide ();
383 minsec_label.set_no_show_all();
384 smpte_label.set_name ("EditorTimeButton");
385 smpte_label.set_size_request (-1, (int)timebar_height);
386 smpte_label.set_alignment (1.0, 0.5);
387 smpte_label.set_padding (5,0);
389 smpte_label.set_no_show_all();
390 frame_label.set_name ("EditorTimeButton");
391 frame_label.set_size_request (-1, (int)timebar_height);
392 frame_label.set_alignment (1.0, 0.5);
393 frame_label.set_padding (5,0);
395 frame_label.set_no_show_all();
397 tempo_label.set_name ("EditorTimeButton");
398 tempo_label.set_size_request (-1, (int)timebar_height);
399 tempo_label.set_alignment (1.0, 0.5);
400 tempo_label.set_padding (5,0);
402 tempo_label.set_no_show_all();
403 meter_label.set_name ("EditorTimeButton");
404 meter_label.set_size_request (-1, (int)timebar_height);
405 meter_label.set_alignment (1.0, 0.5);
406 meter_label.set_padding (5,0);
408 meter_label.set_no_show_all();
409 mark_label.set_name ("EditorTimeButton");
410 mark_label.set_size_request (-1, (int)timebar_height);
411 mark_label.set_alignment (1.0, 0.5);
412 mark_label.set_padding (5,0);
414 mark_label.set_no_show_all();
415 cd_mark_label.set_name ("EditorTimeButton");
416 cd_mark_label.set_size_request (-1, (int)timebar_height);
417 cd_mark_label.set_alignment (1.0, 0.5);
418 cd_mark_label.set_padding (5,0);
419 cd_mark_label.hide();
420 cd_mark_label.set_no_show_all();
421 range_mark_label.set_name ("EditorTimeButton");
422 range_mark_label.set_size_request (-1, (int)timebar_height);
423 range_mark_label.set_alignment (1.0, 0.5);
424 range_mark_label.set_padding (5,0);
425 range_mark_label.hide();
426 range_mark_label.set_no_show_all();
427 transport_mark_label.set_name ("EditorTimeButton");
428 transport_mark_label.set_size_request (-1, (int)timebar_height);
429 transport_mark_label.set_alignment (1.0, 0.5);
430 transport_mark_label.set_padding (5,0);
431 transport_mark_label.hide();
432 transport_mark_label.set_no_show_all();
434 initialize_rulers ();
435 _summary = new EditorSummary (this);
436 initialize_canvas ();
438 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
439 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
440 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
441 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
442 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
444 edit_controls_vbox.set_spacing (0);
445 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
446 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
447 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
449 HBox* h = manage (new HBox);
450 _group_tabs = new EditorGroupTabs (this);
451 h->pack_start (*_group_tabs, PACK_SHRINK);
452 h->pack_start (edit_controls_vbox);
453 controls_layout.add (*h);
455 controls_layout.set_name ("EditControlsBase");
456 controls_layout.add_events (Gdk::SCROLL_MASK);
457 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
459 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
460 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
461 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
463 edit_vscrollbar.set_adjustment (vertical_adjustment);
464 edit_hscrollbar.set_adjustment (horizontal_adjustment);
466 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
467 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
468 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
470 edit_hscrollbar.set_name ("EditorHScrollbar");
474 setup_midi_toolbar ();
476 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
478 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
479 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
480 0.0, 1.0, 100.0, 1.0));
481 pad_line_1->property_color_rgba() = 0xFF0000FF;
485 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
486 time_canvas_vbox.set_size_request (-1, -1);
488 ruler_label_event_box.add (ruler_label_vbox);
489 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
490 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
492 time_button_event_box.add (time_button_vbox);
493 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
494 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
496 /* these enable us to have a dedicated window (for cursor setting, etc.)
497 for the canvas areas.
500 track_canvas_event_box.add (*track_canvas);
502 time_canvas_event_box.add (time_canvas_vbox);
503 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
505 edit_packer.set_col_spacings (0);
506 edit_packer.set_row_spacings (0);
507 edit_packer.set_homogeneous (false);
508 edit_packer.set_border_width (0);
509 edit_packer.set_name ("EditorWindow");
511 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
512 /* labels for the rulers */
513 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
514 /* labels for the marker "tracks" */
515 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
517 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
519 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
521 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
523 bottom_hbox.set_border_width (2);
524 bottom_hbox.set_spacing (3);
526 _route_groups = new EditorRouteGroups (this);
527 _routes = new EditorRoutes (this);
528 _regions = new EditorRegions (this);
529 _snapshots = new EditorSnapshots (this);
531 named_selection_scroller.add (named_selection_display);
532 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
534 named_selection_model = TreeStore::create (named_selection_columns);
535 named_selection_display.set_model (named_selection_model);
536 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
537 named_selection_display.set_headers_visible (false);
538 named_selection_display.set_size_request (100, -1);
539 named_selection_display.set_name ("NamedSelectionDisplay");
541 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
542 named_selection_display.set_size_request (100, -1);
543 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
544 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
545 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
549 nlabel = manage (new Label (_("Regions")));
550 nlabel->set_angle (-90);
551 the_notebook.append_page (_regions->widget (), *nlabel);
552 nlabel = manage (new Label (_("Tracks/Busses")));
553 nlabel->set_angle (-90);
554 the_notebook.append_page (_routes->widget (), *nlabel);
555 nlabel = manage (new Label (_("Snapshots")));
556 nlabel->set_angle (-90);
557 the_notebook.append_page (_snapshots->widget (), *nlabel);
558 nlabel = manage (new Label (_("Route Groups")));
559 nlabel->set_angle (-90);
560 the_notebook.append_page (_route_groups->widget (), *nlabel);
562 if (!Profile->get_sae()) {
563 nlabel = manage (new Label (_("Chunks")));
564 nlabel->set_angle (-90);
565 the_notebook.append_page (named_selection_scroller, *nlabel);
568 the_notebook.set_show_tabs (true);
569 the_notebook.set_scrollable (true);
570 the_notebook.popup_enable ();
571 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
572 the_notebook.show_all ();
574 post_maximal_editor_width = 0;
575 post_maximal_pane_position = 0;
577 VPaned *editor_summary_pane = manage(new VPaned());
578 editor_summary_pane->pack1(edit_packer);
579 editor_summary_pane->pack2(*_summary);
581 edit_pane.pack1 (*editor_summary_pane, true, true);
582 edit_pane.pack2 (the_notebook, false, true);
584 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
586 top_hbox.pack_start (toolbar_frame, false, true);
588 HBox *hbox = manage (new HBox);
589 hbox->pack_start (edit_pane, true, true);
591 global_vpacker.pack_start (top_hbox, false, false);
592 global_vpacker.pack_start (*hbox, true, true);
594 global_hpacker.pack_start (global_vpacker, true, true);
596 set_name ("EditorWindow");
597 add_accel_group (ActionManager::ui_manager->get_accel_group());
599 status_bar_hpacker.show ();
601 vpacker.pack_end (status_bar_hpacker, false, false);
602 vpacker.pack_end (global_hpacker, true, true);
604 /* register actions now so that set_state() can find them and set toggles/checks etc */
608 snap_type = SnapToBeat;
609 set_snap_to (snap_type);
611 set_snap_mode (snap_mode);
612 set_mouse_mode (MouseObject, true);
613 set_edit_point_preference (EditAtMouse, true);
615 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
618 _playlist_selector = new PlaylistSelector();
619 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
621 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
625 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
626 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
628 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
629 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
631 nudge_forward_button.set_name ("TransportButton");
632 nudge_backward_button.set_name ("TransportButton");
634 fade_context_menu.set_name ("ArdourContextMenu");
636 /* icons, titles, WM stuff */
638 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
639 Glib::RefPtr<Gdk::Pixbuf> icon;
641 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
642 window_icons.push_back (icon);
644 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
645 window_icons.push_back (icon);
647 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
648 window_icons.push_back (icon);
650 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
651 window_icons.push_back (icon);
653 if (!window_icons.empty()) {
654 set_icon_list (window_icons);
655 set_default_icon_list (window_icons);
658 WindowTitle title(Glib::get_application_name());
659 title += _("Editor");
660 set_title (title.get_string());
661 set_wmclass (X_("ardour_editor"), "Ardour");
664 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
666 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
667 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
669 /* allow external control surfaces/protocols to do various things */
671 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
672 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
673 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
674 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
675 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
677 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
679 _last_normalization_value = 0;
688 if(image_socket_listener) {
689 if(image_socket_listener->is_connected())
691 image_socket_listener->close_connection() ;
694 delete image_socket_listener ;
695 image_socket_listener = 0 ;
700 delete _route_groups;
706 Editor::add_toplevel_controls (Container& cont)
708 vpacker.pack_start (cont, false, false);
713 Editor::catch_vanishing_regionview (RegionView *rv)
715 /* note: the selection will take care of the vanishing
716 audioregionview by itself.
719 if (_drag && rv->get_canvas_group() == _drag->item() && !_drag->ending()) {
725 if (clicked_regionview == rv) {
726 clicked_regionview = 0;
729 if (entered_regionview == rv) {
730 set_entered_regionview (0);
735 Editor::set_entered_regionview (RegionView* rv)
737 if (rv == entered_regionview) {
741 if (entered_regionview) {
742 entered_regionview->exited ();
745 if ((entered_regionview = rv) != 0) {
746 entered_regionview->entered ();
751 Editor::set_entered_track (TimeAxisView* tav)
754 entered_track->exited ();
757 if ((entered_track = tav) != 0) {
758 entered_track->entered ();
763 Editor::show_window ()
765 if (! is_visible ()) {
768 /* re-hide editor list if necessary */
769 editor_list_button_toggled ();
771 /* re-hide summary widget if necessary */
772 parameter_changed ("show-summary");
774 parameter_changed ("show-edit-group-tabs");
776 /* now reset all audio_time_axis heights, because widgets might need
782 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
783 tv = (static_cast<TimeAxisView*>(*i));
792 Editor::instant_save ()
794 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
799 session->add_instant_xml(get_state());
801 Config->add_instant_xml(get_state());
806 Editor::edit_point_clock_changed()
808 if (_dragging_edit_point) {
812 if (selection->markers.empty()) {
817 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
823 loc->move_to (edit_point_clock.current_time());
827 Editor::zoom_adjustment_changed ()
833 double fpu = zoom_range_clock.current_duration() / _canvas_width;
837 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
838 } else if (fpu > session->current_end_frame() / _canvas_width) {
839 fpu = session->current_end_frame() / _canvas_width;
840 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
847 Editor::control_scroll (float fraction)
849 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
855 double step = fraction * current_page_frames();
858 _control_scroll_target is an optional<T>
860 it acts like a pointer to an nframes64_t, with
861 a operator conversion to boolean to check
862 that it has a value could possibly use
863 playhead_cursor->current_frame to store the
864 value and a boolean in the class to know
865 when it's out of date
868 if (!_control_scroll_target) {
869 _control_scroll_target = session->transport_frame();
870 _dragging_playhead = true;
873 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
874 *_control_scroll_target = 0;
875 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
876 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
878 *_control_scroll_target += (nframes64_t) floor (step);
881 /* move visuals, we'll catch up with it later */
883 playhead_cursor->set_position (*_control_scroll_target);
884 UpdateAllTransportClocks (*_control_scroll_target);
886 if (*_control_scroll_target > (current_page_frames() / 2)) {
887 /* try to center PH in window */
888 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
894 Now we do a timeout to actually bring the session to the right place
895 according to the playhead. This is to avoid reading disk buffers on every
896 call to control_scroll, which is driven by ScrollTimeline and therefore
897 probably by a control surface wheel which can generate lots of events.
899 /* cancel the existing timeout */
901 control_scroll_connection.disconnect ();
903 /* add the next timeout */
905 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
909 Editor::deferred_control_scroll (nframes64_t /*target*/)
911 session->request_locate (*_control_scroll_target, session->transport_rolling());
912 // reset for next stream
913 _control_scroll_target = boost::none;
914 _dragging_playhead = false;
919 Editor::access_action (std::string action_group, std::string action_item)
925 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
928 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
938 Editor::on_realize ()
940 Window::on_realize ();
945 Editor::start_scrolling ()
947 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
948 (mem_fun(*this, &Editor::update_current_screen));
953 Editor::stop_scrolling ()
955 scroll_connection.disconnect ();
959 Editor::map_position_change (nframes64_t frame)
961 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
963 if (session == 0 || !_follow_playhead) {
967 center_screen (frame);
968 playhead_cursor->set_position (frame);
972 Editor::center_screen (nframes64_t frame)
974 double page = _canvas_width * frames_per_unit;
976 /* if we're off the page, then scroll.
979 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
980 center_screen_internal (frame, page);
985 Editor::center_screen_internal (nframes64_t frame, float page)
990 frame -= (nframes64_t) page;
995 reset_x_origin (frame);
999 Editor::handle_new_duration ()
1005 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1006 nframes64_t new_end = session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1008 horizontal_adjustment.set_upper (new_end / frames_per_unit);
1009 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1011 if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
1012 horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
1014 //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
1018 Editor::update_title_s (const string & snap_name)
1020 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1026 Editor::update_title ()
1028 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1031 bool dirty = session->dirty();
1033 string session_name;
1035 if (session->snap_name() != session->name()) {
1036 session_name = session->snap_name();
1038 session_name = session->name();
1042 session_name = "*" + session_name;
1045 WindowTitle title(session_name);
1046 title += Glib::get_application_name();
1047 set_title (title.get_string());
1052 Editor::connect_to_session (Session *t)
1056 compute_fixed_ruler_scale ();
1058 /* there are never any selected regions at startup */
1060 sensitize_the_right_region_actions (false);
1062 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1065 /* catch up with the playhead */
1067 session->request_locate (playhead_cursor->current_frame);
1071 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1072 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1074 /* These signals can all be emitted by a non-GUI thread. Therefore the
1075 handlers for them must not attempt to directly interact with the GUI,
1076 but use Gtkmm2ext::UI::instance()->call_slot();
1079 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1080 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1081 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1082 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1083 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1084 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1085 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1086 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1087 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1089 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1091 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1093 session_connections.push_back (session->Located.connect (mem_fun (*this, &Editor::located)));
1094 session_connections.push_back (session->config.ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed)));
1096 edit_point_clock.set_mode(AudioClock::BBT);
1097 edit_point_clock.set_session (session);
1098 zoom_range_clock.set_session (session);
1099 _playlist_selector->set_session (session);
1100 nudge_clock.set_session (session);
1101 if (Profile->get_sae()) {
1106 nframes_t pos = session->tempo_map().bbt_duration_at (0, bbt, 1);
1107 nudge_clock.set_mode(AudioClock::BBT);
1108 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1111 nudge_clock.set (session->frame_rate() * 5, true, 0, AudioClock::SMPTE); // default of 5 seconds
1114 playhead_cursor->canvas_item.show ();
1116 if (rhythm_ferret) {
1117 rhythm_ferret->set_session (session);
1120 if (analysis_window != 0)
1121 analysis_window->set_session (session);
1123 Location* loc = session->locations()->auto_loop_location();
1125 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1126 if (loc->start() == loc->end()) {
1127 loc->set_end (loc->start() + 1);
1129 session->locations()->add (loc, false);
1130 session->set_auto_loop_location (loc);
1133 loc->set_name (_("Loop"));
1136 loc = session->locations()->auto_punch_location();
1138 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1139 if (loc->start() == loc->end()) {
1140 loc->set_end (loc->start() + 1);
1142 session->locations()->add (loc, false);
1143 session->set_auto_punch_location (loc);
1146 loc->set_name (_("Punch"));
1149 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1150 session->config.map_parameters (mem_fun (*this, &Editor::parameter_changed));
1152 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1154 refresh_location_display ();
1155 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1156 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1157 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1158 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1159 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1162 sfbrowser->set_session (session);
1165 handle_new_duration ();
1167 redisplay_named_selections ();
1169 restore_ruler_visibility ();
1170 //tempo_map_changed (Change (0));
1171 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1173 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1174 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1179 switch (snap_type) {
1180 case SnapToRegionStart:
1181 case SnapToRegionEnd:
1182 case SnapToRegionSync:
1183 case SnapToRegionBoundary:
1184 build_region_boundary_cache ();
1191 /* register for undo history */
1192 session->register_with_memento_command_factory(_id, this);
1194 _summary->connect_to_session (session);
1195 _group_tabs->connect_to_session (session);
1196 _route_groups->connect_to_session (session);
1197 _regions->connect_to_session (session);
1198 _snapshots->connect_to_session (session);
1199 _routes->connect_to_session (session);
1205 Editor::build_cursors ()
1207 using namespace Gdk;
1209 Gdk::Color mbg ("#000000" ); /* Black */
1210 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1213 RefPtr<Bitmap> source, mask;
1214 source = Bitmap::create (mag_bits, mag_width, mag_height);
1215 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1216 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1219 Gdk::Color fbg ("#ffffff" );
1220 Gdk::Color ffg ("#000000" );
1223 RefPtr<Bitmap> source, mask;
1225 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1226 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1227 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1231 RefPtr<Bitmap> source, mask;
1232 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1233 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1234 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1238 RefPtr<Bitmap> bits;
1239 char pix[4] = { 0, 0, 0, 0 };
1240 bits = Bitmap::create (pix, 2, 2);
1242 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1246 RefPtr<Bitmap> bits;
1247 char pix[4] = { 0, 0, 0, 0 };
1248 bits = Bitmap::create (pix, 2, 2);
1250 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1254 grabber_cursor = new Gdk::Cursor (HAND2);
1257 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1258 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1261 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1262 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1263 selector_cursor = new Gdk::Cursor (XTERM);
1264 time_fx_cursor = new Gdk::Cursor (SIZING);
1265 wait_cursor = new Gdk::Cursor (WATCH);
1266 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1267 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1268 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1269 midi_resize_cursor = new Gdk::Cursor (SIZING);
1270 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1273 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1275 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1277 using namespace Menu_Helpers;
1278 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1281 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1285 MenuList& items (fade_context_menu.items());
1289 switch (item_type) {
1291 case FadeInHandleItem:
1292 if (arv->audio_region()->fade_in_active()) {
1293 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1295 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1298 items.push_back (SeparatorElem());
1300 if (Profile->get_sae()) {
1301 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1302 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1304 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1305 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1306 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1307 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1308 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1314 case FadeOutHandleItem:
1315 if (arv->audio_region()->fade_out_active()) {
1316 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1318 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1321 items.push_back (SeparatorElem());
1323 if (Profile->get_sae()) {
1324 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1325 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1327 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1328 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1329 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1330 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1331 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1337 fatal << _("programming error: ")
1338 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1343 fade_context_menu.popup (button, time);
1347 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1349 using namespace Menu_Helpers;
1350 Menu* (Editor::*build_menu_function)(nframes64_t);
1353 switch (item_type) {
1355 case RegionViewName:
1356 case RegionViewNameHighlight:
1357 if (with_selection) {
1358 build_menu_function = &Editor::build_track_selection_context_menu;
1360 build_menu_function = &Editor::build_track_region_context_menu;
1365 if (with_selection) {
1366 build_menu_function = &Editor::build_track_selection_context_menu;
1368 build_menu_function = &Editor::build_track_context_menu;
1372 case CrossfadeViewItem:
1373 build_menu_function = &Editor::build_track_crossfade_context_menu;
1377 if (clicked_routeview->get_diskstream()) {
1378 build_menu_function = &Editor::build_track_context_menu;
1380 build_menu_function = &Editor::build_track_bus_context_menu;
1385 /* probably shouldn't happen but if it does, we don't care */
1389 menu = (this->*build_menu_function)(frame);
1390 menu->set_name ("ArdourContextMenu");
1392 /* now handle specific situations */
1394 switch (item_type) {
1396 case RegionViewName:
1397 case RegionViewNameHighlight:
1398 if (!with_selection) {
1399 if (region_edit_menu_split_item) {
1400 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1401 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1403 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1407 if (region_edit_menu_split_multichannel_item) {
1408 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1409 // GTK2FIX find the action, change its sensitivity
1410 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1412 // GTK2FIX see above
1413 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1422 case CrossfadeViewItem:
1429 /* probably shouldn't happen but if it does, we don't care */
1433 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1435 /* Bounce to disk */
1437 using namespace Menu_Helpers;
1438 MenuList& edit_items = menu->items();
1440 edit_items.push_back (SeparatorElem());
1442 switch (clicked_routeview->audio_track()->freeze_state()) {
1443 case AudioTrack::NoFreeze:
1444 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1447 case AudioTrack::Frozen:
1448 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1451 case AudioTrack::UnFrozen:
1452 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1458 if (item_type == StreamItem && clicked_routeview) {
1459 clicked_routeview->build_underlay_menu(menu);
1462 menu->popup (button, time);
1466 Editor::build_track_context_menu (nframes64_t)
1468 using namespace Menu_Helpers;
1470 MenuList& edit_items = track_context_menu.items();
1473 add_dstream_context_items (edit_items);
1474 return &track_context_menu;
1478 Editor::build_track_bus_context_menu (nframes64_t)
1480 using namespace Menu_Helpers;
1482 MenuList& edit_items = track_context_menu.items();
1485 add_bus_context_items (edit_items);
1486 return &track_context_menu;
1490 Editor::build_track_region_context_menu (nframes64_t frame)
1492 using namespace Menu_Helpers;
1493 MenuList& edit_items = track_region_context_menu.items();
1496 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1499 boost::shared_ptr<Diskstream> ds;
1500 boost::shared_ptr<Playlist> pl;
1502 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1503 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1505 if (selection->regions.size() > 1) {
1506 // there's already a multiple selection: just add a
1507 // single region context menu that will act on all
1509 boost::shared_ptr<Region> dummy_region; // = NULL
1510 add_region_context_items (rtv->view(), dummy_region, edit_items);
1512 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1513 add_region_context_items (rtv->view(), (*i), edit_items);
1521 add_dstream_context_items (edit_items);
1523 return &track_region_context_menu;
1527 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1529 using namespace Menu_Helpers;
1530 MenuList& edit_items = track_crossfade_context_menu.items();
1531 edit_items.clear ();
1533 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1536 boost::shared_ptr<Diskstream> ds;
1537 boost::shared_ptr<Playlist> pl;
1538 boost::shared_ptr<AudioPlaylist> apl;
1540 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1542 Playlist::RegionList* regions = pl->regions_at (frame);
1543 AudioPlaylist::Crossfades xfades;
1545 apl->crossfades_at (frame, xfades);
1547 bool many = xfades.size() > 1;
1549 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1550 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1553 if (selection->regions.size() > 1) {
1554 // there's already a multiple selection: just add a
1555 // single region context menu that will act on all
1557 boost::shared_ptr<Region> dummy_region; // = NULL
1558 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1560 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1561 add_region_context_items (atv->audio_view(), (*i), edit_items);
1568 add_dstream_context_items (edit_items);
1570 return &track_crossfade_context_menu;
1574 Editor::analyze_region_selection()
1576 if (analysis_window == 0) {
1577 analysis_window = new AnalysisWindow();
1580 analysis_window->set_session(session);
1582 analysis_window->show_all();
1585 analysis_window->set_regionmode();
1586 analysis_window->analyze();
1588 analysis_window->present();
1592 Editor::analyze_range_selection()
1594 if (analysis_window == 0) {
1595 analysis_window = new AnalysisWindow();
1598 analysis_window->set_session(session);
1600 analysis_window->show_all();
1603 analysis_window->set_rangemode();
1604 analysis_window->analyze();
1606 analysis_window->present();
1610 Editor::build_track_selection_context_menu (nframes64_t)
1612 using namespace Menu_Helpers;
1613 MenuList& edit_items = track_selection_context_menu.items();
1614 edit_items.clear ();
1616 add_selection_context_items (edit_items);
1617 // edit_items.push_back (SeparatorElem());
1618 // add_dstream_context_items (edit_items);
1620 return &track_selection_context_menu;
1623 /** Add context menu items relevant to crossfades.
1624 * @param edit_items List to add the items to.
1627 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1629 using namespace Menu_Helpers;
1630 Menu *xfade_menu = manage (new Menu);
1631 MenuList& items = xfade_menu->items();
1632 xfade_menu->set_name ("ArdourContextMenu");
1635 if (xfade->active()) {
1641 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1642 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1644 if (xfade->can_follow_overlap()) {
1646 if (xfade->following_overlap()) {
1647 str = _("Convert to short");
1649 str = _("Convert to full");
1652 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1656 str = xfade->out()->name();
1658 str += xfade->in()->name();
1660 str = _("Crossfade");
1663 edit_items.push_back (MenuElem (str, *xfade_menu));
1664 edit_items.push_back (SeparatorElem());
1668 Editor::xfade_edit_left_region ()
1670 if (clicked_crossfadeview) {
1671 clicked_crossfadeview->left_view.show_region_editor ();
1676 Editor::xfade_edit_right_region ()
1678 if (clicked_crossfadeview) {
1679 clicked_crossfadeview->right_view.show_region_editor ();
1684 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1686 using namespace Menu_Helpers;
1687 Gtk::MenuItem* foo_item;
1688 Menu *region_menu = manage (new Menu);
1689 MenuList& items = region_menu->items();
1690 region_menu->set_name ("ArdourContextMenu");
1692 boost::shared_ptr<AudioRegion> ar;
1693 boost::shared_ptr<MidiRegion> mr;
1696 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1697 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1699 /* when this particular menu pops up, make the relevant region
1703 region_menu->signal_map_event().connect (
1704 bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1706 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1707 if (mr && internal_editing()) {
1708 items.push_back (MenuElem (_("Popup list editor"), mem_fun(*this, &Editor::show_midi_list_editor)));
1710 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1714 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1715 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1716 items.push_back (SeparatorElem());
1717 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1718 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1719 items.push_back (SeparatorElem());
1721 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1722 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1723 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1726 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1729 items.push_back (SeparatorElem());
1731 sigc::connection fooc;
1732 boost::shared_ptr<Region> region_to_check;
1735 region_to_check = region;
1737 region_to_check = selection->regions.front()->region();
1740 items.push_back (CheckMenuElem (_("Lock")));
1741 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1742 if (region_to_check->locked()) {
1743 region_lock_item->set_active();
1745 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1747 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1748 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1750 switch (region_to_check->positional_lock_style()) {
1751 case Region::MusicTime:
1752 bbt_glue_item->set_active (true);
1755 bbt_glue_item->set_active (false);
1759 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1761 items.push_back (CheckMenuElem (_("Mute")));
1762 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1763 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1764 if (region_to_check->muted()) {
1766 region_mute_item->set_active();
1770 if (!Profile->get_sae()) {
1771 items.push_back (CheckMenuElem (_("Opaque")));
1772 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1773 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1774 if (region_to_check->opaque()) {
1776 region_opaque_item->set_active();
1781 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1782 if (region_to_check->at_natural_position()) {
1783 items.back().set_sensitive (false);
1786 items.push_back (SeparatorElem());
1790 RegionView* rv = sv->find_view (ar);
1791 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1793 if (!Profile->get_sae()) {
1794 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1796 items.push_back (CheckMenuElem (_("Envelope Visible")));
1797 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1798 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1799 if (arv->envelope_visible()) {
1801 region_envelope_visible_item->set_active (true);
1805 items.push_back (CheckMenuElem (_("Envelope Active")));
1806 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1807 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1809 if (ar->envelope_active()) {
1811 region_envelope_active_item->set_active (true);
1815 items.push_back (SeparatorElem());
1818 if (ar->scale_amplitude() != 1.0f) {
1819 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1821 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1825 items.push_back (MenuElem (_("Quantize"), mem_fun(*this, &Editor::quantize_region)));
1826 items.push_back (SeparatorElem());
1829 items.push_back (MenuElem (_("Strip silence..."), mem_fun (*this, &Editor::strip_region_silence)));
1830 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1831 items.push_back (SeparatorElem());
1833 /* range related stuff */
1835 items.push_back (MenuElem (_("Add Single Range"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1836 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_locations_from_audio_region)));
1837 if (selection->regions.size() < 2) {
1838 items.back().set_sensitive (false);
1841 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
1842 items.push_back (SeparatorElem());
1846 Menu *nudge_menu = manage (new Menu());
1847 MenuList& nudge_items = nudge_menu->items();
1848 nudge_menu->set_name ("ArdourContextMenu");
1850 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1851 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1852 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1853 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1855 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1856 items.push_back (SeparatorElem());
1858 Menu *trim_menu = manage (new Menu);
1859 MenuList& trim_items = trim_menu->items();
1860 trim_menu->set_name ("ArdourContextMenu");
1862 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1863 foo_item = &trim_items.back();
1864 if (_edit_point == EditAtMouse) {
1865 foo_item->set_sensitive (false);
1867 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1868 foo_item = &trim_items.back();
1869 if (_edit_point == EditAtMouse) {
1870 foo_item->set_sensitive (false);
1872 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1873 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1875 items.push_back (MenuElem (_("Trim"), *trim_menu));
1876 items.push_back (SeparatorElem());
1878 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split))));
1879 region_edit_menu_split_item = &items.back();
1881 if (_edit_point == EditAtMouse) {
1882 region_edit_menu_split_item->set_sensitive (false);
1885 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1886 region_edit_menu_split_multichannel_item = &items.back();
1888 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1889 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1890 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1891 items.push_back (SeparatorElem());
1892 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
1894 /* OK, stick the region submenu at the top of the list, and then add
1898 /* we have to hack up the region name because "_" has a special
1899 meaning for menu titles.
1902 string::size_type pos = 0;
1903 string menu_item_name = (region) ? region->name() : _("Selected regions");
1905 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1906 menu_item_name.replace (pos, 1, "__");
1910 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1911 edit_items.push_back (SeparatorElem());
1914 /** Add context menu items relevant to selection ranges.
1915 * @param edit_items List to add the items to.
1918 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1920 using namespace Menu_Helpers;
1922 edit_items.push_back (MenuElem (_("Play Range"), mem_fun(*this, &Editor::play_selection)));
1923 edit_items.push_back (MenuElem (_("Loop Range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
1925 edit_items.push_back (SeparatorElem());
1926 edit_items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
1928 if (!selection->regions.empty()) {
1929 edit_items.push_back (SeparatorElem());
1930 edit_items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1931 edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1934 edit_items.push_back (SeparatorElem());
1935 edit_items.push_back (MenuElem (_("Silence Range"), mem_fun(*this, &Editor::separate_region_from_selection)));
1936 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), mem_fun(*this, &Editor::new_region_from_selection)));
1938 edit_items.push_back (SeparatorElem());
1939 edit_items.push_back (MenuElem (_("Select All in Range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1941 edit_items.push_back (SeparatorElem());
1942 edit_items.push_back (MenuElem (_("Set Loop from Range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
1943 edit_items.push_back (MenuElem (_("Set Punch from Range"), mem_fun(*this, &Editor::set_punch_from_selection)));
1945 edit_items.push_back (SeparatorElem());
1946 edit_items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
1948 edit_items.push_back (SeparatorElem());
1949 edit_items.push_back (MenuElem (_("Crop Region to Range"), mem_fun(*this, &Editor::crop_region_to_selection)));
1950 edit_items.push_back (MenuElem (_("Fill Range with Region"), mem_fun(*this, &Editor::region_fill_selection)));
1951 edit_items.push_back (MenuElem (_("Duplicate Range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
1952 edit_items.push_back (MenuElem (_("Create Chunk from Range"), mem_fun(*this, &Editor::create_named_selection)));
1954 edit_items.push_back (SeparatorElem());
1955 edit_items.push_back (MenuElem (_("Consolidate Range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1956 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1957 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1958 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1959 edit_items.push_back (MenuElem (_("Export Range"), mem_fun(*this, &Editor::export_range)));
1964 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1966 using namespace Menu_Helpers;
1970 Menu *play_menu = manage (new Menu);
1971 MenuList& play_items = play_menu->items();
1972 play_menu->set_name ("ArdourContextMenu");
1974 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
1975 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
1976 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
1977 play_items.push_back (SeparatorElem());
1978 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
1980 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1984 Menu *select_menu = manage (new Menu);
1985 MenuList& select_items = select_menu->items();
1986 select_menu->set_name ("ArdourContextMenu");
1988 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1989 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
1990 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
1991 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
1992 select_items.push_back (SeparatorElem());
1993 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
1994 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
1995 select_items.push_back (SeparatorElem());
1996 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1997 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1998 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1999 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2000 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2001 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2002 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2004 select_items.push_back (SeparatorElem());
2006 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2010 Menu *cutnpaste_menu = manage (new Menu);
2011 MenuList& cutnpaste_items = cutnpaste_menu->items();
2012 cutnpaste_menu->set_name ("ArdourContextMenu");
2014 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2015 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2016 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2018 cutnpaste_items.push_back (SeparatorElem());
2020 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2021 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2023 cutnpaste_items.push_back (SeparatorElem());
2025 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2027 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2029 /* Adding new material */
2031 edit_items.push_back (SeparatorElem());
2032 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2033 edit_items.push_back (MenuElem (_("Insert Existing Media"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2037 Menu *nudge_menu = manage (new Menu());
2038 MenuList& nudge_items = nudge_menu->items();
2039 nudge_menu->set_name ("ArdourContextMenu");
2041 edit_items.push_back (SeparatorElem());
2042 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2043 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2044 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2045 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2047 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2051 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2053 using namespace Menu_Helpers;
2057 Menu *play_menu = manage (new Menu);
2058 MenuList& play_items = play_menu->items();
2059 play_menu->set_name ("ArdourContextMenu");
2061 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2062 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2063 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2067 Menu *select_menu = manage (new Menu);
2068 MenuList& select_items = select_menu->items();
2069 select_menu->set_name ("ArdourContextMenu");
2071 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2072 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2073 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2074 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2075 select_items.push_back (SeparatorElem());
2076 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2077 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2078 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2079 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2081 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2085 Menu *cutnpaste_menu = manage (new Menu);
2086 MenuList& cutnpaste_items = cutnpaste_menu->items();
2087 cutnpaste_menu->set_name ("ArdourContextMenu");
2089 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2090 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2091 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2093 Menu *nudge_menu = manage (new Menu());
2094 MenuList& nudge_items = nudge_menu->items();
2095 nudge_menu->set_name ("ArdourContextMenu");
2097 edit_items.push_back (SeparatorElem());
2098 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2099 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2100 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2101 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2103 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2107 Editor::set_snap_to (SnapType st)
2109 unsigned int snap_ind = (unsigned int)st;
2113 if (snap_ind > snap_type_strings.size() - 1) {
2115 snap_type = (SnapType)snap_ind;
2118 string str = snap_type_strings[snap_ind];
2120 if (str != snap_type_selector.get_active_text()) {
2121 snap_type_selector.set_active_text (str);
2126 switch (snap_type) {
2127 case SnapToAThirtysecondBeat:
2128 case SnapToASixteenthBeat:
2129 case SnapToAEighthBeat:
2130 case SnapToAQuarterBeat:
2131 case SnapToAThirdBeat:
2132 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2133 update_tempo_based_rulers ();
2136 case SnapToRegionStart:
2137 case SnapToRegionEnd:
2138 case SnapToRegionSync:
2139 case SnapToRegionBoundary:
2140 build_region_boundary_cache ();
2150 Editor::set_snap_mode (SnapMode mode)
2153 string str = snap_mode_strings[(int)mode];
2155 if (str != snap_mode_selector.get_active_text ()) {
2156 snap_mode_selector.set_active_text (str);
2162 Editor::set_edit_point_preference (EditPoint ep, bool force)
2164 bool changed = (_edit_point != ep);
2167 string str = edit_point_strings[(int)ep];
2169 if (str != edit_point_selector.get_active_text ()) {
2170 edit_point_selector.set_active_text (str);
2173 set_canvas_cursor ();
2175 if (!force && !changed) {
2179 switch (zoom_focus) {
2180 case ZoomFocusMouse:
2181 case ZoomFocusPlayhead:
2183 switch (_edit_point) {
2185 set_zoom_focus (ZoomFocusMouse);
2187 case EditAtPlayhead:
2188 set_zoom_focus (ZoomFocusPlayhead);
2190 case EditAtSelectedMarker:
2191 set_zoom_focus (ZoomFocusEdit);
2199 const char* action=NULL;
2201 switch (_edit_point) {
2202 case EditAtPlayhead:
2203 action = "edit-at-playhead";
2205 case EditAtSelectedMarker:
2206 action = "edit-at-marker";
2209 action = "edit-at-mouse";
2213 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2215 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2219 bool in_track_canvas;
2221 if (!mouse_frame (foo, in_track_canvas)) {
2222 in_track_canvas = false;
2225 reset_canvas_action_sensitivity (in_track_canvas);
2231 Editor::set_state (const XMLNode& node)
2233 const XMLProperty* prop;
2235 int x, y, xoff, yoff;
2238 if ((prop = node.property ("id")) != 0) {
2239 _id = prop->value ();
2242 g.base_width = default_width;
2243 g.base_height = default_height;
2249 if ((geometry = find_named_node (node, "geometry")) != 0) {
2253 if ((prop = geometry->property("x_size")) == 0) {
2254 prop = geometry->property ("x-size");
2257 g.base_width = atoi(prop->value());
2259 if ((prop = geometry->property("y_size")) == 0) {
2260 prop = geometry->property ("y-size");
2263 g.base_height = atoi(prop->value());
2266 if ((prop = geometry->property ("x_pos")) == 0) {
2267 prop = geometry->property ("x-pos");
2270 x = atoi (prop->value());
2273 if ((prop = geometry->property ("y_pos")) == 0) {
2274 prop = geometry->property ("y-pos");
2277 y = atoi (prop->value());
2280 if ((prop = geometry->property ("x_off")) == 0) {
2281 prop = geometry->property ("x-off");
2284 xoff = atoi (prop->value());
2286 if ((prop = geometry->property ("y_off")) == 0) {
2287 prop = geometry->property ("y-off");
2290 yoff = atoi (prop->value());
2294 set_default_size (g.base_width, g.base_height);
2297 if (session && (prop = node.property ("playhead"))) {
2298 nframes64_t pos = atol (prop->value().c_str());
2299 playhead_cursor->set_position (pos);
2301 playhead_cursor->set_position (0);
2303 /* reset_x_origin() doesn't work right here, since the old
2304 position may be zero already, and it does nothing in such
2309 horizontal_adjustment.set_value (0);
2312 if ((prop = node.property ("mixer-width"))) {
2313 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2316 if ((prop = node.property ("zoom-focus"))) {
2317 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2320 if ((prop = node.property ("zoom"))) {
2321 reset_zoom (PBD::atof (prop->value()));
2324 if ((prop = node.property ("snap-to"))) {
2325 set_snap_to ((SnapType) atoi (prop->value()));
2328 if ((prop = node.property ("snap-mode"))) {
2329 set_snap_mode ((SnapMode) atoi (prop->value()));
2332 if ((prop = node.property ("mouse-mode"))) {
2333 MouseMode m = str2mousemode(prop->value());
2334 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2335 set_mouse_mode (m, true);
2337 mouse_mode = MouseGain; /* lie, to force the mode switch */
2338 set_mouse_mode (MouseObject, true);
2341 if ((prop = node.property ("edit-point"))) {
2342 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2345 if ((prop = node.property ("show-waveforms-recording"))) {
2346 bool yn = (prop->value() == "yes");
2347 _show_waveforms_recording = !yn;
2348 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2350 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2351 /* do it twice to force the change */
2352 tact->set_active (!yn);
2353 tact->set_active (yn);
2357 if ((prop = node.property ("show-measures"))) {
2358 bool yn = (prop->value() == "yes");
2359 _show_measures = !yn;
2360 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2362 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2363 /* do it twice to force the change */
2364 tact->set_active (!yn);
2365 tact->set_active (yn);
2369 if ((prop = node.property ("follow-playhead"))) {
2370 bool yn = (prop->value() == "yes");
2371 set_follow_playhead (yn);
2372 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2374 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2375 if (tact->get_active() != yn) {
2376 tact->set_active (yn);
2381 if ((prop = node.property ("region-list-sort-type"))) {
2382 _regions->reset_sort_type (str2regionlistsorttype(prop->value()), true);
2385 if ((prop = node.property ("xfades-visible"))) {
2386 bool yn = (prop->value() == "yes");
2387 _xfade_visibility = !yn;
2388 // set_xfade_visibility (yn);
2391 if ((prop = node.property ("show-editor-mixer"))) {
2393 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2396 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2397 bool yn = (prop->value() == X_("yes"));
2399 /* do it twice to force the change */
2401 tact->set_active (!yn);
2402 tact->set_active (yn);
2406 if ((prop = node.property ("show-editor-list"))) {
2408 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2412 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2413 bool yn = (prop->value() == X_("yes"));
2415 /* do it twice to force the change */
2417 tact->set_active (!yn);
2418 tact->set_active (yn);
2427 Editor::get_state ()
2429 XMLNode* node = new XMLNode ("Editor");
2432 _id.print (buf, sizeof (buf));
2433 node->add_property ("id", buf);
2435 if (is_realized()) {
2436 Glib::RefPtr<Gdk::Window> win = get_window();
2438 int x, y, xoff, yoff, width, height;
2439 win->get_root_origin(x, y);
2440 win->get_position(xoff, yoff);
2441 win->get_size(width, height);
2443 XMLNode* geometry = new XMLNode ("geometry");
2445 snprintf(buf, sizeof(buf), "%d", width);
2446 geometry->add_property("x-size", string(buf));
2447 snprintf(buf, sizeof(buf), "%d", height);
2448 geometry->add_property("y-size", string(buf));
2449 snprintf(buf, sizeof(buf), "%d", x);
2450 geometry->add_property("x-pos", string(buf));
2451 snprintf(buf, sizeof(buf), "%d", y);
2452 geometry->add_property("y-pos", string(buf));
2453 snprintf(buf, sizeof(buf), "%d", xoff);
2454 geometry->add_property("x-off", string(buf));
2455 snprintf(buf, sizeof(buf), "%d", yoff);
2456 geometry->add_property("y-off", string(buf));
2457 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2458 geometry->add_property("edit_pane_pos", string(buf));
2460 node->add_child_nocopy (*geometry);
2463 maybe_add_mixer_strip_width (*node);
2465 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2466 node->add_property ("zoom-focus", buf);
2467 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2468 node->add_property ("zoom", buf);
2469 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2470 node->add_property ("snap-to", buf);
2471 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2472 node->add_property ("snap-mode", buf);
2474 node->add_property ("edit-point", enum_2_string (_edit_point));
2476 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2477 node->add_property ("playhead", buf);
2479 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2480 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2481 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2482 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2483 node->add_property ("region-list-sort-type", enum2str (_regions->sort_type ()));
2484 node->add_property ("mouse-mode", enum2str(mouse_mode));
2486 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2488 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2489 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2492 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2494 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2495 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2503 /** @param y y offset from the top of all trackviews.
2504 * @return pair: TimeAxisView that y is over, layer index.
2505 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2506 * in stacked region display mode, otherwise 0.
2508 std::pair<TimeAxisView *, layer_t>
2509 Editor::trackview_by_y_position (double y)
2511 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2513 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2519 return std::make_pair ( (TimeAxisView *) 0, 0);
2522 /** Snap a position to the grid, if appropriate, taking into account current
2523 * grid settings and also the state of any snap modifier keys that may be pressed.
2524 * @param start Position to snap.
2525 * @param event Event to get current key modifier information from.
2528 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2534 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2535 if (snap_mode == SnapOff) {
2536 snap_to_internal (start, direction, for_mark);
2539 if (snap_mode != SnapOff) {
2540 snap_to_internal (start, direction, for_mark);
2546 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2548 if (!session || snap_mode == SnapOff) {
2552 snap_to_internal (start, direction, for_mark);
2556 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2558 Location* before = 0;
2559 Location* after = 0;
2561 const nframes64_t one_second = session->frame_rate();
2562 const nframes64_t one_minute = session->frame_rate() * 60;
2563 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2564 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2565 nframes64_t presnap = start;
2567 switch (snap_type) {
2569 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2570 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2572 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2576 case SnapToSMPTEFrame:
2577 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2578 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2580 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2584 case SnapToSMPTESeconds:
2585 if (session->smpte_offset_negative())
2587 start += session->smpte_offset ();
2589 start -= session->smpte_offset ();
2591 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2592 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2594 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2597 if (session->smpte_offset_negative())
2599 start -= session->smpte_offset ();
2601 start += session->smpte_offset ();
2605 case SnapToSMPTEMinutes:
2606 if (session->smpte_offset_negative())
2608 start += session->smpte_offset ();
2610 start -= session->smpte_offset ();
2612 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2613 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2615 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2617 if (session->smpte_offset_negative())
2619 start -= session->smpte_offset ();
2621 start += session->smpte_offset ();
2626 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2627 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2629 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2634 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2635 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2637 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2642 start = session->tempo_map().round_to_bar (start, direction);
2646 start = session->tempo_map().round_to_beat (start, direction);
2649 case SnapToAThirtysecondBeat:
2650 start = session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2653 case SnapToASixteenthBeat:
2654 start = session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2657 case SnapToAEighthBeat:
2658 start = session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2661 case SnapToAQuarterBeat:
2662 start = session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2665 case SnapToAThirdBeat:
2666 start = session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2674 before = session->locations()->first_location_before (start);
2675 after = session->locations()->first_location_after (start);
2677 if (direction < 0) {
2679 start = before->start();
2683 } else if (direction > 0) {
2685 start = after->start();
2687 start = session->current_end_frame();
2692 /* find nearest of the two */
2693 if ((start - before->start()) < (after->start() - start)) {
2694 start = before->start();
2696 start = after->start();
2699 start = before->start();
2702 start = after->start();
2709 case SnapToRegionStart:
2710 case SnapToRegionEnd:
2711 case SnapToRegionSync:
2712 case SnapToRegionBoundary:
2713 if (!region_boundary_cache.empty()) {
2715 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2716 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2718 if (direction > 0) {
2719 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2721 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2724 if (next != region_boundary_cache.begin ()) {
2729 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2730 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2732 if (start > (p + n) / 2) {
2741 switch (snap_mode) {
2747 if (presnap > start) {
2748 if (presnap > (start + unit_to_frame(snap_threshold))) {
2752 } else if (presnap < start) {
2753 if (presnap < (start - unit_to_frame(snap_threshold))) {
2759 /* handled at entry */
2767 Editor::setup_toolbar ()
2771 /* Mode Buttons (tool selection) */
2773 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2774 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2775 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2776 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2777 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2778 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2779 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2781 HBox* mode_box = manage(new HBox);
2782 mode_box->set_border_width (2);
2783 mode_box->set_spacing(4);
2784 mouse_mode_button_box.set_spacing(1);
2785 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2786 if (!Profile->get_sae()) {
2787 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2789 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2790 if (!Profile->get_sae()) {
2791 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2793 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2794 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2795 mouse_mode_button_box.pack_start(internal_edit_button, true, true);
2796 mouse_mode_button_box.set_homogeneous(true);
2798 vector<string> edit_mode_strings;
2799 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2800 if (!Profile->get_sae()) {
2801 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2803 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2805 edit_mode_selector.set_name ("EditModeSelector");
2806 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2807 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2809 mode_box->pack_start(edit_mode_selector);
2810 mode_box->pack_start(mouse_mode_button_box);
2812 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2813 mouse_mode_tearoff->set_name ("MouseModeBase");
2814 mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (bind (sigc::ptr_fun (relay_key_press), &mouse_mode_tearoff->tearoff_window()), false);
2816 if (Profile->get_sae()) {
2817 mouse_mode_tearoff->set_can_be_torn_off (false);
2820 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2821 &mouse_mode_tearoff->tearoff_window()));
2822 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2823 &mouse_mode_tearoff->tearoff_window(), 1));
2824 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2825 &mouse_mode_tearoff->tearoff_window()));
2826 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2827 &mouse_mode_tearoff->tearoff_window(), 1));
2829 mouse_move_button.set_mode (false);
2830 mouse_select_button.set_mode (false);
2831 mouse_gain_button.set_mode (false);
2832 mouse_zoom_button.set_mode (false);
2833 mouse_timefx_button.set_mode (false);
2834 mouse_audition_button.set_mode (false);
2836 mouse_move_button.set_name ("MouseModeButton");
2837 mouse_select_button.set_name ("MouseModeButton");
2838 mouse_gain_button.set_name ("MouseModeButton");
2839 mouse_zoom_button.set_name ("MouseModeButton");
2840 mouse_timefx_button.set_name ("MouseModeButton");
2841 mouse_audition_button.set_name ("MouseModeButton");
2843 internal_edit_button.set_name ("MouseModeButton");
2845 mouse_move_button.unset_flags (CAN_FOCUS);
2846 mouse_select_button.unset_flags (CAN_FOCUS);
2847 mouse_gain_button.unset_flags (CAN_FOCUS);
2848 mouse_zoom_button.unset_flags (CAN_FOCUS);
2849 mouse_timefx_button.unset_flags (CAN_FOCUS);
2850 mouse_audition_button.unset_flags (CAN_FOCUS);
2851 internal_edit_button.unset_flags (CAN_FOCUS);
2855 zoom_box.set_spacing (1);
2856 zoom_box.set_border_width (0);
2858 zoom_in_button.set_name ("EditorTimeButton");
2859 zoom_in_button.set_size_request(-1,16);
2860 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2861 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2862 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2864 zoom_out_button.set_name ("EditorTimeButton");
2865 zoom_out_button.set_size_request(-1,16);
2866 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2867 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2868 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2870 zoom_out_full_button.set_name ("EditorTimeButton");
2871 zoom_out_full_button.set_size_request(-1,16);
2872 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2873 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2874 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2876 zoom_focus_selector.set_name ("ZoomFocusSelector");
2877 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2878 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2879 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2881 zoom_box.pack_start (zoom_out_button, false, false);
2882 zoom_box.pack_start (zoom_in_button, false, false);
2883 zoom_box.pack_start (zoom_out_full_button, false, false);
2885 /* Track zoom buttons */
2886 tav_expand_button.set_name ("TrackHeightButton");
2887 tav_expand_button.set_size_request(-1,20);
2888 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2889 tav_expand_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::tav_zoom_step), true));
2890 ARDOUR_UI::instance()->tooltips().set_tip (tav_expand_button, _("Expand Tracks"));
2892 tav_shrink_button.set_name ("TrackHeightButton");
2893 tav_shrink_button.set_size_request(-1,20);
2894 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2895 tav_shrink_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::tav_zoom_step), false));
2896 ARDOUR_UI::instance()->tooltips().set_tip (tav_shrink_button, _("Shrink Tracks"));
2898 track_zoom_box.set_spacing (1);
2899 track_zoom_box.set_border_width (0);
2901 track_zoom_box.pack_start (tav_shrink_button, false, false);
2902 track_zoom_box.pack_start (tav_expand_button, false, false);
2904 HBox* zbc = manage (new HBox);
2905 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2906 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2907 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2908 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2910 snap_box.set_spacing (1);
2911 snap_box.set_border_width (2);
2913 snap_type_selector.set_name ("SnapTypeSelector");
2914 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2915 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2916 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2918 snap_mode_selector.set_name ("SnapModeSelector");
2919 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2920 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2921 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2923 edit_point_selector.set_name ("EditPointSelector");
2924 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2925 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2926 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2928 snap_box.pack_start (edit_point_clock, false, false);
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 (mem_fun(*this, &Editor::nudge_forward_release), false);
2940 nudge_backward_button.signal_button_release_event().connect (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 (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 (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2961 &tools_tearoff->tearoff_window()));
2962 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2963 &tools_tearoff->tearoff_window(), 0));
2964 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2965 &tools_tearoff->tearoff_window()));
2966 tools_tearoff->Visible.connect (bind (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::midi_panic_button_pressed ()
2993 session->midi_panic();
2998 Editor::setup_midi_toolbar ()
3001 midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
3002 midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
3003 midi_tool_buttons.push_back (&midi_tool_pencil_button);
3004 midi_tool_select_button.add (*(manage (new Image (::get_icon("midi_tool_select")))));
3005 midi_tool_select_button.set_relief(Gtk::RELIEF_NONE);
3006 midi_tool_buttons.push_back (&midi_tool_select_button);
3007 midi_tool_resize_button.add (*(manage (new Image (::get_icon("strip_width")))));
3008 midi_tool_resize_button.set_relief(Gtk::RELIEF_NONE);
3009 midi_tool_buttons.push_back (&midi_tool_resize_button);
3010 midi_tool_erase_button.add (*(manage (new Image (::get_icon("midi_tool_erase")))));
3011 midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
3012 midi_tool_buttons.push_back (&midi_tool_erase_button);
3014 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
3015 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
3016 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
3017 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
3020 /* Midi sound notes */
3021 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3022 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3023 ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes"));
3024 midi_sound_notes.unset_flags (CAN_FOCUS);
3028 midi_panic_button.set_name("MidiPanicButton");
3029 midi_panic_button.signal_pressed().connect (mem_fun(this, &Editor::midi_panic_button_pressed));
3031 panic_box.pack_start (midi_sound_notes , true, true);
3032 panic_box.pack_start (midi_panic_button, true, true);
3036 Editor::convert_drop_to_paths (
3037 vector<ustring>& paths,
3038 const RefPtr<Gdk::DragContext>& /*context*/,
3041 const SelectionData& data,
3049 vector<ustring> uris = data.get_uris();
3053 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3054 are actually URI lists. So do it by hand.
3057 if (data.get_target() != "text/plain") {
3061 /* Parse the "uri-list" format that Nautilus provides,
3062 where each pathname is delimited by \r\n.
3064 THERE MAY BE NO NULL TERMINATING CHAR!!!
3067 ustring txt = data.get_text();
3071 p = (const char *) malloc (txt.length() + 1);
3072 txt.copy ((char *) p, txt.length(), 0);
3073 ((char*)p)[txt.length()] = '\0';
3079 while (g_ascii_isspace (*p))
3083 while (*q && (*q != '\n') && (*q != '\r')) {
3090 while (q > p && g_ascii_isspace (*q))
3095 uris.push_back (ustring (p, q - p + 1));
3099 p = strchr (p, '\n');
3111 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3113 if ((*i).substr (0,7) == "file://") {
3116 PBD::url_decode (p);
3118 // scan forward past three slashes
3120 ustring::size_type slashcnt = 0;
3121 ustring::size_type n = 0;
3122 ustring::iterator x = p.begin();
3124 while (slashcnt < 3 && x != p.end()) {
3127 } else if (slashcnt == 3) {
3134 if (slashcnt != 3 || x == p.end()) {
3135 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3139 paths.push_back (p.substr (n - 1));
3147 Editor::new_tempo_section ()
3153 Editor::map_transport_state ()
3155 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3157 if (session->transport_stopped()) {
3158 have_pending_keyboard_selection = false;
3161 update_loop_range_view (true);
3166 Editor::State::State (PublicEditor const * e)
3168 selection = new Selection (e);
3171 Editor::State::~State ()
3177 Editor::store_state (State& state) const
3179 *state.selection = *selection;
3183 Editor::restore_state (State *state)
3185 if (*selection == *state->selection) {
3189 *selection = *state->selection;
3190 time_selection_changed ();
3191 region_selection_changed ();
3193 /* XXX other selection change handlers? */
3197 Editor::begin_reversible_command (string name)
3200 before = &get_state();
3201 session->begin_reversible_command (name);
3206 Editor::commit_reversible_command ()
3209 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3214 Editor::set_route_group_solo (Route& route, bool yn)
3216 RouteGroup *route_group;
3218 if ((route_group = route.route_group()) != 0) {
3219 route_group->apply (&Route::set_solo, yn, this);
3221 route.set_solo (yn, this);
3226 Editor::set_route_group_mute (Route& route, bool yn)
3228 RouteGroup *route_group = 0;
3230 if ((route_group == route.route_group()) != 0) {
3231 route_group->apply (&Route::set_mute, yn, this);
3233 route.set_mute (yn, this);
3238 Editor::history_changed ()
3242 if (undo_action && session) {
3243 if (session->undo_depth() == 0) {
3246 label = string_compose(_("Undo (%1)"), session->next_undo());
3248 undo_action->property_label() = label;
3251 if (redo_action && session) {
3252 if (session->redo_depth() == 0) {
3255 label = string_compose(_("Redo (%1)"), session->next_redo());
3257 redo_action->property_label() = label;
3262 Editor::duplicate_dialog (bool with_dialog)
3266 if (mouse_mode == MouseRange) {
3267 if (selection->time.length() == 0) {
3273 get_regions_for_action (rs);
3275 if (mouse_mode != MouseRange) {
3284 ArdourDialog win ("Duplication Dialog");
3285 Label label (_("Number of Duplications:"));
3286 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3287 SpinButton spinner (adjustment, 0.0, 1);
3290 win.get_vbox()->set_spacing (12);
3291 win.get_vbox()->pack_start (hbox);
3292 hbox.set_border_width (6);
3293 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3295 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3296 place, visually. so do this by hand.
3299 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3300 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3301 spinner.grab_focus();
3307 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3308 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3309 win.set_default_response (RESPONSE_ACCEPT);
3311 win.set_position (WIN_POS_MOUSE);
3313 spinner.grab_focus ();
3315 switch (win.run ()) {
3316 case RESPONSE_ACCEPT:
3322 times = adjustment.get_value();
3325 if (mouse_mode == MouseRange) {
3326 duplicate_selection (times);
3328 duplicate_some_regions (rs, times);
3333 Editor::show_verbose_canvas_cursor ()
3335 verbose_canvas_cursor->raise_to_top();
3336 verbose_canvas_cursor->show();
3337 verbose_cursor_visible = true;
3341 Editor::hide_verbose_canvas_cursor ()
3343 verbose_canvas_cursor->hide();
3344 verbose_cursor_visible = false;
3348 Editor::clamp_verbose_cursor_x (double x)
3353 x = min (_canvas_width - 200.0, x);
3359 Editor::clamp_verbose_cursor_y (double y)
3361 if (y < canvas_timebars_vsize) {
3362 y = canvas_timebars_vsize;
3364 y = min (_canvas_height - 50, y);
3370 Editor::show_verbose_canvas_cursor_with (const string & txt)
3372 verbose_canvas_cursor->property_text() = txt.c_str();
3377 track_canvas->get_pointer (x, y);
3378 track_canvas->window_to_world (x, y, wx, wy);
3380 /* move it away from the mouse pointer to avoid an
3381 infinite loop of enter/leave events.
3387 /* don't get too close to the edge */
3388 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3389 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3391 show_verbose_canvas_cursor ();
3395 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3397 verbose_canvas_cursor->property_text() = txt.c_str();
3398 /* don't get too close to the edge */
3399 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3400 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3404 Editor::set_verbose_canvas_cursor_text (const string & txt)
3406 verbose_canvas_cursor->property_text() = txt.c_str();
3410 Editor::set_edit_mode (EditMode m)
3412 Config->set_edit_mode (m);
3416 Editor::cycle_edit_mode ()
3418 switch (Config->get_edit_mode()) {
3420 if (Profile->get_sae()) {
3421 Config->set_edit_mode (Lock);
3423 Config->set_edit_mode (Splice);
3427 Config->set_edit_mode (Lock);
3430 Config->set_edit_mode (Slide);
3436 Editor::edit_mode_selection_done ()
3442 string choice = edit_mode_selector.get_active_text();
3443 EditMode mode = Slide;
3445 if (choice == _("Splice Edit")) {
3447 } else if (choice == _("Slide Edit")) {
3449 } else if (choice == _("Lock Edit")) {
3453 Config->set_edit_mode (mode);
3457 Editor::snap_type_selection_done ()
3459 string choice = snap_type_selector.get_active_text();
3460 SnapType snaptype = SnapToBeat;
3462 if (choice == _("Beats/3")) {
3463 snaptype = SnapToAThirdBeat;
3464 } else if (choice == _("Beats/4")) {
3465 snaptype = SnapToAQuarterBeat;
3466 } else if (choice == _("Beats/8")) {
3467 snaptype = SnapToAEighthBeat;
3468 } else if (choice == _("Beats/16")) {
3469 snaptype = SnapToASixteenthBeat;
3470 } else if (choice == _("Beats/32")) {
3471 snaptype = SnapToAThirtysecondBeat;
3472 } else if (choice == _("Beats")) {
3473 snaptype = SnapToBeat;
3474 } else if (choice == _("Bars")) {
3475 snaptype = SnapToBar;
3476 } else if (choice == _("Marks")) {
3477 snaptype = SnapToMark;
3478 } else if (choice == _("Region starts")) {
3479 snaptype = SnapToRegionStart;
3480 } else if (choice == _("Region ends")) {
3481 snaptype = SnapToRegionEnd;
3482 } else if (choice == _("Region bounds")) {
3483 snaptype = SnapToRegionBoundary;
3484 } else if (choice == _("Region syncs")) {
3485 snaptype = SnapToRegionSync;
3486 } else if (choice == _("CD Frames")) {
3487 snaptype = SnapToCDFrame;
3488 } else if (choice == _("SMPTE Frames")) {
3489 snaptype = SnapToSMPTEFrame;
3490 } else if (choice == _("SMPTE Seconds")) {
3491 snaptype = SnapToSMPTESeconds;
3492 } else if (choice == _("SMPTE Minutes")) {
3493 snaptype = SnapToSMPTEMinutes;
3494 } else if (choice == _("Seconds")) {
3495 snaptype = SnapToSeconds;
3496 } else if (choice == _("Minutes")) {
3497 snaptype = SnapToMinutes;
3500 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3502 ract->set_active ();
3507 Editor::snap_mode_selection_done ()
3509 string choice = snap_mode_selector.get_active_text();
3510 SnapMode mode = SnapNormal;
3512 if (choice == _("No Grid")) {
3514 } else if (choice == _("Grid")) {
3516 } else if (choice == _("Magnetic")) {
3517 mode = SnapMagnetic;
3520 RefPtr<RadioAction> ract = snap_mode_action (mode);
3523 ract->set_active (true);
3528 Editor::cycle_edit_point (bool with_marker)
3530 switch (_edit_point) {
3532 set_edit_point_preference (EditAtPlayhead);
3534 case EditAtPlayhead:
3536 set_edit_point_preference (EditAtSelectedMarker);
3538 set_edit_point_preference (EditAtMouse);
3541 case EditAtSelectedMarker:
3542 set_edit_point_preference (EditAtMouse);
3548 Editor::edit_point_selection_done ()
3550 string choice = edit_point_selector.get_active_text();
3551 EditPoint ep = EditAtSelectedMarker;
3553 if (choice == _("Marker")) {
3554 set_edit_point_preference (EditAtSelectedMarker);
3555 } else if (choice == _("Playhead")) {
3556 set_edit_point_preference (EditAtPlayhead);
3558 set_edit_point_preference (EditAtMouse);
3561 RefPtr<RadioAction> ract = edit_point_action (ep);
3564 ract->set_active (true);
3569 Editor::zoom_focus_selection_done ()
3571 string choice = zoom_focus_selector.get_active_text();
3572 ZoomFocus focus_type = ZoomFocusLeft;
3574 if (choice == _("Left")) {
3575 focus_type = ZoomFocusLeft;
3576 } else if (choice == _("Right")) {
3577 focus_type = ZoomFocusRight;
3578 } else if (choice == _("Center")) {
3579 focus_type = ZoomFocusCenter;
3580 } else if (choice == _("Play")) {
3581 focus_type = ZoomFocusPlayhead;
3582 } else if (choice == _("Edit")) {
3583 focus_type = ZoomFocusEdit;
3584 } else if (choice == _("Active Mark")) {
3585 focus_type = ZoomFocusEdit;
3586 } else if (choice == _("Active Mark")) {
3587 focus_type = ZoomFocusEdit;
3589 focus_type = ZoomFocusMouse;
3592 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3595 ract->set_active ();
3600 Editor::edit_controls_button_release (GdkEventButton* ev)
3602 if (Keyboard::is_context_menu_event (ev)) {
3603 ARDOUR_UI::instance()->add_route (this);
3609 Editor::mouse_select_button_release (GdkEventButton* ev)
3611 /* this handles just right-clicks */
3613 if (ev->button != 3) {
3620 Editor::TrackViewList *
3621 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3623 TrackViewList::iterator i;
3625 TrackViewList* v = new TrackViewList;
3627 if (track == 0 && group == 0) {
3631 for (i = track_views.begin(); i != track_views.end (); ++i) {
3635 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->active_property (RouteGroup::Select))) {
3637 /* just the view for this track
3640 v->push_back (track);
3644 /* views for all tracks in the route group */
3646 for (i = track_views.begin(); i != track_views.end (); ++i) {
3648 if (group == 0 || ((*i)->route_group() == group && group->active_property (RouteGroup::Select))) {
3658 Editor::set_zoom_focus (ZoomFocus f)
3660 string str = zoom_focus_strings[(int)f];
3662 if (str != zoom_focus_selector.get_active_text()) {
3663 zoom_focus_selector.set_active_text (str);
3666 if (zoom_focus != f) {
3669 ZoomFocusChanged (); /* EMIT_SIGNAL */
3676 Editor::ensure_float (Window& win)
3678 win.set_transient_for (*this);
3682 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3684 /* recover or initialize pane positions. do this here rather than earlier because
3685 we don't want the positions to change the child allocations, which they seem to do.
3691 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3693 static int32_t done;
3696 width = default_width;
3697 height = default_height;
3699 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3701 if ((prop = geometry->property ("x_size")) == 0) {
3702 prop = geometry->property ("x-size");
3705 width = atoi (prop->value());
3707 if ((prop = geometry->property ("y_size")) == 0) {
3708 prop = geometry->property ("y-size");
3711 height = atoi (prop->value());
3715 if (which == static_cast<Paned*> (&edit_pane)) {
3721 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3722 /* initial allocation is 90% to canvas, 10% to notebook */
3723 pos = (int) floor (alloc.get_width() * 0.90f);
3724 snprintf (buf, sizeof(buf), "%d", pos);
3726 pos = atoi (prop->value());
3729 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3730 edit_pane.set_position (pos);
3731 pre_maximal_pane_position = pos;
3737 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3739 cerr << "remove tearoff\n";
3741 if (tools_tearoff->torn_off() &&
3742 mouse_mode_tearoff->torn_off()) {
3743 top_hbox.remove (toolbar_frame);
3748 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3750 cerr << "reattach tearoff\n";
3751 if (toolbar_frame.get_parent() == 0) {
3752 top_hbox.pack_end (toolbar_frame);
3757 Editor::set_show_measures (bool yn)
3759 if (_show_measures != yn) {
3762 if ((_show_measures = yn) == true) {
3764 tempo_lines->show();
3772 Editor::toggle_follow_playhead ()
3774 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3776 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3777 set_follow_playhead (tact->get_active());
3782 Editor::set_follow_playhead (bool yn)
3784 if (_follow_playhead != yn) {
3785 if ((_follow_playhead = yn) == true) {
3787 update_current_screen ();
3794 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3796 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3798 xfade->set_active (!xfade->active());
3803 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3805 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3807 xfade->set_follow_overlap (!xfade->following_overlap());
3812 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3814 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3820 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3824 switch (cew.run ()) {
3825 case RESPONSE_ACCEPT:
3832 xfade->StateChanged (Change (~0));
3836 Editor::playlist_selector () const
3838 return *_playlist_selector;
3842 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3846 switch (snap_type) {
3851 case SnapToAThirtysecondBeat:
3855 case SnapToASixteenthBeat:
3859 case SnapToAEighthBeat:
3863 case SnapToAQuarterBeat:
3867 case SnapToAThirdBeat:
3873 return session->tempo_map().meter_at (position).beats_per_bar();
3878 case SnapToSMPTEFrame:
3879 case SnapToSMPTESeconds:
3880 case SnapToSMPTEMinutes:
3883 case SnapToRegionStart:
3884 case SnapToRegionEnd:
3885 case SnapToRegionSync:
3886 case SnapToRegionBoundary:
3896 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3900 ret = nudge_clock.current_duration (pos);
3901 next = ret + 1; /* XXXX fix me */
3907 Editor::end_location_changed (Location* location)
3909 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3910 //reset_scrolling_region ();
3911 nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
3912 horizontal_adjustment.set_upper (session_span / frames_per_unit);
3916 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3918 ArdourDialog dialog ("playlist deletion dialog");
3919 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3920 "If left alone, no audio files used by it will be cleaned.\n"
3921 "If deleted, audio files used by it alone by will cleaned."),
3924 dialog.set_position (WIN_POS_CENTER);
3925 dialog.get_vbox()->pack_start (label);
3929 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3930 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3931 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3933 switch (dialog.run ()) {
3934 case RESPONSE_ACCEPT:
3935 /* delete the playlist */
3939 case RESPONSE_REJECT:
3940 /* keep the playlist */
3952 Editor::audio_region_selection_covers (nframes64_t where)
3954 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3955 if ((*a)->region()->covers (where)) {
3964 Editor::prepare_for_cleanup ()
3966 cut_buffer->clear_regions ();
3967 cut_buffer->clear_playlists ();
3969 selection->clear_regions ();
3970 selection->clear_playlists ();
3972 _regions->suspend_redisplay ();
3976 Editor::finish_cleanup ()
3978 _regions->resume_redisplay ();
3982 Editor::transport_loop_location()
3985 return session->locations()->auto_loop_location();
3992 Editor::transport_punch_location()
3995 return session->locations()->auto_punch_location();
4002 Editor::control_layout_scroll (GdkEventScroll* ev)
4004 switch (ev->direction) {
4006 scroll_tracks_up_line ();
4010 case GDK_SCROLL_DOWN:
4011 scroll_tracks_down_line ();
4015 /* no left/right handling yet */
4023 Editor::session_state_saved (string snap_name)
4025 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4027 _snapshots->redisplay ();
4031 Editor::maximise_editing_space ()
4033 mouse_mode_tearoff->set_visible (false);
4034 tools_tearoff->set_visible (false);
4036 pre_maximal_pane_position = edit_pane.get_position();
4037 pre_maximal_editor_width = this->get_width();
4039 if(post_maximal_pane_position == 0) {
4040 post_maximal_pane_position = edit_pane.get_width();
4045 if(post_maximal_editor_width) {
4046 edit_pane.set_position (post_maximal_pane_position -
4047 abs(post_maximal_editor_width - pre_maximal_editor_width));
4049 edit_pane.set_position (post_maximal_pane_position);
4054 Editor::restore_editing_space ()
4056 // user changed width of pane during fullscreen
4058 if(post_maximal_pane_position != edit_pane.get_position()) {
4059 post_maximal_pane_position = edit_pane.get_position();
4064 mouse_mode_tearoff->set_visible (true);
4065 tools_tearoff->set_visible (true);
4066 post_maximal_editor_width = this->get_width();
4068 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4072 * Make new playlists for a given track and also any others that belong
4073 * to the same active route group with the `edit' property.
4078 Editor::new_playlists (TimeAxisView* v)
4080 begin_reversible_command (_("new playlists"));
4081 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4082 session->get_playlists(playlists);
4083 mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, RouteGroup::Edit);
4084 commit_reversible_command ();
4088 * Use a copy of the current playlist for a given track and also any others that belong
4089 * to the same active route group with the `edit' property.
4094 Editor::copy_playlists (TimeAxisView* v)
4096 begin_reversible_command (_("copy playlists"));
4097 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4098 session->get_playlists(playlists);
4099 mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, RouteGroup::Edit);
4100 commit_reversible_command ();
4103 /** Clear the current playlist for a given track and also any others that belong
4104 * to the same active route group with the `edit' property.
4109 Editor::clear_playlists (TimeAxisView* v)
4111 begin_reversible_command (_("clear playlists"));
4112 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4113 session->get_playlists(playlists);
4114 mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v, RouteGroup::Edit);
4115 commit_reversible_command ();
4119 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4121 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4125 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4127 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4131 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4133 atv.clear_playlist ();
4137 Editor::on_key_press_event (GdkEventKey* ev)
4139 return key_press_focus_accelerator_handler (*this, ev);
4143 Editor::on_key_release_event (GdkEventKey* ev)
4145 return Gtk::Window::on_key_release_event (ev);
4146 // return key_press_focus_accelerator_handler (*this, ev);
4150 Editor::reset_x_origin (nframes64_t frame)
4152 //cerr << "resetting x origin" << endl;
4153 queue_visual_change (frame);
4157 Editor::reset_y_origin (double y)
4159 queue_visual_change_y (y);
4163 Editor::reset_zoom (double fpu)
4165 queue_visual_change (fpu);
4169 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4171 //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
4172 reset_x_origin (frame);
4175 if (!no_save_visual) {
4176 undo_visual_stack.push_back (current_visual_state(false));
4180 Editor::VisualState*
4181 Editor::current_visual_state (bool with_tracks)
4183 VisualState* vs = new VisualState;
4184 vs->y_position = vertical_adjustment.get_value();
4185 vs->frames_per_unit = frames_per_unit;
4186 vs->leftmost_frame = leftmost_frame;
4187 vs->zoom_focus = zoom_focus;
4188 vs->zoomed_to_region = zoomed_to_region;
4191 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4192 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4200 Editor::undo_visual_state ()
4202 if (undo_visual_stack.empty()) {
4206 VisualState* vs = undo_visual_stack.back();
4207 undo_visual_stack.pop_back();
4208 use_visual_state (*vs);
4209 redo_visual_stack.push_back (vs);
4213 Editor::redo_visual_state ()
4215 if (redo_visual_stack.empty()) {
4219 VisualState* vs = redo_visual_stack.back();
4220 redo_visual_stack.pop_back();
4221 use_visual_state (*vs);
4222 undo_visual_stack.push_back (vs);
4226 Editor::swap_visual_state ()
4228 if (undo_visual_stack.empty()) {
4229 redo_visual_state ();
4231 undo_visual_state ();
4236 Editor::use_visual_state (VisualState& vs)
4238 no_save_visual = true;
4240 _routes->suspend_redisplay ();
4242 vertical_adjustment.set_value (vs.y_position);
4244 set_zoom_focus (vs.zoom_focus);
4245 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4246 zoomed_to_region = vs.zoomed_to_region;
4248 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4249 TrackViewList::iterator t;
4251 /* check if the track still exists - it could have been deleted */
4253 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4254 (*t)->set_state (*(i->second));
4259 if (!vs.track_states.empty()) {
4260 _routes->update_visibility ();
4263 _routes->resume_redisplay ();
4265 no_save_visual = false;
4269 Editor::set_frames_per_unit (double fpu)
4271 /* this is the core function that controls the zoom level of the canvas. it is called
4272 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4275 if (fpu == frames_per_unit) {
4284 /* don't allow zooms that fit more than the maximum number
4285 of frames into an 800 pixel wide space.
4288 if (max_frames / fpu < 800.0) {
4293 tempo_lines->tempo_map_changed();
4295 frames_per_unit = fpu;
4300 Editor::post_zoom ()
4302 nframes64_t cef = 0;
4304 // convert fpu to frame count
4306 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4308 if (frames_per_unit != zoom_range_clock.current_duration()) {
4309 zoom_range_clock.set (frames);
4312 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4313 if (!selection->tracks.empty()) {
4314 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4315 (*i)->reshow_selection (selection->time);
4318 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4319 (*i)->reshow_selection (selection->time);
4324 leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4326 ZoomChanged (); /* EMIT_SIGNAL */
4328 reset_hscrollbar_stepping ();
4331 cef = session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
4333 horizontal_adjustment.set_upper (cef / frames_per_unit);
4335 //reset_scrolling_region ();
4337 if (playhead_cursor) {
4338 playhead_cursor->set_position (playhead_cursor->current_frame);
4341 refresh_location_display();
4342 _summary->set_overlays_dirty ();
4348 Editor::queue_visual_change (nframes64_t where)
4350 pending_visual_change.add (VisualChange::TimeOrigin);
4352 /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
4356 if (where > session->current_end_frame()) {
4357 horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
4360 pending_visual_change.time_origin = where;
4362 ensure_visual_change_idle_handler ();
4366 Editor::queue_visual_change (double fpu)
4368 pending_visual_change.add (VisualChange::ZoomLevel);
4369 pending_visual_change.frames_per_unit = fpu;
4371 ensure_visual_change_idle_handler ();
4376 Editor::queue_visual_change_y (double y)
4378 pending_visual_change.add (VisualChange::YOrigin);
4379 pending_visual_change.y_origin = y;
4381 ensure_visual_change_idle_handler ();
4385 Editor::ensure_visual_change_idle_handler ()
4387 if (pending_visual_change.idle_handler_id < 0) {
4388 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4393 Editor::_idle_visual_changer (void* arg)
4395 return static_cast<Editor*>(arg)->idle_visual_changer ();
4399 Editor::idle_visual_changer ()
4401 VisualChange::Type p = pending_visual_change.pending;
4402 pending_visual_change.pending = (VisualChange::Type) 0;
4404 #ifdef FIX_THIS_FOR_V3
4405 double last_time_origin = horizontal_adjustment.get_value();
4408 if (p & VisualChange::ZoomLevel) {
4409 set_frames_per_unit (pending_visual_change.frames_per_unit);
4411 compute_fixed_ruler_scale ();
4412 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4413 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4414 update_tempo_based_rulers ();
4416 if (p & VisualChange::TimeOrigin) {
4417 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4419 if (p & VisualChange::YOrigin) {
4420 vertical_adjustment.set_value (pending_visual_change.y_origin);
4423 nframes64_t csf=0, cef=0;
4424 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4427 csf = session->current_start_frame();
4428 cef = session->current_end_frame();
4431 /* if we seek beyond the current end of the canvas, move the end */
4433 #ifdef FIX_THIS_FOR_V3
4434 if (last_time_origin == horizontal_adjustment.get_value() ) {
4435 /* changed signal not emitted */
4436 update_fixed_rulers ();
4437 redisplay_tempo (true);
4441 if (current_time_origin != pending_visual_change.time_origin) {
4442 cef += current_page_frames() / 10; // Add a little extra so we can see the end marker
4443 horizontal_adjustment.set_upper (cef / frames_per_unit);
4444 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4446 update_fixed_rulers();
4447 redisplay_tempo (true);
4450 _summary->set_overlays_dirty ();
4452 //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
4453 pending_visual_change.idle_handler_id = -1;
4454 return 0; /* this is always a one-shot call */
4457 struct EditorOrderTimeAxisSorter {
4458 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4459 return a->order () < b->order ();
4464 Editor::sort_track_selection (TrackSelection* sel)
4466 EditorOrderTimeAxisSorter cmp;
4471 selection->tracks.sort (cmp);
4476 Editor::get_preferred_edit_position (bool ignore_playhead)
4479 nframes64_t where = 0;
4480 EditPoint ep = _edit_point;
4482 if (entered_marker) {
4483 return entered_marker->position();
4486 if (ignore_playhead && ep == EditAtPlayhead) {
4487 ep = EditAtSelectedMarker;
4491 case EditAtPlayhead:
4492 where = session->audible_frame();
4495 case EditAtSelectedMarker:
4496 if (!selection->markers.empty()) {
4498 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4501 where = loc->start();
4512 if (!mouse_frame (where, ignored)) {
4513 /* XXX not right but what can we do ? */
4524 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4526 if (!session) return;
4528 begin_reversible_command (cmd);
4532 if ((tll = transport_loop_location()) == 0) {
4533 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4534 XMLNode &before = session->locations()->get_state();
4535 session->locations()->add (loc, true);
4536 session->set_auto_loop_location (loc);
4537 XMLNode &after = session->locations()->get_state();
4538 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4540 XMLNode &before = tll->get_state();
4541 tll->set_hidden (false, this);
4542 tll->set (start, end);
4543 XMLNode &after = tll->get_state();
4544 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4547 commit_reversible_command ();
4551 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4553 if (!session) return;
4555 begin_reversible_command (cmd);
4559 if ((tpl = transport_punch_location()) == 0) {
4560 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4561 XMLNode &before = session->locations()->get_state();
4562 session->locations()->add (loc, true);
4563 session->set_auto_loop_location (loc);
4564 XMLNode &after = session->locations()->get_state();
4565 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4568 XMLNode &before = tpl->get_state();
4569 tpl->set_hidden (false, this);
4570 tpl->set (start, end);
4571 XMLNode &after = tpl->get_state();
4572 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4575 commit_reversible_command ();
4578 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4579 * @param rs List to which found regions are added.
4580 * @param where Time to look at.
4581 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4584 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4586 const TrackSelection* tracks;
4589 tracks = &track_views;
4594 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4595 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4597 boost::shared_ptr<Diskstream> ds;
4598 boost::shared_ptr<Playlist> pl;
4600 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4602 Playlist::RegionList* regions = pl->regions_at (
4603 (nframes64_t) floor ( (double)where * ds->speed()));
4605 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4606 RegionView* rv = rtv->view()->find_view (*i);
4619 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4621 const TrackSelection* tracks;
4624 tracks = &track_views;
4629 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4630 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4632 boost::shared_ptr<Diskstream> ds;
4633 boost::shared_ptr<Playlist> pl;
4635 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4637 Playlist::RegionList* regions = pl->regions_touched (
4638 (nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4640 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4642 RegionView* rv = rtv->view()->find_view (*i);
4655 /** Find all regions which are either:
4657 * - the entered_regionview (if allow_entered == true) or
4658 * - under the preferred edit position AND on a selected track, or on a track
4659 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4660 * @param rs Returned region list.
4661 * @param allow_entered true to include the entered_regionview in the list.
4664 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4666 /* Start with selected regions */
4667 rs = selection->regions;
4669 /* Add the entered_regionview, if requested */
4670 if (allow_entered && entered_regionview) {
4671 rs.add (entered_regionview);
4674 if (allow_edit_position) {
4676 TrackSelection tracks = selection->tracks;
4678 /* tracks is currently the set of selected tracks; add any other tracks that
4679 * have regions that are in the same edit-activated route group as one of
4681 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4683 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4684 if (g && g->active_property (RouteGroup::Edit)) {
4685 tracks.add (axis_views_from_routes (g->route_list()));
4689 /* now find regions that are at the edit position on those tracks */
4690 nframes64_t const where = get_preferred_edit_position ();
4691 get_regions_at (rs, where, tracks);
4696 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4698 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4700 RouteTimeAxisView* tatv;
4702 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4704 boost::shared_ptr<Playlist> pl;
4705 vector<boost::shared_ptr<Region> > results;
4707 boost::shared_ptr<Diskstream> ds;
4709 if ((ds = tatv->get_diskstream()) == 0) {
4714 if ((pl = (ds->playlist())) != 0) {
4715 pl->get_region_list_equivalent_regions (region, results);
4718 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4719 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4720 regions.push_back (marv);
4729 Editor::show_rhythm_ferret ()
4731 if (rhythm_ferret == 0) {
4732 rhythm_ferret = new RhythmFerret(*this);
4735 rhythm_ferret->set_session (session);
4736 rhythm_ferret->show ();
4737 rhythm_ferret->present ();
4741 Editor::show_bundle_manager ()
4743 if (_bundle_manager == 0) {
4744 _bundle_manager = new BundleManager (*session);
4747 _bundle_manager->show ();
4751 Editor::show_global_port_matrix (ARDOUR::DataType t)
4753 if (_global_port_matrix[t] == 0) {
4754 _global_port_matrix[t] = new GlobalPortMatrixWindow (*session, t);
4757 _global_port_matrix[t]->show ();
4761 Editor::first_idle ()
4763 MessageDialog* dialog = 0;
4765 if (track_views.size() > 1) {
4766 dialog = new MessageDialog (*this,
4767 _("Please wait while Ardour loads visual data"),
4772 ARDOUR_UI::instance()->flush_pending ();
4775 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4779 // first idle adds route children (automation tracks), so we need to redisplay here
4780 _routes->redisplay ();
4788 _idle_resizer (gpointer arg)
4790 return ((Editor*)arg)->idle_resize ();
4794 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4796 if (resize_idle_id < 0) {
4797 resize_idle_id = g_idle_add (_idle_resizer, this);
4798 _pending_resize_amount = 0;
4801 /* make a note of the smallest resulting height, so that we can clamp the
4802 lower limit at TimeAxisView::hSmall */
4804 int32_t min_resulting = INT32_MAX;
4806 _pending_resize_amount += h;
4807 _pending_resize_view = view;
4809 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4811 if (selection->tracks.contains (_pending_resize_view)) {
4812 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4813 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4817 if (min_resulting < 0) {
4822 if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
4823 _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
4827 /** Handle pending resizing of tracks */
4829 Editor::idle_resize ()
4831 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4833 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4834 selection->tracks.contains (_pending_resize_view)) {
4836 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4837 if (*i != _pending_resize_view) {
4838 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4844 _group_tabs->set_dirty ();
4845 resize_idle_id = -1;
4853 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::located));
4855 _pending_locate_request = false;
4859 Editor::region_view_added (RegionView *)
4861 _summary->set_dirty ();
4865 Editor::streamview_height_changed ()
4867 _summary->set_dirty ();
4871 Editor::axis_view_from_route (Route* r) const
4873 TrackViewList::const_iterator j = track_views.begin ();
4874 while (j != track_views.end()) {
4875 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4876 if (rtv && rtv->route().get() == r) {
4887 Editor::axis_views_from_routes (list<Route*> r) const
4891 for (list<Route*>::const_iterator i = r.begin(); i != r.end(); ++i) {
4892 TimeAxisView* tv = axis_view_from_route (*i);
4903 Editor::handle_new_route (RouteList& routes)
4905 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_route), routes));
4907 RouteTimeAxisView *rtv;
4908 list<RouteTimeAxisView*> new_views;
4910 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4911 boost::shared_ptr<Route> route = (*x);
4913 if (route->is_hidden()) {
4917 DataType dt = route->input()->default_type();
4919 if (dt == ARDOUR::DataType::AUDIO) {
4920 rtv = new AudioTimeAxisView (*this, *session, route, *track_canvas);
4921 } else if (dt == ARDOUR::DataType::MIDI) {
4922 rtv = new MidiTimeAxisView (*this, *session, route, *track_canvas);
4924 throw unknown_type();
4927 new_views.push_back (rtv);
4928 track_views.push_back (rtv);
4930 rtv->effective_gain_display ();
4932 rtv->view()->RegionViewAdded.connect (mem_fun (*this, &Editor::region_view_added));
4933 rtv->view()->HeightChanged.connect (mem_fun (*this, &Editor::streamview_height_changed));
4935 rtv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), rtv));
4938 _routes->routes_added (new_views);
4940 if (show_editor_mixer_when_tracks_arrive) {
4941 show_editor_mixer (true);
4944 editor_list_button.set_sensitive (true);
4946 _summary->set_dirty ();
4950 Editor::remove_route (TimeAxisView *tv)
4952 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
4954 TrackViewList::iterator i;
4955 boost::shared_ptr<Route> route;
4956 TimeAxisView* next_tv;
4958 if (tv == entered_track) {
4962 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4964 i = track_views.erase (i);
4966 if (track_views.empty()) {
4968 } else if (i == track_views.end()) {
4969 next_tv = track_views.front();
4975 if (current_mixer_strip && current_mixer_strip->route() == route) {
4978 set_selected_mixer_strip (*next_tv);
4980 /* make the editor mixer strip go away setting the
4981 * button to inactive (which also unticks the menu option)
4984 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
4990 Editor::hide_track_in_display (TimeAxisView& tv, bool /*temponly*/)
4992 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
4994 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
4995 // this will hide the mixer strip
4996 set_selected_mixer_strip (tv);
4999 _routes->hide_track_in_display (tv);
5003 Editor::sync_track_view_list_and_routes ()
5005 track_views = TrackSelection (_routes->views ());
5007 _summary->set_dirty ();
5008 _group_tabs->set_dirty ();
5010 return false; // do not call again (until needed)
5014 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
5016 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5022 Editor::get_route_view_by_id (PBD::ID& id)
5024 RouteTimeAxisView* v;
5026 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5027 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5028 if(v->route()->id() == id) {
5038 Editor::fit_route_group (RouteGroup *g)
5040 TrackSelection ts = axis_views_from_routes (g->route_list ());
5045 Editor::consider_auditioning (boost::shared_ptr<Region> region)
5047 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
5050 session->cancel_audition ();
5054 if (session->is_auditioning()) {
5055 session->cancel_audition ();
5056 if (r == last_audition_region) {
5061 session->audition_region (r);
5062 last_audition_region = r;
5067 Editor::hide_a_region (boost::shared_ptr<Region> r)
5069 r->set_hidden (true);
5073 Editor::remove_a_region (boost::shared_ptr<Region> r)
5075 session->remove_region_from_region_list (r);
5079 Editor::audition_region_from_region_list ()
5081 _regions->selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
5085 Editor::hide_region_from_region_list ()
5087 _regions->selection_mapover (mem_fun (*this, &Editor::hide_a_region));
5091 Editor::start_step_editing ()
5093 step_edit_connection = Glib::signal_timeout().connect (mem_fun (*this, &Editor::check_step_edit), 20);
5097 Editor::stop_step_editing ()
5099 step_edit_connection.disconnect ();
5103 Editor::check_step_edit ()
5105 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5106 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
5108 mtv->check_step_edit ();
5112 return true; // do it again, till we stop