2 Copyright (C) 2000-2007 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 */
28 #include <boost/none.hpp>
30 #include <sigc++/bind.h>
32 #include <pbd/convert.h>
33 #include <pbd/error.h>
34 #include <pbd/enumwriter.h>
35 #include <pbd/memento_command.h>
37 #include <glibmm/miscutils.h>
38 #include <gtkmm/image.h>
39 #include <gdkmm/color.h>
40 #include <gdkmm/bitmap.h>
42 #include <gtkmm2ext/grouped_buttons.h>
43 #include <gtkmm2ext/gtk_ui.h>
44 #include <gtkmm2ext/tearoff.h>
45 #include <gtkmm2ext/utils.h>
46 #include <gtkmm2ext/window_title.h>
47 #include <gtkmm2ext/choice.h>
49 #include <ardour/audio_track.h>
50 #include <ardour/audio_diskstream.h>
51 #include <ardour/plugin_manager.h>
52 #include <ardour/location.h>
53 #include <ardour/audioplaylist.h>
54 #include <ardour/audioregion.h>
55 #include <ardour/midi_region.h>
56 #include <ardour/session_route.h>
57 #include <ardour/session_directory.h>
58 #include <ardour/session_state_utils.h>
59 #include <ardour/tempo.h>
60 #include <ardour/utils.h>
61 #include <ardour/profile.h>
63 #include <control_protocol/control_protocol.h>
65 #include "ardour_ui.h"
69 #include "playlist_selector.h"
70 #include "audio_region_view.h"
71 #include "rgb_macros.h"
72 #include "selection.h"
73 #include "audio_streamview.h"
74 #include "time_axis_view.h"
75 #include "audio_time_axis.h"
77 #include "crossfade_view.h"
79 #include "public_editor.h"
80 #include "crossfade_edit.h"
81 #include "canvas_impl.h"
84 #include "gui_thread.h"
85 #include "simpleline.h"
86 #include "rhythm_ferret.h"
88 #include "tempo_lines.h"
89 #include "analysis_window.h"
94 #include "imageframe_socket_handler.h"
99 using namespace ARDOUR;
102 using namespace Glib;
103 using namespace Gtkmm2ext;
104 using namespace Editing;
106 using PBD::internationalize;
109 const double Editor::timebar_height = 15.0;
111 #include "editor_xpms"
113 static const gchar *_snap_type_strings[] = {
135 static const gchar *_snap_mode_strings[] = {
142 static const gchar *_edit_point_strings[] = {
149 static const gchar *_zoom_focus_strings[] = {
159 #ifdef USE_RUBBERBAND
160 static const gchar *_rb_opt_strings[] = {
163 N_("Balanced multitimbral mixture"),
164 N_("Unpitched percussion with stable notes"),
165 N_("Crisp monophonic instrumental"),
166 N_("Unpitched solo percussion"),
171 /* Soundfile drag-n-drop */
173 Gdk::Cursor* Editor::cross_hair_cursor = 0;
174 Gdk::Cursor* Editor::selector_cursor = 0;
175 Gdk::Cursor* Editor::trimmer_cursor = 0;
176 Gdk::Cursor* Editor::grabber_cursor = 0;
177 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
178 Gdk::Cursor* Editor::zoom_cursor = 0;
179 Gdk::Cursor* Editor::time_fx_cursor = 0;
180 Gdk::Cursor* Editor::fader_cursor = 0;
181 Gdk::Cursor* Editor::speaker_cursor = 0;
182 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
183 Gdk::Cursor* Editor::midi_select_cursor = 0;
184 Gdk::Cursor* Editor::midi_resize_cursor = 0;
185 Gdk::Cursor* Editor::midi_erase_cursor = 0;
186 Gdk::Cursor* Editor::wait_cursor = 0;
187 Gdk::Cursor* Editor::timebar_cursor = 0;
188 Gdk::Cursor* Editor::transparent_cursor = 0;
191 show_me_the_size (Requisition* r, const char* what)
193 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
197 DragInfo::clear_copied_locations ()
199 for (list<Location*>::iterator i = copied_locations.begin(); i != copied_locations.end(); ++i) {
202 copied_locations.clear ();
207 /* time display buttons */
209 minsec_label (_("Mins:Secs")),
210 bbt_label (_("Bars:Beats")),
211 smpte_label (_("Timecode")),
212 frame_label (_("Samples")),
213 tempo_label (_("Tempo")),
214 meter_label (_("Meter")),
215 mark_label (_("Location Markers")),
216 range_mark_label (_("Range Markers")),
217 transport_mark_label (_("Loop/Punch Ranges")),
218 cd_mark_label (_("CD Markers")),
219 edit_packer (3, 4, true),
221 /* the values here don't matter: layout widgets
222 reset them as needed.
225 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
226 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
228 /* tool bar related */
230 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
231 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
233 toolbar_selection_clock_table (2,3),
235 automation_mode_button (_("mode")),
236 global_automation_button (_("automation")),
238 midi_panic_button (_("Panic")),
239 midi_tools_tearoff (0),
242 image_socket_listener(0),
247 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
248 meters_running(false)
253 /* we are a singleton */
255 PublicEditor::_instance = this;
260 selection = new Selection (this);
261 cut_buffer = new Selection (this);
263 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
264 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
265 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
266 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
267 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
269 clicked_regionview = 0;
270 clicked_axisview = 0;
271 clicked_routeview = 0;
272 clicked_crossfadeview = 0;
273 clicked_control_point = 0;
274 last_update_frame = 0;
276 current_mixer_strip = 0;
277 current_bbt_points = 0;
280 snap_type_strings = I18N (_snap_type_strings);
281 snap_mode_strings = I18N (_snap_mode_strings);
282 zoom_focus_strings = I18N (_zoom_focus_strings);
283 edit_point_strings = I18N (_edit_point_strings);
284 #ifdef USE_RUBBERBAND
285 rb_opt_strings = I18N (_rb_opt_strings);
288 snap_threshold = 5.0;
289 bbt_beat_subdivision = 4;
292 last_autoscroll_x = 0;
293 last_autoscroll_y = 0;
294 autoscroll_active = false;
295 autoscroll_timeout_tag = -1;
296 interthread_progress_window = 0;
301 current_interthread_info = 0;
302 _show_measures = true;
303 _show_waveforms = true;
304 _show_waveforms_recording = true;
305 first_action_message = 0;
306 show_gain_after_trim = false;
307 ignore_route_list_reorder = false;
308 no_route_list_redisplay = false;
309 verbose_cursor_on = true;
310 route_removal = false;
311 show_automatic_regions_in_region_list = true;
312 last_item_entered = 0;
313 last_item_entered_n = 0;
315 region_list_sort_type = (Editing::RegionListSortType) 0;
316 have_pending_keyboard_selection = false;
317 _follow_playhead = true;
318 _xfade_visibility = true;
319 editor_ruler_menu = 0;
320 no_ruler_shown_update = false;
321 edit_group_list_menu = 0;
323 region_list_menu = 0;
325 start_end_marker_menu = 0;
326 range_marker_menu = 0;
327 marker_menu_item = 0;
329 transport_marker_menu = 0;
330 new_transport_marker_menu = 0;
331 editor_mixer_strip_width = Wide;
332 show_editor_mixer_when_tracks_arrive = false;
333 region_edit_menu_split_multichannel_item = 0;
334 region_edit_menu_split_item = 0;
337 ignore_mouse_mode_toggle = false;
338 ignore_midi_edit_mode_toggle = false;
339 current_stepping_trackview = 0;
341 entered_regionview = 0;
343 clear_entered_track = false;
344 _new_regionviews_show_envelope = false;
346 in_edit_group_row_change = false;
347 last_canvas_frame = 0;
349 button_release_can_deselect = true;
350 _dragging_playhead = false;
351 _dragging_edit_point = false;
352 _dragging_hscrollbar = false;
353 select_new_marker = false;
354 zoomed_to_region = false;
356 allow_vertical_scroll = false;
357 no_save_visual = false;
358 need_resize_line = false;
360 old_resize_line_y = -1;
361 no_region_list_redisplay = false;
365 scrubbing_direction = 0;
368 ignore_route_order_sync = false;
370 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
371 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
372 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
373 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
374 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
376 range_marker_drag_rect = 0;
377 marker_drag_line = 0;
378 set_midi_edit_mode (MidiEditPencil, true);
379 set_mouse_mode (MouseObject, true);
381 frames_per_unit = 2048; /* too early to use reset_zoom () */
382 reset_hscrollbar_stepping ();
384 zoom_focus = ZoomFocusLeft;
385 set_zoom_focus (ZoomFocusLeft);
386 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
388 initialize_rulers ();
389 initialize_canvas ();
391 edit_controls_vbox.set_spacing (0);
392 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
393 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
394 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
396 controls_layout.add (edit_controls_vbox);
397 controls_layout.set_name ("EditControlsBase");
398 controls_layout.add_events (Gdk::SCROLL_MASK);
399 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
401 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
402 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
403 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
405 edit_vscrollbar.set_adjustment (vertical_adjustment);
406 edit_hscrollbar.set_adjustment (horizontal_adjustment);
408 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
409 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
410 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
412 edit_hscrollbar.set_name ("EditorHScrollbar");
416 setup_midi_toolbar ();
418 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
420 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
421 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
422 0.0, 1.0, 100.0, 1.0));
423 pad_line_1->property_color_rgba() = 0xFF0000FF;
427 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
428 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
429 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
430 time_canvas_vbox.pack_start (*frames_ruler, false, false);
431 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
432 //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
433 time_canvas_vbox.set_size_request (-1, -1);
434 bbt_label.set_name ("EditorTimeButton");
435 bbt_label.set_size_request (-1, (int)timebar_height);
436 bbt_label.set_alignment (1.0, 0.5);
437 bbt_label.set_padding (5,0);
438 minsec_label.set_name ("EditorTimeButton");
439 minsec_label.set_size_request (-1, (int)timebar_height);
440 minsec_label.set_alignment (1.0, 0.5);
441 minsec_label.set_padding (5,0);
442 smpte_label.set_name ("EditorTimeButton");
443 smpte_label.set_size_request (-1, (int)timebar_height);
444 smpte_label.set_alignment (1.0, 0.5);
445 smpte_label.set_padding (5,0);
446 frame_label.set_name ("EditorTimeButton");
447 frame_label.set_size_request (-1, (int)timebar_height);
448 frame_label.set_alignment (1.0, 0.5);
449 frame_label.set_padding (5,0);
451 tempo_label.set_name ("EditorTimeButton");
452 tempo_label.set_size_request (-1, (int)timebar_height);
453 tempo_label.set_alignment (1.0, 0.5);
454 tempo_label.set_padding (5,0);
455 meter_label.set_name ("EditorTimeButton");
456 meter_label.set_size_request (-1, (int)timebar_height);
457 meter_label.set_alignment (1.0, 0.5);
458 meter_label.set_padding (5,0);
459 mark_label.set_name ("EditorTimeButton");
460 mark_label.set_size_request (-1, (int)timebar_height);
461 mark_label.set_alignment (1.0, 0.5);
462 mark_label.set_padding (5,0);
463 cd_mark_label.set_name ("EditorTimeButton");
464 cd_mark_label.set_size_request (-1, (int)timebar_height);
465 cd_mark_label.set_alignment (1.0, 0.5);
466 cd_mark_label.set_padding (5,0);
467 range_mark_label.set_name ("EditorTimeButton");
468 range_mark_label.set_size_request (-1, (int)timebar_height);
469 range_mark_label.set_alignment (1.0, 0.5);
470 range_mark_label.set_padding (5,0);
471 transport_mark_label.set_name ("EditorTimeButton");
472 transport_mark_label.set_size_request (-1, (int)timebar_height);
473 transport_mark_label.set_alignment (1.0, 0.5);
474 transport_mark_label.set_padding (5,0);
476 ruler_label_vbox.pack_start (minsec_label, false, false);
477 ruler_label_vbox.pack_start (smpte_label, false, false);
478 ruler_label_vbox.pack_start (frame_label, false, false);
479 ruler_label_vbox.pack_start (bbt_label, false, false);
481 ruler_label_event_box.add (ruler_label_vbox);
482 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
483 ruler_label_event_box.set_name ("TimebarLabelBase");
484 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
486 time_button_vbox.pack_start (meter_label, false, false);
487 time_button_vbox.pack_start (tempo_label, false, false);
488 time_button_vbox.pack_start (mark_label, false, false);
490 time_button_event_box.add (time_button_vbox);
491 time_button_event_box.set_name ("TimebarLabelBase");
492 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
493 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
495 /* these enable us to have a dedicated window (for cursor setting, etc.)
496 for the canvas areas.
499 track_canvas_event_box.add (*track_canvas);
501 time_canvas_event_box.add (time_canvas_vbox);
502 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
504 edit_packer.set_col_spacings (0);
505 edit_packer.set_row_spacings (0);
506 edit_packer.set_homogeneous (false);
507 edit_packer.set_border_width (0);
508 edit_packer.set_name ("EditorWindow");
512 edit_packer.attach (ruler_label_event_box, 0, 1, 0, 1, FILL, SHRINK, 0, 0);
514 edit_packer.attach (time_button_event_box, 0, 1, 1, 2, FILL, SHRINK, 0, 0);
515 edit_packer.attach (time_canvas_event_box, 1, 2, 0, 1, FILL|EXPAND, FILL, 0, 0);
517 edit_packer.attach (controls_layout, 0, 1, 2, 3, FILL, FILL|EXPAND, 0, 0);
518 edit_packer.attach (track_canvas_event_box, 1, 2, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
520 edit_packer.attach (zoom_box, 0, 1, 3, 4, FILL, FILL, 0, 0);
521 edit_packer.attach (edit_hscrollbar, 1, 2, 3, 4, FILL|EXPAND, FILL, 0, 0);
523 edit_packer.attach (edit_vscrollbar, 3, 4, 2, 3, FILL, FILL|EXPAND, 0, 0);
527 edit_packer.attach (edit_vscrollbar, 0, 1, 0, 4, FILL, FILL|EXPAND, 0, 0);
529 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
530 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
531 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
533 edit_packer.attach (controls_layout, 1, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
534 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
536 edit_packer.attach (zoom_box, 1, 2, 3, 4, FILL, FILL, 0, 0);
537 edit_packer.attach (edit_hscrollbar, 2, 3, 3, 4, FILL|EXPAND, FILL, 0, 0);
540 bottom_hbox.set_border_width (2);
541 bottom_hbox.set_spacing (3);
543 route_display_model = ListStore::create(route_display_columns);
544 route_list_display.set_model (route_display_model);
545 route_list_display.append_column (_("Show"), route_display_columns.visible);
546 route_list_display.append_column (_("Name"), route_display_columns.text);
547 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
548 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
549 route_list_display.set_headers_visible (true);
550 route_list_display.set_name ("TrackListDisplay");
551 route_list_display.get_selection()->set_mode (SELECTION_SINGLE);
552 route_list_display.set_reorderable (true);
553 route_list_display.set_size_request (100,-1);
554 route_list_display.add_object_drag (route_display_columns.route.index(), "routes");
556 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
557 route_list_visible_cell->property_activatable() = true;
558 route_list_visible_cell->property_radio() = false;
560 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
561 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
563 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
565 route_list_scroller.add (route_list_display);
566 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
568 group_model = ListStore::create(group_columns);
569 edit_group_display.set_model (group_model);
570 edit_group_display.append_column (_("Name"), group_columns.text);
571 edit_group_display.append_column (_("Active"), group_columns.is_active);
572 edit_group_display.append_column (_("Show"), group_columns.is_visible);
573 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
574 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
575 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
576 edit_group_display.get_column (0)->set_expand (true);
577 edit_group_display.get_column (1)->set_expand (false);
578 edit_group_display.get_column (2)->set_expand (false);
579 edit_group_display.set_headers_visible (true);
581 /* name is directly editable */
583 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
584 name_cell->property_editable() = true;
585 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
587 /* use checkbox for the active + visible columns */
589 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
590 active_cell->property_activatable() = true;
591 active_cell->property_radio() = false;
593 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
594 active_cell->property_activatable() = true;
595 active_cell->property_radio() = false;
597 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
599 edit_group_display.set_name ("EditGroupList");
600 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
601 edit_group_display.set_headers_visible (true);
602 edit_group_display.set_reorderable (false);
603 edit_group_display.set_rules_hint (true);
604 edit_group_display.set_size_request (75, -1);
606 edit_group_display_scroller.add (edit_group_display);
607 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
609 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
611 VBox* edit_group_display_packer = manage (new VBox());
612 HBox* edit_group_display_button_box = manage (new HBox());
613 edit_group_display_button_box->set_homogeneous (true);
615 Button* edit_group_add_button = manage (new Button ());
616 Button* edit_group_remove_button = manage (new Button ());
620 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
622 edit_group_add_button->add (*w);
624 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
626 edit_group_remove_button->add (*w);
628 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
629 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
631 edit_group_display_button_box->pack_start (*edit_group_add_button);
632 edit_group_display_button_box->pack_start (*edit_group_remove_button);
634 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
635 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
637 region_list_display.set_size_request (100, -1);
638 region_list_display.set_name ("RegionListDisplay");
639 /* Try to prevent single mouse presses from initiating edits.
640 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
642 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
644 region_list_model = TreeStore::create (region_list_columns);
645 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
646 region_list_model->set_sort_column (0, SORT_ASCENDING);
648 region_list_display.set_model (region_list_model);
649 region_list_display.append_column (_("Regions"), region_list_columns.name);
650 region_list_display.append_column (_("Start"), region_list_columns.start);
651 region_list_display.append_column (_("End"), region_list_columns.end);
652 region_list_display.append_column (_("Length"), region_list_columns.length);
653 region_list_display.append_column (_("Sync"), region_list_columns.sync);
654 region_list_display.append_column (_("Fade In"), region_list_columns.fadein);
655 region_list_display.append_column (_("Fade Out"), region_list_columns.fadeout);
656 region_list_display.append_column (_("L"), region_list_columns.locked);
657 region_list_display.append_column (_("G"), region_list_columns.glued);
658 region_list_display.append_column (_("M"), region_list_columns.muted);
659 region_list_display.append_column (_("O"), region_list_columns.opaque);
660 region_list_display.append_column (_("Used"), region_list_columns.used);
661 region_list_display.append_column (_("Path"), region_list_columns.path);
662 region_list_display.set_headers_visible (true);
663 region_list_display.set_grid_lines (TREE_VIEW_GRID_LINES_BOTH);
665 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
666 region_name_cell->property_editable() = true;
667 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
669 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
671 TreeViewColumn* tv_col = region_list_display.get_column(0);
672 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
673 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
674 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
676 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
677 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
679 /* setup DnD handling */
681 list<TargetEntry> region_list_target_table;
683 region_list_target_table.push_back (TargetEntry ("text/plain"));
684 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
685 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
687 region_list_display.add_drop_targets (region_list_target_table);
688 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
690 region_list_scroller.add (region_list_display);
691 region_list_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
693 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
694 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
695 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
696 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
697 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
698 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
700 //ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::redisplay_regions));
701 ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::update_all_region_rows));
702 ARDOUR::Region::RegionPropertyChanged.connect (mem_fun(*this, &Editor::update_region_row));
704 named_selection_scroller.add (named_selection_display);
705 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
707 named_selection_model = TreeStore::create (named_selection_columns);
708 named_selection_display.set_model (named_selection_model);
709 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
710 named_selection_display.set_headers_visible (false);
711 named_selection_display.set_size_request (100, -1);
712 named_selection_display.set_name ("NamedSelectionDisplay");
714 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
715 named_selection_display.set_size_request (100, -1);
716 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
717 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
718 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
722 snapshot_display_model = ListStore::create (snapshot_display_columns);
723 snapshot_display.set_model (snapshot_display_model);
724 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
725 snapshot_display.set_name ("SnapshotDisplay");
726 snapshot_display.set_size_request (75, -1);
727 snapshot_display.set_headers_visible (false);
728 snapshot_display.set_reorderable (false);
729 snapshot_display_scroller.add (snapshot_display);
730 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
732 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
733 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
737 nlabel = manage (new Label (_("Regions")));
738 nlabel->set_angle (-90);
739 the_notebook.append_page (region_list_scroller, *nlabel);
740 nlabel = manage (new Label (_("Tracks/Busses")));
741 nlabel->set_angle (-90);
742 the_notebook.append_page (route_list_scroller, *nlabel);
743 nlabel = manage (new Label (_("Snapshots")));
744 nlabel->set_angle (-90);
745 the_notebook.append_page (snapshot_display_scroller, *nlabel);
746 nlabel = manage (new Label (_("Edit Groups")));
747 nlabel->set_angle (-90);
748 the_notebook.append_page (*edit_group_display_packer, *nlabel);
750 if (!Profile->get_sae()) {
751 nlabel = manage (new Label (_("Chunks")));
752 nlabel->set_angle (-90);
753 the_notebook.append_page (named_selection_scroller, *nlabel);
756 the_notebook.set_show_tabs (true);
757 the_notebook.set_scrollable (true);
758 the_notebook.popup_enable ();
759 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
760 the_notebook.show_all ();
762 post_maximal_editor_width = 0;
763 post_maximal_pane_position = 0;
764 edit_pane.pack1 (edit_packer, true, true);
765 edit_pane.pack2 (the_notebook, false, true);
767 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
769 top_hbox.pack_start (toolbar_frame, false, true);
770 top_hbox.pack_start (midi_toolbar_frame, false, true);
772 HBox *hbox = manage (new HBox);
773 hbox->pack_start (edit_pane, true, true);
775 global_vpacker.pack_start (top_hbox, false, false);
776 global_vpacker.pack_start (*hbox, true, true);
778 global_hpacker.pack_start (global_vpacker, true, true);
780 set_name ("EditorWindow");
781 add_accel_group (ActionManager::ui_manager->get_accel_group());
783 status_bar_hpacker.show ();
785 vpacker.pack_end (status_bar_hpacker, false, false);
786 vpacker.pack_end (global_hpacker, true, true);
788 /* register actions now so that set_state() can find them and set toggles/checks etc */
792 snap_type = SnapToBeat;
793 set_snap_to (snap_type);
795 set_snap_mode (snap_mode);
796 set_edit_point_preference (EditAtMouse, true);
798 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
801 _playlist_selector = new PlaylistSelector();
802 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
804 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
808 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
809 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
811 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
812 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
814 nudge_forward_button.set_name ("TransportButton");
815 nudge_backward_button.set_name ("TransportButton");
817 fade_context_menu.set_name ("ArdourContextMenu");
819 /* icons, titles, WM stuff */
821 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
822 Glib::RefPtr<Gdk::Pixbuf> icon;
824 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
825 window_icons.push_back (icon);
827 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
828 window_icons.push_back (icon);
830 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
831 window_icons.push_back (icon);
833 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
834 window_icons.push_back (icon);
836 if (!window_icons.empty()) {
837 set_icon_list (window_icons);
838 set_default_icon_list (window_icons);
841 WindowTitle title(Glib::get_application_name());
842 title += _("Editor");
843 set_title (title.get_string());
844 set_wmclass (X_("ardour_editor"), "Ardour");
847 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
849 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
850 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
852 /* allow external control surfaces/protocols to do various things */
854 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
855 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
856 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
857 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
858 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
860 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
861 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
870 if(image_socket_listener) {
871 if(image_socket_listener->is_connected())
873 image_socket_listener->close_connection() ;
876 delete image_socket_listener ;
877 image_socket_listener = 0 ;
888 Editor::add_toplevel_controls (Container& cont)
890 vpacker.pack_start (cont, false, false);
895 Editor::catch_vanishing_regionview (RegionView *rv)
897 /* note: the selection will take care of the vanishing
898 audioregionview by itself.
901 if (clicked_regionview == rv) {
902 clicked_regionview = 0;
905 if (entered_regionview == rv) {
906 set_entered_regionview (0);
911 Editor::set_entered_regionview (RegionView* rv)
913 if (rv == entered_regionview) {
917 if (entered_regionview) {
918 entered_regionview->exited ();
921 if ((entered_regionview = rv) != 0) {
922 entered_regionview->entered ();
927 Editor::set_entered_track (TimeAxisView* tav)
930 entered_track->exited ();
933 if ((entered_track = tav) != 0) {
934 entered_track->entered ();
939 Editor::show_window ()
941 show_all_children ();
943 /* re-hide editor list if necessary */
944 editor_list_button_toggled ();
946 /* now reset all audio_time_axis heights, because widgets might need
952 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
953 tv = (static_cast<TimeAxisView*>(*i));
961 Editor::instant_save ()
963 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
968 session->add_instant_xml(get_state());
970 Config->add_instant_xml(get_state());
975 Editor::edit_point_clock_changed()
977 if (_dragging_edit_point) {
981 if (selection->markers.empty()) {
986 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
992 loc->move_to (edit_point_clock.current_time());
996 Editor::zoom_adjustment_changed ()
1002 double fpu = zoom_range_clock.current_duration() / canvas_width;
1006 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
1007 } else if (fpu > session->current_end_frame() / canvas_width) {
1008 fpu = session->current_end_frame() / canvas_width;
1009 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
1012 temporal_zoom (fpu);
1016 Editor::control_scroll (float fraction)
1018 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
1024 double step = fraction * current_page_frames();
1027 _control_scroll_target is an optional<T>
1029 it acts like a pointer to an nframes64_t, with
1030 a operator conversion to boolean to check
1031 that it has a value could possibly use
1032 playhead_cursor->current_frame to store the
1033 value and a boolean in the class to know
1034 when it's out of date
1037 if (!_control_scroll_target) {
1038 _control_scroll_target = session->transport_frame();
1039 _dragging_playhead = true;
1042 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
1043 *_control_scroll_target = 0;
1044 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
1045 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
1047 *_control_scroll_target += (nframes64_t) floor (step);
1050 /* move visuals, we'll catch up with it later */
1052 playhead_cursor->set_position (*_control_scroll_target);
1053 UpdateAllTransportClocks (*_control_scroll_target);
1055 if (*_control_scroll_target > (current_page_frames() / 2)) {
1056 /* try to center PH in window */
1057 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
1063 Now we do a timeout to actually bring the session to the right place
1064 according to the playhead. This is to avoid reading disk buffers on every
1065 call to control_scroll, which is driven by ScrollTimeline and therefore
1066 probably by a control surface wheel which can generate lots of events.
1068 /* cancel the existing timeout */
1070 control_scroll_connection.disconnect ();
1072 /* add the next timeout */
1074 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
1078 Editor::deferred_control_scroll (nframes64_t target)
1080 session->request_locate (*_control_scroll_target, session->transport_rolling());
1081 // reset for next stream
1082 _control_scroll_target = boost::none;
1083 _dragging_playhead = false;
1088 Editor::access_action (std::string action_group, std::string action_item)
1094 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
1096 cout<< "OSC: Recieved: "<< action_item << endl;
1099 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1109 Editor::on_realize ()
1111 Window::on_realize ();
1116 Editor::start_scrolling ()
1118 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1119 (mem_fun(*this, &Editor::update_current_screen));
1124 Editor::stop_scrolling ()
1126 scroll_connection.disconnect ();
1130 Editor::map_position_change (nframes64_t frame)
1132 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1134 if (session == 0 || !_follow_playhead) {
1138 center_screen (frame);
1139 playhead_cursor->set_position (frame);
1143 Editor::center_screen (nframes64_t frame)
1145 double page = canvas_width * frames_per_unit;
1147 /* if we're off the page, then scroll.
1150 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1151 center_screen_internal (frame, page);
1156 Editor::center_screen_internal (nframes64_t frame, float page)
1161 frame -= (nframes64_t) page;
1166 reset_x_origin (frame);
1170 Editor::handle_new_duration ()
1176 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1178 nframes64_t new_end = session->get_maximum_extent() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1180 if (new_end > last_canvas_frame) {
1181 last_canvas_frame = new_end;
1182 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1183 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
1184 //reset_scrolling_region ();
1187 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1188 //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() << ":" << last_canvas_frame << endl;//DEBUG
1192 Editor::update_title_s (const string & snap_name)
1194 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1200 Editor::update_title ()
1202 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1205 bool dirty = session->dirty();
1207 string session_name;
1209 if (session->snap_name() != session->name()) {
1210 session_name = session->snap_name();
1212 session_name = session->name();
1216 session_name = "*" + session_name;
1219 WindowTitle title(session_name);
1220 title += Glib::get_application_name();
1221 set_title (title.get_string());
1226 Editor::connect_to_session (Session *t)
1230 /* there are never any selected regions at startup */
1232 sensitize_the_right_region_actions (false);
1234 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1237 /* catch up with the playhead */
1239 session->request_locate (playhead_cursor->current_frame);
1241 if (first_action_message) {
1242 first_action_message->hide();
1247 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1248 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1250 /* These signals can all be emitted by a non-GUI thread. Therefore the
1251 handlers for them must not attempt to directly interact with the GUI,
1252 but use Gtkmm2ext::UI::instance()->call_slot();
1255 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1256 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1257 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1258 session_connections.push_back (session->RegionsAdded.connect (mem_fun(*this, &Editor::handle_new_regions)));
1259 session_connections.push_back (session->RegionRemoved.connect (mem_fun(*this, &Editor::handle_region_removed)));
1260 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1261 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1262 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1263 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1264 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1265 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1266 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1267 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1268 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1270 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1272 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1274 edit_groups_changed ();
1276 edit_point_clock.set_session (session);
1277 zoom_range_clock.set_session (session);
1278 _playlist_selector->set_session (session);
1279 nudge_clock.set_session (session);
1280 nudge_clock.set (session->frame_rate() * 5); // default of 5 seconds
1282 playhead_cursor->canvas_item.show ();
1284 if (rhythm_ferret) {
1285 rhythm_ferret->set_session (session);
1288 if (analysis_window != 0)
1289 analysis_window->set_session (session);
1291 Location* loc = session->locations()->auto_loop_location();
1293 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1294 if (loc->start() == loc->end()) {
1295 loc->set_end (loc->start() + 1);
1297 session->locations()->add (loc, false);
1298 session->set_auto_loop_location (loc);
1301 loc->set_name (_("Loop"));
1304 loc = session->locations()->auto_punch_location();
1306 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1307 if (loc->start() == loc->end()) {
1308 loc->set_end (loc->start() + 1);
1310 session->locations()->add (loc, false);
1311 session->set_auto_punch_location (loc);
1314 loc->set_name (_("Punch"));
1317 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1319 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1321 refresh_location_display ();
1322 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1323 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1324 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1325 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1326 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1329 sfbrowser->set_session (session);
1332 last_canvas_frame = 0; // force update in handle_new_duration()
1333 handle_new_duration ();
1335 redisplay_regions ();
1336 redisplay_named_selections ();
1337 redisplay_snapshots ();
1339 initial_route_list_display ();
1341 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1342 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1345 restore_ruler_visibility ();
1346 //tempo_map_changed (Change (0));
1347 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1351 /* don't show master bus in a new session */
1353 if (ARDOUR_UI::instance()->session_is_new ()) {
1355 TreeModel::Children rows = route_display_model->children();
1356 TreeModel::Children::iterator i;
1358 no_route_list_redisplay = true;
1360 for (i = rows.begin(); i != rows.end(); ++i) {
1361 TimeAxisView *tv = (*i)[route_display_columns.tv];
1362 RouteTimeAxisView *rtv;
1364 if ((rtv = dynamic_cast<RouteTimeAxisView*>(tv)) != 0) {
1365 if (rtv->route()->is_master()) {
1366 route_list_display.get_selection()->unselect (i);
1371 no_route_list_redisplay = false;
1372 redisplay_route_list ();
1375 switch (snap_type) {
1376 case SnapToRegionStart:
1377 case SnapToRegionEnd:
1378 case SnapToRegionSync:
1379 case SnapToRegionBoundary:
1380 build_region_boundary_cache ();
1387 /* register for undo history */
1388 session->register_with_memento_command_factory(_id, this);
1394 Editor::build_cursors ()
1396 using namespace Gdk;
1398 Gdk::Color mbg ("#000000" ); /* Black */
1399 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1402 RefPtr<Bitmap> source, mask;
1403 source = Bitmap::create (mag_bits, mag_width, mag_height);
1404 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1405 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1408 Gdk::Color fbg ("#ffffff" );
1409 Gdk::Color ffg ("#000000" );
1412 RefPtr<Bitmap> source, mask;
1414 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1415 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1416 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1420 RefPtr<Bitmap> source, mask;
1421 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1422 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1423 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1427 RefPtr<Bitmap> bits;
1428 char pix[4] = { 0, 0, 0, 0 };
1429 bits = Bitmap::create (pix, 2, 2);
1431 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1435 RefPtr<Bitmap> bits;
1436 char pix[4] = { 0, 0, 0, 0 };
1437 bits = Bitmap::create (pix, 2, 2);
1439 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1443 grabber_cursor = new Gdk::Cursor (HAND2);
1446 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1447 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1450 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1451 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1452 selector_cursor = new Gdk::Cursor (XTERM);
1453 time_fx_cursor = new Gdk::Cursor (SIZING);
1454 wait_cursor = new Gdk::Cursor (WATCH);
1455 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1456 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1457 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1458 midi_resize_cursor = new Gdk::Cursor (SIZING);
1459 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1462 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1464 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1466 using namespace Menu_Helpers;
1467 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1470 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1474 MenuList& items (fade_context_menu.items());
1478 switch (item_type) {
1480 case FadeInHandleItem:
1481 if (arv->audio_region()->fade_in_active()) {
1482 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1484 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1487 items.push_back (SeparatorElem());
1489 if (Profile->get_sae()) {
1490 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1491 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1493 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1494 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1495 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1496 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1497 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1503 case FadeOutHandleItem:
1504 if (arv->audio_region()->fade_out_active()) {
1505 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1507 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1510 items.push_back (SeparatorElem());
1512 if (Profile->get_sae()) {
1513 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1514 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1516 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1517 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1518 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1519 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1520 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1526 fatal << _("programming error: ")
1527 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1532 fade_context_menu.popup (button, time);
1536 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1538 using namespace Menu_Helpers;
1539 Menu* (Editor::*build_menu_function)(nframes64_t);
1542 switch (item_type) {
1544 case RegionViewName:
1545 case RegionViewNameHighlight:
1546 if (with_selection) {
1547 build_menu_function = &Editor::build_track_selection_context_menu;
1549 build_menu_function = &Editor::build_track_region_context_menu;
1554 if (with_selection) {
1555 build_menu_function = &Editor::build_track_selection_context_menu;
1557 build_menu_function = &Editor::build_track_context_menu;
1561 case CrossfadeViewItem:
1562 build_menu_function = &Editor::build_track_crossfade_context_menu;
1566 if (clicked_routeview->get_diskstream()) {
1567 build_menu_function = &Editor::build_track_context_menu;
1569 build_menu_function = &Editor::build_track_bus_context_menu;
1574 /* probably shouldn't happen but if it does, we don't care */
1578 menu = (this->*build_menu_function)(frame);
1579 menu->set_name ("ArdourContextMenu");
1581 /* now handle specific situations */
1583 switch (item_type) {
1585 case RegionViewName:
1586 case RegionViewNameHighlight:
1587 if (!with_selection) {
1588 if (region_edit_menu_split_item) {
1589 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1590 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1592 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1596 if (region_edit_menu_split_multichannel_item) {
1597 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1598 // GTK2FIX find the action, change its sensitivity
1599 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1601 // GTK2FIX see above
1602 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1611 case CrossfadeViewItem:
1618 /* probably shouldn't happen but if it does, we don't care */
1622 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1624 /* Bounce to disk */
1626 using namespace Menu_Helpers;
1627 MenuList& edit_items = menu->items();
1629 edit_items.push_back (SeparatorElem());
1631 switch (clicked_routeview->audio_track()->freeze_state()) {
1632 case AudioTrack::NoFreeze:
1633 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1636 case AudioTrack::Frozen:
1637 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1640 case AudioTrack::UnFrozen:
1641 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1647 if (item_type == StreamItem && clicked_routeview) {
1648 clicked_routeview->build_underlay_menu(menu);
1651 menu->popup (button, time);
1655 Editor::build_track_context_menu (nframes64_t ignored)
1657 using namespace Menu_Helpers;
1659 MenuList& edit_items = track_context_menu.items();
1662 add_dstream_context_items (edit_items);
1663 return &track_context_menu;
1667 Editor::build_track_bus_context_menu (nframes64_t ignored)
1669 using namespace Menu_Helpers;
1671 MenuList& edit_items = track_context_menu.items();
1674 add_bus_context_items (edit_items);
1675 return &track_context_menu;
1679 Editor::build_track_region_context_menu (nframes64_t frame)
1681 using namespace Menu_Helpers;
1682 MenuList& edit_items = track_region_context_menu.items();
1685 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1688 boost::shared_ptr<Diskstream> ds;
1689 boost::shared_ptr<Playlist> pl;
1691 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1692 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1694 if (selection->regions.size() > 1) {
1695 // there's already a multiple selection: just add a
1696 // single region context menu that will act on all
1698 boost::shared_ptr<Region> dummy_region; // = NULL
1699 add_region_context_items (rtv->view(), dummy_region, edit_items);
1701 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1702 add_region_context_items (rtv->view(), (*i), edit_items);
1710 add_dstream_context_items (edit_items);
1712 return &track_region_context_menu;
1716 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1718 using namespace Menu_Helpers;
1719 MenuList& edit_items = track_crossfade_context_menu.items();
1720 edit_items.clear ();
1722 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1725 boost::shared_ptr<Diskstream> ds;
1726 boost::shared_ptr<Playlist> pl;
1727 boost::shared_ptr<AudioPlaylist> apl;
1729 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1731 Playlist::RegionList* regions = pl->regions_at (frame);
1732 AudioPlaylist::Crossfades xfades;
1734 apl->crossfades_at (frame, xfades);
1736 bool many = xfades.size() > 1;
1738 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1739 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1742 if (selection->regions.size() > 1) {
1743 // there's already a multiple selection: just add a
1744 // single region context menu that will act on all
1746 boost::shared_ptr<Region> dummy_region; // = NULL
1747 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1749 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1750 add_region_context_items (atv->audio_view(), (*i), edit_items);
1757 add_dstream_context_items (edit_items);
1759 return &track_crossfade_context_menu;
1763 Editor::analyze_region_selection()
1765 if (analysis_window == 0) {
1766 analysis_window = new AnalysisWindow();
1769 analysis_window->set_session(session);
1771 analysis_window->show_all();
1774 analysis_window->set_regionmode();
1775 analysis_window->analyze();
1777 analysis_window->present();
1781 Editor::analyze_range_selection()
1783 if (analysis_window == 0) {
1784 analysis_window = new AnalysisWindow();
1787 analysis_window->set_session(session);
1789 analysis_window->show_all();
1792 analysis_window->set_rangemode();
1793 analysis_window->analyze();
1795 analysis_window->present();
1799 Editor::build_track_selection_context_menu (nframes64_t ignored)
1801 using namespace Menu_Helpers;
1802 MenuList& edit_items = track_selection_context_menu.items();
1803 edit_items.clear ();
1805 add_selection_context_items (edit_items);
1806 // edit_items.push_back (SeparatorElem());
1807 // add_dstream_context_items (edit_items);
1809 return &track_selection_context_menu;
1812 /** Add context menu items relevant to crossfades.
1813 * @param edit_items List to add the items to.
1816 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1818 using namespace Menu_Helpers;
1819 Menu *xfade_menu = manage (new Menu);
1820 MenuList& items = xfade_menu->items();
1821 xfade_menu->set_name ("ArdourContextMenu");
1824 if (xfade->active()) {
1830 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1831 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1833 if (xfade->can_follow_overlap()) {
1835 if (xfade->following_overlap()) {
1836 str = _("Convert to short");
1838 str = _("Convert to full");
1841 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1845 str = xfade->out()->name();
1847 str += xfade->in()->name();
1849 str = _("Crossfade");
1852 edit_items.push_back (MenuElem (str, *xfade_menu));
1853 edit_items.push_back (SeparatorElem());
1857 Editor::xfade_edit_left_region ()
1859 if (clicked_crossfadeview) {
1860 clicked_crossfadeview->left_view.show_region_editor ();
1865 Editor::xfade_edit_right_region ()
1867 if (clicked_crossfadeview) {
1868 clicked_crossfadeview->right_view.show_region_editor ();
1872 /** Add an element to a menu, settings its sensitivity.
1873 * @param m Menu to add to.
1874 * @param e Element to add.
1875 * @param s true to make sensitive, false to make insensitive
1878 Editor::add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s) const
1882 m.back().set_sensitive (false);
1887 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1889 using namespace Menu_Helpers;
1890 Menu *region_menu = manage (new Menu);
1891 MenuList& items = region_menu->items();
1892 region_menu->set_name ("ArdourContextMenu");
1894 boost::shared_ptr<AudioRegion> ar;
1895 boost::shared_ptr<MidiRegion> mr;
1898 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1899 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1901 /* when this particular menu pops up, make the relevant region
1905 region_menu->signal_map_event().connect (
1906 bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1908 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1909 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1912 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1913 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1914 items.push_back (SeparatorElem());
1915 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1916 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1917 items.push_back (SeparatorElem());
1919 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1920 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1921 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1924 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1927 items.push_back (SeparatorElem());
1929 sigc::connection fooc;
1930 boost::shared_ptr<Region> region_to_check;
1933 region_to_check = region;
1935 region_to_check = selection->regions.front()->region();
1938 items.push_back (CheckMenuElem (_("Lock")));
1939 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1940 if (region_to_check->locked()) {
1941 region_lock_item->set_active();
1943 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1945 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1946 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1948 switch (region_to_check->positional_lock_style()) {
1949 case Region::MusicTime:
1950 bbt_glue_item->set_active (true);
1953 bbt_glue_item->set_active (false);
1957 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1959 items.push_back (CheckMenuElem (_("Mute")));
1960 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1961 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1962 if (region_to_check->muted()) {
1964 region_mute_item->set_active();
1968 if (!Profile->get_sae()) {
1969 items.push_back (CheckMenuElem (_("Opaque")));
1970 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1971 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1972 if (region_to_check->opaque()) {
1974 region_opaque_item->set_active();
1979 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1980 if (region_to_check->at_natural_position()) {
1981 items.back().set_sensitive (false);
1984 items.push_back (SeparatorElem());
1988 RegionView* rv = sv->find_view (ar);
1989 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1991 if (!Profile->get_sae()) {
1992 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1994 items.push_back (CheckMenuElem (_("Envelope Visible")));
1995 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1996 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1997 if (arv->envelope_visible()) {
1999 region_envelope_visible_item->set_active (true);
2003 items.push_back (CheckMenuElem (_("Envelope Active")));
2004 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
2005 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
2007 if (ar->envelope_active()) {
2009 region_envelope_active_item->set_active (true);
2013 items.push_back (SeparatorElem());
2016 if (ar->scale_amplitude() != 1.0f) {
2017 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
2019 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
2023 items.push_back (MenuElem (_("Quantize"), mem_fun(*this, &Editor::quantize_region)));
2024 items.push_back (SeparatorElem());
2027 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
2028 items.push_back (SeparatorElem());
2030 /* range related stuff */
2032 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
2033 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
2034 items.push_back (SeparatorElem());
2038 Menu *nudge_menu = manage (new Menu());
2039 MenuList& nudge_items = nudge_menu->items();
2040 nudge_menu->set_name ("ArdourContextMenu");
2042 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
2043 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
2044 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
2045 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
2047 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2048 items.push_back (SeparatorElem());
2050 Menu *trim_menu = manage (new Menu);
2051 MenuList& trim_items = trim_menu->items();
2052 trim_menu->set_name ("ArdourContextMenu");
2054 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
2055 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
2056 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
2057 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
2059 items.push_back (MenuElem (_("Trim"), *trim_menu));
2060 items.push_back (SeparatorElem());
2062 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
2063 region_edit_menu_split_item = &items.back();
2065 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
2066 region_edit_menu_split_multichannel_item = &items.back();
2068 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
2069 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
2070 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
2071 items.push_back (SeparatorElem());
2072 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
2074 /* OK, stick the region submenu at the top of the list, and then add
2078 /* we have to hack up the region name because "_" has a special
2079 meaning for menu titles.
2082 string::size_type pos = 0;
2083 string menu_item_name = (region) ? region->name() : _("Selected regions");
2085 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
2086 menu_item_name.replace (pos, 1, "__");
2090 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
2091 edit_items.push_back (SeparatorElem());
2094 /** Add context menu items relevant to selection ranges.
2095 * @param edit_items List to add the items to.
2098 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
2100 using namespace Menu_Helpers;
2101 Menu *selection_menu = manage (new Menu);
2102 MenuList& items = selection_menu->items();
2103 selection_menu->set_name ("ArdourContextMenu");
2105 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
2106 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
2108 items.push_back (SeparatorElem());
2109 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
2111 items.push_back (SeparatorElem());
2112 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
2113 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
2115 items.push_back (SeparatorElem());
2116 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
2117 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
2119 items.push_back (SeparatorElem());
2120 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
2122 items.push_back (SeparatorElem());
2123 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
2124 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
2126 items.push_back (SeparatorElem());
2127 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
2128 items.push_back (SeparatorElem());
2129 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
2130 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
2131 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
2132 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
2133 items.push_back (SeparatorElem());
2134 items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
2135 items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
2136 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_range)));
2141 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2143 using namespace Menu_Helpers;
2147 Menu *play_menu = manage (new Menu);
2148 MenuList& play_items = play_menu->items();
2149 play_menu->set_name ("ArdourContextMenu");
2151 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2152 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2153 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2154 play_items.push_back (SeparatorElem());
2155 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2157 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2161 Menu *select_menu = manage (new Menu);
2162 MenuList& select_items = select_menu->items();
2163 select_menu->set_name ("ArdourContextMenu");
2165 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2166 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2167 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2168 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2169 select_items.push_back (SeparatorElem());
2170 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2171 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2172 select_items.push_back (SeparatorElem());
2173 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2174 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2175 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2176 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2177 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2178 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2179 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2181 select_items.push_back (SeparatorElem());
2183 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2187 Menu *cutnpaste_menu = manage (new Menu);
2188 MenuList& cutnpaste_items = cutnpaste_menu->items();
2189 cutnpaste_menu->set_name ("ArdourContextMenu");
2191 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2192 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2193 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2195 cutnpaste_items.push_back (SeparatorElem());
2197 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2198 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2200 cutnpaste_items.push_back (SeparatorElem());
2202 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2204 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2206 /* Adding new material */
2208 edit_items.push_back (SeparatorElem());
2209 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2210 edit_items.push_back (MenuElem (_("Insert Existing Media"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2214 Menu *nudge_menu = manage (new Menu());
2215 MenuList& nudge_items = nudge_menu->items();
2216 nudge_menu->set_name ("ArdourContextMenu");
2218 edit_items.push_back (SeparatorElem());
2219 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2220 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2221 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2222 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2224 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2228 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2230 using namespace Menu_Helpers;
2234 Menu *play_menu = manage (new Menu);
2235 MenuList& play_items = play_menu->items();
2236 play_menu->set_name ("ArdourContextMenu");
2238 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2239 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2240 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2244 Menu *select_menu = manage (new Menu);
2245 MenuList& select_items = select_menu->items();
2246 select_menu->set_name ("ArdourContextMenu");
2248 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2249 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2250 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2251 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2252 select_items.push_back (SeparatorElem());
2253 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2254 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2255 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2256 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2258 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2262 Menu *cutnpaste_menu = manage (new Menu);
2263 MenuList& cutnpaste_items = cutnpaste_menu->items();
2264 cutnpaste_menu->set_name ("ArdourContextMenu");
2266 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2267 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2268 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2270 Menu *nudge_menu = manage (new Menu());
2271 MenuList& nudge_items = nudge_menu->items();
2272 nudge_menu->set_name ("ArdourContextMenu");
2274 edit_items.push_back (SeparatorElem());
2275 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2276 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2277 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2278 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2280 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2284 Editor::set_snap_to (SnapType st)
2286 unsigned int snap_ind = (unsigned int)st;
2290 if (snap_ind > snap_type_strings.size() - 1) {
2292 snap_type = (SnapType)snap_ind;
2295 string str = snap_type_strings[snap_ind];
2297 if (str != snap_type_selector.get_active_text()) {
2298 snap_type_selector.set_active_text (str);
2303 switch (snap_type) {
2304 case SnapToAThirtysecondBeat:
2305 case SnapToASixteenthBeat:
2306 case SnapToAEighthBeat:
2307 case SnapToAQuarterBeat:
2308 case SnapToAThirdBeat:
2309 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + (nframes_t)(edit_packer.get_width() * frames_per_unit));
2310 update_tempo_based_rulers ();
2313 case SnapToRegionStart:
2314 case SnapToRegionEnd:
2315 case SnapToRegionSync:
2316 case SnapToRegionBoundary:
2317 build_region_boundary_cache ();
2327 Editor::set_snap_mode (SnapMode mode)
2330 string str = snap_mode_strings[(int)mode];
2332 if (str != snap_mode_selector.get_active_text ()) {
2333 snap_mode_selector.set_active_text (str);
2339 Editor::set_edit_point_preference (EditPoint ep, bool force)
2341 bool changed = (_edit_point != ep);
2344 string str = edit_point_strings[(int)ep];
2346 if (str != edit_point_selector.get_active_text ()) {
2347 edit_point_selector.set_active_text (str);
2350 set_canvas_cursor ();
2352 if (!force && !changed) {
2356 switch (zoom_focus) {
2357 case ZoomFocusMouse:
2358 case ZoomFocusPlayhead:
2360 switch (_edit_point) {
2362 set_zoom_focus (ZoomFocusMouse);
2364 case EditAtPlayhead:
2365 set_zoom_focus (ZoomFocusPlayhead);
2367 case EditAtSelectedMarker:
2368 set_zoom_focus (ZoomFocusEdit);
2376 const char* action=NULL;
2378 switch (_edit_point) {
2379 case EditAtPlayhead:
2380 action = "edit-at-playhead";
2382 case EditAtSelectedMarker:
2383 action = "edit-at-marker";
2386 action = "edit-at-mouse";
2390 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2392 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2396 bool in_track_canvas;
2398 if (!mouse_frame (foo, in_track_canvas)) {
2399 in_track_canvas = false;
2402 reset_canvas_action_sensitivity (in_track_canvas);
2408 Editor::set_state (const XMLNode& node)
2410 const XMLProperty* prop;
2412 int x, y, xoff, yoff;
2415 if ((prop = node.property ("id")) != 0) {
2416 _id = prop->value ();
2419 if ((geometry = find_named_node (node, "geometry")) == 0) {
2421 g.base_width = default_width;
2422 g.base_height = default_height;
2430 g.base_width = atoi(geometry->property("x-size")->value());
2431 g.base_height = atoi(geometry->property("y-size")->value());
2432 x = atoi(geometry->property("x-pos")->value());
2433 y = atoi(geometry->property("y-pos")->value());
2434 xoff = atoi(geometry->property("x-off")->value());
2435 yoff = atoi(geometry->property("y-off")->value());
2438 set_default_size (g.base_width, g.base_height);
2441 if (session && (prop = node.property ("playhead"))) {
2442 nframes64_t pos = atol (prop->value().c_str());
2443 playhead_cursor->set_position (pos);
2445 playhead_cursor->set_position (0);
2447 /* reset_x_origin() doesn't work right here, since the old
2448 position may be zero already, and it does nothing in such
2453 horizontal_adjustment.set_value (0);
2456 if ((prop = node.property ("mixer-width"))) {
2457 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2460 if ((prop = node.property ("zoom-focus"))) {
2461 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2464 if ((prop = node.property ("zoom"))) {
2465 reset_zoom (PBD::atof (prop->value()));
2468 if ((prop = node.property ("snap-to"))) {
2469 set_snap_to ((SnapType) atoi (prop->value()));
2472 if ((prop = node.property ("snap-mode"))) {
2473 set_snap_mode ((SnapMode) atoi (prop->value()));
2476 if ((prop = node.property ("edit-point"))) {
2477 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2480 if ((prop = node.property ("mouse-mode"))) {
2481 MouseMode m = str2mousemode(prop->value());
2482 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2483 set_mouse_mode (m, true);
2485 mouse_mode = MouseGain; /* lie, to force the mode switch */
2486 set_mouse_mode (MouseObject, true);
2489 if ((prop = node.property ("show-waveforms"))) {
2490 bool yn = (prop->value() == "yes");
2491 _show_waveforms = !yn;
2492 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
2494 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2495 /* do it twice to force the change */
2496 tact->set_active (!yn);
2497 tact->set_active (yn);
2501 if ((prop = node.property ("show-waveforms-recording"))) {
2502 bool yn = (prop->value() == "yes");
2503 _show_waveforms_recording = !yn;
2504 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2506 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2507 /* do it twice to force the change */
2508 tact->set_active (!yn);
2509 tact->set_active (yn);
2513 if ((prop = node.property ("show-measures"))) {
2514 bool yn = (prop->value() == "yes");
2515 _show_measures = !yn;
2516 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2518 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2519 /* do it twice to force the change */
2520 tact->set_active (!yn);
2521 tact->set_active (yn);
2525 if ((prop = node.property ("follow-playhead"))) {
2526 bool yn = (prop->value() == "yes");
2527 set_follow_playhead (yn);
2528 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2530 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2531 if (tact->get_active() != yn) {
2532 tact->set_active (yn);
2537 if ((prop = node.property ("region-list-sort-type"))) {
2538 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2539 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2542 if ((prop = node.property ("xfades-visible"))) {
2543 bool yn = (prop->value() == "yes");
2544 _xfade_visibility = !yn;
2545 // set_xfade_visibility (yn);
2548 if ((prop = node.property ("show-editor-mixer"))) {
2550 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2553 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2554 bool yn = (prop->value() == X_("yes"));
2556 /* do it twice to force the change */
2558 tact->set_active (!yn);
2559 tact->set_active (yn);
2563 if ((prop = node.property ("show-editor-list"))) {
2565 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2569 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2570 bool yn = (prop->value() == X_("yes"));
2572 /* do it twice to force the change */
2574 tact->set_active (!yn);
2575 tact->set_active (yn);
2584 Editor::get_state ()
2586 XMLNode* node = new XMLNode ("Editor");
2589 _id.print (buf, sizeof (buf));
2590 node->add_property ("id", buf);
2592 if (is_realized()) {
2593 Glib::RefPtr<Gdk::Window> win = get_window();
2595 int x, y, xoff, yoff, width, height;
2596 win->get_root_origin(x, y);
2597 win->get_position(xoff, yoff);
2598 win->get_size(width, height);
2600 XMLNode* geometry = new XMLNode ("geometry");
2602 snprintf(buf, sizeof(buf), "%d", width);
2603 geometry->add_property("x-size", string(buf));
2604 snprintf(buf, sizeof(buf), "%d", height);
2605 geometry->add_property("y-size", string(buf));
2606 snprintf(buf, sizeof(buf), "%d", x);
2607 geometry->add_property("x-pos", string(buf));
2608 snprintf(buf, sizeof(buf), "%d", y);
2609 geometry->add_property("y-pos", string(buf));
2610 snprintf(buf, sizeof(buf), "%d", xoff);
2611 geometry->add_property("x-off", string(buf));
2612 snprintf(buf, sizeof(buf), "%d", yoff);
2613 geometry->add_property("y-off", string(buf));
2614 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2615 geometry->add_property("edit_pane_pos", string(buf));
2617 node->add_child_nocopy (*geometry);
2620 maybe_add_mixer_strip_width (*node);
2622 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2623 node->add_property ("zoom-focus", buf);
2624 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2625 node->add_property ("zoom", buf);
2626 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2627 node->add_property ("snap-to", buf);
2628 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2629 node->add_property ("snap-mode", buf);
2631 node->add_property ("edit-point", enum_2_string (_edit_point));
2633 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2634 node->add_property ("playhead", buf);
2636 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2637 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2638 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2639 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2640 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2641 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2642 node->add_property ("mouse-mode", enum2str(mouse_mode));
2644 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2646 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2647 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2650 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2652 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2653 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2662 Editor::trackview_by_y_position (double y)
2664 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2668 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2677 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2679 if (!session || snap_mode == SnapOff) {
2683 snap_to_internal (start, direction, for_mark);
2687 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2689 Location* before = 0;
2690 Location* after = 0;
2692 const nframes64_t one_second = session->frame_rate();
2693 const nframes64_t one_minute = session->frame_rate() * 60;
2694 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2695 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2696 nframes64_t presnap = start;
2698 switch (snap_type) {
2700 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2701 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2703 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2707 case SnapToSMPTEFrame:
2708 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2709 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2711 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2715 case SnapToSMPTESeconds:
2716 if (session->smpte_offset_negative())
2718 start += session->smpte_offset ();
2720 start -= session->smpte_offset ();
2722 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2723 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2725 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2728 if (session->smpte_offset_negative())
2730 start -= session->smpte_offset ();
2732 start += session->smpte_offset ();
2736 case SnapToSMPTEMinutes:
2737 if (session->smpte_offset_negative())
2739 start += session->smpte_offset ();
2741 start -= session->smpte_offset ();
2743 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2744 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2746 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2748 if (session->smpte_offset_negative())
2750 start -= session->smpte_offset ();
2752 start += session->smpte_offset ();
2757 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2758 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2760 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2765 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2766 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2768 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2773 start = session->tempo_map().round_to_bar (start, direction);
2777 start = session->tempo_map().round_to_beat (start, direction);
2780 case SnapToAThirtysecondBeat:
2781 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2784 case SnapToASixteenthBeat:
2785 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2788 case SnapToAEighthBeat:
2789 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2792 case SnapToAQuarterBeat:
2793 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2796 case SnapToAThirdBeat:
2797 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2805 before = session->locations()->first_location_before (start);
2806 after = session->locations()->first_location_after (start);
2808 if (direction < 0) {
2810 start = before->start();
2814 } else if (direction > 0) {
2816 start = after->start();
2818 start = session->current_end_frame();
2823 /* find nearest of the two */
2824 if ((start - before->start()) < (after->start() - start)) {
2825 start = before->start();
2827 start = after->start();
2830 start = before->start();
2833 start = after->start();
2840 case SnapToRegionStart:
2841 case SnapToRegionEnd:
2842 case SnapToRegionSync:
2843 case SnapToRegionBoundary:
2844 if (!region_boundary_cache.empty()) {
2845 vector<nframes64_t>::iterator i;
2847 if (direction > 0) {
2848 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2850 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2853 if (i != region_boundary_cache.end()) {
2855 /* lower bound doesn't quite to the right thing for our purposes */
2857 if (direction < 0 && i != region_boundary_cache.begin()) {
2864 start = region_boundary_cache.back();
2870 switch (snap_mode) {
2876 if (presnap > start) {
2877 if (presnap > (start + unit_to_frame(snap_threshold))) {
2881 } else if (presnap < start) {
2882 if (presnap < (start - unit_to_frame(snap_threshold))) {
2888 /* handled at entry */
2895 Editor::snap_length_beats (nframes64_t start)
2901 /* FIXME: This could/should also work with non-tempo based snap settings (ie seconds) */
2903 switch (snap_type) {
2905 return session->tempo_map().meter_at(start).beats_per_bar();
2910 case SnapToAThirtysecondBeat:
2911 return 1.0 / (double)32.0;
2914 case SnapToASixteenthBeat:
2915 return 1.0 / (double)16.0;
2918 case SnapToAEighthBeat:
2919 return 1.0 / (double)8.0;
2922 case SnapToAQuarterBeat:
2923 return 1.0 / (double)4.0;
2926 case SnapToAThirdBeat:
2927 return 1.0 / (double)3.0;
2935 Editor::setup_toolbar ()
2940 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2942 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2945 /* Mode Buttons (tool selection) */
2947 vector<ToggleButton *> mouse_mode_buttons;
2949 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2950 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2951 mouse_mode_buttons.push_back (&mouse_move_button);
2953 if (!Profile->get_sae()) {
2954 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2955 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2956 mouse_mode_buttons.push_back (&mouse_select_button);
2958 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2959 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2960 mouse_mode_buttons.push_back (&mouse_gain_button);
2963 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2964 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2965 mouse_mode_buttons.push_back (&mouse_zoom_button);
2966 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2967 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2968 mouse_mode_buttons.push_back (&mouse_timefx_button);
2969 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2970 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2971 mouse_note_button.add (*(manage (new Image (::get_icon("tool_note")))));
2972 mouse_note_button.set_relief(Gtk::RELIEF_NONE);
2973 mouse_mode_buttons.push_back (&mouse_note_button);
2974 mouse_mode_buttons.push_back (&mouse_audition_button);
2976 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2978 HBox* mode_box = manage(new HBox);
2979 mode_box->set_border_width (2);
2980 mode_box->set_spacing(4);
2981 mouse_mode_button_box.set_spacing(1);
2982 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2983 if (!Profile->get_sae()) {
2984 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2986 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2987 if (!Profile->get_sae()) {
2988 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2990 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2991 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2992 mouse_mode_button_box.pack_start(mouse_note_button, true, true);
2993 mouse_mode_button_box.set_homogeneous(true);
2995 vector<string> edit_mode_strings;
2996 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2997 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2998 edit_mode_strings.push_back (edit_mode_to_string (Lock));
3000 edit_mode_selector.set_name ("EditModeSelector");
3001 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
3002 set_popdown_strings (edit_mode_selector, edit_mode_strings);
3003 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
3005 mode_box->pack_start(edit_mode_selector);
3006 mode_box->pack_start(mouse_mode_button_box);
3008 mouse_mode_tearoff = manage (new TearOff (*mode_box));
3009 mouse_mode_tearoff->set_name ("MouseModeBase");
3011 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3012 &mouse_mode_tearoff->tearoff_window()));
3013 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3014 &mouse_mode_tearoff->tearoff_window(), 1));
3015 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3016 &mouse_mode_tearoff->tearoff_window()));
3017 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3018 &mouse_mode_tearoff->tearoff_window(), 1));
3020 mouse_move_button.set_name ("MouseModeButton");
3021 mouse_select_button.set_name ("MouseModeButton");
3022 mouse_gain_button.set_name ("MouseModeButton");
3023 mouse_zoom_button.set_name ("MouseModeButton");
3024 mouse_timefx_button.set_name ("MouseModeButton");
3025 mouse_audition_button.set_name ("MouseModeButton");
3026 mouse_note_button.set_name ("MouseModeButton");
3028 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
3029 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
3030 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
3031 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
3032 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
3033 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
3034 ARDOUR_UI::instance()->tooltips().set_tip (mouse_note_button, _("Edit MIDI Notes"));
3036 mouse_move_button.unset_flags (CAN_FOCUS);
3037 mouse_select_button.unset_flags (CAN_FOCUS);
3038 mouse_gain_button.unset_flags (CAN_FOCUS);
3039 mouse_zoom_button.unset_flags (CAN_FOCUS);
3040 mouse_timefx_button.unset_flags (CAN_FOCUS);
3041 mouse_audition_button.unset_flags (CAN_FOCUS);
3042 mouse_note_button.unset_flags (CAN_FOCUS);
3044 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
3045 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
3047 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
3048 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
3049 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
3050 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
3051 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
3052 mouse_note_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseNote));
3054 // mouse_move_button.set_active (true);
3059 zoom_box.set_spacing (1);
3060 zoom_box.set_border_width (0);
3062 zoom_in_button.set_name ("EditorTimeButton");
3063 zoom_in_button.set_size_request(-1,16);
3064 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
3065 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
3066 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
3068 zoom_out_button.set_name ("EditorTimeButton");
3069 zoom_out_button.set_size_request(-1,16);
3070 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
3071 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
3072 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
3074 zoom_out_full_button.set_name ("EditorTimeButton");
3075 zoom_out_full_button.set_size_request(-1,16);
3076 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
3077 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
3078 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
3080 zoom_focus_selector.set_name ("ZoomFocusSelector");
3081 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
3082 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
3083 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
3084 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
3086 zoom_box.pack_start (zoom_focus_selector, true, true);
3087 zoom_box.pack_start (zoom_out_button, false, false);
3088 zoom_box.pack_start (zoom_in_button, false, false);
3089 zoom_box.pack_start (zoom_out_full_button, false, false);
3091 snap_box.set_spacing (1);
3092 snap_box.set_border_width (2);
3094 snap_type_selector.set_name ("SnapTypeSelector");
3095 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
3096 set_popdown_strings (snap_type_selector, snap_type_strings);
3097 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
3098 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
3100 snap_mode_selector.set_name ("SnapModeSelector");
3101 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
3102 set_popdown_strings (snap_mode_selector, snap_mode_strings);
3103 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
3104 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3106 edit_point_selector.set_name ("SnapModeSelector");
3107 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
3108 set_popdown_strings (edit_point_selector, edit_point_strings);
3109 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
3110 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
3112 snap_box.pack_start (edit_point_clock, false, false);
3113 snap_box.pack_start (snap_mode_selector, false, false);
3114 snap_box.pack_start (snap_type_selector, false, false);
3115 snap_box.pack_start (edit_point_selector, false, false);
3119 HBox *nudge_box = manage (new HBox);
3120 nudge_box->set_spacing(1);
3121 nudge_box->set_border_width (2);
3123 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
3124 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
3126 nudge_box->pack_start (nudge_backward_button, false, false);
3127 nudge_box->pack_start (nudge_forward_button, false, false);
3128 nudge_box->pack_start (nudge_clock, false, false);
3131 /* Pack everything in... */
3133 HBox* hbox = manage (new HBox);
3134 hbox->set_spacing(10);
3136 tools_tearoff = manage (new TearOff (*hbox));
3137 tools_tearoff->set_name ("MouseModeBase");
3139 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3140 &tools_tearoff->tearoff_window()));
3141 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3142 &tools_tearoff->tearoff_window(), 0));
3143 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3144 &tools_tearoff->tearoff_window()));
3145 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3146 &tools_tearoff->tearoff_window(), 0));
3148 toolbar_hbox.set_spacing (10);
3149 toolbar_hbox.set_border_width (1);
3151 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
3152 toolbar_hbox.pack_start (*tools_tearoff, false, false);
3155 hbox->pack_start (snap_box, false, false);
3156 // hbox->pack_start (zoom_box, false, false);
3157 hbox->pack_start (*nudge_box, false, false);
3161 toolbar_base.set_name ("ToolBarBase");
3162 toolbar_base.add (toolbar_hbox);
3164 toolbar_frame.set_shadow_type (SHADOW_OUT);
3165 toolbar_frame.set_name ("BaseFrame");
3166 toolbar_frame.add (toolbar_base);
3170 Editor::midi_panic_toggle ()
3173 session->midi_panic();
3174 midi_panic_button.set_active (false);
3175 midi_panic_button.set_state (STATE_NORMAL);
3180 Editor::setup_midi_toolbar ()
3184 /* Mode Buttons (tool selection) */
3186 vector<ToggleButton *> midi_tool_buttons;
3188 midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
3189 midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
3190 midi_tool_buttons.push_back (&midi_tool_pencil_button);
3191 midi_tool_select_button.add (*(manage (new Image (::get_icon("midi_tool_select")))));
3192 midi_tool_select_button.set_relief(Gtk::RELIEF_NONE);
3193 midi_tool_buttons.push_back (&midi_tool_select_button);
3194 midi_tool_resize_button.add (*(manage (new Image (::get_icon("strip_width")))));
3195 midi_tool_resize_button.set_relief(Gtk::RELIEF_NONE);
3196 midi_tool_buttons.push_back (&midi_tool_resize_button);
3197 midi_tool_erase_button.add (*(manage (new Image (::get_icon("midi_tool_erase")))));
3198 midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
3199 midi_tool_buttons.push_back (&midi_tool_erase_button);
3201 midi_tool_pencil_button.set_active(true);
3203 midi_tool_button_set = new GroupedButtons (midi_tool_buttons);
3205 midi_tool_button_box.set_border_width (2);
3206 midi_tool_button_box.set_spacing(1);
3207 midi_tool_button_box.pack_start(midi_tool_pencil_button, true, true);
3208 midi_tool_button_box.pack_start(midi_tool_select_button, true, true);
3209 midi_tool_button_box.pack_start(midi_tool_resize_button, true, true);
3210 midi_tool_button_box.pack_start(midi_tool_erase_button, true, true);
3211 midi_tool_button_box.set_homogeneous(true);
3213 midi_tool_pencil_button.set_name ("MouseModeButton");
3214 midi_tool_select_button.set_name ("MouseModeButton");
3215 midi_tool_resize_button.set_name ("MouseModeButton");
3216 midi_tool_erase_button.set_name ("MouseModeButton");
3218 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
3219 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
3220 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
3221 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
3223 midi_tool_pencil_button.unset_flags (CAN_FOCUS);
3224 midi_tool_select_button.unset_flags (CAN_FOCUS);
3225 midi_tool_resize_button.unset_flags (CAN_FOCUS);
3226 midi_tool_erase_button.unset_flags (CAN_FOCUS);
3228 midi_tool_pencil_button.signal_toggled().connect (bind (mem_fun(*this,
3229 &Editor::midi_edit_mode_toggled), Editing::MidiEditPencil));
3230 midi_tool_select_button.signal_toggled().connect (bind (mem_fun(*this,
3231 &Editor::midi_edit_mode_toggled), Editing::MidiEditSelect));
3232 midi_tool_resize_button.signal_toggled().connect (bind (mem_fun(*this,
3233 &Editor::midi_edit_mode_toggled), Editing::MidiEditResize));
3234 midi_tool_erase_button.signal_toggled().connect (bind (mem_fun(*this,
3235 &Editor::midi_edit_mode_toggled), Editing::MidiEditErase));
3239 VBox* panic_box = manage (new VBox);
3240 midi_panic_button.set_name("MidiPanicButton");
3241 midi_panic_button.signal_pressed().connect (
3242 mem_fun(this, &Editor::midi_panic_toggle));
3243 panic_box->pack_start (midi_panic_button, true, true);
3245 /* Pack everything in... */
3247 midi_tools_tearoff = manage (new TearOff (midi_tool_button_box));
3248 midi_tools_tearoff->set_name ("MouseModeBase");
3251 midi_tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3252 &midi_tools_tearoff->tearoff_window()));
3253 midi_tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3254 &midi_tools_tearoff->tearoff_window(), 0));
3255 midi_tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3256 &midi_tools_tearoff->tearoff_window()));
3257 midi_tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3258 &midi_tools_tearoff->tearoff_window(), 0));
3261 midi_toolbar_hbox.set_spacing (10);
3262 midi_toolbar_hbox.set_border_width (1);
3264 midi_toolbar_hbox.pack_start (*midi_tools_tearoff, false, true);
3266 midi_toolbar_hbox.pack_start(*panic_box, false, true, 4);
3268 midi_tool_button_box.show_all ();
3269 midi_toolbar_hbox.show_all();
3270 midi_tools_tearoff->show_all();
3272 midi_toolbar_base.set_name ("ToolBarBase");
3273 midi_toolbar_base.add (midi_toolbar_hbox);
3275 midi_toolbar_frame.set_shadow_type (SHADOW_OUT);
3276 midi_toolbar_frame.set_name ("BaseFrame");
3277 midi_toolbar_frame.add (midi_toolbar_base);
3281 Editor::convert_drop_to_paths (vector<ustring>& paths,
3282 const RefPtr<Gdk::DragContext>& context,
3285 const SelectionData& data,
3294 vector<ustring> uris = data.get_uris();
3298 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3299 are actually URI lists. So do it by hand.
3302 if (data.get_target() != "text/plain") {
3306 /* Parse the "uri-list" format that Nautilus provides,
3307 where each pathname is delimited by \r\n
3310 const char* p = data.get_text().c_str();
3317 while (g_ascii_isspace (*p))
3321 while (*q && (*q != '\n') && (*q != '\r'))
3327 while (q > p && g_ascii_isspace (*q))
3332 uris.push_back (ustring (p, q - p + 1));
3336 p = strchr (p, '\n');
3346 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3348 if ((*i).substr (0,7) == "file://") {
3351 PBD::url_decode (p);
3353 // scan forward past three slashes
3355 ustring::size_type slashcnt = 0;
3356 ustring::size_type n = 0;
3357 ustring::iterator x = p.begin();
3359 while (slashcnt < 3 && x != p.end()) {
3362 } else if (slashcnt == 3) {
3369 if (slashcnt != 3 || x == p.end()) {
3370 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3374 paths.push_back (p.substr (n - 1));
3382 Editor::new_tempo_section ()
3388 Editor::map_transport_state ()
3390 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3392 if (session->transport_stopped()) {
3393 have_pending_keyboard_selection = false;
3396 update_loop_range_view (true);
3401 Editor::State::State (PublicEditor const * e)
3403 selection = new Selection (e);
3406 Editor::State::~State ()
3412 Editor::get_memento () const
3414 State *state = new State (this);
3416 store_state (*state);
3417 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
3421 Editor::store_state (State& state) const
3423 *state.selection = *selection;
3427 Editor::restore_state (State *state)
3429 if (*selection == *state->selection) {
3433 *selection = *state->selection;
3434 time_selection_changed ();
3435 region_selection_changed ();
3437 /* XXX other selection change handlers? */
3441 Editor::begin_reversible_command (string name)
3444 before = &get_state();
3445 session->begin_reversible_command (name);
3450 Editor::commit_reversible_command ()
3453 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3458 Editor::set_edit_group_solo (Route& route, bool yn)
3460 RouteGroup *edit_group;
3462 if ((edit_group = route.edit_group()) != 0) {
3463 edit_group->apply (&Route::set_solo, yn, this);
3465 route.set_solo (yn, this);
3470 Editor::set_edit_group_mute (Route& route, bool yn)
3472 RouteGroup *edit_group = 0;
3474 if ((edit_group == route.edit_group()) != 0) {
3475 edit_group->apply (&Route::set_mute, yn, this);
3477 route.set_mute (yn, this);
3482 Editor::history_changed ()
3486 if (undo_action && session) {
3487 if (session->undo_depth() == 0) {
3490 label = string_compose(_("Undo (%1)"), session->next_undo());
3492 undo_action->property_label() = label;
3495 if (redo_action && session) {
3496 if (session->redo_depth() == 0) {
3499 label = string_compose(_("Redo (%1)"), session->next_redo());
3501 redo_action->property_label() = label;
3506 Editor::duplicate_dialog (bool with_dialog)
3510 if (mouse_mode == MouseRange) {
3511 if (selection->time.length() == 0) {
3517 get_regions_for_action (rs);
3519 if (mouse_mode != MouseRange) {
3528 ArdourDialog win ("Duplication Dialog");
3529 Label label (_("Number of Duplications:"));
3530 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3531 SpinButton spinner (adjustment, 0.0, 1);
3534 win.get_vbox()->set_spacing (12);
3535 win.get_vbox()->pack_start (hbox);
3536 hbox.set_border_width (6);
3537 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3539 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3540 place, visually. so do this by hand.
3543 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3544 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3545 spinner.grab_focus();
3551 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3552 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3553 win.set_default_response (RESPONSE_ACCEPT);
3555 win.set_position (WIN_POS_MOUSE);
3557 spinner.grab_focus ();
3559 switch (win.run ()) {
3560 case RESPONSE_ACCEPT:
3566 times = adjustment.get_value();
3569 if (mouse_mode == MouseRange) {
3570 duplicate_selection (times);
3572 duplicate_some_regions (rs, times);
3577 Editor::show_verbose_canvas_cursor ()
3579 verbose_canvas_cursor->raise_to_top();
3580 verbose_canvas_cursor->show();
3581 verbose_cursor_visible = true;
3585 Editor::hide_verbose_canvas_cursor ()
3587 verbose_canvas_cursor->hide();
3588 verbose_cursor_visible = false;
3592 Editor::clamp_verbose_cursor_x (double x)
3597 x = min (canvas_width - 200.0, x);
3603 Editor::clamp_verbose_cursor_y (double y)
3605 if (y < canvas_timebars_vsize) {
3606 y = canvas_timebars_vsize;
3608 y = min (canvas_height - 50, y);
3614 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3616 verbose_canvas_cursor->property_text() = txt.c_str();
3617 /* don't get too close to the edge */
3618 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3619 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3623 Editor::set_verbose_canvas_cursor_text (const string & txt)
3625 verbose_canvas_cursor->property_text() = txt.c_str();
3629 Editor::set_edit_mode (EditMode m)
3631 Config->set_edit_mode (m);
3635 Editor::cycle_edit_mode ()
3637 switch (Config->get_edit_mode()) {
3639 Config->set_edit_mode (Splice);
3642 Config->set_edit_mode (Lock);
3645 Config->set_edit_mode (Slide);
3651 Editor::edit_mode_selection_done ()
3657 string choice = edit_mode_selector.get_active_text();
3658 EditMode mode = Slide;
3660 if (choice == _("Splice Edit")) {
3662 } else if (choice == _("Slide Edit")) {
3664 } else if (choice == _("Lock Edit")) {
3668 Config->set_edit_mode (mode);
3672 Editor::snap_type_selection_done ()
3674 string choice = snap_type_selector.get_active_text();
3675 SnapType snaptype = SnapToBeat;
3677 if (choice == _("Beats/3")) {
3678 snaptype = SnapToAThirdBeat;
3679 } else if (choice == _("Beats/4")) {
3680 snaptype = SnapToAQuarterBeat;
3681 } else if (choice == _("Beats/8")) {
3682 snaptype = SnapToAEighthBeat;
3683 } else if (choice == _("Beats/16")) {
3684 snaptype = SnapToASixteenthBeat;
3685 } else if (choice == _("Beats/32")) {
3686 snaptype = SnapToAThirtysecondBeat;
3687 } else if (choice == _("Beats")) {
3688 snaptype = SnapToBeat;
3689 } else if (choice == _("Bars")) {
3690 snaptype = SnapToBar;
3691 } else if (choice == _("Marks")) {
3692 snaptype = SnapToMark;
3693 } else if (choice == _("Region starts")) {
3694 snaptype = SnapToRegionStart;
3695 } else if (choice == _("Region ends")) {
3696 snaptype = SnapToRegionEnd;
3697 } else if (choice == _("Region bounds")) {
3698 snaptype = SnapToRegionBoundary;
3699 } else if (choice == _("Region syncs")) {
3700 snaptype = SnapToRegionSync;
3701 } else if (choice == _("CD Frames")) {
3702 snaptype = SnapToCDFrame;
3703 } else if (choice == _("SMPTE Frames")) {
3704 snaptype = SnapToSMPTEFrame;
3705 } else if (choice == _("SMPTE Seconds")) {
3706 snaptype = SnapToSMPTESeconds;
3707 } else if (choice == _("SMPTE Minutes")) {
3708 snaptype = SnapToSMPTEMinutes;
3709 } else if (choice == _("Seconds")) {
3710 snaptype = SnapToSeconds;
3711 } else if (choice == _("Minutes")) {
3712 snaptype = SnapToMinutes;
3715 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3717 ract->set_active ();
3722 Editor::snap_mode_selection_done ()
3724 string choice = snap_mode_selector.get_active_text();
3725 SnapMode mode = SnapNormal;
3727 if (choice == _("No Grid")) {
3729 } else if (choice == _("Grid")) {
3731 } else if (choice == _("Magnetic")) {
3732 mode = SnapMagnetic;
3735 RefPtr<RadioAction> ract = snap_mode_action (mode);
3738 ract->set_active (true);
3743 Editor::cycle_edit_point (bool with_marker)
3745 switch (_edit_point) {
3747 set_edit_point_preference (EditAtPlayhead);
3749 case EditAtPlayhead:
3751 set_edit_point_preference (EditAtSelectedMarker);
3753 set_edit_point_preference (EditAtMouse);
3756 case EditAtSelectedMarker:
3757 set_edit_point_preference (EditAtMouse);
3763 Editor::edit_point_selection_done ()
3765 string choice = edit_point_selector.get_active_text();
3766 EditPoint ep = EditAtSelectedMarker;
3768 if (choice == _("Marker")) {
3769 set_edit_point_preference (EditAtSelectedMarker);
3770 } else if (choice == _("Playhead")) {
3771 set_edit_point_preference (EditAtPlayhead);
3773 set_edit_point_preference (EditAtMouse);
3776 RefPtr<RadioAction> ract = edit_point_action (ep);
3779 ract->set_active (true);
3784 Editor::zoom_focus_selection_done ()
3786 string choice = zoom_focus_selector.get_active_text();
3787 ZoomFocus focus_type = ZoomFocusLeft;
3789 if (choice == _("Left")) {
3790 focus_type = ZoomFocusLeft;
3791 } else if (choice == _("Right")) {
3792 focus_type = ZoomFocusRight;
3793 } else if (choice == _("Center")) {
3794 focus_type = ZoomFocusCenter;
3795 } else if (choice == _("Play")) {
3796 focus_type = ZoomFocusPlayhead;
3797 } else if (choice == _("Edit")) {
3798 focus_type = ZoomFocusEdit;
3799 } else if (choice == _("Active Mark")) {
3800 focus_type = ZoomFocusEdit;
3801 } else if (choice == _("Active Mark")) {
3802 focus_type = ZoomFocusEdit;
3804 focus_type = ZoomFocusMouse;
3807 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3810 ract->set_active ();
3815 Editor::edit_controls_button_release (GdkEventButton* ev)
3817 if (Keyboard::is_context_menu_event (ev)) {
3818 ARDOUR_UI::instance()->add_route (this);
3824 Editor::mouse_select_button_release (GdkEventButton* ev)
3826 /* this handles just right-clicks */
3828 if (ev->button != 3) {
3835 Editor::TrackViewList *
3836 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3839 TrackViewList::iterator i;
3841 v = new TrackViewList;
3843 if (track == 0 && group == 0) {
3847 for (i = track_views.begin(); i != track_views.end (); ++i) {
3851 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->is_active())) {
3853 /* just the view for this track
3856 v->push_back (track);
3860 /* views for all tracks in the edit group */
3862 for (i = track_views.begin(); i != track_views.end (); ++i) {
3864 if (group == 0 || (*i)->edit_group() == group) {
3874 Editor::set_zoom_focus (ZoomFocus f)
3876 string str = zoom_focus_strings[(int)f];
3878 if (str != zoom_focus_selector.get_active_text()) {
3879 zoom_focus_selector.set_active_text (str);
3882 if (zoom_focus != f) {
3885 ZoomFocusChanged (); /* EMIT_SIGNAL */
3892 Editor::ensure_float (Window& win)
3894 win.set_transient_for (*this);
3898 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3900 /* recover or initialize pane positions. do this here rather than earlier because
3901 we don't want the positions to change the child allocations, which they seem to do.
3907 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3909 static int32_t done;
3912 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3913 width = default_width;
3914 height = default_height;
3916 width = atoi(geometry->property("x-size")->value());
3917 height = atoi(geometry->property("y-size")->value());
3920 if (which == static_cast<Paned*> (&edit_pane)) {
3926 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3927 /* initial allocation is 90% to canvas, 10% to notebook */
3928 pos = (int) floor (alloc.get_width() * 0.90f);
3929 snprintf (buf, sizeof(buf), "%d", pos);
3931 pos = atoi (prop->value());
3934 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3935 edit_pane.set_position (pos);
3936 pre_maximal_pane_position = pos;
3942 Editor::detach_tearoff (Box* b, Window* w)
3944 if (tools_tearoff->torn_off() &&
3945 mouse_mode_tearoff->torn_off()) {
3946 top_hbox.remove (toolbar_frame);
3951 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3953 if (toolbar_frame.get_parent() == 0) {
3954 top_hbox.pack_end (toolbar_frame);
3959 Editor::set_show_measures (bool yn)
3961 if (_show_measures != yn) {
3964 if ((_show_measures = yn) == true) {
3966 tempo_lines->show();
3974 Editor::toggle_follow_playhead ()
3976 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3978 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3979 set_follow_playhead (tact->get_active());
3984 Editor::set_follow_playhead (bool yn)
3986 if (_follow_playhead != yn) {
3987 if ((_follow_playhead = yn) == true) {
3989 update_current_screen ();
3996 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3998 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
4000 xfade->set_active (!xfade->active());
4005 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
4007 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
4009 xfade->set_follow_overlap (!xfade->following_overlap());
4014 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
4016 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
4022 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
4026 switch (cew.run ()) {
4027 case RESPONSE_ACCEPT:
4034 xfade->StateChanged (Change (~0));
4038 Editor::playlist_selector () const
4040 return *_playlist_selector;
4044 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
4048 ret = nudge_clock.current_duration (pos);
4049 next = ret + 1; /* XXXX fix me */
4055 Editor::end_location_changed (Location* location)
4057 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
4058 //reset_scrolling_region ();
4059 horizontal_adjustment.set_upper ( location->start());
4063 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
4065 ArdourDialog dialog ("playlist deletion dialog");
4066 Label label (string_compose (_("Playlist %1 is currently unused.\n"
4067 "If left alone, no audio files used by it will be cleaned.\n"
4068 "If deleted, audio files used by it alone by will cleaned."),
4071 dialog.set_position (WIN_POS_CENTER);
4072 dialog.get_vbox()->pack_start (label);
4076 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
4077 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
4078 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
4080 switch (dialog.run ()) {
4081 case RESPONSE_ACCEPT:
4082 /* delete the playlist */
4086 case RESPONSE_REJECT:
4087 /* keep the playlist */
4099 Editor::audio_region_selection_covers (nframes64_t where)
4101 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
4102 if ((*a)->region()->covers (where)) {
4111 Editor::prepare_for_cleanup ()
4113 cut_buffer->clear_regions ();
4114 cut_buffer->clear_playlists ();
4116 selection->clear_regions ();
4117 selection->clear_playlists ();
4119 no_region_list_redisplay = true;
4123 Editor::finish_cleanup ()
4125 no_region_list_redisplay = false;
4126 redisplay_regions ();
4130 Editor::transport_loop_location()
4133 return session->locations()->auto_loop_location();
4140 Editor::transport_punch_location()
4143 return session->locations()->auto_punch_location();
4150 Editor::control_layout_scroll (GdkEventScroll* ev)
4152 switch (ev->direction) {
4154 scroll_tracks_up_line ();
4158 case GDK_SCROLL_DOWN:
4159 scroll_tracks_down_line ();
4163 /* no left/right handling yet */
4171 /** A new snapshot has been selected.
4174 Editor::snapshot_display_selection_changed ()
4176 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
4178 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
4180 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
4182 if (snap_name.length() == 0) {
4186 if (session->snap_name() == snap_name) {
4190 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
4195 Editor::snapshot_display_button_press (GdkEventButton* ev)
4197 if (ev->button == 3) {
4198 /* Right-click on the snapshot list. Work out which snapshot it
4200 Gtk::TreeModel::Path path;
4201 Gtk::TreeViewColumn* col;
4204 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
4205 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
4207 Gtk::TreeModel::Row row = *iter;
4208 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
4217 /** Pop up the snapshot display context menu.
4218 * @param button Button used to open the menu.
4219 * @param time Menu open time.
4220 * @snapshot_name Name of the snapshot that the menu click was over.
4224 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
4226 using namespace Menu_Helpers;
4228 MenuList& items (snapshot_context_menu.items());
4231 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
4233 add_item_with_sensitivity (items, MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)), modification_allowed);
4235 add_item_with_sensitivity (items, MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)), modification_allowed);
4237 snapshot_context_menu.popup (button, time);
4241 Editor::rename_snapshot (Glib::ustring old_name)
4243 ArdourPrompter prompter(true);
4247 prompter.set_name ("Prompter");
4248 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
4249 prompter.set_prompt (_("New name of snapshot"));
4250 prompter.set_initial_text (old_name);
4252 if (prompter.run() == RESPONSE_ACCEPT) {
4253 prompter.get_result (new_name);
4254 if (new_name.length()) {
4255 session->rename_state (old_name, new_name);
4256 redisplay_snapshots ();
4263 Editor::remove_snapshot (Glib::ustring name)
4265 vector<string> choices;
4267 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
4269 choices.push_back (_("No, do nothing."));
4270 choices.push_back (_("Yes, remove it."));
4272 Gtkmm2ext::Choice prompter (prompt, choices);
4274 if (prompter.run () == 1) {
4275 session->remove_state (name);
4276 redisplay_snapshots ();
4281 Editor::redisplay_snapshots ()
4287 vector<sys::path> state_file_paths;
4289 get_state_files_in_directory (session->session_directory().root_path(),
4292 if (state_file_paths.empty()) return;
4294 vector<string> state_file_names(get_file_names_no_extension(state_file_paths));
4296 snapshot_display_model->clear ();
4298 for (vector<string>::iterator i = state_file_names.begin();
4299 i != state_file_names.end(); ++i)
4301 string statename = (*i);
4302 TreeModel::Row row = *(snapshot_display_model->append());
4304 /* this lingers on in case we ever want to change the visible
4305 name of the snapshot.
4308 string display_name;
4309 display_name = statename;
4311 if (statename == session->snap_name()) {
4312 snapshot_display.get_selection()->select(row);
4315 row[snapshot_display_columns.visible_name] = display_name;
4316 row[snapshot_display_columns.real_name] = statename;
4321 Editor::session_state_saved (string snap_name)
4323 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4324 redisplay_snapshots ();
4328 Editor::maximise_editing_space ()
4330 mouse_mode_tearoff->set_visible (false);
4331 tools_tearoff->set_visible (false);
4333 pre_maximal_pane_position = edit_pane.get_position();
4334 pre_maximal_editor_width = this->get_width();
4336 if(post_maximal_pane_position == 0) {
4337 post_maximal_pane_position = edit_pane.get_width();
4342 if(post_maximal_editor_width) {
4343 edit_pane.set_position (post_maximal_pane_position -
4344 abs(post_maximal_editor_width - pre_maximal_editor_width));
4346 edit_pane.set_position (post_maximal_pane_position);
4351 Editor::restore_editing_space ()
4353 // user changed width of pane during fullscreen
4355 if(post_maximal_pane_position != edit_pane.get_position()) {
4356 post_maximal_pane_position = edit_pane.get_position();
4361 mouse_mode_tearoff->set_visible (true);
4362 tools_tearoff->set_visible (true);
4363 post_maximal_editor_width = this->get_width();
4365 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4369 * Make new playlists for a given track and also any others that belong
4370 * to the same active edit group.
4375 Editor::new_playlists (TimeAxisView* v)
4377 begin_reversible_command (_("new playlists"));
4378 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4379 session->get_playlists(playlists);
4380 mapover_tracks ( bind(mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v );
4381 commit_reversible_command ();
4385 * Use a copy of the current playlist for a given track and also any others that belong
4386 * to the same active edit group.
4391 Editor::copy_playlists (TimeAxisView* v)
4393 begin_reversible_command (_("copy playlists"));
4394 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4395 session->get_playlists(playlists);
4396 mapover_tracks ( bind(mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v );
4397 commit_reversible_command ();
4401 * Clear the current playlist for a given track and also any others that belong
4402 * to the same active edit group.
4407 Editor::clear_playlists (TimeAxisView* v)
4409 begin_reversible_command (_("clear playlists"));
4410 vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
4411 session->get_playlists(playlists);
4412 mapover_tracks ( mem_fun (*this, &Editor::mapped_clear_playlist), v );
4413 commit_reversible_command ();
4417 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4419 atv.use_new_playlist (sz > 1 ? false : true, playlists);
4423 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
4425 atv.use_copy_playlist (sz > 1 ? false : true, playlists);
4429 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t sz)
4431 atv.clear_playlist ();
4435 Editor::on_key_press_event (GdkEventKey* ev)
4437 return key_press_focus_accelerator_handler (*this, ev);
4441 Editor::on_key_release_event (GdkEventKey* ev)
4443 return Gtk::Window::on_key_release_event (ev);
4444 // return key_press_focus_accelerator_handler (*this, ev);
4448 Editor::reset_x_origin (nframes64_t frame)
4450 //cerr << "resetting x origin" << endl;
4451 queue_visual_change (frame);
4455 Editor::reset_zoom (double fpu)
4457 queue_visual_change (fpu);
4461 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4463 //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
4464 reset_x_origin (frame);
4467 if (!no_save_visual) {
4468 undo_visual_stack.push_back (current_visual_state(false));
4472 Editor::VisualState*
4473 Editor::current_visual_state (bool with_tracks)
4475 VisualState* vs = new VisualState;
4476 vs->y_position = vertical_adjustment.get_value();
4477 vs->frames_per_unit = frames_per_unit;
4478 vs->leftmost_frame = leftmost_frame;
4479 vs->zoom_focus = zoom_focus;
4480 vs->zoomed_to_region = zoomed_to_region;
4483 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4484 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4492 Editor::undo_visual_state ()
4494 if (undo_visual_stack.empty()) {
4498 VisualState* vs = undo_visual_stack.back();
4499 undo_visual_stack.pop_back();
4500 use_visual_state (*vs);
4501 redo_visual_stack.push_back (vs);
4505 Editor::redo_visual_state ()
4507 if (redo_visual_stack.empty()) {
4511 VisualState* vs = redo_visual_stack.back();
4512 redo_visual_stack.pop_back();
4513 use_visual_state (*vs);
4514 undo_visual_stack.push_back (vs);
4518 Editor::swap_visual_state ()
4520 if (undo_visual_stack.empty()) {
4521 redo_visual_state ();
4523 undo_visual_state ();
4528 Editor::use_visual_state (VisualState& vs)
4530 no_save_visual = true;
4531 no_route_list_redisplay = true;
4533 vertical_adjustment.set_value (vs.y_position);
4535 set_zoom_focus (vs.zoom_focus);
4536 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4538 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4539 TrackViewList::iterator t;
4541 /* check if the track still exists - it could have been deleted */
4543 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4544 (*t)->set_state (*(i->second));
4549 if (!vs.track_states.empty()) {
4550 update_route_visibility ();
4553 no_route_list_redisplay = false;
4554 redisplay_route_list ();
4556 no_save_visual = false;
4560 Editor::set_frames_per_unit (double fpu)
4562 /* this is the core function that controls the zoom level of the canvas. it is called
4563 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4566 if (fpu == frames_per_unit) {
4575 /* don't allow zooms that fit more than the maximum number
4576 of frames into an 800 pixel wide space.
4579 if (max_frames / fpu < 800.0) {
4584 tempo_lines->tempo_map_changed();
4586 frames_per_unit = fpu;
4591 Editor::post_zoom ()
4593 // convert fpu to frame count
4595 nframes64_t frames = (nframes64_t) floor (frames_per_unit * canvas_width);
4597 if (frames_per_unit != zoom_range_clock.current_duration()) {
4598 zoom_range_clock.set (frames);
4601 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4602 if (!selection->tracks.empty()) {
4603 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4604 (*i)->reshow_selection (selection->time);
4607 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4608 (*i)->reshow_selection (selection->time);
4613 ZoomChanged (); /* EMIT_SIGNAL */
4615 reset_hscrollbar_stepping ();
4616 //reset_scrolling_region ();
4618 if (playhead_cursor) {
4619 playhead_cursor->set_position (playhead_cursor->current_frame);
4626 Editor::queue_visual_change (nframes64_t where)
4628 // pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4629 // pending_visual_change.time_origin = where;
4631 if (pending_visual_change.idle_handler_id < 0) {
4632 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4633 pending_visual_change.time_origin = where;
4634 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4639 Editor::queue_visual_change (double fpu)
4641 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4642 pending_visual_change.frames_per_unit = fpu;
4644 if (pending_visual_change.idle_handler_id < 0) {
4645 pending_visual_change.idle_handler_id = g_idle_add ( _idle_visual_changer, this);
4651 Editor::_idle_visual_changer (void* arg)
4653 return static_cast<Editor*>(arg)->idle_visual_changer ();
4657 Editor::idle_visual_changer ()
4659 VisualChange::Type p = pending_visual_change.pending;
4660 pending_visual_change.pending = (VisualChange::Type) 0;
4662 if (p & VisualChange::ZoomLevel) {
4663 set_frames_per_unit (pending_visual_change.frames_per_unit);
4665 compute_fixed_ruler_scale ();
4666 compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + (nframes_t)(edit_packer.get_width() * pending_visual_change.frames_per_unit));
4667 compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + (nframes_t)(edit_packer.get_width() * pending_visual_change.frames_per_unit));
4668 update_tempo_based_rulers ();
4670 if (p & VisualChange::TimeOrigin) {
4672 nframes64_t csf=0, cef=0;
4673 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4676 csf = session->current_start_frame();
4677 cef = session->current_end_frame() + (current_page_frames() / 24);// Add a little extra so we can see the end marker
4680 /* if we seek beyond the current end of the canvas, move the end */
4682 if (current_time_origin != pending_visual_change.time_origin) {
4683 last_canvas_frame = (cef > (pending_visual_change.time_origin + current_page_frames())) ? cef : pending_visual_change.time_origin + current_page_frames();
4684 horizontal_adjustment.set_upper ((cef - csf) / frames_per_unit);
4685 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4687 update_fixed_rulers();
4688 redisplay_tempo (true);
4691 //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
4692 pending_visual_change.idle_handler_id = -1;
4693 return 0; /* this is always a one-shot call */
4696 struct EditorOrderTimeAxisSorter {
4697 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4698 return a->order < b->order;
4703 Editor::sort_track_selection (TrackSelection* sel)
4705 EditorOrderTimeAxisSorter cmp;
4710 selection->tracks.sort (cmp);
4715 Editor::get_preferred_edit_position (bool ignore_playhead)
4718 nframes64_t where = 0;
4719 EditPoint ep = _edit_point;
4721 if (entered_marker) {
4722 return entered_marker->position();
4725 if (ignore_playhead && ep == EditAtPlayhead) {
4726 ep = EditAtSelectedMarker;
4730 case EditAtPlayhead:
4731 where = session->audible_frame();
4734 case EditAtSelectedMarker:
4735 if (!selection->markers.empty()) {
4737 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4740 where = loc->start();
4751 if (!mouse_frame (where, ignored)) {
4752 /* XXX not right but what can we do ? */
4763 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4765 if (!session) return;
4767 begin_reversible_command (cmd);
4771 if ((tll = transport_loop_location()) == 0) {
4772 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4773 XMLNode &before = session->locations()->get_state();
4774 session->locations()->add (loc, true);
4775 session->set_auto_loop_location (loc);
4776 XMLNode &after = session->locations()->get_state();
4777 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4779 XMLNode &before = tll->get_state();
4780 tll->set_hidden (false, this);
4781 tll->set (start, end);
4782 XMLNode &after = tll->get_state();
4783 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4786 commit_reversible_command ();
4790 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4792 if (!session) return;
4794 begin_reversible_command (cmd);
4798 if ((tpl = transport_punch_location()) == 0) {
4799 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4800 XMLNode &before = session->locations()->get_state();
4801 session->locations()->add (loc, true);
4802 session->set_auto_loop_location (loc);
4803 XMLNode &after = session->locations()->get_state();
4804 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4807 XMLNode &before = tpl->get_state();
4808 tpl->set_hidden (false, this);
4809 tpl->set (start, end);
4810 XMLNode &after = tpl->get_state();
4811 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4814 commit_reversible_command ();
4818 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4820 const TrackSelection* tracks;
4823 tracks = &track_views;
4828 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4830 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4833 boost::shared_ptr<Diskstream> ds;
4834 boost::shared_ptr<Playlist> pl;
4836 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4838 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)where * ds->speed()));
4840 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4842 RegionView* rv = atv->audio_view()->find_view (*i);
4856 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4858 const TrackSelection* tracks;
4861 tracks = &track_views;
4866 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4868 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4871 boost::shared_ptr<Diskstream> ds;
4872 boost::shared_ptr<Playlist> pl;
4874 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4876 Playlist::RegionList* regions = pl->regions_touched ((nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4878 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4880 RegionView* rv = atv->audio_view()->find_view (*i);
4894 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4896 if (selection->regions.empty()) {
4898 if (selection->tracks.empty()) {
4900 /* no regions or tracks selected
4903 if (entered_regionview && mouse_mode == Editing::MouseObject) {
4905 /* entered regionview is valid and we're in object mode -
4906 just use entered regionview
4909 rs.add (entered_regionview);
4916 /* no regions selected, so get all regions at the edit point across
4917 all selected tracks.
4920 nframes64_t where = get_preferred_edit_position();
4921 get_regions_at (rs, where, selection->tracks);
4923 /* if the entered regionview wasn't selected and neither was its track
4927 if (entered_regionview != 0 &&
4928 !selection->selected (entered_regionview) &&
4929 !selection->selected (&entered_regionview->get_time_axis_view())) {
4930 rs.add (entered_regionview);
4936 /* just use the selected regions */
4938 rs = selection->regions;
4940 /* if the entered regionview wasn't selected and we allow this sort of thing,
4944 if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
4945 rs.add (entered_regionview);
4952 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4955 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4957 RouteTimeAxisView* tatv;
4959 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4961 boost::shared_ptr<Playlist> pl;
4962 vector<boost::shared_ptr<Region> > results;
4964 boost::shared_ptr<Diskstream> ds;
4966 if ((ds = tatv->get_diskstream()) == 0) {
4971 if ((pl = (ds->playlist())) != 0) {
4972 pl->get_region_list_equivalent_regions (region, results);
4975 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4976 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4977 regions.push_back (marv);
4986 Editor::show_rhythm_ferret ()
4988 if (rhythm_ferret == 0) {
4989 rhythm_ferret = new RhythmFerret(*this);
4992 rhythm_ferret->set_session (session);
4993 rhythm_ferret->show ();
4994 rhythm_ferret->present ();
4998 Editor::first_idle ()
5000 MessageDialog* dialog = 0;
5002 if (track_views.size() > 1) {
5003 dialog = new MessageDialog (*this,
5004 _("Please wait while Ardour loads visual data"),
5009 ARDOUR_UI::instance()->flush_pending ();
5012 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
5024 Editor::start_resize_line_ops ()
5027 old_resize_line_y = -1;
5029 need_resize_line = true;
5034 Editor::end_resize_line_ops ()
5037 need_resize_line = false;
5039 if (old_resize_line_y >= 0) {
5040 Gdk::Rectangle r (0, old_resize_line_y, (int) canvas_width, 3);
5041 Glib::RefPtr<Gdk::Window> win = get_window();
5042 cerr << "Final invalidation at " << old_resize_line_y << endl;
5043 win->invalidate_rect (r, false);
5049 Editor::queue_draw_resize_line (int at)
5052 Glib::RefPtr<Gdk::Window> win = get_window();
5056 if (win && canvas_width) {
5058 int controls_width = controls_layout.get_width();
5061 controls_layout.get_window()->get_origin (xroot, discard);
5063 if (old_resize_line_y >= 0) {
5065 /* redraw where it used to be */
5068 Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) canvas_width, 3);
5069 win->invalidate_rect (r, true);
5070 cerr << "invalidate " << xroot << "," << old_resize_line_y - 1 << ' '
5071 << controls_width + canvas_width << " x 3\n";
5074 /* draw where it is */
5076 Gdk::Rectangle r (0, at - 1, controls_width + (int) canvas_width, 3);
5077 win->invalidate_rect (r, true);
5083 Editor::on_expose_event (GdkEventExpose* ev)
5085 /* cerr << "+++ editor expose "
5086 << ev->area.x << ',' << ev->area.y
5088 << ev->area.width << " x " << ev->area.height
5089 << " need reize ? " << need_resize_line
5092 bool ret = Window::on_expose_event (ev);
5095 if (need_resize_line) {
5097 int xroot, yroot, discard;
5100 /* Our root coordinates for drawing the line will be the left edge
5101 of the track controls, and the upper left edge of our own window.
5104 get_window()->get_origin (discard, yroot);
5105 controls_layout.get_window()->get_origin (xroot, discard);
5106 controls_width = controls_layout.get_width();
5109 GdkRectangle intersection;
5112 lr.y = resize_line_y;
5113 lr.width = controls_width + (int) canvas_width;
5116 if (gdk_rectangle_intersect (&lr, &ev->area, &intersection)) {
5118 Glib::RefPtr<Gtk::Style> style (get_style());
5119 Glib::RefPtr<Gdk::GC> black_gc (style->get_black_gc ());
5120 Glib::RefPtr<Gdk::GC> gc = wrap (black_gc->gobj_copy(), false);
5122 /* draw on root window */
5124 GdkWindow* win = gdk_get_default_root_window();
5126 gc->set_subwindow (Gdk::INCLUDE_INFERIORS);
5127 gc->set_line_attributes (3, Gdk::LINE_SOLID,
5131 gdk_draw_line (win, gc->gobj(),
5134 (int) canvas_width + controls_width,
5137 cerr << "drew line @ " << xroot << ", " << yroot + resize_line_y
5138 << " to " << xroot + (int) canvas_width + controls_width
5139 << ", " << yroot + resize_line_y
5142 old_resize_line_y = resize_line_y;
5143 cerr << "NEXT EXPOSE SHOULD BE AT " << old_resize_line_y << endl;
5145 cerr << "no intersect with "
5146 << lr.x << ',' << lr.y
5148 << lr.width << " x " << lr.height
5153 //cerr << "--- editor expose\n";
5160 _idle_resizer (gpointer arg)
5162 return ((Editor*)arg)->idle_resize ();
5166 Editor::add_to_idle_resize (TimeAxisView* view, uint32_t h)
5168 if (resize_idle_id < 0) {
5169 resize_idle_id = g_idle_add (_idle_resizer, this);
5172 resize_idle_target = h;
5174 pending_resizes.push_back (view);
5176 if (selection->selected (view) && !selection->tracks.empty()) {
5177 pending_resizes.insert (pending_resizes.end(), selection->tracks.begin(), selection->tracks.end());
5182 Editor::idle_resize ()
5184 for (vector<TimeAxisView*>::iterator i = pending_resizes.begin(); i != pending_resizes.end(); ++i) {
5185 (*i)->idle_resize (resize_idle_target);
5187 pending_resizes.clear();
5188 resize_idle_id = -1;