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"
109 #include "imageframe_socket_handler.h"
113 using namespace sigc;
114 using namespace ARDOUR;
117 using namespace Glib;
118 using namespace Gtkmm2ext;
119 using namespace Editing;
121 using PBD::internationalize;
124 const double Editor::timebar_height = 15.0;
126 #include "editor_xpms"
128 static const gchar *_snap_type_strings[] = {
150 static const gchar *_snap_mode_strings[] = {
157 static const gchar *_edit_point_strings[] = {
164 static const gchar *_zoom_focus_strings[] = {
174 #ifdef USE_RUBBERBAND
175 static const gchar *_rb_opt_strings[] = {
178 N_("Balanced multitimbral mixture"),
179 N_("Unpitched percussion with stable notes"),
180 N_("Crisp monophonic instrumental"),
181 N_("Unpitched solo percussion"),
186 /* Soundfile drag-n-drop */
188 Gdk::Cursor* Editor::cross_hair_cursor = 0;
189 Gdk::Cursor* Editor::selector_cursor = 0;
190 Gdk::Cursor* Editor::trimmer_cursor = 0;
191 Gdk::Cursor* Editor::grabber_cursor = 0;
192 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
193 Gdk::Cursor* Editor::zoom_cursor = 0;
194 Gdk::Cursor* Editor::time_fx_cursor = 0;
195 Gdk::Cursor* Editor::fader_cursor = 0;
196 Gdk::Cursor* Editor::speaker_cursor = 0;
197 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
198 Gdk::Cursor* Editor::midi_select_cursor = 0;
199 Gdk::Cursor* Editor::midi_resize_cursor = 0;
200 Gdk::Cursor* Editor::midi_erase_cursor = 0;
201 Gdk::Cursor* Editor::wait_cursor = 0;
202 Gdk::Cursor* Editor::timebar_cursor = 0;
203 Gdk::Cursor* Editor::transparent_cursor = 0;
206 show_me_the_size (Requisition* r, const char* what)
208 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
213 /* time display buttons */
215 minsec_label (_("Mins:Secs")),
216 bbt_label (_("Bars:Beats")),
217 smpte_label (_("Timecode")),
218 frame_label (_("Samples")),
219 tempo_label (_("Tempo")),
220 meter_label (_("Meter")),
221 mark_label (_("Location Markers")),
222 range_mark_label (_("Range Markers")),
223 transport_mark_label (_("Loop/Punch Ranges")),
224 cd_mark_label (_("CD Markers")),
225 edit_packer (4, 4, true),
227 /* the values here don't matter: layout widgets
228 reset them as needed.
231 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
232 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
234 /* tool bar related */
236 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
237 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
239 toolbar_selection_clock_table (2,3),
241 automation_mode_button (_("mode")),
242 global_automation_button (_("automation")),
244 midi_panic_button (_("Panic")),
245 midi_tools_tearoff (0),
248 image_socket_listener(0),
253 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
254 meters_running(false),
255 _pending_locate_request (false)
260 /* we are a singleton */
262 PublicEditor::_instance = this;
267 selection = new Selection (this);
268 cut_buffer = new Selection (this);
270 clicked_regionview = 0;
271 clicked_axisview = 0;
272 clicked_routeview = 0;
273 clicked_crossfadeview = 0;
274 clicked_control_point = 0;
275 last_update_frame = 0;
277 current_mixer_strip = 0;
278 current_bbt_points = 0;
281 snap_type_strings = I18N (_snap_type_strings);
282 snap_mode_strings = I18N (_snap_mode_strings);
283 zoom_focus_strings = I18N (_zoom_focus_strings);
284 edit_point_strings = I18N (_edit_point_strings);
285 #ifdef USE_RUBBERBAND
286 rb_opt_strings = I18N (_rb_opt_strings);
289 snap_threshold = 5.0;
290 bbt_beat_subdivision = 4;
293 last_autoscroll_x = 0;
294 last_autoscroll_y = 0;
295 autoscroll_active = false;
296 autoscroll_timeout_tag = -1;
297 interthread_progress_window = 0;
302 current_interthread_info = 0;
303 _show_measures = true;
304 _show_waveforms_recording = true;
305 show_gain_after_trim = false;
306 verbose_cursor_on = true;
307 route_removal = false;
308 show_automatic_regions_in_region_list = true;
309 last_item_entered = 0;
310 last_item_entered_n = 0;
312 region_list_sort_type = (Editing::RegionListSortType) 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;
318 region_list_menu = 0;
320 start_end_marker_menu = 0;
321 range_marker_menu = 0;
322 marker_menu_item = 0;
324 transport_marker_menu = 0;
325 new_transport_marker_menu = 0;
326 editor_mixer_strip_width = Wide;
327 show_editor_mixer_when_tracks_arrive = false;
328 region_edit_menu_split_multichannel_item = 0;
329 region_edit_menu_split_item = 0;
332 ignore_mouse_mode_toggle = false;
333 ignore_midi_edit_mode_toggle = false;
334 current_stepping_trackview = 0;
336 entered_regionview = 0;
338 clear_entered_track = false;
339 _new_regionviews_show_envelope = false;
342 button_release_can_deselect = true;
343 _dragging_playhead = false;
344 _dragging_edit_point = false;
345 _dragging_hscrollbar = false;
346 select_new_marker = false;
347 zoomed_to_region = false;
350 for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
351 _global_port_matrix[*i] = 0;
353 allow_vertical_scroll = false;
354 no_save_visual = false;
355 no_region_list_redisplay = false;
358 scrubbing_direction = 0;
362 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
363 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
364 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
365 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
366 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
368 set_midi_edit_mode (MidiEditPencil, true);
369 _edit_point = EditAtMouse;
370 set_mouse_mode (MouseObject, true);
372 frames_per_unit = 2048; /* too early to use reset_zoom () */
373 reset_hscrollbar_stepping ();
375 zoom_focus = ZoomFocusLeft;
376 set_zoom_focus (ZoomFocusLeft);
377 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
379 bbt_label.set_name ("EditorTimeButton");
380 bbt_label.set_size_request (-1, (int)timebar_height);
381 bbt_label.set_alignment (1.0, 0.5);
382 bbt_label.set_padding (5,0);
384 bbt_label.set_no_show_all();
385 minsec_label.set_name ("EditorTimeButton");
386 minsec_label.set_size_request (-1, (int)timebar_height);
387 minsec_label.set_alignment (1.0, 0.5);
388 minsec_label.set_padding (5,0);
389 minsec_label.hide ();
390 minsec_label.set_no_show_all();
391 smpte_label.set_name ("EditorTimeButton");
392 smpte_label.set_size_request (-1, (int)timebar_height);
393 smpte_label.set_alignment (1.0, 0.5);
394 smpte_label.set_padding (5,0);
396 smpte_label.set_no_show_all();
397 frame_label.set_name ("EditorTimeButton");
398 frame_label.set_size_request (-1, (int)timebar_height);
399 frame_label.set_alignment (1.0, 0.5);
400 frame_label.set_padding (5,0);
402 frame_label.set_no_show_all();
404 tempo_label.set_name ("EditorTimeButton");
405 tempo_label.set_size_request (-1, (int)timebar_height);
406 tempo_label.set_alignment (1.0, 0.5);
407 tempo_label.set_padding (5,0);
409 tempo_label.set_no_show_all();
410 meter_label.set_name ("EditorTimeButton");
411 meter_label.set_size_request (-1, (int)timebar_height);
412 meter_label.set_alignment (1.0, 0.5);
413 meter_label.set_padding (5,0);
415 meter_label.set_no_show_all();
416 mark_label.set_name ("EditorTimeButton");
417 mark_label.set_size_request (-1, (int)timebar_height);
418 mark_label.set_alignment (1.0, 0.5);
419 mark_label.set_padding (5,0);
421 mark_label.set_no_show_all();
422 cd_mark_label.set_name ("EditorTimeButton");
423 cd_mark_label.set_size_request (-1, (int)timebar_height);
424 cd_mark_label.set_alignment (1.0, 0.5);
425 cd_mark_label.set_padding (5,0);
426 cd_mark_label.hide();
427 cd_mark_label.set_no_show_all();
428 range_mark_label.set_name ("EditorTimeButton");
429 range_mark_label.set_size_request (-1, (int)timebar_height);
430 range_mark_label.set_alignment (1.0, 0.5);
431 range_mark_label.set_padding (5,0);
432 range_mark_label.hide();
433 range_mark_label.set_no_show_all();
434 transport_mark_label.set_name ("EditorTimeButton");
435 transport_mark_label.set_size_request (-1, (int)timebar_height);
436 transport_mark_label.set_alignment (1.0, 0.5);
437 transport_mark_label.set_padding (5,0);
438 transport_mark_label.hide();
439 transport_mark_label.set_no_show_all();
441 initialize_rulers ();
442 _summary = new EditorSummary (this);
443 initialize_canvas ();
445 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
446 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
447 editor_regions_selection_changed_connection = selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
448 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
449 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
451 edit_controls_vbox.set_spacing (0);
452 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
453 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
454 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
456 HBox* h = manage (new HBox);
457 _group_tabs = new EditorGroupTabs (this);
458 h->pack_start (*_group_tabs, PACK_SHRINK);
459 h->pack_start (edit_controls_vbox);
460 controls_layout.add (*h);
462 controls_layout.set_name ("EditControlsBase");
463 controls_layout.add_events (Gdk::SCROLL_MASK);
464 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
466 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
467 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
468 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
470 edit_vscrollbar.set_adjustment (vertical_adjustment);
471 edit_hscrollbar.set_adjustment (horizontal_adjustment);
473 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
474 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
475 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
477 edit_hscrollbar.set_name ("EditorHScrollbar");
481 setup_midi_toolbar ();
483 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
485 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
486 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
487 0.0, 1.0, 100.0, 1.0));
488 pad_line_1->property_color_rgba() = 0xFF0000FF;
492 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
493 time_canvas_vbox.set_size_request (-1, -1);
495 ruler_label_event_box.add (ruler_label_vbox);
496 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
497 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
499 time_button_event_box.add (time_button_vbox);
500 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
501 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
503 /* these enable us to have a dedicated window (for cursor setting, etc.)
504 for the canvas areas.
507 track_canvas_event_box.add (*track_canvas);
509 time_canvas_event_box.add (time_canvas_vbox);
510 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
512 edit_packer.set_col_spacings (0);
513 edit_packer.set_row_spacings (0);
514 edit_packer.set_homogeneous (false);
515 edit_packer.set_border_width (0);
516 edit_packer.set_name ("EditorWindow");
518 edit_packer.attach (zoom_vbox, 0, 1, 0, 2, SHRINK, FILL, 0, 0);
519 /* labels for the rulers */
520 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
521 /* labels for the marker "tracks" */
522 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
524 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
526 edit_packer.attach (controls_layout, 0, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
528 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
530 bottom_hbox.set_border_width (2);
531 bottom_hbox.set_spacing (3);
533 _route_groups = new EditorRouteGroups (this);
534 _routes = new EditorRoutes (this);
536 region_list_display.set_size_request (100, -1);
537 region_list_display.set_name ("RegionListDisplay");
538 /* Try to prevent single mouse presses from initiating edits.
539 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
541 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
543 region_list_model = TreeStore::create (region_list_columns);
544 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
545 region_list_model->set_sort_column (0, SORT_ASCENDING);
547 region_list_display.set_model (region_list_model);
548 region_list_display.append_column (_("Regions"), region_list_columns.name);
549 region_list_display.append_column (_("Start"), region_list_columns.start);
550 region_list_display.append_column (_("End"), region_list_columns.end);
551 region_list_display.append_column (_("Length"), region_list_columns.length);
552 region_list_display.append_column (_("Sync"), region_list_columns.sync);
553 region_list_display.append_column (_("Fade In"), region_list_columns.fadein);
554 region_list_display.append_column (_("Fade Out"), region_list_columns.fadeout);
555 region_list_display.append_column (_("L"), region_list_columns.locked);
556 region_list_display.append_column (_("G"), region_list_columns.glued);
557 region_list_display.append_column (_("M"), region_list_columns.muted);
558 region_list_display.append_column (_("O"), region_list_columns.opaque);
559 region_list_display.append_column (_("Used"), region_list_columns.used);
560 region_list_display.append_column (_("Path"), region_list_columns.path);
561 region_list_display.set_headers_visible (true);
562 //region_list_display.set_grid_lines (TREE_VIEW_GRID_LINES_BOTH);
564 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
565 region_name_cell->property_editable() = true;
566 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
568 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
570 TreeViewColumn* tv_col = region_list_display.get_column(0);
571 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
572 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
573 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
575 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
576 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
578 /* setup DnD handling */
580 list<TargetEntry> region_list_target_table;
582 region_list_target_table.push_back (TargetEntry ("text/plain"));
583 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
584 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
586 region_list_display.add_drop_targets (region_list_target_table);
587 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
589 region_list_scroller.add (region_list_display);
590 region_list_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
592 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
593 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
594 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
595 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
596 region_list_change_connection = region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
597 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
599 //ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::redisplay_regions));
600 ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::update_all_region_rows));
601 ARDOUR::Region::RegionPropertyChanged.connect (mem_fun(*this, &Editor::update_region_row));
603 named_selection_scroller.add (named_selection_display);
604 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
606 named_selection_model = TreeStore::create (named_selection_columns);
607 named_selection_display.set_model (named_selection_model);
608 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
609 named_selection_display.set_headers_visible (false);
610 named_selection_display.set_size_request (100, -1);
611 named_selection_display.set_name ("NamedSelectionDisplay");
613 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
614 named_selection_display.set_size_request (100, -1);
615 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
616 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
617 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
621 snapshot_display_model = ListStore::create (snapshot_display_columns);
622 snapshot_display.set_model (snapshot_display_model);
623 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
624 snapshot_display.set_name ("SnapshotDisplay");
625 snapshot_display.set_size_request (75, -1);
626 snapshot_display.set_headers_visible (false);
627 snapshot_display.set_reorderable (false);
628 snapshot_display_scroller.add (snapshot_display);
629 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
631 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
632 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
636 nlabel = manage (new Label (_("Regions")));
637 nlabel->set_angle (-90);
638 the_notebook.append_page (region_list_scroller, *nlabel);
639 nlabel = manage (new Label (_("Tracks/Busses")));
640 nlabel->set_angle (-90);
641 the_notebook.append_page (_routes->widget (), *nlabel);
642 nlabel = manage (new Label (_("Snapshots")));
643 nlabel->set_angle (-90);
644 the_notebook.append_page (snapshot_display_scroller, *nlabel);
645 nlabel = manage (new Label (_("Route Groups")));
646 nlabel->set_angle (-90);
647 the_notebook.append_page (_route_groups->widget (), *nlabel);
649 if (!Profile->get_sae()) {
650 nlabel = manage (new Label (_("Chunks")));
651 nlabel->set_angle (-90);
652 the_notebook.append_page (named_selection_scroller, *nlabel);
655 the_notebook.set_show_tabs (true);
656 the_notebook.set_scrollable (true);
657 the_notebook.popup_enable ();
658 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
659 the_notebook.show_all ();
661 post_maximal_editor_width = 0;
662 post_maximal_pane_position = 0;
664 VPaned *editor_summary_pane = manage(new VPaned());
665 editor_summary_pane->pack1(edit_packer);
666 editor_summary_pane->pack2(*_summary);
668 edit_pane.pack1 (*editor_summary_pane, true, true);
669 edit_pane.pack2 (the_notebook, false, true);
671 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
673 top_hbox.pack_start (toolbar_frame, false, true);
674 top_hbox.pack_start (midi_toolbar_frame, false, true);
676 HBox *hbox = manage (new HBox);
677 hbox->pack_start (edit_pane, true, true);
679 global_vpacker.pack_start (top_hbox, false, false);
680 global_vpacker.pack_start (*hbox, true, true);
682 global_hpacker.pack_start (global_vpacker, true, true);
684 set_name ("EditorWindow");
685 add_accel_group (ActionManager::ui_manager->get_accel_group());
687 status_bar_hpacker.show ();
689 vpacker.pack_end (status_bar_hpacker, false, false);
690 vpacker.pack_end (global_hpacker, true, true);
692 /* register actions now so that set_state() can find them and set toggles/checks etc */
696 snap_type = SnapToBeat;
697 set_snap_to (snap_type);
699 set_snap_mode (snap_mode);
700 set_edit_point_preference (EditAtMouse, true);
702 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
705 _playlist_selector = new PlaylistSelector();
706 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
708 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
712 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
713 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
715 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
716 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
718 nudge_forward_button.set_name ("TransportButton");
719 nudge_backward_button.set_name ("TransportButton");
721 fade_context_menu.set_name ("ArdourContextMenu");
723 /* icons, titles, WM stuff */
725 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
726 Glib::RefPtr<Gdk::Pixbuf> icon;
728 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
729 window_icons.push_back (icon);
731 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
732 window_icons.push_back (icon);
734 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
735 window_icons.push_back (icon);
737 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
738 window_icons.push_back (icon);
740 if (!window_icons.empty()) {
741 set_icon_list (window_icons);
742 set_default_icon_list (window_icons);
745 WindowTitle title(Glib::get_application_name());
746 title += _("Editor");
747 set_title (title.get_string());
748 set_wmclass (X_("ardour_editor"), "Ardour");
751 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
753 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
754 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
756 /* allow external control surfaces/protocols to do various things */
758 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
759 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
760 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
761 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
762 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
764 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
766 _last_normalization_value = 0;
775 if(image_socket_listener) {
776 if(image_socket_listener->is_connected())
778 image_socket_listener->close_connection() ;
781 delete image_socket_listener ;
782 image_socket_listener = 0 ;
787 delete _route_groups;
793 Editor::add_toplevel_controls (Container& cont)
795 vpacker.pack_start (cont, false, false);
800 Editor::catch_vanishing_regionview (RegionView *rv)
802 /* note: the selection will take care of the vanishing
803 audioregionview by itself.
806 if (_drag && rv->get_canvas_group() == _drag->item() && !_drag->ending()) {
812 if (clicked_regionview == rv) {
813 clicked_regionview = 0;
816 if (entered_regionview == rv) {
817 set_entered_regionview (0);
822 Editor::set_entered_regionview (RegionView* rv)
824 if (rv == entered_regionview) {
828 if (entered_regionview) {
829 entered_regionview->exited ();
832 if ((entered_regionview = rv) != 0) {
833 entered_regionview->entered ();
838 Editor::set_entered_track (TimeAxisView* tav)
841 entered_track->exited ();
844 if ((entered_track = tav) != 0) {
845 entered_track->entered ();
850 Editor::show_window ()
852 if (! is_visible ()) {
855 /* re-hide editor list if necessary */
856 editor_list_button_toggled ();
858 /* re-hide summary widget if necessary */
859 parameter_changed ("show-summary");
861 parameter_changed ("show-edit-group-tabs");
863 /* now reset all audio_time_axis heights, because widgets might need
869 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
870 tv = (static_cast<TimeAxisView*>(*i));
879 Editor::instant_save ()
881 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
886 session->add_instant_xml(get_state());
888 Config->add_instant_xml(get_state());
893 Editor::edit_point_clock_changed()
895 if (_dragging_edit_point) {
899 if (selection->markers.empty()) {
904 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
910 loc->move_to (edit_point_clock.current_time());
914 Editor::zoom_adjustment_changed ()
920 double fpu = zoom_range_clock.current_duration() / _canvas_width;
924 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
925 } else if (fpu > session->current_end_frame() / _canvas_width) {
926 fpu = session->current_end_frame() / _canvas_width;
927 zoom_range_clock.set ((nframes64_t) floor (fpu * _canvas_width));
934 Editor::control_scroll (float fraction)
936 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
942 double step = fraction * current_page_frames();
945 _control_scroll_target is an optional<T>
947 it acts like a pointer to an nframes64_t, with
948 a operator conversion to boolean to check
949 that it has a value could possibly use
950 playhead_cursor->current_frame to store the
951 value and a boolean in the class to know
952 when it's out of date
955 if (!_control_scroll_target) {
956 _control_scroll_target = session->transport_frame();
957 _dragging_playhead = true;
960 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
961 *_control_scroll_target = 0;
962 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
963 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
965 *_control_scroll_target += (nframes64_t) floor (step);
968 /* move visuals, we'll catch up with it later */
970 playhead_cursor->set_position (*_control_scroll_target);
971 UpdateAllTransportClocks (*_control_scroll_target);
973 if (*_control_scroll_target > (current_page_frames() / 2)) {
974 /* try to center PH in window */
975 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
981 Now we do a timeout to actually bring the session to the right place
982 according to the playhead. This is to avoid reading disk buffers on every
983 call to control_scroll, which is driven by ScrollTimeline and therefore
984 probably by a control surface wheel which can generate lots of events.
986 /* cancel the existing timeout */
988 control_scroll_connection.disconnect ();
990 /* add the next timeout */
992 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
996 Editor::deferred_control_scroll (nframes64_t target)
998 session->request_locate (*_control_scroll_target, session->transport_rolling());
999 // reset for next stream
1000 _control_scroll_target = boost::none;
1001 _dragging_playhead = false;
1006 Editor::access_action (std::string action_group, std::string action_item)
1012 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
1015 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1025 Editor::on_realize ()
1027 Window::on_realize ();
1032 Editor::start_scrolling ()
1034 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1035 (mem_fun(*this, &Editor::update_current_screen));
1040 Editor::stop_scrolling ()
1042 scroll_connection.disconnect ();
1046 Editor::map_position_change (nframes64_t frame)
1048 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1050 if (session == 0 || !_follow_playhead) {
1054 center_screen (frame);
1055 playhead_cursor->set_position (frame);
1059 Editor::center_screen (nframes64_t frame)
1061 double page = _canvas_width * frames_per_unit;
1063 /* if we're off the page, then scroll.
1066 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1067 center_screen_internal (frame, page);
1072 Editor::center_screen_internal (nframes64_t frame, float page)
1077 frame -= (nframes64_t) page;
1082 reset_x_origin (frame);
1086 Editor::handle_new_duration ()
1092 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1093 nframes64_t new_end = session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1095 horizontal_adjustment.set_upper (new_end / frames_per_unit);
1096 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1098 if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
1099 horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
1101 //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
1105 Editor::update_title_s (const string & snap_name)
1107 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1113 Editor::update_title ()
1115 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1118 bool dirty = session->dirty();
1120 string session_name;
1122 if (session->snap_name() != session->name()) {
1123 session_name = session->snap_name();
1125 session_name = session->name();
1129 session_name = "*" + session_name;
1132 WindowTitle title(session_name);
1133 title += Glib::get_application_name();
1134 set_title (title.get_string());
1139 Editor::connect_to_session (Session *t)
1143 compute_fixed_ruler_scale ();
1145 /* there are never any selected regions at startup */
1147 sensitize_the_right_region_actions (false);
1149 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1152 /* catch up with the playhead */
1154 session->request_locate (playhead_cursor->current_frame);
1158 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1159 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1161 /* These signals can all be emitted by a non-GUI thread. Therefore the
1162 handlers for them must not attempt to directly interact with the GUI,
1163 but use Gtkmm2ext::UI::instance()->call_slot();
1166 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1167 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1168 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1169 session_connections.push_back (session->RegionsAdded.connect (mem_fun(*this, &Editor::handle_new_regions)));
1170 session_connections.push_back (session->RegionRemoved.connect (mem_fun(*this, &Editor::handle_region_removed)));
1171 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1172 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1173 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1174 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1175 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1176 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1177 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1179 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1181 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1183 session_connections.push_back (session->Located.connect (mem_fun (*this, &Editor::located)));
1184 session_connections.push_back (session->config.ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed)));
1186 _route_groups->connect_to_session (session);
1188 edit_point_clock.set_mode(AudioClock::BBT);
1189 edit_point_clock.set_session (session);
1190 zoom_range_clock.set_session (session);
1191 _playlist_selector->set_session (session);
1192 nudge_clock.set_session (session);
1193 if (Profile->get_sae()) {
1198 nframes_t pos = session->tempo_map().bbt_duration_at (0, bbt, 1);
1199 nudge_clock.set_mode(AudioClock::BBT);
1200 nudge_clock.set (pos, true, 0, AudioClock::BBT);
1203 nudge_clock.set (session->frame_rate() * 5, true, 0, AudioClock::SMPTE); // default of 5 seconds
1206 playhead_cursor->canvas_item.show ();
1208 if (rhythm_ferret) {
1209 rhythm_ferret->set_session (session);
1212 if (analysis_window != 0)
1213 analysis_window->set_session (session);
1215 Location* loc = session->locations()->auto_loop_location();
1217 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1218 if (loc->start() == loc->end()) {
1219 loc->set_end (loc->start() + 1);
1221 session->locations()->add (loc, false);
1222 session->set_auto_loop_location (loc);
1225 loc->set_name (_("Loop"));
1228 loc = session->locations()->auto_punch_location();
1230 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1231 if (loc->start() == loc->end()) {
1232 loc->set_end (loc->start() + 1);
1234 session->locations()->add (loc, false);
1235 session->set_auto_punch_location (loc);
1238 loc->set_name (_("Punch"));
1241 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1242 session->config.map_parameters (mem_fun (*this, &Editor::parameter_changed));
1244 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1246 refresh_location_display ();
1247 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1248 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1249 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1250 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1251 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1254 sfbrowser->set_session (session);
1257 handle_new_duration ();
1259 redisplay_regions ();
1260 redisplay_named_selections ();
1261 redisplay_snapshots ();
1263 restore_ruler_visibility ();
1264 //tempo_map_changed (Change (0));
1265 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1267 _routes->initial_display ();
1269 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1270 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1275 switch (snap_type) {
1276 case SnapToRegionStart:
1277 case SnapToRegionEnd:
1278 case SnapToRegionSync:
1279 case SnapToRegionBoundary:
1280 build_region_boundary_cache ();
1287 /* register for undo history */
1288 session->register_with_memento_command_factory(_id, this);
1290 _summary->connect_to_session (session);
1291 _group_tabs->connect_to_session (session);
1297 Editor::build_cursors ()
1299 using namespace Gdk;
1301 Gdk::Color mbg ("#000000" ); /* Black */
1302 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1305 RefPtr<Bitmap> source, mask;
1306 source = Bitmap::create (mag_bits, mag_width, mag_height);
1307 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1308 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1311 Gdk::Color fbg ("#ffffff" );
1312 Gdk::Color ffg ("#000000" );
1315 RefPtr<Bitmap> source, mask;
1317 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1318 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1319 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1323 RefPtr<Bitmap> source, mask;
1324 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1325 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1326 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1330 RefPtr<Bitmap> bits;
1331 char pix[4] = { 0, 0, 0, 0 };
1332 bits = Bitmap::create (pix, 2, 2);
1334 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1338 RefPtr<Bitmap> bits;
1339 char pix[4] = { 0, 0, 0, 0 };
1340 bits = Bitmap::create (pix, 2, 2);
1342 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1346 grabber_cursor = new Gdk::Cursor (HAND2);
1349 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1350 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1353 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1354 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1355 selector_cursor = new Gdk::Cursor (XTERM);
1356 time_fx_cursor = new Gdk::Cursor (SIZING);
1357 wait_cursor = new Gdk::Cursor (WATCH);
1358 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1359 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1360 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1361 midi_resize_cursor = new Gdk::Cursor (SIZING);
1362 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1365 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1367 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1369 using namespace Menu_Helpers;
1370 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1373 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1377 MenuList& items (fade_context_menu.items());
1381 switch (item_type) {
1383 case FadeInHandleItem:
1384 if (arv->audio_region()->fade_in_active()) {
1385 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1387 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1390 items.push_back (SeparatorElem());
1392 if (Profile->get_sae()) {
1393 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1394 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1396 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1397 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1398 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1399 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1400 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1406 case FadeOutHandleItem:
1407 if (arv->audio_region()->fade_out_active()) {
1408 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1410 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1413 items.push_back (SeparatorElem());
1415 if (Profile->get_sae()) {
1416 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1417 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1419 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1420 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1421 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1422 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1423 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1429 fatal << _("programming error: ")
1430 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1435 fade_context_menu.popup (button, time);
1439 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1441 using namespace Menu_Helpers;
1442 Menu* (Editor::*build_menu_function)(nframes64_t);
1445 switch (item_type) {
1447 case RegionViewName:
1448 case RegionViewNameHighlight:
1449 if (with_selection) {
1450 build_menu_function = &Editor::build_track_selection_context_menu;
1452 build_menu_function = &Editor::build_track_region_context_menu;
1457 if (with_selection) {
1458 build_menu_function = &Editor::build_track_selection_context_menu;
1460 build_menu_function = &Editor::build_track_context_menu;
1464 case CrossfadeViewItem:
1465 build_menu_function = &Editor::build_track_crossfade_context_menu;
1469 if (clicked_routeview->get_diskstream()) {
1470 build_menu_function = &Editor::build_track_context_menu;
1472 build_menu_function = &Editor::build_track_bus_context_menu;
1477 /* probably shouldn't happen but if it does, we don't care */
1481 menu = (this->*build_menu_function)(frame);
1482 menu->set_name ("ArdourContextMenu");
1484 /* now handle specific situations */
1486 switch (item_type) {
1488 case RegionViewName:
1489 case RegionViewNameHighlight:
1490 if (!with_selection) {
1491 if (region_edit_menu_split_item) {
1492 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1493 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1495 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1499 if (region_edit_menu_split_multichannel_item) {
1500 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1501 // GTK2FIX find the action, change its sensitivity
1502 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1504 // GTK2FIX see above
1505 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1514 case CrossfadeViewItem:
1521 /* probably shouldn't happen but if it does, we don't care */
1525 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1527 /* Bounce to disk */
1529 using namespace Menu_Helpers;
1530 MenuList& edit_items = menu->items();
1532 edit_items.push_back (SeparatorElem());
1534 switch (clicked_routeview->audio_track()->freeze_state()) {
1535 case AudioTrack::NoFreeze:
1536 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1539 case AudioTrack::Frozen:
1540 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1543 case AudioTrack::UnFrozen:
1544 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1550 if (item_type == StreamItem && clicked_routeview) {
1551 clicked_routeview->build_underlay_menu(menu);
1554 menu->popup (button, time);
1558 Editor::build_track_context_menu (nframes64_t ignored)
1560 using namespace Menu_Helpers;
1562 MenuList& edit_items = track_context_menu.items();
1565 add_dstream_context_items (edit_items);
1566 return &track_context_menu;
1570 Editor::build_track_bus_context_menu (nframes64_t ignored)
1572 using namespace Menu_Helpers;
1574 MenuList& edit_items = track_context_menu.items();
1577 add_bus_context_items (edit_items);
1578 return &track_context_menu;
1582 Editor::build_track_region_context_menu (nframes64_t frame)
1584 using namespace Menu_Helpers;
1585 MenuList& edit_items = track_region_context_menu.items();
1588 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1591 boost::shared_ptr<Diskstream> ds;
1592 boost::shared_ptr<Playlist> pl;
1594 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1595 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1597 if (selection->regions.size() > 1) {
1598 // there's already a multiple selection: just add a
1599 // single region context menu that will act on all
1601 boost::shared_ptr<Region> dummy_region; // = NULL
1602 add_region_context_items (rtv->view(), dummy_region, edit_items);
1604 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1605 add_region_context_items (rtv->view(), (*i), edit_items);
1613 add_dstream_context_items (edit_items);
1615 return &track_region_context_menu;
1619 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1621 using namespace Menu_Helpers;
1622 MenuList& edit_items = track_crossfade_context_menu.items();
1623 edit_items.clear ();
1625 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1628 boost::shared_ptr<Diskstream> ds;
1629 boost::shared_ptr<Playlist> pl;
1630 boost::shared_ptr<AudioPlaylist> apl;
1632 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1634 Playlist::RegionList* regions = pl->regions_at (frame);
1635 AudioPlaylist::Crossfades xfades;
1637 apl->crossfades_at (frame, xfades);
1639 bool many = xfades.size() > 1;
1641 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1642 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1645 if (selection->regions.size() > 1) {
1646 // there's already a multiple selection: just add a
1647 // single region context menu that will act on all
1649 boost::shared_ptr<Region> dummy_region; // = NULL
1650 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1652 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1653 add_region_context_items (atv->audio_view(), (*i), edit_items);
1660 add_dstream_context_items (edit_items);
1662 return &track_crossfade_context_menu;
1666 Editor::analyze_region_selection()
1668 if (analysis_window == 0) {
1669 analysis_window = new AnalysisWindow();
1672 analysis_window->set_session(session);
1674 analysis_window->show_all();
1677 analysis_window->set_regionmode();
1678 analysis_window->analyze();
1680 analysis_window->present();
1684 Editor::analyze_range_selection()
1686 if (analysis_window == 0) {
1687 analysis_window = new AnalysisWindow();
1690 analysis_window->set_session(session);
1692 analysis_window->show_all();
1695 analysis_window->set_rangemode();
1696 analysis_window->analyze();
1698 analysis_window->present();
1702 Editor::build_track_selection_context_menu (nframes64_t ignored)
1704 using namespace Menu_Helpers;
1705 MenuList& edit_items = track_selection_context_menu.items();
1706 edit_items.clear ();
1708 add_selection_context_items (edit_items);
1709 // edit_items.push_back (SeparatorElem());
1710 // add_dstream_context_items (edit_items);
1712 return &track_selection_context_menu;
1715 /** Add context menu items relevant to crossfades.
1716 * @param edit_items List to add the items to.
1719 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1721 using namespace Menu_Helpers;
1722 Menu *xfade_menu = manage (new Menu);
1723 MenuList& items = xfade_menu->items();
1724 xfade_menu->set_name ("ArdourContextMenu");
1727 if (xfade->active()) {
1733 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1734 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1736 if (xfade->can_follow_overlap()) {
1738 if (xfade->following_overlap()) {
1739 str = _("Convert to short");
1741 str = _("Convert to full");
1744 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1748 str = xfade->out()->name();
1750 str += xfade->in()->name();
1752 str = _("Crossfade");
1755 edit_items.push_back (MenuElem (str, *xfade_menu));
1756 edit_items.push_back (SeparatorElem());
1760 Editor::xfade_edit_left_region ()
1762 if (clicked_crossfadeview) {
1763 clicked_crossfadeview->left_view.show_region_editor ();
1768 Editor::xfade_edit_right_region ()
1770 if (clicked_crossfadeview) {
1771 clicked_crossfadeview->right_view.show_region_editor ();
1775 /** Add an element to a menu, settings its sensitivity.
1776 * @param m Menu to add to.
1777 * @param e Element to add.
1778 * @param s true to make sensitive, false to make insensitive
1781 Editor::add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s) const
1785 m.back().set_sensitive (false);
1790 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1792 using namespace Menu_Helpers;
1793 Gtk::MenuItem* foo_item;
1794 Menu *region_menu = manage (new Menu);
1795 MenuList& items = region_menu->items();
1796 region_menu->set_name ("ArdourContextMenu");
1798 boost::shared_ptr<AudioRegion> ar;
1799 boost::shared_ptr<MidiRegion> mr;
1802 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1803 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1805 /* when this particular menu pops up, make the relevant region
1809 region_menu->signal_map_event().connect (
1810 bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1812 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1813 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1816 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1817 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1818 items.push_back (SeparatorElem());
1819 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1820 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1821 items.push_back (SeparatorElem());
1823 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1824 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1825 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1828 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1831 items.push_back (SeparatorElem());
1833 sigc::connection fooc;
1834 boost::shared_ptr<Region> region_to_check;
1837 region_to_check = region;
1839 region_to_check = selection->regions.front()->region();
1842 items.push_back (CheckMenuElem (_("Lock")));
1843 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1844 if (region_to_check->locked()) {
1845 region_lock_item->set_active();
1847 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1849 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1850 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1852 switch (region_to_check->positional_lock_style()) {
1853 case Region::MusicTime:
1854 bbt_glue_item->set_active (true);
1857 bbt_glue_item->set_active (false);
1861 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1863 items.push_back (CheckMenuElem (_("Mute")));
1864 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1865 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1866 if (region_to_check->muted()) {
1868 region_mute_item->set_active();
1872 if (!Profile->get_sae()) {
1873 items.push_back (CheckMenuElem (_("Opaque")));
1874 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1875 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1876 if (region_to_check->opaque()) {
1878 region_opaque_item->set_active();
1883 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1884 if (region_to_check->at_natural_position()) {
1885 items.back().set_sensitive (false);
1888 items.push_back (SeparatorElem());
1892 RegionView* rv = sv->find_view (ar);
1893 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1895 if (!Profile->get_sae()) {
1896 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1898 items.push_back (CheckMenuElem (_("Envelope Visible")));
1899 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1900 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1901 if (arv->envelope_visible()) {
1903 region_envelope_visible_item->set_active (true);
1907 items.push_back (CheckMenuElem (_("Envelope Active")));
1908 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1909 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1911 if (ar->envelope_active()) {
1913 region_envelope_active_item->set_active (true);
1917 items.push_back (SeparatorElem());
1920 if (ar->scale_amplitude() != 1.0f) {
1921 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1923 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1927 items.push_back (MenuElem (_("Quantize"), mem_fun(*this, &Editor::quantize_region)));
1928 items.push_back (SeparatorElem());
1931 items.push_back (MenuElem (_("Strip silence..."), mem_fun (*this, &Editor::strip_region_silence)));
1932 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1933 items.push_back (SeparatorElem());
1935 /* range related stuff */
1937 items.push_back (MenuElem (_("Add Single Range"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1938 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_locations_from_audio_region)));
1939 if (selection->regions.size() < 2) {
1940 items.back().set_sensitive (false);
1943 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
1944 items.push_back (SeparatorElem());
1948 Menu *nudge_menu = manage (new Menu());
1949 MenuList& nudge_items = nudge_menu->items();
1950 nudge_menu->set_name ("ArdourContextMenu");
1952 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1953 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1954 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1955 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1957 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1958 items.push_back (SeparatorElem());
1960 Menu *trim_menu = manage (new Menu);
1961 MenuList& trim_items = trim_menu->items();
1962 trim_menu->set_name ("ArdourContextMenu");
1964 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1965 foo_item = &trim_items.back();
1966 if (_edit_point == EditAtMouse) {
1967 foo_item->set_sensitive (false);
1969 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1970 foo_item = &trim_items.back();
1971 if (_edit_point == EditAtMouse) {
1972 foo_item->set_sensitive (false);
1974 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1975 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1977 items.push_back (MenuElem (_("Trim"), *trim_menu));
1978 items.push_back (SeparatorElem());
1980 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1981 region_edit_menu_split_item = &items.back();
1983 if (_edit_point == EditAtMouse) {
1984 region_edit_menu_split_item->set_sensitive (false);
1987 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1988 region_edit_menu_split_multichannel_item = &items.back();
1990 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1991 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1992 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1993 items.push_back (SeparatorElem());
1994 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
1996 /* OK, stick the region submenu at the top of the list, and then add
2000 /* we have to hack up the region name because "_" has a special
2001 meaning for menu titles.
2004 string::size_type pos = 0;
2005 string menu_item_name = (region) ? region->name() : _("Selected regions");
2007 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
2008 menu_item_name.replace (pos, 1, "__");
2012 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
2013 edit_items.push_back (SeparatorElem());
2016 /** Add context menu items relevant to selection ranges.
2017 * @param edit_items List to add the items to.
2020 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
2022 using namespace Menu_Helpers;
2024 edit_items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
2025 edit_items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
2027 edit_items.push_back (SeparatorElem());
2028 edit_items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
2030 edit_items.push_back (SeparatorElem());
2031 edit_items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
2032 edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
2034 edit_items.push_back (SeparatorElem());
2035 edit_items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
2036 edit_items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
2038 edit_items.push_back (SeparatorElem());
2039 edit_items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
2041 edit_items.push_back (SeparatorElem());
2042 edit_items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
2043 edit_items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
2045 edit_items.push_back (SeparatorElem());
2046 edit_items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
2047 edit_items.push_back (SeparatorElem());
2048 edit_items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
2049 edit_items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
2050 edit_items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
2051 edit_items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
2052 edit_items.push_back (SeparatorElem());
2053 edit_items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, false)));
2054 edit_items.push_back (MenuElem (_("Consolidate range with processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, true)));
2055 edit_items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, false)));
2056 edit_items.push_back (MenuElem (_("Bounce range to region list with processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, true)));
2057 edit_items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_range)));
2062 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2064 using namespace Menu_Helpers;
2068 Menu *play_menu = manage (new Menu);
2069 MenuList& play_items = play_menu->items();
2070 play_menu->set_name ("ArdourContextMenu");
2072 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2073 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2074 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2075 play_items.push_back (SeparatorElem());
2076 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2078 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2082 Menu *select_menu = manage (new Menu);
2083 MenuList& select_items = select_menu->items();
2084 select_menu->set_name ("ArdourContextMenu");
2086 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2087 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2088 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2089 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2090 select_items.push_back (SeparatorElem());
2091 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2092 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2093 select_items.push_back (SeparatorElem());
2094 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2095 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2096 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2097 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2098 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2099 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2100 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2102 select_items.push_back (SeparatorElem());
2104 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2108 Menu *cutnpaste_menu = manage (new Menu);
2109 MenuList& cutnpaste_items = cutnpaste_menu->items();
2110 cutnpaste_menu->set_name ("ArdourContextMenu");
2112 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2113 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2114 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2116 cutnpaste_items.push_back (SeparatorElem());
2118 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2119 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2121 cutnpaste_items.push_back (SeparatorElem());
2123 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2125 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2127 /* Adding new material */
2129 edit_items.push_back (SeparatorElem());
2130 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2131 edit_items.push_back (MenuElem (_("Insert Existing Media"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2135 Menu *nudge_menu = manage (new Menu());
2136 MenuList& nudge_items = nudge_menu->items();
2137 nudge_menu->set_name ("ArdourContextMenu");
2139 edit_items.push_back (SeparatorElem());
2140 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2141 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2142 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2143 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2145 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2149 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2151 using namespace Menu_Helpers;
2155 Menu *play_menu = manage (new Menu);
2156 MenuList& play_items = play_menu->items();
2157 play_menu->set_name ("ArdourContextMenu");
2159 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2160 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2161 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2165 Menu *select_menu = manage (new Menu);
2166 MenuList& select_items = select_menu->items();
2167 select_menu->set_name ("ArdourContextMenu");
2169 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2170 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2171 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2172 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2173 select_items.push_back (SeparatorElem());
2174 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2175 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2176 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2177 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2179 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2183 Menu *cutnpaste_menu = manage (new Menu);
2184 MenuList& cutnpaste_items = cutnpaste_menu->items();
2185 cutnpaste_menu->set_name ("ArdourContextMenu");
2187 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2188 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2189 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2191 Menu *nudge_menu = manage (new Menu());
2192 MenuList& nudge_items = nudge_menu->items();
2193 nudge_menu->set_name ("ArdourContextMenu");
2195 edit_items.push_back (SeparatorElem());
2196 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2197 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2198 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2199 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2201 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2205 Editor::set_snap_to (SnapType st)
2207 unsigned int snap_ind = (unsigned int)st;
2211 if (snap_ind > snap_type_strings.size() - 1) {
2213 snap_type = (SnapType)snap_ind;
2216 string str = snap_type_strings[snap_ind];
2218 if (str != snap_type_selector.get_active_text()) {
2219 snap_type_selector.set_active_text (str);
2224 switch (snap_type) {
2225 case SnapToAThirtysecondBeat:
2226 case SnapToASixteenthBeat:
2227 case SnapToAEighthBeat:
2228 case SnapToAQuarterBeat:
2229 case SnapToAThirdBeat:
2230 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
2231 update_tempo_based_rulers ();
2234 case SnapToRegionStart:
2235 case SnapToRegionEnd:
2236 case SnapToRegionSync:
2237 case SnapToRegionBoundary:
2238 build_region_boundary_cache ();
2248 Editor::set_snap_mode (SnapMode mode)
2251 string str = snap_mode_strings[(int)mode];
2253 if (str != snap_mode_selector.get_active_text ()) {
2254 snap_mode_selector.set_active_text (str);
2260 Editor::set_edit_point_preference (EditPoint ep, bool force)
2262 bool changed = (_edit_point != ep);
2265 string str = edit_point_strings[(int)ep];
2267 if (str != edit_point_selector.get_active_text ()) {
2268 edit_point_selector.set_active_text (str);
2271 set_canvas_cursor ();
2273 if (!force && !changed) {
2277 switch (zoom_focus) {
2278 case ZoomFocusMouse:
2279 case ZoomFocusPlayhead:
2281 switch (_edit_point) {
2283 set_zoom_focus (ZoomFocusMouse);
2285 case EditAtPlayhead:
2286 set_zoom_focus (ZoomFocusPlayhead);
2288 case EditAtSelectedMarker:
2289 set_zoom_focus (ZoomFocusEdit);
2297 const char* action=NULL;
2299 switch (_edit_point) {
2300 case EditAtPlayhead:
2301 action = "edit-at-playhead";
2303 case EditAtSelectedMarker:
2304 action = "edit-at-marker";
2307 action = "edit-at-mouse";
2311 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2313 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2317 bool in_track_canvas;
2319 if (!mouse_frame (foo, in_track_canvas)) {
2320 in_track_canvas = false;
2323 reset_canvas_action_sensitivity (in_track_canvas);
2329 Editor::set_state (const XMLNode& node)
2331 const XMLProperty* prop;
2333 int x, y, xoff, yoff;
2336 if ((prop = node.property ("id")) != 0) {
2337 _id = prop->value ();
2340 g.base_width = default_width;
2341 g.base_height = default_height;
2347 if ((geometry = find_named_node (node, "geometry")) != 0) {
2351 if ((prop = geometry->property("x_size")) == 0) {
2352 prop = geometry->property ("x-size");
2355 g.base_width = atoi(prop->value());
2357 if ((prop = geometry->property("y_size")) == 0) {
2358 prop = geometry->property ("y-size");
2361 g.base_height = atoi(prop->value());
2364 if ((prop = geometry->property ("x_pos")) == 0) {
2365 prop = geometry->property ("x-pos");
2368 x = atoi (prop->value());
2371 if ((prop = geometry->property ("y_pos")) == 0) {
2372 prop = geometry->property ("y-pos");
2375 y = atoi (prop->value());
2378 if ((prop = geometry->property ("x_off")) == 0) {
2379 prop = geometry->property ("x-off");
2382 xoff = atoi (prop->value());
2384 if ((prop = geometry->property ("y_off")) == 0) {
2385 prop = geometry->property ("y-off");
2388 yoff = atoi (prop->value());
2392 set_default_size (g.base_width, g.base_height);
2395 if (session && (prop = node.property ("playhead"))) {
2396 nframes64_t pos = atol (prop->value().c_str());
2397 playhead_cursor->set_position (pos);
2399 playhead_cursor->set_position (0);
2401 /* reset_x_origin() doesn't work right here, since the old
2402 position may be zero already, and it does nothing in such
2407 horizontal_adjustment.set_value (0);
2410 if ((prop = node.property ("mixer-width"))) {
2411 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2414 if ((prop = node.property ("zoom-focus"))) {
2415 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2418 if ((prop = node.property ("zoom"))) {
2419 reset_zoom (PBD::atof (prop->value()));
2422 if ((prop = node.property ("snap-to"))) {
2423 set_snap_to ((SnapType) atoi (prop->value()));
2426 if ((prop = node.property ("snap-mode"))) {
2427 set_snap_mode ((SnapMode) atoi (prop->value()));
2430 if ((prop = node.property ("edit-point"))) {
2431 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2434 if ((prop = node.property ("mouse-mode"))) {
2435 MouseMode m = str2mousemode(prop->value());
2436 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2437 set_mouse_mode (m, true);
2439 mouse_mode = MouseGain; /* lie, to force the mode switch */
2440 set_mouse_mode (MouseObject, true);
2443 if ((prop = node.property ("show-waveforms-recording"))) {
2444 bool yn = (prop->value() == "yes");
2445 _show_waveforms_recording = !yn;
2446 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2448 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2449 /* do it twice to force the change */
2450 tact->set_active (!yn);
2451 tact->set_active (yn);
2455 if ((prop = node.property ("show-measures"))) {
2456 bool yn = (prop->value() == "yes");
2457 _show_measures = !yn;
2458 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2460 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2461 /* do it twice to force the change */
2462 tact->set_active (!yn);
2463 tact->set_active (yn);
2467 if ((prop = node.property ("follow-playhead"))) {
2468 bool yn = (prop->value() == "yes");
2469 set_follow_playhead (yn);
2470 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2472 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2473 if (tact->get_active() != yn) {
2474 tact->set_active (yn);
2479 if ((prop = node.property ("region-list-sort-type"))) {
2480 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2481 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2484 if ((prop = node.property ("xfades-visible"))) {
2485 bool yn = (prop->value() == "yes");
2486 _xfade_visibility = !yn;
2487 // set_xfade_visibility (yn);
2490 if ((prop = node.property ("show-editor-mixer"))) {
2492 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2495 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2496 bool yn = (prop->value() == X_("yes"));
2498 /* do it twice to force the change */
2500 tact->set_active (!yn);
2501 tact->set_active (yn);
2505 if ((prop = node.property ("show-editor-list"))) {
2507 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2511 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2512 bool yn = (prop->value() == X_("yes"));
2514 /* do it twice to force the change */
2516 tact->set_active (!yn);
2517 tact->set_active (yn);
2526 Editor::get_state ()
2528 XMLNode* node = new XMLNode ("Editor");
2531 _id.print (buf, sizeof (buf));
2532 node->add_property ("id", buf);
2534 if (is_realized()) {
2535 Glib::RefPtr<Gdk::Window> win = get_window();
2537 int x, y, xoff, yoff, width, height;
2538 win->get_root_origin(x, y);
2539 win->get_position(xoff, yoff);
2540 win->get_size(width, height);
2542 XMLNode* geometry = new XMLNode ("geometry");
2544 snprintf(buf, sizeof(buf), "%d", width);
2545 geometry->add_property("x-size", string(buf));
2546 snprintf(buf, sizeof(buf), "%d", height);
2547 geometry->add_property("y-size", string(buf));
2548 snprintf(buf, sizeof(buf), "%d", x);
2549 geometry->add_property("x-pos", string(buf));
2550 snprintf(buf, sizeof(buf), "%d", y);
2551 geometry->add_property("y-pos", string(buf));
2552 snprintf(buf, sizeof(buf), "%d", xoff);
2553 geometry->add_property("x-off", string(buf));
2554 snprintf(buf, sizeof(buf), "%d", yoff);
2555 geometry->add_property("y-off", string(buf));
2556 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2557 geometry->add_property("edit_pane_pos", string(buf));
2559 node->add_child_nocopy (*geometry);
2562 maybe_add_mixer_strip_width (*node);
2564 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2565 node->add_property ("zoom-focus", buf);
2566 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2567 node->add_property ("zoom", buf);
2568 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2569 node->add_property ("snap-to", buf);
2570 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2571 node->add_property ("snap-mode", buf);
2573 node->add_property ("edit-point", enum_2_string (_edit_point));
2575 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2576 node->add_property ("playhead", buf);
2578 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2579 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2580 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2581 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2582 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2583 node->add_property ("mouse-mode", enum2str(mouse_mode));
2585 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2587 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2588 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2591 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2593 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2594 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2602 /** @param y y offset from the top of all trackviews.
2603 * @return pair: TimeAxisView that y is over, layer index.
2604 * TimeAxisView may be 0. Layer index is the layer number if the TimeAxisView is valid and is
2605 * in stacked region display mode, otherwise 0.
2607 std::pair<TimeAxisView *, layer_t>
2608 Editor::trackview_by_y_position (double y)
2610 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2612 std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
2618 return std::make_pair ( (TimeAxisView *) 0, 0);
2622 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2624 if (!session || snap_mode == SnapOff) {
2628 snap_to_internal (start, direction, for_mark);
2632 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2634 Location* before = 0;
2635 Location* after = 0;
2637 const nframes64_t one_second = session->frame_rate();
2638 const nframes64_t one_minute = session->frame_rate() * 60;
2639 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2640 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2641 nframes64_t presnap = start;
2643 switch (snap_type) {
2645 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2646 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2648 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2652 case SnapToSMPTEFrame:
2653 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2654 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2656 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2660 case SnapToSMPTESeconds:
2661 if (session->smpte_offset_negative())
2663 start += session->smpte_offset ();
2665 start -= session->smpte_offset ();
2667 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2668 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2670 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2673 if (session->smpte_offset_negative())
2675 start -= session->smpte_offset ();
2677 start += session->smpte_offset ();
2681 case SnapToSMPTEMinutes:
2682 if (session->smpte_offset_negative())
2684 start += session->smpte_offset ();
2686 start -= session->smpte_offset ();
2688 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2689 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2691 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2693 if (session->smpte_offset_negative())
2695 start -= session->smpte_offset ();
2697 start += session->smpte_offset ();
2702 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2703 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2705 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2710 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2711 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2713 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2718 start = session->tempo_map().round_to_bar (start, direction);
2722 start = session->tempo_map().round_to_beat (start, direction);
2725 case SnapToAThirtysecondBeat:
2726 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2729 case SnapToASixteenthBeat:
2730 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2733 case SnapToAEighthBeat:
2734 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2737 case SnapToAQuarterBeat:
2738 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2741 case SnapToAThirdBeat:
2742 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2750 before = session->locations()->first_location_before (start);
2751 after = session->locations()->first_location_after (start);
2753 if (direction < 0) {
2755 start = before->start();
2759 } else if (direction > 0) {
2761 start = after->start();
2763 start = session->current_end_frame();
2768 /* find nearest of the two */
2769 if ((start - before->start()) < (after->start() - start)) {
2770 start = before->start();
2772 start = after->start();
2775 start = before->start();
2778 start = after->start();
2785 case SnapToRegionStart:
2786 case SnapToRegionEnd:
2787 case SnapToRegionSync:
2788 case SnapToRegionBoundary:
2789 if (!region_boundary_cache.empty()) {
2790 vector<nframes64_t>::iterator i;
2792 if (direction > 0) {
2793 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2795 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2798 if (i != region_boundary_cache.end()) {
2800 /* lower bound doesn't quite to the right thing for our purposes */
2802 if (direction < 0 && i != region_boundary_cache.begin()) {
2809 start = region_boundary_cache.back();
2815 switch (snap_mode) {
2821 if (presnap > start) {
2822 if (presnap > (start + unit_to_frame(snap_threshold))) {
2826 } else if (presnap < start) {
2827 if (presnap < (start - unit_to_frame(snap_threshold))) {
2833 /* handled at entry */
2840 Editor::snap_length_beats (nframes64_t start)
2846 /* FIXME: This could/should also work with non-tempo based snap settings (ie seconds) */
2848 switch (snap_type) {
2850 return session->tempo_map().meter_at(start).beats_per_bar();
2855 case SnapToAThirtysecondBeat:
2856 return 1.0 / (double)32.0;
2859 case SnapToASixteenthBeat:
2860 return 1.0 / (double)16.0;
2863 case SnapToAEighthBeat:
2864 return 1.0 / (double)8.0;
2867 case SnapToAQuarterBeat:
2868 return 1.0 / (double)4.0;
2871 case SnapToAThirdBeat:
2872 return 1.0 / (double)3.0;
2880 Editor::setup_toolbar ()
2884 /* Mode Buttons (tool selection) */
2886 vector<ToggleButton *> mouse_mode_buttons;
2888 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2889 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2890 mouse_mode_buttons.push_back (&mouse_move_button);
2892 if (!Profile->get_sae()) {
2893 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2894 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2895 mouse_mode_buttons.push_back (&mouse_select_button);
2897 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2898 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2899 mouse_mode_buttons.push_back (&mouse_gain_button);
2902 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2903 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2904 mouse_mode_buttons.push_back (&mouse_zoom_button);
2905 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2906 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2907 mouse_mode_buttons.push_back (&mouse_timefx_button);
2908 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2909 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2910 mouse_note_button.add (*(manage (new Image (::get_icon("tool_note")))));
2911 mouse_note_button.set_relief(Gtk::RELIEF_NONE);
2912 mouse_mode_buttons.push_back (&mouse_note_button);
2913 mouse_mode_buttons.push_back (&mouse_audition_button);
2915 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2917 HBox* mode_box = manage(new HBox);
2918 mode_box->set_border_width (2);
2919 mode_box->set_spacing(4);
2920 mouse_mode_button_box.set_spacing(1);
2921 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2922 if (!Profile->get_sae()) {
2923 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2925 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2926 if (!Profile->get_sae()) {
2927 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2929 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2930 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2931 mouse_mode_button_box.pack_start(mouse_note_button, true, true);
2932 mouse_mode_button_box.set_homogeneous(true);
2934 vector<string> edit_mode_strings;
2935 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2936 if (!Profile->get_sae()) {
2937 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2939 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2941 edit_mode_selector.set_name ("EditModeSelector");
2942 set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
2943 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2945 mode_box->pack_start(edit_mode_selector);
2946 mode_box->pack_start(mouse_mode_button_box);
2948 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2949 mouse_mode_tearoff->set_name ("MouseModeBase");
2951 if (Profile->get_sae()) {
2952 mouse_mode_tearoff->set_can_be_torn_off (false);
2955 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2956 &mouse_mode_tearoff->tearoff_window()));
2957 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2958 &mouse_mode_tearoff->tearoff_window(), 1));
2959 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2960 &mouse_mode_tearoff->tearoff_window()));
2961 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2962 &mouse_mode_tearoff->tearoff_window(), 1));
2964 mouse_move_button.set_name ("MouseModeButton");
2965 mouse_select_button.set_name ("MouseModeButton");
2966 mouse_gain_button.set_name ("MouseModeButton");
2967 mouse_zoom_button.set_name ("MouseModeButton");
2968 mouse_timefx_button.set_name ("MouseModeButton");
2969 mouse_audition_button.set_name ("MouseModeButton");
2970 mouse_note_button.set_name ("MouseModeButton");
2972 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2973 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2974 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2975 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2976 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2977 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2978 ARDOUR_UI::instance()->tooltips().set_tip (mouse_note_button, _("Edit MIDI Notes"));
2980 mouse_move_button.unset_flags (CAN_FOCUS);
2981 mouse_select_button.unset_flags (CAN_FOCUS);
2982 mouse_gain_button.unset_flags (CAN_FOCUS);
2983 mouse_zoom_button.unset_flags (CAN_FOCUS);
2984 mouse_timefx_button.unset_flags (CAN_FOCUS);
2985 mouse_audition_button.unset_flags (CAN_FOCUS);
2986 mouse_note_button.unset_flags (CAN_FOCUS);
2988 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2989 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2991 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2992 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2993 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2994 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2995 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2996 mouse_note_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseNote));
2998 // mouse_move_button.set_active (true);
3003 zoom_box.set_spacing (1);
3004 zoom_box.set_border_width (0);
3006 zoom_in_button.set_name ("EditorTimeButton");
3007 zoom_in_button.set_size_request(-1,16);
3008 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
3009 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
3010 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
3012 zoom_out_button.set_name ("EditorTimeButton");
3013 zoom_out_button.set_size_request(-1,16);
3014 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
3015 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
3016 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
3018 zoom_out_full_button.set_name ("EditorTimeButton");
3019 zoom_out_full_button.set_size_request(-1,16);
3020 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
3021 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
3022 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
3024 zoom_focus_selector.set_name ("ZoomFocusSelector");
3025 set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
3026 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
3027 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
3029 zoom_box.pack_start (zoom_out_button, false, false);
3030 zoom_box.pack_start (zoom_in_button, false, false);
3031 zoom_box.pack_start (zoom_out_full_button, false, false);
3033 HBox* zbc = manage (new HBox);
3034 zbc->pack_start (zoom_focus_selector, PACK_SHRINK);
3035 zoom_vbox.pack_start (*zbc, PACK_SHRINK);
3036 zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
3038 snap_box.set_spacing (1);
3039 snap_box.set_border_width (2);
3041 snap_type_selector.set_name ("SnapTypeSelector");
3042 set_popdown_strings (snap_type_selector, snap_type_strings, true);
3043 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
3044 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
3046 snap_mode_selector.set_name ("SnapModeSelector");
3047 set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
3048 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
3049 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3051 edit_point_selector.set_name ("EditPointSelector");
3052 set_popdown_strings (edit_point_selector, edit_point_strings, true);
3053 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
3054 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
3056 snap_box.pack_start (edit_point_clock, false, false);
3057 snap_box.pack_start (snap_mode_selector, false, false);
3058 snap_box.pack_start (snap_type_selector, false, false);
3059 snap_box.pack_start (edit_point_selector, false, false);
3063 HBox *nudge_box = manage (new HBox);
3064 nudge_box->set_spacing(1);
3065 nudge_box->set_border_width (2);
3067 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
3068 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
3070 nudge_box->pack_start (nudge_backward_button, false, false);
3071 nudge_box->pack_start (nudge_forward_button, false, false);
3072 nudge_box->pack_start (nudge_clock, false, false);
3075 /* Pack everything in... */
3077 HBox* hbox = manage (new HBox);
3078 hbox->set_spacing(10);
3080 tools_tearoff = manage (new TearOff (*hbox));
3081 tools_tearoff->set_name ("MouseModeBase");
3083 if (Profile->get_sae()) {
3084 tools_tearoff->set_can_be_torn_off (false);
3087 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3088 &tools_tearoff->tearoff_window()));
3089 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3090 &tools_tearoff->tearoff_window(), 0));
3091 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3092 &tools_tearoff->tearoff_window()));
3093 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3094 &tools_tearoff->tearoff_window(), 0));
3096 toolbar_hbox.set_spacing (10);
3097 toolbar_hbox.set_border_width (1);
3099 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
3100 toolbar_hbox.pack_start (*tools_tearoff, false, false);
3103 hbox->pack_start (snap_box, false, false);
3104 // hbox->pack_start (zoom_box, false, false);
3105 hbox->pack_start (*nudge_box, false, false);
3109 toolbar_base.set_name ("ToolBarBase");
3110 toolbar_base.add (toolbar_hbox);
3112 toolbar_frame.set_shadow_type (SHADOW_OUT);
3113 toolbar_frame.set_name ("BaseFrame");
3114 toolbar_frame.add (toolbar_base);
3118 Editor::midi_panic_button_pressed ()
3121 session->midi_panic();
3126 Editor::setup_midi_toolbar ()
3130 /* Mode Buttons (tool selection) */
3132 vector<ToggleButton *> midi_tool_buttons;
3134 midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
3135 midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
3136 midi_tool_buttons.push_back (&midi_tool_pencil_button);
3137 midi_tool_select_button.add (*(manage (new Image (::get_icon("midi_tool_select")))));
3138 midi_tool_select_button.set_relief(Gtk::RELIEF_NONE);
3139 midi_tool_buttons.push_back (&midi_tool_select_button);
3140 midi_tool_resize_button.add (*(manage (new Image (::get_icon("strip_width")))));
3141 midi_tool_resize_button.set_relief(Gtk::RELIEF_NONE);
3142 midi_tool_buttons.push_back (&midi_tool_resize_button);
3143 midi_tool_erase_button.add (*(manage (new Image (::get_icon("midi_tool_erase")))));
3144 midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
3145 midi_tool_buttons.push_back (&midi_tool_erase_button);
3147 midi_tool_pencil_button.set_active(true);
3149 midi_tool_button_set = new GroupedButtons (midi_tool_buttons);
3151 midi_tool_button_box.set_border_width (2);
3152 midi_tool_button_box.set_spacing(1);
3153 midi_tool_button_box.pack_start(midi_tool_pencil_button, true, true);
3154 midi_tool_button_box.pack_start(midi_tool_select_button, true, true);
3155 midi_tool_button_box.pack_start(midi_tool_resize_button, true, true);
3156 midi_tool_button_box.pack_start(midi_tool_erase_button , true, true);
3157 midi_tool_button_box.set_homogeneous(true);
3159 midi_tool_pencil_button.set_name ("MouseModeButton");
3160 midi_tool_select_button.set_name ("MouseModeButton");
3161 midi_tool_resize_button.set_name ("MouseModeButton");
3162 midi_tool_erase_button .set_name ("MouseModeButton");
3164 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
3165 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
3166 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
3167 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
3169 midi_tool_pencil_button.unset_flags (CAN_FOCUS);
3170 midi_tool_select_button.unset_flags (CAN_FOCUS);
3171 midi_tool_resize_button.unset_flags (CAN_FOCUS);
3172 midi_tool_erase_button.unset_flags (CAN_FOCUS);
3174 midi_tool_pencil_button.signal_toggled().connect (bind (mem_fun(*this,
3175 &Editor::midi_edit_mode_toggled), Editing::MidiEditPencil));
3176 midi_tool_select_button.signal_toggled().connect (bind (mem_fun(*this,
3177 &Editor::midi_edit_mode_toggled), Editing::MidiEditSelect));
3178 midi_tool_resize_button.signal_toggled().connect (bind (mem_fun(*this,
3179 &Editor::midi_edit_mode_toggled), Editing::MidiEditResize));
3180 midi_tool_erase_button.signal_toggled().connect (bind (mem_fun(*this,
3181 &Editor::midi_edit_mode_toggled), Editing::MidiEditErase));
3184 /* Midi sound notes */
3185 midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
3186 midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
3187 ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes"));
3188 midi_sound_notes.unset_flags (CAN_FOCUS);
3192 HBox* panic_box = manage (new HBox);
3193 midi_panic_button.set_name("MidiPanicButton");
3194 midi_panic_button.signal_pressed().connect (
3195 mem_fun(this, &Editor::midi_panic_button_pressed));
3196 panic_box->pack_start (midi_sound_notes , true, true);
3197 panic_box->pack_start (midi_panic_button, true, true);
3199 /* Pack everything in... */
3201 midi_tools_tearoff = manage (new TearOff (midi_tool_button_box));
3202 midi_tools_tearoff->set_name ("MouseModeBase");
3205 midi_tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3206 &midi_tools_tearoff->tearoff_window()));
3207 midi_tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3208 &midi_tools_tearoff->tearoff_window(), 0));
3209 midi_tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3210 &midi_tools_tearoff->tearoff_window()));
3211 midi_tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3212 &midi_tools_tearoff->tearoff_window(), 0));
3215 midi_toolbar_hbox.set_spacing (10);
3216 midi_toolbar_hbox.set_border_width (1);
3218 midi_toolbar_hbox.pack_start (*midi_tools_tearoff, false, true);
3220 midi_toolbar_hbox.pack_start(*panic_box, false, true, 4);
3222 midi_tool_button_box.show_all ();
3223 midi_toolbar_hbox.show_all();
3224 midi_tools_tearoff->show_all();
3226 midi_toolbar_base.set_name ("ToolBarBase");
3227 midi_toolbar_base.add (midi_toolbar_hbox);
3229 midi_toolbar_frame.set_shadow_type (SHADOW_OUT);
3230 midi_toolbar_frame.set_name ("BaseFrame");
3231 midi_toolbar_frame.add (midi_toolbar_base);
3235 Editor::convert_drop_to_paths (
3236 vector<ustring>& paths,
3237 const RefPtr<Gdk::DragContext>& context,
3240 const SelectionData& data,
3248 vector<ustring> uris = data.get_uris();
3252 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3253 are actually URI lists. So do it by hand.
3256 if (data.get_target() != "text/plain") {
3260 /* Parse the "uri-list" format that Nautilus provides,
3261 where each pathname is delimited by \r\n.
3263 THERE MAY BE NO NULL TERMINATING CHAR!!!
3266 ustring txt = data.get_text();
3270 p = (const char *) malloc (txt.length() + 1);
3271 txt.copy ((char *) p, txt.length(), 0);
3272 ((char*)p)[txt.length()] = '\0';
3278 while (g_ascii_isspace (*p))
3282 while (*q && (*q != '\n') && (*q != '\r')) {
3289 while (q > p && g_ascii_isspace (*q))
3294 uris.push_back (ustring (p, q - p + 1));
3298 p = strchr (p, '\n');
3310 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3312 if ((*i).substr (0,7) == "file://") {
3315 PBD::url_decode (p);
3317 // scan forward past three slashes
3319 ustring::size_type slashcnt = 0;
3320 ustring::size_type n = 0;
3321 ustring::iterator x = p.begin();
3323 while (slashcnt < 3 && x != p.end()) {
3326 } else if (slashcnt == 3) {
3333 if (slashcnt != 3 || x == p.end()) {
3334 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3338 paths.push_back (p.substr (n - 1));
3346 Editor::new_tempo_section ()
3352 Editor::map_transport_state ()
3354 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3356 if (session->transport_stopped()) {
3357 have_pending_keyboard_selection = false;
3360 update_loop_range_view (true);
3365 Editor::State::State (PublicEditor const * e)
3367 selection = new Selection (e);
3370 Editor::State::~State ()
3376 Editor::store_state (State& state) const
3378 *state.selection = *selection;
3382 Editor::restore_state (State *state)
3384 if (*selection == *state->selection) {
3388 *selection = *state->selection;
3389 time_selection_changed ();
3390 region_selection_changed ();
3392 /* XXX other selection change handlers? */
3396 Editor::begin_reversible_command (string name)
3399 before = &get_state();
3400 session->begin_reversible_command (name);
3405 Editor::commit_reversible_command ()
3408 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3413 Editor::set_route_group_solo (Route& route, bool yn)
3415 RouteGroup *route_group;
3417 if ((route_group = route.route_group()) != 0) {
3418 route_group->apply (&Route::set_solo, yn, this);
3420 route.set_solo (yn, this);
3425 Editor::set_route_group_mute (Route& route, bool yn)
3427 RouteGroup *route_group = 0;
3429 if ((route_group == route.route_group()) != 0) {
3430 route_group->apply (&Route::set_mute, yn, this);
3432 route.set_mute (yn, this);
3437 Editor::history_changed ()
3441 if (undo_action && session) {
3442 if (session->undo_depth() == 0) {
3445 label = string_compose(_("Undo (%1)"), session->next_undo());
3447 undo_action->property_label() = label;
3450 if (redo_action && session) {
3451 if (session->redo_depth() == 0) {
3454 label = string_compose(_("Redo (%1)"), session->next_redo());
3456 redo_action->property_label() = label;
3461 Editor::duplicate_dialog (bool with_dialog)
3465 if (mouse_mode == MouseRange) {
3466 if (selection->time.length() == 0) {
3472 get_regions_for_action (rs);
3474 if (mouse_mode != MouseRange) {
3483 ArdourDialog win ("Duplication Dialog");
3484 Label label (_("Number of Duplications:"));
3485 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3486 SpinButton spinner (adjustment, 0.0, 1);
3489 win.get_vbox()->set_spacing (12);
3490 win.get_vbox()->pack_start (hbox);
3491 hbox.set_border_width (6);
3492 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3494 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3495 place, visually. so do this by hand.
3498 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3499 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3500 spinner.grab_focus();
3506 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3507 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3508 win.set_default_response (RESPONSE_ACCEPT);
3510 win.set_position (WIN_POS_MOUSE);
3512 spinner.grab_focus ();
3514 switch (win.run ()) {
3515 case RESPONSE_ACCEPT:
3521 times = adjustment.get_value();
3524 if (mouse_mode == MouseRange) {
3525 duplicate_selection (times);
3527 duplicate_some_regions (rs, times);
3532 Editor::show_verbose_canvas_cursor ()
3534 verbose_canvas_cursor->raise_to_top();
3535 verbose_canvas_cursor->show();
3536 verbose_cursor_visible = true;
3540 Editor::hide_verbose_canvas_cursor ()
3542 verbose_canvas_cursor->hide();
3543 verbose_cursor_visible = false;
3547 Editor::clamp_verbose_cursor_x (double x)
3552 x = min (_canvas_width - 200.0, x);
3558 Editor::clamp_verbose_cursor_y (double y)
3560 if (y < canvas_timebars_vsize) {
3561 y = canvas_timebars_vsize;
3563 y = min (_canvas_height - 50, y);
3569 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3571 verbose_canvas_cursor->property_text() = txt.c_str();
3572 /* don't get too close to the edge */
3573 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3574 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3578 Editor::set_verbose_canvas_cursor_text (const string & txt)
3580 verbose_canvas_cursor->property_text() = txt.c_str();
3584 Editor::set_edit_mode (EditMode m)
3586 Config->set_edit_mode (m);
3590 Editor::cycle_edit_mode ()
3592 switch (Config->get_edit_mode()) {
3594 if (Profile->get_sae()) {
3595 Config->set_edit_mode (Lock);
3597 Config->set_edit_mode (Splice);
3601 Config->set_edit_mode (Lock);
3604 Config->set_edit_mode (Slide);
3610 Editor::edit_mode_selection_done ()
3616 string choice = edit_mode_selector.get_active_text();
3617 EditMode mode = Slide;
3619 if (choice == _("Splice Edit")) {
3621 } else if (choice == _("Slide Edit")) {
3623 } else if (choice == _("Lock Edit")) {
3627 Config->set_edit_mode (mode);
3631 Editor::snap_type_selection_done ()
3633 string choice = snap_type_selector.get_active_text();
3634 SnapType snaptype = SnapToBeat;
3636 if (choice == _("Beats/3")) {
3637 snaptype = SnapToAThirdBeat;
3638 } else if (choice == _("Beats/4")) {
3639 snaptype = SnapToAQuarterBeat;
3640 } else if (choice == _("Beats/8")) {
3641 snaptype = SnapToAEighthBeat;
3642 } else if (choice == _("Beats/16")) {
3643 snaptype = SnapToASixteenthBeat;
3644 } else if (choice == _("Beats/32")) {
3645 snaptype = SnapToAThirtysecondBeat;
3646 } else if (choice == _("Beats")) {
3647 snaptype = SnapToBeat;
3648 } else if (choice == _("Bars")) {
3649 snaptype = SnapToBar;
3650 } else if (choice == _("Marks")) {
3651 snaptype = SnapToMark;
3652 } else if (choice == _("Region starts")) {
3653 snaptype = SnapToRegionStart;
3654 } else if (choice == _("Region ends")) {
3655 snaptype = SnapToRegionEnd;
3656 } else if (choice == _("Region bounds")) {
3657 snaptype = SnapToRegionBoundary;
3658 } else if (choice == _("Region syncs")) {
3659 snaptype = SnapToRegionSync;
3660 } else if (choice == _("CD Frames")) {
3661 snaptype = SnapToCDFrame;
3662 } else if (choice == _("SMPTE Frames")) {
3663 snaptype = SnapToSMPTEFrame;
3664 } else if (choice == _("SMPTE Seconds")) {
3665 snaptype = SnapToSMPTESeconds;
3666 } else if (choice == _("SMPTE Minutes")) {
3667 snaptype = SnapToSMPTEMinutes;
3668 } else if (choice == _("Seconds")) {
3669 snaptype = SnapToSeconds;
3670 } else if (choice == _("Minutes")) {
3671 snaptype = SnapToMinutes;
3674 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3676 ract->set_active ();
3681 Editor::snap_mode_selection_done ()
3683 string choice = snap_mode_selector.get_active_text();
3684 SnapMode mode = SnapNormal;
3686 if (choice == _("No Grid")) {
3688 } else if (choice == _("Grid")) {
3690 } else if (choice == _("Magnetic")) {
3691 mode = SnapMagnetic;
3694 RefPtr<RadioAction> ract = snap_mode_action (mode);
3697 ract->set_active (true);
3702 Editor::cycle_edit_point (bool with_marker)
3704 switch (_edit_point) {
3706 set_edit_point_preference (EditAtPlayhead);
3708 case EditAtPlayhead:
3710 set_edit_point_preference (EditAtSelectedMarker);
3712 set_edit_point_preference (EditAtMouse);
3715 case EditAtSelectedMarker:
3716 set_edit_point_preference (EditAtMouse);
3722 Editor::edit_point_selection_done ()
3724 string choice = edit_point_selector.get_active_text();
3725 EditPoint ep = EditAtSelectedMarker;
3727 if (choice == _("Marker")) {
3728 set_edit_point_preference (EditAtSelectedMarker);
3729 } else if (choice == _("Playhead")) {
3730 set_edit_point_preference (EditAtPlayhead);
3732 set_edit_point_preference (EditAtMouse);
3735 RefPtr<RadioAction> ract = edit_point_action (ep);
3738 ract->set_active (true);
3743 Editor::zoom_focus_selection_done ()
3745 string choice = zoom_focus_selector.get_active_text();
3746 ZoomFocus focus_type = ZoomFocusLeft;
3748 if (choice == _("Left")) {
3749 focus_type = ZoomFocusLeft;
3750 } else if (choice == _("Right")) {
3751 focus_type = ZoomFocusRight;
3752 } else if (choice == _("Center")) {
3753 focus_type = ZoomFocusCenter;
3754 } else if (choice == _("Play")) {
3755 focus_type = ZoomFocusPlayhead;
3756 } else if (choice == _("Edit")) {
3757 focus_type = ZoomFocusEdit;
3758 } else if (choice == _("Active Mark")) {
3759 focus_type = ZoomFocusEdit;
3760 } else if (choice == _("Active Mark")) {
3761 focus_type = ZoomFocusEdit;
3763 focus_type = ZoomFocusMouse;
3766 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3769 ract->set_active ();
3774 Editor::edit_controls_button_release (GdkEventButton* ev)
3776 if (Keyboard::is_context_menu_event (ev)) {
3777 ARDOUR_UI::instance()->add_route (this);
3783 Editor::mouse_select_button_release (GdkEventButton* ev)
3785 /* this handles just right-clicks */
3787 if (ev->button != 3) {
3794 Editor::TrackViewList *
3795 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3797 TrackViewList::iterator i;
3799 TrackViewList* v = new TrackViewList;
3801 if (track == 0 && group == 0) {
3805 for (i = track_views.begin(); i != track_views.end (); ++i) {
3809 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->active_property (RouteGroup::Select))) {
3811 /* just the view for this track
3814 v->push_back (track);
3818 /* views for all tracks in the route group */
3820 for (i = track_views.begin(); i != track_views.end (); ++i) {
3822 if (group == 0 || ((*i)->route_group() == group && group->active_property (RouteGroup::Select))) {
3832 Editor::set_zoom_focus (ZoomFocus f)
3834 string str = zoom_focus_strings[(int)f];
3836 if (str != zoom_focus_selector.get_active_text()) {
3837 zoom_focus_selector.set_active_text (str);
3840 if (zoom_focus != f) {
3843 ZoomFocusChanged (); /* EMIT_SIGNAL */
3850 Editor::ensure_float (Window& win)
3852 win.set_transient_for (*this);
3856 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3858 /* recover or initialize pane positions. do this here rather than earlier because
3859 we don't want the positions to change the child allocations, which they seem to do.
3865 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3867 static int32_t done;
3870 width = default_width;
3871 height = default_height;
3873 if ((geometry = find_named_node (*node, "geometry")) != 0) {
3875 if ((prop = geometry->property ("x_size")) == 0) {
3876 prop = geometry->property ("x-size");
3879 width = atoi (prop->value());
3881 if ((prop = geometry->property ("y_size")) == 0) {
3882 prop = geometry->property ("y-size");
3885 height = atoi (prop->value());
3889 if (which == static_cast<Paned*> (&edit_pane)) {
3895 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3896 /* initial allocation is 90% to canvas, 10% to notebook */
3897 pos = (int) floor (alloc.get_width() * 0.90f);
3898 snprintf (buf, sizeof(buf), "%d", pos);
3900 pos = atoi (prop->value());
3903 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3904 edit_pane.set_position (pos);
3905 pre_maximal_pane_position = pos;
3911 Editor::detach_tearoff (Box* b, Window* w)
3913 if (tools_tearoff->torn_off() &&
3914 mouse_mode_tearoff->torn_off()) {
3915 top_hbox.remove (toolbar_frame);
3920 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3922 if (toolbar_frame.get_parent() == 0) {
3923 top_hbox.pack_end (toolbar_frame);
3928 Editor::set_show_measures (bool yn)
3930 if (_show_measures != yn) {
3933 if ((_show_measures = yn) == true) {
3935 tempo_lines->show();
3943 Editor::toggle_follow_playhead ()
3945 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3947 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3948 set_follow_playhead (tact->get_active());
3953 Editor::set_follow_playhead (bool yn)
3955 if (_follow_playhead != yn) {
3956 if ((_follow_playhead = yn) == true) {
3958 update_current_screen ();
3965 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3967 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3969 xfade->set_active (!xfade->active());
3974 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3976 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3978 xfade->set_follow_overlap (!xfade->following_overlap());
3983 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3985 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3991 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3995 switch (cew.run ()) {
3996 case RESPONSE_ACCEPT:
4003 xfade->StateChanged (Change (~0));
4007 Editor::playlist_selector () const
4009 return *_playlist_selector;
4013 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
4017 ret = nudge_clock.current_duration (pos);
4018 next = ret + 1; /* XXXX fix me */
4024 Editor::end_location_changed (Location* location)
4026 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
4027 //reset_scrolling_region ();
4028 nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
4029 horizontal_adjustment.set_upper (session_span / frames_per_unit);
4033 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
4035 ArdourDialog dialog ("playlist deletion dialog");
4036 Label label (string_compose (_("Playlist %1 is currently unused.\n"
4037 "If left alone, no audio files used by it will be cleaned.\n"
4038 "If deleted, audio files used by it alone by will cleaned."),
4041 dialog.set_position (WIN_POS_CENTER);
4042 dialog.get_vbox()->pack_start (label);
4046 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
4047 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
4048 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
4050 switch (dialog.run ()) {
4051 case RESPONSE_ACCEPT:
4052 /* delete the playlist */
4056 case RESPONSE_REJECT:
4057 /* keep the playlist */
4069 Editor::audio_region_selection_covers (nframes64_t where)
4071 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
4072 if ((*a)->region()->covers (where)) {
4081 Editor::prepare_for_cleanup ()
4083 cut_buffer->clear_regions ();
4084 cut_buffer->clear_playlists ();
4086 selection->clear_regions ();
4087 selection->clear_playlists ();
4089 no_region_list_redisplay = true;
4093 Editor::finish_cleanup ()
4095 no_region_list_redisplay = false;
4096 redisplay_regions ();
4100 Editor::transport_loop_location()
4103 return session->locations()->auto_loop_location();
4110 Editor::transport_punch_location()
4113 return session->locations()->auto_punch_location();
4120 Editor::control_layout_scroll (GdkEventScroll* ev)
4122 switch (ev->direction) {
4124 scroll_tracks_up_line ();
4128 case GDK_SCROLL_DOWN:
4129 scroll_tracks_down_line ();
4133 /* no left/right handling yet */
4141 /** A new snapshot has been selected.
4144 Editor::snapshot_display_selection_changed ()
4146 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
4148 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
4150 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
4152 if (snap_name.length() == 0) {
4156 if (session->snap_name() == snap_name) {
4160 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
4165 Editor::snapshot_display_button_press (GdkEventButton* ev)
4167 if (ev->button == 3) {
4168 /* Right-click on the snapshot list. Work out which snapshot it
4170 Gtk::TreeModel::Path path;
4171 Gtk::TreeViewColumn* col;
4174 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
4175 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
4177 Gtk::TreeModel::Row row = *iter;
4178 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
4187 /** Pop up the snapshot display context menu.
4188 * @param button Button used to open the menu.
4189 * @param time Menu open time.
4190 * @snapshot_name Name of the snapshot that the menu click was over.
4194 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
4196 using namespace Menu_Helpers;
4198 MenuList& items (snapshot_context_menu.items());
4201 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
4203 add_item_with_sensitivity (items, MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)), modification_allowed);
4205 add_item_with_sensitivity (items, MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)), modification_allowed);
4207 snapshot_context_menu.popup (button, time);
4211 Editor::rename_snapshot (Glib::ustring old_name)
4213 ArdourPrompter prompter(true);
4217 prompter.set_name ("Prompter");
4218 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
4219 prompter.set_prompt (_("New name of snapshot"));
4220 prompter.set_initial_text (old_name);
4222 if (prompter.run() == RESPONSE_ACCEPT) {
4223 prompter.get_result (new_name);
4224 if (new_name.length()) {
4225 session->rename_state (old_name, new_name);
4226 redisplay_snapshots ();
4233 Editor::remove_snapshot (Glib::ustring name)
4235 vector<string> choices;
4237 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
4239 choices.push_back (_("No, do nothing."));
4240 choices.push_back (_("Yes, remove it."));
4242 Gtkmm2ext::Choice prompter (prompt, choices);
4244 if (prompter.run () == 1) {
4245 session->remove_state (name);
4246 redisplay_snapshots ();
4251 Editor::redisplay_snapshots ()
4257 vector<sys::path> state_file_paths;
4259 get_state_files_in_directory (session->session_directory().root_path(),
4262 if (state_file_paths.empty()) return;
4264 vector<string> state_file_names(get_file_names_no_extension(state_file_paths));
4266 snapshot_display_model->clear ();
4268 for (vector<string>::iterator i = state_file_names.begin();
4269 i != state_file_names.end(); ++i)
4271 string statename = (*i);
4272 TreeModel::Row row = *(snapshot_display_model->append());
4274 /* this lingers on in case we ever want to change the visible
4275 name of the snapshot.
4278 string display_name;
4279 display_name = statename;
4281 if (statename == session->snap_name()) {
4282 snapshot_display.get_selection()->select(row);
4285 row[snapshot_display_columns.visible_name] = display_name;
4286 row[snapshot_display_columns.real_name] = statename;
4291 Editor::session_state_saved (string snap_name)
4293 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4294 redisplay_snapshots ();
4298 Editor::maximise_editing_space ()
4300 mouse_mode_tearoff->set_visible (false);
4301 tools_tearoff->set_visible (false);
4303 pre_maximal_pane_position = edit_pane.get_position();
4304 pre_maximal_editor_width = this->get_width();
4306 if(post_maximal_pane_position == 0) {
4307 post_maximal_pane_position = edit_pane.get_width();
4312 if(post_maximal_editor_width) {
4313 edit_pane.set_position (post_maximal_pane_position -
4314 abs(post_maximal_editor_width - pre_maximal_editor_width));
4316 edit_pane.set_position (post_maximal_pane_position);
4321 Editor::restore_editing_space ()
4323 // user changed width of pane during fullscreen
4325 if(post_maximal_pane_position != edit_pane.get_position()) {
4326 post_maximal_pane_position = edit_pane.get_position();
4331 mouse_mode_tearoff->set_visible (true);
4332 tools_tearoff->set_visible (true);
4333 post_maximal_editor_width = this->get_width();
4335 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4339 * Make new playlists for a given track and also any others that belong
4340 * to the same active route group with the `edit' property.
4345 Editor::new_playlists (TimeAxisView* v)
4347 begin_reversible_command (_("new playlists"));
4348 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4349 session->get_playlists(playlists);
4350 mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, RouteGroup::Edit);
4351 commit_reversible_command ();
4355 * Use a copy of the current playlist for a given track and also any others that belong
4356 * to the same active route group with the `edit' property.
4361 Editor::copy_playlists (TimeAxisView* v)
4363 begin_reversible_command (_("copy playlists"));
4364 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4365 session->get_playlists(playlists);
4366 mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, RouteGroup::Edit);
4367 commit_reversible_command ();
4370 /** Clear the current playlist for a given track and also any others that belong
4371 * to the same active route group with the `edit' property.
4376 Editor::clear_playlists (TimeAxisView* v)
4378 begin_reversible_command (_("clear playlists"));
4379 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4380 session->get_playlists(playlists);
4381 mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v, RouteGroup::Edit);
4382 commit_reversible_command ();
4386 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4388 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4392 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4394 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4398 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t sz)
4400 atv.clear_playlist ();
4404 Editor::on_key_press_event (GdkEventKey* ev)
4406 return key_press_focus_accelerator_handler (*this, ev);
4410 Editor::on_key_release_event (GdkEventKey* ev)
4412 return Gtk::Window::on_key_release_event (ev);
4413 // return key_press_focus_accelerator_handler (*this, ev);
4417 Editor::reset_x_origin (nframes64_t frame)
4419 //cerr << "resetting x origin" << endl;
4420 queue_visual_change (frame);
4424 Editor::reset_y_origin (double y)
4426 queue_visual_change_y (y);
4430 Editor::reset_zoom (double fpu)
4432 queue_visual_change (fpu);
4436 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4438 //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
4439 reset_x_origin (frame);
4442 if (!no_save_visual) {
4443 undo_visual_stack.push_back (current_visual_state(false));
4447 Editor::VisualState*
4448 Editor::current_visual_state (bool with_tracks)
4450 VisualState* vs = new VisualState;
4451 vs->y_position = vertical_adjustment.get_value();
4452 vs->frames_per_unit = frames_per_unit;
4453 vs->leftmost_frame = leftmost_frame;
4454 vs->zoom_focus = zoom_focus;
4455 vs->zoomed_to_region = zoomed_to_region;
4458 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4459 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4467 Editor::undo_visual_state ()
4469 if (undo_visual_stack.empty()) {
4473 VisualState* vs = undo_visual_stack.back();
4474 undo_visual_stack.pop_back();
4475 use_visual_state (*vs);
4476 redo_visual_stack.push_back (vs);
4480 Editor::redo_visual_state ()
4482 if (redo_visual_stack.empty()) {
4486 VisualState* vs = redo_visual_stack.back();
4487 redo_visual_stack.pop_back();
4488 use_visual_state (*vs);
4489 undo_visual_stack.push_back (vs);
4493 Editor::swap_visual_state ()
4495 if (undo_visual_stack.empty()) {
4496 redo_visual_state ();
4498 undo_visual_state ();
4503 Editor::use_visual_state (VisualState& vs)
4505 no_save_visual = true;
4507 _routes->suspend_redisplay ();
4509 vertical_adjustment.set_value (vs.y_position);
4511 set_zoom_focus (vs.zoom_focus);
4512 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4513 zoomed_to_region = vs.zoomed_to_region;
4515 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4516 TrackViewList::iterator t;
4518 /* check if the track still exists - it could have been deleted */
4520 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4521 (*t)->set_state (*(i->second));
4526 if (!vs.track_states.empty()) {
4527 _routes->update_visibility ();
4530 _routes->resume_redisplay ();
4532 no_save_visual = false;
4536 Editor::set_frames_per_unit (double fpu)
4538 /* this is the core function that controls the zoom level of the canvas. it is called
4539 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4542 if (fpu == frames_per_unit) {
4551 /* don't allow zooms that fit more than the maximum number
4552 of frames into an 800 pixel wide space.
4555 if (max_frames / fpu < 800.0) {
4560 tempo_lines->tempo_map_changed();
4562 frames_per_unit = fpu;
4567 Editor::post_zoom ()
4569 nframes64_t cef = 0;
4571 // convert fpu to frame count
4573 nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
4575 if (frames_per_unit != zoom_range_clock.current_duration()) {
4576 zoom_range_clock.set (frames);
4579 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4580 if (!selection->tracks.empty()) {
4581 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4582 (*i)->reshow_selection (selection->time);
4585 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4586 (*i)->reshow_selection (selection->time);
4591 leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4593 ZoomChanged (); /* EMIT_SIGNAL */
4595 reset_hscrollbar_stepping ();
4598 cef = session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
4600 horizontal_adjustment.set_upper (cef / frames_per_unit);
4602 //reset_scrolling_region ();
4604 if (playhead_cursor) {
4605 playhead_cursor->set_position (playhead_cursor->current_frame);
4608 refresh_location_display();
4609 _summary->set_overlays_dirty ();
4615 Editor::queue_visual_change (nframes64_t where)
4617 pending_visual_change.add (VisualChange::TimeOrigin);
4619 /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
4623 if (where > session->current_end_frame()) {
4624 horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
4627 pending_visual_change.time_origin = where;
4629 ensure_visual_change_idle_handler ();
4633 Editor::queue_visual_change (double fpu)
4635 pending_visual_change.add (VisualChange::ZoomLevel);
4636 pending_visual_change.frames_per_unit = fpu;
4638 ensure_visual_change_idle_handler ();
4643 Editor::queue_visual_change_y (double y)
4645 pending_visual_change.add (VisualChange::YOrigin);
4646 pending_visual_change.y_origin = y;
4648 ensure_visual_change_idle_handler ();
4652 Editor::ensure_visual_change_idle_handler ()
4654 if (pending_visual_change.idle_handler_id < 0) {
4655 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4660 Editor::_idle_visual_changer (void* arg)
4662 return static_cast<Editor*>(arg)->idle_visual_changer ();
4666 Editor::idle_visual_changer ()
4668 VisualChange::Type p = pending_visual_change.pending;
4669 pending_visual_change.pending = (VisualChange::Type) 0;
4671 #ifdef FIX_THIS_FOR_V3
4672 double last_time_origin = horizontal_adjustment.get_value();
4675 if (p & VisualChange::ZoomLevel) {
4676 set_frames_per_unit (pending_visual_change.frames_per_unit);
4678 compute_fixed_ruler_scale ();
4679 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4680 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
4681 update_tempo_based_rulers ();
4683 if (p & VisualChange::TimeOrigin) {
4684 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4686 if (p & VisualChange::YOrigin) {
4687 vertical_adjustment.set_value (pending_visual_change.y_origin);
4690 nframes64_t csf=0, cef=0;
4691 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4694 csf = session->current_start_frame();
4695 cef = session->current_end_frame();
4698 /* if we seek beyond the current end of the canvas, move the end */
4700 #ifdef FIX_THIS_FOR_V3
4701 if (last_time_origin == horizontal_adjustment.get_value() ) {
4702 /* changed signal not emitted */
4703 update_fixed_rulers ();
4704 redisplay_tempo (true);
4708 if (current_time_origin != pending_visual_change.time_origin) {
4709 cef += current_page_frames() / 10; // Add a little extra so we can see the end marker
4710 horizontal_adjustment.set_upper (cef / frames_per_unit);
4711 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4713 update_fixed_rulers();
4714 redisplay_tempo (true);
4717 _summary->set_overlays_dirty ();
4719 //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
4720 pending_visual_change.idle_handler_id = -1;
4721 return 0; /* this is always a one-shot call */
4724 struct EditorOrderTimeAxisSorter {
4725 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4726 return a->order () < b->order ();
4731 Editor::sort_track_selection (TrackSelection* sel)
4733 EditorOrderTimeAxisSorter cmp;
4738 selection->tracks.sort (cmp);
4743 Editor::get_preferred_edit_position (bool ignore_playhead)
4746 nframes64_t where = 0;
4747 EditPoint ep = _edit_point;
4749 if (entered_marker) {
4750 return entered_marker->position();
4753 if (ignore_playhead && ep == EditAtPlayhead) {
4754 ep = EditAtSelectedMarker;
4758 case EditAtPlayhead:
4759 where = session->audible_frame();
4762 case EditAtSelectedMarker:
4763 if (!selection->markers.empty()) {
4765 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4768 where = loc->start();
4779 if (!mouse_frame (where, ignored)) {
4780 /* XXX not right but what can we do ? */
4791 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4793 if (!session) return;
4795 begin_reversible_command (cmd);
4799 if ((tll = transport_loop_location()) == 0) {
4800 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4801 XMLNode &before = session->locations()->get_state();
4802 session->locations()->add (loc, true);
4803 session->set_auto_loop_location (loc);
4804 XMLNode &after = session->locations()->get_state();
4805 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4807 XMLNode &before = tll->get_state();
4808 tll->set_hidden (false, this);
4809 tll->set (start, end);
4810 XMLNode &after = tll->get_state();
4811 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4814 commit_reversible_command ();
4818 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4820 if (!session) return;
4822 begin_reversible_command (cmd);
4826 if ((tpl = transport_punch_location()) == 0) {
4827 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4828 XMLNode &before = session->locations()->get_state();
4829 session->locations()->add (loc, true);
4830 session->set_auto_loop_location (loc);
4831 XMLNode &after = session->locations()->get_state();
4832 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4835 XMLNode &before = tpl->get_state();
4836 tpl->set_hidden (false, this);
4837 tpl->set (start, end);
4838 XMLNode &after = tpl->get_state();
4839 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4842 commit_reversible_command ();
4846 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4848 const TrackSelection* tracks;
4851 tracks = &track_views;
4856 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4857 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4859 boost::shared_ptr<Diskstream> ds;
4860 boost::shared_ptr<Playlist> pl;
4862 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4864 Playlist::RegionList* regions = pl->regions_at (
4865 (nframes64_t) floor ( (double)where * ds->speed()));
4867 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4868 RegionView* rv = rtv->view()->find_view (*i);
4881 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4883 const TrackSelection* tracks;
4886 tracks = &track_views;
4891 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4892 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
4894 boost::shared_ptr<Diskstream> ds;
4895 boost::shared_ptr<Playlist> pl;
4897 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
4899 Playlist::RegionList* regions = pl->regions_touched (
4900 (nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4902 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4904 RegionView* rv = rtv->view()->find_view (*i);
4918 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4920 rs = selection->regions;
4922 if (allow_entered && entered_regionview) {
4923 rs.add (entered_regionview);
4926 TrackSelection tracks = selection->tracks;
4928 RegionSelection to_map = rs;
4930 for (RegionSelection::iterator i = to_map.begin (); i != to_map.end(); ++i) {
4932 RouteGroup* g = (*i)->get_time_axis_view().route_group ();
4933 if (g && g->active_property (RouteGroup::Edit)) {
4934 tracks.add (axis_views_from_routes (g->route_list()));
4937 nframes64_t const where = get_preferred_edit_position ();
4938 get_regions_at (rs, where, tracks);
4943 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4946 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4948 RouteTimeAxisView* tatv;
4950 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4952 boost::shared_ptr<Playlist> pl;
4953 vector<boost::shared_ptr<Region> > results;
4955 boost::shared_ptr<Diskstream> ds;
4957 if ((ds = tatv->get_diskstream()) == 0) {
4962 if ((pl = (ds->playlist())) != 0) {
4963 pl->get_region_list_equivalent_regions (region, results);
4966 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4967 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4968 regions.push_back (marv);
4977 Editor::show_rhythm_ferret ()
4979 if (rhythm_ferret == 0) {
4980 rhythm_ferret = new RhythmFerret(*this);
4983 rhythm_ferret->set_session (session);
4984 rhythm_ferret->show ();
4985 rhythm_ferret->present ();
4989 Editor::show_bundle_manager ()
4991 if (_bundle_manager == 0) {
4992 _bundle_manager = new BundleManager (*session);
4995 _bundle_manager->show ();
4999 Editor::show_global_port_matrix (ARDOUR::DataType t)
5001 if (_global_port_matrix[t] == 0) {
5002 _global_port_matrix[t] = new GlobalPortMatrixWindow (*session, t);
5005 _global_port_matrix[t]->show ();
5009 Editor::first_idle ()
5011 MessageDialog* dialog = 0;
5013 if (track_views.size() > 1) {
5014 dialog = new MessageDialog (*this,
5015 _("Please wait while Ardour loads visual data"),
5020 ARDOUR_UI::instance()->flush_pending ();
5023 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
5027 // first idle adds route children (automation tracks), so we need to redisplay here
5028 _routes->redisplay ();
5036 _idle_resizer (gpointer arg)
5038 return ((Editor*)arg)->idle_resize ();
5042 Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
5044 if (resize_idle_id < 0) {
5045 resize_idle_id = g_idle_add (_idle_resizer, this);
5046 _pending_resize_amount = 0;
5049 /* make a note of the smallest resulting height, so that we can clamp the
5050 lower limit at TimeAxisView::hSmall */
5052 int32_t min_resulting = INT32_MAX;
5054 _pending_resize_amount += h;
5055 _pending_resize_view = view;
5057 min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
5059 if (selection->tracks.contains (_pending_resize_view)) {
5060 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
5061 min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
5065 if (min_resulting < 0) {
5070 if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
5071 _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
5075 /** Handle pending resizing of tracks */
5077 Editor::idle_resize ()
5079 _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
5081 if (dynamic_cast<AutomationTimeAxisView*> (_pending_resize_view) == 0 &&
5082 selection->tracks.contains (_pending_resize_view)) {
5084 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
5085 if (*i != _pending_resize_view) {
5086 (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
5092 _group_tabs->set_dirty ();
5093 resize_idle_id = -1;
5101 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::located));
5103 _pending_locate_request = false;
5107 Editor::region_view_added (RegionView *)
5109 _summary->set_dirty ();
5113 Editor::streamview_height_changed ()
5115 _summary->set_dirty ();
5119 Editor::axis_views_from_routes (list<Route*> r) const
5123 for (list<Route*>::const_iterator i = r.begin(); i != r.end(); ++i) {
5124 TrackViewList::const_iterator j = track_views.begin ();
5125 while (j != track_views.end()) {
5126 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
5127 if (rtv && rtv->route().get() == *i) {
5139 Editor::handle_new_route (RouteList& routes)
5141 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_route), routes));
5143 RouteTimeAxisView *rtv;
5144 list<RouteTimeAxisView*> new_views;
5146 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
5147 boost::shared_ptr<Route> route = (*x);
5149 if (route->is_hidden()) {
5153 DataType dt = route->input()->default_type();
5155 if (dt == ARDOUR::DataType::AUDIO) {
5156 rtv = new AudioTimeAxisView (*this, *session, route, *track_canvas);
5157 } else if (dt == ARDOUR::DataType::MIDI) {
5158 rtv = new MidiTimeAxisView (*this, *session, route, *track_canvas);
5160 throw unknown_type();
5163 new_views.push_back (rtv);
5164 track_views.push_back (rtv);
5166 rtv->effective_gain_display ();
5168 rtv->view()->RegionViewAdded.connect (mem_fun (*this, &Editor::region_view_added));
5169 rtv->view()->HeightChanged.connect (mem_fun (*this, &Editor::streamview_height_changed));
5171 rtv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), rtv));
5174 _routes->routes_added (new_views);
5176 if (show_editor_mixer_when_tracks_arrive) {
5177 show_editor_mixer (true);
5180 editor_list_button.set_sensitive (true);
5182 _summary->set_dirty ();
5186 Editor::remove_route (TimeAxisView *tv)
5188 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
5190 TrackViewList::iterator i;
5191 boost::shared_ptr<Route> route;
5192 TimeAxisView* next_tv;
5194 if (tv == entered_track) {
5198 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
5200 i = track_views.erase (i);
5202 if (track_views.empty()) {
5204 } else if (i == track_views.end()) {
5205 next_tv = track_views.front();
5211 if (current_mixer_strip && current_mixer_strip->route() == route) {
5214 set_selected_mixer_strip (*next_tv);
5216 /* make the editor mixer strip go away setting the
5217 * button to inactive (which also unticks the menu option)
5220 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
5226 Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
5228 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
5230 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
5231 // this will hide the mixer strip
5232 set_selected_mixer_strip (tv);
5235 _routes->hide_track_in_display (tv);
5239 Editor::sync_track_view_list_and_routes ()
5241 track_views = TrackSelection (_routes->views ());
5243 _summary->set_dirty ();
5244 _group_tabs->set_dirty ();
5246 return false; // do not call again (until needed)
5250 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
5252 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5258 Editor::get_route_view_by_id (PBD::ID& id)
5260 RouteTimeAxisView* v;
5262 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5263 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
5264 if(v->route()->id() == id) {
5274 Editor::fit_route_group (RouteGroup *g)
5276 TrackSelection ts = axis_views_from_routes (g->route_list ());