2 Copyright (C) 2000-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* Note: public Editor methods are documented in public_editor.h */
22 #define __STDC_LIMIT_MACROS 1
31 #include "ardour_ui.h"
33 * ardour_ui.h include was moved to the top of the list
34 * due to a conflicting definition of 'Style' between
35 * Apple's MacTypes.h and BarController.
38 #include <boost/none.hpp>
40 #include <sigc++/bind.h>
42 #include "pbd/convert.h"
43 #include "pbd/error.h"
44 #include "pbd/enumwriter.h"
45 #include "pbd/memento_command.h"
46 #include "pbd/unknown_type.h"
48 #include <glibmm/miscutils.h>
49 #include <gtkmm/image.h>
50 #include <gdkmm/color.h>
51 #include <gdkmm/bitmap.h>
53 #include <gtkmm2ext/grouped_buttons.h>
54 #include <gtkmm2ext/gtk_ui.h>
55 #include <gtkmm2ext/tearoff.h>
56 #include <gtkmm2ext/utils.h>
57 #include <gtkmm2ext/window_title.h>
58 #include <gtkmm2ext/choice.h>
59 #include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
61 #include "ardour/audio_diskstream.h"
62 #include "ardour/audio_track.h"
63 #include "ardour/audioplaylist.h"
64 #include "ardour/audioregion.h"
65 #include "ardour/location.h"
66 #include "ardour/midi_region.h"
67 #include "ardour/plugin_manager.h"
68 #include "ardour/profile.h"
69 #include "ardour/route_group.h"
70 #include "ardour/session_directory.h"
71 #include "ardour/session_route.h"
72 #include "ardour/session_state_utils.h"
73 #include "ardour/tempo.h"
74 #include "ardour/utils.h"
75 #include "ardour/session_playlists.h"
76 #include "ardour/audioengine.h"
78 #include "control_protocol/control_protocol.h"
83 #include "playlist_selector.h"
84 #include "audio_region_view.h"
85 #include "rgb_macros.h"
86 #include "selection.h"
87 #include "audio_streamview.h"
88 #include "time_axis_view.h"
89 #include "audio_time_axis.h"
91 #include "crossfade_view.h"
92 #include "canvas-noevent-text.h"
94 #include "public_editor.h"
95 #include "crossfade_edit.h"
96 #include "canvas_impl.h"
99 #include "gui_thread.h"
100 #include "simpleline.h"
101 #include "rhythm_ferret.h"
103 #include "tempo_lines.h"
104 #include "analysis_window.h"
105 #include "bundle_manager.h"
106 #include "global_port_matrix.h"
107 #include "editor_drag.h"
108 #include "editor_group_tabs.h"
109 #include "automation_time_axis.h"
110 #include "editor_routes.h"
111 #include "midi_time_axis.h"
112 #include "mixer_strip.h"
113 #include "editor_route_groups.h"
114 #include "editor_regions.h"
115 #include "editor_locations.h"
116 #include "editor_snapshots.h"
121 #include "imageframe_socket_handler.h"
125 using namespace ARDOUR;
128 using namespace Glib;
129 using namespace Gtkmm2ext;
130 using namespace Editing;
132 using PBD::internationalize;
134 using Gtkmm2ext::Keyboard;
136 const double Editor::timebar_height = 15.0;
138 #include "editor_xpms"
140 static const gchar *_snap_type_strings[] = {
142 N_("Timecode Frames"),
143 N_("Timecode Seconds"),
144 N_("Timecode Minutes"),
171 static const gchar *_snap_mode_strings[] = {
178 static const gchar *_edit_point_strings[] = {
185 static const gchar *_zoom_focus_strings[] = {
195 #ifdef USE_RUBBERBAND
196 static const gchar *_rb_opt_strings[] = {
199 N_("Balanced multitimbral mixture"),
200 N_("Unpitched percussion with stable notes"),
201 N_("Crisp monophonic instrumental"),
202 N_("Unpitched solo percussion"),
207 /* Soundfile drag-n-drop */
209 Gdk::Cursor* Editor::cross_hair_cursor = 0;
210 Gdk::Cursor* Editor::selector_cursor = 0;
211 Gdk::Cursor* Editor::trimmer_cursor = 0;
212 Gdk::Cursor* Editor::left_side_trim_cursor = 0;
213 Gdk::Cursor* Editor::right_side_trim_cursor = 0;
214 Gdk::Cursor* Editor::grabber_cursor = 0;
215 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
216 Gdk::Cursor* Editor::zoom_cursor = 0;
217 Gdk::Cursor* Editor::time_fx_cursor = 0;
218 Gdk::Cursor* Editor::fader_cursor = 0;
219 Gdk::Cursor* Editor::speaker_cursor = 0;
220 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
221 Gdk::Cursor* Editor::midi_select_cursor = 0;
222 Gdk::Cursor* Editor::midi_resize_cursor = 0;
223 Gdk::Cursor* Editor::midi_erase_cursor = 0;
224 Gdk::Cursor* Editor::wait_cursor = 0;
225 Gdk::Cursor* Editor::timebar_cursor = 0;
226 Gdk::Cursor* Editor::transparent_cursor = 0;
229 show_me_the_size (Requisition* r, const char* what)
231 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
236 pane_size_watcher (Paned* pane)
238 /* if the handle of a pane vanishes into (at least) the tabs of a notebook,
239 it is no longer accessible. so stop that. this doesn't happen on X11,
240 just the quartz backend.
245 int max_width_of_lhs = GTK_WIDGET(pane->gobj())->allocation.width - 25;
247 gint pos = pane->get_position ();
249 if (pos > max_width_of_lhs) {
250 pane->set_position (max_width_of_lhs);
256 : _join_object_range_state (JOIN_OBJECT_RANGE_NONE)
258 /* time display buttons */
259 , minsec_label (_("Mins:Secs"))
260 , bbt_label (_("Bars:Beats"))
261 , timecode_label (_("Timecode"))
262 , frame_label (_("Samples"))
263 , tempo_label (_("Tempo"))
264 , meter_label (_("Meter"))
265 , mark_label (_("Location Markers"))
266 , range_mark_label (_("Range Markers"))
267 , transport_mark_label (_("Loop/Punch Ranges"))
268 , cd_mark_label (_("CD Markers"))
269 , edit_packer (4, 4, true)
271 /* the values here don't matter: layout widgets
272 reset them as needed.
275 , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
277 /* tool bar related */
279 , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
281 , toolbar_selection_clock_table (2,3)
283 , automation_mode_button (_("mode"))
284 , global_automation_button (_("automation"))
286 , midi_panic_button (_("Panic"))
289 , image_socket_listener(0)
294 , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
295 , meters_running(false)
296 , _pending_locate_request (false)
297 , _pending_initial_locate (false)
302 /* we are a singleton */
304 PublicEditor::_instance = this;
308 selection = new Selection (this);
309 cut_buffer = new Selection (this);
311 clicked_regionview = 0;
312 clicked_axisview = 0;
313 clicked_routeview = 0;
314 clicked_crossfadeview = 0;
315 clicked_control_point = 0;
316 last_update_frame = 0;
317 _drags = new DragManager (this);
318 current_mixer_strip = 0;
319 current_bbt_points = 0;
322 snap_type_strings = I18N (_snap_type_strings);
323 snap_mode_strings = I18N (_snap_mode_strings);
324 zoom_focus_strings = I18N (_zoom_focus_strings);
325 edit_point_strings = I18N (_edit_point_strings);
326 #ifdef USE_RUBBERBAND
327 rb_opt_strings = I18N (_rb_opt_strings);
330 snap_threshold = 5.0;
331 bbt_beat_subdivision = 4;
334 last_autoscroll_x = 0;
335 last_autoscroll_y = 0;
336 autoscroll_active = false;
337 autoscroll_timeout_tag = -1;
342 current_interthread_info = 0;
343 _show_measures = true;
344 show_gain_after_trim = false;
345 verbose_cursor_on = true;
346 last_item_entered = 0;
347 last_item_entered_n = 0;
349 have_pending_keyboard_selection = false;
350 _follow_playhead = true;
351 _stationary_playhead = false;
352 _xfade_visibility = true;
353 editor_ruler_menu = 0;
354 no_ruler_shown_update = false;
356 session_range_marker_menu = 0;
357 range_marker_menu = 0;
358 marker_menu_item = 0;
359 tempo_or_meter_marker_menu = 0;
360 transport_marker_menu = 0;
361 new_transport_marker_menu = 0;
362 editor_mixer_strip_width = Wide;
363 show_editor_mixer_when_tracks_arrive = false;
364 region_edit_menu_split_multichannel_item = 0;
365 region_edit_menu_split_item = 0;
368 current_stepping_trackview = 0;
370 entered_regionview = 0;
372 clear_entered_track = false;
375 button_release_can_deselect = true;
376 _dragging_playhead = false;
377 _dragging_edit_point = false;
378 select_new_marker = false;
381 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
382 _global_port_matrix[*i] = 0;
384 allow_vertical_scroll = false;
385 no_save_visual = false;
388 scrubbing_direction = 0;
392 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
393 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
394 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
395 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
396 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
398 _edit_point = EditAtMouse;
399 _internal_editing = false;
400 current_canvas_cursor = 0;
402 frames_per_unit = 2048; /* too early to use reset_zoom () */
404 _scroll_callbacks = 0;
406 zoom_focus = ZoomFocusLeft;
407 set_zoom_focus (ZoomFocusLeft);
408 zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
410 bbt_label.set_name ("EditorTimeButton");
411 bbt_label.set_size_request (-1, (int)timebar_height);
412 bbt_label.set_alignment (1.0, 0.5);
413 bbt_label.set_padding (5,0);
415 bbt_label.set_no_show_all();
416 minsec_label.set_name ("EditorTimeButton");
417 minsec_label.set_size_request (-1, (int)timebar_height);
418 minsec_label.set_alignment (1.0, 0.5);
419 minsec_label.set_padding (5,0);
420 minsec_label.hide ();
421 minsec_label.set_no_show_all();
422 timecode_label.set_name ("EditorTimeButton");
423 timecode_label.set_size_request (-1, (int)timebar_height);
424 timecode_label.set_alignment (1.0, 0.5);
425 timecode_label.set_padding (5,0);
426 timecode_label.hide ();
427 timecode_label.set_no_show_all();
428 frame_label.set_name ("EditorTimeButton");
429 frame_label.set_size_request (-1, (int)timebar_height);
430 frame_label.set_alignment (1.0, 0.5);
431 frame_label.set_padding (5,0);
433 frame_label.set_no_show_all();
435 tempo_label.set_name ("EditorTimeButton");
436 tempo_label.set_size_request (-1, (int)timebar_height);
437 tempo_label.set_alignment (1.0, 0.5);
438 tempo_label.set_padding (5,0);
440 tempo_label.set_no_show_all();
441 meter_label.set_name ("EditorTimeButton");
442 meter_label.set_size_request (-1, (int)timebar_height);
443 meter_label.set_alignment (1.0, 0.5);
444 meter_label.set_padding (5,0);
446 meter_label.set_no_show_all();
447 mark_label.set_name ("EditorTimeButton");
448 mark_label.set_size_request (-1, (int)timebar_height);
449 mark_label.set_alignment (1.0, 0.5);
450 mark_label.set_padding (5,0);
452 mark_label.set_no_show_all();
453 cd_mark_label.set_name ("EditorTimeButton");
454 cd_mark_label.set_size_request (-1, (int)timebar_height);
455 cd_mark_label.set_alignment (1.0, 0.5);
456 cd_mark_label.set_padding (5,0);
457 cd_mark_label.hide();
458 cd_mark_label.set_no_show_all();
459 range_mark_label.set_name ("EditorTimeButton");
460 range_mark_label.set_size_request (-1, (int)timebar_height);
461 range_mark_label.set_alignment (1.0, 0.5);
462 range_mark_label.set_padding (5,0);
463 range_mark_label.hide();
464 range_mark_label.set_no_show_all();
465 transport_mark_label.set_name ("EditorTimeButton");
466 transport_mark_label.set_size_request (-1, (int)timebar_height);
467 transport_mark_label.set_alignment (1.0, 0.5);
468 transport_mark_label.set_padding (5,0);
469 transport_mark_label.hide();
470 transport_mark_label.set_no_show_all();
472 initialize_rulers ();
473 initialize_canvas ();
474 _summary = new EditorSummary (this);
476 selection->TimeChanged.connect (sigc::mem_fun(*this, &Editor::time_selection_changed));
477 selection->TracksChanged.connect (sigc::mem_fun(*this, &Editor::track_selection_changed));
478 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (sigc::mem_fun(*this, &Editor::region_selection_changed));
479 selection->PointsChanged.connect (sigc::mem_fun(*this, &Editor::point_selection_changed));
480 selection->MarkersChanged.connect (sigc::mem_fun(*this, &Editor::marker_selection_changed));
482 edit_controls_vbox.set_spacing (0);
483 vertical_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &Editor::tie_vertical_scrolling), true);
484 track_canvas->signal_map_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_map_handler));
486 HBox* h = manage (new HBox);
487 _group_tabs = new EditorGroupTabs (this);
488 h->pack_start (*_group_tabs, PACK_SHRINK);
489 h->pack_start (edit_controls_vbox);
490 controls_layout.add (*h);
492 controls_layout.set_name ("EditControlsBase");
493 controls_layout.add_events (Gdk::SCROLL_MASK);
494 controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false);
496 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
497 controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
498 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
502 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
503 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
504 0.0, 1.0, 100.0, 1.0));
505 pad_line_1->property_color_rgba() = 0xFF0000FF;
509 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
510 time_canvas_vbox.set_size_request (-1, -1);
512 ruler_label_event_box.add (ruler_label_vbox);
513 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
514 ruler_label_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
516 time_button_event_box.add (time_button_vbox);
517 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
518 time_button_event_box.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_label_button_release));
520 /* these enable us to have a dedicated window (for cursor setting, etc.)
521 for the canvas areas.
524 track_canvas_event_box.add (*track_canvas);
526 time_canvas_event_box.add (time_canvas_vbox);
527 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
529 edit_packer.set_col_spacings (0);
530 edit_packer.set_row_spacings (0);
531 edit_packer.set_homogeneous (false);
532 edit_packer.set_border_width (0);
533 edit_packer.set_name ("EditorWindow");
535 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
536 /* labels for the rulers */
537 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
538 /* labels for the marker "tracks" */
539 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
541 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
543 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
545 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
547 bottom_hbox.set_border_width (2);
548 bottom_hbox.set_spacing (3);
550 _route_groups = new EditorRouteGroups (this);
551 _routes = new EditorRoutes (this);
552 _regions = new EditorRegions (this);
553 _snapshots = new EditorSnapshots (this);
554 _locations = new EditorLocations (this);
558 nlabel = manage (new Label (_("Regions")));
559 nlabel->set_angle (-90);
560 the_notebook.append_page (_regions->widget (), *nlabel);
561 nlabel = manage (new Label (_("Tracks & Busses")));
562 nlabel->set_angle (-90);
563 the_notebook.append_page (_routes->widget (), *nlabel);
564 nlabel = manage (new Label (_("Snapshots")));
565 nlabel->set_angle (-90);
566 the_notebook.append_page (_snapshots->widget (), *nlabel);
567 nlabel = manage (new Label (_("Route Groups")));
568 nlabel->set_angle (-90);
569 the_notebook.append_page (_route_groups->widget (), *nlabel);
570 nlabel = manage (new Label (_("Ranges & Marks")));
571 nlabel->set_angle (-90);
572 the_notebook.append_page (_locations->widget (), *nlabel);
574 the_notebook.set_show_tabs (true);
575 the_notebook.set_scrollable (true);
576 the_notebook.popup_disable ();
577 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
578 the_notebook.show_all ();
580 post_maximal_editor_width = 0;
581 post_maximal_horizontal_pane_position = 0;
582 post_maximal_editor_height = 0;
583 post_maximal_vertical_pane_position = 0;
585 editor_summary_pane.pack1(edit_packer);
587 Button* summary_arrows_left_left = manage (new Button);
588 summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
589 summary_arrows_left_left->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_press)));
590 summary_arrows_left_left->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_release));
591 Button* summary_arrows_left_right = manage (new Button);
592 summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
593 summary_arrows_left_right->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_press)));
594 summary_arrows_left_right->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_release));
595 VBox* summary_arrows_left = manage (new VBox);
596 summary_arrows_left->pack_start (*summary_arrows_left_left);
597 summary_arrows_left->pack_start (*summary_arrows_left_right);
599 Button* summary_arrows_right_left = manage (new Button);
600 summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
601 summary_arrows_right_left->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_press)));
602 summary_arrows_right_left->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_release));
603 Button* summary_arrows_right_right = manage (new Button);
604 summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
605 summary_arrows_right_right->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_press)));
606 summary_arrows_right_right->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_release));
607 VBox* summary_arrows_right = manage (new VBox);
608 summary_arrows_right->pack_start (*summary_arrows_right_left);
609 summary_arrows_right->pack_start (*summary_arrows_right_right);
611 Frame* summary_frame = manage (new Frame);
612 summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
613 summary_frame->add (*_summary);
614 summary_frame->show ();
616 _summary_hbox.pack_start (*summary_arrows_left, false, false);
617 _summary_hbox.pack_start (*summary_frame, true, true);
618 _summary_hbox.pack_start (*summary_arrows_right, false, false);
620 editor_summary_pane.pack2 (_summary_hbox);
622 edit_pane.pack1 (editor_summary_pane, true, true);
623 edit_pane.pack2 (the_notebook, false, true);
625 editor_summary_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&editor_summary_pane)));
627 /* XXX: editor_summary_pane might need similar special OS X treatment to the edit_pane */
629 edit_pane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
631 Glib::PropertyProxy<int> proxy = edit_pane.property_position();
632 proxy.signal_changed().connect (bind (sigc::ptr_fun (pane_size_watcher), static_cast<Paned*> (&edit_pane)));
634 top_hbox.pack_start (toolbar_frame, false, true);
636 HBox *hbox = manage (new HBox);
637 hbox->pack_start (edit_pane, true, true);
639 global_vpacker.pack_start (top_hbox, false, false);
640 global_vpacker.pack_start (*hbox, true, true);
642 global_hpacker.pack_start (global_vpacker, true, true);
644 set_name ("EditorWindow");
645 add_accel_group (ActionManager::ui_manager->get_accel_group());
647 status_bar_hpacker.show ();
649 vpacker.pack_end (status_bar_hpacker, false, false);
650 vpacker.pack_end (global_hpacker, true, true);
652 /* register actions now so that set_state() can find them and set toggles/checks etc */
657 setup_midi_toolbar ();
659 _snap_type = SnapToBeat;
660 set_snap_to (_snap_type);
661 _snap_mode = SnapOff;
662 set_snap_mode (_snap_mode);
663 set_mouse_mode (MouseObject, true);
664 set_edit_point_preference (EditAtMouse, true);
666 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
667 set_state (*node, Stateful::loading_state_version);
669 _playlist_selector = new PlaylistSelector();
670 _playlist_selector->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
672 RegionView::RegionViewGoingAway.connect (*this, invalidator (*this), ui_bind (&Editor::catch_vanishing_regionview, this, _1), gui_context());
676 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
677 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
679 nudge_forward_button.set_name ("TransportButton");
680 nudge_backward_button.set_name ("TransportButton");
682 fade_context_menu.set_name ("ArdourContextMenu");
684 /* icons, titles, WM stuff */
686 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
687 Glib::RefPtr<Gdk::Pixbuf> icon;
689 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
690 window_icons.push_back (icon);
692 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
693 window_icons.push_back (icon);
695 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
696 window_icons.push_back (icon);
698 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
699 window_icons.push_back (icon);
701 if (!window_icons.empty()) {
702 set_icon_list (window_icons);
703 set_default_icon_list (window_icons);
706 WindowTitle title(Glib::get_application_name());
707 title += _("Editor");
708 set_title (title.get_string());
709 set_wmclass (X_("ardour_editor"), "Ardour");
712 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
714 signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
715 signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
717 /* allow external control surfaces/protocols to do various things */
719 ControlProtocol::ZoomToSession.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_session, this), gui_context());
720 ControlProtocol::ZoomIn.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
721 ControlProtocol::ZoomOut.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
722 ControlProtocol::ScrollTimeline.connect (*this, invalidator (*this), ui_bind (&Editor::control_scroll, this, _1), gui_context());
723 BasicUI::AccessAction.connect (*this, invalidator (*this), ui_bind (&Editor::access_action, this, _1, _2), gui_context());
725 /* problematic: has to return a value and thus cannot be x-thread */
727 Session::AskAboutPlaylistDeletion.connect_same_thread (*this, boost::bind (&Editor::playlist_deletion_dialog, this, _1));
729 Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
731 TimeAxisView::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&Editor::timeaxisview_deleted, this, _1), gui_context());
733 _last_normalization_value = 0;
742 if(image_socket_listener) {
743 if(image_socket_listener->is_connected())
745 image_socket_listener->close_connection() ;
748 delete image_socket_listener ;
749 image_socket_listener = 0 ;
754 delete _route_groups;
760 Editor::add_toplevel_controls (Container& cont)
762 vpacker.pack_start (cont, false, false);
767 Editor::catch_vanishing_regionview (RegionView *rv)
769 /* note: the selection will take care of the vanishing
770 audioregionview by itself.
773 if (_drags->active() && _drags->have_item (rv->get_canvas_group()) && !_drags->ending()) {
777 if (clicked_regionview == rv) {
778 clicked_regionview = 0;
781 if (entered_regionview == rv) {
782 set_entered_regionview (0);
787 Editor::set_entered_regionview (RegionView* rv)
789 if (rv == entered_regionview) {
793 if (entered_regionview) {
794 entered_regionview->exited ();
797 if ((entered_regionview = rv) != 0) {
798 entered_regionview->entered ();
803 Editor::set_entered_track (TimeAxisView* tav)
806 entered_track->exited ();
809 if ((entered_track = tav) != 0) {
810 entered_track->entered ();
815 Editor::show_window ()
817 if (! is_visible ()) {
820 /* re-hide editor list if necessary */
821 editor_list_button_toggled ();
823 /* re-hide summary widget if necessary */
824 parameter_changed ("show-summary");
826 parameter_changed ("show-edit-group-tabs");
828 /* now reset all audio_time_axis heights, because widgets might need
834 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
835 tv = (static_cast<TimeAxisView*>(*i));
839 reset_zoom (frames_per_unit);
846 Editor::instant_save ()
848 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
853 _session->add_instant_xml(get_state());
855 Config->add_instant_xml(get_state());
860 Editor::zoom_adjustment_changed ()
866 double fpu = zoom_range_clock.current_duration() / _canvas_width;
870 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
871 } else if (fpu > _session->current_end_frame() / _canvas_width) {
872 fpu = _session->current_end_frame() / _canvas_width;
873 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
880 Editor::control_scroll (float fraction)
882 ENSURE_GUI_THREAD (*this, &Editor::control_scroll, fraction)
888 double step = fraction * current_page_frames();
891 _control_scroll_target is an optional<T>
893 it acts like a pointer to an nframes64_t, with
894 a operator conversion to boolean to check
895 that it has a value could possibly use
896 playhead_cursor->current_frame to store the
897 value and a boolean in the class to know
898 when it's out of date
901 if (!_control_scroll_target) {
902 _control_scroll_target = _session->transport_frame();
903 _dragging_playhead = true;
906 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
907 *_control_scroll_target = 0;
908 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
909 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
911 *_control_scroll_target += (nframes64_t) floor (step);
914 /* move visuals, we'll catch up with it later */
916 playhead_cursor->set_position (*_control_scroll_target);
917 UpdateAllTransportClocks (*_control_scroll_target);
919 if (*_control_scroll_target > (current_page_frames() / 2)) {
920 /* try to center PH in window */
921 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
927 Now we do a timeout to actually bring the session to the right place
928 according to the playhead. This is to avoid reading disk buffers on every
929 call to control_scroll, which is driven by ScrollTimeline and therefore
930 probably by a control surface wheel which can generate lots of events.
932 /* cancel the existing timeout */
934 control_scroll_connection.disconnect ();
936 /* add the next timeout */
938 control_scroll_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
942 Editor::deferred_control_scroll (nframes64_t /*target*/)
944 _session->request_locate (*_control_scroll_target, _session->transport_rolling());
945 // reset for next stream
946 _control_scroll_target = boost::none;
947 _dragging_playhead = false;
952 Editor::access_action (std::string action_group, std::string action_item)
958 ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
961 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
969 Editor::on_realize ()
971 Window::on_realize ();
976 Editor::map_position_change (nframes64_t frame)
978 ENSURE_GUI_THREAD (*this, &Editor::map_position_change, frame)
980 if (_session == 0 || !_follow_playhead) {
984 center_screen (frame);
985 playhead_cursor->set_position (frame);
989 Editor::center_screen (nframes64_t frame)
991 double page = _canvas_width * frames_per_unit;
993 /* if we're off the page, then scroll.
996 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
997 center_screen_internal (frame, page);
1002 Editor::center_screen_internal (nframes64_t frame, float page)
1007 frame -= (nframes64_t) page;
1012 reset_x_origin (frame);
1017 Editor::update_title ()
1019 ENSURE_GUI_THREAD (*this, &Editor::update_title)
1022 bool dirty = _session->dirty();
1024 string session_name;
1026 if (_session->snap_name() != _session->name()) {
1027 session_name = _session->snap_name();
1029 session_name = _session->name();
1033 session_name = "*" + session_name;
1036 WindowTitle title(session_name);
1037 title += Glib::get_application_name();
1038 set_title (title.get_string());
1043 Editor::set_session (Session *t)
1045 SessionHandlePtr::set_session (t);
1051 zoom_range_clock.set_session (_session);
1052 _playlist_selector->set_session (_session);
1053 nudge_clock.set_session (_session);
1054 _summary->set_session (_session);
1055 _group_tabs->set_session (_session);
1056 _route_groups->set_session (_session);
1057 _regions->set_session (_session);
1058 _snapshots->set_session (_session);
1059 _routes->set_session (_session);
1060 _locations->set_session (_session);
1062 if (rhythm_ferret) {
1063 rhythm_ferret->set_session (_session);
1066 if (analysis_window) {
1067 analysis_window->set_session (_session);
1071 sfbrowser->set_session (_session);
1074 compute_fixed_ruler_scale ();
1076 /* there are never any selected regions at startup */
1077 sensitize_the_right_region_actions (false);
1079 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1080 set_state (*node, Stateful::loading_state_version);
1082 /* catch up with the playhead */
1084 _session->request_locate (playhead_cursor->current_frame);
1085 _pending_initial_locate = true;
1089 /* These signals can all be emitted by a non-GUI thread. Therefore the
1090 handlers for them must not attempt to directly interact with the GUI,
1091 but use Gtkmm2ext::UI::instance()->call_slot();
1094 _session->TransportStateChange.connect (_session_connections, invalidator (*this), boost::bind (&Editor::map_transport_state, this), gui_context());
1095 _session->PositionChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::map_position_change, this, _1), gui_context());
1096 _session->RouteAdded.connect (_session_connections, invalidator (*this), ui_bind (&Editor::handle_new_route, this, _1), gui_context());
1097 _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_title, this), gui_context());
1098 _session->TimecodeOffsetChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::update_just_timecode, this), gui_context());
1099 _session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::tempo_map_changed, this, _1), gui_context());
1100 _session->Located.connect (_session_connections, invalidator (*this), boost::bind (&Editor::located, this), gui_context());
1101 _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::parameter_changed, this, _1), gui_context());
1102 _session->StateSaved.connect (_session_connections, invalidator (*this), ui_bind (&Editor::session_state_saved, this, _1), gui_context());
1103 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&Editor::add_new_location, this, _1), gui_context());
1104 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&Editor::location_gone, this, _1), gui_context());
1105 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::refresh_location_display, this), gui_context());
1106 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), ui_bind (&Editor::refresh_location_display_s, this, _1), gui_context());
1107 _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context());
1109 if (Profile->get_sae()) {
1114 nframes_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
1115 nudge_clock.set_mode(AudioClock::BBT);
1116 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1119 nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
1122 playhead_cursor->canvas_item.show ();
1124 Location* loc = _session->locations()->auto_loop_location();
1126 loc = new Location (0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1127 if (loc->start() == loc->end()) {
1128 loc->set_end (loc->start() + 1);
1130 _session->locations()->add (loc, false);
1131 _session->set_auto_loop_location (loc);
1134 loc->set_name (_("Loop"));
1137 loc = _session->locations()->auto_punch_location();
1139 loc = new Location (0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1140 if (loc->start() == loc->end()) {
1141 loc->set_end (loc->start() + 1);
1143 _session->locations()->add (loc, false);
1144 _session->set_auto_punch_location (loc);
1147 loc->set_name (_("Punch"));
1150 boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
1151 Config->map_parameters (pc);
1152 _session->config.map_parameters (pc);
1154 refresh_location_display ();
1156 restore_ruler_visibility ();
1157 //tempo_map_changed (PropertyChange (0));
1158 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1160 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1161 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1164 super_rapid_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
1165 sigc::mem_fun (*this, &Editor::super_rapid_screen_update)
1168 switch (_snap_type) {
1169 case SnapToRegionStart:
1170 case SnapToRegionEnd:
1171 case SnapToRegionSync:
1172 case SnapToRegionBoundary:
1173 build_region_boundary_cache ();
1180 /* register for undo history */
1181 _session->register_with_memento_command_factory(_id, this);
1183 start_updating_meters ();
1187 Editor::build_cursors ()
1189 using namespace Gdk;
1191 Gdk::Color mbg ("#000000" ); /* Black */
1192 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1195 RefPtr<Bitmap> source, mask;
1196 source = Bitmap::create (mag_bits, mag_width, mag_height);
1197 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1198 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1201 Gdk::Color fbg ("#ffffff" );
1202 Gdk::Color ffg ("#000000" );
1205 RefPtr<Bitmap> source, mask;
1207 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1208 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1209 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1213 RefPtr<Bitmap> source, mask;
1214 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1215 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1216 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1220 RefPtr<Bitmap> bits;
1221 char pix[4] = { 0, 0, 0, 0 };
1222 bits = Bitmap::create (pix, 2, 2);
1224 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1228 RefPtr<Bitmap> bits;
1229 char pix[4] = { 0, 0, 0, 0 };
1230 bits = Bitmap::create (pix, 2, 2);
1232 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1236 grabber_cursor = new Gdk::Cursor (HAND2);
1239 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1240 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1243 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1244 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1247 Glib::RefPtr<Gdk::Pixbuf> apixbuf (::get_icon ("trim_left_cursor"));
1248 left_side_trim_cursor = new Gdk::Cursor (Gdk::Display::get_default(), apixbuf, 5, 17);
1252 Glib::RefPtr<Gdk::Pixbuf> apixbuf (::get_icon ("trim_right_cursor"));
1253 right_side_trim_cursor = new Gdk::Cursor (Gdk::Display::get_default(), apixbuf, 5, 17);
1256 selector_cursor = new Gdk::Cursor (XTERM);
1257 time_fx_cursor = new Gdk::Cursor (SIZING);
1258 wait_cursor = new Gdk::Cursor (WATCH);
1259 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1260 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1261 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1262 midi_resize_cursor = new Gdk::Cursor (SIZING);
1263 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1266 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1268 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1270 using namespace Menu_Helpers;
1271 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1274 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1278 MenuList& items (fade_context_menu.items());
1282 switch (item_type) {
1284 case FadeInHandleItem:
1285 if (arv->audio_region()->fade_in_active()) {
1286 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), false)));
1288 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_active), true)));
1291 items.push_back (SeparatorElem());
1293 if (Profile->get_sae()) {
1294 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1295 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1297 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1298 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1299 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1300 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1301 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1307 case FadeOutHandleItem:
1308 if (arv->audio_region()->fade_out_active()) {
1309 items.push_back (MenuElem (_("Deactivate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), false)));
1311 items.push_back (MenuElem (_("Activate"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_active), true)));
1314 items.push_back (SeparatorElem());
1316 if (Profile->get_sae()) {
1317 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1318 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1320 items.push_back (MenuElem (_("Linear"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1321 items.push_back (MenuElem (_("Slowest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1322 items.push_back (MenuElem (_("Slow"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1323 items.push_back (MenuElem (_("Fast"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1324 items.push_back (MenuElem (_("Fastest"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1330 fatal << _("programming error: ")
1331 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1336 fade_context_menu.popup (button, time);
1340 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1342 using namespace Menu_Helpers;
1343 Menu* (Editor::*build_menu_function)(nframes64_t);
1346 switch (item_type) {
1348 case RegionViewName:
1349 case RegionViewNameHighlight:
1350 case LeftFrameHandle:
1351 case RightFrameHandle:
1352 if (with_selection) {
1353 build_menu_function = &Editor::build_track_selection_context_menu;
1355 build_menu_function = &Editor::build_track_region_context_menu;
1360 if (with_selection) {
1361 build_menu_function = &Editor::build_track_selection_context_menu;
1363 build_menu_function = &Editor::build_track_context_menu;
1367 case CrossfadeViewItem:
1368 build_menu_function = &Editor::build_track_crossfade_context_menu;
1372 if (clicked_routeview->track()) {
1373 build_menu_function = &Editor::build_track_context_menu;
1375 build_menu_function = &Editor::build_track_bus_context_menu;
1380 /* probably shouldn't happen but if it does, we don't care */
1384 menu = (this->*build_menu_function)(frame);
1385 menu->set_name ("ArdourContextMenu");
1387 /* now handle specific situations */
1389 switch (item_type) {
1391 case RegionViewName:
1392 case RegionViewNameHighlight:
1393 case LeftFrameHandle:
1394 case RightFrameHandle:
1395 if (!with_selection) {
1396 if (region_edit_menu_split_item) {
1397 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1398 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1400 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1403 if (region_edit_menu_split_multichannel_item) {
1404 if (clicked_regionview && clicked_regionview->region()->n_channels() > 1) {
1405 region_edit_menu_split_multichannel_item->set_sensitive (true);
1407 region_edit_menu_split_multichannel_item->set_sensitive (false);
1416 case CrossfadeViewItem:
1423 /* probably shouldn't happen but if it does, we don't care */
1427 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1429 /* Bounce to disk */
1431 using namespace Menu_Helpers;
1432 MenuList& edit_items = menu->items();
1434 edit_items.push_back (SeparatorElem());
1436 switch (clicked_routeview->audio_track()->freeze_state()) {
1437 case AudioTrack::NoFreeze:
1438 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1441 case AudioTrack::Frozen:
1442 edit_items.push_back (MenuElem (_("Unfreeze"), sigc::mem_fun(*this, &Editor::unfreeze_route)));
1445 case AudioTrack::UnFrozen:
1446 edit_items.push_back (MenuElem (_("Freeze"), sigc::mem_fun(*this, &Editor::freeze_route)));
1452 if (item_type == StreamItem && clicked_routeview) {
1453 clicked_routeview->build_underlay_menu(menu);
1456 menu->popup (button, time);
1460 Editor::build_track_context_menu (nframes64_t)
1462 using namespace Menu_Helpers;
1464 MenuList& edit_items = track_context_menu.items();
1467 add_dstream_context_items (edit_items);
1468 return &track_context_menu;
1472 Editor::build_track_bus_context_menu (nframes64_t)
1474 using namespace Menu_Helpers;
1476 MenuList& edit_items = track_context_menu.items();
1479 add_bus_context_items (edit_items);
1480 return &track_context_menu;
1484 Editor::build_track_region_context_menu (nframes64_t frame)
1486 using namespace Menu_Helpers;
1487 MenuList& edit_items = track_region_context_menu.items();
1490 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1493 boost::shared_ptr<Track> tr;
1494 boost::shared_ptr<Playlist> pl;
1496 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
1497 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * tr->speed()));
1499 if (selection->regions.size() > 1) {
1500 // there's already a multiple selection: just add a
1501 // single region context menu that will act on all
1503 boost::shared_ptr<Region> dummy_region; // = NULL
1504 add_region_context_items (rtv->view(), dummy_region, edit_items);
1506 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1507 add_region_context_items (rtv->view(), (*i), edit_items);
1515 add_dstream_context_items (edit_items);
1517 return &track_region_context_menu;
1521 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1523 using namespace Menu_Helpers;
1524 MenuList& edit_items = track_crossfade_context_menu.items();
1525 edit_items.clear ();
1527 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1530 boost::shared_ptr<Track> tr;
1531 boost::shared_ptr<Playlist> pl;
1532 boost::shared_ptr<AudioPlaylist> apl;
1534 if ((tr = atv->track()) && ((pl = tr->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1536 Playlist::RegionList* regions = pl->regions_at (frame);
1537 AudioPlaylist::Crossfades xfades;
1539 apl->crossfades_at (frame, xfades);
1541 bool many = xfades.size() > 1;
1543 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1544 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1547 if (selection->regions.size() > 1) {
1548 // there's already a multiple selection: just add a
1549 // single region context menu that will act on all
1551 boost::shared_ptr<Region> dummy_region; // = NULL
1552 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1554 for (Playlist::RegionList::reverse_iterator i = regions->rbegin(); i != regions->rend(); ++i) {
1555 add_region_context_items (atv->audio_view(), (*i), edit_items);
1562 add_dstream_context_items (edit_items);
1564 return &track_crossfade_context_menu;
1568 Editor::analyze_region_selection()
1570 if (analysis_window == 0) {
1571 analysis_window = new AnalysisWindow();
1574 analysis_window->set_session(_session);
1576 analysis_window->show_all();
1579 analysis_window->set_regionmode();
1580 analysis_window->analyze();
1582 analysis_window->present();
1586 Editor::analyze_range_selection()
1588 if (analysis_window == 0) {
1589 analysis_window = new AnalysisWindow();
1592 analysis_window->set_session(_session);
1594 analysis_window->show_all();
1597 analysis_window->set_rangemode();
1598 analysis_window->analyze();
1600 analysis_window->present();
1604 Editor::build_track_selection_context_menu (nframes64_t)
1606 using namespace Menu_Helpers;
1607 MenuList& edit_items = track_selection_context_menu.items();
1608 edit_items.clear ();
1610 add_selection_context_items (edit_items);
1611 // edit_items.push_back (SeparatorElem());
1612 // add_dstream_context_items (edit_items);
1614 return &track_selection_context_menu;
1617 /** Add context menu items relevant to crossfades.
1618 * @param edit_items List to add the items to.
1621 Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1623 using namespace Menu_Helpers;
1624 Menu *xfade_menu = manage (new Menu);
1625 MenuList& items = xfade_menu->items();
1626 xfade_menu->set_name ("ArdourContextMenu");
1629 if (xfade->active()) {
1635 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1636 items.push_back (MenuElem (_("Edit"), sigc::bind (sigc::mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1638 if (xfade->can_follow_overlap()) {
1640 if (xfade->following_overlap()) {
1641 str = _("Convert to Short");
1643 str = _("Convert to Full");
1646 items.push_back (MenuElem (str, sigc::bind (sigc::mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1650 str = xfade->out()->name();
1652 str += xfade->in()->name();
1654 str = _("Crossfade");
1657 edit_items.push_back (MenuElem (str, *xfade_menu));
1658 edit_items.push_back (SeparatorElem());
1662 Editor::xfade_edit_left_region ()
1664 if (clicked_crossfadeview) {
1665 clicked_crossfadeview->left_view.show_region_editor ();
1670 Editor::xfade_edit_right_region ()
1672 if (clicked_crossfadeview) {
1673 clicked_crossfadeview->right_view.show_region_editor ();
1678 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1680 using namespace Menu_Helpers;
1681 Gtk::MenuItem* foo_item;
1682 Menu *region_menu = manage (new Menu);
1683 MenuList& items = region_menu->items();
1684 region_menu->set_name ("ArdourContextMenu");
1686 boost::shared_ptr<AudioRegion> ar;
1687 boost::shared_ptr<MidiRegion> mr;
1690 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1691 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1693 /* when this particular menu pops up, make the relevant region
1697 region_menu->signal_map_event().connect (
1698 sigc::bind (sigc::mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1700 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::rename_region)));
1702 items.push_back (MenuElem (_("List Editor..."), sigc::mem_fun(*this, &Editor::show_midi_list_editor)));
1704 items.push_back (MenuElem (_("Region Properties..."), sigc::mem_fun(*this, &Editor::edit_region)));
1707 items.push_back (MenuElem (_("Raise to Top Layer"), sigc::mem_fun(*this, &Editor::raise_region_to_top)));
1708 items.push_back (MenuElem (_("Lower to Bottom Layer"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom)));
1709 items.push_back (SeparatorElem());
1710 items.push_back (MenuElem (_("Define Sync Point"), sigc::mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1711 if (_edit_point == EditAtMouse) {
1712 items.back ().set_sensitive (false);
1714 items.push_back (MenuElem (_("Remove Sync Point"), sigc::mem_fun(*this, &Editor::remove_region_sync)));
1715 items.push_back (SeparatorElem());
1717 items.push_back (MenuElem (_("Audition"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1718 items.push_back (MenuElem (_("Export..."), sigc::mem_fun(*this, &Editor::export_region)));
1719 items.push_back (MenuElem (_("Bounce"), sigc::mem_fun(*this, &Editor::bounce_region_selection)));
1722 items.push_back (MenuElem (_("Spectral Analysis..."), sigc::mem_fun(*this, &Editor::analyze_region_selection)));
1725 items.push_back (SeparatorElem());
1727 sigc::connection fooc;
1728 boost::shared_ptr<Region> region_to_check;
1731 region_to_check = region;
1733 region_to_check = selection->regions.front()->region();
1736 items.push_back (CheckMenuElem (_("Lock")));
1737 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1738 if (region_to_check->locked()) {
1739 region_lock_item->set_active();
1741 region_lock_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_lock));
1743 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
1744 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1746 switch (region_to_check->positional_lock_style()) {
1747 case Region::MusicTime:
1748 bbt_glue_item->set_active (true);
1751 bbt_glue_item->set_active (false);
1755 bbt_glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_region_lock_style));
1757 items.push_back (CheckMenuElem (_("Mute")));
1758 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1759 fooc = region_mute_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_mute));
1760 if (region_to_check->muted()) {
1762 region_mute_item->set_active();
1766 items.push_back (MenuElem (_("Transpose..."), mem_fun(*this, &Editor::pitch_shift_regions)));
1768 if (!Profile->get_sae()) {
1769 items.push_back (CheckMenuElem (_("Opaque")));
1770 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1771 fooc = region_opaque_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_region_opaque));
1772 if (region_to_check->opaque()) {
1774 region_opaque_item->set_active();
1779 items.push_back (CheckMenuElem (_("Original Position"), sigc::mem_fun(*this, &Editor::naturalize)));
1780 if (region_to_check->at_natural_position()) {
1781 items.back().set_sensitive (false);
1784 items.push_back (SeparatorElem());
1788 RegionView* rv = sv->find_view (ar);
1789 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1791 if (!Profile->get_sae()) {
1792 items.push_back (MenuElem (_("Reset Envelope"), sigc::mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1794 items.push_back (CheckMenuElem (_("Envelope Visible")));
1795 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1796 fooc = region_envelope_visible_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1797 if (arv->envelope_visible()) {
1799 region_envelope_visible_item->set_active (true);
1803 items.push_back (CheckMenuElem (_("Envelope Active")));
1804 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1805 fooc = region_envelope_active_item->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_gain_envelope_active));
1807 if (ar->envelope_active()) {
1809 region_envelope_active_item->set_active (true);
1813 items.push_back (SeparatorElem());
1816 items.push_back (MenuElem (_("Normalize..."), sigc::mem_fun(*this, &Editor::normalize_region)));
1817 if (ar->scale_amplitude() != 1) {
1818 items.push_back (MenuElem (_("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_scale_amplitude)));
1822 items.push_back (MenuElem (_("Quantize"), sigc::mem_fun(*this, &Editor::quantize_region)));
1823 items.push_back (MenuElem (_("Fork"), sigc::mem_fun(*this, &Editor::fork_region)));
1824 items.push_back (SeparatorElem());
1827 items.push_back (MenuElem (_("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence)));
1828 items.push_back (MenuElem (_("Reverse"), sigc::mem_fun(*this, &Editor::reverse_region)));
1829 items.push_back (SeparatorElem());
1831 /* range related stuff */
1833 items.push_back (MenuElem (_("Add Single Range"), sigc::mem_fun (*this, &Editor::add_location_from_audio_region)));
1834 items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_locations_from_audio_region)));
1835 if (selection->regions.size() < 2) {
1836 items.back().set_sensitive (false);
1839 items.push_back (MenuElem (_("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region)));
1840 items.push_back (SeparatorElem());
1844 Menu *nudge_menu = manage (new Menu());
1845 MenuList& nudge_items = nudge_menu->items();
1846 nudge_menu->set_name ("ArdourContextMenu");
1848 nudge_items.push_back (MenuElem (_("Nudge Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_forward), false, false))));
1849 nudge_items.push_back (MenuElem (_("Nudge Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_backward), false, false))));
1850 nudge_items.push_back (MenuElem (_("Nudge Forward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1851 nudge_items.push_back (MenuElem (_("Nudge Backward by Capture Offset"), (sigc::mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1853 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1854 items.push_back (SeparatorElem());
1856 Menu *trim_menu = manage (new Menu);
1857 MenuList& trim_items = trim_menu->items();
1858 trim_menu->set_name ("ArdourContextMenu");
1860 trim_items.push_back (MenuElem (_("Start to Edit Point"), sigc::mem_fun(*this, &Editor::trim_region_from_edit_point)));
1861 foo_item = &trim_items.back();
1862 if (_edit_point == EditAtMouse) {
1863 foo_item->set_sensitive (false);
1865 trim_items.push_back (MenuElem (_("Edit Point to End"), sigc::mem_fun(*this, &Editor::trim_region_to_edit_point)));
1866 foo_item = &trim_items.back();
1867 if (_edit_point == EditAtMouse) {
1868 foo_item->set_sensitive (false);
1870 trim_items.push_back (MenuElem (_("Trim to Loop"), sigc::mem_fun(*this, &Editor::trim_region_to_loop)));
1871 trim_items.push_back (MenuElem (_("Trim to Punch"), sigc::mem_fun(*this, &Editor::trim_region_to_punch)));
1873 items.push_back (MenuElem (_("Trim"), *trim_menu));
1874 items.push_back (SeparatorElem());
1876 items.push_back (MenuElem (_("Split"), (sigc::mem_fun(*this, &Editor::split))));
1877 region_edit_menu_split_item = &items.back();
1879 if (_edit_point == EditAtMouse) {
1880 region_edit_menu_split_item->set_sensitive (false);
1883 items.push_back (MenuElem (_("Make Mono Regions"), (sigc::mem_fun(*this, &Editor::split_multichannel_region))));
1884 region_edit_menu_split_multichannel_item = &items.back();
1886 items.push_back (MenuElem (_("Duplicate"), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false))));
1887 items.push_back (MenuElem (_("Multi-Duplicate..."), (sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), true))));
1888 items.push_back (MenuElem (_("Fill Track"), (sigc::mem_fun(*this, &Editor::region_fill_track))));
1889 items.push_back (SeparatorElem());
1890 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::remove_selected_regions)));
1892 /* OK, stick the region submenu at the top of the list, and then add
1896 /* we have to hack up the region name because "_" has a special
1897 meaning for menu titles.
1900 string::size_type pos = 0;
1901 string menu_item_name = (region) ? region->name() : _("Selected Regions");
1903 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1904 menu_item_name.replace (pos, 1, "__");
1908 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1909 edit_items.push_back (SeparatorElem());
1912 /** Add context menu items relevant to selection ranges.
1913 * @param edit_items List to add the items to.
1916 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1918 using namespace Menu_Helpers;
1920 edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
1921 edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
1923 edit_items.push_back (SeparatorElem());
1924 edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
1926 if (!selection->regions.empty()) {
1927 edit_items.push_back (SeparatorElem());
1928 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)));
1929 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)));
1932 edit_items.push_back (SeparatorElem());
1933 edit_items.push_back (MenuElem (_("Silence Range"), sigc::mem_fun(*this, &Editor::separate_region_from_selection)));
1934 edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
1936 edit_items.push_back (SeparatorElem());
1937 edit_items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1939 edit_items.push_back (SeparatorElem());
1940 edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false)));
1941 edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
1943 edit_items.push_back (SeparatorElem());
1944 edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
1946 edit_items.push_back (SeparatorElem());
1947 edit_items.push_back (MenuElem (_("Crop Region to Range"), sigc::mem_fun(*this, &Editor::crop_region_to_selection)));
1948 edit_items.push_back (MenuElem (_("Fill Range with Region"), sigc::mem_fun(*this, &Editor::region_fill_selection)));
1949 edit_items.push_back (MenuElem (_("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_dialog), false)));
1951 edit_items.push_back (SeparatorElem());
1952 edit_items.push_back (MenuElem (_("Consolidate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1953 edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1954 edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1955 edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1956 edit_items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_selection)));
1961 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1963 using namespace Menu_Helpers;
1967 Menu *play_menu = manage (new Menu);
1968 MenuList& play_items = play_menu->items();
1969 play_menu->set_name ("ArdourContextMenu");
1971 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
1972 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
1973 play_items.push_back (MenuElem (_("Play Region"), sigc::mem_fun(*this, &Editor::play_selected_region)));
1974 play_items.push_back (SeparatorElem());
1975 play_items.push_back (MenuElem (_("Loop Region"), sigc::mem_fun(*this, &Editor::loop_selected_region)));
1977 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1981 Menu *select_menu = manage (new Menu);
1982 MenuList& select_items = select_menu->items();
1983 select_menu->set_name ("ArdourContextMenu");
1985 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1986 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
1987 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
1988 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
1989 select_items.push_back (SeparatorElem());
1990 select_items.push_back (MenuElem (_("Set Range to Loop Range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop)));
1991 select_items.push_back (MenuElem (_("Set Range to Punch Range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch)));
1992 select_items.push_back (SeparatorElem());
1993 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1994 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1995 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1996 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1997 select_items.push_back (MenuElem (_("Select All Between Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
1998 select_items.push_back (MenuElem (_("Select All Within Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
1999 select_items.push_back (MenuElem (_("Select Range Between Playhead and Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
2001 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2005 Menu *cutnpaste_menu = manage (new Menu);
2006 MenuList& cutnpaste_items = cutnpaste_menu->items();
2007 cutnpaste_menu->set_name ("ArdourContextMenu");
2009 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2010 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2011 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2013 cutnpaste_items.push_back (SeparatorElem());
2015 cutnpaste_items.push_back (MenuElem (_("Align"), sigc::bind (sigc::mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2016 cutnpaste_items.push_back (MenuElem (_("Align Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2018 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2020 /* Adding new material */
2022 edit_items.push_back (SeparatorElem());
2023 edit_items.push_back (MenuElem (_("Insert Selected Region"), sigc::bind (sigc::mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2024 edit_items.push_back (MenuElem (_("Insert Existing Media"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2028 Menu *nudge_menu = manage (new Menu());
2029 MenuList& nudge_items = nudge_menu->items();
2030 nudge_menu->set_name ("ArdourContextMenu");
2032 edit_items.push_back (SeparatorElem());
2033 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2034 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2035 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2036 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2038 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2042 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2044 using namespace Menu_Helpers;
2048 Menu *play_menu = manage (new Menu);
2049 MenuList& play_items = play_menu->items();
2050 play_menu->set_name ("ArdourContextMenu");
2052 play_items.push_back (MenuElem (_("Play From Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point)));
2053 play_items.push_back (MenuElem (_("Play From Start"), sigc::mem_fun(*this, &Editor::play_from_start)));
2054 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2058 Menu *select_menu = manage (new Menu);
2059 MenuList& select_items = select_menu->items();
2060 select_menu->set_name ("ArdourContextMenu");
2062 select_items.push_back (MenuElem (_("Select All in Track"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2063 select_items.push_back (MenuElem (_("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set)));
2064 select_items.push_back (MenuElem (_("Invert Selection in Track"), sigc::mem_fun(*this, &Editor::invert_selection_in_track)));
2065 select_items.push_back (MenuElem (_("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection)));
2066 select_items.push_back (SeparatorElem());
2067 select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2068 select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2069 select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2070 select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2072 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2076 Menu *cutnpaste_menu = manage (new Menu);
2077 MenuList& cutnpaste_items = cutnpaste_menu->items();
2078 cutnpaste_menu->set_name ("ArdourContextMenu");
2080 cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
2081 cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
2082 cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f)));
2084 Menu *nudge_menu = manage (new Menu());
2085 MenuList& nudge_items = nudge_menu->items();
2086 nudge_menu->set_name ("ArdourContextMenu");
2088 edit_items.push_back (SeparatorElem());
2089 nudge_items.push_back (MenuElem (_("Nudge Entire Track Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, true))));
2090 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Forward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, true))));
2091 nudge_items.push_back (MenuElem (_("Nudge Entire Track Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), false, false))));
2092 nudge_items.push_back (MenuElem (_("Nudge Track After Edit Point Backward"), (sigc::bind (sigc::mem_fun(*this, &Editor::nudge_track), true, false))));
2094 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2098 Editor::snap_type() const
2104 Editor::snap_mode() const
2110 Editor::set_snap_to (SnapType st)
2112 unsigned int snap_ind = (unsigned int)st;
2116 if (snap_ind > snap_type_strings.size() - 1) {
2118 _snap_type = (SnapType)snap_ind;
2121 string str = snap_type_strings[snap_ind];
2123 if (str != snap_type_selector.get_active_text()) {
2124 snap_type_selector.set_active_text (str);
2129 switch (_snap_type) {
2130 case SnapToBeatDiv32:
2131 case SnapToBeatDiv28:
2132 case SnapToBeatDiv24:
2133 case SnapToBeatDiv16:
2134 case SnapToBeatDiv14:
2135 case SnapToBeatDiv12:
2136 case SnapToBeatDiv10:
2137 case SnapToBeatDiv8:
2138 case SnapToBeatDiv7:
2139 case SnapToBeatDiv6:
2140 case SnapToBeatDiv5:
2141 case SnapToBeatDiv4:
2142 case SnapToBeatDiv3:
2143 case SnapToBeatDiv2:
2144 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2145 update_tempo_based_rulers ();
2148 case SnapToRegionStart:
2149 case SnapToRegionEnd:
2150 case SnapToRegionSync:
2151 case SnapToRegionBoundary:
2152 build_region_boundary_cache ();
2160 SnapChanged (); /* EMIT SIGNAL */
2164 Editor::set_snap_mode (SnapMode mode)
2167 string str = snap_mode_strings[(int)mode];
2169 if (str != snap_mode_selector.get_active_text ()) {
2170 snap_mode_selector.set_active_text (str);
2176 Editor::set_edit_point_preference (EditPoint ep, bool force)
2178 bool changed = (_edit_point != ep);
2181 string str = edit_point_strings[(int)ep];
2183 if (str != edit_point_selector.get_active_text ()) {
2184 edit_point_selector.set_active_text (str);
2187 set_canvas_cursor ();
2189 if (!force && !changed) {
2193 const char* action=NULL;
2195 switch (_edit_point) {
2196 case EditAtPlayhead:
2197 action = "edit-at-playhead";
2199 case EditAtSelectedMarker:
2200 action = "edit-at-marker";
2203 action = "edit-at-mouse";
2207 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2209 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2213 bool in_track_canvas;
2215 if (!mouse_frame (foo, in_track_canvas)) {
2216 in_track_canvas = false;
2219 reset_canvas_action_sensitivity (in_track_canvas);
2225 Editor::set_state (const XMLNode& node, int /*version*/)
2227 const XMLProperty* prop;
2229 int x, y, xoff, yoff;
2232 if ((prop = node.property ("id")) != 0) {
2233 _id = prop->value ();
2236 g.base_width = default_width;
2237 g.base_height = default_height;
2243 if ((geometry = find_named_node (node, "geometry")) != 0) {
2247 if ((prop = geometry->property("x_size")) == 0) {
2248 prop = geometry->property ("x-size");
2251 g.base_width = atoi(prop->value());
2253 if ((prop = geometry->property("y_size")) == 0) {
2254 prop = geometry->property ("y-size");
2257 g.base_height = atoi(prop->value());
2260 if ((prop = geometry->property ("x_pos")) == 0) {
2261 prop = geometry->property ("x-pos");
2264 x = atoi (prop->value());
2267 if ((prop = geometry->property ("y_pos")) == 0) {
2268 prop = geometry->property ("y-pos");
2271 y = atoi (prop->value());
2274 if ((prop = geometry->property ("x_off")) == 0) {
2275 prop = geometry->property ("x-off");
2278 xoff = atoi (prop->value());
2280 if ((prop = geometry->property ("y_off")) == 0) {
2281 prop = geometry->property ("y-off");
2284 yoff = atoi (prop->value());
2288 set_default_size (g.base_width, g.base_height);
2291 if (_session && (prop = node.property ("playhead"))) {
2293 sscanf (prop->value().c_str(), "%" PRIi64, &pos);
2294 playhead_cursor->set_position (pos);
2296 playhead_cursor->set_position (0);
2299 if ((prop = node.property ("mixer-width"))) {
2300 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2303 if ((prop = node.property ("zoom-focus"))) {
2304 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2307 if ((prop = node.property ("zoom"))) {
2308 reset_zoom (PBD::atof (prop->value()));
2311 if ((prop = node.property ("snap-to"))) {
2312 set_snap_to ((SnapType) atoi (prop->value()));
2315 if ((prop = node.property ("snap-mode"))) {
2316 set_snap_mode ((SnapMode) atoi (prop->value()));
2319 if ((prop = node.property ("mouse-mode"))) {
2320 MouseMode m = str2mousemode(prop->value());
2321 set_mouse_mode (m, true);
2323 set_mouse_mode (MouseObject, true);
2326 if ((prop = node.property ("left-frame")) != 0){
2328 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
2329 reset_x_origin (pos);
2333 if ((prop = node.property ("y-origin")) != 0) {
2334 reset_y_origin (atof (prop->value ()));
2337 if ((prop = node.property ("internal-edit"))) {
2338 bool yn = string_is_affirmative (prop->value());
2339 RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit"));
2341 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2342 tact->set_active (!yn);
2343 tact->set_active (yn);
2347 if ((prop = node.property ("join-object-range"))) {
2348 join_object_range_button.set_active (string_is_affirmative (prop->value ()));
2351 if ((prop = node.property ("edit-point"))) {
2352 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2355 if ((prop = node.property ("show-measures"))) {
2356 bool yn = string_is_affirmative (prop->value());
2357 _show_measures = !yn;
2358 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2360 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2361 /* do it twice to force the change */
2362 tact->set_active (!yn);
2363 tact->set_active (yn);
2367 if ((prop = node.property ("follow-playhead"))) {
2368 bool yn = string_is_affirmative (prop->value());
2369 set_follow_playhead (yn);
2370 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2372 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2373 if (tact->get_active() != yn) {
2374 tact->set_active (yn);
2379 if ((prop = node.property ("stationary-playhead"))) {
2380 bool yn = (prop->value() == "yes");
2381 set_stationary_playhead (yn);
2382 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
2384 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2385 if (tact->get_active() != yn) {
2386 tact->set_active (yn);
2391 if ((prop = node.property ("region-list-sort-type"))) {
2392 RegionListSortType st;
2393 _regions->reset_sort_type ((RegionListSortType) string_2_enum (prop->value(), st), true);
2396 if ((prop = node.property ("xfades-visible"))) {
2397 bool yn = string_is_affirmative (prop->value());
2398 _xfade_visibility = !yn;
2399 // set_xfade_visibility (yn);
2402 if ((prop = node.property ("show-editor-mixer"))) {
2404 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2407 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2408 bool yn = string_is_affirmative (prop->value());
2410 /* do it twice to force the change */
2412 tact->set_active (!yn);
2413 tact->set_active (yn);
2417 if ((prop = node.property ("show-editor-list"))) {
2419 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2423 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2424 bool yn = string_is_affirmative (prop->value());
2426 /* do it twice to force the change */
2428 tact->set_active (!yn);
2429 tact->set_active (yn);
2433 if ((prop = node.property (X_("editor-list-page")))) {
2434 the_notebook.set_current_page (atoi (prop->value ()));
2441 Editor::get_state ()
2443 XMLNode* node = new XMLNode ("Editor");
2446 _id.print (buf, sizeof (buf));
2447 node->add_property ("id", buf);
2449 if (is_realized()) {
2450 Glib::RefPtr<Gdk::Window> win = get_window();
2452 int x, y, xoff, yoff, width, height;
2453 win->get_root_origin(x, y);
2454 win->get_position(xoff, yoff);
2455 win->get_size(width, height);
2457 XMLNode* geometry = new XMLNode ("geometry");
2459 snprintf(buf, sizeof(buf), "%d", width);
2460 geometry->add_property("x-size", string(buf));
2461 snprintf(buf, sizeof(buf), "%d", height);
2462 geometry->add_property("y-size", string(buf));
2463 snprintf(buf, sizeof(buf), "%d", x);
2464 geometry->add_property("x-pos", string(buf));
2465 snprintf(buf, sizeof(buf), "%d", y);
2466 geometry->add_property("y-pos", string(buf));
2467 snprintf(buf, sizeof(buf), "%d", xoff);
2468 geometry->add_property("x-off", string(buf));
2469 snprintf(buf, sizeof(buf), "%d", yoff);
2470 geometry->add_property("y-off", string(buf));
2471 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2472 geometry->add_property("edit-horizontal-pane-pos", string(buf));
2473 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&editor_summary_pane)->gobj()));
2474 geometry->add_property("edit-vertical-pane-pos", string(buf));
2476 node->add_child_nocopy (*geometry);
2479 maybe_add_mixer_strip_width (*node);
2481 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2482 node->add_property ("zoom-focus", buf);
2483 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2484 node->add_property ("zoom", buf);
2485 snprintf (buf, sizeof(buf), "%d", (int) _snap_type);
2486 node->add_property ("snap-to", buf);
2487 snprintf (buf, sizeof(buf), "%d", (int) _snap_mode);
2488 node->add_property ("snap-mode", buf);
2490 node->add_property ("edit-point", enum_2_string (_edit_point));
2492 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2493 node->add_property ("playhead", buf);
2494 snprintf (buf, sizeof (buf), "%" PRIi64, leftmost_frame);
2495 node->add_property ("left-frame", buf);
2496 snprintf (buf, sizeof (buf), "%f", vertical_adjustment.get_value ());
2497 node->add_property ("y-origin", buf);
2499 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2500 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2501 node->add_property ("stationary-playhead", _stationary_playhead ? "yes" : "no");
2502 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2503 node->add_property ("region-list-sort-type", enum_2_string (_regions->sort_type ()));
2504 node->add_property ("mouse-mode", enum2str(mouse_mode));
2505 node->add_property ("internal-edit", _internal_editing ? "yes" : "no");
2506 node->add_property ("join-object-range", join_object_range_button.get_active () ? "yes" : "no");
2508 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2510 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2511 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2514 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2516 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2517 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2520 snprintf (buf, sizeof (buf), "%d", the_notebook.get_current_page ());
2521 node->add_property (X_("editor-list-page"), buf);
2528 /** @param y y offset from the top of all trackviews.
2529 * @return pair: TimeAxisView that y is over, layer index.
2530 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2531 * in stacked region display mode, otherwise 0.
2533 std::pair<TimeAxisView *, layer_t>
2534 Editor::trackview_by_y_position (double y)
2536 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2538 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2544 return std::make_pair ( (TimeAxisView *) 0, 0);
2547 /** Snap a position to the grid, if appropriate, taking into account current
2548 * grid settings and also the state of any snap modifier keys that may be pressed.
2549 * @param start Position to snap.
2550 * @param event Event to get current key modifier information from, or 0.
2553 Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
2555 if (!_session || !event) {
2559 if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
2560 if (_snap_mode == SnapOff) {
2561 snap_to_internal (start, direction, for_mark);
2564 if (_snap_mode != SnapOff) {
2565 snap_to_internal (start, direction, for_mark);
2571 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2573 if (!_session || _snap_mode == SnapOff) {
2577 snap_to_internal (start, direction, for_mark);
2581 Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
2583 const nframes64_t one_timecode_second = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
2584 nframes64_t one_timecode_minute = (nframes64_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
2586 switch (_snap_type) {
2587 case SnapToTimecodeFrame:
2588 if (((direction == 0) && (fmod((double)start, (double)_session->frames_per_timecode_frame()) > (_session->frames_per_timecode_frame() / 2))) || (direction > 0)) {
2589 start = (nframes64_t) (ceil ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2591 start = (nframes64_t) (floor ((double) start / _session->frames_per_timecode_frame()) * _session->frames_per_timecode_frame());
2595 case SnapToTimecodeSeconds:
2596 if (_session->timecode_offset_negative())
2598 start += _session->timecode_offset ();
2600 start -= _session->timecode_offset ();
2602 if (((direction == 0) && (start % one_timecode_second > one_timecode_second / 2)) || direction > 0) {
2603 start = (nframes64_t) ceil ((double) start / one_timecode_second) * one_timecode_second;
2605 start = (nframes64_t) floor ((double) start / one_timecode_second) * one_timecode_second;
2608 if (_session->timecode_offset_negative())
2610 start -= _session->timecode_offset ();
2612 start += _session->timecode_offset ();
2616 case SnapToTimecodeMinutes:
2617 if (_session->timecode_offset_negative())
2619 start += _session->timecode_offset ();
2621 start -= _session->timecode_offset ();
2623 if (((direction == 0) && (start % one_timecode_minute > one_timecode_minute / 2)) || direction > 0) {
2624 start = (nframes64_t) ceil ((double) start / one_timecode_minute) * one_timecode_minute;
2626 start = (nframes64_t) floor ((double) start / one_timecode_minute) * one_timecode_minute;
2628 if (_session->timecode_offset_negative())
2630 start -= _session->timecode_offset ();
2632 start += _session->timecode_offset ();
2636 fatal << "Editor::smpte_snap_to_internal() called with non-timecode snap type!" << endmsg;
2642 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2644 const nframes64_t one_second = _session->frame_rate();
2645 const nframes64_t one_minute = _session->frame_rate() * 60;
2646 nframes64_t presnap = start;
2650 switch (_snap_type) {
2651 case SnapToTimecodeFrame:
2652 case SnapToTimecodeSeconds:
2653 case SnapToTimecodeMinutes:
2654 return timecode_snap_to_internal (start, direction, for_mark);
2657 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2658 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2660 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2665 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2666 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2668 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2673 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2674 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2676 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2681 start = _session->tempo_map().round_to_bar (start, direction);
2685 start = _session->tempo_map().round_to_beat (start, direction);
2688 case SnapToBeatDiv32:
2689 start = _session->tempo_map().round_to_beat_subdivision (start, 32, direction);
2691 case SnapToBeatDiv28:
2692 start = _session->tempo_map().round_to_beat_subdivision (start, 28, direction);
2694 case SnapToBeatDiv24:
2695 start = _session->tempo_map().round_to_beat_subdivision (start, 24, direction);
2697 case SnapToBeatDiv16:
2698 start = _session->tempo_map().round_to_beat_subdivision (start, 16, direction);
2700 case SnapToBeatDiv14:
2701 start = _session->tempo_map().round_to_beat_subdivision (start, 14, direction);
2703 case SnapToBeatDiv12:
2704 start = _session->tempo_map().round_to_beat_subdivision (start, 12, direction);
2706 case SnapToBeatDiv10:
2707 start = _session->tempo_map().round_to_beat_subdivision (start, 10, direction);
2709 case SnapToBeatDiv8:
2710 start = _session->tempo_map().round_to_beat_subdivision (start, 8, direction);
2712 case SnapToBeatDiv7:
2713 start = _session->tempo_map().round_to_beat_subdivision (start, 7, direction);
2715 case SnapToBeatDiv6:
2716 start = _session->tempo_map().round_to_beat_subdivision (start, 6, direction);
2718 case SnapToBeatDiv5:
2719 start = _session->tempo_map().round_to_beat_subdivision (start, 5, direction);
2721 case SnapToBeatDiv4:
2722 start = _session->tempo_map().round_to_beat_subdivision (start, 4, direction);
2724 case SnapToBeatDiv3:
2725 start = _session->tempo_map().round_to_beat_subdivision (start, 3, direction);
2727 case SnapToBeatDiv2:
2728 start = _session->tempo_map().round_to_beat_subdivision (start, 2, direction);
2736 _session->locations()->marks_either_side (start, before, after);
2738 if (before == max_frames) {
2740 } else if (after == max_frames) {
2742 } else if (before != max_frames && after != max_frames) {
2743 /* have before and after */
2744 if ((start - before) < (after - start)) {
2753 case SnapToRegionStart:
2754 case SnapToRegionEnd:
2755 case SnapToRegionSync:
2756 case SnapToRegionBoundary:
2757 if (!region_boundary_cache.empty()) {
2759 vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
2760 vector<nframes64_t>::iterator next = region_boundary_cache.end ();
2762 if (direction > 0) {
2763 next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2765 next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2768 if (next != region_boundary_cache.begin ()) {
2773 nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
2774 nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
2776 if (start > (p + n) / 2) {
2785 switch (_snap_mode) {
2791 if (presnap > start) {
2792 if (presnap > (start + unit_to_frame(snap_threshold))) {
2796 } else if (presnap < start) {
2797 if (presnap < (start - unit_to_frame(snap_threshold))) {
2803 /* handled at entry */
2811 Editor::setup_toolbar ()
2815 /* Mode Buttons (tool selection) */
2817 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2818 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2819 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2820 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2821 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2822 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2823 // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
2824 join_object_range_button.set_relief(Gtk::RELIEF_NONE);
2826 HBox* mode_box = manage(new HBox);
2827 mode_box->set_border_width (2);
2828 mode_box->set_spacing(4);
2830 /* table containing mode buttons */
2832 HBox* mouse_mode_button_box = manage (new HBox ());
2834 if (Profile->get_sae()) {
2835 mouse_mode_button_box->pack_start (mouse_move_button);
2837 mouse_mode_button_box->pack_start (mouse_move_button);
2838 mouse_mode_button_box->pack_start (join_object_range_button);
2839 mouse_mode_button_box->pack_start (mouse_select_button);
2842 mouse_mode_button_box->pack_start (mouse_zoom_button);
2844 if (!Profile->get_sae()) {
2845 mouse_mode_button_box->pack_start (mouse_gain_button);
2848 mouse_mode_button_box->pack_start (mouse_timefx_button);
2849 mouse_mode_button_box->pack_start (mouse_audition_button);
2850 mouse_mode_button_box->pack_start (internal_edit_button);
2852 vector<string> edit_mode_strings;
2853 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2854 if (!Profile->get_sae()) {
2855 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2857 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2859 edit_mode_selector.set_name ("EditModeSelector");
2860 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2861 edit_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_mode_selection_done));
2863 mode_box->pack_start (edit_mode_selector);
2864 mode_box->pack_start (*mouse_mode_button_box);
2866 _mouse_mode_tearoff = manage (new TearOff (*mode_box));
2867 _mouse_mode_tearoff->set_name ("MouseModeBase");
2868 _mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_mouse_mode_tearoff->tearoff_window()), false);
2870 if (Profile->get_sae()) {
2871 _mouse_mode_tearoff->set_can_be_torn_off (false);
2874 _mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2875 &_mouse_mode_tearoff->tearoff_window()));
2876 _mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2877 &_mouse_mode_tearoff->tearoff_window(), 1));
2878 _mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2879 &_mouse_mode_tearoff->tearoff_window()));
2880 _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2881 &_mouse_mode_tearoff->tearoff_window(), 1));
2883 mouse_move_button.set_mode (false);
2884 mouse_select_button.set_mode (false);
2885 mouse_gain_button.set_mode (false);
2886 mouse_zoom_button.set_mode (false);
2887 mouse_timefx_button.set_mode (false);
2888 mouse_audition_button.set_mode (false);
2889 join_object_range_button.set_mode (false);
2891 mouse_move_button.set_name ("MouseModeButton");
2892 mouse_select_button.set_name ("MouseModeButton");
2893 mouse_gain_button.set_name ("MouseModeButton");
2894 mouse_zoom_button.set_name ("MouseModeButton");
2895 mouse_timefx_button.set_name ("MouseModeButton");
2896 mouse_audition_button.set_name ("MouseModeButton");
2897 internal_edit_button.set_name ("MouseModeButton");
2898 join_object_range_button.set_name ("MouseModeButton");
2900 mouse_move_button.unset_flags (CAN_FOCUS);
2901 mouse_select_button.unset_flags (CAN_FOCUS);
2902 mouse_gain_button.unset_flags (CAN_FOCUS);
2903 mouse_zoom_button.unset_flags (CAN_FOCUS);
2904 mouse_timefx_button.unset_flags (CAN_FOCUS);
2905 mouse_audition_button.unset_flags (CAN_FOCUS);
2906 internal_edit_button.unset_flags (CAN_FOCUS);
2907 join_object_range_button.unset_flags (CAN_FOCUS);
2911 zoom_box.set_spacing (1);
2912 zoom_box.set_border_width (0);
2914 zoom_in_button.set_name ("EditorTimeButton");
2915 zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_MENU))));
2916 zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
2918 zoom_out_button.set_name ("EditorTimeButton");
2919 zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_MENU))));
2920 zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
2922 zoom_out_full_button.set_name ("EditorTimeButton");
2923 zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_MENU))));
2924 zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
2926 zoom_focus_selector.set_name ("ZoomFocusSelector");
2927 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2928 zoom_focus_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done));
2930 zoom_box.pack_start (zoom_out_button, false, false);
2931 zoom_box.pack_start (zoom_in_button, false, false);
2932 zoom_box.pack_start (zoom_out_full_button, false, false);
2934 /* Track zoom buttons */
2935 tav_expand_button.set_name ("TrackHeightButton");
2936 tav_expand_button.set_size_request(-1,20);
2937 tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
2938 tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
2940 tav_shrink_button.set_name ("TrackHeightButton");
2941 tav_shrink_button.set_size_request(-1,20);
2942 tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
2943 tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
2945 track_zoom_box.set_spacing (1);
2946 track_zoom_box.set_border_width (0);
2948 track_zoom_box.pack_start (tav_shrink_button, false, false);
2949 track_zoom_box.pack_start (tav_expand_button, false, false);
2951 HBox* zbc = manage (new HBox);
2952 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2953 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2954 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2955 zoom_vbox.pack_start (track_zoom_box, PACK_SHRINK);
2957 snap_box.set_spacing (1);
2958 snap_box.set_border_width (2);
2960 snap_type_selector.set_name ("SnapTypeSelector");
2961 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2962 snap_type_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_type_selection_done));
2964 snap_mode_selector.set_name ("SnapModeSelector");
2965 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2966 snap_mode_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::snap_mode_selection_done));
2968 edit_point_selector.set_name ("EditPointSelector");
2969 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2970 edit_point_selector.signal_changed().connect (sigc::mem_fun(*this, &Editor::edit_point_selection_done));
2972 snap_box.pack_start (snap_mode_selector, false, false);
2973 snap_box.pack_start (snap_type_selector, false, false);
2974 snap_box.pack_start (edit_point_selector, false, false);
2978 HBox *nudge_box = manage (new HBox);
2979 nudge_box->set_spacing(1);
2980 nudge_box->set_border_width (2);
2982 nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
2983 nudge_backward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_backward_release), false);
2985 nudge_box->pack_start (nudge_backward_button, false, false);
2986 nudge_box->pack_start (nudge_forward_button, false, false);
2987 nudge_box->pack_start (nudge_clock, false, false);
2990 /* Pack everything in... */
2992 HBox* hbox = manage (new HBox);
2993 hbox->set_spacing(10);
2995 _tools_tearoff = manage (new TearOff (*hbox));
2996 _tools_tearoff->set_name ("MouseModeBase");
2997 _tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_tools_tearoff->tearoff_window()), false);
2999 if (Profile->get_sae()) {
3000 _tools_tearoff->set_can_be_torn_off (false);
3003 _tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3004 &_tools_tearoff->tearoff_window()));
3005 _tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3006 &_tools_tearoff->tearoff_window(), 0));
3007 _tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3008 &_tools_tearoff->tearoff_window()));
3009 _tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3010 &_tools_tearoff->tearoff_window(), 0));
3012 toolbar_hbox.set_spacing (10);
3013 toolbar_hbox.set_border_width (1);
3015 toolbar_hbox.pack_start (*_mouse_mode_tearoff, false, false);
3016 toolbar_hbox.pack_start (*_tools_tearoff, false, false);
3018 hbox->pack_start (snap_box, false, false);
3019 hbox->pack_start (*nudge_box, false, false);
3020 hbox->pack_start (panic_box, false, false);
3024 toolbar_base.set_name ("ToolBarBase");
3025 toolbar_base.add (toolbar_hbox);
3027 toolbar_frame.set_shadow_type (SHADOW_OUT);
3028 toolbar_frame.set_name ("BaseFrame");
3029 toolbar_frame.add (toolbar_base);
3033 Editor::setup_tooltips ()
3035 ARDOUR_UI::instance()->set_tip (mouse_move_button, _("Select/Move Objects"));
3036 ARDOUR_UI::instance()->set_tip (mouse_gain_button, _("Draw Gain Automation"));
3037 ARDOUR_UI::instance()->set_tip (mouse_zoom_button, _("Select Zoom Range"));
3038 ARDOUR_UI::instance()->set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
3039 ARDOUR_UI::instance()->set_tip (mouse_audition_button, _("Listen to Specific Regions"));
3040 ARDOUR_UI::instance()->set_tip (join_object_range_button, _("Select/Move Objects or Ranges"));
3041 ARDOUR_UI::instance()->set_tip (internal_edit_button, _("Edit Region Contents (e.g. notes)"));
3042 ARDOUR_UI::instance()->set_tip (*_group_tabs, _("Groups: context-click for possible operations"));
3043 ARDOUR_UI::instance()->set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
3044 ARDOUR_UI::instance()->set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
3045 ARDOUR_UI::instance()->set_tip (zoom_in_button, _("Zoom In"));
3046 ARDOUR_UI::instance()->set_tip (zoom_out_button, _("Zoom Out"));
3047 ARDOUR_UI::instance()->set_tip (zoom_out_full_button, _("Zoom to Session"));
3048 ARDOUR_UI::instance()->set_tip (zoom_focus_selector, _("Zoom focus"));
3049 ARDOUR_UI::instance()->set_tip (tav_expand_button, _("Expand Tracks"));
3050 ARDOUR_UI::instance()->set_tip (tav_shrink_button, _("Shrink Tracks"));
3051 ARDOUR_UI::instance()->set_tip (snap_type_selector, _("Snap/Grid Units"));
3052 ARDOUR_UI::instance()->set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3053 ARDOUR_UI::instance()->set_tip (edit_point_selector, _("Edit point"));
3054 ARDOUR_UI::instance()->set_tip (midi_sound_notes, _("Sound Notes"));
3055 ARDOUR_UI::instance()->set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
3059 Editor::midi_panic ()
3061 cerr << "MIDI panic\n";
3064 _session->midi_panic();
3069 Editor::setup_midi_toolbar ()
3073 /* Midi sound notes */
3074 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3075 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3076 midi_sound_notes.unset_flags (CAN_FOCUS);
3080 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
3081 midi_panic_button.set_name("MidiPanicButton");
3082 act->connect_proxy (midi_panic_button);
3084 panic_box.pack_start (midi_sound_notes , true, true);
3085 panic_box.pack_start (midi_panic_button, true, true);
3089 Editor::convert_drop_to_paths (
3090 vector<ustring>& paths,
3091 const RefPtr<Gdk::DragContext>& /*context*/,
3094 const SelectionData& data,
3098 if (_session == 0) {
3102 vector<ustring> uris = data.get_uris();
3106 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3107 are actually URI lists. So do it by hand.
3110 if (data.get_target() != "text/plain") {
3114 /* Parse the "uri-list" format that Nautilus provides,
3115 where each pathname is delimited by \r\n.
3117 THERE MAY BE NO NULL TERMINATING CHAR!!!
3120 ustring txt = data.get_text();
3124 p = (const char *) malloc (txt.length() + 1);
3125 txt.copy ((char *) p, txt.length(), 0);
3126 ((char*)p)[txt.length()] = '\0';
3132 while (g_ascii_isspace (*p))
3136 while (*q && (*q != '\n') && (*q != '\r')) {
3143 while (q > p && g_ascii_isspace (*q))
3148 uris.push_back (ustring (p, q - p + 1));
3152 p = strchr (p, '\n');
3164 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3166 if ((*i).substr (0,7) == "file://") {
3169 PBD::url_decode (p);
3171 // scan forward past three slashes
3173 ustring::size_type slashcnt = 0;
3174 ustring::size_type n = 0;
3175 ustring::iterator x = p.begin();
3177 while (slashcnt < 3 && x != p.end()) {
3180 } else if (slashcnt == 3) {
3187 if (slashcnt != 3 || x == p.end()) {
3188 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3192 paths.push_back (p.substr (n - 1));
3200 Editor::new_tempo_section ()
3206 Editor::map_transport_state ()
3208 ENSURE_GUI_THREAD (*this, &Editor::map_transport_state)
3210 if (_session && _session->transport_stopped()) {
3211 have_pending_keyboard_selection = false;
3214 update_loop_range_view (true);
3219 Editor::State::State (PublicEditor const * e)
3221 selection = new Selection (e);
3224 Editor::State::~State ()
3230 Editor::begin_reversible_command (string name)
3233 _session->begin_reversible_command (name);
3238 Editor::commit_reversible_command ()
3241 _session->commit_reversible_command ();
3246 Editor::set_route_group_solo (Route& route, bool yn)
3248 RouteGroup *route_group;
3250 if ((route_group = route.route_group()) != 0) {
3251 route_group->apply (&Route::set_solo, yn, this);
3253 route.set_solo (yn, this);
3258 Editor::set_route_group_mute (Route& route, bool yn)
3260 RouteGroup *route_group = 0;
3262 if ((route_group = route.route_group()) != 0) {
3263 route_group->apply (&Route::set_mute, yn, this);
3265 route.set_mute (yn, this);
3270 Editor::history_changed ()
3274 if (undo_action && _session) {
3275 if (_session->undo_depth() == 0) {
3278 label = string_compose(_("Undo (%1)"), _session->next_undo());
3280 undo_action->property_label() = label;
3283 if (redo_action && _session) {
3284 if (_session->redo_depth() == 0) {
3287 label = string_compose(_("Redo (%1)"), _session->next_redo());
3289 redo_action->property_label() = label;
3294 Editor::duplicate_dialog (bool with_dialog)
3298 if (mouse_mode == MouseRange) {
3299 if (selection->time.length() == 0) {
3305 get_regions_for_action (rs);
3307 if (mouse_mode != MouseRange) {
3316 ArdourDialog win (_("Duplicate"));
3317 Label label (_("Number of duplications:"));
3318 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3319 SpinButton spinner (adjustment, 0.0, 1);
3322 win.get_vbox()->set_spacing (12);
3323 win.get_vbox()->pack_start (hbox);
3324 hbox.set_border_width (6);
3325 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3327 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3328 place, visually. so do this by hand.
3331 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3332 spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3333 spinner.grab_focus();
3339 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3340 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3341 win.set_default_response (RESPONSE_ACCEPT);
3343 win.set_position (WIN_POS_MOUSE);
3345 spinner.grab_focus ();
3347 switch (win.run ()) {
3348 case RESPONSE_ACCEPT:
3354 times = adjustment.get_value();
3357 if (mouse_mode == MouseRange) {
3358 duplicate_selection (times);
3360 duplicate_some_regions (rs, times);
3365 Editor::show_verbose_canvas_cursor ()
3367 verbose_canvas_cursor->raise_to_top();
3368 verbose_canvas_cursor->show();
3369 verbose_cursor_visible = true;
3373 Editor::hide_verbose_canvas_cursor ()
3375 verbose_canvas_cursor->hide();
3376 verbose_cursor_visible = false;
3380 Editor::clamp_verbose_cursor_x (double x)
3385 x = min (_canvas_width - 200.0, x);
3391 Editor::clamp_verbose_cursor_y (double y)
3393 if (y < canvas_timebars_vsize) {
3394 y = canvas_timebars_vsize;
3396 y = min (_canvas_height - 50, y);
3402 Editor::show_verbose_canvas_cursor_with (const string & txt)
3404 verbose_canvas_cursor->property_text() = txt.c_str();
3409 track_canvas->get_pointer (x, y);
3410 track_canvas->window_to_world (x, y, wx, wy);
3412 /* don't get too close to the edge */
3413 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
3414 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
3416 show_verbose_canvas_cursor ();
3420 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3422 verbose_canvas_cursor->property_text() = txt.c_str();
3423 /* don't get too close to the edge */
3424 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3425 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3429 Editor::set_verbose_canvas_cursor_text (const string & txt)
3431 verbose_canvas_cursor->property_text() = txt.c_str();
3435 Editor::set_edit_mode (EditMode m)
3437 Config->set_edit_mode (m);
3441 Editor::cycle_edit_mode ()
3443 switch (Config->get_edit_mode()) {
3445 if (Profile->get_sae()) {
3446 Config->set_edit_mode (Lock);
3448 Config->set_edit_mode (Splice);
3452 Config->set_edit_mode (Lock);
3455 Config->set_edit_mode (Slide);
3461 Editor::edit_mode_selection_done ()
3463 if (_session == 0) {
3467 string choice = edit_mode_selector.get_active_text();
3468 EditMode mode = Slide;
3470 if (choice == _("Splice Edit")) {
3472 } else if (choice == _("Slide Edit")) {
3474 } else if (choice == _("Lock Edit")) {
3478 Config->set_edit_mode (mode);
3482 Editor::snap_type_selection_done ()
3484 string choice = snap_type_selector.get_active_text();
3485 SnapType snaptype = SnapToBeat;
3487 if (choice == _("Beats/2")) {
3488 snaptype = SnapToBeatDiv2;
3489 } else if (choice == _("Beats/3")) {
3490 snaptype = SnapToBeatDiv3;
3491 } else if (choice == _("Beats/4")) {
3492 snaptype = SnapToBeatDiv4;
3493 } else if (choice == _("Beats/5")) {
3494 snaptype = SnapToBeatDiv5;
3495 } else if (choice == _("Beats/6")) {
3496 snaptype = SnapToBeatDiv6;
3497 } else if (choice == _("Beats/7")) {
3498 snaptype = SnapToBeatDiv7;
3499 } else if (choice == _("Beats/8")) {
3500 snaptype = SnapToBeatDiv8;
3501 } else if (choice == _("Beats/10")) {
3502 snaptype = SnapToBeatDiv10;
3503 } else if (choice == _("Beats/12")) {
3504 snaptype = SnapToBeatDiv12;
3505 } else if (choice == _("Beats/14")) {
3506 snaptype = SnapToBeatDiv14;
3507 } else if (choice == _("Beats/16")) {
3508 snaptype = SnapToBeatDiv16;
3509 } else if (choice == _("Beats/24")) {
3510 snaptype = SnapToBeatDiv24;
3511 } else if (choice == _("Beats/28")) {
3512 snaptype = SnapToBeatDiv28;
3513 } else if (choice == _("Beats/32")) {
3514 snaptype = SnapToBeatDiv32;
3515 } else if (choice == _("Beats")) {
3516 snaptype = SnapToBeat;
3517 } else if (choice == _("Bars")) {
3518 snaptype = SnapToBar;
3519 } else if (choice == _("Marks")) {
3520 snaptype = SnapToMark;
3521 } else if (choice == _("Region starts")) {
3522 snaptype = SnapToRegionStart;
3523 } else if (choice == _("Region ends")) {
3524 snaptype = SnapToRegionEnd;
3525 } else if (choice == _("Region bounds")) {
3526 snaptype = SnapToRegionBoundary;
3527 } else if (choice == _("Region syncs")) {
3528 snaptype = SnapToRegionSync;
3529 } else if (choice == _("CD Frames")) {
3530 snaptype = SnapToCDFrame;
3531 } else if (choice == _("Timecode Frames")) {
3532 snaptype = SnapToTimecodeFrame;
3533 } else if (choice == _("Timecode Seconds")) {
3534 snaptype = SnapToTimecodeSeconds;
3535 } else if (choice == _("Timecode Minutes")) {
3536 snaptype = SnapToTimecodeMinutes;
3537 } else if (choice == _("Seconds")) {
3538 snaptype = SnapToSeconds;
3539 } else if (choice == _("Minutes")) {
3540 snaptype = SnapToMinutes;
3543 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3545 ract->set_active ();
3550 Editor::snap_mode_selection_done ()
3552 string choice = snap_mode_selector.get_active_text();
3553 SnapMode mode = SnapNormal;
3555 if (choice == _("No Grid")) {
3557 } else if (choice == _("Grid")) {
3559 } else if (choice == _("Magnetic")) {
3560 mode = SnapMagnetic;
3563 RefPtr<RadioAction> ract = snap_mode_action (mode);
3566 ract->set_active (true);
3571 Editor::cycle_edit_point (bool with_marker)
3573 switch (_edit_point) {
3575 set_edit_point_preference (EditAtPlayhead);
3577 case EditAtPlayhead:
3579 set_edit_point_preference (EditAtSelectedMarker);
3581 set_edit_point_preference (EditAtMouse);
3584 case EditAtSelectedMarker:
3585 set_edit_point_preference (EditAtMouse);
3591 Editor::edit_point_selection_done ()
3593 string choice = edit_point_selector.get_active_text();
3594 EditPoint ep = EditAtSelectedMarker;
3596 if (choice == _("Marker")) {
3597 set_edit_point_preference (EditAtSelectedMarker);
3598 } else if (choice == _("Playhead")) {
3599 set_edit_point_preference (EditAtPlayhead);
3601 set_edit_point_preference (EditAtMouse);
3604 RefPtr<RadioAction> ract = edit_point_action (ep);
3607 ract->set_active (true);
3612 Editor::zoom_focus_selection_done ()
3614 string choice = zoom_focus_selector.get_active_text();
3615 ZoomFocus focus_type = ZoomFocusLeft;
3617 if (choice == _("Left")) {
3618 focus_type = ZoomFocusLeft;
3619 } else if (choice == _("Right")) {
3620 focus_type = ZoomFocusRight;
3621 } else if (choice == _("Center")) {
3622 focus_type = ZoomFocusCenter;
3623 } else if (choice == _("Playhead")) {
3624 focus_type = ZoomFocusPlayhead;
3625 } else if (choice == _("Mouse")) {
3626 focus_type = ZoomFocusMouse;
3627 } else if (choice == _("Edit point")) {
3628 focus_type = ZoomFocusEdit;
3631 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3634 ract->set_active ();
3639 Editor::edit_controls_button_release (GdkEventButton* ev)
3641 if (Keyboard::is_context_menu_event (ev)) {
3642 ARDOUR_UI::instance()->add_route (this);
3648 Editor::mouse_select_button_release (GdkEventButton* ev)
3650 /* this handles just right-clicks */
3652 if (ev->button != 3) {
3660 Editor::set_zoom_focus (ZoomFocus f)
3662 string str = zoom_focus_strings[(int)f];
3664 if (str != zoom_focus_selector.get_active_text()) {
3665 zoom_focus_selector.set_active_text (str);
3668 if (zoom_focus != f) {
3671 ZoomFocusChanged (); /* EMIT_SIGNAL */
3678 Editor::ensure_float (Window& win)
3680 win.set_transient_for (*this);
3684 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3686 /* recover or initialize pane positions. do this here rather than earlier because
3687 we don't want the positions to change the child allocations, which they seem to do.
3693 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3705 width = default_width;
3706 height = default_height;
3708 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3710 prop = geometry->property ("x-size");
3712 width = atoi (prop->value());
3714 prop = geometry->property ("y-size");
3716 height = atoi (prop->value());
3720 if (which == static_cast<Paned*> (&edit_pane)) {
3722 if (done & Horizontal) {
3726 if (!geometry || (prop = geometry->property ("edit-horizontal-pane-pos")) == 0) {
3727 /* initial allocation is 90% to canvas, 10% to notebook */
3728 pos = (int) floor (alloc.get_width() * 0.90f);
3729 snprintf (buf, sizeof(buf), "%d", pos);
3731 pos = atoi (prop->value());
3734 if (GTK_WIDGET(edit_pane.gobj())->allocation.width > pos) {
3735 edit_pane.set_position (pos);
3736 pre_maximal_horizontal_pane_position = pos;
3739 done = (Pane) (done | Horizontal);
3741 } else if (which == static_cast<Paned*> (&editor_summary_pane)) {
3743 if (done & Vertical) {
3747 if (!geometry || (prop = geometry->property ("edit-vertical-pane-pos")) == 0) {
3748 /* initial allocation is 90% to canvas, 10% to summary */
3749 pos = (int) floor (alloc.get_height() * 0.90f);
3750 snprintf (buf, sizeof(buf), "%d", pos);
3752 pos = atoi (prop->value());
3755 if (GTK_WIDGET(editor_summary_pane.gobj())->allocation.height > pos) {
3756 editor_summary_pane.set_position (pos);
3757 pre_maximal_vertical_pane_position = pos;
3760 done = (Pane) (done | Vertical);
3765 Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
3767 if (_tools_tearoff->torn_off() && _mouse_mode_tearoff->torn_off()) {
3768 top_hbox.remove (toolbar_frame);
3773 Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
3775 if (toolbar_frame.get_parent() == 0) {
3776 top_hbox.pack_end (toolbar_frame);
3781 Editor::set_show_measures (bool yn)
3783 if (_show_measures != yn) {
3786 if ((_show_measures = yn) == true) {
3788 tempo_lines->show();
3796 Editor::toggle_follow_playhead ()
3798 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3800 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3801 set_follow_playhead (tact->get_active());
3806 Editor::set_follow_playhead (bool yn)
3808 if (_follow_playhead != yn) {
3809 if ((_follow_playhead = yn) == true) {
3811 reset_x_origin_to_follow_playhead ();
3818 Editor::toggle_stationary_playhead ()
3820 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
3822 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3823 set_stationary_playhead (tact->get_active());
3828 Editor::set_stationary_playhead (bool yn)
3830 if (_stationary_playhead != yn) {
3831 if ((_stationary_playhead = yn) == true) {
3833 // FIXME need a 3.0 equivalent of this 2.X call
3834 // update_current_screen ();
3841 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3843 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3845 xfade->set_active (!xfade->active());
3850 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3852 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3854 xfade->set_follow_overlap (!xfade->following_overlap());
3859 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3861 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3867 CrossfadeEditor cew (_session, xfade, xfade->fade_in().get_min_y(), 1.0);
3871 switch (cew.run ()) {
3872 case RESPONSE_ACCEPT:
3879 PropertyChange all_crossfade_properties;
3880 all_crossfade_properties.add (ARDOUR::Properties::active);
3881 all_crossfade_properties.add (ARDOUR::Properties::follow_overlap);
3882 xfade->PropertyChanged (all_crossfade_properties);
3886 Editor::playlist_selector () const
3888 return *_playlist_selector;
3892 Editor::get_grid_type_as_beats (bool& success, nframes64_t position)
3896 switch (_snap_type) {
3901 case SnapToBeatDiv32:
3904 case SnapToBeatDiv28:
3907 case SnapToBeatDiv24:
3910 case SnapToBeatDiv16:
3913 case SnapToBeatDiv14:
3916 case SnapToBeatDiv12:
3919 case SnapToBeatDiv10:
3922 case SnapToBeatDiv8:
3925 case SnapToBeatDiv7:
3928 case SnapToBeatDiv6:
3931 case SnapToBeatDiv5:
3934 case SnapToBeatDiv4:
3937 case SnapToBeatDiv3:
3940 case SnapToBeatDiv2:
3946 return _session->tempo_map().meter_at (position).beats_per_bar();
3951 case SnapToTimecodeFrame:
3952 case SnapToTimecodeSeconds:
3953 case SnapToTimecodeMinutes:
3956 case SnapToRegionStart:
3957 case SnapToRegionEnd:
3958 case SnapToRegionSync:
3959 case SnapToRegionBoundary:
3969 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3973 ret = nudge_clock.current_duration (pos);
3974 next = ret + 1; /* XXXX fix me */
3980 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3982 ArdourDialog dialog (_("Playlist Deletion"));
3983 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3984 "If left alone, no audio files used by it will be cleaned.\n"
3985 "If deleted, audio files used by it alone by will cleaned."),
3988 dialog.set_position (WIN_POS_CENTER);
3989 dialog.get_vbox()->pack_start (label);
3993 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3994 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3995 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3997 switch (dialog.run ()) {
3998 case RESPONSE_ACCEPT:
3999 /* delete the playlist */
4003 case RESPONSE_REJECT:
4004 /* keep the playlist */
4016 Editor::audio_region_selection_covers (nframes64_t where)
4018 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
4019 if ((*a)->region()->covers (where)) {
4028 Editor::prepare_for_cleanup ()
4030 cut_buffer->clear_regions ();
4031 cut_buffer->clear_playlists ();
4033 selection->clear_regions ();
4034 selection->clear_playlists ();
4036 _regions->suspend_redisplay ();
4040 Editor::finish_cleanup ()
4042 _regions->resume_redisplay ();
4046 Editor::transport_loop_location()
4049 return _session->locations()->auto_loop_location();
4056 Editor::transport_punch_location()
4059 return _session->locations()->auto_punch_location();
4066 Editor::control_layout_scroll (GdkEventScroll* ev)
4068 if (Keyboard::some_magic_widget_has_focus()) {
4072 switch (ev->direction) {
4074 scroll_tracks_up_line ();
4078 case GDK_SCROLL_DOWN:
4079 scroll_tracks_down_line ();
4083 /* no left/right handling yet */
4091 Editor::session_state_saved (string snap_name)
4093 ENSURE_GUI_THREAD (*this, &Editor::session_state_saved, snap_name);
4096 _snapshots->redisplay ();
4100 Editor::maximise_editing_space ()
4102 _mouse_mode_tearoff->set_visible (false);
4103 _tools_tearoff->set_visible (false);
4105 pre_maximal_horizontal_pane_position = edit_pane.get_position ();
4106 pre_maximal_vertical_pane_position = editor_summary_pane.get_position ();
4107 pre_maximal_editor_width = this->get_width ();
4108 pre_maximal_editor_height = this->get_height ();
4110 if (post_maximal_horizontal_pane_position == 0) {
4111 post_maximal_horizontal_pane_position = edit_pane.get_width();
4114 if (post_maximal_vertical_pane_position == 0) {
4115 post_maximal_vertical_pane_position = editor_summary_pane.get_height();
4120 if (post_maximal_editor_width) {
4121 edit_pane.set_position (post_maximal_horizontal_pane_position -
4122 abs(post_maximal_editor_width - pre_maximal_editor_width));
4124 edit_pane.set_position (post_maximal_horizontal_pane_position);
4127 if (post_maximal_editor_height) {
4128 editor_summary_pane.set_position (post_maximal_vertical_pane_position -
4129 abs(post_maximal_editor_height - pre_maximal_editor_height));
4131 editor_summary_pane.set_position (post_maximal_vertical_pane_position);
4136 Editor::restore_editing_space ()
4138 // user changed width/height of panes during fullscreen
4140 if (post_maximal_horizontal_pane_position != edit_pane.get_position()) {
4141 post_maximal_horizontal_pane_position = edit_pane.get_position();
4144 if (post_maximal_vertical_pane_position != editor_summary_pane.get_position()) {
4145 post_maximal_vertical_pane_position = editor_summary_pane.get_position();
4150 _mouse_mode_tearoff->set_visible (true);
4151 _tools_tearoff->set_visible (true);
4152 post_maximal_editor_width = this->get_width();
4153 post_maximal_editor_height = this->get_height();
4155 edit_pane.set_position (pre_maximal_horizontal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4156 editor_summary_pane.set_position (pre_maximal_vertical_pane_position + abs(this->get_height() - pre_maximal_editor_height));
4160 * Make new playlists for a given track and also any others that belong
4161 * to the same active route group with the `edit' property.
4166 Editor::new_playlists (TimeAxisView* v)
4168 begin_reversible_command (_("new playlists"));
4169 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4170 _session->playlists->get (playlists);
4171 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4172 commit_reversible_command ();
4176 * Use a copy of the current playlist for a given track and also any others that belong
4177 * to the same active route group with the `edit' property.
4182 Editor::copy_playlists (TimeAxisView* v)
4184 begin_reversible_command (_("copy playlists"));
4185 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4186 _session->playlists->get (playlists);
4187 mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, ARDOUR::Properties::edit.property_id);
4188 commit_reversible_command ();
4191 /** Clear the current playlist for a given track and also any others that belong
4192 * to the same active route group with the `edit' property.
4197 Editor::clear_playlists (TimeAxisView* v)
4199 begin_reversible_command (_("clear playlists"));
4200 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4201 _session->playlists->get (playlists);
4202 mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, ARDOUR::Properties::edit.property_id);
4203 commit_reversible_command ();
4207 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4209 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4213 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4215 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4219 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
4221 atv.clear_playlist ();
4225 Editor::on_key_press_event (GdkEventKey* ev)
4227 return key_press_focus_accelerator_handler (*this, ev);
4231 Editor::on_key_release_event (GdkEventKey* ev)
4233 return Gtk::Window::on_key_release_event (ev);
4234 // return key_press_focus_accelerator_handler (*this, ev);
4237 /** Queue up a change to the viewport x origin.
4238 * @param frame New x origin.
4241 Editor::reset_x_origin (nframes64_t frame)
4243 queue_visual_change (frame);
4247 Editor::reset_y_origin (double y)
4249 queue_visual_change_y (y);
4253 Editor::reset_zoom (double fpu)
4255 queue_visual_change (fpu);
4259 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4261 reset_x_origin (frame);
4264 if (!no_save_visual) {
4265 undo_visual_stack.push_back (current_visual_state(false));
4269 Editor::VisualState*
4270 Editor::current_visual_state (bool with_tracks)
4272 VisualState* vs = new VisualState;
4273 vs->y_position = vertical_adjustment.get_value();
4274 vs->frames_per_unit = frames_per_unit;
4275 vs->leftmost_frame = leftmost_frame;
4276 vs->zoom_focus = zoom_focus;
4279 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4280 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4288 Editor::undo_visual_state ()
4290 if (undo_visual_stack.empty()) {
4294 redo_visual_stack.push_back (current_visual_state());
4296 VisualState* vs = undo_visual_stack.back();
4297 undo_visual_stack.pop_back();
4298 use_visual_state (*vs);
4302 Editor::redo_visual_state ()
4304 if (redo_visual_stack.empty()) {
4308 undo_visual_stack.push_back (current_visual_state());
4310 VisualState* vs = redo_visual_stack.back();
4311 redo_visual_stack.pop_back();
4312 use_visual_state (*vs);
4316 Editor::swap_visual_state ()
4318 if (undo_visual_stack.empty()) {
4319 redo_visual_state ();
4321 undo_visual_state ();
4326 Editor::use_visual_state (VisualState& vs)
4328 no_save_visual = true;
4330 _routes->suspend_redisplay ();
4332 vertical_adjustment.set_value (vs.y_position);
4334 set_zoom_focus (vs.zoom_focus);
4335 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4337 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4338 TrackViewList::iterator t;
4340 /* check if the track still exists - it could have been deleted */
4342 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4343 (*t)->set_state (*(i->second), Stateful::loading_state_version);
4348 if (!vs.track_states.empty()) {
4349 _routes->update_visibility ();
4352 _routes->resume_redisplay ();
4354 no_save_visual = false;
4358 Editor::set_frames_per_unit (double fpu)
4360 /* this is the core function that controls the zoom level of the canvas. it is called
4361 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4364 if (fpu == frames_per_unit) {
4373 /* don't allow zooms that fit more than the maximum number
4374 of frames into an 800 pixel wide space.
4377 if (max_frames / fpu < 800.0) {
4382 tempo_lines->tempo_map_changed();
4384 frames_per_unit = fpu;
4389 Editor::post_zoom ()
4391 // convert fpu to frame count
4393 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4395 if (frames_per_unit != zoom_range_clock.current_duration()) {
4396 zoom_range_clock.set (frames);
4399 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4400 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4401 (*i)->reshow_selection (selection->time);
4405 ZoomChanged (); /* EMIT_SIGNAL */
4407 //reset_scrolling_region ();
4409 if (playhead_cursor) {
4410 playhead_cursor->set_position (playhead_cursor->current_frame);
4413 refresh_location_display();
4414 _summary->set_overlays_dirty ();
4420 Editor::queue_visual_change (nframes64_t where)
4422 pending_visual_change.add (VisualChange::TimeOrigin);
4423 pending_visual_change.time_origin = where;
4424 ensure_visual_change_idle_handler ();
4428 Editor::queue_visual_change (double fpu)
4430 pending_visual_change.add (VisualChange::ZoomLevel);
4431 pending_visual_change.frames_per_unit = fpu;
4433 ensure_visual_change_idle_handler ();
4437 Editor::queue_visual_change_y (double y)
4439 pending_visual_change.add (VisualChange::YOrigin);
4440 pending_visual_change.y_origin = y;
4442 ensure_visual_change_idle_handler ();
4446 Editor::ensure_visual_change_idle_handler ()
4448 if (pending_visual_change.idle_handler_id < 0) {
4449 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4454 Editor::_idle_visual_changer (void* arg)
4456 return static_cast<Editor*>(arg)->idle_visual_changer ();
4460 Editor::idle_visual_changer ()
4462 VisualChange::Type p = pending_visual_change.pending;
4463 pending_visual_change.pending = (VisualChange::Type) 0;
4465 double last_time_origin = horizontal_position ();
4467 if (p & VisualChange::ZoomLevel) {
4468 set_frames_per_unit (pending_visual_change.frames_per_unit);
4470 compute_fixed_ruler_scale ();
4471 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4472 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4473 update_tempo_based_rulers ();
4475 if (p & VisualChange::TimeOrigin) {
4476 set_horizontal_position (pending_visual_change.time_origin / frames_per_unit);
4478 if (p & VisualChange::YOrigin) {
4479 vertical_adjustment.set_value (pending_visual_change.y_origin);
4482 if (last_time_origin == horizontal_position ()) {
4483 /* changed signal not emitted */
4484 update_fixed_rulers ();
4485 redisplay_tempo (true);
4488 _summary->set_overlays_dirty ();
4490 pending_visual_change.idle_handler_id = -1;
4491 return 0; /* this is always a one-shot call */
4494 struct EditorOrderTimeAxisSorter {
4495 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4496 return a->order () < b->order ();
4501 Editor::sort_track_selection (TrackViewList* sel)
4503 EditorOrderTimeAxisSorter cmp;
4508 selection->tracks.sort (cmp);
4513 Editor::get_preferred_edit_position (bool ignore_playhead)
4516 nframes64_t where = 0;
4517 EditPoint ep = _edit_point;
4519 if (entered_marker) {
4520 return entered_marker->position();
4523 if (ignore_playhead && ep == EditAtPlayhead) {
4524 ep = EditAtSelectedMarker;
4528 case EditAtPlayhead:
4529 where = _session->audible_frame();
4532 case EditAtSelectedMarker:
4533 if (!selection->markers.empty()) {
4535 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4538 where = loc->start();
4549 if (!mouse_frame (where, ignored)) {
4550 /* XXX not right but what can we do ? */
4561 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4563 if (!_session) return;
4565 begin_reversible_command (cmd);
4569 if ((tll = transport_loop_location()) == 0) {
4570 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4571 XMLNode &before = _session->locations()->get_state();
4572 _session->locations()->add (loc, true);
4573 _session->set_auto_loop_location (loc);
4574 XMLNode &after = _session->locations()->get_state();
4575 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4577 XMLNode &before = tll->get_state();
4578 tll->set_hidden (false, this);
4579 tll->set (start, end);
4580 XMLNode &after = tll->get_state();
4581 _session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4584 commit_reversible_command ();
4588 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4590 if (!_session) return;
4592 begin_reversible_command (cmd);
4596 if ((tpl = transport_punch_location()) == 0) {
4597 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4598 XMLNode &before = _session->locations()->get_state();
4599 _session->locations()->add (loc, true);
4600 _session->set_auto_loop_location (loc);
4601 XMLNode &after = _session->locations()->get_state();
4602 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
4605 XMLNode &before = tpl->get_state();
4606 tpl->set_hidden (false, this);
4607 tpl->set (start, end);
4608 XMLNode &after = tpl->get_state();
4609 _session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4612 commit_reversible_command ();
4615 /** Find regions which exist at a given time, and optionally on a given list of tracks.
4616 * @param rs List to which found regions are added.
4617 * @param where Time to look at.
4618 * @param ts Tracks to look on; if this is empty, all tracks are examined.
4621 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4623 const TrackViewList* tracks;
4626 tracks = &track_views;
4631 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4632 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4634 boost::shared_ptr<Track> tr;
4635 boost::shared_ptr<Playlist> pl;
4637 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4639 Playlist::RegionList* regions = pl->regions_at (
4640 (nframes64_t) floor ( (double)where * tr->speed()));
4642 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4643 RegionView* rv = rtv->view()->find_view (*i);
4656 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackViewList& ts) const
4658 const TrackViewList* tracks;
4661 tracks = &track_views;
4666 for (TrackViewList::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4667 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4669 boost::shared_ptr<Track> tr;
4670 boost::shared_ptr<Playlist> pl;
4672 if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
4674 Playlist::RegionList* regions = pl->regions_touched (
4675 (nframes64_t) floor ( (double)where * tr->speed()), max_frames);
4677 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4679 RegionView* rv = rtv->view()->find_view (*i);
4692 /** Find all regions which are either:
4694 * - the entered_regionview (if allow_entered == true) or
4695 * - under the preferred edit position AND on a selected track, or on a track
4696 * which is in the same active edit-enable route group as a selected region (if allow_edit_position == true)
4697 * @param rs Returned region list.
4698 * @param allow_entered true to include the entered_regionview in the list.
4701 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered, bool allow_edit_position)
4703 /* Start with selected regions */
4704 rs = selection->regions;
4706 /* Add the entered_regionview, if requested */
4707 if (allow_entered && entered_regionview) {
4708 rs.add (entered_regionview);
4711 if (allow_edit_position) {
4713 TrackViewList tracks = selection->tracks;
4715 /* tracks is currently the set of selected tracks; add any other tracks that
4716 * have regions that are in the same edit-activated route group as one of
4718 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4720 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4721 if (g && g->is_active() && g->is_edit()) {
4722 tracks.add (axis_views_from_routes (g->route_list()));
4727 if (!tracks.empty()) {
4728 /* now find regions that are at the edit position on those tracks */
4729 nframes64_t const where = get_preferred_edit_position ();
4730 get_regions_at (rs, where, tracks);
4736 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4738 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4740 RouteTimeAxisView* tatv;
4742 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4744 boost::shared_ptr<Playlist> pl;
4745 vector<boost::shared_ptr<Region> > results;
4747 boost::shared_ptr<Track> tr;
4749 if ((tr = tatv->track()) == 0) {
4754 if ((pl = (tr->playlist())) != 0) {
4755 pl->get_region_list_equivalent_regions (region, results);
4758 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4759 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4760 regions.push_back (marv);
4769 Editor::show_rhythm_ferret ()
4771 if (rhythm_ferret == 0) {
4772 rhythm_ferret = new RhythmFerret(*this);
4775 rhythm_ferret->set_session (_session);
4776 rhythm_ferret->show ();
4777 rhythm_ferret->present ();
4781 Editor::show_global_port_matrix (ARDOUR::DataType t)
4783 if (_global_port_matrix[t] == 0) {
4784 _global_port_matrix[t] = new GlobalPortMatrixWindow (_session, t);
4787 _global_port_matrix[t]->show ();
4791 Editor::first_idle ()
4793 MessageDialog* dialog = 0;
4795 if (track_views.size() > 1) {
4796 dialog = new MessageDialog (*this,
4797 string_compose (_("Please wait while %1 loads visual data"), PROGRAM_NAME),
4802 ARDOUR_UI::instance()->flush_pending ();
4805 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4809 // first idle adds route children (automation tracks), so we need to redisplay here
4810 _routes->redisplay ();
4818 Editor::_idle_resize (gpointer arg)
4820 return ((Editor*)arg)->idle_resize ();
4824 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4826 if (resize_idle_id < 0) {
4827 resize_idle_id = g_idle_add (_idle_resize, this);
4828 _pending_resize_amount = 0;
4831 /* make a note of the smallest resulting height, so that we can clamp the
4832 lower limit at TimeAxisView::hSmall */
4834 int32_t min_resulting = INT32_MAX;
4836 _pending_resize_amount += h;
4837 _pending_resize_view = view;
4839 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4841 if (selection->tracks.contains (_pending_resize_view)) {
4842 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4843 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4847 if (min_resulting < 0) {
4852 if (uint32_t (min_resulting) < TimeAxisView::preset_height (HeightSmall)) {
4853 _pending_resize_amount += TimeAxisView::preset_height (HeightSmall) - min_resulting;
4857 /** Handle pending resizing of tracks */
4859 Editor::idle_resize ()
4861 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4863 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4864 selection->tracks.contains (_pending_resize_view)) {
4866 for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4867 if (*i != _pending_resize_view) {
4868 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4873 _pending_resize_amount = 0;
4875 _group_tabs->set_dirty ();
4876 resize_idle_id = -1;
4884 ENSURE_GUI_THREAD (*this, &Editor::located);
4886 playhead_cursor->set_position (_session->audible_frame ());
4887 if (_follow_playhead && !_pending_initial_locate) {
4888 reset_x_origin_to_follow_playhead ();
4891 _pending_locate_request = false;
4892 _pending_initial_locate = false;
4896 Editor::region_view_added (RegionView *)
4898 _summary->set_dirty ();
4902 Editor::streamview_height_changed ()
4904 _summary->set_dirty ();
4908 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
4910 TrackViewList::const_iterator j = track_views.begin ();
4911 while (j != track_views.end()) {
4912 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4913 if (rtv && rtv->route() == r) {
4924 Editor::axis_views_from_routes (boost::shared_ptr<RouteList> r) const
4928 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
4929 TimeAxisView* tv = axis_view_from_route (*i);
4940 Editor::handle_new_route (RouteList& routes)
4942 ENSURE_GUI_THREAD (*this, &Editor::handle_new_route, routes)
4944 RouteTimeAxisView *rtv;
4945 list<RouteTimeAxisView*> new_views;
4947 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4948 boost::shared_ptr<Route> route = (*x);
4950 if (route->is_hidden() || route->is_monitor()) {
4954 DataType dt = route->input()->default_type();
4956 if (dt == ARDOUR::DataType::AUDIO) {
4957 rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
4958 } else if (dt == ARDOUR::DataType::MIDI) {
4959 rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
4961 throw unknown_type();
4964 new_views.push_back (rtv);
4965 track_views.push_back (rtv);
4967 rtv->effective_gain_display ();
4969 rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
4970 rtv->view()->HeightChanged.connect (sigc::mem_fun (*this, &Editor::streamview_height_changed));
4973 _routes->routes_added (new_views);
4975 if (show_editor_mixer_when_tracks_arrive) {
4976 show_editor_mixer (true);
4979 editor_list_button.set_sensitive (true);
4981 _summary->set_dirty ();
4985 Editor::timeaxisview_deleted (TimeAxisView *tv)
4987 if (_session && _session->deletion_in_progress()) {
4988 /* the situation is under control */
4992 ENSURE_GUI_THREAD (*this, &Editor::timeaxisview_deleted, tv);
4995 _routes->route_removed (tv);
4997 if (tv == entered_track) {
5001 /* remove it from the list of track views */
5003 TrackViewList::iterator i;
5005 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
5006 i = track_views.erase (i);
5009 /* update whatever the current mixer strip is displaying, if revelant */
5011 boost::shared_ptr<Route> route;
5012 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv);
5015 route = rtav->route ();
5018 if (current_mixer_strip && current_mixer_strip->route() == route) {
5020 TimeAxisView* next_tv;
5022 if (track_views.empty()) {
5024 } else if (i == track_views.end()) {
5025 next_tv = track_views.front();
5032 set_selected_mixer_strip (*next_tv);
5034 /* make the editor mixer strip go away setting the
5035 * button to inactive (which also unticks the menu option)
5038 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
5044 Editor::hide_track_in_display (TimeAxisView* tv, bool /*temponly*/)
5046 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
5048 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
5049 // this will hide the mixer strip
5050 set_selected_mixer_strip (*tv);
5053 _routes->hide_track_in_display (*tv);
5057 Editor::sync_track_view_list_and_routes ()
5059 track_views = TrackViewList (_routes->views ());
5061 _summary->set_dirty ();
5062 _group_tabs->set_dirty ();
5064 return false; // do not call again (until needed)
5068 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
5070 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5076 Editor::get_route_view_by_id (PBD::ID& id)
5078 RouteTimeAxisView* v;
5080 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5081 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5082 if(v->route()->id() == id) {
5092 Editor::fit_route_group (RouteGroup *g)
5094 TrackViewList ts = axis_views_from_routes (g->route_list ());
5099 Editor::consider_auditioning (boost::shared_ptr<Region> region)
5101 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
5104 _session->cancel_audition ();
5108 if (_session->is_auditioning()) {
5109 _session->cancel_audition ();
5110 if (r == last_audition_region) {
5115 _session->audition_region (r);
5116 last_audition_region = r;
5121 Editor::hide_a_region (boost::shared_ptr<Region> r)
5123 r->set_hidden (true);
5127 Editor::show_a_region (boost::shared_ptr<Region> r)
5129 r->set_hidden (false);
5133 Editor::audition_region_from_region_list ()
5135 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::consider_auditioning));
5139 Editor::hide_region_from_region_list ()
5141 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::hide_a_region));
5145 Editor::show_region_in_region_list ()
5147 _regions->selection_mapover (sigc::mem_fun (*this, &Editor::show_a_region));
5151 Editor::start_step_editing ()
5153 step_edit_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::check_step_edit), 20);
5157 Editor::stop_step_editing ()
5159 step_edit_connection.disconnect ();
5163 Editor::check_step_edit ()
5165 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5166 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (*i);
5168 mtv->check_step_edit ();
5172 return true; // do it again, till we stop
5176 Editor::horizontal_scroll_left_press ()
5178 ++_scroll_callbacks;
5180 if (_scroll_connection.connected() && _scroll_callbacks < 5) {
5181 /* delay the first auto-repeat */
5185 double x = leftmost_position() - current_page_frames() / 5;
5192 /* do hacky auto-repeat */
5193 if (!_scroll_connection.connected ()) {
5194 _scroll_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_press), 100);
5195 _scroll_callbacks = 0;
5202 Editor::horizontal_scroll_left_release ()
5204 _scroll_connection.disconnect ();
5208 Editor::horizontal_scroll_right_press ()
5210 ++_scroll_callbacks;
5212 if (_scroll_connection.connected() && _scroll_callbacks < 5) {
5213 /* delay the first auto-repeat */
5217 reset_x_origin (leftmost_position() + current_page_frames() / 5);
5219 /* do hacky auto-repeat */
5220 if (!_scroll_connection.connected ()) {
5221 _scroll_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_press), 100);
5222 _scroll_callbacks = 0;
5229 Editor::horizontal_scroll_right_release ()
5231 _scroll_connection.disconnect ();
5234 /** Queue a change for the Editor viewport x origin to follow the playhead */
5236 Editor::reset_x_origin_to_follow_playhead ()
5238 nframes64_t const frame = playhead_cursor->current_frame;
5240 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
5242 if (_session->transport_speed() < 0) {
5244 if (frame > (current_page_frames() / 2)) {
5245 center_screen (frame-(current_page_frames()/2));
5247 center_screen (current_page_frames()/2);
5252 if (frame < leftmost_frame) {
5255 if (_session->transport_rolling()) {
5256 /* rolling; end up with the playhead at the right of the page */
5257 l = frame - current_page_frames ();
5259 /* not rolling: end up with the playhead 3/4 of the way along the page */
5260 l = frame - (3 * current_page_frames() / 4);
5267 center_screen_internal (l + (current_page_frames() / 2), current_page_frames ());
5270 if (_session->transport_rolling()) {
5271 /* rolling: end up with the playhead on the left of the page */
5272 center_screen_internal (frame + (current_page_frames() / 2), current_page_frames ());
5274 /* not rolling: end up with the playhead 1/4 of the way along the page */
5275 center_screen_internal (frame + (current_page_frames() / 4), current_page_frames ());
5283 Editor::super_rapid_screen_update ()
5285 if (!_session || !_session->engine().running()) {
5289 /* METERING / MIXER STRIPS */
5291 /* update track meters, if required */
5292 if (is_mapped() && meters_running) {
5293 RouteTimeAxisView* rtv;
5294 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5295 if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5296 rtv->fast_update ();
5301 /* and any current mixer strip */
5302 if (current_mixer_strip) {
5303 current_mixer_strip->fast_update ();
5306 /* PLAYHEAD AND VIEWPORT */
5308 nframes64_t const frame = _session->audible_frame();
5310 /* There are a few reasons why we might not update the playhead / viewport stuff:
5312 * 1. we don't update things when there's a pending locate request, otherwise
5313 * when the editor requests a locate there is a chance that this method
5314 * will move the playhead before the locate request is processed, causing
5316 * 2. if we're not rolling, there's nothing to do here (locates are handled elsewhere).
5317 * 3. if we're still at the same frame that we were last time, there's nothing to do.
5320 if (!_pending_locate_request && _session->transport_speed() != 0 && frame != last_update_frame) {
5322 last_update_frame = frame;
5324 if (!_dragging_playhead) {
5325 playhead_cursor->set_position (frame);
5328 if (!_stationary_playhead) {
5330 if (!_dragging_playhead && _follow_playhead && _session->requested_return_frame() < 0) {
5331 reset_x_origin_to_follow_playhead ();
5336 /* don't do continuous scroll till the new position is in the rightmost quarter of the
5340 // FIXME DO SOMETHING THAT WORKS HERE - this is 2.X code
5341 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
5342 if (target <= 0.0) {
5345 if (fabs(target - current) < current_page_frames() / frames_per_unit) {
5346 target = (target * 0.15) + (current * 0.85);
5352 set_horizontal_position (current);
5361 Editor::session_going_away ()
5363 _have_idled = false;
5365 _session_connections.drop_connections ();
5367 super_rapid_screen_update_connection.disconnect ();
5369 selection->clear ();
5370 cut_buffer->clear ();
5372 clicked_regionview = 0;
5373 clicked_axisview = 0;
5374 clicked_routeview = 0;
5375 clicked_crossfadeview = 0;
5376 entered_regionview = 0;
5378 last_update_frame = 0;
5381 playhead_cursor->canvas_item.hide ();
5383 /* rip everything out of the list displays */
5387 _route_groups->clear ();
5389 /* do this first so that deleting a track doesn't reset cms to null
5390 and thus cause a leak.
5393 if (current_mixer_strip) {
5394 if (current_mixer_strip->get_parent() != 0) {
5395 global_hpacker.remove (*current_mixer_strip);
5397 delete current_mixer_strip;
5398 current_mixer_strip = 0;
5401 /* delete all trackviews */
5403 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5406 track_views.clear ();
5408 zoom_range_clock.set_session (0);
5409 nudge_clock.set_session (0);
5411 editor_list_button.set_active(false);
5412 editor_list_button.set_sensitive(false);
5414 /* clear tempo/meter rulers */
5415 remove_metric_marks ();
5417 clear_marker_display ();
5419 delete current_bbt_points;
5420 current_bbt_points = 0;
5422 /* get rid of any existing editor mixer strip */
5424 WindowTitle title(Glib::get_application_name());
5425 title += _("Editor");
5427 set_title (title.get_string());
5429 SessionHandlePtr::session_going_away ();
5434 Editor::show_editor_list (bool yn)
5437 the_notebook.show();
5439 the_notebook.hide();