2 Copyright (C) 2000-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* Note: public Editor methods are documented in public_editor.h */
22 #define __STDC_LIMIT_MACROS 1
31 #include <boost/none.hpp>
33 #include <sigc++/bind.h>
35 #include "pbd/convert.h"
36 #include "pbd/error.h"
37 #include "pbd/enumwriter.h"
38 #include "pbd/memento_command.h"
39 #include "pbd/unknown_type.h"
41 #include <glibmm/miscutils.h>
42 #include <gtkmm/image.h>
43 #include <gdkmm/color.h>
44 #include <gdkmm/bitmap.h>
46 #include <gtkmm2ext/grouped_buttons.h>
47 #include <gtkmm2ext/gtk_ui.h>
48 #include <gtkmm2ext/tearoff.h>
49 #include <gtkmm2ext/utils.h>
50 #include <gtkmm2ext/window_title.h>
51 #include <gtkmm2ext/choice.h>
52 #include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
54 #include "ardour/audio_diskstream.h"
55 #include "ardour/audio_track.h"
56 #include "ardour/audioplaylist.h"
57 #include "ardour/audioregion.h"
58 #include "ardour/location.h"
59 #include "ardour/midi_region.h"
60 #include "ardour/plugin_manager.h"
61 #include "ardour/profile.h"
62 #include "ardour/route_group.h"
63 #include "ardour/session_directory.h"
64 #include "ardour/session_route.h"
65 #include "ardour/session_state_utils.h"
66 #include "ardour/tempo.h"
67 #include "ardour/utils.h"
69 #include "control_protocol/control_protocol.h"
71 #include "ardour_ui.h"
75 #include "playlist_selector.h"
76 #include "audio_region_view.h"
77 #include "rgb_macros.h"
78 #include "selection.h"
79 #include "audio_streamview.h"
80 #include "time_axis_view.h"
81 #include "audio_time_axis.h"
83 #include "crossfade_view.h"
85 #include "public_editor.h"
86 #include "crossfade_edit.h"
87 #include "canvas_impl.h"
90 #include "gui_thread.h"
91 #include "simpleline.h"
92 #include "rhythm_ferret.h"
94 #include "tempo_lines.h"
95 #include "analysis_window.h"
96 #include "bundle_manager.h"
97 #include "global_port_matrix.h"
98 #include "editor_drag.h"
99 #include "editor_group_tabs.h"
100 #include "automation_time_axis.h"
101 #include "editor_routes.h"
102 #include "midi_time_axis.h"
103 #include "mixer_strip.h"
104 #include "editor_route_groups.h"
105 #include "editor_regions.h"
106 #include "editor_snapshots.h"
111 #include "imageframe_socket_handler.h"
115 using namespace sigc;
116 using namespace ARDOUR;
119 using namespace Glib;
120 using namespace Gtkmm2ext;
121 using namespace Editing;
123 using PBD::internationalize;
126 const double Editor::timebar_height = 15.0;
128 #include "editor_xpms"
130 static const gchar *_snap_type_strings[] = {
152 static const gchar *_snap_mode_strings[] = {
159 static const gchar *_edit_point_strings[] = {
166 static const gchar *_zoom_focus_strings[] = {
176 #ifdef USE_RUBBERBAND
177 static const gchar *_rb_opt_strings[] = {
180 N_("Balanced multitimbral mixture"),
181 N_("Unpitched percussion with stable notes"),
182 N_("Crisp monophonic instrumental"),
183 N_("Unpitched solo percussion"),
188 /* Soundfile drag-n-drop */
190 Gdk::Cursor* Editor::cross_hair_cursor = 0;
191 Gdk::Cursor* Editor::selector_cursor = 0;
192 Gdk::Cursor* Editor::trimmer_cursor = 0;
193 Gdk::Cursor* Editor::grabber_cursor = 0;
194 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
195 Gdk::Cursor* Editor::zoom_cursor = 0;
196 Gdk::Cursor* Editor::time_fx_cursor = 0;
197 Gdk::Cursor* Editor::fader_cursor = 0;
198 Gdk::Cursor* Editor::speaker_cursor = 0;
199 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
200 Gdk::Cursor* Editor::midi_select_cursor = 0;
201 Gdk::Cursor* Editor::midi_resize_cursor = 0;
202 Gdk::Cursor* Editor::midi_erase_cursor = 0;
203 Gdk::Cursor* Editor::wait_cursor = 0;
204 Gdk::Cursor* Editor::timebar_cursor = 0;
205 Gdk::Cursor* Editor::transparent_cursor = 0;
208 show_me_the_size (Requisition* r, const char* what)
210 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
215 /* time display buttons */
217 minsec_label (_("Mins:Secs")),
218 bbt_label (_("Bars:Beats")),
219 smpte_label (_("Timecode")),
220 frame_label (_("Samples")),
221 tempo_label (_("Tempo")),
222 meter_label (_("Meter")),
223 mark_label (_("Location Markers")),
224 range_mark_label (_("Range Markers")),
225 transport_mark_label (_("Loop/Punch Ranges")),
226 cd_mark_label (_("CD Markers")),
227 edit_packer (4, 4, true),
229 /* the values here don't matter: layout widgets
230 reset them as needed.
233 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
234 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
236 /* tool bar related */
238 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
239 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
241 toolbar_selection_clock_table (2,3),
243 automation_mode_button (_("mode")),
244 global_automation_button (_("automation")),
246 midi_panic_button (_("Panic")),
247 midi_tools_tearoff (0),
250 image_socket_listener(0),
255 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
256 meters_running(false),
257 _pending_locate_request (false)
262 /* we are a singleton */
264 PublicEditor::_instance = this;
269 selection = new Selection (this);
270 cut_buffer = new Selection (this);
272 clicked_regionview = 0;
273 clicked_axisview = 0;
274 clicked_routeview = 0;
275 clicked_crossfadeview = 0;
276 clicked_control_point = 0;
277 last_update_frame = 0;
279 current_mixer_strip = 0;
280 current_bbt_points = 0;
283 snap_type_strings = I18N (_snap_type_strings);
284 snap_mode_strings = I18N (_snap_mode_strings);
285 zoom_focus_strings = I18N (_zoom_focus_strings);
286 edit_point_strings = I18N (_edit_point_strings);
287 #ifdef USE_RUBBERBAND
288 rb_opt_strings = I18N (_rb_opt_strings);
291 snap_threshold = 5.0;
292 bbt_beat_subdivision = 4;
295 last_autoscroll_x = 0;
296 last_autoscroll_y = 0;
297 autoscroll_active = false;
298 autoscroll_timeout_tag = -1;
299 interthread_progress_window = 0;
304 current_interthread_info = 0;
305 _show_measures = true;
306 _show_waveforms_recording = true;
307 show_gain_after_trim = false;
308 verbose_cursor_on = true;
309 route_removal = false;
310 last_item_entered = 0;
311 last_item_entered_n = 0;
313 have_pending_keyboard_selection = false;
314 _follow_playhead = true;
315 _xfade_visibility = true;
316 editor_ruler_menu = 0;
317 no_ruler_shown_update = false;
319 start_end_marker_menu = 0;
320 range_marker_menu = 0;
321 marker_menu_item = 0;
323 transport_marker_menu = 0;
324 new_transport_marker_menu = 0;
325 editor_mixer_strip_width = Wide;
326 show_editor_mixer_when_tracks_arrive = false;
327 region_edit_menu_split_multichannel_item = 0;
328 region_edit_menu_split_item = 0;
331 ignore_mouse_mode_toggle = false;
332 ignore_midi_edit_mode_toggle = false;
333 current_stepping_trackview = 0;
335 entered_regionview = 0;
337 clear_entered_track = false;
338 _new_regionviews_show_envelope = false;
341 button_release_can_deselect = true;
342 _dragging_playhead = false;
343 _dragging_edit_point = false;
344 _dragging_hscrollbar = false;
345 select_new_marker = false;
346 zoomed_to_region = false;
349 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
350 _global_port_matrix[*i] = 0;
352 allow_vertical_scroll = false;
353 no_save_visual = false;
356 scrubbing_direction = 0;
360 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
361 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
362 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
363 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
364 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
366 set_midi_edit_mode (MidiEditPencil, true);
367 _edit_point = EditAtMouse;
368 set_mouse_mode (MouseObject, true);
370 frames_per_unit = 2048; /* too early to use reset_zoom () */
371 reset_hscrollbar_stepping ();
373 zoom_focus = ZoomFocusLeft;
374 set_zoom_focus (ZoomFocusLeft);
375 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
377 bbt_label.set_name ("EditorTimeButton");
378 bbt_label.set_size_request (-1, (int)timebar_height);
379 bbt_label.set_alignment (1.0, 0.5);
380 bbt_label.set_padding (5,0);
382 bbt_label.set_no_show_all();
383 minsec_label.set_name ("EditorTimeButton");
384 minsec_label.set_size_request (-1, (int)timebar_height);
385 minsec_label.set_alignment (1.0, 0.5);
386 minsec_label.set_padding (5,0);
387 minsec_label.hide ();
388 minsec_label.set_no_show_all();
389 smpte_label.set_name ("EditorTimeButton");
390 smpte_label.set_size_request (-1, (int)timebar_height);
391 smpte_label.set_alignment (1.0, 0.5);
392 smpte_label.set_padding (5,0);
394 smpte_label.set_no_show_all();
395 frame_label.set_name ("EditorTimeButton");
396 frame_label.set_size_request (-1, (int)timebar_height);
397 frame_label.set_alignment (1.0, 0.5);
398 frame_label.set_padding (5,0);
400 frame_label.set_no_show_all();
402 tempo_label.set_name ("EditorTimeButton");
403 tempo_label.set_size_request (-1, (int)timebar_height);
404 tempo_label.set_alignment (1.0, 0.5);
405 tempo_label.set_padding (5,0);
407 tempo_label.set_no_show_all();
408 meter_label.set_name ("EditorTimeButton");
409 meter_label.set_size_request (-1, (int)timebar_height);
410 meter_label.set_alignment (1.0, 0.5);
411 meter_label.set_padding (5,0);
413 meter_label.set_no_show_all();
414 mark_label.set_name ("EditorTimeButton");
415 mark_label.set_size_request (-1, (int)timebar_height);
416 mark_label.set_alignment (1.0, 0.5);
417 mark_label.set_padding (5,0);
419 mark_label.set_no_show_all();
420 cd_mark_label.set_name ("EditorTimeButton");
421 cd_mark_label.set_size_request (-1, (int)timebar_height);
422 cd_mark_label.set_alignment (1.0, 0.5);
423 cd_mark_label.set_padding (5,0);
424 cd_mark_label.hide();
425 cd_mark_label.set_no_show_all();
426 range_mark_label.set_name ("EditorTimeButton");
427 range_mark_label.set_size_request (-1, (int)timebar_height);
428 range_mark_label.set_alignment (1.0, 0.5);
429 range_mark_label.set_padding (5,0);
430 range_mark_label.hide();
431 range_mark_label.set_no_show_all();
432 transport_mark_label.set_name ("EditorTimeButton");
433 transport_mark_label.set_size_request (-1, (int)timebar_height);
434 transport_mark_label.set_alignment (1.0, 0.5);
435 transport_mark_label.set_padding (5,0);
436 transport_mark_label.hide();
437 transport_mark_label.set_no_show_all();
439 initialize_rulers ();
440 _summary = new EditorSummary (this);
441 initialize_canvas ();
443 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
444 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
445 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
446 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
447 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
449 edit_controls_vbox.set_spacing (0);
450 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
451 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
452 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
454 HBox* h = manage (new HBox);
455 _group_tabs = new EditorGroupTabs (this);
456 h->pack_start (*_group_tabs, PACK_SHRINK);
457 h->pack_start (edit_controls_vbox);
458 controls_layout.add (*h);
460 controls_layout.set_name ("EditControlsBase");
461 controls_layout.add_events (Gdk::SCROLL_MASK);
462 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
464 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
465 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
466 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
468 edit_vscrollbar.set_adjustment (vertical_adjustment);
469 edit_hscrollbar.set_adjustment (horizontal_adjustment);
471 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
472 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
473 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
475 edit_hscrollbar.set_name ("EditorHScrollbar");
479 setup_midi_toolbar ();
481 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
483 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
484 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
485 0.0, 1.0, 100.0, 1.0));
486 pad_line_1->property_color_rgba() = 0xFF0000FF;
490 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
491 time_canvas_vbox.set_size_request (-1, -1);
493 ruler_label_event_box.add (ruler_label_vbox);
494 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
495 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
497 time_button_event_box.add (time_button_vbox);
498 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
499 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
501 /* these enable us to have a dedicated window (for cursor setting, etc.)
502 for the canvas areas.
505 track_canvas_event_box.add (*track_canvas);
507 time_canvas_event_box.add (time_canvas_vbox);
508 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
510 edit_packer.set_col_spacings (0);
511 edit_packer.set_row_spacings (0);
512 edit_packer.set_homogeneous (false);
513 edit_packer.set_border_width (0);
514 edit_packer.set_name ("EditorWindow");
516 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
517 /* labels for the rulers */
518 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
519 /* labels for the marker "tracks" */
520 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
522 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
524 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
526 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
528 bottom_hbox.set_border_width (2);
529 bottom_hbox.set_spacing (3);
531 _route_groups = new EditorRouteGroups (this);
532 _routes = new EditorRoutes (this);
533 _regions = new EditorRegions (this);
534 _snapshots = new EditorSnapshots (this);
536 named_selection_scroller.add (named_selection_display);
537 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
539 named_selection_model = TreeStore::create (named_selection_columns);
540 named_selection_display.set_model (named_selection_model);
541 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
542 named_selection_display.set_headers_visible (false);
543 named_selection_display.set_size_request (100, -1);
544 named_selection_display.set_name ("NamedSelectionDisplay");
546 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
547 named_selection_display.set_size_request (100, -1);
548 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
549 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
550 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
554 nlabel = manage (new Label (_("Regions")));
555 nlabel->set_angle (-90);
556 the_notebook.append_page (_regions->widget (), *nlabel);
557 nlabel = manage (new Label (_("Tracks/Busses")));
558 nlabel->set_angle (-90);
559 the_notebook.append_page (_routes->widget (), *nlabel);
560 nlabel = manage (new Label (_("Snapshots")));
561 nlabel->set_angle (-90);
562 the_notebook.append_page (_snapshots->widget (), *nlabel);
563 nlabel = manage (new Label (_("Route Groups")));
564 nlabel->set_angle (-90);
565 the_notebook.append_page (_route_groups->widget (), *nlabel);
567 if (!Profile->get_sae()) {
568 nlabel = manage (new Label (_("Chunks")));
569 nlabel->set_angle (-90);
570 the_notebook.append_page (named_selection_scroller, *nlabel);
573 the_notebook.set_show_tabs (true);
574 the_notebook.set_scrollable (true);
575 the_notebook.popup_enable ();
576 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
577 the_notebook.show_all ();
579 post_maximal_editor_width = 0;
580 post_maximal_pane_position = 0;
582 VPaned *editor_summary_pane = manage(new VPaned());
583 editor_summary_pane->pack1(edit_packer);
584 editor_summary_pane->pack2(*_summary);
586 edit_pane.pack1 (*editor_summary_pane, true, true);
587 edit_pane.pack2 (the_notebook, false, true);
589 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
591 top_hbox.pack_start (toolbar_frame, false, true);
592 top_hbox.pack_start (midi_toolbar_frame, false, true);
594 HBox *hbox = manage (new HBox);
595 hbox->pack_start (edit_pane, true, true);
597 global_vpacker.pack_start (top_hbox, false, false);
598 global_vpacker.pack_start (*hbox, true, true);
600 global_hpacker.pack_start (global_vpacker, true, true);
602 set_name ("EditorWindow");
603 add_accel_group (ActionManager::ui_manager->get_accel_group());
605 status_bar_hpacker.show ();
607 vpacker.pack_end (status_bar_hpacker, false, false);
608 vpacker.pack_end (global_hpacker, true, true);
610 /* register actions now so that set_state() can find them and set toggles/checks etc */
614 snap_type = SnapToBeat;
615 set_snap_to (snap_type);
617 set_snap_mode (snap_mode);
618 set_edit_point_preference (EditAtMouse, true);
620 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
623 _playlist_selector = new PlaylistSelector();
624 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
626 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
630 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
631 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
633 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
634 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
636 nudge_forward_button.set_name ("TransportButton");
637 nudge_backward_button.set_name ("TransportButton");
639 fade_context_menu.set_name ("ArdourContextMenu");
641 /* icons, titles, WM stuff */
643 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
644 Glib::RefPtr<Gdk::Pixbuf> icon;
646 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
647 window_icons.push_back (icon);
649 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
650 window_icons.push_back (icon);
652 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
653 window_icons.push_back (icon);
655 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
656 window_icons.push_back (icon);
658 if (!window_icons.empty()) {
659 set_icon_list (window_icons);
660 set_default_icon_list (window_icons);
663 WindowTitle title(Glib::get_application_name());
664 title += _("Editor");
665 set_title (title.get_string());
666 set_wmclass (X_("ardour_editor"), "Ardour");
669 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
671 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
672 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
674 /* allow external control surfaces/protocols to do various things */
676 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
677 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
678 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
679 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
680 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
682 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
684 _last_normalization_value = 0;
693 if(image_socket_listener) {
694 if(image_socket_listener->is_connected())
696 image_socket_listener->close_connection() ;
699 delete image_socket_listener ;
700 image_socket_listener = 0 ;
705 delete _route_groups;
711 Editor::add_toplevel_controls (Container& cont)
713 vpacker.pack_start (cont, false, false);
718 Editor::catch_vanishing_regionview (RegionView *rv)
720 /* note: the selection will take care of the vanishing
721 audioregionview by itself.
724 if (_drag && rv->get_canvas_group() == _drag->item() && !_drag->ending()) {
730 if (clicked_regionview == rv) {
731 clicked_regionview = 0;
734 if (entered_regionview == rv) {
735 set_entered_regionview (0);
740 Editor::set_entered_regionview (RegionView* rv)
742 if (rv == entered_regionview) {
746 if (entered_regionview) {
747 entered_regionview->exited ();
750 if ((entered_regionview = rv) != 0) {
751 entered_regionview->entered ();
756 Editor::set_entered_track (TimeAxisView* tav)
759 entered_track->exited ();
762 if ((entered_track = tav) != 0) {
763 entered_track->entered ();
768 Editor::show_window ()
770 if (! is_visible ()) {
773 /* re-hide editor list if necessary */
774 editor_list_button_toggled ();
776 /* re-hide summary widget if necessary */
777 parameter_changed ("show-summary");
779 parameter_changed ("show-edit-group-tabs");
781 /* now reset all audio_time_axis heights, because widgets might need
787 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
788 tv = (static_cast<TimeAxisView*>(*i));
797 Editor::instant_save ()
799 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
804 session->add_instant_xml(get_state());
806 Config->add_instant_xml(get_state());
811 Editor::edit_point_clock_changed()
813 if (_dragging_edit_point) {
817 if (selection->markers.empty()) {
822 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
828 loc->move_to (edit_point_clock.current_time());
832 Editor::zoom_adjustment_changed ()
838 double fpu = zoom_range_clock.current_duration() / _canvas_width;
842 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
843 } else if (fpu > session->current_end_frame() / _canvas_width) {
844 fpu = session->current_end_frame() / _canvas_width;
845 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
852 Editor::control_scroll (float fraction)
854 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
860 double step = fraction * current_page_frames();
863 _control_scroll_target is an optional<T>
865 it acts like a pointer to an nframes64_t, with
866 a operator conversion to boolean to check
867 that it has a value could possibly use
868 playhead_cursor->current_frame to store the
869 value and a boolean in the class to know
870 when it's out of date
873 if (!_control_scroll_target) {
874 _control_scroll_target = session->transport_frame();
875 _dragging_playhead = true;
878 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
879 *_control_scroll_target = 0;
880 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
881 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
883 *_control_scroll_target += (nframes64_t) floor (step);
886 /* move visuals, we'll catch up with it later */
888 playhead_cursor->set_position (*_control_scroll_target);
889 UpdateAllTransportClocks (*_control_scroll_target);
891 if (*_control_scroll_target > (current_page_frames() / 2)) {
892 /* try to center PH in window */
893 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
899 Now we do a timeout to actually bring the session to the right place
900 according to the playhead. This is to avoid reading disk buffers on every
901 call to control_scroll, which is driven by ScrollTimeline and therefore
902 probably by a control surface wheel which can generate lots of events.
904 /* cancel the existing timeout */
906 control_scroll_connection.disconnect ();
908 /* add the next timeout */
910 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
914 Editor::deferred_control_scroll (nframes64_t target)
916 session->request_locate (*_control_scroll_target, session->transport_rolling());
917 // reset for next stream
918 _control_scroll_target = boost::none;
919 _dragging_playhead = false;
924 Editor::access_action (std::string action_group, std::string action_item)
930 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
933 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
943 Editor::on_realize ()
945 Window::on_realize ();
950 Editor::start_scrolling ()
952 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
953 (mem_fun(*this, &Editor::update_current_screen));
958 Editor::stop_scrolling ()
960 scroll_connection.disconnect ();
964 Editor::map_position_change (nframes64_t frame)
966 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
968 if (session == 0 || !_follow_playhead) {
972 center_screen (frame);
973 playhead_cursor->set_position (frame);
977 Editor::center_screen (nframes64_t frame)
979 double page = _canvas_width * frames_per_unit;
981 /* if we're off the page, then scroll.
984 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
985 center_screen_internal (frame, page);
990 Editor::center_screen_internal (nframes64_t frame, float page)
995 frame -= (nframes64_t) page;
1000 reset_x_origin (frame);
1004 Editor::handle_new_duration ()
1010 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1011 nframes64_t new_end = session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1013 horizontal_adjustment.set_upper (new_end / frames_per_unit);
1014 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1016 if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
1017 horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
1019 //cerr << "Editor::handle_new_duration () called ha v:l:u:ps:lcf = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << endl;//DEBUG
1023 Editor::update_title_s (const string & snap_name)
1025 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1031 Editor::update_title ()
1033 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1036 bool dirty = session->dirty();
1038 string session_name;
1040 if (session->snap_name() != session->name()) {
1041 session_name = session->snap_name();
1043 session_name = session->name();
1047 session_name = "*" + session_name;
1050 WindowTitle title(session_name);
1051 title += Glib::get_application_name();
1052 set_title (title.get_string());
1057 Editor::connect_to_session (Session *t)
1061 compute_fixed_ruler_scale ();
1063 /* there are never any selected regions at startup */
1065 sensitize_the_right_region_actions (false);
1067 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1070 /* catch up with the playhead */
1072 session->request_locate (playhead_cursor->current_frame);
1076 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1077 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1079 /* These signals can all be emitted by a non-GUI thread. Therefore the
1080 handlers for them must not attempt to directly interact with the GUI,
1081 but use Gtkmm2ext::UI::instance()->call_slot();
1084 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1085 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1086 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1087 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1088 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1089 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1090 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1091 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1092 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1094 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1096 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1098 session_connections.push_back (session->Located.connect (mem_fun (*this, &Editor::located)));
1099 session_connections.push_back (session->config.ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed)));
1101 edit_point_clock.set_mode(AudioClock::BBT);
1102 edit_point_clock.set_session (session);
1103 zoom_range_clock.set_session (session);
1104 _playlist_selector->set_session (session);
1105 nudge_clock.set_session (session);
1106 if (Profile->get_sae()) {
1111 nframes_t pos = session->tempo_map().bbt_duration_at (0, bbt, 1);
1112 nudge_clock.set_mode(AudioClock::BBT);
1113 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1116 nudge_clock.set (session->frame_rate() * 5, true, 0, AudioClock::SMPTE); // default of 5 seconds
1119 playhead_cursor->canvas_item.show ();
1121 if (rhythm_ferret) {
1122 rhythm_ferret->set_session (session);
1125 if (analysis_window != 0)
1126 analysis_window->set_session (session);
1128 Location* loc = session->locations()->auto_loop_location();
1130 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1131 if (loc->start() == loc->end()) {
1132 loc->set_end (loc->start() + 1);
1134 session->locations()->add (loc, false);
1135 session->set_auto_loop_location (loc);
1138 loc->set_name (_("Loop"));
1141 loc = session->locations()->auto_punch_location();
1143 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1144 if (loc->start() == loc->end()) {
1145 loc->set_end (loc->start() + 1);
1147 session->locations()->add (loc, false);
1148 session->set_auto_punch_location (loc);
1151 loc->set_name (_("Punch"));
1154 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1155 session->config.map_parameters (mem_fun (*this, &Editor::parameter_changed));
1157 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1159 refresh_location_display ();
1160 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1161 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1162 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1163 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1164 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1167 sfbrowser->set_session (session);
1170 handle_new_duration ();
1172 redisplay_named_selections ();
1174 restore_ruler_visibility ();
1175 //tempo_map_changed (Change (0));
1176 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1178 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1179 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1184 switch (snap_type) {
1185 case SnapToRegionStart:
1186 case SnapToRegionEnd:
1187 case SnapToRegionSync:
1188 case SnapToRegionBoundary:
1189 build_region_boundary_cache ();
1196 /* register for undo history */
1197 session->register_with_memento_command_factory(_id, this);
1199 _summary->connect_to_session (session);
1200 _group_tabs->connect_to_session (session);
1201 _route_groups->connect_to_session (session);
1202 _regions->connect_to_session (session);
1203 _snapshots->connect_to_session (session);
1204 _routes->connect_to_session (session);
1210 Editor::build_cursors ()
1212 using namespace Gdk;
1214 Gdk::Color mbg ("#000000" ); /* Black */
1215 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1218 RefPtr<Bitmap> source, mask;
1219 source = Bitmap::create (mag_bits, mag_width, mag_height);
1220 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1221 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1224 Gdk::Color fbg ("#ffffff" );
1225 Gdk::Color ffg ("#000000" );
1228 RefPtr<Bitmap> source, mask;
1230 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1231 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1232 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1236 RefPtr<Bitmap> source, mask;
1237 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1238 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1239 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1243 RefPtr<Bitmap> bits;
1244 char pix[4] = { 0, 0, 0, 0 };
1245 bits = Bitmap::create (pix, 2, 2);
1247 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1251 RefPtr<Bitmap> bits;
1252 char pix[4] = { 0, 0, 0, 0 };
1253 bits = Bitmap::create (pix, 2, 2);
1255 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1259 grabber_cursor = new Gdk::Cursor (HAND2);
1262 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1263 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1266 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1267 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1268 selector_cursor = new Gdk::Cursor (XTERM);
1269 time_fx_cursor = new Gdk::Cursor (SIZING);
1270 wait_cursor = new Gdk::Cursor (WATCH);
1271 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1272 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1273 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1274 midi_resize_cursor = new Gdk::Cursor (SIZING);
1275 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1278 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1280 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1282 using namespace Menu_Helpers;
1283 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1286 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1290 MenuList& items (fade_context_menu.items());
1294 switch (item_type) {
1296 case FadeInHandleItem:
1297 if (arv->audio_region()->fade_in_active()) {
1298 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1300 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1303 items.push_back (SeparatorElem());
1305 if (Profile->get_sae()) {
1306 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1307 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1309 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1310 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1311 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1312 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1313 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1319 case FadeOutHandleItem:
1320 if (arv->audio_region()->fade_out_active()) {
1321 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1323 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1326 items.push_back (SeparatorElem());
1328 if (Profile->get_sae()) {
1329 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1330 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1332 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1333 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1334 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1335 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1336 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1342 fatal << _("programming error: ")
1343 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1348 fade_context_menu.popup (button, time);
1352 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1354 using namespace Menu_Helpers;
1355 Menu* (Editor::*build_menu_function)(nframes64_t);
1358 switch (item_type) {
1360 case RegionViewName:
1361 case RegionViewNameHighlight:
1362 if (with_selection) {
1363 build_menu_function = &Editor::build_track_selection_context_menu;
1365 build_menu_function = &Editor::build_track_region_context_menu;
1370 if (with_selection) {
1371 build_menu_function = &Editor::build_track_selection_context_menu;
1373 build_menu_function = &Editor::build_track_context_menu;
1377 case CrossfadeViewItem:
1378 build_menu_function = &Editor::build_track_crossfade_context_menu;
1382 if (clicked_routeview->get_diskstream()) {
1383 build_menu_function = &Editor::build_track_context_menu;
1385 build_menu_function = &Editor::build_track_bus_context_menu;
1390 /* probably shouldn't happen but if it does, we don't care */
1394 menu = (this->*build_menu_function)(frame);
1395 menu->set_name ("ArdourContextMenu");
1397 /* now handle specific situations */
1399 switch (item_type) {
1401 case RegionViewName:
1402 case RegionViewNameHighlight:
1403 if (!with_selection) {
1404 if (region_edit_menu_split_item) {
1405 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1406 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1408 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1412 if (region_edit_menu_split_multichannel_item) {
1413 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1414 // GTK2FIX find the action, change its sensitivity
1415 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1417 // GTK2FIX see above
1418 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1427 case CrossfadeViewItem:
1434 /* probably shouldn't happen but if it does, we don't care */
1438 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1440 /* Bounce to disk */
1442 using namespace Menu_Helpers;
1443 MenuList& edit_items = menu->items();
1445 edit_items.push_back (SeparatorElem());
1447 switch (clicked_routeview->audio_track()->freeze_state()) {
1448 case AudioTrack::NoFreeze:
1449 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1452 case AudioTrack::Frozen:
1453 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1456 case AudioTrack::UnFrozen:
1457 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1463 if (item_type == StreamItem && clicked_routeview) {
1464 clicked_routeview->build_underlay_menu(menu);
1467 menu->popup (button, time);
1471 Editor::build_track_context_menu (nframes64_t ignored)
1473 using namespace Menu_Helpers;
1475 MenuList& edit_items = track_context_menu.items();
1478 add_dstream_context_items (edit_items);
1479 return &track_context_menu;
1483 Editor::build_track_bus_context_menu (nframes64_t ignored)
1485 using namespace Menu_Helpers;
1487 MenuList& edit_items = track_context_menu.items();
1490 add_bus_context_items (edit_items);
1491 return &track_context_menu;
1495 Editor::build_track_region_context_menu (nframes64_t frame)
1497 using namespace Menu_Helpers;
1498 MenuList& edit_items = track_region_context_menu.items();
1501 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1504 boost::shared_ptr<Diskstream> ds;
1505 boost::shared_ptr<Playlist> pl;
1507 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1508 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1510 if (selection->regions.size() > 1) {
1511 // there's already a multiple selection: just add a
1512 // single region context menu that will act on all
1514 boost::shared_ptr<Region> dummy_region; // = NULL
1515 add_region_context_items (rtv->view(), dummy_region, edit_items);
1517 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1518 add_region_context_items (rtv->view(), (*i), edit_items);
1526 add_dstream_context_items (edit_items);
1528 return &track_region_context_menu;
1532 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1534 using namespace Menu_Helpers;
1535 MenuList& edit_items = track_crossfade_context_menu.items();
1536 edit_items.clear ();
1538 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1541 boost::shared_ptr<Diskstream> ds;
1542 boost::shared_ptr<Playlist> pl;
1543 boost::shared_ptr<AudioPlaylist> apl;
1545 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1547 Playlist::RegionList* regions = pl->regions_at (frame);
1548 AudioPlaylist::Crossfades xfades;
1550 apl->crossfades_at (frame, xfades);
1552 bool many = xfades.size() > 1;
1554 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1555 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1558 if (selection->regions.size() > 1) {
1559 // there's already a multiple selection: just add a
1560 // single region context menu that will act on all
1562 boost::shared_ptr<Region> dummy_region; // = NULL
1563 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1565 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1566 add_region_context_items (atv->audio_view(), (*i), edit_items);
1573 add_dstream_context_items (edit_items);
1575 return &track_crossfade_context_menu;
1579 Editor::analyze_region_selection()
1581 if (analysis_window == 0) {
1582 analysis_window = new AnalysisWindow();
1585 analysis_window->set_session(session);
1587 analysis_window->show_all();
1590 analysis_window->set_regionmode();
1591 analysis_window->analyze();
1593 analysis_window->present();
1597 Editor::analyze_range_selection()
1599 if (analysis_window == 0) {
1600 analysis_window = new AnalysisWindow();
1603 analysis_window->set_session(session);
1605 analysis_window->show_all();
1608 analysis_window->set_rangemode();
1609 analysis_window->analyze();
1611 analysis_window->present();
1615 Editor::build_track_selection_context_menu (nframes64_t ignored)
1617 using namespace Menu_Helpers;
1618 MenuList& edit_items = track_selection_context_menu.items();
1619 edit_items.clear ();
1621 add_selection_context_items (edit_items);
1622 // edit_items.push_back (SeparatorElem());
1623 // add_dstream_context_items (edit_items);
1625 return &track_selection_context_menu;
1628 /** Add context menu items relevant to crossfades.
1629 * @param edit_items List to add the items to.
1632 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1634 using namespace Menu_Helpers;
1635 Menu *xfade_menu = manage (new Menu);
1636 MenuList& items = xfade_menu->items();
1637 xfade_menu->set_name ("ArdourContextMenu");
1640 if (xfade->active()) {
1646 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1647 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1649 if (xfade->can_follow_overlap()) {
1651 if (xfade->following_overlap()) {
1652 str = _("Convert to short");
1654 str = _("Convert to full");
1657 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1661 str = xfade->out()->name();
1663 str += xfade->in()->name();
1665 str = _("Crossfade");
1668 edit_items.push_back (MenuElem (str, *xfade_menu));
1669 edit_items.push_back (SeparatorElem());
1673 Editor::xfade_edit_left_region ()
1675 if (clicked_crossfadeview) {
1676 clicked_crossfadeview->left_view.show_region_editor ();
1681 Editor::xfade_edit_right_region ()
1683 if (clicked_crossfadeview) {
1684 clicked_crossfadeview->right_view.show_region_editor ();
1689 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1691 using namespace Menu_Helpers;
1692 Gtk::MenuItem* foo_item;
1693 Menu *region_menu = manage (new Menu);
1694 MenuList& items = region_menu->items();
1695 region_menu->set_name ("ArdourContextMenu");
1697 boost::shared_ptr<AudioRegion> ar;
1698 boost::shared_ptr<MidiRegion> mr;
1701 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1702 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1704 /* when this particular menu pops up, make the relevant region
1708 region_menu->signal_map_event().connect (
1709 bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1711 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1712 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1715 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1716 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1717 items.push_back (SeparatorElem());
1718 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1719 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1720 items.push_back (SeparatorElem());
1722 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1723 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1724 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1727 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1730 items.push_back (SeparatorElem());
1732 sigc::connection fooc;
1733 boost::shared_ptr<Region> region_to_check;
1736 region_to_check = region;
1738 region_to_check = selection->regions.front()->region();
1741 items.push_back (CheckMenuElem (_("Lock")));
1742 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1743 if (region_to_check->locked()) {
1744 region_lock_item->set_active();
1746 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1748 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1749 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1751 switch (region_to_check->positional_lock_style()) {
1752 case Region::MusicTime:
1753 bbt_glue_item->set_active (true);
1756 bbt_glue_item->set_active (false);
1760 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1762 items.push_back (CheckMenuElem (_("Mute")));
1763 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1764 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1765 if (region_to_check->muted()) {
1767 region_mute_item->set_active();
1771 if (!Profile->get_sae()) {
1772 items.push_back (CheckMenuElem (_("Opaque")));
1773 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1774 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1775 if (region_to_check->opaque()) {
1777 region_opaque_item->set_active();
1782 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1783 if (region_to_check->at_natural_position()) {
1784 items.back().set_sensitive (false);
1787 items.push_back (SeparatorElem());
1791 RegionView* rv = sv->find_view (ar);
1792 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1794 if (!Profile->get_sae()) {
1795 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1797 items.push_back (CheckMenuElem (_("Envelope Visible")));
1798 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1799 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1800 if (arv->envelope_visible()) {
1802 region_envelope_visible_item->set_active (true);
1806 items.push_back (CheckMenuElem (_("Envelope Active")));
1807 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1808 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1810 if (ar->envelope_active()) {
1812 region_envelope_active_item->set_active (true);
1816 items.push_back (SeparatorElem());
1819 if (ar->scale_amplitude() != 1.0f) {
1820 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1822 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1826 items.push_back (MenuElem (_("Quantize"), mem_fun(*this, &Editor::quantize_region)));
1827 items.push_back (SeparatorElem());
1830 items.push_back (MenuElem (_("Strip silence..."), mem_fun (*this, &Editor::strip_region_silence)));
1831 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1832 items.push_back (SeparatorElem());
1834 /* range related stuff */
1836 items.push_back (MenuElem (_("Add Single Range"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1837 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_locations_from_audio_region)));
1838 if (selection->regions.size() < 2) {
1839 items.back().set_sensitive (false);
1842 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
1843 items.push_back (SeparatorElem());
1847 Menu *nudge_menu = manage (new Menu());
1848 MenuList& nudge_items = nudge_menu->items();
1849 nudge_menu->set_name ("ArdourContextMenu");
1851 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1852 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1853 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1854 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1856 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1857 items.push_back (SeparatorElem());
1859 Menu *trim_menu = manage (new Menu);
1860 MenuList& trim_items = trim_menu->items();
1861 trim_menu->set_name ("ArdourContextMenu");
1863 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1864 foo_item = &trim_items.back();
1865 if (_edit_point == EditAtMouse) {
1866 foo_item->set_sensitive (false);
1868 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1869 foo_item = &trim_items.back();
1870 if (_edit_point == EditAtMouse) {
1871 foo_item->set_sensitive (false);
1873 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1874 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1876 items.push_back (MenuElem (_("Trim"), *trim_menu));
1877 items.push_back (SeparatorElem());
1879 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1880 region_edit_menu_split_item = &items.back();
1882 if (_edit_point == EditAtMouse) {
1883 region_edit_menu_split_item->set_sensitive (false);
1886 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1887 region_edit_menu_split_multichannel_item = &items.back();
1889 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1890 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1891 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1892 items.push_back (SeparatorElem());
1893 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
1895 /* OK, stick the region submenu at the top of the list, and then add
1899 /* we have to hack up the region name because "_" has a special
1900 meaning for menu titles.
1903 string::size_type pos = 0;
1904 string menu_item_name = (region) ? region->name() : _("Selected regions");
1906 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1907 menu_item_name.replace (pos, 1, "__");
1911 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1912 edit_items.push_back (SeparatorElem());
1915 /** Add context menu items relevant to selection ranges.
1916 * @param edit_items List to add the items to.
1919 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1921 using namespace Menu_Helpers;
1923 edit_items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
1924 edit_items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
1926 edit_items.push_back (SeparatorElem());
1927 edit_items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
1929 edit_items.push_back (SeparatorElem());
1930 edit_items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1931 edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1933 edit_items.push_back (SeparatorElem());
1934 edit_items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
1935 edit_items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
1937 edit_items.push_back (SeparatorElem());
1938 edit_items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1940 edit_items.push_back (SeparatorElem());
1941 edit_items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
1942 edit_items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
1944 edit_items.push_back (SeparatorElem());
1945 edit_items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
1946 edit_items.push_back (SeparatorElem());
1947 edit_items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
1948 edit_items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
1949 edit_items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
1950 edit_items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
1951 edit_items.push_back (SeparatorElem());
1952 edit_items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, false)));
1953 edit_items.push_back (MenuElem (_("Consolidate range with processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, true)));
1954 edit_items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, false)));
1955 edit_items.push_back (MenuElem (_("Bounce range to region list with processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, true)));
1956 edit_items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_range)));
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"), mem_fun(*this, &Editor::play_from_edit_point)));
1972 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
1973 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
1974 play_items.push_back (SeparatorElem());
1975 play_items.push_back (MenuElem (_("Loop Region"), 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"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1986 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
1987 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
1988 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
1989 select_items.push_back (SeparatorElem());
1990 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
1991 select_items.push_back (MenuElem (_("Set range to punch range"), 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"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1994 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1995 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1996 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1997 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
1998 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
1999 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2001 select_items.push_back (SeparatorElem());
2003 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2007 Menu *cutnpaste_menu = manage (new Menu);
2008 MenuList& cutnpaste_items = cutnpaste_menu->items();
2009 cutnpaste_menu->set_name ("ArdourContextMenu");
2011 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2012 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2013 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2015 cutnpaste_items.push_back (SeparatorElem());
2017 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2018 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2020 cutnpaste_items.push_back (SeparatorElem());
2022 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2024 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2026 /* Adding new material */
2028 edit_items.push_back (SeparatorElem());
2029 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2030 edit_items.push_back (MenuElem (_("Insert Existing Media"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2034 Menu *nudge_menu = manage (new Menu());
2035 MenuList& nudge_items = nudge_menu->items();
2036 nudge_menu->set_name ("ArdourContextMenu");
2038 edit_items.push_back (SeparatorElem());
2039 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2040 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2041 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2042 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2044 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2048 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2050 using namespace Menu_Helpers;
2054 Menu *play_menu = manage (new Menu);
2055 MenuList& play_items = play_menu->items();
2056 play_menu->set_name ("ArdourContextMenu");
2058 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2059 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2060 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2064 Menu *select_menu = manage (new Menu);
2065 MenuList& select_items = select_menu->items();
2066 select_menu->set_name ("ArdourContextMenu");
2068 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2069 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2070 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2071 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2072 select_items.push_back (SeparatorElem());
2073 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2074 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2075 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2076 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2078 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2082 Menu *cutnpaste_menu = manage (new Menu);
2083 MenuList& cutnpaste_items = cutnpaste_menu->items();
2084 cutnpaste_menu->set_name ("ArdourContextMenu");
2086 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2087 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2088 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2090 Menu *nudge_menu = manage (new Menu());
2091 MenuList& nudge_items = nudge_menu->items();
2092 nudge_menu->set_name ("ArdourContextMenu");
2094 edit_items.push_back (SeparatorElem());
2095 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2096 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2097 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2098 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2100 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2104 Editor::set_snap_to (SnapType st)
2106 unsigned int snap_ind = (unsigned int)st;
2110 if (snap_ind > snap_type_strings.size() - 1) {
2112 snap_type = (SnapType)snap_ind;
2115 string str = snap_type_strings[snap_ind];
2117 if (str != snap_type_selector.get_active_text()) {
2118 snap_type_selector.set_active_text (str);
2123 switch (snap_type) {
2124 case SnapToAThirtysecondBeat:
2125 case SnapToASixteenthBeat:
2126 case SnapToAEighthBeat:
2127 case SnapToAQuarterBeat:
2128 case SnapToAThirdBeat:
2129 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2130 update_tempo_based_rulers ();
2133 case SnapToRegionStart:
2134 case SnapToRegionEnd:
2135 case SnapToRegionSync:
2136 case SnapToRegionBoundary:
2137 build_region_boundary_cache ();
2147 Editor::set_snap_mode (SnapMode mode)
2150 string str = snap_mode_strings[(int)mode];
2152 if (str != snap_mode_selector.get_active_text ()) {
2153 snap_mode_selector.set_active_text (str);
2159 Editor::set_edit_point_preference (EditPoint ep, bool force)
2161 bool changed = (_edit_point != ep);
2164 string str = edit_point_strings[(int)ep];
2166 if (str != edit_point_selector.get_active_text ()) {
2167 edit_point_selector.set_active_text (str);
2170 set_canvas_cursor ();
2172 if (!force && !changed) {
2176 switch (zoom_focus) {
2177 case ZoomFocusMouse:
2178 case ZoomFocusPlayhead:
2180 switch (_edit_point) {
2182 set_zoom_focus (ZoomFocusMouse);
2184 case EditAtPlayhead:
2185 set_zoom_focus (ZoomFocusPlayhead);
2187 case EditAtSelectedMarker:
2188 set_zoom_focus (ZoomFocusEdit);
2196 const char* action=NULL;
2198 switch (_edit_point) {
2199 case EditAtPlayhead:
2200 action = "edit-at-playhead";
2202 case EditAtSelectedMarker:
2203 action = "edit-at-marker";
2206 action = "edit-at-mouse";
2210 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2212 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2216 bool in_track_canvas;
2218 if (!mouse_frame (foo, in_track_canvas)) {
2219 in_track_canvas = false;
2222 reset_canvas_action_sensitivity (in_track_canvas);
2228 Editor::set_state (const XMLNode& node)
2230 const XMLProperty* prop;
2232 int x, y, xoff, yoff;
2235 if ((prop = node.property ("id")) != 0) {
2236 _id = prop->value ();
2239 g.base_width = default_width;
2240 g.base_height = default_height;
2246 if ((geometry = find_named_node (node, "geometry")) != 0) {
2250 if ((prop = geometry->property("x_size")) == 0) {
2251 prop = geometry->property ("x-size");
2254 g.base_width = atoi(prop->value());
2256 if ((prop = geometry->property("y_size")) == 0) {
2257 prop = geometry->property ("y-size");
2260 g.base_height = atoi(prop->value());
2263 if ((prop = geometry->property ("x_pos")) == 0) {
2264 prop = geometry->property ("x-pos");
2267 x = atoi (prop->value());
2270 if ((prop = geometry->property ("y_pos")) == 0) {
2271 prop = geometry->property ("y-pos");
2274 y = atoi (prop->value());
2277 if ((prop = geometry->property ("x_off")) == 0) {
2278 prop = geometry->property ("x-off");
2281 xoff = atoi (prop->value());
2283 if ((prop = geometry->property ("y_off")) == 0) {
2284 prop = geometry->property ("y-off");
2287 yoff = atoi (prop->value());
2291 set_default_size (g.base_width, g.base_height);
2294 if (session && (prop = node.property ("playhead"))) {
2295 nframes64_t pos = atol (prop->value().c_str());
2296 playhead_cursor->set_position (pos);
2298 playhead_cursor->set_position (0);
2300 /* reset_x_origin() doesn't work right here, since the old
2301 position may be zero already, and it does nothing in such
2306 horizontal_adjustment.set_value (0);
2309 if ((prop = node.property ("mixer-width"))) {
2310 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2313 if ((prop = node.property ("zoom-focus"))) {
2314 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2317 if ((prop = node.property ("zoom"))) {
2318 reset_zoom (PBD::atof (prop->value()));
2321 if ((prop = node.property ("snap-to"))) {
2322 set_snap_to ((SnapType) atoi (prop->value()));
2325 if ((prop = node.property ("snap-mode"))) {
2326 set_snap_mode ((SnapMode) atoi (prop->value()));
2329 if ((prop = node.property ("edit-point"))) {
2330 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2333 if ((prop = node.property ("mouse-mode"))) {
2334 MouseMode m = str2mousemode(prop->value());
2335 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2336 set_mouse_mode (m, true);
2338 mouse_mode = MouseGain; /* lie, to force the mode switch */
2339 set_mouse_mode (MouseObject, true);
2342 if ((prop = node.property ("show-waveforms-recording"))) {
2343 bool yn = (prop->value() == "yes");
2344 _show_waveforms_recording = !yn;
2345 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2347 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2348 /* do it twice to force the change */
2349 tact->set_active (!yn);
2350 tact->set_active (yn);
2354 if ((prop = node.property ("show-measures"))) {
2355 bool yn = (prop->value() == "yes");
2356 _show_measures = !yn;
2357 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2359 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2360 /* do it twice to force the change */
2361 tact->set_active (!yn);
2362 tact->set_active (yn);
2366 if ((prop = node.property ("follow-playhead"))) {
2367 bool yn = (prop->value() == "yes");
2368 set_follow_playhead (yn);
2369 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2371 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2372 if (tact->get_active() != yn) {
2373 tact->set_active (yn);
2378 if ((prop = node.property ("region-list-sort-type"))) {
2379 _regions->reset_sort_type (str2regionlistsorttype(prop->value()), true);
2382 if ((prop = node.property ("xfades-visible"))) {
2383 bool yn = (prop->value() == "yes");
2384 _xfade_visibility = !yn;
2385 // set_xfade_visibility (yn);
2388 if ((prop = node.property ("show-editor-mixer"))) {
2390 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2393 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2394 bool yn = (prop->value() == X_("yes"));
2396 /* do it twice to force the change */
2398 tact->set_active (!yn);
2399 tact->set_active (yn);
2403 if ((prop = node.property ("show-editor-list"))) {
2405 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2409 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2410 bool yn = (prop->value() == X_("yes"));
2412 /* do it twice to force the change */
2414 tact->set_active (!yn);
2415 tact->set_active (yn);
2424 Editor::get_state ()
2426 XMLNode* node = new XMLNode ("Editor");
2429 _id.print (buf, sizeof (buf));
2430 node->add_property ("id", buf);
2432 if (is_realized()) {
2433 Glib::RefPtr<Gdk::Window> win = get_window();
2435 int x, y, xoff, yoff, width, height;
2436 win->get_root_origin(x, y);
2437 win->get_position(xoff, yoff);
2438 win->get_size(width, height);
2440 XMLNode* geometry = new XMLNode ("geometry");
2442 snprintf(buf, sizeof(buf), "%d", width);
2443 geometry->add_property("x-size", string(buf));
2444 snprintf(buf, sizeof(buf), "%d", height);
2445 geometry->add_property("y-size", string(buf));
2446 snprintf(buf, sizeof(buf), "%d", x);
2447 geometry->add_property("x-pos", string(buf));
2448 snprintf(buf, sizeof(buf), "%d", y);
2449 geometry->add_property("y-pos", string(buf));
2450 snprintf(buf, sizeof(buf), "%d", xoff);
2451 geometry->add_property("x-off", string(buf));
2452 snprintf(buf, sizeof(buf), "%d", yoff);
2453 geometry->add_property("y-off", string(buf));
2454 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2455 geometry->add_property("edit_pane_pos", string(buf));
2457 node->add_child_nocopy (*geometry);
2460 maybe_add_mixer_strip_width (*node);
2462 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2463 node->add_property ("zoom-focus", buf);
2464 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2465 node->add_property ("zoom", buf);
2466 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2467 node->add_property ("snap-to", buf);
2468 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2469 node->add_property ("snap-mode", buf);
2471 node->add_property ("edit-point", enum_2_string (_edit_point));
2473 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2474 node->add_property ("playhead", buf);
2476 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2477 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2478 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2479 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2480 node->add_property ("region-list-sort-type", enum2str (_regions->sort_type ()));
2481 node->add_property ("mouse-mode", enum2str(mouse_mode));
2483 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2485 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2486 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2489 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2491 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2492 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2500 /** @param y y offset from the top of all trackviews.
2501 * @return pair: TimeAxisView that y is over, layer index.
2502 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2503 * in stacked region display mode, otherwise 0.
2505 std::pair<TimeAxisView *, layer_t>
2506 Editor::trackview_by_y_position (double y)
2508 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2510 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2516 return std::make_pair ( (TimeAxisView *) 0, 0);
2520 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2522 if (!session || snap_mode == SnapOff) {
2526 snap_to_internal (start, direction, for_mark);
2530 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2532 Location* before = 0;
2533 Location* after = 0;
2535 const nframes64_t one_second = session->frame_rate();
2536 const nframes64_t one_minute = session->frame_rate() * 60;
2537 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2538 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2539 nframes64_t presnap = start;
2541 switch (snap_type) {
2543 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2544 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2546 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2550 case SnapToSMPTEFrame:
2551 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2552 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2554 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2558 case SnapToSMPTESeconds:
2559 if (session->smpte_offset_negative())
2561 start += session->smpte_offset ();
2563 start -= session->smpte_offset ();
2565 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2566 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2568 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2571 if (session->smpte_offset_negative())
2573 start -= session->smpte_offset ();
2575 start += session->smpte_offset ();
2579 case SnapToSMPTEMinutes:
2580 if (session->smpte_offset_negative())
2582 start += session->smpte_offset ();
2584 start -= session->smpte_offset ();
2586 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2587 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2589 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2591 if (session->smpte_offset_negative())
2593 start -= session->smpte_offset ();
2595 start += session->smpte_offset ();
2600 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2601 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2603 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2608 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2609 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2611 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2616 start = session->tempo_map().round_to_bar (start, direction);
2620 start = session->tempo_map().round_to_beat (start, direction);
2623 case SnapToAThirtysecondBeat:
2624 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2627 case SnapToASixteenthBeat:
2628 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2631 case SnapToAEighthBeat:
2632 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2635 case SnapToAQuarterBeat:
2636 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2639 case SnapToAThirdBeat:
2640 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2648 before = session->locations()->first_location_before (start);
2649 after = session->locations()->first_location_after (start);
2651 if (direction < 0) {
2653 start = before->start();
2657 } else if (direction > 0) {
2659 start = after->start();
2661 start = session->current_end_frame();
2666 /* find nearest of the two */
2667 if ((start - before->start()) < (after->start() - start)) {
2668 start = before->start();
2670 start = after->start();
2673 start = before->start();
2676 start = after->start();
2683 case SnapToRegionStart:
2684 case SnapToRegionEnd:
2685 case SnapToRegionSync:
2686 case SnapToRegionBoundary:
2687 if (!region_boundary_cache.empty()) {
2688 vector<nframes64_t>::iterator i;
2690 if (direction > 0) {
2691 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2693 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2696 if (i != region_boundary_cache.end()) {
2698 /* lower bound doesn't quite to the right thing for our purposes */
2700 if (direction < 0 && i != region_boundary_cache.begin()) {
2707 start = region_boundary_cache.back();
2713 switch (snap_mode) {
2719 if (presnap > start) {
2720 if (presnap > (start + unit_to_frame(snap_threshold))) {
2724 } else if (presnap < start) {
2725 if (presnap < (start - unit_to_frame(snap_threshold))) {
2731 /* handled at entry */
2738 Editor::snap_length_beats (nframes64_t start)
2744 /* FIXME: This could/should also work with non-tempo based snap settings (ie seconds) */
2746 switch (snap_type) {
2748 return session->tempo_map().meter_at(start).beats_per_bar();
2753 case SnapToAThirtysecondBeat:
2754 return 1.0 / (double)32.0;
2757 case SnapToASixteenthBeat:
2758 return 1.0 / (double)16.0;
2761 case SnapToAEighthBeat:
2762 return 1.0 / (double)8.0;
2765 case SnapToAQuarterBeat:
2766 return 1.0 / (double)4.0;
2769 case SnapToAThirdBeat:
2770 return 1.0 / (double)3.0;
2778 Editor::setup_toolbar ()
2782 /* Mode Buttons (tool selection) */
2784 vector<ToggleButton *> mouse_mode_buttons;
2786 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2787 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2788 mouse_mode_buttons.push_back (&mouse_move_button);
2790 if (!Profile->get_sae()) {
2791 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2792 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2793 mouse_mode_buttons.push_back (&mouse_select_button);
2795 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2796 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2797 mouse_mode_buttons.push_back (&mouse_gain_button);
2800 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2801 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2802 mouse_mode_buttons.push_back (&mouse_zoom_button);
2803 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2804 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2805 mouse_mode_buttons.push_back (&mouse_timefx_button);
2806 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2807 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2808 mouse_note_button.add (*(manage (new Image (::get_icon("tool_note")))));
2809 mouse_note_button.set_relief(Gtk::RELIEF_NONE);
2810 mouse_mode_buttons.push_back (&mouse_note_button);
2811 mouse_mode_buttons.push_back (&mouse_audition_button);
2813 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2815 HBox* mode_box = manage(new HBox);
2816 mode_box->set_border_width (2);
2817 mode_box->set_spacing(4);
2818 mouse_mode_button_box.set_spacing(1);
2819 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2820 if (!Profile->get_sae()) {
2821 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2823 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2824 if (!Profile->get_sae()) {
2825 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2827 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2828 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2829 mouse_mode_button_box.pack_start(mouse_note_button, true, true);
2830 mouse_mode_button_box.set_homogeneous(true);
2832 vector<string> edit_mode_strings;
2833 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2834 if (!Profile->get_sae()) {
2835 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2837 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2839 edit_mode_selector.set_name ("EditModeSelector");
2840 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2841 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2843 mode_box->pack_start(edit_mode_selector);
2844 mode_box->pack_start(mouse_mode_button_box);
2846 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2847 mouse_mode_tearoff->set_name ("MouseModeBase");
2849 if (Profile->get_sae()) {
2850 mouse_mode_tearoff->set_can_be_torn_off (false);
2853 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2854 &mouse_mode_tearoff->tearoff_window()));
2855 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2856 &mouse_mode_tearoff->tearoff_window(), 1));
2857 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2858 &mouse_mode_tearoff->tearoff_window()));
2859 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2860 &mouse_mode_tearoff->tearoff_window(), 1));
2862 mouse_move_button.set_name ("MouseModeButton");
2863 mouse_select_button.set_name ("MouseModeButton");
2864 mouse_gain_button.set_name ("MouseModeButton");
2865 mouse_zoom_button.set_name ("MouseModeButton");
2866 mouse_timefx_button.set_name ("MouseModeButton");
2867 mouse_audition_button.set_name ("MouseModeButton");
2868 mouse_note_button.set_name ("MouseModeButton");
2870 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2871 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2872 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2873 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2874 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2875 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2876 ARDOUR_UI::instance()->tooltips().set_tip (mouse_note_button, _("Edit MIDI Notes"));
2878 mouse_move_button.unset_flags (CAN_FOCUS);
2879 mouse_select_button.unset_flags (CAN_FOCUS);
2880 mouse_gain_button.unset_flags (CAN_FOCUS);
2881 mouse_zoom_button.unset_flags (CAN_FOCUS);
2882 mouse_timefx_button.unset_flags (CAN_FOCUS);
2883 mouse_audition_button.unset_flags (CAN_FOCUS);
2884 mouse_note_button.unset_flags (CAN_FOCUS);
2886 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2887 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2889 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2890 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2891 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2892 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2893 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2894 mouse_note_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseNote));
2896 // mouse_move_button.set_active (true);
2901 zoom_box.set_spacing (1);
2902 zoom_box.set_border_width (0);
2904 zoom_in_button.set_name ("EditorTimeButton");
2905 zoom_in_button.set_size_request(-1,16);
2906 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2907 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2908 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2910 zoom_out_button.set_name ("EditorTimeButton");
2911 zoom_out_button.set_size_request(-1,16);
2912 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2913 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2914 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2916 zoom_out_full_button.set_name ("EditorTimeButton");
2917 zoom_out_full_button.set_size_request(-1,16);
2918 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2919 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2920 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2922 zoom_focus_selector.set_name ("ZoomFocusSelector");
2923 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
2924 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2925 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2927 zoom_box.pack_start (zoom_out_button, false, false);
2928 zoom_box.pack_start (zoom_in_button, false, false);
2929 zoom_box.pack_start (zoom_out_full_button, false, false);
2931 HBox* zbc = manage (new HBox);
2932 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
2933 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
2934 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
2936 snap_box.set_spacing (1);
2937 snap_box.set_border_width (2);
2939 snap_type_selector.set_name ("SnapTypeSelector");
2940 set_popdown_strings (snap_type_selector, snap_type_strings, true);
2941 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2942 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2944 snap_mode_selector.set_name ("SnapModeSelector");
2945 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
2946 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2947 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2949 edit_point_selector.set_name ("EditPointSelector");
2950 set_popdown_strings (edit_point_selector, edit_point_strings, true);
2951 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2952 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2954 snap_box.pack_start (edit_point_clock, false, false);
2955 snap_box.pack_start (snap_mode_selector, false, false);
2956 snap_box.pack_start (snap_type_selector, false, false);
2957 snap_box.pack_start (edit_point_selector, false, false);
2961 HBox *nudge_box = manage (new HBox);
2962 nudge_box->set_spacing(1);
2963 nudge_box->set_border_width (2);
2965 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
2966 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
2968 nudge_box->pack_start (nudge_backward_button, false, false);
2969 nudge_box->pack_start (nudge_forward_button, false, false);
2970 nudge_box->pack_start (nudge_clock, false, false);
2973 /* Pack everything in... */
2975 HBox* hbox = manage (new HBox);
2976 hbox->set_spacing(10);
2978 tools_tearoff = manage (new TearOff (*hbox));
2979 tools_tearoff->set_name ("MouseModeBase");
2981 if (Profile->get_sae()) {
2982 tools_tearoff->set_can_be_torn_off (false);
2985 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2986 &tools_tearoff->tearoff_window()));
2987 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2988 &tools_tearoff->tearoff_window(), 0));
2989 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2990 &tools_tearoff->tearoff_window()));
2991 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2992 &tools_tearoff->tearoff_window(), 0));
2994 toolbar_hbox.set_spacing (10);
2995 toolbar_hbox.set_border_width (1);
2997 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2998 toolbar_hbox.pack_start (*tools_tearoff, false, false);
3001 hbox->pack_start (snap_box, false, false);
3002 // hbox->pack_start (zoom_box, false, false);
3003 hbox->pack_start (*nudge_box, false, false);
3007 toolbar_base.set_name ("ToolBarBase");
3008 toolbar_base.add (toolbar_hbox);
3010 toolbar_frame.set_shadow_type (SHADOW_OUT);
3011 toolbar_frame.set_name ("BaseFrame");
3012 toolbar_frame.add (toolbar_base);
3016 Editor::midi_panic_button_pressed ()
3019 session->midi_panic();
3024 Editor::setup_midi_toolbar ()
3028 /* Mode Buttons (tool selection) */
3030 vector<ToggleButton *> midi_tool_buttons;
3032 midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
3033 midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
3034 midi_tool_buttons.push_back (&midi_tool_pencil_button);
3035 midi_tool_select_button.add (*(manage (new Image (::get_icon("midi_tool_select")))));
3036 midi_tool_select_button.set_relief(Gtk::RELIEF_NONE);
3037 midi_tool_buttons.push_back (&midi_tool_select_button);
3038 midi_tool_resize_button.add (*(manage (new Image (::get_icon("strip_width")))));
3039 midi_tool_resize_button.set_relief(Gtk::RELIEF_NONE);
3040 midi_tool_buttons.push_back (&midi_tool_resize_button);
3041 midi_tool_erase_button.add (*(manage (new Image (::get_icon("midi_tool_erase")))));
3042 midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
3043 midi_tool_buttons.push_back (&midi_tool_erase_button);
3045 midi_tool_pencil_button.set_active(true);
3047 midi_tool_button_set = new GroupedButtons (midi_tool_buttons);
3049 midi_tool_button_box.set_border_width (2);
3050 midi_tool_button_box.set_spacing(1);
3051 midi_tool_button_box.pack_start(midi_tool_pencil_button, true, true);
3052 midi_tool_button_box.pack_start(midi_tool_select_button, true, true);
3053 midi_tool_button_box.pack_start(midi_tool_resize_button, true, true);
3054 midi_tool_button_box.pack_start(midi_tool_erase_button , true, true);
3055 midi_tool_button_box.set_homogeneous(true);
3057 midi_tool_pencil_button.set_name ("MouseModeButton");
3058 midi_tool_select_button.set_name ("MouseModeButton");
3059 midi_tool_resize_button.set_name ("MouseModeButton");
3060 midi_tool_erase_button .set_name ("MouseModeButton");
3062 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
3063 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
3064 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
3065 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
3067 midi_tool_pencil_button.unset_flags (CAN_FOCUS);
3068 midi_tool_select_button.unset_flags (CAN_FOCUS);
3069 midi_tool_resize_button.unset_flags (CAN_FOCUS);
3070 midi_tool_erase_button.unset_flags (CAN_FOCUS);
3072 midi_tool_pencil_button.signal_toggled().connect (bind (mem_fun(*this,
3073 &Editor::midi_edit_mode_toggled), Editing::MidiEditPencil));
3074 midi_tool_select_button.signal_toggled().connect (bind (mem_fun(*this,
3075 &Editor::midi_edit_mode_toggled), Editing::MidiEditSelect));
3076 midi_tool_resize_button.signal_toggled().connect (bind (mem_fun(*this,
3077 &Editor::midi_edit_mode_toggled), Editing::MidiEditResize));
3078 midi_tool_erase_button.signal_toggled().connect (bind (mem_fun(*this,
3079 &Editor::midi_edit_mode_toggled), Editing::MidiEditErase));
3082 /* Midi sound notes */
3083 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3084 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3085 ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes"));
3086 midi_sound_notes.unset_flags (CAN_FOCUS);
3090 HBox* panic_box = manage (new HBox);
3091 midi_panic_button.set_name("MidiPanicButton");
3092 midi_panic_button.signal_pressed().connect (
3093 mem_fun(this, &Editor::midi_panic_button_pressed));
3094 panic_box->pack_start (midi_sound_notes , true, true);
3095 panic_box->pack_start (midi_panic_button, true, true);
3097 /* Pack everything in... */
3099 midi_tools_tearoff = manage (new TearOff (midi_tool_button_box));
3100 midi_tools_tearoff->set_name ("MouseModeBase");
3103 midi_tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3104 &midi_tools_tearoff->tearoff_window()));
3105 midi_tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3106 &midi_tools_tearoff->tearoff_window(), 0));
3107 midi_tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3108 &midi_tools_tearoff->tearoff_window()));
3109 midi_tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3110 &midi_tools_tearoff->tearoff_window(), 0));
3113 midi_toolbar_hbox.set_spacing (10);
3114 midi_toolbar_hbox.set_border_width (1);
3116 midi_toolbar_hbox.pack_start (*midi_tools_tearoff, false, true);
3118 midi_toolbar_hbox.pack_start(*panic_box, false, true, 4);
3120 midi_tool_button_box.show_all ();
3121 midi_toolbar_hbox.show_all();
3122 midi_tools_tearoff->show_all();
3124 midi_toolbar_base.set_name ("ToolBarBase");
3125 midi_toolbar_base.add (midi_toolbar_hbox);
3127 midi_toolbar_frame.set_shadow_type (SHADOW_OUT);
3128 midi_toolbar_frame.set_name ("BaseFrame");
3129 midi_toolbar_frame.add (midi_toolbar_base);
3133 Editor::convert_drop_to_paths (
3134 vector<ustring>& paths,
3135 const RefPtr<Gdk::DragContext>& context,
3138 const SelectionData& data,
3146 vector<ustring> uris = data.get_uris();
3150 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3151 are actually URI lists. So do it by hand.
3154 if (data.get_target() != "text/plain") {
3158 /* Parse the "uri-list" format that Nautilus provides,
3159 where each pathname is delimited by \r\n.
3161 THERE MAY BE NO NULL TERMINATING CHAR!!!
3164 ustring txt = data.get_text();
3168 p = (const char *) malloc (txt.length() + 1);
3169 txt.copy ((char *) p, txt.length(), 0);
3170 ((char*)p)[txt.length()] = '\0';
3176 while (g_ascii_isspace (*p))
3180 while (*q && (*q != '\n') && (*q != '\r')) {
3187 while (q > p && g_ascii_isspace (*q))
3192 uris.push_back (ustring (p, q - p + 1));
3196 p = strchr (p, '\n');
3208 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3210 if ((*i).substr (0,7) == "file://") {
3213 PBD::url_decode (p);
3215 // scan forward past three slashes
3217 ustring::size_type slashcnt = 0;
3218 ustring::size_type n = 0;
3219 ustring::iterator x = p.begin();
3221 while (slashcnt < 3 && x != p.end()) {
3224 } else if (slashcnt == 3) {
3231 if (slashcnt != 3 || x == p.end()) {
3232 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3236 paths.push_back (p.substr (n - 1));
3244 Editor::new_tempo_section ()
3250 Editor::map_transport_state ()
3252 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3254 if (session->transport_stopped()) {
3255 have_pending_keyboard_selection = false;
3258 update_loop_range_view (true);
3263 Editor::State::State (PublicEditor const * e)
3265 selection = new Selection (e);
3268 Editor::State::~State ()
3274 Editor::store_state (State& state) const
3276 *state.selection = *selection;
3280 Editor::restore_state (State *state)
3282 if (*selection == *state->selection) {
3286 *selection = *state->selection;
3287 time_selection_changed ();
3288 region_selection_changed ();
3290 /* XXX other selection change handlers? */
3294 Editor::begin_reversible_command (string name)
3297 before = &get_state();
3298 session->begin_reversible_command (name);
3303 Editor::commit_reversible_command ()
3306 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3311 Editor::set_route_group_solo (Route& route, bool yn)
3313 RouteGroup *route_group;
3315 if ((route_group = route.route_group()) != 0) {
3316 route_group->apply (&Route::set_solo, yn, this);
3318 route.set_solo (yn, this);
3323 Editor::set_route_group_mute (Route& route, bool yn)
3325 RouteGroup *route_group = 0;
3327 if ((route_group == route.route_group()) != 0) {
3328 route_group->apply (&Route::set_mute, yn, this);
3330 route.set_mute (yn, this);
3335 Editor::history_changed ()
3339 if (undo_action && session) {
3340 if (session->undo_depth() == 0) {
3343 label = string_compose(_("Undo (%1)"), session->next_undo());
3345 undo_action->property_label() = label;
3348 if (redo_action && session) {
3349 if (session->redo_depth() == 0) {
3352 label = string_compose(_("Redo (%1)"), session->next_redo());
3354 redo_action->property_label() = label;
3359 Editor::duplicate_dialog (bool with_dialog)
3363 if (mouse_mode == MouseRange) {
3364 if (selection->time.length() == 0) {
3370 get_regions_for_action (rs);
3372 if (mouse_mode != MouseRange) {
3381 ArdourDialog win ("Duplication Dialog");
3382 Label label (_("Number of Duplications:"));
3383 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3384 SpinButton spinner (adjustment, 0.0, 1);
3387 win.get_vbox()->set_spacing (12);
3388 win.get_vbox()->pack_start (hbox);
3389 hbox.set_border_width (6);
3390 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3392 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3393 place, visually. so do this by hand.
3396 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3397 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3398 spinner.grab_focus();
3404 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3405 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3406 win.set_default_response (RESPONSE_ACCEPT);
3408 win.set_position (WIN_POS_MOUSE);
3410 spinner.grab_focus ();
3412 switch (win.run ()) {
3413 case RESPONSE_ACCEPT:
3419 times = adjustment.get_value();
3422 if (mouse_mode == MouseRange) {
3423 duplicate_selection (times);
3425 duplicate_some_regions (rs, times);
3430 Editor::show_verbose_canvas_cursor ()
3432 verbose_canvas_cursor->raise_to_top();
3433 verbose_canvas_cursor->show();
3434 verbose_cursor_visible = true;
3438 Editor::hide_verbose_canvas_cursor ()
3440 verbose_canvas_cursor->hide();
3441 verbose_cursor_visible = false;
3445 Editor::clamp_verbose_cursor_x (double x)
3450 x = min (_canvas_width - 200.0, x);
3456 Editor::clamp_verbose_cursor_y (double y)
3458 if (y < canvas_timebars_vsize) {
3459 y = canvas_timebars_vsize;
3461 y = min (_canvas_height - 50, y);
3467 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3469 verbose_canvas_cursor->property_text() = txt.c_str();
3470 /* don't get too close to the edge */
3471 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3472 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3476 Editor::set_verbose_canvas_cursor_text (const string & txt)
3478 verbose_canvas_cursor->property_text() = txt.c_str();
3482 Editor::set_edit_mode (EditMode m)
3484 Config->set_edit_mode (m);
3488 Editor::cycle_edit_mode ()
3490 switch (Config->get_edit_mode()) {
3492 if (Profile->get_sae()) {
3493 Config->set_edit_mode (Lock);
3495 Config->set_edit_mode (Splice);
3499 Config->set_edit_mode (Lock);
3502 Config->set_edit_mode (Slide);
3508 Editor::edit_mode_selection_done ()
3514 string choice = edit_mode_selector.get_active_text();
3515 EditMode mode = Slide;
3517 if (choice == _("Splice Edit")) {
3519 } else if (choice == _("Slide Edit")) {
3521 } else if (choice == _("Lock Edit")) {
3525 Config->set_edit_mode (mode);
3529 Editor::snap_type_selection_done ()
3531 string choice = snap_type_selector.get_active_text();
3532 SnapType snaptype = SnapToBeat;
3534 if (choice == _("Beats/3")) {
3535 snaptype = SnapToAThirdBeat;
3536 } else if (choice == _("Beats/4")) {
3537 snaptype = SnapToAQuarterBeat;
3538 } else if (choice == _("Beats/8")) {
3539 snaptype = SnapToAEighthBeat;
3540 } else if (choice == _("Beats/16")) {
3541 snaptype = SnapToASixteenthBeat;
3542 } else if (choice == _("Beats/32")) {
3543 snaptype = SnapToAThirtysecondBeat;
3544 } else if (choice == _("Beats")) {
3545 snaptype = SnapToBeat;
3546 } else if (choice == _("Bars")) {
3547 snaptype = SnapToBar;
3548 } else if (choice == _("Marks")) {
3549 snaptype = SnapToMark;
3550 } else if (choice == _("Region starts")) {
3551 snaptype = SnapToRegionStart;
3552 } else if (choice == _("Region ends")) {
3553 snaptype = SnapToRegionEnd;
3554 } else if (choice == _("Region bounds")) {
3555 snaptype = SnapToRegionBoundary;
3556 } else if (choice == _("Region syncs")) {
3557 snaptype = SnapToRegionSync;
3558 } else if (choice == _("CD Frames")) {
3559 snaptype = SnapToCDFrame;
3560 } else if (choice == _("SMPTE Frames")) {
3561 snaptype = SnapToSMPTEFrame;
3562 } else if (choice == _("SMPTE Seconds")) {
3563 snaptype = SnapToSMPTESeconds;
3564 } else if (choice == _("SMPTE Minutes")) {
3565 snaptype = SnapToSMPTEMinutes;
3566 } else if (choice == _("Seconds")) {
3567 snaptype = SnapToSeconds;
3568 } else if (choice == _("Minutes")) {
3569 snaptype = SnapToMinutes;
3572 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3574 ract->set_active ();
3579 Editor::snap_mode_selection_done ()
3581 string choice = snap_mode_selector.get_active_text();
3582 SnapMode mode = SnapNormal;
3584 if (choice == _("No Grid")) {
3586 } else if (choice == _("Grid")) {
3588 } else if (choice == _("Magnetic")) {
3589 mode = SnapMagnetic;
3592 RefPtr<RadioAction> ract = snap_mode_action (mode);
3595 ract->set_active (true);
3600 Editor::cycle_edit_point (bool with_marker)
3602 switch (_edit_point) {
3604 set_edit_point_preference (EditAtPlayhead);
3606 case EditAtPlayhead:
3608 set_edit_point_preference (EditAtSelectedMarker);
3610 set_edit_point_preference (EditAtMouse);
3613 case EditAtSelectedMarker:
3614 set_edit_point_preference (EditAtMouse);
3620 Editor::edit_point_selection_done ()
3622 string choice = edit_point_selector.get_active_text();
3623 EditPoint ep = EditAtSelectedMarker;
3625 if (choice == _("Marker")) {
3626 set_edit_point_preference (EditAtSelectedMarker);
3627 } else if (choice == _("Playhead")) {
3628 set_edit_point_preference (EditAtPlayhead);
3630 set_edit_point_preference (EditAtMouse);
3633 RefPtr<RadioAction> ract = edit_point_action (ep);
3636 ract->set_active (true);
3641 Editor::zoom_focus_selection_done ()
3643 string choice = zoom_focus_selector.get_active_text();
3644 ZoomFocus focus_type = ZoomFocusLeft;
3646 if (choice == _("Left")) {
3647 focus_type = ZoomFocusLeft;
3648 } else if (choice == _("Right")) {
3649 focus_type = ZoomFocusRight;
3650 } else if (choice == _("Center")) {
3651 focus_type = ZoomFocusCenter;
3652 } else if (choice == _("Play")) {
3653 focus_type = ZoomFocusPlayhead;
3654 } else if (choice == _("Edit")) {
3655 focus_type = ZoomFocusEdit;
3656 } else if (choice == _("Active Mark")) {
3657 focus_type = ZoomFocusEdit;
3658 } else if (choice == _("Active Mark")) {
3659 focus_type = ZoomFocusEdit;
3661 focus_type = ZoomFocusMouse;
3664 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3667 ract->set_active ();
3672 Editor::edit_controls_button_release (GdkEventButton* ev)
3674 if (Keyboard::is_context_menu_event (ev)) {
3675 ARDOUR_UI::instance()->add_route (this);
3681 Editor::mouse_select_button_release (GdkEventButton* ev)
3683 /* this handles just right-clicks */
3685 if (ev->button != 3) {
3692 Editor::TrackViewList *
3693 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3695 TrackViewList::iterator i;
3697 TrackViewList* v = new TrackViewList;
3699 if (track == 0 && group == 0) {
3703 for (i = track_views.begin(); i != track_views.end (); ++i) {
3707 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->active_property (RouteGroup::Select))) {
3709 /* just the view for this track
3712 v->push_back (track);
3716 /* views for all tracks in the route group */
3718 for (i = track_views.begin(); i != track_views.end (); ++i) {
3720 if (group == 0 || ((*i)->route_group() == group && group->active_property (RouteGroup::Select))) {
3730 Editor::set_zoom_focus (ZoomFocus f)
3732 string str = zoom_focus_strings[(int)f];
3734 if (str != zoom_focus_selector.get_active_text()) {
3735 zoom_focus_selector.set_active_text (str);
3738 if (zoom_focus != f) {
3741 ZoomFocusChanged (); /* EMIT_SIGNAL */
3748 Editor::ensure_float (Window& win)
3750 win.set_transient_for (*this);
3754 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3756 /* recover or initialize pane positions. do this here rather than earlier because
3757 we don't want the positions to change the child allocations, which they seem to do.
3763 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3765 static int32_t done;
3768 width = default_width;
3769 height = default_height;
3771 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3773 if ((prop = geometry->property ("x_size")) == 0) {
3774 prop = geometry->property ("x-size");
3777 width = atoi (prop->value());
3779 if ((prop = geometry->property ("y_size")) == 0) {
3780 prop = geometry->property ("y-size");
3783 height = atoi (prop->value());
3787 if (which == static_cast<Paned*> (&edit_pane)) {
3793 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3794 /* initial allocation is 90% to canvas, 10% to notebook */
3795 pos = (int) floor (alloc.get_width() * 0.90f);
3796 snprintf (buf, sizeof(buf), "%d", pos);
3798 pos = atoi (prop->value());
3801 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3802 edit_pane.set_position (pos);
3803 pre_maximal_pane_position = pos;
3809 Editor::detach_tearoff (Box* b, Window* w)
3811 if (tools_tearoff->torn_off() &&
3812 mouse_mode_tearoff->torn_off()) {
3813 top_hbox.remove (toolbar_frame);
3818 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3820 if (toolbar_frame.get_parent() == 0) {
3821 top_hbox.pack_end (toolbar_frame);
3826 Editor::set_show_measures (bool yn)
3828 if (_show_measures != yn) {
3831 if ((_show_measures = yn) == true) {
3833 tempo_lines->show();
3841 Editor::toggle_follow_playhead ()
3843 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3845 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3846 set_follow_playhead (tact->get_active());
3851 Editor::set_follow_playhead (bool yn)
3853 if (_follow_playhead != yn) {
3854 if ((_follow_playhead = yn) == true) {
3856 update_current_screen ();
3863 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3865 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3867 xfade->set_active (!xfade->active());
3872 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3874 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3876 xfade->set_follow_overlap (!xfade->following_overlap());
3881 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3883 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3889 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3893 switch (cew.run ()) {
3894 case RESPONSE_ACCEPT:
3901 xfade->StateChanged (Change (~0));
3905 Editor::playlist_selector () const
3907 return *_playlist_selector;
3911 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3915 ret = nudge_clock.current_duration (pos);
3916 next = ret + 1; /* XXXX fix me */
3922 Editor::end_location_changed (Location* location)
3924 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3925 //reset_scrolling_region ();
3926 nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
3927 horizontal_adjustment.set_upper (session_span / frames_per_unit);
3931 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3933 ArdourDialog dialog ("playlist deletion dialog");
3934 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3935 "If left alone, no audio files used by it will be cleaned.\n"
3936 "If deleted, audio files used by it alone by will cleaned."),
3939 dialog.set_position (WIN_POS_CENTER);
3940 dialog.get_vbox()->pack_start (label);
3944 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3945 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3946 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3948 switch (dialog.run ()) {
3949 case RESPONSE_ACCEPT:
3950 /* delete the playlist */
3954 case RESPONSE_REJECT:
3955 /* keep the playlist */
3967 Editor::audio_region_selection_covers (nframes64_t where)
3969 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3970 if ((*a)->region()->covers (where)) {
3979 Editor::prepare_for_cleanup ()
3981 cut_buffer->clear_regions ();
3982 cut_buffer->clear_playlists ();
3984 selection->clear_regions ();
3985 selection->clear_playlists ();
3987 _regions->suspend_redisplay ();
3991 Editor::finish_cleanup ()
3993 _regions->resume_redisplay ();
3997 Editor::transport_loop_location()
4000 return session->locations()->auto_loop_location();
4007 Editor::transport_punch_location()
4010 return session->locations()->auto_punch_location();
4017 Editor::control_layout_scroll (GdkEventScroll* ev)
4019 switch (ev->direction) {
4021 scroll_tracks_up_line ();
4025 case GDK_SCROLL_DOWN:
4026 scroll_tracks_down_line ();
4030 /* no left/right handling yet */
4038 Editor::session_state_saved (string snap_name)
4040 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4042 _snapshots->redisplay ();
4046 Editor::maximise_editing_space ()
4048 mouse_mode_tearoff->set_visible (false);
4049 tools_tearoff->set_visible (false);
4051 pre_maximal_pane_position = edit_pane.get_position();
4052 pre_maximal_editor_width = this->get_width();
4054 if(post_maximal_pane_position == 0) {
4055 post_maximal_pane_position = edit_pane.get_width();
4060 if(post_maximal_editor_width) {
4061 edit_pane.set_position (post_maximal_pane_position -
4062 abs(post_maximal_editor_width - pre_maximal_editor_width));
4064 edit_pane.set_position (post_maximal_pane_position);
4069 Editor::restore_editing_space ()
4071 // user changed width of pane during fullscreen
4073 if(post_maximal_pane_position != edit_pane.get_position()) {
4074 post_maximal_pane_position = edit_pane.get_position();
4079 mouse_mode_tearoff->set_visible (true);
4080 tools_tearoff->set_visible (true);
4081 post_maximal_editor_width = this->get_width();
4083 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4087 * Make new playlists for a given track and also any others that belong
4088 * to the same active route group with the `edit' property.
4093 Editor::new_playlists (TimeAxisView* v)
4095 begin_reversible_command (_("new playlists"));
4096 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4097 session->get_playlists(playlists);
4098 mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, RouteGroup::Edit);
4099 commit_reversible_command ();
4103 * Use a copy of the current playlist for a given track and also any others that belong
4104 * to the same active route group with the `edit' property.
4109 Editor::copy_playlists (TimeAxisView* v)
4111 begin_reversible_command (_("copy playlists"));
4112 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4113 session->get_playlists(playlists);
4114 mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, RouteGroup::Edit);
4115 commit_reversible_command ();
4118 /** Clear the current playlist for a given track and also any others that belong
4119 * to the same active route group with the `edit' property.
4124 Editor::clear_playlists (TimeAxisView* v)
4126 begin_reversible_command (_("clear playlists"));
4127 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4128 session->get_playlists(playlists);
4129 mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v, RouteGroup::Edit);
4130 commit_reversible_command ();
4134 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4136 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4140 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4142 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4146 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t sz)
4148 atv.clear_playlist ();
4152 Editor::on_key_press_event (GdkEventKey* ev)
4154 return key_press_focus_accelerator_handler (*this, ev);
4158 Editor::on_key_release_event (GdkEventKey* ev)
4160 return Gtk::Window::on_key_release_event (ev);
4161 // return key_press_focus_accelerator_handler (*this, ev);
4165 Editor::reset_x_origin (nframes64_t frame)
4167 //cerr << "resetting x origin" << endl;
4168 queue_visual_change (frame);
4172 Editor::reset_y_origin (double y)
4174 queue_visual_change_y (y);
4178 Editor::reset_zoom (double fpu)
4180 queue_visual_change (fpu);
4184 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4186 //cerr << "Editor::reposition_and_zoom () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
4187 reset_x_origin (frame);
4190 if (!no_save_visual) {
4191 undo_visual_stack.push_back (current_visual_state(false));
4195 Editor::VisualState*
4196 Editor::current_visual_state (bool with_tracks)
4198 VisualState* vs = new VisualState;
4199 vs->y_position = vertical_adjustment.get_value();
4200 vs->frames_per_unit = frames_per_unit;
4201 vs->leftmost_frame = leftmost_frame;
4202 vs->zoom_focus = zoom_focus;
4203 vs->zoomed_to_region = zoomed_to_region;
4206 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4207 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4215 Editor::undo_visual_state ()
4217 if (undo_visual_stack.empty()) {
4221 VisualState* vs = undo_visual_stack.back();
4222 undo_visual_stack.pop_back();
4223 use_visual_state (*vs);
4224 redo_visual_stack.push_back (vs);
4228 Editor::redo_visual_state ()
4230 if (redo_visual_stack.empty()) {
4234 VisualState* vs = redo_visual_stack.back();
4235 redo_visual_stack.pop_back();
4236 use_visual_state (*vs);
4237 undo_visual_stack.push_back (vs);
4241 Editor::swap_visual_state ()
4243 if (undo_visual_stack.empty()) {
4244 redo_visual_state ();
4246 undo_visual_state ();
4251 Editor::use_visual_state (VisualState& vs)
4253 no_save_visual = true;
4255 _routes->suspend_redisplay ();
4257 vertical_adjustment.set_value (vs.y_position);
4259 set_zoom_focus (vs.zoom_focus);
4260 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4261 zoomed_to_region = vs.zoomed_to_region;
4263 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4264 TrackViewList::iterator t;
4266 /* check if the track still exists - it could have been deleted */
4268 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4269 (*t)->set_state (*(i->second));
4274 if (!vs.track_states.empty()) {
4275 _routes->update_visibility ();
4278 _routes->resume_redisplay ();
4280 no_save_visual = false;
4284 Editor::set_frames_per_unit (double fpu)
4286 /* this is the core function that controls the zoom level of the canvas. it is called
4287 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4290 if (fpu == frames_per_unit) {
4299 /* don't allow zooms that fit more than the maximum number
4300 of frames into an 800 pixel wide space.
4303 if (max_frames / fpu < 800.0) {
4308 tempo_lines->tempo_map_changed();
4310 frames_per_unit = fpu;
4315 Editor::post_zoom ()
4317 nframes64_t cef = 0;
4319 // convert fpu to frame count
4321 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4323 if (frames_per_unit != zoom_range_clock.current_duration()) {
4324 zoom_range_clock.set (frames);
4327 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4328 if (!selection->tracks.empty()) {
4329 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4330 (*i)->reshow_selection (selection->time);
4333 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4334 (*i)->reshow_selection (selection->time);
4339 leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4341 ZoomChanged (); /* EMIT_SIGNAL */
4343 reset_hscrollbar_stepping ();
4346 cef = session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
4348 horizontal_adjustment.set_upper (cef / frames_per_unit);
4350 //reset_scrolling_region ();
4352 if (playhead_cursor) {
4353 playhead_cursor->set_position (playhead_cursor->current_frame);
4356 refresh_location_display();
4357 _summary->set_overlays_dirty ();
4363 Editor::queue_visual_change (nframes64_t where)
4365 pending_visual_change.add (VisualChange::TimeOrigin);
4367 /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
4371 if (where > session->current_end_frame()) {
4372 horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
4375 pending_visual_change.time_origin = where;
4377 ensure_visual_change_idle_handler ();
4381 Editor::queue_visual_change (double fpu)
4383 pending_visual_change.add (VisualChange::ZoomLevel);
4384 pending_visual_change.frames_per_unit = fpu;
4386 ensure_visual_change_idle_handler ();
4391 Editor::queue_visual_change_y (double y)
4393 pending_visual_change.add (VisualChange::YOrigin);
4394 pending_visual_change.y_origin = y;
4396 ensure_visual_change_idle_handler ();
4400 Editor::ensure_visual_change_idle_handler ()
4402 if (pending_visual_change.idle_handler_id < 0) {
4403 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4408 Editor::_idle_visual_changer (void* arg)
4410 return static_cast<Editor*>(arg)->idle_visual_changer ();
4414 Editor::idle_visual_changer ()
4416 VisualChange::Type p = pending_visual_change.pending;
4417 pending_visual_change.pending = (VisualChange::Type) 0;
4419 #ifdef FIX_THIS_FOR_V3
4420 double last_time_origin = horizontal_adjustment.get_value();
4423 if (p & VisualChange::ZoomLevel) {
4424 set_frames_per_unit (pending_visual_change.frames_per_unit);
4426 compute_fixed_ruler_scale ();
4427 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4428 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4429 update_tempo_based_rulers ();
4431 if (p & VisualChange::TimeOrigin) {
4432 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4434 if (p & VisualChange::YOrigin) {
4435 vertical_adjustment.set_value (pending_visual_change.y_origin);
4438 nframes64_t csf=0, cef=0;
4439 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4442 csf = session->current_start_frame();
4443 cef = session->current_end_frame();
4446 /* if we seek beyond the current end of the canvas, move the end */
4448 #ifdef FIX_THIS_FOR_V3
4449 if (last_time_origin == horizontal_adjustment.get_value() ) {
4450 /* changed signal not emitted */
4451 update_fixed_rulers ();
4452 redisplay_tempo (true);
4456 if (current_time_origin != pending_visual_change.time_origin) {
4457 cef += current_page_frames() / 10; // Add a little extra so we can see the end marker
4458 horizontal_adjustment.set_upper (cef / frames_per_unit);
4459 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4461 update_fixed_rulers();
4462 redisplay_tempo (true);
4465 _summary->set_overlays_dirty ();
4467 //cerr << "Editor::idle_visual_changer () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
4468 pending_visual_change.idle_handler_id = -1;
4469 return 0; /* this is always a one-shot call */
4472 struct EditorOrderTimeAxisSorter {
4473 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4474 return a->order () < b->order ();
4479 Editor::sort_track_selection (TrackSelection* sel)
4481 EditorOrderTimeAxisSorter cmp;
4486 selection->tracks.sort (cmp);
4491 Editor::get_preferred_edit_position (bool ignore_playhead)
4494 nframes64_t where = 0;
4495 EditPoint ep = _edit_point;
4497 if (entered_marker) {
4498 return entered_marker->position();
4501 if (ignore_playhead && ep == EditAtPlayhead) {
4502 ep = EditAtSelectedMarker;
4506 case EditAtPlayhead:
4507 where = session->audible_frame();
4510 case EditAtSelectedMarker:
4511 if (!selection->markers.empty()) {
4513 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4516 where = loc->start();
4527 if (!mouse_frame (where, ignored)) {
4528 /* XXX not right but what can we do ? */
4539 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4541 if (!session) return;
4543 begin_reversible_command (cmd);
4547 if ((tll = transport_loop_location()) == 0) {
4548 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4549 XMLNode &before = session->locations()->get_state();
4550 session->locations()->add (loc, true);
4551 session->set_auto_loop_location (loc);
4552 XMLNode &after = session->locations()->get_state();
4553 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4555 XMLNode &before = tll->get_state();
4556 tll->set_hidden (false, this);
4557 tll->set (start, end);
4558 XMLNode &after = tll->get_state();
4559 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4562 commit_reversible_command ();
4566 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4568 if (!session) return;
4570 begin_reversible_command (cmd);
4574 if ((tpl = transport_punch_location()) == 0) {
4575 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4576 XMLNode &before = session->locations()->get_state();
4577 session->locations()->add (loc, true);
4578 session->set_auto_loop_location (loc);
4579 XMLNode &after = session->locations()->get_state();
4580 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4583 XMLNode &before = tpl->get_state();
4584 tpl->set_hidden (false, this);
4585 tpl->set (start, end);
4586 XMLNode &after = tpl->get_state();
4587 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4590 commit_reversible_command ();
4594 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4596 const TrackSelection* tracks;
4599 tracks = &track_views;
4604 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4605 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4607 boost::shared_ptr<Diskstream> ds;
4608 boost::shared_ptr<Playlist> pl;
4610 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4612 Playlist::RegionList* regions = pl->regions_at (
4613 (nframes64_t) floor ( (double)where * ds->speed()));
4615 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4616 RegionView* rv = rtv->view()->find_view (*i);
4629 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4631 const TrackSelection* tracks;
4634 tracks = &track_views;
4639 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4640 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4642 boost::shared_ptr<Diskstream> ds;
4643 boost::shared_ptr<Playlist> pl;
4645 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4647 Playlist::RegionList* regions = pl->regions_touched (
4648 (nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4650 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4652 RegionView* rv = rtv->view()->find_view (*i);
4666 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4668 rs = selection->regions;
4670 if (allow_entered && entered_regionview) {
4671 rs.add (entered_regionview);
4674 TrackSelection tracks = selection->tracks;
4676 RegionSelection to_map = rs;
4678 for (RegionSelection::iterator i = to_map.begin (); i != to_map.end(); ++i) {
4680 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4681 if (g && g->active_property (RouteGroup::Edit)) {
4682 tracks.add (axis_views_from_routes (g->route_list()));
4685 nframes64_t const where = get_preferred_edit_position ();
4686 get_regions_at (rs, where, tracks);
4691 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4694 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4696 RouteTimeAxisView* tatv;
4698 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4700 boost::shared_ptr<Playlist> pl;
4701 vector<boost::shared_ptr<Region> > results;
4703 boost::shared_ptr<Diskstream> ds;
4705 if ((ds = tatv->get_diskstream()) == 0) {
4710 if ((pl = (ds->playlist())) != 0) {
4711 pl->get_region_list_equivalent_regions (region, results);
4714 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4715 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4716 regions.push_back (marv);
4725 Editor::show_rhythm_ferret ()
4727 if (rhythm_ferret == 0) {
4728 rhythm_ferret = new RhythmFerret(*this);
4731 rhythm_ferret->set_session (session);
4732 rhythm_ferret->show ();
4733 rhythm_ferret->present ();
4737 Editor::show_bundle_manager ()
4739 if (_bundle_manager == 0) {
4740 _bundle_manager = new BundleManager (*session);
4743 _bundle_manager->show ();
4747 Editor::show_global_port_matrix (ARDOUR::DataType t)
4749 if (_global_port_matrix[t] == 0) {
4750 _global_port_matrix[t] = new GlobalPortMatrixWindow (*session, t);
4753 _global_port_matrix[t]->show ();
4757 Editor::first_idle ()
4759 MessageDialog* dialog = 0;
4761 if (track_views.size() > 1) {
4762 dialog = new MessageDialog (*this,
4763 _("Please wait while Ardour loads visual data"),
4768 ARDOUR_UI::instance()->flush_pending ();
4771 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4775 // first idle adds route children (automation tracks), so we need to redisplay here
4776 _routes->redisplay ();
4784 _idle_resizer (gpointer arg)
4786 return ((Editor*)arg)->idle_resize ();
4790 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
4792 if (resize_idle_id < 0) {
4793 resize_idle_id = g_idle_add (_idle_resizer, this);
4794 _pending_resize_amount = 0;
4797 /* make a note of the smallest resulting height, so that we can clamp the
4798 lower limit at TimeAxisView::hSmall */
4800 int32_t min_resulting = INT32_MAX;
4802 _pending_resize_amount += h;
4803 _pending_resize_view = view;
4805 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
4807 if (selection->tracks.contains (_pending_resize_view)) {
4808 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4809 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
4813 if (min_resulting < 0) {
4818 if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
4819 _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
4823 /** Handle pending resizing of tracks */
4825 Editor::idle_resize ()
4827 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
4829 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
4830 selection->tracks.contains (_pending_resize_view)) {
4832 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4833 if (*i != _pending_resize_view) {
4834 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
4840 _group_tabs->set_dirty ();
4841 resize_idle_id = -1;
4849 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::located));
4851 _pending_locate_request = false;
4855 Editor::region_view_added (RegionView *)
4857 _summary->set_dirty ();
4861 Editor::streamview_height_changed ()
4863 _summary->set_dirty ();
4867 Editor::axis_views_from_routes (list<Route*> r) const
4871 for (list<Route*>::const_iterator i = r.begin(); i != r.end(); ++i) {
4872 TrackViewList::const_iterator j = track_views.begin ();
4873 while (j != track_views.end()) {
4874 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
4875 if (rtv && rtv->route().get() == *i) {
4887 Editor::handle_new_route (RouteList& routes)
4889 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_route), routes));
4891 RouteTimeAxisView *rtv;
4892 list<RouteTimeAxisView*> new_views;
4894 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
4895 boost::shared_ptr<Route> route = (*x);
4897 if (route->is_hidden()) {
4901 DataType dt = route->input()->default_type();
4903 if (dt == ARDOUR::DataType::AUDIO) {
4904 rtv = new AudioTimeAxisView (*this, *session, route, *track_canvas);
4905 } else if (dt == ARDOUR::DataType::MIDI) {
4906 rtv = new MidiTimeAxisView (*this, *session, route, *track_canvas);
4908 throw unknown_type();
4911 new_views.push_back (rtv);
4912 track_views.push_back (rtv);
4914 rtv->effective_gain_display ();
4916 rtv->view()->RegionViewAdded.connect (mem_fun (*this, &Editor::region_view_added));
4917 rtv->view()->HeightChanged.connect (mem_fun (*this, &Editor::streamview_height_changed));
4919 rtv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), rtv));
4922 _routes->routes_added (new_views);
4924 if (show_editor_mixer_when_tracks_arrive) {
4925 show_editor_mixer (true);
4928 editor_list_button.set_sensitive (true);
4930 _summary->set_dirty ();
4934 Editor::remove_route (TimeAxisView *tv)
4936 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
4938 TrackViewList::iterator i;
4939 boost::shared_ptr<Route> route;
4940 TimeAxisView* next_tv;
4942 if (tv == entered_track) {
4946 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
4948 i = track_views.erase (i);
4950 if (track_views.empty()) {
4952 } else if (i == track_views.end()) {
4953 next_tv = track_views.front();
4959 if (current_mixer_strip && current_mixer_strip->route() == route) {
4962 set_selected_mixer_strip (*next_tv);
4964 /* make the editor mixer strip go away setting the
4965 * button to inactive (which also unticks the menu option)
4968 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
4974 Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
4976 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
4978 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
4979 // this will hide the mixer strip
4980 set_selected_mixer_strip (tv);
4983 _routes->hide_track_in_display (tv);
4987 Editor::sync_track_view_list_and_routes ()
4989 track_views = TrackSelection (_routes->views ());
4991 _summary->set_dirty ();
4992 _group_tabs->set_dirty ();
4994 return false; // do not call again (until needed)
4998 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
5000 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5006 Editor::get_route_view_by_id (PBD::ID& id)
5008 RouteTimeAxisView* v;
5010 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5011 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5012 if(v->route()->id() == id) {
5022 Editor::fit_route_group (RouteGroup *g)
5024 TrackSelection ts = axis_views_from_routes (g->route_list ());
5029 Editor::consider_auditioning (boost::shared_ptr<Region> region)
5031 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
5034 session->cancel_audition ();
5038 if (session->is_auditioning()) {
5039 session->cancel_audition ();
5040 if (r == last_audition_region) {
5045 session->audition_region (r);
5046 last_audition_region = r;
5051 Editor::hide_a_region (boost::shared_ptr<Region> r)
5053 r->set_hidden (true);
5057 Editor::remove_a_region (boost::shared_ptr<Region> r)
5059 session->remove_region_from_region_list (r);
5063 Editor::audition_region_from_region_list ()
5065 _regions->selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
5069 Editor::hide_region_from_region_list ()
5071 _regions->selection_mapover (mem_fun (*this, &Editor::hide_a_region));