2 Copyright (C) 2000-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* Note: public Editor methods are documented in public_editor.h */
22 #define __STDC_LIMIT_MACROS 1
31 #include "ardour_ui.h"
33 * ardour_ui.h include was moved to the top of the list
34 * due to a conflicting definition of 'Style' between
35 * Apple's MacTypes.h and BarController.
38 #include <boost/none.hpp>
40 #include <sigc++/bind.h>
42 #include "pbd/convert.h"
43 #include "pbd/error.h"
44 #include "pbd/enumwriter.h"
45 #include "pbd/memento_command.h"
46 #include "pbd/unknown_type.h"
48 #include <glibmm/miscutils.h>
49 #include <gtkmm/image.h>
50 #include <gdkmm/color.h>
51 #include <gdkmm/bitmap.h>
53 #include <gtkmm2ext/grouped_buttons.h>
54 #include <gtkmm2ext/gtk_ui.h>
55 #include <gtkmm2ext/tearoff.h>
56 #include <gtkmm2ext/utils.h>
57 #include <gtkmm2ext/window_title.h>
58 #include <gtkmm2ext/choice.h>
59 #include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
61 #include "ardour/audio_diskstream.h"
62 #include "ardour/audio_track.h"
63 #include "ardour/audioplaylist.h"
64 #include "ardour/audioregion.h"
65 #include "ardour/location.h"
66 #include "ardour/midi_region.h"
67 #include "ardour/plugin_manager.h"
68 #include "ardour/profile.h"
69 #include "ardour/route_group.h"
70 #include "ardour/session_directory.h"
71 #include "ardour/session_route.h"
72 #include "ardour/session_state_utils.h"
73 #include "ardour/tempo.h"
74 #include "ardour/utils.h"
75 #include "ardour/session_playlists.h"
77 #include "control_protocol/control_protocol.h"
82 #include "playlist_selector.h"
83 #include "audio_region_view.h"
84 #include "rgb_macros.h"
85 #include "selection.h"
86 #include "audio_streamview.h"
87 #include "time_axis_view.h"
88 #include "audio_time_axis.h"
90 #include "crossfade_view.h"
91 #include "canvas-noevent-text.h"
93 #include "public_editor.h"
94 #include "crossfade_edit.h"
95 #include "canvas_impl.h"
98 #include "gui_thread.h"
99 #include "simpleline.h"
100 #include "rhythm_ferret.h"
102 #include "tempo_lines.h"
103 #include "analysis_window.h"
104 #include "bundle_manager.h"
105 #include "global_port_matrix.h"
106 #include "editor_drag.h"
107 #include "editor_group_tabs.h"
108 #include "automation_time_axis.h"
109 #include "editor_routes.h"
110 #include "midi_time_axis.h"
111 #include "mixer_strip.h"
112 #include "editor_route_groups.h"
113 #include "editor_regions.h"
114 #include "editor_locations.h"
115 #include "editor_snapshots.h"
120 #include "imageframe_socket_handler.h"
124 using namespace ARDOUR;
127 using namespace Glib;
128 using namespace Gtkmm2ext;
129 using namespace Editing;
131 using PBD::internationalize;
133 using Gtkmm2ext::Keyboard;
135 const double Editor::timebar_height = 15.0;
137 #include "editor_xpms"
139 static const gchar *_snap_type_strings[] = {
141 N_("Timecode Frames"),
142 N_("Timecode Seconds"),
143 N_("Timecode Minutes"),
161 static const gchar *_snap_mode_strings[] = {
168 static const gchar *_edit_point_strings[] = {
175 static const gchar *_zoom_focus_strings[] = {
185 #ifdef USE_RUBBERBAND
186 static const gchar *_rb_opt_strings[] = {
189 N_("Balanced multitimbral mixture"),
190 N_("Unpitched percussion with stable notes"),
191 N_("Crisp monophonic instrumental"),
192 N_("Unpitched solo percussion"),
197 /* Soundfile drag-n-drop */
199 Gdk::Cursor* Editor::cross_hair_cursor = 0;
200 Gdk::Cursor* Editor::selector_cursor = 0;
201 Gdk::Cursor* Editor::trimmer_cursor = 0;
202 Gdk::Cursor* Editor::grabber_cursor = 0;
203 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
204 Gdk::Cursor* Editor::zoom_cursor = 0;
205 Gdk::Cursor* Editor::time_fx_cursor = 0;
206 Gdk::Cursor* Editor::fader_cursor = 0;
207 Gdk::Cursor* Editor::speaker_cursor = 0;
208 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
209 Gdk::Cursor* Editor::midi_select_cursor = 0;
210 Gdk::Cursor* Editor::midi_resize_cursor = 0;
211 Gdk::Cursor* Editor::midi_erase_cursor = 0;
212 Gdk::Cursor* Editor::wait_cursor = 0;
213 Gdk::Cursor* Editor::timebar_cursor = 0;
214 Gdk::Cursor* Editor::transparent_cursor = 0;
217 show_me_the_size (Requisition* r, const char* what)
219 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
223 /* time display buttons */
224 : minsec_label (_("Mins:Secs"))
225 , bbt_label (_("Bars:Beats"))
226 , timecode_label (_("Timecode"))
227 , frame_label (_("Samples"))
228 , tempo_label (_("Tempo"))
229 , meter_label (_("Meter"))
230 , mark_label (_("Location Markers"))
231 , range_mark_label (_("Range Markers"))
232 , transport_mark_label (_("Loop/Punch Ranges"))
233 , cd_mark_label (_("CD Markers"))
234 , edit_packer (4, 4, true)
236 /* the values here don't matter: layout widgets
237 reset them as needed.
240 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
241 , horizontal_adjustment (0.0, 0.0, 20.0, 1200.0)
243 /* tool bar related */
245 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
247 , toolbar_selection_clock_table (2,3)
249 , automation_mode_button (_("mode"))
250 , global_automation_button (_("automation"))
252 , midi_panic_button (_("Panic"))
255 , image_socket_listener(0)
260 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
261 , meters_running(false)
262 , _pending_locate_request (false)
267 /* we are a singleton */
269 PublicEditor::_instance = this;
273 selection = new Selection (this);
274 cut_buffer = new Selection (this);
276 clicked_regionview = 0;
277 clicked_axisview = 0;
278 clicked_routeview = 0;
279 clicked_crossfadeview = 0;
280 clicked_control_point = 0;
281 last_update_frame = 0;
283 current_mixer_strip = 0;
284 current_bbt_points = 0;
287 snap_type_strings = I18N (_snap_type_strings);
288 snap_mode_strings = I18N (_snap_mode_strings);
289 zoom_focus_strings = I18N (_zoom_focus_strings);
290 edit_point_strings = I18N (_edit_point_strings);
291 #ifdef USE_RUBBERBAND
292 rb_opt_strings = I18N (_rb_opt_strings);
295 snap_threshold = 5.0;
296 bbt_beat_subdivision = 4;
299 last_autoscroll_x = 0;
300 last_autoscroll_y = 0;
301 autoscroll_active = false;
302 autoscroll_timeout_tag = -1;
303 interthread_progress_window = 0;
308 current_interthread_info = 0;
309 _show_measures = true;
310 _show_waveforms_recording = true;
311 show_gain_after_trim = false;
312 verbose_cursor_on = true;
313 route_removal = false;
314 last_item_entered = 0;
315 last_item_entered_n = 0;
317 have_pending_keyboard_selection = false;
318 _follow_playhead = true;
319 _xfade_visibility = true;
320 editor_ruler_menu = 0;
321 no_ruler_shown_update = false;
323 start_end_marker_menu = 0;
324 range_marker_menu = 0;
325 marker_menu_item = 0;
327 transport_marker_menu = 0;
328 new_transport_marker_menu = 0;
329 editor_mixer_strip_width = Wide;
330 show_editor_mixer_when_tracks_arrive = false;
331 region_edit_menu_split_multichannel_item = 0;
332 region_edit_menu_split_item = 0;
335 current_stepping_trackview = 0;
337 entered_regionview = 0;
339 clear_entered_track = false;
340 _new_regionviews_show_envelope = false;
343 button_release_can_deselect = true;
344 _dragging_playhead = false;
345 _dragging_edit_point = false;
346 select_new_marker = false;
349 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
350 _global_port_matrix[*i] = 0;
352 allow_vertical_scroll = false;
353 no_save_visual = false;
356 scrubbing_direction = 0;
360 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
361 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
362 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
363 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
364 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
366 _edit_point = EditAtMouse;
367 _internal_editing = false;
368 current_canvas_cursor = 0;
370 frames_per_unit = 2048; /* too early to use reset_zoom () */
372 zoom_focus = ZoomFocusLeft;
373 set_zoom_focus (ZoomFocusLeft);
374 zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
376 bbt_label.set_name ("EditorTimeButton");
377 bbt_label.set_size_request (-1, (int)timebar_height);
378 bbt_label.set_alignment (1.0, 0.5);
379 bbt_label.set_padding (5,0);
381 bbt_label.set_no_show_all();
382 minsec_label.set_name ("EditorTimeButton");
383 minsec_label.set_size_request (-1, (int)timebar_height);
384 minsec_label.set_alignment (1.0, 0.5);
385 minsec_label.set_padding (5,0);
386 minsec_label.hide ();
387 minsec_label.set_no_show_all();
388 timecode_label.set_name ("EditorTimeButton");
389 timecode_label.set_size_request (-1, (int)timebar_height);
390 timecode_label.set_alignment (1.0, 0.5);
391 timecode_label.set_padding (5,0);
392 timecode_label.hide ();
393 timecode_label.set_no_show_all();
394 frame_label.set_name ("EditorTimeButton");
395 frame_label.set_size_request (-1, (int)timebar_height);
396 frame_label.set_alignment (1.0, 0.5);
397 frame_label.set_padding (5,0);
399 frame_label.set_no_show_all();
401 tempo_label.set_name ("EditorTimeButton");
402 tempo_label.set_size_request (-1, (int)timebar_height);
403 tempo_label.set_alignment (1.0, 0.5);
404 tempo_label.set_padding (5,0);
406 tempo_label.set_no_show_all();
407 meter_label.set_name ("EditorTimeButton");
408 meter_label.set_size_request (-1, (int)timebar_height);
409 meter_label.set_alignment (1.0, 0.5);
410 meter_label.set_padding (5,0);
412 meter_label.set_no_show_all();
413 mark_label.set_name ("EditorTimeButton");
414 mark_label.set_size_request (-1, (int)timebar_height);
415 mark_label.set_alignment (1.0, 0.5);
416 mark_label.set_padding (5,0);
418 mark_label.set_no_show_all();
419 cd_mark_label.set_name ("EditorTimeButton");
420 cd_mark_label.set_size_request (-1, (int)timebar_height);
421 cd_mark_label.set_alignment (1.0, 0.5);
422 cd_mark_label.set_padding (5,0);
423 cd_mark_label.hide();
424 cd_mark_label.set_no_show_all();
425 range_mark_label.set_name ("EditorTimeButton");
426 range_mark_label.set_size_request (-1, (int)timebar_height);
427 range_mark_label.set_alignment (1.0, 0.5);
428 range_mark_label.set_padding (5,0);
429 range_mark_label.hide();
430 range_mark_label.set_no_show_all();
431 transport_mark_label.set_name ("EditorTimeButton");
432 transport_mark_label.set_size_request (-1, (int)timebar_height);
433 transport_mark_label.set_alignment (1.0, 0.5);
434 transport_mark_label.set_padding (5,0);
435 transport_mark_label.hide();
436 transport_mark_label.set_no_show_all();
438 initialize_rulers ();
439 initialize_canvas ();
440 _summary = new EditorSummary (this);
442 selection->TimeChanged.connect (sigc::mem_fun(*this, &Editor::time_selection_changed));
443 selection->TracksChanged.connect (sigc::mem_fun(*this, &Editor::track_selection_changed));
444 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (sigc::mem_fun(*this, &Editor::region_selection_changed));
445 selection->PointsChanged.connect (sigc::mem_fun(*this, &Editor::point_selection_changed));
446 selection->MarkersChanged.connect (sigc::mem_fun(*this, &Editor::marker_selection_changed));
448 edit_controls_vbox.set_spacing (0);
449 horizontal_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
450 vertical_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::tie_vertical_scrolling), true);
451 track_canvas->signal_map_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_map_handler));
453 HBox* h = manage (new HBox);
454 _group_tabs = new EditorGroupTabs (this);
455 h->pack_start (*_group_tabs, PACK_SHRINK);
456 h->pack_start (edit_controls_vbox);
457 controls_layout.add (*h);
459 ARDOUR_UI::instance()->tooltips().set_tip (*_group_tabs, _("Groups: context-click for possible operations"));
461 controls_layout.set_name ("EditControlsBase");
462 controls_layout.add_events (Gdk::SCROLL_MASK);
463 controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false);
465 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
466 controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
467 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
471 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
472 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
473 0.0, 1.0, 100.0, 1.0));
474 pad_line_1->property_color_rgba() = 0xFF0000FF;
478 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
479 time_canvas_vbox.set_size_request (-1, -1);
481 ruler_label_event_box.add (ruler_label_vbox);
482 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
483 ruler_label_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
485 time_button_event_box.add (time_button_vbox);
486 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
487 time_button_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
489 /* these enable us to have a dedicated window (for cursor setting, etc.)
490 for the canvas areas.
493 track_canvas_event_box.add (*track_canvas);
495 time_canvas_event_box.add (time_canvas_vbox);
496 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
498 edit_packer.set_col_spacings (0);
499 edit_packer.set_row_spacings (0);
500 edit_packer.set_homogeneous (false);
501 edit_packer.set_border_width (0);
502 edit_packer.set_name ("EditorWindow");
504 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
505 /* labels for the rulers */
506 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
507 /* labels for the marker "tracks" */
508 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
510 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
512 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
514 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
516 bottom_hbox.set_border_width (2);
517 bottom_hbox.set_spacing (3);
519 _route_groups = new EditorRouteGroups (this);
520 _routes = new EditorRoutes (this);
521 _regions = new EditorRegions (this);
522 _snapshots = new EditorSnapshots (this);
523 _locations = new EditorLocations (this);
527 nlabel = manage (new Label (_("Regions")));
528 nlabel->set_angle (-90);
529 the_notebook.append_page (_regions->widget (), *nlabel);
530 nlabel = manage (new Label (_("Tracks/Busses")));
531 nlabel->set_angle (-90);
532 the_notebook.append_page (_routes->widget (), *nlabel);
533 nlabel = manage (new Label (_("Snapshots")));
534 nlabel->set_angle (-90);
535 the_notebook.append_page (_snapshots->widget (), *nlabel);
536 nlabel = manage (new Label (_("Route Groups")));
537 nlabel->set_angle (-90);
538 the_notebook.append_page (_route_groups->widget (), *nlabel);
539 nlabel = manage (new Label (_("Ranges & Marks")));
540 nlabel->set_angle (-90);
541 the_notebook.append_page (_locations->widget (), *nlabel);
543 the_notebook.set_show_tabs (true);
544 the_notebook.set_scrollable (true);
545 the_notebook.popup_disable ();
546 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
547 the_notebook.show_all ();
549 post_maximal_editor_width = 0;
550 post_maximal_pane_position = 0;
552 VPaned *editor_summary_pane = manage(new VPaned());
553 editor_summary_pane->pack1(edit_packer);
555 Button* summary_arrows_left_left = manage (new Button);
556 summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
557 summary_arrows_left_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
558 Button* summary_arrows_left_right = manage (new Button);
559 summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
560 summary_arrows_left_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
561 VBox* summary_arrows_left = manage (new VBox);
562 summary_arrows_left->pack_start (*summary_arrows_left_left);
563 summary_arrows_left->pack_start (*summary_arrows_left_right);
565 Button* summary_arrows_right_left = manage (new Button);
566 summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
567 summary_arrows_right_left->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left));
568 Button* summary_arrows_right_right = manage (new Button);
569 summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
570 summary_arrows_right_right->signal_clicked().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right));
571 VBox* summary_arrows_right = manage (new VBox);
572 summary_arrows_right->pack_start (*summary_arrows_right_left);
573 summary_arrows_right->pack_start (*summary_arrows_right_right);
575 Frame* summary_frame = manage (new Frame);
576 summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
577 summary_frame->add (*_summary);
578 summary_frame->show ();
580 _summary_hbox.pack_start (*summary_arrows_left, false, false);
581 _summary_hbox.pack_start (*summary_frame, true, true);
582 _summary_hbox.pack_start (*summary_arrows_right, false, false);
584 editor_summary_pane->pack2 (_summary_hbox);
586 edit_pane.pack1 (*editor_summary_pane, true, true);
587 edit_pane.pack2 (the_notebook, false, true);
589 edit_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
591 top_hbox.pack_start (toolbar_frame, false, true);
593 HBox *hbox = manage (new HBox);
594 hbox->pack_start (edit_pane, true, true);
596 global_vpacker.pack_start (top_hbox, false, false);
597 global_vpacker.pack_start (*hbox, true, true);
599 global_hpacker.pack_start (global_vpacker, true, true);
601 set_name ("EditorWindow");
602 add_accel_group (ActionManager::ui_manager->get_accel_group());
604 status_bar_hpacker.show ();
606 vpacker.pack_end (status_bar_hpacker, false, false);
607 vpacker.pack_end (global_hpacker, true, true);
609 /* register actions now so that set_state() can find them and set toggles/checks etc */
614 setup_midi_toolbar ();
616 _snap_type = SnapToBeat;
617 set_snap_to (_snap_type);
618 _snap_mode = SnapOff;
619 set_snap_mode (_snap_mode);
620 set_mouse_mode (MouseObject, true);
621 set_edit_point_preference (EditAtMouse, true);
623 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
624 set_state (*node, Stateful::loading_state_version);
626 _playlist_selector = new PlaylistSelector();
627 _playlist_selector->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
629 RegionView::RegionViewGoingAway.connect (*this, ui_bind (&Editor::catch_vanishing_regionview, this, _1), gui_context());
633 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
634 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
636 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
637 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
639 nudge_forward_button.set_name ("TransportButton");
640 nudge_backward_button.set_name ("TransportButton");
642 fade_context_menu.set_name ("ArdourContextMenu");
644 /* icons, titles, WM stuff */
646 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
647 Glib::RefPtr<Gdk::Pixbuf> icon;
649 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
650 window_icons.push_back (icon);
652 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
653 window_icons.push_back (icon);
655 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
656 window_icons.push_back (icon);
658 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
659 window_icons.push_back (icon);
661 if (!window_icons.empty()) {
662 set_icon_list (window_icons);
663 set_default_icon_list (window_icons);
666 WindowTitle title(Glib::get_application_name());
667 title += _("Editor");
668 set_title (title.get_string());
669 set_wmclass (X_("ardour_editor"), "Ardour");
672 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
674 signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
675 signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
677 /* allow external control surfaces/protocols to do various things */
679 ControlProtocol::ZoomToSession.connect (*this, boost::bind (&Editor::temporal_zoom_session, this), gui_context());
680 ControlProtocol::ZoomIn.connect (*this, boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
681 ControlProtocol::ZoomOut.connect (*this, boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
682 ControlProtocol::ScrollTimeline.connect (*this, ui_bind (&Editor::control_scroll, this, _1), gui_context());
683 BasicUI::AccessAction.connect (*this, ui_bind (&Editor::access_action, this, _1, _2), gui_context());
685 /* problematic: has to return a value and thus cannot be x-thread */
687 Session::AskAboutPlaylistDeletion.connect_same_thread (*this, boost::bind (&Editor::playlist_deletion_dialog, this, _1));
689 Config->ParameterChanged.connect (*this, ui_bind (&Editor::parameter_changed, this, _1), gui_context());
691 _last_normalization_value = 0;
700 if(image_socket_listener) {
701 if(image_socket_listener->is_connected())
703 image_socket_listener->close_connection() ;
706 delete image_socket_listener ;
707 image_socket_listener = 0 ;
712 delete _route_groups;
718 Editor::add_toplevel_controls (Container& cont)
720 vpacker.pack_start (cont, false, false);
725 Editor::catch_vanishing_regionview (RegionView *rv)
727 /* note: the selection will take care of the vanishing
728 audioregionview by itself.
731 if (_drag && rv->get_canvas_group() == _drag->item() && !_drag->ending()) {
737 if (clicked_regionview == rv) {
738 clicked_regionview = 0;
741 if (entered_regionview == rv) {
742 set_entered_regionview (0);
747 Editor::set_entered_regionview (RegionView* rv)
749 if (rv == entered_regionview) {
753 if (entered_regionview) {
754 entered_regionview->exited ();
757 if ((entered_regionview = rv) != 0) {
758 entered_regionview->entered ();
763 Editor::set_entered_track (TimeAxisView* tav)
766 entered_track->exited ();
769 if ((entered_track = tav) != 0) {
770 entered_track->entered ();
775 Editor::show_window ()
777 if (! is_visible ()) {
780 /* re-hide editor list if necessary */
781 editor_list_button_toggled ();
783 /* re-hide summary widget if necessary */
784 parameter_changed ("show-summary");
786 parameter_changed ("show-edit-group-tabs");
788 /* now reset all audio_time_axis heights, because widgets might need
794 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
795 tv = (static_cast<TimeAxisView*>(*i));
804 Editor::instant_save ()
806 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
811 _session->add_instant_xml(get_state());
813 Config->add_instant_xml(get_state());
818 Editor::zoom_adjustment_changed ()
824 double fpu = zoom_range_clock.current_duration() / _canvas_width;
828 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
829 } else if (fpu > _session->current_end_frame() / _canvas_width) {
830 fpu = _session->current_end_frame() / _canvas_width;
831 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
838 Editor::control_scroll (float fraction)
840 ENSURE_GUI_THREAD (*this, &Editor::control_scroll, fraction)
846 double step = fraction * current_page_frames();
849 _control_scroll_target is an optional<T>
851 it acts like a pointer to an nframes64_t, with
852 a operator conversion to boolean to check
853 that it has a value could possibly use
854 playhead_cursor->current_frame to store the
855 value and a boolean in the class to know
856 when it's out of date
859 if (!_control_scroll_target) {
860 _control_scroll_target = _session->transport_frame();
861 _dragging_playhead = true;
864 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
865 *_control_scroll_target = 0;
866 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
867 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
869 *_control_scroll_target += (nframes64_t) floor (step);
872 /* move visuals, we'll catch up with it later */
874 playhead_cursor->set_position (*_control_scroll_target);
875 UpdateAllTransportClocks (*_control_scroll_target);
877 if (*_control_scroll_target > (current_page_frames() / 2)) {
878 /* try to center PH in window */
879 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
885 Now we do a timeout to actually bring the session to the right place
886 according to the playhead. This is to avoid reading disk buffers on every
887 call to control_scroll, which is driven by ScrollTimeline and therefore
888 probably by a control surface wheel which can generate lots of events.
890 /* cancel the existing timeout */
892 control_scroll_connection.disconnect ();
894 /* add the next timeout */
896 control_scroll_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
900 Editor::deferred_control_scroll (nframes64_t /*target*/)
902 _session->request_locate (*_control_scroll_target, _session->transport_rolling());
903 // reset for next stream
904 _control_scroll_target = boost::none;
905 _dragging_playhead = false;
910 Editor::access_action (std::string action_group, std::string action_item)
916 ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
919 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
929 Editor::on_realize ()
931 Window::on_realize ();
936 Editor::start_scrolling ()
938 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
939 (sigc::mem_fun(*this, &Editor::update_current_screen));
944 Editor::stop_scrolling ()
946 scroll_connection.disconnect ();
950 Editor::map_position_change (nframes64_t frame)
952 ENSURE_GUI_THREAD (*this, &Editor::map_position_change, frame)
954 if (_session == 0 || !_follow_playhead) {
958 center_screen (frame);
959 playhead_cursor->set_position (frame);
963 Editor::center_screen (nframes64_t frame)
965 double page = _canvas_width * frames_per_unit;
967 /* if we're off the page, then scroll.
970 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
971 center_screen_internal (frame, page);
976 Editor::center_screen_internal (nframes64_t frame, float page)
981 frame -= (nframes64_t) page;
986 reset_x_origin (frame);
990 Editor::handle_new_duration ()
996 ENSURE_GUI_THREAD (*this, &Editor::handle_new_duration)
997 nframes64_t new_end = _session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
999 horizontal_adjustment.set_upper (new_end / frames_per_unit);
1000 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1002 if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
1003 horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
1005 //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
1009 Editor::update_title ()
1011 ENSURE_GUI_THREAD (*this, &Editor::update_title)
1014 bool dirty = _session->dirty();
1016 string session_name;
1018 if (_session->snap_name() != _session->name()) {
1019 session_name = _session->snap_name();
1021 session_name = _session->name();
1025 session_name = "*" + session_name;
1028 WindowTitle title(session_name);
1029 title += Glib::get_application_name();
1030 set_title (title.get_string());
1035 Editor::set_session (Session *t)
1037 SessionHandlePtr::set_session (t);
1043 zoom_range_clock.set_session (_session);
1044 _playlist_selector->set_session (_session);
1045 nudge_clock.set_session (_session);
1046 _summary->set_session (_session);
1047 _group_tabs->set_session (_session);
1048 _route_groups->set_session (_session);
1049 _regions->set_session (_session);
1050 _snapshots->set_session (_session);
1051 _routes->set_session (_session);
1052 _locations->set_session (_session);
1054 if (rhythm_ferret) {
1055 rhythm_ferret->set_session (_session);
1058 if (analysis_window) {
1059 analysis_window->set_session (_session);
1063 sfbrowser->set_session (_session);
1066 compute_fixed_ruler_scale ();
1068 /* there are never any selected regions at startup */
1070 sensitize_the_right_region_actions (false);
1072 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1073 set_state (*node, Stateful::loading_state_version);
1075 /* catch up with the playhead */
1077 _session->request_locate (playhead_cursor->current_frame);
1081 /* These signals can all be emitted by a non-GUI thread. Therefore the
1082 handlers for them must not attempt to directly interact with the GUI,
1083 but use Gtkmm2ext::UI::instance()->call_slot();
1086 _session->TransportStateChange.connect (_session_connections, boost::bind (&Editor::map_transport_state, this), gui_context());
1087 _session->PositionChanged.connect (_session_connections, ui_bind (&Editor::map_position_change, this, _1), gui_context());
1088 _session->RouteAdded.connect (_session_connections, ui_bind (&Editor::handle_new_route, this, _1), gui_context());
1089 _session->DurationChanged.connect (_session_connections, boost::bind (&Editor::handle_new_duration, this), gui_context());
1090 _session->DirtyChanged.connect (_session_connections, boost::bind (&Editor::update_title, this), gui_context());
1091 _session->TimecodeOffsetChanged.connect (_session_connections, boost::bind (&Editor::update_just_timecode, this), gui_context());
1092 _session->tempo_map().StateChanged.connect (_session_connections, ui_bind (&Editor::tempo_map_changed, this, _1), gui_context());
1093 _session->Located.connect (_session_connections, boost::bind (&Editor::located, this), gui_context());
1094 _session->config.ParameterChanged.connect (_session_connections, ui_bind (&Editor::parameter_changed, this, _1), gui_context());
1095 _session->StateSaved.connect (_session_connections, ui_bind (&Editor::session_state_saved, this, _1), gui_context());
1096 _session->locations()->added.connect (_session_connections, ui_bind (&Editor::add_new_location, this, _1), gui_context());
1097 _session->locations()->removed.connect (_session_connections, ui_bind (&Editor::location_gone, this, _1), gui_context());
1098 _session->locations()->changed.connect (_session_connections, boost::bind (&Editor::refresh_location_display, this), gui_context());
1099 _session->locations()->StateChanged.connect (_session_connections, ui_bind (&Editor::refresh_location_display_s, this, _1), gui_context());
1100 _session->locations()->end_location()->changed.connect (_session_connections, ui_bind (&Editor::end_location_changed, this, _1), gui_context());
1101 _session->history().Changed.connect (_session_connections, boost::bind (&Editor::history_changed, this), gui_context());
1103 if (Profile->get_sae()) {
1108 nframes_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
1109 nudge_clock.set_mode(AudioClock::BBT);
1110 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1113 nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
1116 playhead_cursor->canvas_item.show ();
1118 Location* loc = _session->locations()->auto_loop_location();
1120 loc = new Location (0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1121 if (loc->start() == loc->end()) {
1122 loc->set_end (loc->start() + 1);
1124 _session->locations()->add (loc, false);
1125 _session->set_auto_loop_location (loc);
1128 loc->set_name (_("Loop"));
1131 loc = _session->locations()->auto_punch_location();
1133 loc = new Location (0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1134 if (loc->start() == loc->end()) {
1135 loc->set_end (loc->start() + 1);
1137 _session->locations()->add (loc, false);
1138 _session->set_auto_punch_location (loc);
1141 loc->set_name (_("Punch"));
1144 boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
1145 Config->map_parameters (pc);
1146 _session->config.map_parameters (pc);
1148 refresh_location_display ();
1149 handle_new_duration ();
1151 restore_ruler_visibility ();
1152 //tempo_map_changed (Change (0));
1153 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1155 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1156 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1161 switch (_snap_type) {
1162 case SnapToRegionStart:
1163 case SnapToRegionEnd:
1164 case SnapToRegionSync:
1165 case SnapToRegionBoundary:
1166 build_region_boundary_cache ();
1173 /* register for undo history */
1174 _session->register_with_memento_command_factory(_id, this);
1180 Editor::build_cursors ()
1182 using namespace Gdk;
1184 Gdk::Color mbg ("#000000" ); /* Black */
1185 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1188 RefPtr<Bitmap> source, mask;
1189 source = Bitmap::create (mag_bits, mag_width, mag_height);
1190 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1191 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1194 Gdk::Color fbg ("#ffffff" );
1195 Gdk::Color ffg ("#000000" );
1198 RefPtr<Bitmap> source, mask;
1200 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1201 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1202 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1206 RefPtr<Bitmap> source, mask;
1207 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1208 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1209 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1213 RefPtr<Bitmap> bits;
1214 char pix[4] = { 0, 0, 0, 0 };
1215 bits = Bitmap::create (pix, 2, 2);
1217 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1221 RefPtr<Bitmap> bits;
1222 char pix[4] = { 0, 0, 0, 0 };
1223 bits = Bitmap::create (pix, 2, 2);
1225 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1229 grabber_cursor = new Gdk::Cursor (HAND2);
1232 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1233 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1236 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1237 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1238 selector_cursor = new Gdk::Cursor (XTERM);
1239 time_fx_cursor = new Gdk::Cursor (SIZING);
1240 wait_cursor = new Gdk::Cursor (WATCH);
1241 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1242 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1243 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1244 midi_resize_cursor = new Gdk::Cursor (SIZING);
1245 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1248 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1250 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1252 using namespace Menu_Helpers;
1253 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1256 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1260 MenuList& items (fade_context_menu.items());
1264 switch (item_type) {
1266 case FadeInHandleItem:
1267 if (arv->audio_region()->fade_in_active()) {
1268 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), false)));
1270 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), true)));
1273 items.push_back (SeparatorElem());
1275 if (Profile->get_sae()) {
1276 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1277 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1279 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1280 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1281 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1282 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1283 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1289 case FadeOutHandleItem:
1290 if (arv->audio_region()->fade_out_active()) {
1291 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), false)));
1293 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), true)));
1296 items.push_back (SeparatorElem());
1298 if (Profile->get_sae()) {
1299 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1300 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1302 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1303 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1304 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1305 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1306 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1312 fatal << _("programming error: ")
1313 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1318 fade_context_menu.popup (button, time);
1322 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1324 using namespace Menu_Helpers;
1325 Menu* (Editor::*build_menu_function)(nframes64_t);
1328 switch (item_type) {
1330 case RegionViewName:
1331 case RegionViewNameHighlight:
1332 if (with_selection) {
1333 build_menu_function = &Editor::build_track_selection_context_menu;
1335 build_menu_function = &Editor::build_track_region_context_menu;
1340 if (with_selection) {
1341 build_menu_function = &Editor::build_track_selection_context_menu;
1343 build_menu_function = &Editor::build_track_context_menu;
1347 case CrossfadeViewItem:
1348 build_menu_function = &Editor::build_track_crossfade_context_menu;
1352 if (clicked_routeview->get_diskstream()) {
1353 build_menu_function = &Editor::build_track_context_menu;
1355 build_menu_function = &Editor::build_track_bus_context_menu;
1360 /* probably shouldn't happen but if it does, we don't care */
1364 menu = (this->*build_menu_function)(frame);
1365 menu->set_name ("ArdourContextMenu");
1367 /* now handle specific situations */
1369 switch (item_type) {
1371 case RegionViewName:
1372 case RegionViewNameHighlight:
1373 if (!with_selection) {
1374 if (region_edit_menu_split_item) {
1375 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1376 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1378 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1382 if (region_edit_menu_split_multichannel_item) {
1383 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1384 // GTK2FIX find the action, change its sensitivity
1385 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1387 // GTK2FIX see above
1388 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1397 case CrossfadeViewItem:
1404 /* probably shouldn't happen but if it does, we don't care */
1408 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1410 /* Bounce to disk */
1412 using namespace Menu_Helpers;
1413 MenuList& edit_items = menu->items();
1415 edit_items.push_back (SeparatorElem());
1417 switch (clicked_routeview->audio_track()->freeze_state()) {
1418 case AudioTrack::NoFreeze:
1419 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1422 case AudioTrack::Frozen:
1423 edit_items.push_back (MenuElem (_("Unfreeze"), sigc::mem_fun(*this, &Editor::unfreeze_route)));
1426 case AudioTrack::UnFrozen:
1427 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1433 if (item_type == StreamItem && clicked_routeview) {
1434 clicked_routeview->build_underlay_menu(menu);
1437 menu->popup (button, time);
1441 Editor::build_track_context_menu (nframes64_t)
1443 using namespace Menu_Helpers;
1445 MenuList& edit_items = track_context_menu.items();
1448 add_dstream_context_items (edit_items);
1449 return &track_context_menu;
1453 Editor::build_track_bus_context_menu (nframes64_t)
1455 using namespace Menu_Helpers;
1457 MenuList& edit_items = track_context_menu.items();
1460 add_bus_context_items (edit_items);
1461 return &track_context_menu;
1465 Editor::build_track_region_context_menu (nframes64_t frame)
1467 using namespace Menu_Helpers;
1468 MenuList& edit_items = track_region_context_menu.items();
1471 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1474 boost::shared_ptr<Diskstream> ds;
1475 boost::shared_ptr<Playlist> pl;
1477 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1478 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1480 if (selection->regions.size() > 1) {
1481 // there's already a multiple selection: just add a
1482 // single region context menu that will act on all
1484 boost::shared_ptr<Region> dummy_region; // = NULL
1485 add_region_context_items (rtv->view(), dummy_region, edit_items);
1487 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1488 add_region_context_items (rtv->view(), (*i), edit_items);
1496 add_dstream_context_items (edit_items);
1498 return &track_region_context_menu;
1502 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1504 using namespace Menu_Helpers;
1505 MenuList& edit_items = track_crossfade_context_menu.items();
1506 edit_items.clear ();
1508 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1511 boost::shared_ptr<Diskstream> ds;
1512 boost::shared_ptr<Playlist> pl;
1513 boost::shared_ptr<AudioPlaylist> apl;
1515 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1517 Playlist::RegionList* regions = pl->regions_at (frame);
1518 AudioPlaylist::Crossfades xfades;
1520 apl->crossfades_at (frame, xfades);
1522 bool many = xfades.size() > 1;
1524 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1525 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1528 if (selection->regions.size() > 1) {
1529 // there's already a multiple selection: just add a
1530 // single region context menu that will act on all
1532 boost::shared_ptr<Region> dummy_region; // = NULL
1533 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1535 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1536 add_region_context_items (atv->audio_view(), (*i), edit_items);
1543 add_dstream_context_items (edit_items);
1545 return &track_crossfade_context_menu;
1549 Editor::analyze_region_selection()
1551 if (analysis_window == 0) {
1552 analysis_window = new AnalysisWindow();
1555 analysis_window->set_session(_session);
1557 analysis_window->show_all();
1560 analysis_window->set_regionmode();
1561 analysis_window->analyze();
1563 analysis_window->present();
1567 Editor::analyze_range_selection()
1569 if (analysis_window == 0) {
1570 analysis_window = new AnalysisWindow();
1573 analysis_window->set_session(_session);
1575 analysis_window->show_all();
1578 analysis_window->set_rangemode();
1579 analysis_window->analyze();
1581 analysis_window->present();
1585 Editor::build_track_selection_context_menu (nframes64_t)
1587 using namespace Menu_Helpers;
1588 MenuList& edit_items = track_selection_context_menu.items();
1589 edit_items.clear ();
1591 add_selection_context_items (edit_items);
1592 // edit_items.push_back (SeparatorElem());
1593 // add_dstream_context_items (edit_items);
1595 return &track_selection_context_menu;
1598 /** Add context menu items relevant to crossfades.
1599 * @param edit_items List to add the items to.
1602 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1604 using namespace Menu_Helpers;
1605 Menu *xfade_menu = manage (new Menu);
1606 MenuList& items = xfade_menu->items();
1607 xfade_menu->set_name ("ArdourContextMenu");
1610 if (xfade->active()) {
1616 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1617 items.push_back (MenuElem (_("Edit"), sigc::bind (sigc::mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1619 if (xfade->can_follow_overlap()) {
1621 if (xfade->following_overlap()) {
1622 str = _("Convert to short");
1624 str = _("Convert to full");
1627 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1631 str = xfade->out()->name();
1633 str += xfade->in()->name();
1635 str = _("Crossfade");
1638 edit_items.push_back (MenuElem (str, *xfade_menu));
1639 edit_items.push_back (SeparatorElem());
1643 Editor::xfade_edit_left_region ()
1645 if (clicked_crossfadeview) {
1646 clicked_crossfadeview->left_view.show_region_editor ();
1651 Editor::xfade_edit_right_region ()
1653 if (clicked_crossfadeview) {
1654 clicked_crossfadeview->right_view.show_region_editor ();
1659 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1661 using namespace Menu_Helpers;
1662 Gtk::MenuItem* foo_item;
1663 Menu *region_menu = manage (new Menu);
1664 MenuList& items = region_menu->items();
1665 region_menu->set_name ("ArdourContextMenu");
1667 boost::shared_ptr<AudioRegion> ar;
1668 boost::shared_ptr<MidiRegion> mr;
1671 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1672 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1674 /* when this particular menu pops up, make the relevant region
1678 region_menu->signal_map_event().connect (
1679 sigc::bind (sigc::mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1681 items.push_back (MenuElem (_("Rename"), sigc::mem_fun(*this, &Editor::rename_region)));
1682 if (mr && internal_editing()) {
1683 items.push_back (MenuElem (_("List editor..."), sigc::mem_fun(*this, &Editor::show_midi_list_editor)));
1685 items.push_back (MenuElem (_("Region editor"), sigc::mem_fun(*this, &Editor::edit_region)));
1689 items.push_back (MenuElem (_("Raise to top layer"), sigc::mem_fun(*this, &Editor::raise_region_to_top)));
1690 items.push_back (MenuElem (_("Lower to bottom layer"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom)));
1691 items.push_back (SeparatorElem());
1692 items.push_back (MenuElem (_("Define sync point"), sigc::mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1693 if (_edit_point == EditAtMouse) {
1694 items.back ().set_sensitive (false);
1696 items.push_back (MenuElem (_("Remove sync point"), sigc::mem_fun(*this, &Editor::remove_region_sync)));
1697 items.push_back (SeparatorElem());
1699 items.push_back (MenuElem (_("Audition"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1700 items.push_back (MenuElem (_("Export"), sigc::mem_fun(*this, &Editor::export_region)));
1701 items.push_back (MenuElem (_("Bounce"), sigc::mem_fun(*this, &Editor::bounce_region_selection)));
1704 items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_region_selection)));
1707 items.push_back (SeparatorElem());
1709 sigc::connection fooc;
1710 boost::shared_ptr<Region> region_to_check;
1713 region_to_check = region;
1715 region_to_check = selection->regions.front()->region();
1718 items.push_back (CheckMenuElem (_("Lock")));
1719 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1720 if (region_to_check->locked()) {
1721 region_lock_item->set_active();
1723 region_lock_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_lock));
1725 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1726 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1728 switch (region_to_check->positional_lock_style()) {
1729 case Region::MusicTime:
1730 bbt_glue_item->set_active (true);
1733 bbt_glue_item->set_active (false);
1737 bbt_glue_item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1739 items.push_back (CheckMenuElem (_("Mute")));
1740 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1741 fooc = region_mute_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_mute));
1742 if (region_to_check->muted()) {
1744 region_mute_item->set_active();
1748 if (!Profile->get_sae()) {
1749 items.push_back (CheckMenuElem (_("Opaque")));
1750 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1751 fooc = region_opaque_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_opaque));
1752 if (region_to_check->opaque()) {
1754 region_opaque_item->set_active();
1759 items.push_back (CheckMenuElem (_("Original position"), sigc::mem_fun(*this, &Editor::naturalize)));
1760 if (region_to_check->at_natural_position()) {
1761 items.back().set_sensitive (false);
1764 items.push_back (SeparatorElem());
1768 RegionView* rv = sv->find_view (ar);
1769 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1771 if (!Profile->get_sae()) {
1772 items.push_back (MenuElem (_("Reset Envelope"), sigc::mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1774 items.push_back (CheckMenuElem (_("Envelope Visible")));
1775 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1776 fooc = region_envelope_visible_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1777 if (arv->envelope_visible()) {
1779 region_envelope_visible_item->set_active (true);
1783 items.push_back (CheckMenuElem (_("Envelope Active")));
1784 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1785 fooc = region_envelope_active_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_active));
1787 if (ar->envelope_active()) {
1789 region_envelope_active_item->set_active (true);
1793 items.push_back (SeparatorElem());
1796 items.push_back (MenuElem (_("Normalize"), sigc::mem_fun(*this, &Editor::normalize_region)));
1797 if (ar->scale_amplitude() != 1) {
1798 items.push_back (MenuElem (_("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_scale_amplitude)));
1802 items.push_back (MenuElem (_("Quantize"), sigc::mem_fun(*this, &Editor::quantize_region)));
1803 items.push_back (SeparatorElem());
1806 items.push_back (MenuElem (_("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence)));
1807 items.push_back (MenuElem (_("Reverse"), sigc::mem_fun(*this, &Editor::reverse_region)));
1808 items.push_back (SeparatorElem());
1810 /* range related stuff */
1812 items.push_back (MenuElem (_("Add Single Range"), sigc::mem_fun (*this, &Editor::add_location_from_audio_region)));
1813 items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_locations_from_audio_region)));
1814 if (selection->regions.size() < 2) {
1815 items.back().set_sensitive (false);
1818 items.push_back (MenuElem (_("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region)));
1819 items.push_back (SeparatorElem());
1823 Menu *nudge_menu = manage (new Menu());
1824 MenuList& nudge_items = nudge_menu->items();
1825 nudge_menu->set_name ("ArdourContextMenu");
1827 nudge_items.push_back (MenuElem (_("Nudge fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_forward), false, false))));
1828 nudge_items.push_back (MenuElem (_("Nudge bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_backward), false, false))));
1829 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (sigc::mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1830 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (sigc::mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1832 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1833 items.push_back (SeparatorElem());
1835 Menu *trim_menu = manage (new Menu);
1836 MenuList& trim_items = trim_menu->items();
1837 trim_menu->set_name ("ArdourContextMenu");
1839 trim_items.push_back (MenuElem (_("Start to edit point"), sigc::mem_fun(*this, &Editor::trim_region_from_edit_point)));
1840 foo_item = &trim_items.back();
1841 if (_edit_point == EditAtMouse) {
1842 foo_item->set_sensitive (false);
1844 trim_items.push_back (MenuElem (_("Edit point to end"), sigc::mem_fun(*this, &Editor::trim_region_to_edit_point)));
1845 foo_item = &trim_items.back();
1846 if (_edit_point == EditAtMouse) {
1847 foo_item->set_sensitive (false);
1849 trim_items.push_back (MenuElem (_("Trim To Loop"), sigc::mem_fun(*this, &Editor::trim_region_to_loop)));
1850 trim_items.push_back (MenuElem (_("Trim To Punch"), sigc::mem_fun(*this, &Editor::trim_region_to_punch)));
1852 items.push_back (MenuElem (_("Trim"), *trim_menu));
1853 items.push_back (SeparatorElem());
1855 items.push_back (MenuElem (_("Split"), (sigc::mem_fun(*this, &Editor::split))));
1856 region_edit_menu_split_item = &items.back();
1858 if (_edit_point == EditAtMouse) {
1859 region_edit_menu_split_item->set_sensitive (false);
1862 items.push_back (MenuElem (_("Make mono regions"), (sigc::mem_fun(*this, &Editor::split_multichannel_region))));
1863 region_edit_menu_split_multichannel_item = &items.back();
1865 items.push_back (MenuElem (_("Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false))));
1866 items.push_back (MenuElem (_("Multi-Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), true))));
1867 items.push_back (MenuElem (_("Fill Track"), (sigc::mem_fun(*this, &Editor::region_fill_track))));
1868 items.push_back (SeparatorElem());
1869 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::remove_selected_regions)));
1871 /* OK, stick the region submenu at the top of the list, and then add
1875 /* we have to hack up the region name because "_" has a special
1876 meaning for menu titles.
1879 string::size_type pos = 0;
1880 string menu_item_name = (region) ? region->name() : _("Selected regions");
1882 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1883 menu_item_name.replace (pos, 1, "__");
1887 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1888 edit_items.push_back (SeparatorElem());
1891 /** Add context menu items relevant to selection ranges.
1892 * @param edit_items List to add the items to.
1895 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1897 using namespace Menu_Helpers;
1899 edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
1900 edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
1902 edit_items.push_back (SeparatorElem());
1903 edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
1905 if (!selection->regions.empty()) {
1906 edit_items.push_back (SeparatorElem());
1907 edit_items.push_back (MenuElem (_("Extend Range to End of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1908 edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1911 edit_items.push_back (SeparatorElem());
1912 edit_items.push_back (MenuElem (_("Silence Range"), sigc::mem_fun(*this, &Editor::separate_region_from_selection)));
1913 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
1915 edit_items.push_back (SeparatorElem());
1916 edit_items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1918 edit_items.push_back (SeparatorElem());
1919 edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false)));
1920 edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
1922 edit_items.push_back (SeparatorElem());
1923 edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
1925 edit_items.push_back (SeparatorElem());
1926 edit_items.push_back (MenuElem (_("Crop Region to Range"), sigc::mem_fun(*this, &Editor::crop_region_to_selection)));
1927 edit_items.push_back (MenuElem (_("Fill Range with Region"), sigc::mem_fun(*this, &Editor::region_fill_selection)));
1928 edit_items.push_back (MenuElem (_("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false)));
1930 edit_items.push_back (SeparatorElem());
1931 edit_items.push_back (MenuElem (_("Consolidate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1932 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1933 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1934 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1935 edit_items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_range)));
1940 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1942 using namespace Menu_Helpers;
1946 Menu *play_menu = manage (new Menu);
1947 MenuList& play_items = play_menu->items();
1948 play_menu->set_name ("ArdourContextMenu");
1950 play_items.push_back (MenuElem (_("Play from edit point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
1951 play_items.push_back (MenuElem (_("Play from start"), sigc::mem_fun(*this, &Editor::play_from_start)));
1952 play_items.push_back (MenuElem (_("Play region"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1953 play_items.push_back (SeparatorElem());
1954 play_items.push_back (MenuElem (_("Loop Region"), sigc::mem_fun(*this, &Editor::loop_selected_region)));
1956 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1960 Menu *select_menu = manage (new Menu);
1961 MenuList& select_items = select_menu->items();
1962 select_menu->set_name ("ArdourContextMenu");
1964 select_items.push_back (MenuElem (_("Select All in track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1965 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
1966 select_items.push_back (MenuElem (_("Invert selection in track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
1967 select_items.push_back (MenuElem (_("Invert selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
1968 select_items.push_back (SeparatorElem());
1969 select_items.push_back (MenuElem (_("Set range to loop range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop)));
1970 select_items.push_back (MenuElem (_("Set range to punch range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch)));
1971 select_items.push_back (SeparatorElem());
1972 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1973 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1974 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1975 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1976 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
1977 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
1978 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
1980 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1984 Menu *cutnpaste_menu = manage (new Menu);
1985 MenuList& cutnpaste_items = cutnpaste_menu->items();
1986 cutnpaste_menu->set_name ("ArdourContextMenu");
1988 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
1989 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
1990 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
1992 cutnpaste_items.push_back (SeparatorElem());
1994 cutnpaste_items.push_back (MenuElem (_("Align"), sigc::bind (sigc::mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
1995 cutnpaste_items.push_back (MenuElem (_("Align Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
1997 cutnpaste_items.push_back (SeparatorElem());
1999 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2001 /* Adding new material */
2003 edit_items.push_back (SeparatorElem());
2004 edit_items.push_back (MenuElem (_("Insert Selected Region"), sigc::bind (sigc::mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2005 edit_items.push_back (MenuElem (_("Insert Existing Media"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2009 Menu *nudge_menu = manage (new Menu());
2010 MenuList& nudge_items = nudge_menu->items();
2011 nudge_menu->set_name ("ArdourContextMenu");
2013 edit_items.push_back (SeparatorElem());
2014 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2015 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2016 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2017 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2019 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2023 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2025 using namespace Menu_Helpers;
2029 Menu *play_menu = manage (new Menu);
2030 MenuList& play_items = play_menu->items();
2031 play_menu->set_name ("ArdourContextMenu");
2033 play_items.push_back (MenuElem (_("Play from edit point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
2034 play_items.push_back (MenuElem (_("Play from start"), sigc::mem_fun(*this, &Editor::play_from_start)));
2035 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2039 Menu *select_menu = manage (new Menu);
2040 MenuList& select_items = select_menu->items();
2041 select_menu->set_name ("ArdourContextMenu");
2043 select_items.push_back (MenuElem (_("Select All in track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2044 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
2045 select_items.push_back (MenuElem (_("Invert selection in track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
2046 select_items.push_back (MenuElem (_("Invert selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
2047 select_items.push_back (SeparatorElem());
2048 select_items.push_back (MenuElem (_("Select all after edit point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2049 select_items.push_back (MenuElem (_("Select all before edit point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2050 select_items.push_back (MenuElem (_("Select all after playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2051 select_items.push_back (MenuElem (_("Select all before playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2053 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2057 Menu *cutnpaste_menu = manage (new Menu);
2058 MenuList& cutnpaste_items = cutnpaste_menu->items();
2059 cutnpaste_menu->set_name ("ArdourContextMenu");
2061 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2062 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2063 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2065 Menu *nudge_menu = manage (new Menu());
2066 MenuList& nudge_items = nudge_menu->items();
2067 nudge_menu->set_name ("ArdourContextMenu");
2069 edit_items.push_back (SeparatorElem());
2070 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2071 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2072 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2073 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2075 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2079 Editor::snap_type() const
2085 Editor::snap_mode() const
2091 Editor::set_snap_to (SnapType st)
2093 unsigned int snap_ind = (unsigned int)st;
2097 if (snap_ind > snap_type_strings.size() - 1) {
2099 _snap_type = (SnapType)snap_ind;
2102 string str = snap_type_strings[snap_ind];
2104 if (str != snap_type_selector.get_active_text()) {
2105 snap_type_selector.set_active_text (str);
2110 switch (_snap_type) {
2111 case SnapToAThirtysecondBeat:
2112 case SnapToASixteenthBeat:
2113 case SnapToAEighthBeat:
2114 case SnapToAQuarterBeat:
2115 case SnapToAThirdBeat:
2116 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2117 update_tempo_based_rulers ();
2120 case SnapToRegionStart:
2121 case SnapToRegionEnd:
2122 case SnapToRegionSync:
2123 case SnapToRegionBoundary:
2124 build_region_boundary_cache ();
2134 Editor::set_snap_mode (SnapMode mode)
2137 string str = snap_mode_strings[(int)mode];
2139 if (str != snap_mode_selector.get_active_text ()) {
2140 snap_mode_selector.set_active_text (str);
2146 Editor::set_edit_point_preference (EditPoint ep, bool force)
2148 bool changed = (_edit_point != ep);
2151 string str = edit_point_strings[(int)ep];
2153 if (str != edit_point_selector.get_active_text ()) {
2154 edit_point_selector.set_active_text (str);
2157 set_canvas_cursor ();
2159 if (!force && !changed) {
2163 const char* action=NULL;
2165 switch (_edit_point) {
2166 case EditAtPlayhead:
2167 action = "edit-at-playhead";
2169 case EditAtSelectedMarker:
2170 action = "edit-at-marker";
2173 action = "edit-at-mouse";
2177 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2179 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2183 bool in_track_canvas;
2185 if (!mouse_frame (foo, in_track_canvas)) {
2186 in_track_canvas = false;
2189 reset_canvas_action_sensitivity (in_track_canvas);
2195 Editor::set_state (const XMLNode& node, int /*version*/)
2197 const XMLProperty* prop;
2199 int x, y, xoff, yoff;
2202 if ((prop = node.property ("id")) != 0) {
2203 _id = prop->value ();
2206 g.base_width = default_width;
2207 g.base_height = default_height;
2213 if ((geometry = find_named_node (node, "geometry")) != 0) {
2217 if ((prop = geometry->property("x_size")) == 0) {
2218 prop = geometry->property ("x-size");
2221 g.base_width = atoi(prop->value());
2223 if ((prop = geometry->property("y_size")) == 0) {
2224 prop = geometry->property ("y-size");
2227 g.base_height = atoi(prop->value());
2230 if ((prop = geometry->property ("x_pos")) == 0) {
2231 prop = geometry->property ("x-pos");
2234 x = atoi (prop->value());
2237 if ((prop = geometry->property ("y_pos")) == 0) {
2238 prop = geometry->property ("y-pos");
2241 y = atoi (prop->value());
2244 if ((prop = geometry->property ("x_off")) == 0) {
2245 prop = geometry->property ("x-off");
2248 xoff = atoi (prop->value());
2250 if ((prop = geometry->property ("y_off")) == 0) {
2251 prop = geometry->property ("y-off");
2254 yoff = atoi (prop->value());
2258 set_default_size (g.base_width, g.base_height);
2261 if (_session && (prop = node.property ("playhead"))) {
2262 nframes64_t pos = atol (prop->value().c_str());
2263 playhead_cursor->set_position (pos);
2265 playhead_cursor->set_position (0);
2268 if ((prop = node.property ("mixer-width"))) {
2269 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2272 if ((prop = node.property ("zoom-focus"))) {
2273 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2276 if ((prop = node.property ("zoom"))) {
2277 reset_zoom (PBD::atof (prop->value()));
2280 if ((prop = node.property ("snap-to"))) {
2281 set_snap_to ((SnapType) atoi (prop->value()));
2284 if ((prop = node.property ("snap-mode"))) {
2285 set_snap_mode ((SnapMode) atoi (prop->value()));
2288 if ((prop = node.property ("mouse-mode"))) {
2289 MouseMode m = str2mousemode(prop->value());
2290 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2291 set_mouse_mode (m, true);
2293 mouse_mode = MouseGain; /* lie, to force the mode switch */
2294 set_mouse_mode (MouseObject, true);
2297 if ((prop = node.property ("left-frame")) != 0){
2299 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
2300 reset_x_origin (pos);
2301 /* this hack prevents the initial call to update_current_screen() from doing re-centering on the playhead */
2302 last_update_frame = pos;
2306 if ((prop = node.property ("internal-edit"))) {
2307 bool yn = string_is_affirmative (prop->value());
2308 RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit"));
2310 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2311 tact->set_active (!yn);
2312 tact->set_active (yn);
2316 if ((prop = node.property ("edit-point"))) {
2317 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2320 if ((prop = node.property ("show-waveforms-recording"))) {
2321 bool yn = string_is_affirmative (prop->value());
2322 _show_waveforms_recording = !yn;
2323 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2325 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2326 /* do it twice to force the change */
2327 tact->set_active (!yn);
2328 tact->set_active (yn);
2332 if ((prop = node.property ("show-measures"))) {
2333 bool yn = string_is_affirmative (prop->value());
2334 _show_measures = !yn;
2335 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2337 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2338 /* do it twice to force the change */
2339 tact->set_active (!yn);
2340 tact->set_active (yn);
2344 if ((prop = node.property ("follow-playhead"))) {
2345 bool yn = string_is_affirmative (prop->value());
2346 set_follow_playhead (yn);
2347 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2349 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2350 if (tact->get_active() != yn) {
2351 tact->set_active (yn);
2356 if ((prop = node.property ("region-list-sort-type"))) {
2357 _regions->reset_sort_type (str2regionlistsorttype(prop->value()), true);
2360 if ((prop = node.property ("xfades-visible"))) {
2361 bool yn = string_is_affirmative (prop->value());
2362 _xfade_visibility = !yn;
2363 // set_xfade_visibility (yn);
2366 if ((prop = node.property ("show-editor-mixer"))) {
2368 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2371 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2372 bool yn = string_is_affirmative (prop->value());
2374 /* do it twice to force the change */
2376 tact->set_active (!yn);
2377 tact->set_active (yn);
2381 if ((prop = node.property ("show-editor-list"))) {
2383 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2387 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2388 bool yn = string_is_affirmative (prop->value());
2390 /* do it twice to force the change */
2392 tact->set_active (!yn);
2393 tact->set_active (yn);
2402 Editor::get_state ()
2404 XMLNode* node = new XMLNode ("Editor");
2407 _id.print (buf, sizeof (buf));
2408 node->add_property ("id", buf);
2410 if (is_realized()) {
2411 Glib::RefPtr<Gdk::Window> win = get_window();
2413 int x, y, xoff, yoff, width, height;
2414 win->get_root_origin(x, y);
2415 win->get_position(xoff, yoff);
2416 win->get_size(width, height);
2418 XMLNode* geometry = new XMLNode ("geometry");
2420 snprintf(buf, sizeof(buf), "%d", width);
2421 geometry->add_property("x-size", string(buf));
2422 snprintf(buf, sizeof(buf), "%d", height);
2423 geometry->add_property("y-size", string(buf));
2424 snprintf(buf, sizeof(buf), "%d", x);
2425 geometry->add_property("x-pos", string(buf));
2426 snprintf(buf, sizeof(buf), "%d", y);
2427 geometry->add_property("y-pos", string(buf));
2428 snprintf(buf, sizeof(buf), "%d", xoff);
2429 geometry->add_property("x-off", string(buf));
2430 snprintf(buf, sizeof(buf), "%d", yoff);
2431 geometry->add_property("y-off", string(buf));
2432 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2433 geometry->add_property("edit_pane_pos", string(buf));
2435 node->add_child_nocopy (*geometry);
2438 maybe_add_mixer_strip_width (*node);
2440 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2441 node->add_property ("zoom-focus", buf);
2442 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2443 node->add_property ("zoom", buf);
2444 snprintf (buf, sizeof(buf), "%d", (int) _snap_type);
2445 node->add_property ("snap-to", buf);
2446 snprintf (buf, sizeof(buf), "%d", (int) _snap_mode);
2447 node->add_property ("snap-mode", buf);
2449 node->add_property ("edit-point", enum_2_string (_edit_point));
2451 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2452 node->add_property ("playhead", buf);
2453 snprintf (buf, sizeof (buf), "%" PRIi64, leftmost_frame);
2454 node->add_property ("left-frame", buf);
2456 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2457 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2458 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2459 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2460 node->add_property ("region-list-sort-type", enum2str (_regions->sort_type ()));
2461 node->add_property ("mouse-mode", enum2str(mouse_mode));
2462 node->add_property ("internal-edit", _internal_editing ? "yes" : "no");
2464 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2466 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2467 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2470 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2472 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2473 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2481 /** @param y y offset from the top of all trackviews.
2482 * @return pair: TimeAxisView that y is over, layer index.
2483 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2484 * in stacked region display mode, otherwise 0.
2486 std::pair<TimeAxisView *, layer_t>
2487 Editor::trackview_by_y_position (double y)
2489 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2491 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2497 return std::make_pair ( (TimeAxisView *) 0, 0);
2500 /** Snap a position to the grid, if appropriate, taking into account current
2501 * grid settings and also the state of any snap modifier keys that may be pressed.
2502 * @param start Position to snap.
2503 * @param event Event to get current key modifier information from, or 0.
2506 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2508 if (!_session || !event) {
2512 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2513 if (_snap_mode == SnapOff) {
2514 snap_to_internal (start, direction, for_mark);
2517 if (_snap_mode != SnapOff) {
2518 snap_to_internal (start, direction, for_mark);
2524 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2526 if (!_session || _snap_mode == SnapOff) {
2530 snap_to_internal (start, direction, for_mark);
2534 Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
2536 const nframes64_t one_timecode_second = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
2537 nframes64_t one_timecode_minute = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
2539 switch (_snap_type) {
2540 case SnapToTimecodeFrame:
2541 if (((direction == 0) && (fmod((double)start, (double)_session->frames_per_timecode_frame()) > (_session->frames_per_timecode_frame() / 2))) || (direction > 0)) {
2542 start = (nframes64_t) (ceil ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2544 start = (nframes64_t) (floor ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2548 case SnapToTimecodeSeconds:
2549 if (_session->timecode_offset_negative())
2551 start += _session->timecode_offset ();
2553 start -= _session->timecode_offset ();
2555 if (((direction == 0) && (start % one_timecode_second > one_timecode_second / 2)) || direction > 0) {
2556 start = (nframes64_t) ceil ((double) start / one_timecode_second) * one_timecode_second;
2558 start = (nframes64_t) floor ((double) start / one_timecode_second) * one_timecode_second;
2561 if (_session->timecode_offset_negative())
2563 start -= _session->timecode_offset ();
2565 start += _session->timecode_offset ();
2569 case SnapToTimecodeMinutes:
2570 if (_session->timecode_offset_negative())
2572 start += _session->timecode_offset ();
2574 start -= _session->timecode_offset ();
2576 if (((direction == 0) && (start % one_timecode_minute > one_timecode_minute / 2)) || direction > 0) {
2577 start = (nframes64_t) ceil ((double) start / one_timecode_minute) * one_timecode_minute;
2579 start = (nframes64_t) floor ((double) start / one_timecode_minute) * one_timecode_minute;
2581 if (_session->timecode_offset_negative())
2583 start -= _session->timecode_offset ();
2585 start += _session->timecode_offset ();
2589 fatal << "Editor::smpte_snap_to_internal() called with non-timecode snap type!" << endmsg;
2595 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2597 const nframes64_t one_second = _session->frame_rate();
2598 const nframes64_t one_minute = _session->frame_rate() * 60;
2599 nframes64_t presnap = start;
2603 switch (_snap_type) {
2604 case SnapToTimecodeFrame:
2605 case SnapToTimecodeSeconds:
2606 case SnapToTimecodeMinutes:
2607 return timecode_snap_to_internal (start, direction, for_mark);
2610 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2611 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2613 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2618 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2619 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2621 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2626 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2627 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2629 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2634 start = _session->tempo_map().round_to_bar (start, direction);
2638 start = _session->tempo_map().round_to_beat (start, direction);
2641 case SnapToAThirtysecondBeat:
2642 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2645 case SnapToASixteenthBeat:
2646 start = _session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2649 case SnapToAEighthBeat:
2650 start = _session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2653 case SnapToAQuarterBeat:
2654 start = _session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2657 case SnapToAThirdBeat:
2658 start = _session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2666 _session->locations()->marks_either_side (start, before, after);
2668 if (before == max_frames) {
2670 } else if (after == max_frames) {
2672 } else if (before != max_frames && after != max_frames) {
2673 /* have before and after */
2674 if ((start - before) < (after - start)) {
2683 case SnapToRegionStart:
2684 case SnapToRegionEnd:
2685 case SnapToRegionSync:
2686 case SnapToRegionBoundary:
2687 if (!region_boundary_cache.empty()) {
2689 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2690 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2692 if (direction > 0) {
2693 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2695 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2698 if (next != region_boundary_cache.begin ()) {
2703 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2704 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2706 if (start > (p + n) / 2) {
2715 switch (_snap_mode) {
2721 if (presnap > start) {
2722 if (presnap > (start + unit_to_frame(snap_threshold))) {
2726 } else if (presnap < start) {
2727 if (presnap < (start - unit_to_frame(snap_threshold))) {
2733 /* handled at entry */
2741 Editor::setup_toolbar ()
2745 /* Mode Buttons (tool selection) */
2747 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2748 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2749 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2750 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2751 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2752 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2753 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2755 HBox* mode_box = manage(new HBox);
2756 mode_box->set_border_width (2);
2757 mode_box->set_spacing(4);
2758 mouse_mode_button_box.set_spacing(1);
2759 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2760 if (!Profile->get_sae()) {
2761 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2763 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2764 if (!Profile->get_sae()) {
2765 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2767 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2768 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2769 mouse_mode_button_box.pack_start(internal_edit_button, true, true);
2770 mouse_mode_button_box.set_homogeneous(true);
2772 vector<string> edit_mode_strings;
2773 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2774 if (!Profile->get_sae()) {
2775 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2777 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2779 edit_mode_selector.set_name ("EditModeSelector");
2780 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2781 edit_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_mode_selection_done));
2783 mode_box->pack_start(edit_mode_selector);
2784 mode_box->pack_start(mouse_mode_button_box);
2786 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2787 mouse_mode_tearoff->set_name ("MouseModeBase");
2788 mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &mouse_mode_tearoff->tearoff_window()), false);
2790 if (Profile->get_sae()) {
2791 mouse_mode_tearoff->set_can_be_torn_off (false);
2794 mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2795 &mouse_mode_tearoff->tearoff_window()));
2796 mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2797 &mouse_mode_tearoff->tearoff_window(), 1));
2798 mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2799 &mouse_mode_tearoff->tearoff_window()));
2800 mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2801 &mouse_mode_tearoff->tearoff_window(), 1));
2803 mouse_move_button.set_mode (false);
2804 mouse_select_button.set_mode (false);
2805 mouse_gain_button.set_mode (false);
2806 mouse_zoom_button.set_mode (false);
2807 mouse_timefx_button.set_mode (false);
2808 mouse_audition_button.set_mode (false);
2810 mouse_move_button.set_name ("MouseModeButton");
2811 mouse_select_button.set_name ("MouseModeButton");
2812 mouse_gain_button.set_name ("MouseModeButton");
2813 mouse_zoom_button.set_name ("MouseModeButton");
2814 mouse_timefx_button.set_name ("MouseModeButton");
2815 mouse_audition_button.set_name ("MouseModeButton");
2817 internal_edit_button.set_name ("MouseModeButton");
2819 mouse_move_button.unset_flags (CAN_FOCUS);
2820 mouse_select_button.unset_flags (CAN_FOCUS);
2821 mouse_gain_button.unset_flags (CAN_FOCUS);
2822 mouse_zoom_button.unset_flags (CAN_FOCUS);
2823 mouse_timefx_button.unset_flags (CAN_FOCUS);
2824 mouse_audition_button.unset_flags (CAN_FOCUS);
2825 internal_edit_button.unset_flags (CAN_FOCUS);
2829 zoom_box.set_spacing (1);
2830 zoom_box.set_border_width (0);
2832 zoom_in_button.set_name ("EditorTimeButton");
2833 zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_BUTTON))));
2834 zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
2835 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2837 zoom_out_button.set_name ("EditorTimeButton");
2838 zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_BUTTON))));
2839 zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
2840 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2842 zoom_out_full_button.set_name ("EditorTimeButton");
2843 zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_BUTTON))));
2844 zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
2845 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2847 zoom_focus_selector.set_name ("ZoomFocusSelector");
2848 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2849 zoom_focus_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done));
2850 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2852 zoom_box.pack_start (zoom_out_button, false, false);
2853 zoom_box.pack_start (zoom_in_button, false, false);
2854 zoom_box.pack_start (zoom_out_full_button, false, false);
2856 /* Track zoom buttons */
2857 tav_expand_button.set_name ("TrackHeightButton");
2858 tav_expand_button.set_size_request(-1,20);
2859 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2860 tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
2861 ARDOUR_UI::instance()->tooltips().set_tip (tav_expand_button, _("Expand Tracks"));
2863 tav_shrink_button.set_name ("TrackHeightButton");
2864 tav_shrink_button.set_size_request(-1,20);
2865 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2866 tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
2867 ARDOUR_UI::instance()->tooltips().set_tip (tav_shrink_button, _("Shrink Tracks"));
2869 track_zoom_box.set_spacing (1);
2870 track_zoom_box.set_border_width (0);
2872 track_zoom_box.pack_start (tav_shrink_button, false, false);
2873 track_zoom_box.pack_start (tav_expand_button, false, false);
2875 HBox* zbc = manage (new HBox);
2876 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2877 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2878 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2879 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2881 snap_box.set_spacing (1);
2882 snap_box.set_border_width (2);
2884 snap_type_selector.set_name ("SnapTypeSelector");
2885 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2886 snap_type_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_type_selection_done));
2887 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2889 snap_mode_selector.set_name ("SnapModeSelector");
2890 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2891 snap_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_mode_selection_done));
2892 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2894 edit_point_selector.set_name ("EditPointSelector");
2895 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2896 edit_point_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_point_selection_done));
2897 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2899 snap_box.pack_start (snap_mode_selector, false, false);
2900 snap_box.pack_start (snap_type_selector, false, false);
2901 snap_box.pack_start (edit_point_selector, false, false);
2905 HBox *nudge_box = manage (new HBox);
2906 nudge_box->set_spacing(1);
2907 nudge_box->set_border_width (2);
2909 nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
2910 nudge_backward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_backward_release), false);
2912 nudge_box->pack_start (nudge_backward_button, false, false);
2913 nudge_box->pack_start (nudge_forward_button, false, false);
2914 nudge_box->pack_start (nudge_clock, false, false);
2917 /* Pack everything in... */
2919 HBox* hbox = manage (new HBox);
2920 hbox->set_spacing(10);
2922 tools_tearoff = manage (new TearOff (*hbox));
2923 tools_tearoff->set_name ("MouseModeBase");
2924 tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &tools_tearoff->tearoff_window()), false);
2926 if (Profile->get_sae()) {
2927 tools_tearoff->set_can_be_torn_off (false);
2930 tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2931 &tools_tearoff->tearoff_window()));
2932 tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2933 &tools_tearoff->tearoff_window(), 0));
2934 tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2935 &tools_tearoff->tearoff_window()));
2936 tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2937 &tools_tearoff->tearoff_window(), 0));
2939 toolbar_hbox.set_spacing (10);
2940 toolbar_hbox.set_border_width (1);
2942 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2943 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2945 hbox->pack_start (snap_box, false, false);
2946 hbox->pack_start (*nudge_box, false, false);
2947 hbox->pack_start (panic_box, false, false);
2951 toolbar_base.set_name ("ToolBarBase");
2952 toolbar_base.add (toolbar_hbox);
2954 toolbar_frame.set_shadow_type (SHADOW_OUT);
2955 toolbar_frame.set_name ("BaseFrame");
2956 toolbar_frame.add (toolbar_base);
2960 Editor::midi_panic ()
2962 cerr << "MIDI panic\n";
2965 _session->midi_panic();
2970 Editor::setup_midi_toolbar ()
2974 /* Midi sound notes */
2975 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
2976 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
2977 ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes"));
2978 midi_sound_notes.unset_flags (CAN_FOCUS);
2982 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
2983 midi_panic_button.set_name("MidiPanicButton");
2984 ARDOUR_UI::instance()->tooltips().set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
2985 act->connect_proxy (midi_panic_button);
2987 panic_box.pack_start (midi_sound_notes , true, true);
2988 panic_box.pack_start (midi_panic_button, true, true);
2992 Editor::convert_drop_to_paths (
2993 vector<ustring>& paths,
2994 const RefPtr<Gdk::DragContext>& /*context*/,
2997 const SelectionData& data,
3001 if (_session == 0) {
3005 vector<ustring> uris = data.get_uris();
3009 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3010 are actually URI lists. So do it by hand.
3013 if (data.get_target() != "text/plain") {
3017 /* Parse the "uri-list" format that Nautilus provides,
3018 where each pathname is delimited by \r\n.
3020 THERE MAY BE NO NULL TERMINATING CHAR!!!
3023 ustring txt = data.get_text();
3027 p = (const char *) malloc (txt.length() + 1);
3028 txt.copy ((char *) p, txt.length(), 0);
3029 ((char*)p)[txt.length()] = '\0';
3035 while (g_ascii_isspace (*p))
3039 while (*q && (*q != '\n') && (*q != '\r')) {
3046 while (q > p && g_ascii_isspace (*q))
3051 uris.push_back (ustring (p, q - p + 1));
3055 p = strchr (p, '\n');
3067 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3069 if ((*i).substr (0,7) == "file://") {
3072 PBD::url_decode (p);
3074 // scan forward past three slashes
3076 ustring::size_type slashcnt = 0;
3077 ustring::size_type n = 0;
3078 ustring::iterator x = p.begin();
3080 while (slashcnt < 3 && x != p.end()) {
3083 } else if (slashcnt == 3) {
3090 if (slashcnt != 3 || x == p.end()) {
3091 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3095 paths.push_back (p.substr (n - 1));
3103 Editor::new_tempo_section ()
3109 Editor::map_transport_state ()
3111 ENSURE_GUI_THREAD (*this, &Editor::map_transport_state)
3113 if (_session->transport_stopped()) {
3114 have_pending_keyboard_selection = false;
3117 update_loop_range_view (true);
3122 Editor::State::State (PublicEditor const * e)
3124 selection = new Selection (e);
3127 Editor::State::~State ()
3133 Editor::begin_reversible_command (string name)
3136 before = &get_state();
3137 _session->begin_reversible_command (name);
3142 Editor::commit_reversible_command ()
3145 _session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3150 Editor::set_route_group_solo (Route& route, bool yn)
3152 RouteGroup *route_group;
3154 if ((route_group = route.route_group()) != 0) {
3155 route_group->apply (&Route::set_solo, yn, this);
3157 route.set_solo (yn, this);
3162 Editor::set_route_group_mute (Route& route, bool yn)
3164 RouteGroup *route_group = 0;
3166 if ((route_group == route.route_group()) != 0) {
3167 route_group->apply (&Route::set_mute, yn, this);
3169 route.set_mute (yn, this);
3174 Editor::history_changed ()
3178 if (undo_action && _session) {
3179 if (_session->undo_depth() == 0) {
3182 label = string_compose(_("Undo (%1)"), _session->next_undo());
3184 undo_action->property_label() = label;
3187 if (redo_action && _session) {
3188 if (_session->redo_depth() == 0) {
3191 label = string_compose(_("Redo (%1)"), _session->next_redo());
3193 redo_action->property_label() = label;
3198 Editor::duplicate_dialog (bool with_dialog)
3202 if (mouse_mode == MouseRange) {
3203 if (selection->time.length() == 0) {
3209 get_regions_for_action (rs);
3211 if (mouse_mode != MouseRange) {
3220 ArdourDialog win ("Duplicate");
3221 Label label (_("Number of Duplications:"));
3222 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3223 SpinButton spinner (adjustment, 0.0, 1);
3226 win.get_vbox()->set_spacing (12);
3227 win.get_vbox()->pack_start (hbox);
3228 hbox.set_border_width (6);
3229 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3231 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3232 place, visually. so do this by hand.
3235 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3236 spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3237 spinner.grab_focus();
3243 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3244 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3245 win.set_default_response (RESPONSE_ACCEPT);
3247 win.set_position (WIN_POS_MOUSE);
3249 spinner.grab_focus ();
3251 switch (win.run ()) {
3252 case RESPONSE_ACCEPT:
3258 times = adjustment.get_value();
3261 if (mouse_mode == MouseRange) {
3262 duplicate_selection (times);
3264 duplicate_some_regions (rs, times);
3269 Editor::show_verbose_canvas_cursor ()
3271 verbose_canvas_cursor->raise_to_top();
3272 verbose_canvas_cursor->show();
3273 verbose_cursor_visible = true;
3277 Editor::hide_verbose_canvas_cursor ()
3279 verbose_canvas_cursor->hide();
3280 verbose_cursor_visible = false;
3284 Editor::clamp_verbose_cursor_x (double x)
3289 x = min (_canvas_width - 200.0, x);
3295 Editor::clamp_verbose_cursor_y (double y)
3297 if (y < canvas_timebars_vsize) {
3298 y = canvas_timebars_vsize;
3300 y = min (_canvas_height - 50, y);
3306 Editor::show_verbose_canvas_cursor_with (const string & txt)
3308 verbose_canvas_cursor->property_text() = txt.c_str();
3313 track_canvas->get_pointer (x, y);
3314 track_canvas->window_to_world (x, y, wx, wy);
3316 /* don't get too close to the edge */
3317 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3318 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3320 show_verbose_canvas_cursor ();
3324 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3326 verbose_canvas_cursor->property_text() = txt.c_str();
3327 /* don't get too close to the edge */
3328 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3329 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3333 Editor::set_verbose_canvas_cursor_text (const string & txt)
3335 verbose_canvas_cursor->property_text() = txt.c_str();
3339 Editor::set_edit_mode (EditMode m)
3341 Config->set_edit_mode (m);
3345 Editor::cycle_edit_mode ()
3347 switch (Config->get_edit_mode()) {
3349 if (Profile->get_sae()) {
3350 Config->set_edit_mode (Lock);
3352 Config->set_edit_mode (Splice);
3356 Config->set_edit_mode (Lock);
3359 Config->set_edit_mode (Slide);
3365 Editor::edit_mode_selection_done ()
3367 if (_session == 0) {
3371 string choice = edit_mode_selector.get_active_text();
3372 EditMode mode = Slide;
3374 if (choice == _("Splice Edit")) {
3376 } else if (choice == _("Slide Edit")) {
3378 } else if (choice == _("Lock Edit")) {
3382 Config->set_edit_mode (mode);
3386 Editor::snap_type_selection_done ()
3388 string choice = snap_type_selector.get_active_text();
3389 SnapType snaptype = SnapToBeat;
3391 if (choice == _("Beats/3")) {
3392 snaptype = SnapToAThirdBeat;
3393 } else if (choice == _("Beats/4")) {
3394 snaptype = SnapToAQuarterBeat;
3395 } else if (choice == _("Beats/8")) {
3396 snaptype = SnapToAEighthBeat;
3397 } else if (choice == _("Beats/16")) {
3398 snaptype = SnapToASixteenthBeat;
3399 } else if (choice == _("Beats/32")) {
3400 snaptype = SnapToAThirtysecondBeat;
3401 } else if (choice == _("Beats")) {
3402 snaptype = SnapToBeat;
3403 } else if (choice == _("Bars")) {
3404 snaptype = SnapToBar;
3405 } else if (choice == _("Marks")) {
3406 snaptype = SnapToMark;
3407 } else if (choice == _("Region starts")) {
3408 snaptype = SnapToRegionStart;
3409 } else if (choice == _("Region ends")) {
3410 snaptype = SnapToRegionEnd;
3411 } else if (choice == _("Region bounds")) {
3412 snaptype = SnapToRegionBoundary;
3413 } else if (choice == _("Region syncs")) {
3414 snaptype = SnapToRegionSync;
3415 } else if (choice == _("CD Frames")) {
3416 snaptype = SnapToCDFrame;
3417 } else if (choice == _("Timecode Frames")) {
3418 snaptype = SnapToTimecodeFrame;
3419 } else if (choice == _("Timecode Seconds")) {
3420 snaptype = SnapToTimecodeSeconds;
3421 } else if (choice == _("Timecode Minutes")) {
3422 snaptype = SnapToTimecodeMinutes;
3423 } else if (choice == _("Seconds")) {
3424 snaptype = SnapToSeconds;
3425 } else if (choice == _("Minutes")) {
3426 snaptype = SnapToMinutes;
3429 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3431 ract->set_active ();
3436 Editor::snap_mode_selection_done ()
3438 string choice = snap_mode_selector.get_active_text();
3439 SnapMode mode = SnapNormal;
3441 if (choice == _("No Grid")) {
3443 } else if (choice == _("Grid")) {
3445 } else if (choice == _("Magnetic")) {
3446 mode = SnapMagnetic;
3449 RefPtr<RadioAction> ract = snap_mode_action (mode);
3452 ract->set_active (true);
3457 Editor::cycle_edit_point (bool with_marker)
3459 switch (_edit_point) {
3461 set_edit_point_preference (EditAtPlayhead);
3463 case EditAtPlayhead:
3465 set_edit_point_preference (EditAtSelectedMarker);
3467 set_edit_point_preference (EditAtMouse);
3470 case EditAtSelectedMarker:
3471 set_edit_point_preference (EditAtMouse);
3477 Editor::edit_point_selection_done ()
3479 string choice = edit_point_selector.get_active_text();
3480 EditPoint ep = EditAtSelectedMarker;
3482 if (choice == _("Marker")) {
3483 set_edit_point_preference (EditAtSelectedMarker);
3484 } else if (choice == _("Playhead")) {
3485 set_edit_point_preference (EditAtPlayhead);
3487 set_edit_point_preference (EditAtMouse);
3490 RefPtr<RadioAction> ract = edit_point_action (ep);
3493 ract->set_active (true);
3498 Editor::zoom_focus_selection_done ()
3500 string choice = zoom_focus_selector.get_active_text();
3501 ZoomFocus focus_type = ZoomFocusLeft;
3503 if (choice == _("Left")) {
3504 focus_type = ZoomFocusLeft;
3505 } else if (choice == _("Right")) {
3506 focus_type = ZoomFocusRight;
3507 } else if (choice == _("Center")) {
3508 focus_type = ZoomFocusCenter;
3509 } else if (choice == _("Playhead")) {
3510 focus_type = ZoomFocusPlayhead;
3511 } else if (choice == _("Mouse")) {
3512 focus_type = ZoomFocusMouse;
3513 } else if (choice == _("Edit point")) {
3514 focus_type = ZoomFocusEdit;
3517 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3520 ract->set_active ();
3525 Editor::edit_controls_button_release (GdkEventButton* ev)
3527 if (Keyboard::is_context_menu_event (ev)) {
3528 ARDOUR_UI::instance()->add_route (this);
3534 Editor::mouse_select_button_release (GdkEventButton* ev)
3536 /* this handles just right-clicks */
3538 if (ev->button != 3) {
3546 Editor::set_zoom_focus (ZoomFocus f)
3548 string str = zoom_focus_strings[(int)f];
3550 if (str != zoom_focus_selector.get_active_text()) {
3551 zoom_focus_selector.set_active_text (str);
3554 if (zoom_focus != f) {
3557 ZoomFocusChanged (); /* EMIT_SIGNAL */
3564 Editor::ensure_float (Window& win)
3566 win.set_transient_for (*this);
3570 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3572 /* recover or initialize pane positions. do this here rather than earlier because
3573 we don't want the positions to change the child allocations, which they seem to do.
3579 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3581 static int32_t done;
3584 width = default_width;
3585 height = default_height;
3587 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3589 if ((prop = geometry->property ("x_size")) == 0) {
3590 prop = geometry->property ("x-size");
3593 width = atoi (prop->value());
3595 if ((prop = geometry->property ("y_size")) == 0) {
3596 prop = geometry->property ("y-size");
3599 height = atoi (prop->value());
3603 if (which == static_cast<Paned*> (&edit_pane)) {
3609 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3610 /* initial allocation is 90% to canvas, 10% to notebook */
3611 pos = (int) floor (alloc.get_width() * 0.90f);
3612 snprintf (buf, sizeof(buf), "%d", pos);
3614 pos = atoi (prop->value());
3617 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3618 edit_pane.set_position (pos);
3619 pre_maximal_pane_position = pos;
3625 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3627 cerr << "remove tearoff\n";
3629 if (tools_tearoff->torn_off() &&
3630 mouse_mode_tearoff->torn_off()) {
3631 top_hbox.remove (toolbar_frame);
3636 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3638 cerr << "reattach tearoff\n";
3639 if (toolbar_frame.get_parent() == 0) {
3640 top_hbox.pack_end (toolbar_frame);
3645 Editor::set_show_measures (bool yn)
3647 if (_show_measures != yn) {
3650 if ((_show_measures = yn) == true) {
3652 tempo_lines->show();
3660 Editor::toggle_follow_playhead ()
3662 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3664 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3665 set_follow_playhead (tact->get_active());
3670 Editor::set_follow_playhead (bool yn)
3672 if (_follow_playhead != yn) {
3673 if ((_follow_playhead = yn) == true) {
3675 update_current_screen ();
3682 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3684 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3686 xfade->set_active (!xfade->active());
3691 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3693 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3695 xfade->set_follow_overlap (!xfade->following_overlap());
3700 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3702 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3708 CrossfadeEditor cew (_session, xfade, xfade->fade_in().get_min_y(), 1.0);
3712 switch (cew.run ()) {
3713 case RESPONSE_ACCEPT:
3720 xfade->StateChanged (Change (~0));
3724 Editor::playlist_selector () const
3726 return *_playlist_selector;
3730 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3734 switch (_snap_type) {
3739 case SnapToAThirtysecondBeat:
3743 case SnapToASixteenthBeat:
3747 case SnapToAEighthBeat:
3751 case SnapToAQuarterBeat:
3755 case SnapToAThirdBeat:
3761 return _session->tempo_map().meter_at (position).beats_per_bar();
3766 case SnapToTimecodeFrame:
3767 case SnapToTimecodeSeconds:
3768 case SnapToTimecodeMinutes:
3771 case SnapToRegionStart:
3772 case SnapToRegionEnd:
3773 case SnapToRegionSync:
3774 case SnapToRegionBoundary:
3784 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3788 ret = nudge_clock.current_duration (pos);
3789 next = ret + 1; /* XXXX fix me */
3795 Editor::end_location_changed (Location* location)
3797 ENSURE_GUI_THREAD (*this, &Editor::end_location_changed, location)
3798 //reset_scrolling_region ();
3799 nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
3800 horizontal_adjustment.set_upper (session_span / frames_per_unit);
3804 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3806 ArdourDialog dialog ("playlist deletion dialog");
3807 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3808 "If left alone, no audio files used by it will be cleaned.\n"
3809 "If deleted, audio files used by it alone by will cleaned."),
3812 dialog.set_position (WIN_POS_CENTER);
3813 dialog.get_vbox()->pack_start (label);
3817 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3818 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3819 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3821 switch (dialog.run ()) {
3822 case RESPONSE_ACCEPT:
3823 /* delete the playlist */
3827 case RESPONSE_REJECT:
3828 /* keep the playlist */
3840 Editor::audio_region_selection_covers (nframes64_t where)
3842 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3843 if ((*a)->region()->covers (where)) {
3852 Editor::prepare_for_cleanup ()
3854 cut_buffer->clear_regions ();
3855 cut_buffer->clear_playlists ();
3857 selection->clear_regions ();
3858 selection->clear_playlists ();
3860 _regions->suspend_redisplay ();
3864 Editor::finish_cleanup ()
3866 _regions->resume_redisplay ();
3870 Editor::transport_loop_location()
3873 return _session->locations()->auto_loop_location();
3880 Editor::transport_punch_location()
3883 return _session->locations()->auto_punch_location();
3890 Editor::control_layout_scroll (GdkEventScroll* ev)
3892 if (Keyboard::some_magic_widget_has_focus()) {
3896 switch (ev->direction) {
3898 scroll_tracks_up_line ();
3902 case GDK_SCROLL_DOWN:
3903 scroll_tracks_down_line ();
3907 /* no left/right handling yet */
3915 Editor::session_state_saved (string snap_name)
3917 ENSURE_GUI_THREAD (*this, &Editor::session_state_saved, snap_name);
3920 _snapshots->redisplay ();
3924 Editor::maximise_editing_space ()
3926 mouse_mode_tearoff->set_visible (false);
3927 tools_tearoff->set_visible (false);
3929 pre_maximal_pane_position = edit_pane.get_position();
3930 pre_maximal_editor_width = this->get_width();
3932 if(post_maximal_pane_position == 0) {
3933 post_maximal_pane_position = edit_pane.get_width();
3938 if(post_maximal_editor_width) {
3939 edit_pane.set_position (post_maximal_pane_position -
3940 abs(post_maximal_editor_width - pre_maximal_editor_width));
3942 edit_pane.set_position (post_maximal_pane_position);
3947 Editor::restore_editing_space ()
3949 // user changed width of pane during fullscreen
3951 if(post_maximal_pane_position != edit_pane.get_position()) {
3952 post_maximal_pane_position = edit_pane.get_position();
3957 mouse_mode_tearoff->set_visible (true);
3958 tools_tearoff->set_visible (true);
3959 post_maximal_editor_width = this->get_width();
3961 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
3965 * Make new playlists for a given track and also any others that belong
3966 * to the same active route group with the `edit' property.
3971 Editor::new_playlists (TimeAxisView* v)
3973 begin_reversible_command (_("new playlists"));
3974 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
3975 _session->playlists->get (playlists);
3976 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, RouteGroup::Edit);
3977 commit_reversible_command ();
3981 * Use a copy of the current playlist for a given track and also any others that belong
3982 * to the same active route group with the `edit' property.
3987 Editor::copy_playlists (TimeAxisView* v)
3989 begin_reversible_command (_("copy playlists"));
3990 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
3991 _session->playlists->get (playlists);
3992 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, RouteGroup::Edit);
3993 commit_reversible_command ();
3996 /** Clear the current playlist for a given track and also any others that belong
3997 * to the same active route group with the `edit' property.
4002 Editor::clear_playlists (TimeAxisView* v)
4004 begin_reversible_command (_("clear playlists"));
4005 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4006 _session->playlists->get (playlists);
4007 mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, RouteGroup::Edit);
4008 commit_reversible_command ();
4012 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4014 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4018 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4020 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4024 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4026 atv.clear_playlist ();
4030 Editor::on_key_press_event (GdkEventKey* ev)
4032 return key_press_focus_accelerator_handler (*this, ev);
4036 Editor::on_key_release_event (GdkEventKey* ev)
4038 return Gtk::Window::on_key_release_event (ev);
4039 // return key_press_focus_accelerator_handler (*this, ev);
4043 Editor::reset_x_origin (nframes64_t frame)
4045 //cerr << "resetting x origin" << endl;
4046 queue_visual_change (frame);
4050 Editor::reset_y_origin (double y)
4052 queue_visual_change_y (y);
4056 Editor::reset_zoom (double fpu)
4058 queue_visual_change (fpu);
4062 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4064 //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
4065 reset_x_origin (frame);
4068 if (!no_save_visual) {
4069 undo_visual_stack.push_back (current_visual_state(false));
4073 Editor::VisualState*
4074 Editor::current_visual_state (bool with_tracks)
4076 VisualState* vs = new VisualState;
4077 vs->y_position = vertical_adjustment.get_value();
4078 vs->frames_per_unit = frames_per_unit;
4079 vs->leftmost_frame = leftmost_frame;
4080 vs->zoom_focus = zoom_focus;
4083 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4084 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4092 Editor::undo_visual_state ()
4094 if (undo_visual_stack.empty()) {
4098 VisualState* vs = undo_visual_stack.back();
4099 undo_visual_stack.pop_back();
4100 use_visual_state (*vs);
4101 redo_visual_stack.push_back (vs);
4105 Editor::redo_visual_state ()
4107 if (redo_visual_stack.empty()) {
4111 VisualState* vs = redo_visual_stack.back();
4112 redo_visual_stack.pop_back();
4113 use_visual_state (*vs);
4114 undo_visual_stack.push_back (vs);
4118 Editor::swap_visual_state ()
4120 if (undo_visual_stack.empty()) {
4121 redo_visual_state ();
4123 undo_visual_state ();
4128 Editor::use_visual_state (VisualState& vs)
4130 no_save_visual = true;
4132 _routes->suspend_redisplay ();
4134 vertical_adjustment.set_value (vs.y_position);
4136 set_zoom_focus (vs.zoom_focus);
4137 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4139 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4140 TrackViewList::iterator t;
4142 /* check if the track still exists - it could have been deleted */
4144 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4145 (*t)->set_state (*(i->second), Stateful::loading_state_version);
4150 if (!vs.track_states.empty()) {
4151 _routes->update_visibility ();
4154 _routes->resume_redisplay ();
4156 no_save_visual = false;
4160 Editor::set_frames_per_unit (double fpu)
4162 /* this is the core function that controls the zoom level of the canvas. it is called
4163 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4166 if (fpu == frames_per_unit) {
4175 /* don't allow zooms that fit more than the maximum number
4176 of frames into an 800 pixel wide space.
4179 if (max_frames / fpu < 800.0) {
4184 tempo_lines->tempo_map_changed();
4186 frames_per_unit = fpu;
4191 Editor::post_zoom ()
4193 nframes64_t cef = 0;
4195 // convert fpu to frame count
4197 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4199 if (frames_per_unit != zoom_range_clock.current_duration()) {
4200 zoom_range_clock.set (frames);
4203 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4204 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4205 (*i)->reshow_selection (selection->time);
4209 leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4211 ZoomChanged (); /* EMIT_SIGNAL */
4214 cef = _session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
4216 horizontal_adjustment.set_upper (cef / frames_per_unit);
4218 //reset_scrolling_region ();
4220 if (playhead_cursor) {
4221 playhead_cursor->set_position (playhead_cursor->current_frame);
4224 refresh_location_display();
4225 _summary->set_overlays_dirty ();
4231 Editor::queue_visual_change (nframes64_t where)
4233 pending_visual_change.add (VisualChange::TimeOrigin);
4235 /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
4239 if (_session && (where > _session->current_end_frame())) {
4240 horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
4243 pending_visual_change.time_origin = where;
4245 ensure_visual_change_idle_handler ();
4249 Editor::queue_visual_change (double fpu)
4251 pending_visual_change.add (VisualChange::ZoomLevel);
4252 pending_visual_change.frames_per_unit = fpu;
4254 ensure_visual_change_idle_handler ();
4258 Editor::queue_visual_change_y (double y)
4260 pending_visual_change.add (VisualChange::YOrigin);
4261 pending_visual_change.y_origin = y;
4263 ensure_visual_change_idle_handler ();
4267 Editor::ensure_visual_change_idle_handler ()
4269 if (pending_visual_change.idle_handler_id < 0) {
4270 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4275 Editor::_idle_visual_changer (void* arg)
4277 return static_cast<Editor*>(arg)->idle_visual_changer ();
4281 Editor::idle_visual_changer ()
4283 VisualChange::Type p = pending_visual_change.pending;
4284 pending_visual_change.pending = (VisualChange::Type) 0;
4286 double last_time_origin = horizontal_adjustment.get_value();
4288 if (p & VisualChange::ZoomLevel) {
4289 set_frames_per_unit (pending_visual_change.frames_per_unit);
4291 compute_fixed_ruler_scale ();
4292 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4293 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4294 update_tempo_based_rulers ();
4296 if (p & VisualChange::TimeOrigin) {
4297 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4299 if (p & VisualChange::YOrigin) {
4300 vertical_adjustment.set_value (pending_visual_change.y_origin);
4303 nframes64_t csf=0, cef=0;
4304 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4307 csf = _session->current_start_frame();
4308 cef = _session->current_end_frame();
4311 /* if we seek beyond the current end of the canvas, move the end */
4314 if (last_time_origin == horizontal_adjustment.get_value() ) {
4315 /* changed signal not emitted */
4316 update_fixed_rulers ();
4317 redisplay_tempo (true);
4320 if (current_time_origin != pending_visual_change.time_origin) {
4321 cef += current_page_frames() / 10; // Add a little extra so we can see the end marker
4322 horizontal_adjustment.set_upper (cef / frames_per_unit);
4323 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4325 update_fixed_rulers();
4326 redisplay_tempo (true);
4329 _summary->set_overlays_dirty ();
4331 // 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
4332 pending_visual_change.idle_handler_id = -1;
4333 return 0; /* this is always a one-shot call */
4336 struct EditorOrderTimeAxisSorter {
4337 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4338 return a->order () < b->order ();
4343 Editor::sort_track_selection (TrackViewList* sel)
4345 EditorOrderTimeAxisSorter cmp;
4350 selection->tracks.sort (cmp);
4355 Editor::get_preferred_edit_position (bool ignore_playhead)
4358 nframes64_t where = 0;
4359 EditPoint ep = _edit_point;
4361 if (entered_marker) {
4362 return entered_marker->position();
4365 if (ignore_playhead && ep == EditAtPlayhead) {
4366 ep = EditAtSelectedMarker;
4370 case EditAtPlayhead:
4371 where = _session->audible_frame();
4374 case EditAtSelectedMarker:
4375 if (!selection->markers.empty()) {
4377 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4380 where = loc->start();
4391 if (!mouse_frame (where, ignored)) {
4392 /* XXX not right but what can we do ? */
4403 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4405 if (!_session) return;
4407 begin_reversible_command (cmd);
4411 if ((tll = transport_loop_location()) == 0) {
4412 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4413 XMLNode &before = _session->locations()->get_state();
4414 _session->locations()->add (loc, true);
4415 _session->set_auto_loop_location (loc);
4416 XMLNode &after = _session->locations()->get_state();
4417 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4419 XMLNode &before = tll->get_state();
4420 tll->set_hidden (false, this);
4421 tll->set (start, end);
4422 XMLNode &after = tll->get_state();
4423 _session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4426 commit_reversible_command ();
4430 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4432 if (!_session) return;
4434 begin_reversible_command (cmd);
4438 if ((tpl = transport_punch_location()) == 0) {
4439 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4440 XMLNode &before = _session->locations()->get_state();
4441 _session->locations()->add (loc, true);
4442 _session->set_auto_loop_location (loc);
4443 XMLNode &after = _session->locations()->get_state();
4444 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4447 XMLNode &before = tpl->get_state();
4448 tpl->set_hidden (false, this);
4449 tpl->set (start, end);
4450 XMLNode &after = tpl->get_state();
4451 _session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4454 commit_reversible_command ();
4457 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4458 * @param rs List to which found regions are added.
4459 * @param where Time to look at.
4460 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4463 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4465 const TrackViewList* tracks;
4468 tracks = &track_views;
4473 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4474 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4476 boost::shared_ptr<Diskstream> ds;
4477 boost::shared_ptr<Playlist> pl;
4479 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4481 Playlist::RegionList* regions = pl->regions_at (
4482 (nframes64_t) floor ( (double)where * ds->speed()));
4484 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4485 RegionView* rv = rtv->view()->find_view (*i);
4498 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4500 const TrackViewList* tracks;
4503 tracks = &track_views;
4508 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4509 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4511 boost::shared_ptr<Diskstream> ds;
4512 boost::shared_ptr<Playlist> pl;
4514 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4516 Playlist::RegionList* regions = pl->regions_touched (
4517 (nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4519 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4521 RegionView* rv = rtv->view()->find_view (*i);
4534 /** Find all regions which are either:
4536 * - the entered_regionview (if allow_entered == true) or
4537 * - under the preferred edit position AND on a selected track, or on a track
4538 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4539 * @param rs Returned region list.
4540 * @param allow_entered true to include the entered_regionview in the list.
4543 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4545 /* Start with selected regions */
4546 rs = selection->regions;
4548 /* Add the entered_regionview, if requested */
4549 if (allow_entered && entered_regionview) {
4550 rs.add (entered_regionview);
4553 if (allow_edit_position) {
4555 TrackViewList tracks = selection->tracks;
4557 /* tracks is currently the set of selected tracks; add any other tracks that
4558 * have regions that are in the same edit-activated route group as one of
4560 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4562 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4563 if (g && g->active_property (RouteGroup::Edit)) {
4564 tracks.add (axis_views_from_routes (g->route_list()));
4569 if (!tracks.empty()) {
4570 /* now find regions that are at the edit position on those tracks */
4571 nframes64_t const where = get_preferred_edit_position ();
4572 get_regions_at (rs, where, tracks);
4578 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4580 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4582 RouteTimeAxisView* tatv;
4584 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4586 boost::shared_ptr<Playlist> pl;
4587 vector<boost::shared_ptr<Region> > results;
4589 boost::shared_ptr<Diskstream> ds;
4591 if ((ds = tatv->get_diskstream()) == 0) {
4596 if ((pl = (ds->playlist())) != 0) {
4597 pl->get_region_list_equivalent_regions (region, results);
4600 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4601 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4602 regions.push_back (marv);
4611 Editor::show_rhythm_ferret ()
4613 if (rhythm_ferret == 0) {
4614 rhythm_ferret = new RhythmFerret(*this);
4617 rhythm_ferret->set_session (_session);
4618 rhythm_ferret->show ();
4619 rhythm_ferret->present ();
4623 Editor::show_global_port_matrix (ARDOUR::DataType t)
4625 if (_global_port_matrix[t] == 0) {
4626 _global_port_matrix[t] = new GlobalPortMatrixWindow (_session, t);
4629 _global_port_matrix[t]->show ();
4633 Editor::first_idle ()
4635 MessageDialog* dialog = 0;
4637 if (track_views.size() > 1) {
4638 dialog = new MessageDialog (*this,
4639 _("Please wait while Ardour loads visual data"),
4644 ARDOUR_UI::instance()->flush_pending ();
4647 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4651 // first idle adds route children (automation tracks), so we need to redisplay here
4652 _routes->redisplay ();
4660 _idle_resizer (gpointer arg)
4662 return ((Editor*)arg)->idle_resize ();
4666 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4668 if (resize_idle_id < 0) {
4669 resize_idle_id = g_idle_add (_idle_resizer, this);
4670 _pending_resize_amount = 0;
4673 /* make a note of the smallest resulting height, so that we can clamp the
4674 lower limit at TimeAxisView::hSmall */
4676 int32_t min_resulting = INT32_MAX;
4678 _pending_resize_amount += h;
4679 _pending_resize_view = view;
4681 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4683 if (selection->tracks.contains (_pending_resize_view)) {
4684 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4685 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4689 if (min_resulting < 0) {
4694 if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
4695 _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
4699 /** Handle pending resizing of tracks */
4701 Editor::idle_resize ()
4703 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4705 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4706 selection->tracks.contains (_pending_resize_view)) {
4708 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4709 if (*i != _pending_resize_view) {
4710 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4716 _group_tabs->set_dirty ();
4717 resize_idle_id = -1;
4725 ENSURE_GUI_THREAD (*this, &Editor::located)
4727 _pending_locate_request = false;
4731 Editor::region_view_added (RegionView *)
4733 _summary->set_dirty ();
4737 Editor::streamview_height_changed ()
4739 _summary->set_dirty ();
4743 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
4745 TrackViewList::const_iterator j = track_views.begin ();
4746 while (j != track_views.end()) {
4747 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4748 if (rtv && rtv->route() == r) {
4759 Editor::axis_views_from_routes (boost::shared_ptr<RouteList> r) const
4763 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
4764 TimeAxisView* tv = axis_view_from_route (*i);
4775 Editor::handle_new_route (RouteList& routes)
4777 ENSURE_GUI_THREAD (*this, &Editor::handle_new_route, routes)
4779 RouteTimeAxisView *rtv;
4780 list<RouteTimeAxisView*> new_views;
4782 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4783 boost::shared_ptr<Route> route = (*x);
4785 if (route->is_hidden()) {
4789 DataType dt = route->input()->default_type();
4791 if (dt == ARDOUR::DataType::AUDIO) {
4792 rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
4793 } else if (dt == ARDOUR::DataType::MIDI) {
4794 rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
4796 throw unknown_type();
4799 new_views.push_back (rtv);
4800 track_views.push_back (rtv);
4802 rtv->effective_gain_display ();
4804 rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
4805 rtv->view()->HeightChanged.connect (sigc::mem_fun (*this, &Editor::streamview_height_changed));
4807 rtv->GoingAway.connect (*this, boost::bind (&Editor::remove_route, this, rtv), gui_context());
4810 _routes->routes_added (new_views);
4812 if (show_editor_mixer_when_tracks_arrive) {
4813 show_editor_mixer (true);
4816 editor_list_button.set_sensitive (true);
4818 _summary->set_dirty ();
4822 Editor::remove_route (TimeAxisView *tv)
4824 ENSURE_GUI_THREAD (*this, &Editor::remove_route, tv)
4826 TrackViewList::iterator i;
4828 boost::shared_ptr<Route> route;
4829 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv);
4831 route = rtav->route ();
4834 TimeAxisView* next_tv = 0;
4836 if (tv == entered_track) {
4840 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4842 i = track_views.erase (i);
4844 if (track_views.empty()) {
4846 } else if (i == track_views.end()) {
4847 next_tv = track_views.front();
4853 if (current_mixer_strip && current_mixer_strip->route() == route) {
4856 set_selected_mixer_strip (*next_tv);
4858 /* make the editor mixer strip go away setting the
4859 * button to inactive (which also unticks the menu option)
4862 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
4868 Editor::hide_track_in_display (TimeAxisView& tv, bool /*temponly*/)
4870 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
4872 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
4873 // this will hide the mixer strip
4874 set_selected_mixer_strip (tv);
4877 _routes->hide_track_in_display (tv);
4881 Editor::sync_track_view_list_and_routes ()
4883 track_views = TrackViewList (_routes->views ());
4885 _summary->set_dirty ();
4886 _group_tabs->set_dirty ();
4888 return false; // do not call again (until needed)
4892 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
4894 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4900 Editor::get_route_view_by_id (PBD::ID& id)
4902 RouteTimeAxisView* v;
4904 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4905 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
4906 if(v->route()->id() == id) {
4916 Editor::fit_route_group (RouteGroup *g)
4918 TrackViewList ts = axis_views_from_routes (g->route_list ());
4923 Editor::consider_auditioning (boost::shared_ptr<Region> region)
4925 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
4928 _session->cancel_audition ();
4932 if (_session->is_auditioning()) {
4933 _session->cancel_audition ();
4934 if (r == last_audition_region) {
4939 _session->audition_region (r);
4940 last_audition_region = r;
4945 Editor::hide_a_region (boost::shared_ptr<Region> r)
4947 r->set_hidden (true);
4951 Editor::remove_a_region (boost::shared_ptr<Region> r)
4953 _session->remove_region_from_region_list (r);
4957 Editor::audition_region_from_region_list ()
4959 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::consider_auditioning));
4963 Editor::hide_region_from_region_list ()
4965 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::hide_a_region));
4969 Editor::start_step_editing ()
4971 step_edit_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::check_step_edit), 20);
4975 Editor::stop_step_editing ()
4977 step_edit_connection.disconnect ();
4981 Editor::check_step_edit ()
4983 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4984 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
4986 mtv->check_step_edit ();
4990 return true; // do it again, till we stop
4994 Editor::horizontal_scroll_left ()
4996 double x = leftmost_position() - current_page_frames() / 5;
5005 Editor::horizontal_scroll_right ()
5007 reset_x_origin (leftmost_position() + current_page_frames() / 5);