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"
91 #include "analysis_window.h"
97 #include "imageframe_socket_handler.h"
101 using namespace sigc;
102 using namespace ARDOUR;
105 using namespace Glib;
106 using namespace Gtkmm2ext;
107 using namespace Editing;
109 using PBD::internationalize;
112 const double Editor::timebar_height = 15.0;
114 #include "editor_xpms"
116 static const gchar *_snap_type_strings[] = {
138 static const gchar *_snap_mode_strings[] = {
145 static const gchar *_edit_point_strings[] = {
152 static const gchar *_zoom_focus_strings[] = {
162 #ifdef USE_RUBBERBAND
163 static const gchar *_rb_opt_strings[] = {
166 N_("Balanced multitimbral mixture"),
167 N_("Unpitched percussion with stable notes"),
168 N_("Crisp monophonic instrumental"),
169 N_("Unpitched solo percussion"),
174 /* Soundfile drag-n-drop */
176 Gdk::Cursor* Editor::cross_hair_cursor = 0;
177 Gdk::Cursor* Editor::selector_cursor = 0;
178 Gdk::Cursor* Editor::trimmer_cursor = 0;
179 Gdk::Cursor* Editor::grabber_cursor = 0;
180 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
181 Gdk::Cursor* Editor::zoom_cursor = 0;
182 Gdk::Cursor* Editor::time_fx_cursor = 0;
183 Gdk::Cursor* Editor::fader_cursor = 0;
184 Gdk::Cursor* Editor::speaker_cursor = 0;
185 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
186 Gdk::Cursor* Editor::midi_select_cursor = 0;
187 Gdk::Cursor* Editor::midi_resize_cursor = 0;
188 Gdk::Cursor* Editor::midi_erase_cursor = 0;
189 Gdk::Cursor* Editor::wait_cursor = 0;
190 Gdk::Cursor* Editor::timebar_cursor = 0;
191 Gdk::Cursor* Editor::transparent_cursor = 0;
194 show_me_the_size (Requisition* r, const char* what)
196 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
200 DragInfo::clear_copied_locations ()
202 for (list<Location*>::iterator i = copied_locations.begin(); i != copied_locations.end(); ++i) {
205 copied_locations.clear ();
210 /* time display buttons */
212 minsec_label (_("Mins:Secs")),
213 bbt_label (_("Bars:Beats")),
214 smpte_label (_("Timecode")),
215 frame_label (_("Samples")),
216 tempo_label (_("Tempo")),
217 meter_label (_("Meter")),
218 mark_label (_("Location Markers")),
219 range_mark_label (_("Range Markers")),
220 transport_mark_label (_("Loop/Punch Ranges")),
221 cd_mark_label (_("CD Markers")),
222 edit_packer (3, 4, true),
224 /* the values here don't matter: layout widgets
225 reset them as needed.
228 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
229 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
231 /* tool bar related */
233 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
234 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
236 toolbar_selection_clock_table (2,3),
238 automation_mode_button (_("mode")),
239 global_automation_button (_("automation")),
241 midi_panic_button (_("Panic")),
242 midi_tools_tearoff (0),
245 image_socket_listener(0),
250 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
251 meters_running(false)
256 /* we are a singleton */
258 PublicEditor::_instance = this;
263 selection = new Selection (this);
264 cut_buffer = new Selection (this);
266 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
267 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
268 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
269 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
270 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
272 clicked_regionview = 0;
273 clicked_axisview = 0;
274 clicked_routeview = 0;
275 clicked_crossfadeview = 0;
276 clicked_control_point = 0;
277 last_update_frame = 0;
279 current_mixer_strip = 0;
280 current_bbt_points = 0;
283 snap_type_strings = I18N (_snap_type_strings);
284 snap_mode_strings = I18N (_snap_mode_strings);
285 zoom_focus_strings = I18N (_zoom_focus_strings);
286 edit_point_strings = I18N (_edit_point_strings);
287 #ifdef USE_RUBBERBAND
288 rb_opt_strings = I18N (_rb_opt_strings);
291 snap_threshold = 5.0;
292 bbt_beat_subdivision = 4;
295 last_autoscroll_x = 0;
296 last_autoscroll_y = 0;
297 autoscroll_active = false;
298 autoscroll_timeout_tag = -1;
299 interthread_progress_window = 0;
306 current_interthread_info = 0;
307 _show_measures = true;
308 _show_waveforms = true;
309 _show_waveforms_recording = true;
310 first_action_message = 0;
311 show_gain_after_trim = false;
312 ignore_route_list_reorder = false;
313 no_route_list_redisplay = false;
314 verbose_cursor_on = true;
315 route_removal = false;
316 show_automatic_regions_in_region_list = true;
317 last_item_entered = 0;
318 last_item_entered_n = 0;
320 region_list_sort_type = (Editing::RegionListSortType) 0;
321 have_pending_keyboard_selection = false;
322 _follow_playhead = true;
323 _xfade_visibility = true;
324 editor_ruler_menu = 0;
325 no_ruler_shown_update = false;
326 edit_group_list_menu = 0;
328 region_list_menu = 0;
330 start_end_marker_menu = 0;
331 range_marker_menu = 0;
332 marker_menu_item = 0;
334 transport_marker_menu = 0;
335 new_transport_marker_menu = 0;
336 editor_mixer_strip_width = Wide;
337 show_editor_mixer_when_tracks_arrive = false;
338 region_edit_menu_split_multichannel_item = 0;
339 region_edit_menu_split_item = 0;
342 ignore_mouse_mode_toggle = false;
343 ignore_midi_edit_mode_toggle = false;
344 current_stepping_trackview = 0;
346 entered_regionview = 0;
348 clear_entered_track = false;
349 _new_regionviews_show_envelope = false;
351 in_edit_group_row_change = false;
352 last_canvas_frame = 0;
354 button_release_can_deselect = true;
355 _dragging_playhead = false;
356 _dragging_edit_point = false;
357 _dragging_hscrollbar = false;
358 select_new_marker = false;
359 zoomed_to_region = false;
361 allow_vertical_scroll = false;
362 no_save_visual = false;
363 need_resize_line = false;
365 old_resize_line_y = -1;
366 no_region_list_redisplay = false;
370 scrubbing_direction = 0;
373 ignore_route_order_sync = false;
375 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
376 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
377 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
378 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
379 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
381 range_marker_drag_rect = 0;
382 marker_drag_line = 0;
383 set_midi_edit_mode (MidiEditPencil, true);
384 set_mouse_mode (MouseObject, true);
386 frames_per_unit = 2048; /* too early to use reset_zoom () */
387 reset_hscrollbar_stepping ();
389 zoom_focus = ZoomFocusLeft;
390 set_zoom_focus (ZoomFocusLeft);
391 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
393 initialize_rulers ();
394 initialize_canvas ();
396 edit_controls_vbox.set_spacing (0);
397 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
398 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
399 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
401 controls_layout.add (edit_controls_vbox);
402 controls_layout.set_name ("EditControlsBase");
403 controls_layout.add_events (Gdk::SCROLL_MASK);
404 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
406 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
407 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
408 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
410 edit_vscrollbar.set_adjustment (vertical_adjustment);
411 edit_hscrollbar.set_adjustment (horizontal_adjustment);
413 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
414 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
415 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
417 edit_hscrollbar.set_name ("EditorHScrollbar");
421 setup_midi_toolbar ();
423 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
425 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
426 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
427 0.0, 1.0, 100.0, 1.0));
428 pad_line_1->property_color_rgba() = 0xFF0000FF;
432 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
433 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
434 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
435 time_canvas_vbox.pack_start (*frames_ruler, false, false);
436 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
437 //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
438 time_canvas_vbox.set_size_request (-1, -1);
439 bbt_label.set_name ("EditorTimeButton");
440 bbt_label.set_size_request (-1, (int)timebar_height);
441 bbt_label.set_alignment (1.0, 0.5);
442 bbt_label.set_padding (5,0);
443 minsec_label.set_name ("EditorTimeButton");
444 minsec_label.set_size_request (-1, (int)timebar_height);
445 minsec_label.set_alignment (1.0, 0.5);
446 minsec_label.set_padding (5,0);
447 smpte_label.set_name ("EditorTimeButton");
448 smpte_label.set_size_request (-1, (int)timebar_height);
449 smpte_label.set_alignment (1.0, 0.5);
450 smpte_label.set_padding (5,0);
451 frame_label.set_name ("EditorTimeButton");
452 frame_label.set_size_request (-1, (int)timebar_height);
453 frame_label.set_alignment (1.0, 0.5);
454 frame_label.set_padding (5,0);
456 tempo_label.set_name ("EditorTimeButton");
457 tempo_label.set_size_request (-1, (int)timebar_height);
458 tempo_label.set_alignment (1.0, 0.5);
459 tempo_label.set_padding (5,0);
460 meter_label.set_name ("EditorTimeButton");
461 meter_label.set_size_request (-1, (int)timebar_height);
462 meter_label.set_alignment (1.0, 0.5);
463 meter_label.set_padding (5,0);
464 mark_label.set_name ("EditorTimeButton");
465 mark_label.set_size_request (-1, (int)timebar_height);
466 mark_label.set_alignment (1.0, 0.5);
467 mark_label.set_padding (5,0);
468 cd_mark_label.set_name ("EditorTimeButton");
469 cd_mark_label.set_size_request (-1, (int)timebar_height);
470 cd_mark_label.set_alignment (1.0, 0.5);
471 cd_mark_label.set_padding (5,0);
472 range_mark_label.set_name ("EditorTimeButton");
473 range_mark_label.set_size_request (-1, (int)timebar_height);
474 range_mark_label.set_alignment (1.0, 0.5);
475 range_mark_label.set_padding (5,0);
476 transport_mark_label.set_name ("EditorTimeButton");
477 transport_mark_label.set_size_request (-1, (int)timebar_height);
478 transport_mark_label.set_alignment (1.0, 0.5);
479 transport_mark_label.set_padding (5,0);
481 ruler_label_vbox.pack_start (minsec_label, false, false);
482 ruler_label_vbox.pack_start (smpte_label, false, false);
483 ruler_label_vbox.pack_start (frame_label, false, false);
484 ruler_label_vbox.pack_start (bbt_label, false, false);
486 ruler_label_event_box.add (ruler_label_vbox);
487 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
488 ruler_label_event_box.set_name ("TimebarLabelBase");
489 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
491 time_button_vbox.pack_start (meter_label, false, false);
492 time_button_vbox.pack_start (tempo_label, false, false);
493 time_button_vbox.pack_start (mark_label, false, false);
495 time_button_event_box.add (time_button_vbox);
496 time_button_event_box.set_name ("TimebarLabelBase");
497 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
498 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
500 /* these enable us to have a dedicated window (for cursor setting, etc.)
501 for the canvas areas.
504 track_canvas_event_box.add (*track_canvas);
506 time_canvas_event_box.add (time_canvas_vbox);
507 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
509 edit_packer.set_col_spacings (0);
510 edit_packer.set_row_spacings (0);
511 edit_packer.set_homogeneous (false);
512 edit_packer.set_border_width (0);
513 edit_packer.set_name ("EditorWindow");
517 edit_packer.attach (ruler_label_event_box, 0, 1, 0, 1, FILL, SHRINK, 0, 0);
519 edit_packer.attach (time_button_event_box, 0, 1, 1, 2, FILL, SHRINK, 0, 0);
520 edit_packer.attach (time_canvas_event_box, 1, 2, 0, 1, FILL|EXPAND, FILL, 0, 0);
522 edit_packer.attach (controls_layout, 0, 1, 2, 3, FILL, FILL|EXPAND, 0, 0);
523 edit_packer.attach (track_canvas_event_box, 1, 2, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
525 edit_packer.attach (zoom_box, 0, 1, 3, 4, FILL, FILL, 0, 0);
526 edit_packer.attach (edit_hscrollbar, 1, 2, 3, 4, FILL|EXPAND, FILL, 0, 0);
528 edit_packer.attach (edit_vscrollbar, 3, 4, 2, 3, FILL, FILL|EXPAND, 0, 0);
532 edit_packer.attach (edit_vscrollbar, 0, 1, 0, 4, FILL, FILL|EXPAND, 0, 0);
534 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
535 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
536 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
538 edit_packer.attach (controls_layout, 1, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
539 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
541 edit_packer.attach (zoom_box, 1, 2, 3, 4, FILL, FILL, 0, 0);
542 edit_packer.attach (edit_hscrollbar, 2, 3, 3, 4, FILL|EXPAND, FILL, 0, 0);
545 bottom_hbox.set_border_width (2);
546 bottom_hbox.set_spacing (3);
548 route_display_model = ListStore::create(route_display_columns);
549 route_list_display.set_model (route_display_model);
550 route_list_display.append_column (_("Show"), route_display_columns.visible);
551 route_list_display.append_column (_("Name"), route_display_columns.text);
552 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
553 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
554 route_list_display.set_headers_visible (true);
555 route_list_display.set_name ("TrackListDisplay");
556 route_list_display.get_selection()->set_mode (SELECTION_SINGLE);
557 route_list_display.set_reorderable (true);
558 route_list_display.set_size_request (100,-1);
559 route_list_display.add_object_drag (route_display_columns.route.index(), "routes");
561 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
562 route_list_visible_cell->property_activatable() = true;
563 route_list_visible_cell->property_radio() = false;
565 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
566 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
568 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
570 route_list_scroller.add (route_list_display);
571 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
573 group_model = ListStore::create(group_columns);
574 edit_group_display.set_model (group_model);
575 edit_group_display.append_column (_("Name"), group_columns.text);
576 edit_group_display.append_column (_("Active"), group_columns.is_active);
577 edit_group_display.append_column (_("Show"), group_columns.is_visible);
578 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
579 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
580 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
581 edit_group_display.get_column (0)->set_expand (true);
582 edit_group_display.get_column (1)->set_expand (false);
583 edit_group_display.get_column (2)->set_expand (false);
584 edit_group_display.set_headers_visible (true);
586 /* name is directly editable */
588 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
589 name_cell->property_editable() = true;
590 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
592 /* use checkbox for the active + visible columns */
594 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
595 active_cell->property_activatable() = true;
596 active_cell->property_radio() = false;
598 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
599 active_cell->property_activatable() = true;
600 active_cell->property_radio() = false;
602 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
604 edit_group_display.set_name ("EditGroupList");
605 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
606 edit_group_display.set_headers_visible (true);
607 edit_group_display.set_reorderable (false);
608 edit_group_display.set_rules_hint (true);
609 edit_group_display.set_size_request (75, -1);
611 edit_group_display_scroller.add (edit_group_display);
612 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
614 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
616 VBox* edit_group_display_packer = manage (new VBox());
617 HBox* edit_group_display_button_box = manage (new HBox());
618 edit_group_display_button_box->set_homogeneous (true);
620 Button* edit_group_add_button = manage (new Button ());
621 Button* edit_group_remove_button = manage (new Button ());
625 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
627 edit_group_add_button->add (*w);
629 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
631 edit_group_remove_button->add (*w);
633 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
634 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
636 edit_group_display_button_box->pack_start (*edit_group_add_button);
637 edit_group_display_button_box->pack_start (*edit_group_remove_button);
639 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
640 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
642 region_list_display.set_size_request (100, -1);
643 region_list_display.set_name ("RegionListDisplay");
644 /* Try to prevent single mouse presses from initiating edits.
645 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
647 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
649 region_list_model = TreeStore::create (region_list_columns);
650 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
651 region_list_model->set_sort_column (0, SORT_ASCENDING);
653 region_list_display.set_model (region_list_model);
654 region_list_display.append_column (_("Regions"), region_list_columns.name);
655 region_list_display.append_column (_("Start"), region_list_columns.start);
656 region_list_display.append_column (_("End"), region_list_columns.end);
657 region_list_display.append_column (_("Length"), region_list_columns.length);
658 region_list_display.append_column (_("Sync"), region_list_columns.sync);
659 region_list_display.append_column (_("Fade In"), region_list_columns.fadein);
660 region_list_display.append_column (_("Fade Out"), region_list_columns.fadeout);
661 region_list_display.append_column (_("L"), region_list_columns.locked);
662 region_list_display.append_column (_("G"), region_list_columns.glued);
663 region_list_display.append_column (_("M"), region_list_columns.muted);
664 region_list_display.append_column (_("O"), region_list_columns.opaque);
665 region_list_display.append_column (_("Used"), region_list_columns.used);
666 region_list_display.append_column (_("Path"), region_list_columns.path);
667 region_list_display.set_headers_visible (true);
668 region_list_display.set_grid_lines (TREE_VIEW_GRID_LINES_BOTH);
670 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
671 region_name_cell->property_editable() = true;
672 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
674 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
676 TreeViewColumn* tv_col = region_list_display.get_column(0);
677 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
678 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
679 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
681 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
682 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
684 /* setup DnD handling */
686 list<TargetEntry> region_list_target_table;
688 region_list_target_table.push_back (TargetEntry ("text/plain"));
689 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
690 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
692 region_list_display.add_drop_targets (region_list_target_table);
693 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
695 region_list_scroller.add (region_list_display);
696 region_list_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
698 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
699 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
700 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
701 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
702 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
703 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
705 //ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::redisplay_regions));
706 ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::update_all_region_rows));
707 ARDOUR::Region::RegionPropertyChanged.connect (mem_fun(*this, &Editor::update_region_row));
709 named_selection_scroller.add (named_selection_display);
710 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
712 named_selection_model = TreeStore::create (named_selection_columns);
713 named_selection_display.set_model (named_selection_model);
714 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
715 named_selection_display.set_headers_visible (false);
716 named_selection_display.set_size_request (100, -1);
717 named_selection_display.set_name ("NamedSelectionDisplay");
719 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
720 named_selection_display.set_size_request (100, -1);
721 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
722 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
723 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
727 snapshot_display_model = ListStore::create (snapshot_display_columns);
728 snapshot_display.set_model (snapshot_display_model);
729 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
730 snapshot_display.set_name ("SnapshotDisplay");
731 snapshot_display.set_size_request (75, -1);
732 snapshot_display.set_headers_visible (false);
733 snapshot_display.set_reorderable (false);
734 snapshot_display_scroller.add (snapshot_display);
735 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
737 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
738 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
742 nlabel = manage (new Label (_("Regions")));
743 nlabel->set_angle (-90);
744 the_notebook.append_page (region_list_scroller, *nlabel);
745 nlabel = manage (new Label (_("Tracks/Busses")));
746 nlabel->set_angle (-90);
747 the_notebook.append_page (route_list_scroller, *nlabel);
748 nlabel = manage (new Label (_("Snapshots")));
749 nlabel->set_angle (-90);
750 the_notebook.append_page (snapshot_display_scroller, *nlabel);
751 nlabel = manage (new Label (_("Edit Groups")));
752 nlabel->set_angle (-90);
753 the_notebook.append_page (*edit_group_display_packer, *nlabel);
755 if (!Profile->get_sae()) {
756 nlabel = manage (new Label (_("Chunks")));
757 nlabel->set_angle (-90);
758 the_notebook.append_page (named_selection_scroller, *nlabel);
761 the_notebook.set_show_tabs (true);
762 the_notebook.set_scrollable (true);
763 the_notebook.popup_enable ();
764 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
765 the_notebook.show_all ();
767 post_maximal_editor_width = 0;
768 post_maximal_pane_position = 0;
769 edit_pane.pack1 (edit_packer, true, true);
770 edit_pane.pack2 (the_notebook, false, true);
772 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
774 top_hbox.pack_start (toolbar_frame, false, true);
775 top_hbox.pack_start (midi_toolbar_frame, false, true);
777 HBox *hbox = manage (new HBox);
778 hbox->pack_start (edit_pane, true, true);
780 global_vpacker.pack_start (top_hbox, false, false);
781 global_vpacker.pack_start (*hbox, true, true);
783 global_hpacker.pack_start (global_vpacker, true, true);
785 set_name ("EditorWindow");
786 add_accel_group (ActionManager::ui_manager->get_accel_group());
788 status_bar_hpacker.show ();
790 vpacker.pack_end (status_bar_hpacker, false, false);
791 vpacker.pack_end (global_hpacker, true, true);
793 /* register actions now so that set_state() can find them and set toggles/checks etc */
797 snap_type = SnapToBeat;
798 set_snap_to (snap_type);
800 set_snap_mode (snap_mode);
801 set_edit_point_preference (EditAtMouse, true);
803 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
806 _playlist_selector = new PlaylistSelector();
807 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
809 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
813 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
814 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
816 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
817 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
819 nudge_forward_button.set_name ("TransportButton");
820 nudge_backward_button.set_name ("TransportButton");
822 fade_context_menu.set_name ("ArdourContextMenu");
824 /* icons, titles, WM stuff */
826 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
827 Glib::RefPtr<Gdk::Pixbuf> icon;
829 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
830 window_icons.push_back (icon);
832 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
833 window_icons.push_back (icon);
835 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
836 window_icons.push_back (icon);
838 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
839 window_icons.push_back (icon);
841 if (!window_icons.empty()) {
842 set_icon_list (window_icons);
843 set_default_icon_list (window_icons);
846 WindowTitle title(Glib::get_application_name());
847 title += _("Editor");
848 set_title (title.get_string());
849 set_wmclass (X_("ardour_editor"), "Ardour");
852 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
854 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
855 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
857 /* allow external control surfaces/protocols to do various things */
859 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
860 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
861 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
862 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
863 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
865 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
866 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
875 if(image_socket_listener) {
876 if(image_socket_listener->is_connected())
878 image_socket_listener->close_connection() ;
881 delete image_socket_listener ;
882 image_socket_listener = 0 ;
893 Editor::add_toplevel_controls (Container& cont)
895 vpacker.pack_start (cont, false, false);
900 Editor::catch_vanishing_regionview (RegionView *rv)
902 /* note: the selection will take care of the vanishing
903 audioregionview by itself.
906 if (clicked_regionview == rv) {
907 clicked_regionview = 0;
910 if (entered_regionview == rv) {
911 set_entered_regionview (0);
916 Editor::set_entered_regionview (RegionView* rv)
918 if (rv == entered_regionview) {
922 if (entered_regionview) {
923 entered_regionview->exited ();
926 if ((entered_regionview = rv) != 0) {
927 entered_regionview->entered ();
932 Editor::set_entered_track (TimeAxisView* tav)
935 entered_track->exited ();
938 if ((entered_track = tav) != 0) {
939 entered_track->entered ();
944 Editor::show_window ()
946 show_all_children ();
948 /* re-hide editor list if necessary */
949 editor_list_button_toggled ();
951 /* now reset all audio_time_axis heights, because widgets might need
957 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
958 tv = (static_cast<TimeAxisView*>(*i));
966 Editor::instant_save ()
968 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
973 session->add_instant_xml(get_state());
975 Config->add_instant_xml(get_state());
980 Editor::edit_point_clock_changed()
982 if (_dragging_edit_point) {
986 if (selection->markers.empty()) {
991 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
997 loc->move_to (edit_point_clock.current_time());
1001 Editor::zoom_adjustment_changed ()
1007 double fpu = zoom_range_clock.current_duration() / canvas_width;
1011 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
1012 } else if (fpu > session->current_end_frame() / canvas_width) {
1013 fpu = session->current_end_frame() / canvas_width;
1014 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
1017 temporal_zoom (fpu);
1021 Editor::control_scroll (float fraction)
1023 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
1029 double step = fraction * current_page_frames();
1032 _control_scroll_target is an optional<T>
1034 it acts like a pointer to an nframes64_t, with
1035 a operator conversion to boolean to check
1036 that it has a value could possibly use
1037 playhead_cursor->current_frame to store the
1038 value and a boolean in the class to know
1039 when it's out of date
1042 if (!_control_scroll_target) {
1043 _control_scroll_target = session->transport_frame();
1044 _dragging_playhead = true;
1047 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
1048 *_control_scroll_target = 0;
1049 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
1050 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
1052 *_control_scroll_target += (nframes64_t) floor (step);
1055 /* move visuals, we'll catch up with it later */
1057 playhead_cursor->set_position (*_control_scroll_target);
1058 UpdateAllTransportClocks (*_control_scroll_target);
1060 if (*_control_scroll_target > (current_page_frames() / 2)) {
1061 /* try to center PH in window */
1062 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
1068 Now we do a timeout to actually bring the session to the right place
1069 according to the playhead. This is to avoid reading disk buffers on every
1070 call to control_scroll, which is driven by ScrollTimeline and therefore
1071 probably by a control surface wheel which can generate lots of events.
1073 /* cancel the existing timeout */
1075 control_scroll_connection.disconnect ();
1077 /* add the next timeout */
1079 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
1083 Editor::deferred_control_scroll (nframes64_t target)
1085 session->request_locate (*_control_scroll_target, session->transport_rolling());
1086 // reset for next stream
1087 _control_scroll_target = boost::none;
1088 _dragging_playhead = false;
1093 Editor::access_action (std::string action_group, std::string action_item)
1099 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
1101 cout<< "OSC: Recieved: "<< action_item << endl;
1104 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1114 Editor::on_realize ()
1116 Window::on_realize ();
1121 Editor::start_scrolling ()
1123 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1124 (mem_fun(*this, &Editor::update_current_screen));
1129 Editor::stop_scrolling ()
1131 scroll_connection.disconnect ();
1135 Editor::map_position_change (nframes64_t frame)
1137 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1139 if (session == 0 || !_follow_playhead) {
1143 center_screen (frame);
1144 playhead_cursor->set_position (frame);
1148 Editor::center_screen (nframes64_t frame)
1150 double page = canvas_width * frames_per_unit;
1152 /* if we're off the page, then scroll.
1155 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1156 center_screen_internal (frame, page);
1161 Editor::center_screen_internal (nframes64_t frame, float page)
1166 frame -= (nframes64_t) page;
1171 reset_x_origin (frame);
1175 Editor::handle_new_duration ()
1177 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1179 nframes64_t new_end = session->get_maximum_extent() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1181 if (new_end > last_canvas_frame) {
1182 last_canvas_frame = new_end;
1183 horizontal_adjustment.set_upper (last_canvas_frame / 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);
1289 if (analysis_window != 0)
1290 analysis_window->set_session (session);
1293 Location* loc = session->locations()->auto_loop_location();
1295 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1296 if (loc->start() == loc->end()) {
1297 loc->set_end (loc->start() + 1);
1299 session->locations()->add (loc, false);
1300 session->set_auto_loop_location (loc);
1303 loc->set_name (_("Loop"));
1306 loc = session->locations()->auto_punch_location();
1308 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1309 if (loc->start() == loc->end()) {
1310 loc->set_end (loc->start() + 1);
1312 session->locations()->add (loc, false);
1313 session->set_auto_punch_location (loc);
1316 loc->set_name (_("Punch"));
1319 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1321 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1323 refresh_location_display ();
1324 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1325 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1326 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1327 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1328 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1331 sfbrowser->set_session (session);
1334 handle_new_duration ();
1336 redisplay_regions ();
1337 redisplay_named_selections ();
1338 redisplay_snapshots ();
1340 initial_route_list_display ();
1342 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1343 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1346 restore_ruler_visibility ();
1347 //tempo_map_changed (Change (0));
1348 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1352 /* don't show master bus in a new session */
1354 if (ARDOUR_UI::instance()->session_is_new ()) {
1356 TreeModel::Children rows = route_display_model->children();
1357 TreeModel::Children::iterator i;
1359 no_route_list_redisplay = true;
1361 for (i = rows.begin(); i != rows.end(); ++i) {
1362 TimeAxisView *tv = (*i)[route_display_columns.tv];
1363 RouteTimeAxisView *rtv;
1365 if ((rtv = dynamic_cast<RouteTimeAxisView*>(tv)) != 0) {
1366 if (rtv->route()->is_master()) {
1367 route_list_display.get_selection()->unselect (i);
1372 no_route_list_redisplay = false;
1373 redisplay_route_list ();
1376 switch (snap_type) {
1377 case SnapToRegionStart:
1378 case SnapToRegionEnd:
1379 case SnapToRegionSync:
1380 case SnapToRegionBoundary:
1381 build_region_boundary_cache ();
1388 /* register for undo history */
1389 session->register_with_memento_command_factory(_id, this);
1395 Editor::build_cursors ()
1397 using namespace Gdk;
1399 Gdk::Color mbg ("#000000" ); /* Black */
1400 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1403 RefPtr<Bitmap> source, mask;
1404 source = Bitmap::create (mag_bits, mag_width, mag_height);
1405 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1406 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1409 Gdk::Color fbg ("#ffffff" );
1410 Gdk::Color ffg ("#000000" );
1413 RefPtr<Bitmap> source, mask;
1415 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1416 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1417 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1421 RefPtr<Bitmap> source, mask;
1422 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1423 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1424 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1428 RefPtr<Bitmap> bits;
1429 char pix[4] = { 0, 0, 0, 0 };
1430 bits = Bitmap::create (pix, 2, 2);
1432 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1436 RefPtr<Bitmap> bits;
1437 char pix[4] = { 0, 0, 0, 0 };
1438 bits = Bitmap::create (pix, 2, 2);
1440 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1444 grabber_cursor = new Gdk::Cursor (HAND2);
1447 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1448 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1451 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1452 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1453 selector_cursor = new Gdk::Cursor (XTERM);
1454 time_fx_cursor = new Gdk::Cursor (SIZING);
1455 wait_cursor = new Gdk::Cursor (WATCH);
1456 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1457 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1458 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1459 midi_resize_cursor = new Gdk::Cursor (SIZING);
1460 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1463 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1465 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1467 using namespace Menu_Helpers;
1468 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1471 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1475 MenuList& items (fade_context_menu.items());
1479 switch (item_type) {
1481 case FadeInHandleItem:
1482 if (arv->audio_region()->fade_in_active()) {
1483 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1485 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1488 items.push_back (SeparatorElem());
1490 if (Profile->get_sae()) {
1491 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1492 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1494 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1495 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1496 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1497 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1498 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1504 case FadeOutHandleItem:
1505 if (arv->audio_region()->fade_out_active()) {
1506 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1508 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1511 items.push_back (SeparatorElem());
1513 if (Profile->get_sae()) {
1514 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1515 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1517 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1518 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1519 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1520 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1521 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1527 fatal << _("programming error: ")
1528 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1533 fade_context_menu.popup (button, time);
1537 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1539 using namespace Menu_Helpers;
1540 Menu* (Editor::*build_menu_function)(nframes64_t);
1543 switch (item_type) {
1545 case RegionViewName:
1546 case RegionViewNameHighlight:
1547 if (with_selection) {
1548 build_menu_function = &Editor::build_track_selection_context_menu;
1550 build_menu_function = &Editor::build_track_region_context_menu;
1555 if (with_selection) {
1556 build_menu_function = &Editor::build_track_selection_context_menu;
1558 build_menu_function = &Editor::build_track_context_menu;
1562 case CrossfadeViewItem:
1563 build_menu_function = &Editor::build_track_crossfade_context_menu;
1567 if (clicked_routeview->get_diskstream()) {
1568 build_menu_function = &Editor::build_track_context_menu;
1570 build_menu_function = &Editor::build_track_bus_context_menu;
1575 /* probably shouldn't happen but if it does, we don't care */
1579 menu = (this->*build_menu_function)(frame);
1580 menu->set_name ("ArdourContextMenu");
1582 /* now handle specific situations */
1584 switch (item_type) {
1586 case RegionViewName:
1587 case RegionViewNameHighlight:
1588 if (!with_selection) {
1589 if (region_edit_menu_split_item) {
1590 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1591 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1593 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1597 if (region_edit_menu_split_multichannel_item) {
1598 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1599 // GTK2FIX find the action, change its sensitivity
1600 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1602 // GTK2FIX see above
1603 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1612 case CrossfadeViewItem:
1619 /* probably shouldn't happen but if it does, we don't care */
1623 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1625 /* Bounce to disk */
1627 using namespace Menu_Helpers;
1628 MenuList& edit_items = menu->items();
1630 edit_items.push_back (SeparatorElem());
1632 switch (clicked_routeview->audio_track()->freeze_state()) {
1633 case AudioTrack::NoFreeze:
1634 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1637 case AudioTrack::Frozen:
1638 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1641 case AudioTrack::UnFrozen:
1642 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1648 if (item_type == StreamItem && clicked_routeview) {
1649 clicked_routeview->build_underlay_menu(menu);
1652 menu->popup (button, time);
1656 Editor::build_track_context_menu (nframes64_t ignored)
1658 using namespace Menu_Helpers;
1660 MenuList& edit_items = track_context_menu.items();
1663 add_dstream_context_items (edit_items);
1664 return &track_context_menu;
1668 Editor::build_track_bus_context_menu (nframes64_t ignored)
1670 using namespace Menu_Helpers;
1672 MenuList& edit_items = track_context_menu.items();
1675 add_bus_context_items (edit_items);
1676 return &track_context_menu;
1680 Editor::build_track_region_context_menu (nframes64_t frame)
1682 using namespace Menu_Helpers;
1683 MenuList& edit_items = track_region_context_menu.items();
1686 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1689 boost::shared_ptr<Diskstream> ds;
1690 boost::shared_ptr<Playlist> pl;
1692 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1693 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1695 if (selection->regions.size() > 1) {
1696 // there's already a multiple selection: just add a
1697 // single region context menu that will act on all
1699 boost::shared_ptr<Region> dummy_region; // = NULL
1700 add_region_context_items (rtv->view(), dummy_region, edit_items);
1702 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1703 add_region_context_items (rtv->view(), (*i), edit_items);
1711 add_dstream_context_items (edit_items);
1713 return &track_region_context_menu;
1717 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1719 using namespace Menu_Helpers;
1720 MenuList& edit_items = track_crossfade_context_menu.items();
1721 edit_items.clear ();
1723 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1726 boost::shared_ptr<Diskstream> ds;
1727 boost::shared_ptr<Playlist> pl;
1728 boost::shared_ptr<AudioPlaylist> apl;
1730 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1732 Playlist::RegionList* regions = pl->regions_at (frame);
1733 AudioPlaylist::Crossfades xfades;
1735 apl->crossfades_at (frame, xfades);
1737 bool many = xfades.size() > 1;
1739 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1740 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1743 if (selection->regions.size() > 1) {
1744 // there's already a multiple selection: just add a
1745 // single region context menu that will act on all
1747 boost::shared_ptr<Region> dummy_region; // = NULL
1748 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1750 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1751 add_region_context_items (atv->audio_view(), (*i), edit_items);
1758 add_dstream_context_items (edit_items);
1760 return &track_crossfade_context_menu;
1765 Editor::analyze_region_selection()
1767 if (analysis_window == 0) {
1768 analysis_window = new AnalysisWindow();
1771 analysis_window->set_session(session);
1773 analysis_window->show_all();
1776 analysis_window->set_regionmode();
1777 analysis_window->analyze();
1779 analysis_window->present();
1783 Editor::analyze_range_selection()
1785 if (analysis_window == 0) {
1786 analysis_window = new AnalysisWindow();
1789 analysis_window->set_session(session);
1791 analysis_window->show_all();
1794 analysis_window->set_rangemode();
1795 analysis_window->analyze();
1797 analysis_window->present();
1799 #endif /* FFT_ANALYSIS */
1802 Editor::build_track_selection_context_menu (nframes64_t ignored)
1804 using namespace Menu_Helpers;
1805 MenuList& edit_items = track_selection_context_menu.items();
1806 edit_items.clear ();
1808 add_selection_context_items (edit_items);
1809 // edit_items.push_back (SeparatorElem());
1810 // add_dstream_context_items (edit_items);
1812 return &track_selection_context_menu;
1815 /** Add context menu items relevant to crossfades.
1816 * @param edit_items List to add the items to.
1819 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1821 using namespace Menu_Helpers;
1822 Menu *xfade_menu = manage (new Menu);
1823 MenuList& items = xfade_menu->items();
1824 xfade_menu->set_name ("ArdourContextMenu");
1827 if (xfade->active()) {
1833 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1834 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1836 if (xfade->can_follow_overlap()) {
1838 if (xfade->following_overlap()) {
1839 str = _("Convert to short");
1841 str = _("Convert to full");
1844 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1848 str = xfade->out()->name();
1850 str += xfade->in()->name();
1852 str = _("Crossfade");
1855 edit_items.push_back (MenuElem (str, *xfade_menu));
1856 edit_items.push_back (SeparatorElem());
1860 Editor::xfade_edit_left_region ()
1862 if (clicked_crossfadeview) {
1863 clicked_crossfadeview->left_view.show_region_editor ();
1868 Editor::xfade_edit_right_region ()
1870 if (clicked_crossfadeview) {
1871 clicked_crossfadeview->right_view.show_region_editor ();
1875 /** Add an element to a menu, settings its sensitivity.
1876 * @param m Menu to add to.
1877 * @param e Element to add.
1878 * @param s true to make sensitive, false to make insensitive
1881 Editor::add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s) const
1885 m.back().set_sensitive (false);
1890 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1892 using namespace Menu_Helpers;
1893 Menu *region_menu = manage (new Menu);
1894 MenuList& items = region_menu->items();
1895 region_menu->set_name ("ArdourContextMenu");
1897 boost::shared_ptr<AudioRegion> ar;
1898 boost::shared_ptr<MidiRegion> mr;
1901 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1902 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1904 /* when this particular menu pops up, make the relevant region
1908 region_menu->signal_map_event().connect (
1909 bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1911 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1912 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1915 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1916 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1917 items.push_back (SeparatorElem());
1918 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1919 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1920 items.push_back (SeparatorElem());
1922 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1923 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1924 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1928 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1932 items.push_back (SeparatorElem());
1934 sigc::connection fooc;
1935 boost::shared_ptr<Region> region_to_check;
1938 region_to_check = region;
1940 region_to_check = selection->regions.front()->region();
1943 items.push_back (CheckMenuElem (_("Lock")));
1944 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1945 if (region_to_check->locked()) {
1946 region_lock_item->set_active();
1948 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1950 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1951 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1953 switch (region_to_check->positional_lock_style()) {
1954 case Region::MusicTime:
1955 bbt_glue_item->set_active (true);
1958 bbt_glue_item->set_active (false);
1962 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1964 items.push_back (CheckMenuElem (_("Mute")));
1965 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1966 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1967 if (region_to_check->muted()) {
1969 region_mute_item->set_active();
1973 if (!Profile->get_sae()) {
1974 items.push_back (CheckMenuElem (_("Opaque")));
1975 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1976 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1977 if (region_to_check->opaque()) {
1979 region_opaque_item->set_active();
1984 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1985 if (region_to_check->at_natural_position()) {
1986 items.back().set_sensitive (false);
1989 items.push_back (SeparatorElem());
1993 RegionView* rv = sv->find_view (ar);
1994 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1996 if (!Profile->get_sae()) {
1997 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1999 items.push_back (CheckMenuElem (_("Envelope Visible")));
2000 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
2001 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
2002 if (arv->envelope_visible()) {
2004 region_envelope_visible_item->set_active (true);
2008 items.push_back (CheckMenuElem (_("Envelope Active")));
2009 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
2010 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
2012 if (ar->envelope_active()) {
2014 region_envelope_active_item->set_active (true);
2018 items.push_back (SeparatorElem());
2021 if (ar->scale_amplitude() != 1.0f) {
2022 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
2024 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
2028 items.push_back (MenuElem (_("Quantize"), mem_fun(*this, &Editor::quantize_region)));
2029 items.push_back (SeparatorElem());
2032 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
2033 items.push_back (SeparatorElem());
2035 /* range related stuff */
2037 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
2038 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
2039 items.push_back (SeparatorElem());
2043 Menu *nudge_menu = manage (new Menu());
2044 MenuList& nudge_items = nudge_menu->items();
2045 nudge_menu->set_name ("ArdourContextMenu");
2047 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
2048 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
2049 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
2050 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
2052 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2053 items.push_back (SeparatorElem());
2055 Menu *trim_menu = manage (new Menu);
2056 MenuList& trim_items = trim_menu->items();
2057 trim_menu->set_name ("ArdourContextMenu");
2059 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
2060 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
2061 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
2062 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
2064 items.push_back (MenuElem (_("Trim"), *trim_menu));
2065 items.push_back (SeparatorElem());
2067 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
2068 region_edit_menu_split_item = &items.back();
2070 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
2071 region_edit_menu_split_multichannel_item = &items.back();
2073 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
2074 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
2075 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
2076 items.push_back (SeparatorElem());
2077 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
2079 /* OK, stick the region submenu at the top of the list, and then add
2083 /* we have to hack up the region name because "_" has a special
2084 meaning for menu titles.
2087 string::size_type pos = 0;
2088 string menu_item_name = (region) ? region->name() : _("Selected regions");
2090 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
2091 menu_item_name.replace (pos, 1, "__");
2095 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
2096 edit_items.push_back (SeparatorElem());
2099 /** Add context menu items relevant to selection ranges.
2100 * @param edit_items List to add the items to.
2103 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
2105 using namespace Menu_Helpers;
2106 Menu *selection_menu = manage (new Menu);
2107 MenuList& items = selection_menu->items();
2108 selection_menu->set_name ("ArdourContextMenu");
2110 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
2111 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
2114 items.push_back (SeparatorElem());
2115 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
2118 items.push_back (SeparatorElem());
2119 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
2120 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
2122 items.push_back (SeparatorElem());
2123 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
2124 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
2126 items.push_back (SeparatorElem());
2127 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
2129 items.push_back (SeparatorElem());
2130 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
2131 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
2133 items.push_back (SeparatorElem());
2134 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
2135 items.push_back (SeparatorElem());
2136 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
2137 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
2138 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
2139 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
2140 items.push_back (SeparatorElem());
2141 items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
2142 items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
2143 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_range)));
2148 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2150 using namespace Menu_Helpers;
2154 Menu *play_menu = manage (new Menu);
2155 MenuList& play_items = play_menu->items();
2156 play_menu->set_name ("ArdourContextMenu");
2158 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2159 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2160 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2161 play_items.push_back (SeparatorElem());
2162 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2164 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2168 Menu *select_menu = manage (new Menu);
2169 MenuList& select_items = select_menu->items();
2170 select_menu->set_name ("ArdourContextMenu");
2172 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2173 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2174 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2175 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2176 select_items.push_back (SeparatorElem());
2177 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2178 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2179 select_items.push_back (SeparatorElem());
2180 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2181 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2182 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2183 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2184 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2185 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2186 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2188 select_items.push_back (SeparatorElem());
2190 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2194 Menu *cutnpaste_menu = manage (new Menu);
2195 MenuList& cutnpaste_items = cutnpaste_menu->items();
2196 cutnpaste_menu->set_name ("ArdourContextMenu");
2198 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2199 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2200 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2202 cutnpaste_items.push_back (SeparatorElem());
2204 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2205 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2207 cutnpaste_items.push_back (SeparatorElem());
2209 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2211 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2213 /* Adding new material */
2215 edit_items.push_back (SeparatorElem());
2216 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2217 edit_items.push_back (MenuElem (_("Insert Existing Media"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2221 Menu *nudge_menu = manage (new Menu());
2222 MenuList& nudge_items = nudge_menu->items();
2223 nudge_menu->set_name ("ArdourContextMenu");
2225 edit_items.push_back (SeparatorElem());
2226 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2227 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2228 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2229 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2231 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2235 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2237 using namespace Menu_Helpers;
2241 Menu *play_menu = manage (new Menu);
2242 MenuList& play_items = play_menu->items();
2243 play_menu->set_name ("ArdourContextMenu");
2245 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2246 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2247 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2251 Menu *select_menu = manage (new Menu);
2252 MenuList& select_items = select_menu->items();
2253 select_menu->set_name ("ArdourContextMenu");
2255 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2256 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2257 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2258 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2259 select_items.push_back (SeparatorElem());
2260 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2261 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2262 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2263 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2265 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2269 Menu *cutnpaste_menu = manage (new Menu);
2270 MenuList& cutnpaste_items = cutnpaste_menu->items();
2271 cutnpaste_menu->set_name ("ArdourContextMenu");
2273 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2274 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2275 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2277 Menu *nudge_menu = manage (new Menu());
2278 MenuList& nudge_items = nudge_menu->items();
2279 nudge_menu->set_name ("ArdourContextMenu");
2281 edit_items.push_back (SeparatorElem());
2282 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2283 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2284 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2285 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2287 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2291 Editor::set_snap_to (SnapType st)
2293 unsigned int snap_ind = (unsigned int)st;
2297 if (snap_ind > snap_type_strings.size() - 1) {
2299 snap_type = (SnapType)snap_ind;
2302 string str = snap_type_strings[snap_ind];
2304 if (str != snap_type_selector.get_active_text()) {
2305 snap_type_selector.set_active_text (str);
2310 switch (snap_type) {
2311 case SnapToAThirtysecondBeat:
2312 case SnapToASixteenthBeat:
2313 case SnapToAEighthBeat:
2314 case SnapToAQuarterBeat:
2315 case SnapToAThirdBeat:
2316 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + (nframes_t)(edit_packer.get_width() * frames_per_unit));
2317 update_tempo_based_rulers ();
2320 case SnapToRegionStart:
2321 case SnapToRegionEnd:
2322 case SnapToRegionSync:
2323 case SnapToRegionBoundary:
2324 build_region_boundary_cache ();
2334 Editor::set_snap_mode (SnapMode mode)
2337 string str = snap_mode_strings[(int)mode];
2339 if (str != snap_mode_selector.get_active_text ()) {
2340 snap_mode_selector.set_active_text (str);
2346 Editor::set_edit_point_preference (EditPoint ep, bool force)
2348 bool changed = (_edit_point != ep);
2351 string str = edit_point_strings[(int)ep];
2353 if (str != edit_point_selector.get_active_text ()) {
2354 edit_point_selector.set_active_text (str);
2357 set_canvas_cursor ();
2359 if (!force && !changed) {
2363 switch (zoom_focus) {
2364 case ZoomFocusMouse:
2365 case ZoomFocusPlayhead:
2367 switch (_edit_point) {
2369 set_zoom_focus (ZoomFocusMouse);
2371 case EditAtPlayhead:
2372 set_zoom_focus (ZoomFocusPlayhead);
2374 case EditAtSelectedMarker:
2375 set_zoom_focus (ZoomFocusEdit);
2383 const char* action=NULL;
2385 switch (_edit_point) {
2386 case EditAtPlayhead:
2387 action = "edit-at-playhead";
2389 case EditAtSelectedMarker:
2390 action = "edit-at-marker";
2393 action = "edit-at-mouse";
2397 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2399 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2403 bool in_track_canvas;
2405 if (!mouse_frame (foo, in_track_canvas)) {
2406 in_track_canvas = false;
2409 reset_canvas_action_sensitivity (in_track_canvas);
2415 Editor::set_state (const XMLNode& node)
2417 const XMLProperty* prop;
2419 int x, y, xoff, yoff;
2422 if ((prop = node.property ("id")) != 0) {
2423 _id = prop->value ();
2426 if ((geometry = find_named_node (node, "geometry")) == 0) {
2428 g.base_width = default_width;
2429 g.base_height = default_height;
2437 g.base_width = atoi(geometry->property("x-size")->value());
2438 g.base_height = atoi(geometry->property("y-size")->value());
2439 x = atoi(geometry->property("x-pos")->value());
2440 y = atoi(geometry->property("y-pos")->value());
2441 xoff = atoi(geometry->property("x-off")->value());
2442 yoff = atoi(geometry->property("y-off")->value());
2445 set_default_size (g.base_width, g.base_height);
2448 if (session && (prop = node.property ("playhead"))) {
2449 nframes64_t pos = atol (prop->value().c_str());
2450 playhead_cursor->set_position (pos);
2452 playhead_cursor->set_position (0);
2454 /* reset_x_origin() doesn't work right here, since the old
2455 position may be zero already, and it does nothing in such
2460 horizontal_adjustment.set_value (0);
2463 if ((prop = node.property ("mixer-width"))) {
2464 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2467 if ((prop = node.property ("zoom-focus"))) {
2468 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2471 if ((prop = node.property ("zoom"))) {
2472 reset_zoom (PBD::atof (prop->value()));
2475 if ((prop = node.property ("snap-to"))) {
2476 set_snap_to ((SnapType) atoi (prop->value()));
2479 if ((prop = node.property ("snap-mode"))) {
2480 set_snap_mode ((SnapMode) atoi (prop->value()));
2483 if ((prop = node.property ("edit-point"))) {
2484 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2487 if ((prop = node.property ("mouse-mode"))) {
2488 MouseMode m = str2mousemode(prop->value());
2489 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2490 set_mouse_mode (m, true);
2492 mouse_mode = MouseGain; /* lie, to force the mode switch */
2493 set_mouse_mode (MouseObject, true);
2496 if ((prop = node.property ("show-waveforms"))) {
2497 bool yn = (prop->value() == "yes");
2498 _show_waveforms = !yn;
2499 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
2501 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2502 /* do it twice to force the change */
2503 tact->set_active (!yn);
2504 tact->set_active (yn);
2508 if ((prop = node.property ("show-waveforms-recording"))) {
2509 bool yn = (prop->value() == "yes");
2510 _show_waveforms_recording = !yn;
2511 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2513 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2514 /* do it twice to force the change */
2515 tact->set_active (!yn);
2516 tact->set_active (yn);
2520 if ((prop = node.property ("show-measures"))) {
2521 bool yn = (prop->value() == "yes");
2522 _show_measures = !yn;
2523 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2525 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2526 /* do it twice to force the change */
2527 tact->set_active (!yn);
2528 tact->set_active (yn);
2532 if ((prop = node.property ("follow-playhead"))) {
2533 bool yn = (prop->value() == "yes");
2534 set_follow_playhead (yn);
2535 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2537 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2538 if (tact->get_active() != yn) {
2539 tact->set_active (yn);
2544 if ((prop = node.property ("region-list-sort-type"))) {
2545 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2546 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2549 if ((prop = node.property ("xfades-visible"))) {
2550 bool yn = (prop->value() == "yes");
2551 _xfade_visibility = !yn;
2552 // set_xfade_visibility (yn);
2555 if ((prop = node.property ("show-editor-mixer"))) {
2557 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2560 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2561 bool yn = (prop->value() == X_("yes"));
2563 /* do it twice to force the change */
2565 tact->set_active (!yn);
2566 tact->set_active (yn);
2570 if ((prop = node.property ("show-editor-list"))) {
2572 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2576 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2577 bool yn = (prop->value() == X_("yes"));
2579 /* do it twice to force the change */
2581 tact->set_active (!yn);
2582 tact->set_active (yn);
2591 Editor::get_state ()
2593 XMLNode* node = new XMLNode ("Editor");
2596 _id.print (buf, sizeof (buf));
2597 node->add_property ("id", buf);
2599 if (is_realized()) {
2600 Glib::RefPtr<Gdk::Window> win = get_window();
2602 int x, y, xoff, yoff, width, height;
2603 win->get_root_origin(x, y);
2604 win->get_position(xoff, yoff);
2605 win->get_size(width, height);
2607 XMLNode* geometry = new XMLNode ("geometry");
2609 snprintf(buf, sizeof(buf), "%d", width);
2610 geometry->add_property("x-size", string(buf));
2611 snprintf(buf, sizeof(buf), "%d", height);
2612 geometry->add_property("y-size", string(buf));
2613 snprintf(buf, sizeof(buf), "%d", x);
2614 geometry->add_property("x-pos", string(buf));
2615 snprintf(buf, sizeof(buf), "%d", y);
2616 geometry->add_property("y-pos", string(buf));
2617 snprintf(buf, sizeof(buf), "%d", xoff);
2618 geometry->add_property("x-off", string(buf));
2619 snprintf(buf, sizeof(buf), "%d", yoff);
2620 geometry->add_property("y-off", string(buf));
2621 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2622 geometry->add_property("edit_pane_pos", string(buf));
2624 node->add_child_nocopy (*geometry);
2627 maybe_add_mixer_strip_width (*node);
2629 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2630 node->add_property ("zoom-focus", buf);
2631 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2632 node->add_property ("zoom", buf);
2633 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2634 node->add_property ("snap-to", buf);
2635 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2636 node->add_property ("snap-mode", buf);
2638 node->add_property ("edit-point", enum_2_string (_edit_point));
2640 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2641 node->add_property ("playhead", buf);
2643 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2644 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2645 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2646 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2647 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2648 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2649 node->add_property ("mouse-mode", enum2str(mouse_mode));
2651 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2653 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2654 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2657 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2659 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2660 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2669 Editor::trackview_by_y_position (double y)
2671 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2675 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2684 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2686 if (!session || snap_mode == SnapOff) {
2690 snap_to_internal (start, direction, for_mark);
2694 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2696 Location* before = 0;
2697 Location* after = 0;
2699 const nframes64_t one_second = session->frame_rate();
2700 const nframes64_t one_minute = session->frame_rate() * 60;
2701 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2702 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2703 nframes64_t presnap = start;
2705 switch (snap_type) {
2707 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2708 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2710 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2714 case SnapToSMPTEFrame:
2715 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2716 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2718 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2722 case SnapToSMPTESeconds:
2723 if (session->smpte_offset_negative())
2725 start += session->smpte_offset ();
2727 start -= session->smpte_offset ();
2729 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2730 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2732 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2735 if (session->smpte_offset_negative())
2737 start -= session->smpte_offset ();
2739 start += session->smpte_offset ();
2743 case SnapToSMPTEMinutes:
2744 if (session->smpte_offset_negative())
2746 start += session->smpte_offset ();
2748 start -= session->smpte_offset ();
2750 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2751 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2753 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2755 if (session->smpte_offset_negative())
2757 start -= session->smpte_offset ();
2759 start += session->smpte_offset ();
2764 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2765 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2767 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2772 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2773 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2775 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2780 start = session->tempo_map().round_to_bar (start, direction);
2784 start = session->tempo_map().round_to_beat (start, direction);
2787 case SnapToAThirtysecondBeat:
2788 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2791 case SnapToASixteenthBeat:
2792 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2795 case SnapToAEighthBeat:
2796 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2799 case SnapToAQuarterBeat:
2800 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2803 case SnapToAThirdBeat:
2804 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2812 before = session->locations()->first_location_before (start);
2813 after = session->locations()->first_location_after (start);
2815 if (direction < 0) {
2817 start = before->start();
2821 } else if (direction > 0) {
2823 start = after->start();
2825 start = session->current_end_frame();
2830 /* find nearest of the two */
2831 if ((start - before->start()) < (after->start() - start)) {
2832 start = before->start();
2834 start = after->start();
2837 start = before->start();
2840 start = after->start();
2847 case SnapToRegionStart:
2848 case SnapToRegionEnd:
2849 case SnapToRegionSync:
2850 case SnapToRegionBoundary:
2851 if (!region_boundary_cache.empty()) {
2852 vector<nframes64_t>::iterator i;
2854 if (direction > 0) {
2855 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2857 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2860 if (i != region_boundary_cache.end()) {
2862 /* lower bound doesn't quite to the right thing for our purposes */
2864 if (direction < 0 && i != region_boundary_cache.begin()) {
2871 start = region_boundary_cache.back();
2877 switch (snap_mode) {
2883 if (presnap > start) {
2884 if (presnap > (start + unit_to_frame(snap_threshold))) {
2888 } else if (presnap < start) {
2889 if (presnap < (start - unit_to_frame(snap_threshold))) {
2895 /* handled at entry */
2902 Editor::snap_length_beats (nframes64_t start)
2908 /* FIXME: This could/should also work with non-tempo based snap settings (ie seconds) */
2910 switch (snap_type) {
2912 return session->tempo_map().meter_at(start).beats_per_bar();
2917 case SnapToAThirtysecondBeat:
2918 return 1.0 / (double)32.0;
2921 case SnapToASixteenthBeat:
2922 return 1.0 / (double)16.0;
2925 case SnapToAEighthBeat:
2926 return 1.0 / (double)8.0;
2929 case SnapToAQuarterBeat:
2930 return 1.0 / (double)4.0;
2933 case SnapToAThirdBeat:
2934 return 1.0 / (double)3.0;
2942 Editor::setup_toolbar ()
2947 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2949 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2952 /* Mode Buttons (tool selection) */
2954 vector<ToggleButton *> mouse_mode_buttons;
2956 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2957 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2958 mouse_mode_buttons.push_back (&mouse_move_button);
2960 if (!Profile->get_sae()) {
2961 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2962 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2963 mouse_mode_buttons.push_back (&mouse_select_button);
2965 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2966 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2967 mouse_mode_buttons.push_back (&mouse_gain_button);
2970 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2971 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2972 mouse_mode_buttons.push_back (&mouse_zoom_button);
2973 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2974 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2975 mouse_mode_buttons.push_back (&mouse_timefx_button);
2976 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2977 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2978 mouse_note_button.add (*(manage (new Image (::get_icon("tool_note")))));
2979 mouse_note_button.set_relief(Gtk::RELIEF_NONE);
2980 mouse_mode_buttons.push_back (&mouse_note_button);
2981 mouse_mode_buttons.push_back (&mouse_audition_button);
2983 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2985 HBox* mode_box = manage(new HBox);
2986 mode_box->set_border_width (2);
2987 mode_box->set_spacing(4);
2988 mouse_mode_button_box.set_spacing(1);
2989 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2990 if (!Profile->get_sae()) {
2991 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2993 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2994 if (!Profile->get_sae()) {
2995 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2997 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2998 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2999 mouse_mode_button_box.pack_start(mouse_note_button, true, true);
3000 mouse_mode_button_box.set_homogeneous(true);
3002 vector<string> edit_mode_strings;
3003 edit_mode_strings.push_back (edit_mode_to_string (Slide));
3004 edit_mode_strings.push_back (edit_mode_to_string (Splice));
3005 edit_mode_strings.push_back (edit_mode_to_string (Lock));
3007 edit_mode_selector.set_name ("EditModeSelector");
3008 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
3009 set_popdown_strings (edit_mode_selector, edit_mode_strings);
3010 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
3012 mode_box->pack_start(edit_mode_selector);
3013 mode_box->pack_start(mouse_mode_button_box);
3015 mouse_mode_tearoff = manage (new TearOff (*mode_box));
3016 mouse_mode_tearoff->set_name ("MouseModeBase");
3018 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3019 &mouse_mode_tearoff->tearoff_window()));
3020 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3021 &mouse_mode_tearoff->tearoff_window(), 1));
3022 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3023 &mouse_mode_tearoff->tearoff_window()));
3024 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3025 &mouse_mode_tearoff->tearoff_window(), 1));
3027 mouse_move_button.set_name ("MouseModeButton");
3028 mouse_select_button.set_name ("MouseModeButton");
3029 mouse_gain_button.set_name ("MouseModeButton");
3030 mouse_zoom_button.set_name ("MouseModeButton");
3031 mouse_timefx_button.set_name ("MouseModeButton");
3032 mouse_audition_button.set_name ("MouseModeButton");
3033 mouse_note_button.set_name ("MouseModeButton");
3035 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
3036 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
3037 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
3038 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
3039 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
3040 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
3041 ARDOUR_UI::instance()->tooltips().set_tip (mouse_note_button, _("Edit MIDI Notes"));
3043 mouse_move_button.unset_flags (CAN_FOCUS);
3044 mouse_select_button.unset_flags (CAN_FOCUS);
3045 mouse_gain_button.unset_flags (CAN_FOCUS);
3046 mouse_zoom_button.unset_flags (CAN_FOCUS);
3047 mouse_timefx_button.unset_flags (CAN_FOCUS);
3048 mouse_audition_button.unset_flags (CAN_FOCUS);
3049 mouse_note_button.unset_flags (CAN_FOCUS);
3051 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
3052 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
3054 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
3055 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
3056 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
3057 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
3058 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
3059 mouse_note_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseNote));
3061 // mouse_move_button.set_active (true);
3066 zoom_box.set_spacing (1);
3067 zoom_box.set_border_width (0);
3069 zoom_in_button.set_name ("EditorTimeButton");
3070 zoom_in_button.set_size_request(-1,16);
3071 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
3072 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
3073 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
3075 zoom_out_button.set_name ("EditorTimeButton");
3076 zoom_out_button.set_size_request(-1,16);
3077 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
3078 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
3079 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
3081 zoom_out_full_button.set_name ("EditorTimeButton");
3082 zoom_out_full_button.set_size_request(-1,16);
3083 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
3084 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
3085 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
3087 zoom_focus_selector.set_name ("ZoomFocusSelector");
3088 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
3089 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
3090 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
3091 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
3093 zoom_box.pack_start (zoom_focus_selector, true, true);
3094 zoom_box.pack_start (zoom_out_button, false, false);
3095 zoom_box.pack_start (zoom_in_button, false, false);
3096 zoom_box.pack_start (zoom_out_full_button, false, false);
3098 snap_box.set_spacing (1);
3099 snap_box.set_border_width (2);
3101 snap_type_selector.set_name ("SnapTypeSelector");
3102 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
3103 set_popdown_strings (snap_type_selector, snap_type_strings);
3104 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
3105 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
3107 snap_mode_selector.set_name ("SnapModeSelector");
3108 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
3109 set_popdown_strings (snap_mode_selector, snap_mode_strings);
3110 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
3111 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3113 edit_point_selector.set_name ("SnapModeSelector");
3114 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
3115 set_popdown_strings (edit_point_selector, edit_point_strings);
3116 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
3117 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
3119 snap_box.pack_start (edit_point_clock, false, false);
3120 snap_box.pack_start (snap_mode_selector, false, false);
3121 snap_box.pack_start (snap_type_selector, false, false);
3122 snap_box.pack_start (edit_point_selector, false, false);
3126 HBox *nudge_box = manage (new HBox);
3127 nudge_box->set_spacing(1);
3128 nudge_box->set_border_width (2);
3130 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
3131 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
3133 nudge_box->pack_start (nudge_backward_button, false, false);
3134 nudge_box->pack_start (nudge_forward_button, false, false);
3135 nudge_box->pack_start (nudge_clock, false, false);
3138 /* Pack everything in... */
3140 HBox* hbox = manage (new HBox);
3141 hbox->set_spacing(10);
3143 tools_tearoff = manage (new TearOff (*hbox));
3144 tools_tearoff->set_name ("MouseModeBase");
3146 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3147 &tools_tearoff->tearoff_window()));
3148 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3149 &tools_tearoff->tearoff_window(), 0));
3150 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3151 &tools_tearoff->tearoff_window()));
3152 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3153 &tools_tearoff->tearoff_window(), 0));
3155 toolbar_hbox.set_spacing (10);
3156 toolbar_hbox.set_border_width (1);
3158 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
3159 toolbar_hbox.pack_start (*tools_tearoff, false, false);
3162 hbox->pack_start (snap_box, false, false);
3163 // hbox->pack_start (zoom_box, false, false);
3164 hbox->pack_start (*nudge_box, false, false);
3168 toolbar_base.set_name ("ToolBarBase");
3169 toolbar_base.add (toolbar_hbox);
3171 toolbar_frame.set_shadow_type (SHADOW_OUT);
3172 toolbar_frame.set_name ("BaseFrame");
3173 toolbar_frame.add (toolbar_base);
3177 Editor::midi_panic_toggle ()
3180 session->midi_panic();
3181 midi_panic_button.set_active (false);
3182 midi_panic_button.set_state (STATE_NORMAL);
3187 Editor::setup_midi_toolbar ()
3191 /* Mode Buttons (tool selection) */
3193 vector<ToggleButton *> midi_tool_buttons;
3195 midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
3196 midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
3197 midi_tool_buttons.push_back (&midi_tool_pencil_button);
3198 midi_tool_select_button.add (*(manage (new Image (::get_icon("midi_tool_select")))));
3199 midi_tool_select_button.set_relief(Gtk::RELIEF_NONE);
3200 midi_tool_buttons.push_back (&midi_tool_select_button);
3201 midi_tool_resize_button.add (*(manage (new Image (::get_icon("strip_width")))));
3202 midi_tool_resize_button.set_relief(Gtk::RELIEF_NONE);
3203 midi_tool_buttons.push_back (&midi_tool_resize_button);
3204 midi_tool_erase_button.add (*(manage (new Image (::get_icon("midi_tool_erase")))));
3205 midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
3206 midi_tool_buttons.push_back (&midi_tool_erase_button);
3208 midi_tool_pencil_button.set_active(true);
3210 midi_tool_button_set = new GroupedButtons (midi_tool_buttons);
3212 midi_tool_button_box.set_border_width (2);
3213 midi_tool_button_box.set_spacing(1);
3214 midi_tool_button_box.pack_start(midi_tool_pencil_button, true, true);
3215 midi_tool_button_box.pack_start(midi_tool_select_button, true, true);
3216 midi_tool_button_box.pack_start(midi_tool_resize_button, true, true);
3217 midi_tool_button_box.pack_start(midi_tool_erase_button, true, true);
3218 midi_tool_button_box.set_homogeneous(true);
3220 midi_tool_pencil_button.set_name ("MouseModeButton");
3221 midi_tool_select_button.set_name ("MouseModeButton");
3222 midi_tool_resize_button.set_name ("MouseModeButton");
3223 midi_tool_erase_button.set_name ("MouseModeButton");
3225 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
3226 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
3227 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
3228 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
3230 midi_tool_pencil_button.unset_flags (CAN_FOCUS);
3231 midi_tool_select_button.unset_flags (CAN_FOCUS);
3232 midi_tool_resize_button.unset_flags (CAN_FOCUS);
3233 midi_tool_erase_button.unset_flags (CAN_FOCUS);
3235 midi_tool_pencil_button.signal_toggled().connect (bind (mem_fun(*this,
3236 &Editor::midi_edit_mode_toggled), Editing::MidiEditPencil));
3237 midi_tool_select_button.signal_toggled().connect (bind (mem_fun(*this,
3238 &Editor::midi_edit_mode_toggled), Editing::MidiEditSelect));
3239 midi_tool_resize_button.signal_toggled().connect (bind (mem_fun(*this,
3240 &Editor::midi_edit_mode_toggled), Editing::MidiEditResize));
3241 midi_tool_erase_button.signal_toggled().connect (bind (mem_fun(*this,
3242 &Editor::midi_edit_mode_toggled), Editing::MidiEditErase));
3246 VBox* panic_box = manage (new VBox);
3247 midi_panic_button.set_name("MidiPanicButton");
3248 midi_panic_button.signal_pressed().connect (
3249 mem_fun(this, &Editor::midi_panic_toggle));
3250 panic_box->pack_start (midi_panic_button, true, true);
3252 /* Pack everything in... */
3254 midi_tools_tearoff = manage (new TearOff (midi_tool_button_box));
3255 midi_tools_tearoff->set_name ("MouseModeBase");
3258 midi_tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3259 &midi_tools_tearoff->tearoff_window()));
3260 midi_tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3261 &midi_tools_tearoff->tearoff_window(), 0));
3262 midi_tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3263 &midi_tools_tearoff->tearoff_window()));
3264 midi_tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3265 &midi_tools_tearoff->tearoff_window(), 0));
3268 midi_toolbar_hbox.set_spacing (10);
3269 midi_toolbar_hbox.set_border_width (1);
3271 midi_toolbar_hbox.pack_start (*midi_tools_tearoff, false, true);
3273 midi_toolbar_hbox.pack_start(*panic_box, false, true, 4);
3275 midi_tool_button_box.show_all ();
3276 midi_toolbar_hbox.show_all();
3277 midi_tools_tearoff->show_all();
3279 midi_toolbar_base.set_name ("ToolBarBase");
3280 midi_toolbar_base.add (midi_toolbar_hbox);
3282 midi_toolbar_frame.set_shadow_type (SHADOW_OUT);
3283 midi_toolbar_frame.set_name ("BaseFrame");
3284 midi_toolbar_frame.add (midi_toolbar_base);
3288 Editor::convert_drop_to_paths (vector<ustring>& paths,
3289 const RefPtr<Gdk::DragContext>& context,
3292 const SelectionData& data,
3301 vector<ustring> uris = data.get_uris();
3305 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3306 are actually URI lists. So do it by hand.
3309 if (data.get_target() != "text/plain") {
3313 /* Parse the "uri-list" format that Nautilus provides,
3314 where each pathname is delimited by \r\n
3317 const char* p = data.get_text().c_str();
3324 while (g_ascii_isspace (*p))
3328 while (*q && (*q != '\n') && (*q != '\r'))
3334 while (q > p && g_ascii_isspace (*q))
3339 uris.push_back (ustring (p, q - p + 1));
3343 p = strchr (p, '\n');
3353 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3355 if ((*i).substr (0,7) == "file://") {
3358 PBD::url_decode (p);
3360 // scan forward past three slashes
3362 ustring::size_type slashcnt = 0;
3363 ustring::size_type n = 0;
3364 ustring::iterator x = p.begin();
3366 while (slashcnt < 3 && x != p.end()) {
3369 } else if (slashcnt == 3) {
3376 if (slashcnt != 3 || x == p.end()) {
3377 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3381 paths.push_back (p.substr (n - 1));
3389 Editor::new_tempo_section ()
3395 Editor::map_transport_state ()
3397 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3399 if (session->transport_stopped()) {
3400 have_pending_keyboard_selection = false;
3403 update_loop_range_view (true);
3408 Editor::State::State (PublicEditor const * e)
3410 selection = new Selection (e);
3413 Editor::State::~State ()
3419 Editor::get_memento () const
3421 State *state = new State (this);
3423 store_state (*state);
3424 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
3428 Editor::store_state (State& state) const
3430 *state.selection = *selection;
3434 Editor::restore_state (State *state)
3436 if (*selection == *state->selection) {
3440 *selection = *state->selection;
3441 time_selection_changed ();
3442 region_selection_changed ();
3444 /* XXX other selection change handlers? */
3448 Editor::begin_reversible_command (string name)
3451 before = &get_state();
3452 session->begin_reversible_command (name);
3457 Editor::commit_reversible_command ()
3460 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3465 Editor::set_edit_group_solo (Route& route, bool yn)
3467 RouteGroup *edit_group;
3469 if ((edit_group = route.edit_group()) != 0) {
3470 edit_group->apply (&Route::set_solo, yn, this);
3472 route.set_solo (yn, this);
3477 Editor::set_edit_group_mute (Route& route, bool yn)
3479 RouteGroup *edit_group = 0;
3481 if ((edit_group == route.edit_group()) != 0) {
3482 edit_group->apply (&Route::set_mute, yn, this);
3484 route.set_mute (yn, this);
3489 Editor::history_changed ()
3493 if (undo_action && session) {
3494 if (session->undo_depth() == 0) {
3497 label = string_compose(_("Undo (%1)"), session->next_undo());
3499 undo_action->property_label() = label;
3502 if (redo_action && session) {
3503 if (session->redo_depth() == 0) {
3506 label = string_compose(_("Redo (%1)"), session->next_redo());
3508 redo_action->property_label() = label;
3513 Editor::duplicate_dialog (bool with_dialog)
3517 if (mouse_mode == MouseRange) {
3518 if (selection->time.length() == 0) {
3524 get_regions_for_action (rs);
3526 if (mouse_mode != MouseRange) {
3535 ArdourDialog win ("Duplication Dialog");
3536 Label label (_("Number of Duplications:"));
3537 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3538 SpinButton spinner (adjustment, 0.0, 1);
3541 win.get_vbox()->set_spacing (12);
3542 win.get_vbox()->pack_start (hbox);
3543 hbox.set_border_width (6);
3544 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3546 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3547 place, visually. so do this by hand.
3550 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3551 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3552 spinner.grab_focus();
3558 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3559 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3560 win.set_default_response (RESPONSE_ACCEPT);
3562 win.set_position (WIN_POS_MOUSE);
3564 spinner.grab_focus ();
3566 switch (win.run ()) {
3567 case RESPONSE_ACCEPT:
3573 times = adjustment.get_value();
3576 if (mouse_mode == MouseRange) {
3577 duplicate_selection (times);
3579 duplicate_some_regions (rs, times);
3584 Editor::show_verbose_canvas_cursor ()
3586 verbose_canvas_cursor->raise_to_top();
3587 verbose_canvas_cursor->show();
3588 verbose_cursor_visible = true;
3592 Editor::hide_verbose_canvas_cursor ()
3594 verbose_canvas_cursor->hide();
3595 verbose_cursor_visible = false;
3599 Editor::clamp_verbose_cursor_x (double x)
3604 x = min (canvas_width - 200.0, x);
3610 Editor::clamp_verbose_cursor_y (double y)
3612 if (y < canvas_timebars_vsize) {
3613 y = canvas_timebars_vsize;
3615 y = min (canvas_height - 50, y);
3621 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3623 verbose_canvas_cursor->property_text() = txt.c_str();
3624 /* don't get too close to the edge */
3625 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3626 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3630 Editor::set_verbose_canvas_cursor_text (const string & txt)
3632 verbose_canvas_cursor->property_text() = txt.c_str();
3636 Editor::set_edit_mode (EditMode m)
3638 Config->set_edit_mode (m);
3642 Editor::cycle_edit_mode ()
3644 switch (Config->get_edit_mode()) {
3646 Config->set_edit_mode (Splice);
3649 Config->set_edit_mode (Lock);
3652 Config->set_edit_mode (Slide);
3658 Editor::edit_mode_selection_done ()
3664 string choice = edit_mode_selector.get_active_text();
3665 EditMode mode = Slide;
3667 if (choice == _("Splice Edit")) {
3669 } else if (choice == _("Slide Edit")) {
3671 } else if (choice == _("Lock Edit")) {
3675 Config->set_edit_mode (mode);
3679 Editor::snap_type_selection_done ()
3681 string choice = snap_type_selector.get_active_text();
3682 SnapType snaptype = SnapToBeat;
3684 if (choice == _("Beats/3")) {
3685 snaptype = SnapToAThirdBeat;
3686 } else if (choice == _("Beats/4")) {
3687 snaptype = SnapToAQuarterBeat;
3688 } else if (choice == _("Beats/8")) {
3689 snaptype = SnapToAEighthBeat;
3690 } else if (choice == _("Beats/16")) {
3691 snaptype = SnapToASixteenthBeat;
3692 } else if (choice == _("Beats/32")) {
3693 snaptype = SnapToAThirtysecondBeat;
3694 } else if (choice == _("Beats")) {
3695 snaptype = SnapToBeat;
3696 } else if (choice == _("Bars")) {
3697 snaptype = SnapToBar;
3698 } else if (choice == _("Marks")) {
3699 snaptype = SnapToMark;
3700 } else if (choice == _("Region starts")) {
3701 snaptype = SnapToRegionStart;
3702 } else if (choice == _("Region ends")) {
3703 snaptype = SnapToRegionEnd;
3704 } else if (choice == _("Region bounds")) {
3705 snaptype = SnapToRegionBoundary;
3706 } else if (choice == _("Region syncs")) {
3707 snaptype = SnapToRegionSync;
3708 } else if (choice == _("CD Frames")) {
3709 snaptype = SnapToCDFrame;
3710 } else if (choice == _("SMPTE Frames")) {
3711 snaptype = SnapToSMPTEFrame;
3712 } else if (choice == _("SMPTE Seconds")) {
3713 snaptype = SnapToSMPTESeconds;
3714 } else if (choice == _("SMPTE Minutes")) {
3715 snaptype = SnapToSMPTEMinutes;
3716 } else if (choice == _("Seconds")) {
3717 snaptype = SnapToSeconds;
3718 } else if (choice == _("Minutes")) {
3719 snaptype = SnapToMinutes;
3722 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3724 ract->set_active ();
3729 Editor::snap_mode_selection_done ()
3731 string choice = snap_mode_selector.get_active_text();
3732 SnapMode mode = SnapNormal;
3734 if (choice == _("No Grid")) {
3736 } else if (choice == _("Grid")) {
3738 } else if (choice == _("Magnetic")) {
3739 mode = SnapMagnetic;
3742 RefPtr<RadioAction> ract = snap_mode_action (mode);
3745 ract->set_active (true);
3750 Editor::cycle_edit_point (bool with_marker)
3752 switch (_edit_point) {
3754 set_edit_point_preference (EditAtPlayhead);
3756 case EditAtPlayhead:
3758 set_edit_point_preference (EditAtSelectedMarker);
3760 set_edit_point_preference (EditAtMouse);
3763 case EditAtSelectedMarker:
3764 set_edit_point_preference (EditAtMouse);
3770 Editor::edit_point_selection_done ()
3772 string choice = edit_point_selector.get_active_text();
3773 EditPoint ep = EditAtSelectedMarker;
3775 if (choice == _("Marker")) {
3776 set_edit_point_preference (EditAtSelectedMarker);
3777 } else if (choice == _("Playhead")) {
3778 set_edit_point_preference (EditAtPlayhead);
3780 set_edit_point_preference (EditAtMouse);
3783 RefPtr<RadioAction> ract = edit_point_action (ep);
3786 ract->set_active (true);
3791 Editor::zoom_focus_selection_done ()
3793 string choice = zoom_focus_selector.get_active_text();
3794 ZoomFocus focus_type = ZoomFocusLeft;
3796 if (choice == _("Left")) {
3797 focus_type = ZoomFocusLeft;
3798 } else if (choice == _("Right")) {
3799 focus_type = ZoomFocusRight;
3800 } else if (choice == _("Center")) {
3801 focus_type = ZoomFocusCenter;
3802 } else if (choice == _("Play")) {
3803 focus_type = ZoomFocusPlayhead;
3804 } else if (choice == _("Edit")) {
3805 focus_type = ZoomFocusEdit;
3806 } else if (choice == _("Active Mark")) {
3807 focus_type = ZoomFocusEdit;
3808 } else if (choice == _("Active Mark")) {
3809 focus_type = ZoomFocusEdit;
3811 focus_type = ZoomFocusMouse;
3814 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3817 ract->set_active ();
3822 Editor::edit_controls_button_release (GdkEventButton* ev)
3824 if (Keyboard::is_context_menu_event (ev)) {
3825 ARDOUR_UI::instance()->add_route (this);
3831 Editor::mouse_select_button_release (GdkEventButton* ev)
3833 /* this handles just right-clicks */
3835 if (ev->button != 3) {
3842 Editor::TrackViewList *
3843 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3846 TrackViewList::iterator i;
3848 v = new TrackViewList;
3850 if (track == 0 && group == 0) {
3854 for (i = track_views.begin(); i != track_views.end (); ++i) {
3858 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->is_active())) {
3860 /* just the view for this track
3863 v->push_back (track);
3867 /* views for all tracks in the edit group */
3869 for (i = track_views.begin(); i != track_views.end (); ++i) {
3871 if (group == 0 || (*i)->edit_group() == group) {
3881 Editor::set_zoom_focus (ZoomFocus f)
3883 string str = zoom_focus_strings[(int)f];
3885 if (str != zoom_focus_selector.get_active_text()) {
3886 zoom_focus_selector.set_active_text (str);
3889 if (zoom_focus != f) {
3892 ZoomFocusChanged (); /* EMIT_SIGNAL */
3899 Editor::ensure_float (Window& win)
3901 win.set_transient_for (*this);
3905 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3907 /* recover or initialize pane positions. do this here rather than earlier because
3908 we don't want the positions to change the child allocations, which they seem to do.
3914 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3916 static int32_t done;
3919 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3920 width = default_width;
3921 height = default_height;
3923 width = atoi(geometry->property("x-size")->value());
3924 height = atoi(geometry->property("y-size")->value());
3927 if (which == static_cast<Paned*> (&edit_pane)) {
3933 if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
3934 /* initial allocation is 90% to canvas, 10% to notebook */
3935 pos = (int) floor (alloc.get_width() * 0.90f);
3936 snprintf (buf, sizeof(buf), "%d", pos);
3938 pos = atoi (prop->value());
3941 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3942 edit_pane.set_position (pos);
3943 pre_maximal_pane_position = pos;
3949 Editor::detach_tearoff (Box* b, Window* w)
3951 if (tools_tearoff->torn_off() &&
3952 mouse_mode_tearoff->torn_off()) {
3953 top_hbox.remove (toolbar_frame);
3958 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3960 if (toolbar_frame.get_parent() == 0) {
3961 top_hbox.pack_end (toolbar_frame);
3966 Editor::set_show_measures (bool yn)
3968 if (_show_measures != yn) {
3971 if ((_show_measures = yn) == true) {
3973 tempo_lines->show();
3981 Editor::toggle_follow_playhead ()
3983 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3985 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3986 set_follow_playhead (tact->get_active());
3991 Editor::set_follow_playhead (bool yn)
3993 if (_follow_playhead != yn) {
3994 if ((_follow_playhead = yn) == true) {
3996 update_current_screen ();
4003 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
4005 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
4007 xfade->set_active (!xfade->active());
4012 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
4014 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
4016 xfade->set_follow_overlap (!xfade->following_overlap());
4021 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
4023 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
4029 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
4033 switch (cew.run ()) {
4034 case RESPONSE_ACCEPT:
4041 xfade->StateChanged (Change (~0));
4045 Editor::playlist_selector () const
4047 return *_playlist_selector;
4051 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
4055 ret = nudge_clock.current_duration (pos);
4056 next = ret + 1; /* XXXX fix me */
4062 Editor::end_location_changed (Location* location)
4064 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
4065 //reset_scrolling_region ();
4066 horizontal_adjustment.set_upper ( location->start());
4070 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
4072 ArdourDialog dialog ("playlist deletion dialog");
4073 Label label (string_compose (_("Playlist %1 is currently unused.\n"
4074 "If left alone, no audio files used by it will be cleaned.\n"
4075 "If deleted, audio files used by it alone by will cleaned."),
4078 dialog.set_position (WIN_POS_CENTER);
4079 dialog.get_vbox()->pack_start (label);
4083 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
4084 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
4085 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
4087 switch (dialog.run ()) {
4088 case RESPONSE_ACCEPT:
4089 /* delete the playlist */
4093 case RESPONSE_REJECT:
4094 /* keep the playlist */
4106 Editor::audio_region_selection_covers (nframes64_t where)
4108 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
4109 if ((*a)->region()->covers (where)) {
4118 Editor::prepare_for_cleanup ()
4120 cut_buffer->clear_regions ();
4121 cut_buffer->clear_playlists ();
4123 selection->clear_regions ();
4124 selection->clear_playlists ();
4126 no_region_list_redisplay = true;
4130 Editor::finish_cleanup ()
4132 no_region_list_redisplay = false;
4133 redisplay_regions ();
4137 Editor::transport_loop_location()
4140 return session->locations()->auto_loop_location();
4147 Editor::transport_punch_location()
4150 return session->locations()->auto_punch_location();
4157 Editor::control_layout_scroll (GdkEventScroll* ev)
4159 switch (ev->direction) {
4161 scroll_tracks_up_line ();
4165 case GDK_SCROLL_DOWN:
4166 scroll_tracks_down_line ();
4170 /* no left/right handling yet */
4178 /** A new snapshot has been selected.
4181 Editor::snapshot_display_selection_changed ()
4183 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
4185 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
4187 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
4189 if (snap_name.length() == 0) {
4193 if (session->snap_name() == snap_name) {
4197 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
4202 Editor::snapshot_display_button_press (GdkEventButton* ev)
4204 if (ev->button == 3) {
4205 /* Right-click on the snapshot list. Work out which snapshot it
4207 Gtk::TreeModel::Path path;
4208 Gtk::TreeViewColumn* col;
4211 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
4212 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
4214 Gtk::TreeModel::Row row = *iter;
4215 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
4224 /** Pop up the snapshot display context menu.
4225 * @param button Button used to open the menu.
4226 * @param time Menu open time.
4227 * @snapshot_name Name of the snapshot that the menu click was over.
4231 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
4233 using namespace Menu_Helpers;
4235 MenuList& items (snapshot_context_menu.items());
4238 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
4240 add_item_with_sensitivity (items, MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)), modification_allowed);
4242 add_item_with_sensitivity (items, MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)), modification_allowed);
4244 snapshot_context_menu.popup (button, time);
4248 Editor::rename_snapshot (Glib::ustring old_name)
4250 ArdourPrompter prompter(true);
4254 prompter.set_name ("Prompter");
4255 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
4256 prompter.set_prompt (_("New name of snapshot"));
4257 prompter.set_initial_text (old_name);
4259 if (prompter.run() == RESPONSE_ACCEPT) {
4260 prompter.get_result (new_name);
4261 if (new_name.length()) {
4262 session->rename_state (old_name, new_name);
4263 redisplay_snapshots ();
4270 Editor::remove_snapshot (Glib::ustring name)
4272 vector<string> choices;
4274 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
4276 choices.push_back (_("No, do nothing."));
4277 choices.push_back (_("Yes, remove it."));
4279 Gtkmm2ext::Choice prompter (prompt, choices);
4281 if (prompter.run () == 1) {
4282 session->remove_state (name);
4283 redisplay_snapshots ();
4288 Editor::redisplay_snapshots ()
4294 vector<sys::path> state_file_paths;
4296 get_state_files_in_directory (session->session_directory().root_path(),
4299 if (state_file_paths.empty()) return;
4301 vector<string> state_file_names(get_file_names_no_extension(state_file_paths));
4303 snapshot_display_model->clear ();
4305 for (vector<string>::iterator i = state_file_names.begin();
4306 i != state_file_names.end(); ++i)
4308 string statename = (*i);
4309 TreeModel::Row row = *(snapshot_display_model->append());
4311 /* this lingers on in case we ever want to change the visible
4312 name of the snapshot.
4315 string display_name;
4316 display_name = statename;
4318 if (statename == session->snap_name()) {
4319 snapshot_display.get_selection()->select(row);
4322 row[snapshot_display_columns.visible_name] = display_name;
4323 row[snapshot_display_columns.real_name] = statename;
4328 Editor::session_state_saved (string snap_name)
4330 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4331 redisplay_snapshots ();
4335 Editor::maximise_editing_space ()
4337 mouse_mode_tearoff->set_visible (false);
4338 tools_tearoff->set_visible (false);
4340 pre_maximal_pane_position = edit_pane.get_position();
4341 pre_maximal_editor_width = this->get_width();
4343 if(post_maximal_pane_position == 0) {
4344 post_maximal_pane_position = edit_pane.get_width();
4349 if(post_maximal_editor_width) {
4350 edit_pane.set_position (post_maximal_pane_position -
4351 abs(post_maximal_editor_width - pre_maximal_editor_width));
4353 edit_pane.set_position (post_maximal_pane_position);
4358 Editor::restore_editing_space ()
4360 // user changed width of pane during fullscreen
4362 if(post_maximal_pane_position != edit_pane.get_position()) {
4363 post_maximal_pane_position = edit_pane.get_position();
4368 mouse_mode_tearoff->set_visible (true);
4369 tools_tearoff->set_visible (true);
4370 post_maximal_editor_width = this->get_width();
4372 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4376 * Make new playlists for a given track and also any others that belong
4377 * to the same active edit group.
4382 Editor::new_playlists (TimeAxisView* v)
4384 begin_reversible_command (_("new playlists"));
4385 mapover_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
4386 commit_reversible_command ();
4390 * Use a copy of the current playlist for a given track and also any others that belong
4391 * to the same active edit group.
4396 Editor::copy_playlists (TimeAxisView* v)
4398 begin_reversible_command (_("copy playlists"));
4399 mapover_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
4400 commit_reversible_command ();
4404 * Clear the current playlist for a given track and also any others that belong
4405 * to the same active edit group.
4410 Editor::clear_playlists (TimeAxisView* v)
4412 begin_reversible_command (_("clear playlists"));
4413 mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
4414 commit_reversible_command ();
4418 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz)
4420 atv.use_new_playlist (sz > 1 ? false : true);
4424 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz)
4426 atv.use_copy_playlist (sz > 1 ? false : true);
4430 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t sz)
4432 atv.clear_playlist ();
4436 Editor::on_key_press_event (GdkEventKey* ev)
4438 return key_press_focus_accelerator_handler (*this, ev);
4442 Editor::on_key_release_event (GdkEventKey* ev)
4444 return Gtk::Window::on_key_release_event (ev);
4445 // return key_press_focus_accelerator_handler (*this, ev);
4449 Editor::reset_x_origin (nframes64_t frame)
4451 //cerr << "resetting x origin" << endl;
4452 queue_visual_change (frame);
4456 Editor::reset_zoom (double fpu)
4458 queue_visual_change (fpu);
4462 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4464 //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
4465 reset_x_origin (frame);
4468 if (!no_save_visual) {
4469 undo_visual_stack.push_back (current_visual_state(false));
4473 Editor::VisualState*
4474 Editor::current_visual_state (bool with_tracks)
4476 VisualState* vs = new VisualState;
4477 vs->y_position = vertical_adjustment.get_value();
4478 vs->frames_per_unit = frames_per_unit;
4479 vs->leftmost_frame = leftmost_frame;
4480 vs->zoom_focus = zoom_focus;
4481 vs->zoomed_to_region = zoomed_to_region;
4484 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4485 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4493 Editor::undo_visual_state ()
4495 if (undo_visual_stack.empty()) {
4499 VisualState* vs = undo_visual_stack.back();
4500 undo_visual_stack.pop_back();
4501 use_visual_state (*vs);
4502 redo_visual_stack.push_back (vs);
4506 Editor::redo_visual_state ()
4508 if (redo_visual_stack.empty()) {
4512 VisualState* vs = redo_visual_stack.back();
4513 redo_visual_stack.pop_back();
4514 use_visual_state (*vs);
4515 undo_visual_stack.push_back (vs);
4519 Editor::swap_visual_state ()
4521 if (undo_visual_stack.empty()) {
4522 redo_visual_state ();
4524 undo_visual_state ();
4529 Editor::use_visual_state (VisualState& vs)
4531 no_save_visual = 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));
4548 if (!vs.track_states.empty()) {
4549 update_route_visibility ();
4552 no_save_visual = false;
4556 Editor::set_frames_per_unit (double fpu)
4558 /* this is the core function that controls the zoom level of the canvas. it is called
4559 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4562 if (fpu == frames_per_unit) {
4571 /* don't allow zooms that fit more than the maximum number
4572 of frames into an 800 pixel wide space.
4575 if (max_frames / fpu < 800.0) {
4580 tempo_lines->tempo_map_changed();
4582 frames_per_unit = fpu;
4587 Editor::post_zoom ()
4589 // convert fpu to frame count
4591 nframes64_t frames = (nframes64_t) floor (frames_per_unit * canvas_width);
4593 if (frames_per_unit != zoom_range_clock.current_duration()) {
4594 zoom_range_clock.set (frames);
4597 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4598 if (!selection->tracks.empty()) {
4599 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4600 (*i)->reshow_selection (selection->time);
4603 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4604 (*i)->reshow_selection (selection->time);
4609 ZoomChanged (); /* EMIT_SIGNAL */
4611 reset_hscrollbar_stepping ();
4612 //reset_scrolling_region ();
4614 if (playhead_cursor) {
4615 playhead_cursor->set_position (playhead_cursor->current_frame);
4622 Editor::queue_visual_change (nframes64_t where)
4624 // pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4625 // pending_visual_change.time_origin = where;
4627 if (pending_visual_change.idle_handler_id < 0) {
4628 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4629 pending_visual_change.time_origin = where;
4630 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4635 Editor::queue_visual_change (double fpu)
4637 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4638 pending_visual_change.frames_per_unit = fpu;
4640 if (pending_visual_change.idle_handler_id < 0) {
4641 pending_visual_change.idle_handler_id = g_idle_add ( _idle_visual_changer, this);
4647 Editor::_idle_visual_changer (void* arg)
4649 return static_cast<Editor*>(arg)->idle_visual_changer ();
4653 Editor::idle_visual_changer ()
4655 VisualChange::Type p = pending_visual_change.pending;
4656 pending_visual_change.pending = (VisualChange::Type) 0;
4658 if (p & VisualChange::ZoomLevel) {
4659 set_frames_per_unit (pending_visual_change.frames_per_unit);
4661 compute_fixed_ruler_scale ();
4662 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));
4663 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));
4664 update_tempo_based_rulers ();
4666 if (p & VisualChange::TimeOrigin) {
4668 nframes64_t csf=0, cef=0;
4669 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4672 csf = session->current_start_frame();
4673 cef = session->current_end_frame() + (current_page_frames() / 24);// Add a little extra so we can see the end marker
4676 /* if we seek beyond the current end of the canvas, move the end */
4678 if (current_time_origin != pending_visual_change.time_origin) {
4679 last_canvas_frame = (cef > (pending_visual_change.time_origin + current_page_frames())) ? cef : pending_visual_change.time_origin + current_page_frames();
4680 horizontal_adjustment.set_upper ((cef - csf) / frames_per_unit);
4681 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4683 update_fixed_rulers();
4684 redisplay_tempo (true);
4687 //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
4688 pending_visual_change.idle_handler_id = -1;
4689 return 0; /* this is always a one-shot call */
4692 struct EditorOrderTimeAxisSorter {
4693 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4694 return a->order < b->order;
4699 Editor::sort_track_selection (TrackSelection* sel)
4701 EditorOrderTimeAxisSorter cmp;
4706 selection->tracks.sort (cmp);
4711 Editor::get_preferred_edit_position (bool ignore_playhead)
4714 nframes64_t where = 0;
4715 EditPoint ep = _edit_point;
4717 if (entered_marker) {
4718 return entered_marker->position();
4721 if (ignore_playhead && ep == EditAtPlayhead) {
4722 ep = EditAtSelectedMarker;
4726 case EditAtPlayhead:
4727 where = session->audible_frame();
4730 case EditAtSelectedMarker:
4731 if (!selection->markers.empty()) {
4733 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4736 where = loc->start();
4747 if (!mouse_frame (where, ignored)) {
4748 /* XXX not right but what can we do ? */
4759 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4761 if (!session) return;
4763 begin_reversible_command (cmd);
4767 if ((tll = transport_loop_location()) == 0) {
4768 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4769 XMLNode &before = session->locations()->get_state();
4770 session->locations()->add (loc, true);
4771 session->set_auto_loop_location (loc);
4772 XMLNode &after = session->locations()->get_state();
4773 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4775 XMLNode &before = tll->get_state();
4776 tll->set_hidden (false, this);
4777 tll->set (start, end);
4778 XMLNode &after = tll->get_state();
4779 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4782 commit_reversible_command ();
4786 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4788 if (!session) return;
4790 begin_reversible_command (cmd);
4794 if ((tpl = transport_punch_location()) == 0) {
4795 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4796 XMLNode &before = session->locations()->get_state();
4797 session->locations()->add (loc, true);
4798 session->set_auto_loop_location (loc);
4799 XMLNode &after = session->locations()->get_state();
4800 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4803 XMLNode &before = tpl->get_state();
4804 tpl->set_hidden (false, this);
4805 tpl->set (start, end);
4806 XMLNode &after = tpl->get_state();
4807 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4810 commit_reversible_command ();
4814 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4816 const TrackSelection* tracks;
4819 tracks = &track_views;
4824 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4826 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4829 boost::shared_ptr<Diskstream> ds;
4830 boost::shared_ptr<Playlist> pl;
4832 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4834 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)where * ds->speed()));
4836 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4838 RegionView* rv = atv->audio_view()->find_view (*i);
4852 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4854 const TrackSelection* tracks;
4857 tracks = &track_views;
4862 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4864 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4867 boost::shared_ptr<Diskstream> ds;
4868 boost::shared_ptr<Playlist> pl;
4870 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4872 Playlist::RegionList* regions = pl->regions_touched ((nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4874 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4876 RegionView* rv = atv->audio_view()->find_view (*i);
4890 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4892 if (selection->regions.empty()) {
4894 if (selection->tracks.empty()) {
4896 /* no regions or tracks selected
4899 if (entered_regionview && mouse_mode == Editing::MouseObject) {
4901 /* entered regionview is valid and we're in object mode -
4902 just use entered regionview
4905 rs.add (entered_regionview);
4912 /* no regions selected, so get all regions at the edit point across
4913 all selected tracks.
4916 nframes64_t where = get_preferred_edit_position();
4917 get_regions_at (rs, where, selection->tracks);
4919 /* if the entered regionview wasn't selected and neither was its track
4923 if (entered_regionview != 0 &&
4924 !selection->selected (entered_regionview) &&
4925 !selection->selected (&entered_regionview->get_time_axis_view())) {
4926 rs.add (entered_regionview);
4932 /* just use the selected regions */
4934 rs = selection->regions;
4936 /* if the entered regionview wasn't selected and we allow this sort of thing,
4940 if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
4941 rs.add (entered_regionview);
4948 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4951 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4953 RouteTimeAxisView* tatv;
4955 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4957 boost::shared_ptr<Playlist> pl;
4958 vector<boost::shared_ptr<Region> > results;
4960 boost::shared_ptr<Diskstream> ds;
4962 if ((ds = tatv->get_diskstream()) == 0) {
4967 if ((pl = (ds->playlist())) != 0) {
4968 pl->get_region_list_equivalent_regions (region, results);
4971 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4972 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4973 regions.push_back (marv);
4982 Editor::show_rhythm_ferret ()
4984 if (rhythm_ferret == 0) {
4985 rhythm_ferret = new RhythmFerret(*this);
4988 rhythm_ferret->set_session (session);
4989 rhythm_ferret->show ();
4990 rhythm_ferret->present ();
4994 Editor::first_idle ()
4996 MessageDialog* dialog = 0;
4998 if (track_views.size() > 1) {
4999 dialog = new MessageDialog (*this,
5000 _("Please wait while Ardour loads visual data"),
5005 ARDOUR_UI::instance()->flush_pending ();
5008 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
5020 Editor::start_resize_line_ops ()
5023 old_resize_line_y = -1;
5025 need_resize_line = true;
5030 Editor::end_resize_line_ops ()
5033 need_resize_line = false;
5035 if (old_resize_line_y >= 0) {
5036 Gdk::Rectangle r (0, old_resize_line_y, (int) canvas_width, 3);
5037 Glib::RefPtr<Gdk::Window> win = get_window();
5038 cerr << "Final invalidation at " << old_resize_line_y << endl;
5039 win->invalidate_rect (r, false);
5045 Editor::queue_draw_resize_line (int at)
5048 Glib::RefPtr<Gdk::Window> win = get_window();
5052 if (win && canvas_width) {
5054 int controls_width = controls_layout.get_width();
5057 controls_layout.get_window()->get_origin (xroot, discard);
5059 if (old_resize_line_y >= 0) {
5061 /* redraw where it used to be */
5064 Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) canvas_width, 3);
5065 win->invalidate_rect (r, true);
5066 cerr << "invalidate " << xroot << "," << old_resize_line_y - 1 << ' '
5067 << controls_width + canvas_width << " x 3\n";
5070 /* draw where it is */
5072 Gdk::Rectangle r (0, at - 1, controls_width + (int) canvas_width, 3);
5073 win->invalidate_rect (r, true);
5079 Editor::on_expose_event (GdkEventExpose* ev)
5081 /* cerr << "+++ editor expose "
5082 << ev->area.x << ',' << ev->area.y
5084 << ev->area.width << " x " << ev->area.height
5085 << " need reize ? " << need_resize_line
5088 bool ret = Window::on_expose_event (ev);
5091 if (need_resize_line) {
5093 int xroot, yroot, discard;
5096 /* Our root coordinates for drawing the line will be the left edge
5097 of the track controls, and the upper left edge of our own window.
5100 get_window()->get_origin (discard, yroot);
5101 controls_layout.get_window()->get_origin (xroot, discard);
5102 controls_width = controls_layout.get_width();
5105 GdkRectangle intersection;
5108 lr.y = resize_line_y;
5109 lr.width = controls_width + (int) canvas_width;
5112 if (gdk_rectangle_intersect (&lr, &ev->area, &intersection)) {
5114 Glib::RefPtr<Gtk::Style> style (get_style());
5115 Glib::RefPtr<Gdk::GC> black_gc (style->get_black_gc ());
5116 Glib::RefPtr<Gdk::GC> gc = wrap (black_gc->gobj_copy(), false);
5118 /* draw on root window */
5120 GdkWindow* win = gdk_get_default_root_window();
5122 gc->set_subwindow (Gdk::INCLUDE_INFERIORS);
5123 gc->set_line_attributes (3, Gdk::LINE_SOLID,
5127 gdk_draw_line (win, gc->gobj(),
5130 (int) canvas_width + controls_width,
5133 cerr << "drew line @ " << xroot << ", " << yroot + resize_line_y
5134 << " to " << xroot + (int) canvas_width + controls_width
5135 << ", " << yroot + resize_line_y
5138 old_resize_line_y = resize_line_y;
5139 cerr << "NEXT EXPOSE SHOULD BE AT " << old_resize_line_y << endl;
5141 cerr << "no intersect with "
5142 << lr.x << ',' << lr.y
5144 << lr.width << " x " << lr.height
5149 //cerr << "--- editor expose\n";
5156 _idle_resizer (gpointer arg)
5158 return ((Editor*)arg)->idle_resize ();
5162 Editor::add_to_idle_resize (TimeAxisView* view, uint32_t h)
5164 if (resize_idle_id < 0) {
5165 resize_idle_id = g_idle_add (_idle_resizer, this);
5168 resize_idle_target = h;
5170 pending_resizes.push_back (view);
5172 if (selection->selected (view) && !selection->tracks.empty()) {
5173 pending_resizes.insert (pending_resizes.end(), selection->tracks.begin(), selection->tracks.end());
5178 Editor::idle_resize ()
5180 for (vector<TimeAxisView*>::iterator i = pending_resizes.begin(); i != pending_resizes.end(); ++i) {
5181 (*i)->idle_resize (resize_idle_target);
5183 pending_resizes.clear();
5184 resize_idle_id = -1;