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"
90 #include "analysis_window.h"
96 #include "imageframe_socket_handler.h"
100 using namespace sigc;
101 using namespace ARDOUR;
104 using namespace Glib;
105 using namespace Gtkmm2ext;
106 using namespace Editing;
108 using PBD::internationalize;
111 const double Editor::timebar_height = 15.0;
113 #include "editor_xpms"
115 static const gchar *_snap_type_strings[] = {
137 static const gchar *_snap_mode_strings[] = {
144 static const gchar *_edit_point_strings[] = {
151 static const gchar *_zoom_focus_strings[] = {
161 #ifdef USE_RUBBERBAND
162 static const gchar *_rb_opt_strings[] = {
165 N_("Balanced multitimbral mixture"),
166 N_("Unpitched percussion with stable notes"),
167 N_("Crisp monophonic instrumental"),
168 N_("Unpitched solo percussion"),
173 /* Soundfile drag-n-drop */
175 Gdk::Cursor* Editor::cross_hair_cursor = 0;
176 Gdk::Cursor* Editor::selector_cursor = 0;
177 Gdk::Cursor* Editor::trimmer_cursor = 0;
178 Gdk::Cursor* Editor::grabber_cursor = 0;
179 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
180 Gdk::Cursor* Editor::zoom_cursor = 0;
181 Gdk::Cursor* Editor::time_fx_cursor = 0;
182 Gdk::Cursor* Editor::fader_cursor = 0;
183 Gdk::Cursor* Editor::speaker_cursor = 0;
184 Gdk::Cursor* Editor::midi_pencil_cursor = 0;
185 Gdk::Cursor* Editor::midi_select_cursor = 0;
186 Gdk::Cursor* Editor::midi_resize_cursor = 0;
187 Gdk::Cursor* Editor::midi_erase_cursor = 0;
188 Gdk::Cursor* Editor::wait_cursor = 0;
189 Gdk::Cursor* Editor::timebar_cursor = 0;
190 Gdk::Cursor* Editor::transparent_cursor = 0;
193 show_me_the_size (Requisition* r, const char* what)
195 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
199 DragInfo::clear_copied_locations ()
201 for (list<Location*>::iterator i = copied_locations.begin(); i != copied_locations.end(); ++i) {
204 copied_locations.clear ();
209 /* time display buttons */
211 minsec_label (_("Mins:Secs")),
212 bbt_label (_("Bars:Beats")),
213 smpte_label (_("Timecode")),
214 frame_label (_("Samples")),
215 tempo_label (_("Tempo")),
216 meter_label (_("Meter")),
217 mark_label (_("Location Markers")),
218 range_mark_label (_("Range Markers")),
219 transport_mark_label (_("Loop/Punch Ranges")),
220 cd_mark_label (_("CD Markers")),
221 edit_packer (3, 4, true),
223 /* the values here don't matter: layout widgets
224 reset them as needed.
227 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
228 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
230 /* tool bar related */
232 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
233 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
235 toolbar_selection_clock_table (2,3),
237 automation_mode_button (_("mode")),
238 global_automation_button (_("automation")),
241 image_socket_listener(0),
246 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
247 meters_running(false)
252 /* we are a singleton */
254 PublicEditor::_instance = this;
259 selection = new Selection (this);
260 cut_buffer = new Selection (this);
262 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
263 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
264 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
265 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
266 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
268 clicked_regionview = 0;
269 clicked_axisview = 0;
270 clicked_routeview = 0;
271 clicked_crossfadeview = 0;
272 clicked_control_point = 0;
273 last_update_frame = 0;
275 current_mixer_strip = 0;
276 current_bbt_points = 0;
279 snap_type_strings = I18N (_snap_type_strings);
280 snap_mode_strings = I18N (_snap_mode_strings);
281 zoom_focus_strings = I18N (_zoom_focus_strings);
282 edit_point_strings = I18N (_edit_point_strings);
283 #ifdef USE_RUBBERBAND
284 rb_opt_strings = I18N (_rb_opt_strings);
287 snap_threshold = 5.0;
288 bbt_beat_subdivision = 4;
291 last_autoscroll_x = 0;
292 last_autoscroll_y = 0;
293 autoscroll_active = false;
294 autoscroll_timeout_tag = -1;
295 interthread_progress_window = 0;
302 current_interthread_info = 0;
303 _show_measures = true;
304 _show_waveforms = true;
305 _show_waveforms_recording = true;
306 first_action_message = 0;
307 show_gain_after_trim = false;
308 ignore_route_list_reorder = false;
309 no_route_list_redisplay = false;
310 verbose_cursor_on = true;
311 route_removal = false;
312 show_automatic_regions_in_region_list = true;
313 last_item_entered = 0;
314 last_item_entered_n = 0;
316 region_list_sort_type = (Editing::RegionListSortType) 0;
317 have_pending_keyboard_selection = false;
318 _follow_playhead = true;
319 _xfade_visibility = true;
320 editor_ruler_menu = 0;
321 no_ruler_shown_update = false;
322 edit_group_list_menu = 0;
324 region_list_menu = 0;
326 start_end_marker_menu = 0;
327 range_marker_menu = 0;
328 marker_menu_item = 0;
330 transport_marker_menu = 0;
331 new_transport_marker_menu = 0;
332 editor_mixer_strip_width = Wide;
333 show_editor_mixer_when_tracks_arrive = false;
334 region_edit_menu_split_multichannel_item = 0;
335 region_edit_menu_split_item = 0;
338 ignore_mouse_mode_toggle = false;
339 ignore_midi_edit_mode_toggle = false;
340 current_stepping_trackview = 0;
342 entered_regionview = 0;
344 clear_entered_track = false;
345 _new_regionviews_show_envelope = false;
347 in_edit_group_row_change = false;
348 last_canvas_frame = 0;
350 button_release_can_deselect = true;
351 _dragging_playhead = false;
352 _dragging_edit_point = false;
353 _dragging_hscrollbar = false;
354 select_new_marker = false;
355 zoomed_to_region = false;
357 allow_vertical_scroll = false;
358 no_save_visual = false;
359 need_resize_line = false;
361 old_resize_line_y = -1;
362 no_region_list_redisplay = false;
366 scrubbing_direction = 0;
369 ignore_route_order_sync = false;
371 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
372 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
373 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
374 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
375 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
377 range_marker_drag_rect = 0;
378 marker_drag_line = 0;
379 tempo_map_change_idle_handler_id = -1;
380 set_midi_edit_mode (MidiEditPencil, true);
381 set_mouse_mode (MouseObject, true);
383 frames_per_unit = 2048; /* too early to use reset_zoom () */
384 reset_hscrollbar_stepping ();
386 zoom_focus = ZoomFocusLeft;
387 set_zoom_focus (ZoomFocusLeft);
388 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
390 initialize_rulers ();
391 initialize_canvas ();
393 edit_controls_vbox.set_spacing (0);
394 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
395 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
396 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
398 controls_layout.add (edit_controls_vbox);
399 controls_layout.set_name ("EditControlsBase");
400 controls_layout.add_events (Gdk::SCROLL_MASK);
401 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
403 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
404 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
405 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
407 edit_vscrollbar.set_adjustment (vertical_adjustment);
408 edit_hscrollbar.set_adjustment (horizontal_adjustment);
410 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
411 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
412 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
414 edit_hscrollbar.set_name ("EditorHScrollbar");
418 setup_midi_toolbar ();
420 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
422 ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
423 ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
424 0.0, 1.0, 100.0, 1.0));
425 pad_line_1->property_color_rgba() = 0xFF0000FF;
429 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
430 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
431 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
432 time_canvas_vbox.pack_start (*frames_ruler, false, false);
433 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
434 //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
435 time_canvas_vbox.set_size_request (-1, -1);
436 bbt_label.set_name ("EditorTimeButton");
437 bbt_label.set_size_request (-1, (int)timebar_height);
438 bbt_label.set_alignment (1.0, 0.5);
439 bbt_label.set_padding (5,0);
440 minsec_label.set_name ("EditorTimeButton");
441 minsec_label.set_size_request (-1, (int)timebar_height);
442 minsec_label.set_alignment (1.0, 0.5);
443 minsec_label.set_padding (5,0);
444 smpte_label.set_name ("EditorTimeButton");
445 smpte_label.set_size_request (-1, (int)timebar_height);
446 smpte_label.set_alignment (1.0, 0.5);
447 smpte_label.set_padding (5,0);
448 frame_label.set_name ("EditorTimeButton");
449 frame_label.set_size_request (-1, (int)timebar_height);
450 frame_label.set_alignment (1.0, 0.5);
451 frame_label.set_padding (5,0);
453 tempo_label.set_name ("EditorTimeButton");
454 tempo_label.set_size_request (-1, (int)timebar_height);
455 tempo_label.set_alignment (1.0, 0.5);
456 tempo_label.set_padding (5,0);
457 meter_label.set_name ("EditorTimeButton");
458 meter_label.set_size_request (-1, (int)timebar_height);
459 meter_label.set_alignment (1.0, 0.5);
460 meter_label.set_padding (5,0);
461 mark_label.set_name ("EditorTimeButton");
462 mark_label.set_size_request (-1, (int)timebar_height);
463 mark_label.set_alignment (1.0, 0.5);
464 mark_label.set_padding (5,0);
465 cd_mark_label.set_name ("EditorTimeButton");
466 cd_mark_label.set_size_request (-1, (int)timebar_height);
467 cd_mark_label.set_alignment (1.0, 0.5);
468 cd_mark_label.set_padding (5,0);
469 range_mark_label.set_name ("EditorTimeButton");
470 range_mark_label.set_size_request (-1, (int)timebar_height);
471 range_mark_label.set_alignment (1.0, 0.5);
472 range_mark_label.set_padding (5,0);
473 transport_mark_label.set_name ("EditorTimeButton");
474 transport_mark_label.set_size_request (-1, (int)timebar_height);
475 transport_mark_label.set_alignment (1.0, 0.5);
476 transport_mark_label.set_padding (5,0);
478 ruler_label_vbox.pack_start (minsec_label, false, false);
479 ruler_label_vbox.pack_start (smpte_label, false, false);
480 ruler_label_vbox.pack_start (frame_label, false, false);
481 ruler_label_vbox.pack_start (bbt_label, false, false);
483 ruler_label_event_box.add (ruler_label_vbox);
484 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
485 ruler_label_event_box.set_name ("TimebarLabelBase");
486 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
488 time_button_vbox.pack_start (meter_label, false, false);
489 time_button_vbox.pack_start (tempo_label, false, false);
490 time_button_vbox.pack_start (mark_label, false, false);
492 time_button_event_box.add (time_button_vbox);
493 time_button_event_box.set_name ("TimebarLabelBase");
494 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
495 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
497 /* these enable us to have a dedicated window (for cursor setting, etc.)
498 for the canvas areas.
501 track_canvas_event_box.add (*track_canvas);
503 time_canvas_event_box.add (time_canvas_vbox);
504 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
506 edit_packer.set_col_spacings (0);
507 edit_packer.set_row_spacings (0);
508 edit_packer.set_homogeneous (false);
509 edit_packer.set_border_width (0);
510 edit_packer.set_name ("EditorWindow");
514 edit_packer.attach (ruler_label_event_box, 0, 1, 0, 1, FILL, SHRINK, 0, 0);
516 edit_packer.attach (time_button_event_box, 0, 1, 1, 2, FILL, SHRINK, 0, 0);
517 edit_packer.attach (time_canvas_event_box, 1, 2, 0, 1, FILL|EXPAND, FILL, 0, 0);
519 edit_packer.attach (controls_layout, 0, 1, 2, 3, FILL, FILL|EXPAND, 0, 0);
520 edit_packer.attach (track_canvas_event_box, 1, 2, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
522 edit_packer.attach (zoom_box, 0, 1, 3, 4, FILL, FILL, 0, 0);
523 edit_packer.attach (edit_hscrollbar, 1, 2, 3, 4, FILL|EXPAND, FILL, 0, 0);
525 edit_packer.attach (edit_vscrollbar, 3, 4, 2, 3, FILL, FILL|EXPAND, 0, 0);
529 edit_packer.attach (edit_vscrollbar, 0, 1, 0, 4, FILL, FILL|EXPAND, 0, 0);
531 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
532 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
533 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
535 edit_packer.attach (controls_layout, 1, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
536 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
538 edit_packer.attach (zoom_box, 1, 2, 3, 4, FILL, FILL, 0, 0);
539 edit_packer.attach (edit_hscrollbar, 2, 3, 3, 4, FILL|EXPAND, FILL, 0, 0);
542 bottom_hbox.set_border_width (2);
543 bottom_hbox.set_spacing (3);
545 route_display_model = ListStore::create(route_display_columns);
546 route_list_display.set_model (route_display_model);
547 route_list_display.append_column (_("Show"), route_display_columns.visible);
548 route_list_display.append_column (_("Name"), route_display_columns.text);
549 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
550 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
551 route_list_display.set_headers_visible (true);
552 route_list_display.set_name ("TrackListDisplay");
553 route_list_display.get_selection()->set_mode (SELECTION_SINGLE);
554 route_list_display.set_reorderable (true);
555 route_list_display.set_size_request (100,-1);
556 route_list_display.add_object_drag (route_display_columns.route.index(), "routes");
558 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
559 route_list_visible_cell->property_activatable() = true;
560 route_list_visible_cell->property_radio() = false;
562 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
563 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
565 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
567 route_list_scroller.add (route_list_display);
568 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
570 group_model = ListStore::create(group_columns);
571 edit_group_display.set_model (group_model);
572 edit_group_display.append_column (_("Name"), group_columns.text);
573 edit_group_display.append_column (_("Active"), group_columns.is_active);
574 edit_group_display.append_column (_("Show"), group_columns.is_visible);
575 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
576 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
577 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
578 edit_group_display.get_column (0)->set_expand (true);
579 edit_group_display.get_column (1)->set_expand (false);
580 edit_group_display.get_column (2)->set_expand (false);
581 edit_group_display.set_headers_visible (true);
583 /* name is directly editable */
585 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
586 name_cell->property_editable() = true;
587 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
589 /* use checkbox for the active + visible columns */
591 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
592 active_cell->property_activatable() = true;
593 active_cell->property_radio() = false;
595 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
596 active_cell->property_activatable() = true;
597 active_cell->property_radio() = false;
599 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
601 edit_group_display.set_name ("EditGroupList");
602 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
603 edit_group_display.set_headers_visible (true);
604 edit_group_display.set_reorderable (false);
605 edit_group_display.set_rules_hint (true);
606 edit_group_display.set_size_request (75, -1);
608 edit_group_display_scroller.add (edit_group_display);
609 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
611 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
613 VBox* edit_group_display_packer = manage (new VBox());
614 HBox* edit_group_display_button_box = manage (new HBox());
615 edit_group_display_button_box->set_homogeneous (true);
617 Button* edit_group_add_button = manage (new Button ());
618 Button* edit_group_remove_button = manage (new Button ());
622 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
624 edit_group_add_button->add (*w);
626 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
628 edit_group_remove_button->add (*w);
630 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
631 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
633 edit_group_display_button_box->pack_start (*edit_group_add_button);
634 edit_group_display_button_box->pack_start (*edit_group_remove_button);
636 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
637 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
639 region_list_display.set_size_request (100, -1);
640 region_list_display.set_name ("RegionListDisplay");
641 /* Try to prevent single mouse presses from initiating edits.
642 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
644 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
646 region_list_model = TreeStore::create (region_list_columns);
647 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
648 region_list_model->set_sort_column (0, SORT_ASCENDING);
650 region_list_display.set_model (region_list_model);
651 region_list_display.append_column (_("Regions"), region_list_columns.name);
652 region_list_display.append_column (_("Start"), region_list_columns.start);
653 region_list_display.append_column (_("End"), region_list_columns.end);
654 region_list_display.append_column (_("Length"), region_list_columns.length);
655 region_list_display.append_column (_("Used"), region_list_columns.used);
656 region_list_display.append_column (_("Path to parent file"), region_list_columns.path);
657 region_list_display.set_headers_visible (true);
659 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
660 region_name_cell->property_editable() = true;
661 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
663 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
665 TreeViewColumn* tv_col = region_list_display.get_column(0);
666 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
667 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
668 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
670 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
671 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
673 /* setup DnD handling */
675 list<TargetEntry> region_list_target_table;
677 region_list_target_table.push_back (TargetEntry ("text/plain"));
678 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
679 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
681 region_list_display.add_drop_targets (region_list_target_table);
682 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
684 region_list_scroller.add (region_list_display);
685 region_list_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
687 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
688 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
689 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
690 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
691 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
692 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
694 ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::redisplay_regions));
695 ARDOUR::Region::RegionPropertyChanged.connect (mem_fun(*this, &Editor::update_region_row));
697 named_selection_scroller.add (named_selection_display);
698 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
700 named_selection_model = TreeStore::create (named_selection_columns);
701 named_selection_display.set_model (named_selection_model);
702 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
703 named_selection_display.set_headers_visible (false);
704 named_selection_display.set_size_request (100, -1);
705 named_selection_display.set_name ("NamedSelectionDisplay");
707 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
708 named_selection_display.set_size_request (100, -1);
709 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
710 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
711 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
715 snapshot_display_model = ListStore::create (snapshot_display_columns);
716 snapshot_display.set_model (snapshot_display_model);
717 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
718 snapshot_display.set_name ("SnapshotDisplay");
719 snapshot_display.set_size_request (75, -1);
720 snapshot_display.set_headers_visible (false);
721 snapshot_display.set_reorderable (false);
722 snapshot_display_scroller.add (snapshot_display);
723 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
725 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
726 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
730 nlabel = manage (new Label (_("Regions")));
731 nlabel->set_angle (-90);
732 the_notebook.append_page (region_list_scroller, *nlabel);
733 nlabel = manage (new Label (_("Tracks/Busses")));
734 nlabel->set_angle (-90);
735 the_notebook.append_page (route_list_scroller, *nlabel);
736 nlabel = manage (new Label (_("Snapshots")));
737 nlabel->set_angle (-90);
738 the_notebook.append_page (snapshot_display_scroller, *nlabel);
739 nlabel = manage (new Label (_("Edit Groups")));
740 nlabel->set_angle (-90);
741 the_notebook.append_page (*edit_group_display_packer, *nlabel);
743 if (!Profile->get_sae()) {
744 nlabel = manage (new Label (_("Chunks")));
745 nlabel->set_angle (-90);
746 the_notebook.append_page (named_selection_scroller, *nlabel);
749 the_notebook.set_show_tabs (true);
750 the_notebook.set_scrollable (true);
751 the_notebook.popup_enable ();
752 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
753 the_notebook.show_all ();
755 post_maximal_editor_width = 0;
756 post_maximal_pane_position = 0;
757 edit_pane.pack1 (edit_packer, true, true);
758 edit_pane.pack2 (the_notebook, false, true);
760 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
762 top_hbox.pack_start (toolbar_frame, false, true);
763 top_hbox.pack_start (midi_toolbar_frame, false, true);
765 HBox *hbox = manage (new HBox);
766 hbox->pack_start (edit_pane, true, true);
768 global_vpacker.pack_start (top_hbox, false, false);
769 global_vpacker.pack_start (*hbox, true, true);
771 global_hpacker.pack_start (global_vpacker, true, true);
773 set_name ("EditorWindow");
774 add_accel_group (ActionManager::ui_manager->get_accel_group());
776 status_bar_hpacker.show ();
778 vpacker.pack_end (status_bar_hpacker, false, false);
779 vpacker.pack_end (global_hpacker, true, true);
781 /* register actions now so that set_state() can find them and set toggles/checks etc */
785 snap_type = SnapToBeat;
786 set_snap_to (snap_type);
788 set_snap_mode (snap_mode);
789 set_edit_point_preference (EditAtMouse, true);
791 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
794 _playlist_selector = new PlaylistSelector();
795 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
797 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
801 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
802 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
804 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
805 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
807 nudge_forward_button.set_name ("TransportButton");
808 nudge_backward_button.set_name ("TransportButton");
810 fade_context_menu.set_name ("ArdourContextMenu");
812 /* icons, titles, WM stuff */
814 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
815 Glib::RefPtr<Gdk::Pixbuf> icon;
817 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
818 window_icons.push_back (icon);
820 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
821 window_icons.push_back (icon);
823 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
824 window_icons.push_back (icon);
826 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
827 window_icons.push_back (icon);
829 if (!window_icons.empty()) {
830 set_icon_list (window_icons);
831 set_default_icon_list (window_icons);
834 WindowTitle title(Glib::get_application_name());
835 title += _("Editor");
836 set_title (title.get_string());
837 set_wmclass (X_("ardour_editor"), "Ardour");
840 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
842 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
843 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
845 /* allow external control surfaces/protocols to do various things */
847 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
848 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
849 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
850 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
851 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
853 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
854 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
863 if(image_socket_listener) {
864 if(image_socket_listener->is_connected())
866 image_socket_listener->close_connection() ;
869 delete image_socket_listener ;
870 image_socket_listener = 0 ;
881 Editor::add_toplevel_controls (Container& cont)
883 vpacker.pack_start (cont, false, false);
888 Editor::catch_vanishing_regionview (RegionView *rv)
890 /* note: the selection will take care of the vanishing
891 audioregionview by itself.
894 if (clicked_regionview == rv) {
895 clicked_regionview = 0;
898 if (entered_regionview == rv) {
899 set_entered_regionview (0);
904 Editor::set_entered_regionview (RegionView* rv)
906 if (rv == entered_regionview) {
910 if (entered_regionview) {
911 entered_regionview->exited ();
914 if ((entered_regionview = rv) != 0) {
915 entered_regionview->entered ();
920 Editor::set_entered_track (TimeAxisView* tav)
923 entered_track->exited ();
926 if ((entered_track = tav) != 0) {
927 entered_track->entered ();
932 Editor::show_window ()
934 show_all_children ();
936 /* re-hide editor list if necessary */
937 editor_list_button_toggled ();
939 /* now reset all audio_time_axis heights, because widgets might need
945 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
946 tv = (static_cast<TimeAxisView*>(*i));
954 Editor::instant_save ()
956 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
961 session->add_instant_xml(get_state());
963 Config->add_instant_xml(get_state());
968 Editor::edit_point_clock_changed()
970 if (_dragging_edit_point) {
974 if (selection->markers.empty()) {
979 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
985 loc->move_to (edit_point_clock.current_time());
989 Editor::zoom_adjustment_changed ()
995 double fpu = zoom_range_clock.current_duration() / canvas_width;
999 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
1000 } else if (fpu > session->current_end_frame() / canvas_width) {
1001 fpu = session->current_end_frame() / canvas_width;
1002 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
1005 temporal_zoom (fpu);
1009 Editor::control_scroll (float fraction)
1011 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
1017 double step = fraction * current_page_frames();
1020 _control_scroll_target is an optional<T>
1022 it acts like a pointer to an nframes64_t, with
1023 a operator conversion to boolean to check
1024 that it has a value could possibly use
1025 playhead_cursor->current_frame to store the
1026 value and a boolean in the class to know
1027 when it's out of date
1030 if (!_control_scroll_target) {
1031 _control_scroll_target = session->transport_frame();
1032 _dragging_playhead = true;
1035 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
1036 *_control_scroll_target = 0;
1037 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
1038 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
1040 *_control_scroll_target += (nframes64_t) floor (step);
1043 /* move visuals, we'll catch up with it later */
1045 playhead_cursor->set_position (*_control_scroll_target);
1046 UpdateAllTransportClocks (*_control_scroll_target);
1048 if (*_control_scroll_target > (current_page_frames() / 2)) {
1049 /* try to center PH in window */
1050 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
1056 Now we do a timeout to actually bring the session to the right place
1057 according to the playhead. This is to avoid reading disk buffers on every
1058 call to control_scroll, which is driven by ScrollTimeline and therefore
1059 probably by a control surface wheel which can generate lots of events.
1061 /* cancel the existing timeout */
1063 control_scroll_connection.disconnect ();
1065 /* add the next timeout */
1067 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
1071 Editor::deferred_control_scroll (nframes64_t target)
1073 session->request_locate (*_control_scroll_target, session->transport_rolling());
1074 // reset for next stream
1075 _control_scroll_target = boost::none;
1076 _dragging_playhead = false;
1081 Editor::access_action (std::string action_group, std::string action_item)
1087 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
1089 cout<< "OSC: Recieved: "<< action_item << endl;
1092 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1102 Editor::on_realize ()
1104 Window::on_realize ();
1109 Editor::start_scrolling ()
1111 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1112 (mem_fun(*this, &Editor::update_current_screen));
1117 Editor::stop_scrolling ()
1119 scroll_connection.disconnect ();
1123 Editor::map_position_change (nframes64_t frame)
1125 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1127 if (session == 0 || !_follow_playhead) {
1131 center_screen (frame);
1132 playhead_cursor->set_position (frame);
1136 Editor::center_screen (nframes64_t frame)
1138 double page = canvas_width * frames_per_unit;
1140 /* if we're off the page, then scroll.
1143 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1144 center_screen_internal (frame, page);
1149 Editor::center_screen_internal (nframes64_t frame, float page)
1154 frame -= (nframes64_t) page;
1159 reset_x_origin (frame);
1163 Editor::handle_new_duration ()
1165 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1167 nframes64_t new_end = session->get_maximum_extent() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1169 if (new_end > last_canvas_frame) {
1170 last_canvas_frame = new_end;
1171 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1172 //reset_scrolling_region ();
1175 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1176 //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
1180 Editor::update_title_s (const string & snap_name)
1182 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1188 Editor::update_title ()
1190 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1193 bool dirty = session->dirty();
1195 string session_name;
1197 if (session->snap_name() != session->name()) {
1198 session_name = session->snap_name();
1200 session_name = session->name();
1204 session_name = "*" + session_name;
1207 WindowTitle title(session_name);
1208 title += Glib::get_application_name();
1209 set_title (title.get_string());
1214 Editor::connect_to_session (Session *t)
1218 /* there are never any selected regions at startup */
1220 sensitize_the_right_region_actions (false);
1222 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1225 /* catch up with the playhead */
1227 session->request_locate (playhead_cursor->current_frame);
1229 if (first_action_message) {
1230 first_action_message->hide();
1235 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1236 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1238 /* These signals can all be emitted by a non-GUI thread. Therefore the
1239 handlers for them must not attempt to directly interact with the GUI,
1240 but use Gtkmm2ext::UI::instance()->call_slot();
1243 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1244 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1245 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1246 session_connections.push_back (session->RegionsAdded.connect (mem_fun(*this, &Editor::handle_new_regions)));
1247 session_connections.push_back (session->RegionRemoved.connect (mem_fun(*this, &Editor::handle_region_removed)));
1248 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1249 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1250 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1251 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1252 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1253 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1254 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1255 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1256 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1258 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1260 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1262 edit_groups_changed ();
1264 edit_point_clock.set_session (session);
1265 zoom_range_clock.set_session (session);
1266 _playlist_selector->set_session (session);
1267 nudge_clock.set_session (session);
1268 nudge_clock.set (session->frame_rate() * 5); // default of 5 seconds
1270 playhead_cursor->canvas_item.show ();
1272 if (rhythm_ferret) {
1273 rhythm_ferret->set_session (session);
1277 if (analysis_window != 0)
1278 analysis_window->set_session (session);
1281 Location* loc = session->locations()->auto_loop_location();
1283 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1284 if (loc->start() == loc->end()) {
1285 loc->set_end (loc->start() + 1);
1287 session->locations()->add (loc, false);
1288 session->set_auto_loop_location (loc);
1291 loc->set_name (_("Loop"));
1294 loc = session->locations()->auto_punch_location();
1296 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1297 if (loc->start() == loc->end()) {
1298 loc->set_end (loc->start() + 1);
1300 session->locations()->add (loc, false);
1301 session->set_auto_punch_location (loc);
1304 loc->set_name (_("Punch"));
1307 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1309 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1311 refresh_location_display ();
1312 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1313 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1314 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1315 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1316 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1319 sfbrowser->set_session (session);
1322 handle_new_duration ();
1324 redisplay_regions ();
1325 redisplay_named_selections ();
1326 redisplay_snapshots ();
1328 initial_route_list_display ();
1330 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1331 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1334 restore_ruler_visibility ();
1335 //tempo_map_changed (Change (0));
1336 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1340 /* don't show master bus in a new session */
1342 if (ARDOUR_UI::instance()->session_is_new ()) {
1344 TreeModel::Children rows = route_display_model->children();
1345 TreeModel::Children::iterator i;
1347 no_route_list_redisplay = true;
1349 for (i = rows.begin(); i != rows.end(); ++i) {
1350 TimeAxisView *tv = (*i)[route_display_columns.tv];
1351 RouteTimeAxisView *rtv;
1353 if ((rtv = dynamic_cast<RouteTimeAxisView*>(tv)) != 0) {
1354 if (rtv->route()->is_master()) {
1355 route_list_display.get_selection()->unselect (i);
1360 no_route_list_redisplay = false;
1361 redisplay_route_list ();
1364 switch (snap_type) {
1365 case SnapToRegionStart:
1366 case SnapToRegionEnd:
1367 case SnapToRegionSync:
1368 case SnapToRegionBoundary:
1369 build_region_boundary_cache ();
1376 /* register for undo history */
1377 session->register_with_memento_command_factory(_id, this);
1383 Editor::build_cursors ()
1385 using namespace Gdk;
1387 Gdk::Color mbg ("#000000" ); /* Black */
1388 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1391 RefPtr<Bitmap> source, mask;
1392 source = Bitmap::create (mag_bits, mag_width, mag_height);
1393 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1394 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1397 Gdk::Color fbg ("#ffffff" );
1398 Gdk::Color ffg ("#000000" );
1401 RefPtr<Bitmap> source, mask;
1403 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1404 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1405 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1409 RefPtr<Bitmap> source, mask;
1410 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1411 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1412 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1416 RefPtr<Bitmap> bits;
1417 char pix[4] = { 0, 0, 0, 0 };
1418 bits = Bitmap::create (pix, 2, 2);
1420 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1424 RefPtr<Bitmap> bits;
1425 char pix[4] = { 0, 0, 0, 0 };
1426 bits = Bitmap::create (pix, 2, 2);
1428 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1432 grabber_cursor = new Gdk::Cursor (HAND2);
1435 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1436 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1439 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1440 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1441 selector_cursor = new Gdk::Cursor (XTERM);
1442 time_fx_cursor = new Gdk::Cursor (SIZING);
1443 wait_cursor = new Gdk::Cursor (WATCH);
1444 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1445 midi_pencil_cursor = new Gdk::Cursor (PENCIL);
1446 midi_select_cursor = new Gdk::Cursor (CENTER_PTR);
1447 midi_resize_cursor = new Gdk::Cursor (SIZING);
1448 midi_erase_cursor = new Gdk::Cursor (DRAPED_BOX);
1451 /** Pop up a context menu for when the user clicks on a fade in or fade out */
1453 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1455 using namespace Menu_Helpers;
1456 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1459 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1463 MenuList& items (fade_context_menu.items());
1467 switch (item_type) {
1469 case FadeInHandleItem:
1470 if (arv->audio_region()->fade_in_active()) {
1471 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1473 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1476 items.push_back (SeparatorElem());
1478 if (Profile->get_sae()) {
1479 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1480 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1482 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1483 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1484 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1485 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1486 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1492 case FadeOutHandleItem:
1493 if (arv->audio_region()->fade_out_active()) {
1494 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1496 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1499 items.push_back (SeparatorElem());
1501 if (Profile->get_sae()) {
1502 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1503 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1505 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1506 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1507 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1508 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1509 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1515 fatal << _("programming error: ")
1516 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1521 fade_context_menu.popup (button, time);
1525 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1527 using namespace Menu_Helpers;
1528 Menu* (Editor::*build_menu_function)(nframes64_t);
1531 switch (item_type) {
1533 case RegionViewName:
1534 case RegionViewNameHighlight:
1535 if (with_selection) {
1536 build_menu_function = &Editor::build_track_selection_context_menu;
1538 build_menu_function = &Editor::build_track_region_context_menu;
1543 if (with_selection) {
1544 build_menu_function = &Editor::build_track_selection_context_menu;
1546 build_menu_function = &Editor::build_track_context_menu;
1550 case CrossfadeViewItem:
1551 build_menu_function = &Editor::build_track_crossfade_context_menu;
1555 if (clicked_routeview->get_diskstream()) {
1556 build_menu_function = &Editor::build_track_context_menu;
1558 build_menu_function = &Editor::build_track_bus_context_menu;
1563 /* probably shouldn't happen but if it does, we don't care */
1567 menu = (this->*build_menu_function)(frame);
1568 menu->set_name ("ArdourContextMenu");
1570 /* now handle specific situations */
1572 switch (item_type) {
1574 case RegionViewName:
1575 case RegionViewNameHighlight:
1576 if (!with_selection) {
1577 if (region_edit_menu_split_item) {
1578 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1579 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1581 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1585 if (region_edit_menu_split_multichannel_item) {
1586 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1587 // GTK2FIX find the action, change its sensitivity
1588 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1590 // GTK2FIX see above
1591 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1600 case CrossfadeViewItem:
1607 /* probably shouldn't happen but if it does, we don't care */
1611 if (item_type != SelectionItem && clicked_routeview && clicked_routeview->audio_track()) {
1613 /* Bounce to disk */
1615 using namespace Menu_Helpers;
1616 MenuList& edit_items = menu->items();
1618 edit_items.push_back (SeparatorElem());
1620 switch (clicked_routeview->audio_track()->freeze_state()) {
1621 case AudioTrack::NoFreeze:
1622 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1625 case AudioTrack::Frozen:
1626 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1629 case AudioTrack::UnFrozen:
1630 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1636 if (item_type == StreamItem && clicked_routeview) {
1637 clicked_routeview->build_underlay_menu(menu);
1640 menu->popup (button, time);
1644 Editor::build_track_context_menu (nframes64_t ignored)
1646 using namespace Menu_Helpers;
1648 MenuList& edit_items = track_context_menu.items();
1651 add_dstream_context_items (edit_items);
1652 return &track_context_menu;
1656 Editor::build_track_bus_context_menu (nframes64_t ignored)
1658 using namespace Menu_Helpers;
1660 MenuList& edit_items = track_context_menu.items();
1663 add_bus_context_items (edit_items);
1664 return &track_context_menu;
1668 Editor::build_track_region_context_menu (nframes64_t frame)
1670 using namespace Menu_Helpers;
1671 MenuList& edit_items = track_region_context_menu.items();
1674 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
1677 boost::shared_ptr<Diskstream> ds;
1678 boost::shared_ptr<Playlist> pl;
1680 if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
1681 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1683 if (selection->regions.size() > 1) {
1684 // there's already a multiple selection: just add a
1685 // single region context menu that will act on all
1687 boost::shared_ptr<Region> dummy_region; // = NULL
1688 add_region_context_items (rtv->view(), dummy_region, edit_items);
1690 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1691 add_region_context_items (rtv->view(), (*i), edit_items);
1699 add_dstream_context_items (edit_items);
1701 return &track_region_context_menu;
1705 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1707 using namespace Menu_Helpers;
1708 MenuList& edit_items = track_crossfade_context_menu.items();
1709 edit_items.clear ();
1711 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
1714 boost::shared_ptr<Diskstream> ds;
1715 boost::shared_ptr<Playlist> pl;
1716 boost::shared_ptr<AudioPlaylist> apl;
1718 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1720 Playlist::RegionList* regions = pl->regions_at (frame);
1721 AudioPlaylist::Crossfades xfades;
1723 apl->crossfades_at (frame, xfades);
1725 bool many = xfades.size() > 1;
1727 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1728 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1731 if (selection->regions.size() > 1) {
1732 // there's already a multiple selection: just add a
1733 // single region context menu that will act on all
1735 boost::shared_ptr<Region> dummy_region; // = NULL
1736 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1738 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1739 add_region_context_items (atv->audio_view(), (*i), edit_items);
1746 add_dstream_context_items (edit_items);
1748 return &track_crossfade_context_menu;
1753 Editor::analyze_region_selection()
1755 if (analysis_window == 0) {
1756 analysis_window = new AnalysisWindow();
1759 analysis_window->set_session(session);
1761 analysis_window->show_all();
1764 analysis_window->set_regionmode();
1765 analysis_window->analyze();
1767 analysis_window->present();
1771 Editor::analyze_range_selection()
1773 if (analysis_window == 0) {
1774 analysis_window = new AnalysisWindow();
1777 analysis_window->set_session(session);
1779 analysis_window->show_all();
1782 analysis_window->set_rangemode();
1783 analysis_window->analyze();
1785 analysis_window->present();
1787 #endif /* FFT_ANALYSIS */
1790 Editor::build_track_selection_context_menu (nframes64_t ignored)
1792 using namespace Menu_Helpers;
1793 MenuList& edit_items = track_selection_context_menu.items();
1794 edit_items.clear ();
1796 add_selection_context_items (edit_items);
1797 // edit_items.push_back (SeparatorElem());
1798 // add_dstream_context_items (edit_items);
1800 return &track_selection_context_menu;
1803 /** Add context menu items relevant to crossfades.
1804 * @param edit_items List to add the items to.
1807 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1809 using namespace Menu_Helpers;
1810 Menu *xfade_menu = manage (new Menu);
1811 MenuList& items = xfade_menu->items();
1812 xfade_menu->set_name ("ArdourContextMenu");
1815 if (xfade->active()) {
1821 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1822 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1824 if (xfade->can_follow_overlap()) {
1826 if (xfade->following_overlap()) {
1827 str = _("Convert to short");
1829 str = _("Convert to full");
1832 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1836 str = xfade->out()->name();
1838 str += xfade->in()->name();
1840 str = _("Crossfade");
1843 edit_items.push_back (MenuElem (str, *xfade_menu));
1844 edit_items.push_back (SeparatorElem());
1848 Editor::xfade_edit_left_region ()
1850 if (clicked_crossfadeview) {
1851 clicked_crossfadeview->left_view.show_region_editor ();
1856 Editor::xfade_edit_right_region ()
1858 if (clicked_crossfadeview) {
1859 clicked_crossfadeview->right_view.show_region_editor ();
1863 /** Add an element to a menu, settings its sensitivity.
1864 * @param m Menu to add to.
1865 * @param e Element to add.
1866 * @param s true to make sensitive, false to make insensitive
1869 Editor::add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s) const
1873 m.back().set_sensitive (false);
1878 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1880 using namespace Menu_Helpers;
1881 Menu *region_menu = manage (new Menu);
1882 MenuList& items = region_menu->items();
1883 region_menu->set_name ("ArdourContextMenu");
1885 boost::shared_ptr<AudioRegion> ar;
1886 boost::shared_ptr<MidiRegion> mr;
1889 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1890 mr = boost::dynamic_pointer_cast<MidiRegion> (region);
1892 /* when this particular menu pops up, make the relevant region
1896 region_menu->signal_map_event().connect (
1897 bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1899 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1900 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1903 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1904 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1905 items.push_back (SeparatorElem());
1906 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1907 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1908 items.push_back (SeparatorElem());
1910 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1911 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1912 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1916 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1920 items.push_back (SeparatorElem());
1922 sigc::connection fooc;
1923 boost::shared_ptr<Region> region_to_check;
1926 region_to_check = region;
1928 region_to_check = selection->regions.front()->region();
1931 items.push_back (CheckMenuElem (_("Lock")));
1932 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1933 if (region_to_check->locked()) {
1934 region_lock_item->set_active();
1936 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1938 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1939 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1941 switch (region_to_check->positional_lock_style()) {
1942 case Region::MusicTime:
1943 bbt_glue_item->set_active (true);
1946 bbt_glue_item->set_active (false);
1950 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1952 items.push_back (CheckMenuElem (_("Mute")));
1953 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1954 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1955 if (region_to_check->muted()) {
1957 region_mute_item->set_active();
1961 if (!Profile->get_sae()) {
1962 items.push_back (CheckMenuElem (_("Opaque")));
1963 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1964 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1965 if (region_to_check->opaque()) {
1967 region_opaque_item->set_active();
1972 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1973 if (region_to_check->at_natural_position()) {
1974 items.back().set_sensitive (false);
1977 items.push_back (SeparatorElem());
1981 RegionView* rv = sv->find_view (ar);
1982 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1984 if (!Profile->get_sae()) {
1985 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1987 items.push_back (CheckMenuElem (_("Envelope Visible")));
1988 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1989 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1990 if (arv->envelope_visible()) {
1992 region_envelope_visible_item->set_active (true);
1996 items.push_back (CheckMenuElem (_("Envelope Active")));
1997 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1998 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
2000 if (ar->envelope_active()) {
2002 region_envelope_active_item->set_active (true);
2006 items.push_back (SeparatorElem());
2009 if (ar->scale_amplitude() != 1.0f) {
2010 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
2012 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
2016 items.push_back (MenuElem (_("Quantize"), mem_fun(*this, &Editor::quantize_region)));
2017 items.push_back (SeparatorElem());
2020 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
2021 items.push_back (SeparatorElem());
2023 /* range related stuff */
2025 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
2026 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
2027 items.push_back (SeparatorElem());
2031 Menu *nudge_menu = manage (new Menu());
2032 MenuList& nudge_items = nudge_menu->items();
2033 nudge_menu->set_name ("ArdourContextMenu");
2035 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
2036 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
2037 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
2038 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
2040 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2041 items.push_back (SeparatorElem());
2043 Menu *trim_menu = manage (new Menu);
2044 MenuList& trim_items = trim_menu->items();
2045 trim_menu->set_name ("ArdourContextMenu");
2047 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
2048 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
2049 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
2050 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
2052 items.push_back (MenuElem (_("Trim"), *trim_menu));
2053 items.push_back (SeparatorElem());
2055 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
2056 region_edit_menu_split_item = &items.back();
2058 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
2059 region_edit_menu_split_multichannel_item = &items.back();
2061 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
2062 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
2063 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
2064 items.push_back (SeparatorElem());
2065 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
2067 /* OK, stick the region submenu at the top of the list, and then add
2071 /* we have to hack up the region name because "_" has a special
2072 meaning for menu titles.
2075 string::size_type pos = 0;
2076 string menu_item_name = (region) ? region->name() : _("Selected regions");
2078 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
2079 menu_item_name.replace (pos, 1, "__");
2083 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
2084 edit_items.push_back (SeparatorElem());
2087 /** Add context menu items relevant to selection ranges.
2088 * @param edit_items List to add the items to.
2091 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
2093 using namespace Menu_Helpers;
2094 Menu *selection_menu = manage (new Menu);
2095 MenuList& items = selection_menu->items();
2096 selection_menu->set_name ("ArdourContextMenu");
2098 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
2099 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
2102 items.push_back (SeparatorElem());
2103 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
2106 items.push_back (SeparatorElem());
2107 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
2108 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
2110 items.push_back (SeparatorElem());
2111 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
2112 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
2114 items.push_back (SeparatorElem());
2115 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
2117 items.push_back (SeparatorElem());
2118 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
2119 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
2121 items.push_back (SeparatorElem());
2122 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
2123 items.push_back (SeparatorElem());
2124 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
2125 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
2126 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
2127 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
2128 items.push_back (SeparatorElem());
2129 items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
2130 items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
2131 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_range)));
2136 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2138 using namespace Menu_Helpers;
2142 Menu *play_menu = manage (new Menu);
2143 MenuList& play_items = play_menu->items();
2144 play_menu->set_name ("ArdourContextMenu");
2146 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2147 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2148 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2149 play_items.push_back (SeparatorElem());
2150 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2152 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2156 Menu *select_menu = manage (new Menu);
2157 MenuList& select_items = select_menu->items();
2158 select_menu->set_name ("ArdourContextMenu");
2160 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2161 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2162 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2163 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2164 select_items.push_back (SeparatorElem());
2165 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2166 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2167 select_items.push_back (SeparatorElem());
2168 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2169 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2170 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2171 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2172 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2173 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2174 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2176 select_items.push_back (SeparatorElem());
2178 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2182 Menu *cutnpaste_menu = manage (new Menu);
2183 MenuList& cutnpaste_items = cutnpaste_menu->items();
2184 cutnpaste_menu->set_name ("ArdourContextMenu");
2186 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2187 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2188 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2190 cutnpaste_items.push_back (SeparatorElem());
2192 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2193 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2195 cutnpaste_items.push_back (SeparatorElem());
2197 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2199 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2201 /* Adding new material */
2203 edit_items.push_back (SeparatorElem());
2204 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2205 edit_items.push_back (MenuElem (_("Insert Existing Media"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2209 Menu *nudge_menu = manage (new Menu());
2210 MenuList& nudge_items = nudge_menu->items();
2211 nudge_menu->set_name ("ArdourContextMenu");
2213 edit_items.push_back (SeparatorElem());
2214 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2215 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2216 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2217 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2219 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2223 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2225 using namespace Menu_Helpers;
2229 Menu *play_menu = manage (new Menu);
2230 MenuList& play_items = play_menu->items();
2231 play_menu->set_name ("ArdourContextMenu");
2233 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2234 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2235 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2239 Menu *select_menu = manage (new Menu);
2240 MenuList& select_items = select_menu->items();
2241 select_menu->set_name ("ArdourContextMenu");
2243 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2244 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2245 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2246 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2247 select_items.push_back (SeparatorElem());
2248 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2249 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2250 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2251 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2253 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2257 Menu *cutnpaste_menu = manage (new Menu);
2258 MenuList& cutnpaste_items = cutnpaste_menu->items();
2259 cutnpaste_menu->set_name ("ArdourContextMenu");
2261 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2262 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2263 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2265 Menu *nudge_menu = manage (new Menu());
2266 MenuList& nudge_items = nudge_menu->items();
2267 nudge_menu->set_name ("ArdourContextMenu");
2269 edit_items.push_back (SeparatorElem());
2270 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2271 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2272 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2273 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2275 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2279 Editor::set_snap_to (SnapType st)
2281 unsigned int snap_ind = (unsigned int)st;
2285 if (snap_ind > snap_type_strings.size() - 1) {
2287 snap_type = (SnapType)snap_ind;
2290 string str = snap_type_strings[snap_ind];
2292 if (str != snap_type_selector.get_active_text()) {
2293 snap_type_selector.set_active_text (str);
2298 switch (snap_type) {
2299 case SnapToAThirtysecondBeat:
2300 case SnapToASixteenthBeat:
2301 case SnapToAEighthBeat:
2302 case SnapToAQuarterBeat:
2303 case SnapToAThirdBeat:
2304 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + (nframes_t)(edit_packer.get_width() * frames_per_unit));
2305 update_tempo_based_rulers ();
2308 case SnapToRegionStart:
2309 case SnapToRegionEnd:
2310 case SnapToRegionSync:
2311 case SnapToRegionBoundary:
2312 build_region_boundary_cache ();
2322 Editor::set_snap_mode (SnapMode mode)
2325 string str = snap_mode_strings[(int)mode];
2327 if (str != snap_mode_selector.get_active_text ()) {
2328 snap_mode_selector.set_active_text (str);
2334 Editor::set_edit_point_preference (EditPoint ep, bool force)
2336 bool changed = (_edit_point != ep);
2339 string str = edit_point_strings[(int)ep];
2341 if (str != edit_point_selector.get_active_text ()) {
2342 edit_point_selector.set_active_text (str);
2345 set_canvas_cursor ();
2347 if (!force && !changed) {
2351 switch (zoom_focus) {
2352 case ZoomFocusMouse:
2353 case ZoomFocusPlayhead:
2355 switch (_edit_point) {
2357 set_zoom_focus (ZoomFocusMouse);
2359 case EditAtPlayhead:
2360 set_zoom_focus (ZoomFocusPlayhead);
2362 case EditAtSelectedMarker:
2363 set_zoom_focus (ZoomFocusEdit);
2373 switch (_edit_point) {
2374 case EditAtPlayhead:
2375 action = "edit-at-playhead";
2377 case EditAtSelectedMarker:
2378 action = "edit-at-marker";
2381 action = "edit-at-mouse";
2385 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2387 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2391 bool in_track_canvas;
2393 if (!mouse_frame (foo, in_track_canvas)) {
2394 in_track_canvas = false;
2397 reset_canvas_action_sensitivity (in_track_canvas);
2403 Editor::set_state (const XMLNode& node)
2405 const XMLProperty* prop;
2407 int x, y, xoff, yoff;
2410 if ((prop = node.property ("id")) != 0) {
2411 _id = prop->value ();
2414 if ((geometry = find_named_node (node, "geometry")) == 0) {
2416 g.base_width = default_width;
2417 g.base_height = default_height;
2425 g.base_width = atoi(geometry->property("x_size")->value());
2426 g.base_height = atoi(geometry->property("y_size")->value());
2427 x = atoi(geometry->property("x_pos")->value());
2428 y = atoi(geometry->property("y_pos")->value());
2429 xoff = atoi(geometry->property("x_off")->value());
2430 yoff = atoi(geometry->property("y_off")->value());
2433 set_default_size (g.base_width, g.base_height);
2436 if (session && (prop = node.property ("playhead"))) {
2437 nframes64_t pos = atol (prop->value().c_str());
2438 playhead_cursor->set_position (pos);
2440 playhead_cursor->set_position (0);
2442 /* reset_x_origin() doesn't work right here, since the old
2443 position may be zero already, and it does nothing in such
2448 horizontal_adjustment.set_value (0);
2451 if ((prop = node.property ("mixer-width"))) {
2452 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2455 if ((prop = node.property ("zoom-focus"))) {
2456 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2459 if ((prop = node.property ("zoom"))) {
2460 reset_zoom (PBD::atof (prop->value()));
2463 if ((prop = node.property ("snap-to"))) {
2464 set_snap_to ((SnapType) atoi (prop->value()));
2467 if ((prop = node.property ("snap-mode"))) {
2468 set_snap_mode ((SnapMode) atoi (prop->value()));
2471 if ((prop = node.property ("edit-point"))) {
2472 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2475 if ((prop = node.property ("mouse-mode"))) {
2476 MouseMode m = str2mousemode(prop->value());
2477 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2478 set_mouse_mode (m, true);
2480 mouse_mode = MouseGain; /* lie, to force the mode switch */
2481 set_mouse_mode (MouseObject, true);
2484 if ((prop = node.property ("show-waveforms"))) {
2485 bool yn = (prop->value() == "yes");
2486 _show_waveforms = !yn;
2487 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
2489 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2490 /* do it twice to force the change */
2491 tact->set_active (!yn);
2492 tact->set_active (yn);
2496 if ((prop = node.property ("show-waveforms-recording"))) {
2497 bool yn = (prop->value() == "yes");
2498 _show_waveforms_recording = !yn;
2499 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
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-measures"))) {
2509 bool yn = (prop->value() == "yes");
2510 _show_measures = !yn;
2511 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
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 ("follow-playhead"))) {
2521 bool yn = (prop->value() == "yes");
2522 set_follow_playhead (yn);
2523 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2525 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2526 if (tact->get_active() != yn) {
2527 tact->set_active (yn);
2532 if ((prop = node.property ("region-list-sort-type"))) {
2533 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2534 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2537 if ((prop = node.property ("xfades-visible"))) {
2538 bool yn = (prop->value() == "yes");
2539 _xfade_visibility = !yn;
2540 // set_xfade_visibility (yn);
2543 if ((prop = node.property ("show-editor-mixer"))) {
2545 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2548 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2549 bool yn = (prop->value() == X_("yes"));
2551 /* do it twice to force the change */
2553 tact->set_active (!yn);
2554 tact->set_active (yn);
2558 if ((prop = node.property ("show-editor-list"))) {
2560 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2564 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2565 bool yn = (prop->value() == X_("yes"));
2567 /* do it twice to force the change */
2569 tact->set_active (!yn);
2570 tact->set_active (yn);
2579 Editor::get_state ()
2581 XMLNode* node = new XMLNode ("Editor");
2584 _id.print (buf, sizeof (buf));
2585 node->add_property ("id", buf);
2587 if (is_realized()) {
2588 Glib::RefPtr<Gdk::Window> win = get_window();
2590 int x, y, xoff, yoff, width, height;
2591 win->get_root_origin(x, y);
2592 win->get_position(xoff, yoff);
2593 win->get_size(width, height);
2595 XMLNode* geometry = new XMLNode ("geometry");
2597 snprintf(buf, sizeof(buf), "%d", width);
2598 geometry->add_property("x_size", string(buf));
2599 snprintf(buf, sizeof(buf), "%d", height);
2600 geometry->add_property("y_size", string(buf));
2601 snprintf(buf, sizeof(buf), "%d", x);
2602 geometry->add_property("x_pos", string(buf));
2603 snprintf(buf, sizeof(buf), "%d", y);
2604 geometry->add_property("y_pos", string(buf));
2605 snprintf(buf, sizeof(buf), "%d", xoff);
2606 geometry->add_property("x_off", string(buf));
2607 snprintf(buf, sizeof(buf), "%d", yoff);
2608 geometry->add_property("y_off", string(buf));
2609 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2610 geometry->add_property("edit_pane_pos", string(buf));
2612 node->add_child_nocopy (*geometry);
2615 maybe_add_mixer_strip_width (*node);
2617 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2618 node->add_property ("zoom-focus", buf);
2619 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2620 node->add_property ("zoom", buf);
2621 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2622 node->add_property ("snap-to", buf);
2623 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2624 node->add_property ("snap-mode", buf);
2626 node->add_property ("edit-point", enum_2_string (_edit_point));
2628 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2629 node->add_property ("playhead", buf);
2631 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2632 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2633 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2634 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2635 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2636 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2637 node->add_property ("mouse-mode", enum2str(mouse_mode));
2639 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2641 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2642 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2645 act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
2647 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2648 node->add_property (X_("show-editor-list"), tact->get_active() ? "yes" : "no");
2657 Editor::trackview_by_y_position (double y)
2659 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2663 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2672 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2674 if (!session || snap_mode == SnapOff) {
2678 snap_to_internal (start, direction, for_mark);
2682 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2684 Location* before = 0;
2685 Location* after = 0;
2687 const nframes64_t one_second = session->frame_rate();
2688 const nframes64_t one_minute = session->frame_rate() * 60;
2689 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2690 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2691 nframes64_t presnap = start;
2693 switch (snap_type) {
2695 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2696 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2698 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2702 case SnapToSMPTEFrame:
2703 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2704 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2706 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2710 case SnapToSMPTESeconds:
2711 if (session->smpte_offset_negative())
2713 start += session->smpte_offset ();
2715 start -= session->smpte_offset ();
2717 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2718 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2720 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2723 if (session->smpte_offset_negative())
2725 start -= session->smpte_offset ();
2727 start += session->smpte_offset ();
2731 case SnapToSMPTEMinutes:
2732 if (session->smpte_offset_negative())
2734 start += session->smpte_offset ();
2736 start -= session->smpte_offset ();
2738 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2739 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2741 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2743 if (session->smpte_offset_negative())
2745 start -= session->smpte_offset ();
2747 start += session->smpte_offset ();
2752 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2753 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2755 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2760 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2761 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2763 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2768 start = session->tempo_map().round_to_bar (start, direction);
2772 start = session->tempo_map().round_to_beat (start, direction);
2775 case SnapToAThirtysecondBeat:
2776 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2779 case SnapToASixteenthBeat:
2780 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2783 case SnapToAEighthBeat:
2784 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2787 case SnapToAQuarterBeat:
2788 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2791 case SnapToAThirdBeat:
2792 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2800 before = session->locations()->first_location_before (start);
2801 after = session->locations()->first_location_after (start);
2803 if (direction < 0) {
2805 start = before->start();
2809 } else if (direction > 0) {
2811 start = after->start();
2813 start = session->current_end_frame();
2818 /* find nearest of the two */
2819 if ((start - before->start()) < (after->start() - start)) {
2820 start = before->start();
2822 start = after->start();
2825 start = before->start();
2828 start = after->start();
2835 case SnapToRegionStart:
2836 case SnapToRegionEnd:
2837 case SnapToRegionSync:
2838 case SnapToRegionBoundary:
2839 if (!region_boundary_cache.empty()) {
2840 vector<nframes64_t>::iterator i;
2842 if (direction > 0) {
2843 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2845 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2848 if (i != region_boundary_cache.end()) {
2850 /* lower bound doesn't quite to the right thing for our purposes */
2852 if (direction < 0 && i != region_boundary_cache.begin()) {
2859 start = region_boundary_cache.back();
2865 switch (snap_mode) {
2871 if (presnap > start) {
2872 if (presnap > (start + unit_to_frame(snap_threshold))) {
2876 } else if (presnap < start) {
2877 if (presnap < (start - unit_to_frame(snap_threshold))) {
2883 /* handled at entry */
2890 Editor::snap_length_beats (nframes64_t start)
2896 /* FIXME: This could/should also work with non-tempo based snap settings (ie seconds) */
2898 switch (snap_type) {
2900 return session->tempo_map().meter_at(start).beats_per_bar();
2905 case SnapToAThirtysecondBeat:
2906 return 1.0 / (double)32.0;
2909 case SnapToASixteenthBeat:
2910 return 1.0 / (double)16.0;
2913 case SnapToAEighthBeat:
2914 return 1.0 / (double)8.0;
2917 case SnapToAQuarterBeat:
2918 return 1.0 / (double)4.0;
2921 case SnapToAThirdBeat:
2922 return 1.0 / (double)3.0;
2930 Editor::setup_toolbar ()
2935 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2937 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2940 /* Mode Buttons (tool selection) */
2942 vector<ToggleButton *> mouse_mode_buttons;
2944 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2945 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2946 mouse_mode_buttons.push_back (&mouse_move_button);
2948 if (!Profile->get_sae()) {
2949 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2950 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2951 mouse_mode_buttons.push_back (&mouse_select_button);
2953 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2954 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2955 mouse_mode_buttons.push_back (&mouse_gain_button);
2958 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2959 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2960 mouse_mode_buttons.push_back (&mouse_zoom_button);
2961 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2962 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2963 mouse_mode_buttons.push_back (&mouse_timefx_button);
2964 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2965 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2966 mouse_note_button.add (*(manage (new Image (::get_icon("tool_note")))));
2967 mouse_note_button.set_relief(Gtk::RELIEF_NONE);
2968 mouse_mode_buttons.push_back (&mouse_note_button);
2969 mouse_mode_buttons.push_back (&mouse_audition_button);
2971 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2973 HBox* mode_box = manage(new HBox);
2974 mode_box->set_border_width (2);
2975 mode_box->set_spacing(4);
2976 mouse_mode_button_box.set_spacing(1);
2977 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2978 if (!Profile->get_sae()) {
2979 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2981 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2982 if (!Profile->get_sae()) {
2983 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2985 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2986 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2987 mouse_mode_button_box.pack_start(mouse_note_button, true, true);
2988 mouse_mode_button_box.set_homogeneous(true);
2990 vector<string> edit_mode_strings;
2991 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2992 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2993 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2995 edit_mode_selector.set_name ("EditModeSelector");
2996 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2997 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2998 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
3000 mode_box->pack_start(edit_mode_selector);
3001 mode_box->pack_start(mouse_mode_button_box);
3003 mouse_mode_tearoff = manage (new TearOff (*mode_box));
3004 mouse_mode_tearoff->set_name ("MouseModeBase");
3006 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3007 &mouse_mode_tearoff->tearoff_window()));
3008 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3009 &mouse_mode_tearoff->tearoff_window(), 1));
3010 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3011 &mouse_mode_tearoff->tearoff_window()));
3012 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3013 &mouse_mode_tearoff->tearoff_window(), 1));
3015 mouse_move_button.set_name ("MouseModeButton");
3016 mouse_select_button.set_name ("MouseModeButton");
3017 mouse_gain_button.set_name ("MouseModeButton");
3018 mouse_zoom_button.set_name ("MouseModeButton");
3019 mouse_timefx_button.set_name ("MouseModeButton");
3020 mouse_audition_button.set_name ("MouseModeButton");
3021 mouse_note_button.set_name ("MouseModeButton");
3023 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
3024 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
3025 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
3026 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
3027 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
3028 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
3029 ARDOUR_UI::instance()->tooltips().set_tip (mouse_note_button, _("Edit MIDI Notes"));
3031 mouse_move_button.unset_flags (CAN_FOCUS);
3032 mouse_select_button.unset_flags (CAN_FOCUS);
3033 mouse_gain_button.unset_flags (CAN_FOCUS);
3034 mouse_zoom_button.unset_flags (CAN_FOCUS);
3035 mouse_timefx_button.unset_flags (CAN_FOCUS);
3036 mouse_audition_button.unset_flags (CAN_FOCUS);
3037 mouse_note_button.unset_flags (CAN_FOCUS);
3039 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
3040 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
3042 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
3043 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
3044 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
3045 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
3046 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
3047 mouse_note_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseNote));
3049 // mouse_move_button.set_active (true);
3054 zoom_box.set_spacing (1);
3055 zoom_box.set_border_width (0);
3057 zoom_in_button.set_name ("EditorTimeButton");
3058 zoom_in_button.set_size_request(-1,16);
3059 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
3060 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
3061 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
3063 zoom_out_button.set_name ("EditorTimeButton");
3064 zoom_out_button.set_size_request(-1,16);
3065 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
3066 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
3067 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
3069 zoom_out_full_button.set_name ("EditorTimeButton");
3070 zoom_out_full_button.set_size_request(-1,16);
3071 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
3072 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
3073 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
3075 zoom_focus_selector.set_name ("ZoomFocusSelector");
3076 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
3077 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
3078 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
3079 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
3081 zoom_box.pack_start (zoom_focus_selector, true, true);
3082 zoom_box.pack_start (zoom_out_button, false, false);
3083 zoom_box.pack_start (zoom_in_button, false, false);
3084 zoom_box.pack_start (zoom_out_full_button, false, false);
3086 snap_box.set_spacing (1);
3087 snap_box.set_border_width (2);
3089 snap_type_selector.set_name ("SnapTypeSelector");
3090 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
3091 set_popdown_strings (snap_type_selector, snap_type_strings);
3092 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
3093 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
3095 snap_mode_selector.set_name ("SnapModeSelector");
3096 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
3097 set_popdown_strings (snap_mode_selector, snap_mode_strings);
3098 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
3099 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
3101 edit_point_selector.set_name ("SnapModeSelector");
3102 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
3103 set_popdown_strings (edit_point_selector, edit_point_strings);
3104 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
3105 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
3107 snap_box.pack_start (edit_point_clock, false, false);
3108 snap_box.pack_start (snap_mode_selector, false, false);
3109 snap_box.pack_start (snap_type_selector, false, false);
3110 snap_box.pack_start (edit_point_selector, false, false);
3114 HBox *nudge_box = manage (new HBox);
3115 nudge_box->set_spacing(1);
3116 nudge_box->set_border_width (2);
3118 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
3119 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
3121 nudge_box->pack_start (nudge_backward_button, false, false);
3122 nudge_box->pack_start (nudge_forward_button, false, false);
3123 nudge_box->pack_start (nudge_clock, false, false);
3126 /* Pack everything in... */
3128 HBox* hbox = manage (new HBox);
3129 hbox->set_spacing(10);
3131 tools_tearoff = manage (new TearOff (*hbox));
3132 tools_tearoff->set_name ("MouseModeBase");
3134 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3135 &tools_tearoff->tearoff_window()));
3136 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3137 &tools_tearoff->tearoff_window(), 0));
3138 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
3139 &tools_tearoff->tearoff_window()));
3140 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
3141 &tools_tearoff->tearoff_window(), 0));
3143 toolbar_hbox.set_spacing (10);
3144 toolbar_hbox.set_border_width (1);
3146 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
3147 toolbar_hbox.pack_start (*tools_tearoff, false, false);
3150 hbox->pack_start (snap_box, false, false);
3151 // hbox->pack_start (zoom_box, false, false);
3152 hbox->pack_start (*nudge_box, false, false);
3156 toolbar_base.set_name ("ToolBarBase");
3157 toolbar_base.add (toolbar_hbox);
3159 toolbar_frame.set_shadow_type (SHADOW_OUT);
3160 toolbar_frame.set_name ("BaseFrame");
3161 toolbar_frame.add (toolbar_base);
3166 Editor::setup_midi_toolbar ()
3170 /* Mode Buttons (tool selection) */
3172 vector<ToggleButton *> midi_tool_buttons;
3174 midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
3175 midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
3176 midi_tool_buttons.push_back (&midi_tool_pencil_button);
3177 midi_tool_select_button.add (*(manage (new Image (::get_icon("midi_tool_select")))));
3178 midi_tool_select_button.set_relief(Gtk::RELIEF_NONE);
3179 midi_tool_buttons.push_back (&midi_tool_select_button);
3180 midi_tool_resize_button.add (*(manage (new Image (::get_icon("strip_width")))));
3181 midi_tool_resize_button.set_relief(Gtk::RELIEF_NONE);
3182 midi_tool_buttons.push_back (&midi_tool_resize_button);
3183 midi_tool_erase_button.add (*(manage (new Image (::get_icon("midi_tool_erase")))));
3184 midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
3185 midi_tool_buttons.push_back (&midi_tool_erase_button);
3187 midi_tool_pencil_button.set_active(true);
3189 midi_tool_button_set = new GroupedButtons (midi_tool_buttons);
3191 midi_tool_button_box.set_border_width (2);
3192 midi_tool_button_box.set_spacing(1);
3193 midi_tool_button_box.pack_start(midi_tool_pencil_button, true, true);
3194 midi_tool_button_box.pack_start(midi_tool_select_button, true, true);
3195 midi_tool_button_box.pack_start(midi_tool_resize_button, true, true);
3196 midi_tool_button_box.pack_start(midi_tool_erase_button, true, true);
3197 midi_tool_button_box.set_homogeneous(true);
3199 midi_tool_pencil_button.set_name ("MouseModeButton");
3200 midi_tool_select_button.set_name ("MouseModeButton");
3201 midi_tool_resize_button.set_name ("MouseModeButton");
3202 midi_tool_erase_button.set_name ("MouseModeButton");
3204 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
3205 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
3206 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
3207 ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
3209 midi_tool_pencil_button.unset_flags (CAN_FOCUS);
3210 midi_tool_select_button.unset_flags (CAN_FOCUS);
3211 midi_tool_resize_button.unset_flags (CAN_FOCUS);
3212 midi_tool_erase_button.unset_flags (CAN_FOCUS);
3214 midi_tool_pencil_button.signal_toggled().connect (bind (mem_fun(*this,
3215 &Editor::midi_edit_mode_toggled), Editing::MidiEditPencil));
3216 midi_tool_select_button.signal_toggled().connect (bind (mem_fun(*this,
3217 &Editor::midi_edit_mode_toggled), Editing::MidiEditSelect));
3218 midi_tool_resize_button.signal_toggled().connect (bind (mem_fun(*this,
3219 &Editor::midi_edit_mode_toggled), Editing::MidiEditResize));
3220 midi_tool_erase_button.signal_toggled().connect (bind (mem_fun(*this,
3221 &Editor::midi_edit_mode_toggled), Editing::MidiEditErase));
3223 /* Pack everything in... */
3225 midi_tools_tearoff = manage (new TearOff (midi_tool_button_box));
3226 midi_tools_tearoff->set_name ("MouseModeBase");
3229 midi_tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3230 &midi_tools_tearoff->tearoff_window()));
3231 midi_tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3232 &midi_tools_tearoff->tearoff_window(), 0));
3233 midi_tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox),
3234 &midi_tools_tearoff->tearoff_window()));
3235 midi_tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox),
3236 &midi_tools_tearoff->tearoff_window(), 0));
3239 midi_toolbar_hbox.set_spacing (10);
3240 midi_toolbar_hbox.set_border_width (1);
3242 midi_toolbar_hbox.pack_start (*midi_tools_tearoff, false, true);
3244 midi_tool_button_box.show_all ();
3245 midi_toolbar_hbox.show_all();
3246 midi_tools_tearoff->show_all();
3248 midi_toolbar_base.set_name ("ToolBarBase");
3249 midi_toolbar_base.add (midi_toolbar_hbox);
3251 midi_toolbar_frame.set_shadow_type (SHADOW_OUT);
3252 midi_toolbar_frame.set_name ("BaseFrame");
3253 midi_toolbar_frame.add (midi_toolbar_base);
3257 Editor::convert_drop_to_paths (vector<ustring>& paths,
3258 const RefPtr<Gdk::DragContext>& context,
3261 const SelectionData& data,
3270 vector<ustring> uris = data.get_uris();
3274 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3275 are actually URI lists. So do it by hand.
3278 if (data.get_target() != "text/plain") {
3282 /* Parse the "uri-list" format that Nautilus provides,
3283 where each pathname is delimited by \r\n
3286 const char* p = data.get_text().c_str();
3293 while (g_ascii_isspace (*p))
3297 while (*q && (*q != '\n') && (*q != '\r'))
3303 while (q > p && g_ascii_isspace (*q))
3308 uris.push_back (ustring (p, q - p + 1));
3312 p = strchr (p, '\n');
3322 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3324 if ((*i).substr (0,7) == "file://") {
3327 PBD::url_decode (p);
3329 // scan forward past three slashes
3331 ustring::size_type slashcnt = 0;
3332 ustring::size_type n = 0;
3333 ustring::iterator x = p.begin();
3335 while (slashcnt < 3 && x != p.end()) {
3338 } else if (slashcnt == 3) {
3345 if (slashcnt != 3 || x == p.end()) {
3346 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3350 paths.push_back (p.substr (n - 1));
3358 Editor::new_tempo_section ()
3364 Editor::map_transport_state ()
3366 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3368 if (session->transport_stopped()) {
3369 have_pending_keyboard_selection = false;
3372 update_loop_range_view (true);
3377 Editor::State::State (PublicEditor const * e)
3379 selection = new Selection (e);
3382 Editor::State::~State ()
3388 Editor::get_memento () const
3390 State *state = new State (this);
3392 store_state (*state);
3393 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
3397 Editor::store_state (State& state) const
3399 *state.selection = *selection;
3403 Editor::restore_state (State *state)
3405 if (*selection == *state->selection) {
3409 *selection = *state->selection;
3410 time_selection_changed ();
3411 region_selection_changed ();
3413 /* XXX other selection change handlers? */
3417 Editor::begin_reversible_command (string name)
3420 before = &get_state();
3421 session->begin_reversible_command (name);
3426 Editor::commit_reversible_command ()
3429 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3434 Editor::set_edit_group_solo (Route& route, bool yn)
3436 RouteGroup *edit_group;
3438 if ((edit_group = route.edit_group()) != 0) {
3439 edit_group->apply (&Route::set_solo, yn, this);
3441 route.set_solo (yn, this);
3446 Editor::set_edit_group_mute (Route& route, bool yn)
3448 RouteGroup *edit_group = 0;
3450 if ((edit_group == route.edit_group()) != 0) {
3451 edit_group->apply (&Route::set_mute, yn, this);
3453 route.set_mute (yn, this);
3458 Editor::history_changed ()
3462 if (undo_action && session) {
3463 if (session->undo_depth() == 0) {
3466 label = string_compose(_("Undo (%1)"), session->next_undo());
3468 undo_action->property_label() = label;
3471 if (redo_action && session) {
3472 if (session->redo_depth() == 0) {
3475 label = string_compose(_("Redo (%1)"), session->next_redo());
3477 redo_action->property_label() = label;
3482 Editor::duplicate_dialog (bool with_dialog)
3486 if (mouse_mode == MouseRange) {
3487 if (selection->time.length() == 0) {
3493 get_regions_for_action (rs);
3495 if (mouse_mode != MouseRange) {
3504 ArdourDialog win ("Duplication Dialog");
3505 Label label (_("Number of Duplications:"));
3506 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3507 SpinButton spinner (adjustment, 0.0, 1);
3510 win.get_vbox()->set_spacing (12);
3511 win.get_vbox()->pack_start (hbox);
3512 hbox.set_border_width (6);
3513 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3515 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3516 place, visually. so do this by hand.
3519 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3520 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3521 spinner.grab_focus();
3527 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3528 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3529 win.set_default_response (RESPONSE_ACCEPT);
3531 win.set_position (WIN_POS_MOUSE);
3533 spinner.grab_focus ();
3535 switch (win.run ()) {
3536 case RESPONSE_ACCEPT:
3542 times = adjustment.get_value();
3545 if (mouse_mode == MouseRange) {
3546 duplicate_selection (times);
3548 duplicate_some_regions (rs, times);
3553 Editor::show_verbose_canvas_cursor ()
3555 verbose_canvas_cursor->raise_to_top();
3556 verbose_canvas_cursor->show();
3557 verbose_cursor_visible = true;
3561 Editor::hide_verbose_canvas_cursor ()
3563 verbose_canvas_cursor->hide();
3564 verbose_cursor_visible = false;
3568 Editor::clamp_verbose_cursor_x (double x)
3573 x = min (canvas_width - 200.0, x);
3579 Editor::clamp_verbose_cursor_y (double y)
3581 if (y < canvas_timebars_vsize) {
3582 y = canvas_timebars_vsize;
3584 y = min (canvas_height - 50, y);
3590 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3592 verbose_canvas_cursor->property_text() = txt.c_str();
3593 /* don't get too close to the edge */
3594 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3595 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3599 Editor::set_verbose_canvas_cursor_text (const string & txt)
3601 verbose_canvas_cursor->property_text() = txt.c_str();
3605 Editor::set_edit_mode (EditMode m)
3607 Config->set_edit_mode (m);
3611 Editor::cycle_edit_mode ()
3613 switch (Config->get_edit_mode()) {
3615 Config->set_edit_mode (Splice);
3618 Config->set_edit_mode (Lock);
3621 Config->set_edit_mode (Slide);
3627 Editor::edit_mode_selection_done ()
3633 string choice = edit_mode_selector.get_active_text();
3634 EditMode mode = Slide;
3636 if (choice == _("Splice Edit")) {
3638 } else if (choice == _("Slide Edit")) {
3640 } else if (choice == _("Lock Edit")) {
3644 Config->set_edit_mode (mode);
3648 Editor::snap_type_selection_done ()
3650 string choice = snap_type_selector.get_active_text();
3651 SnapType snaptype = SnapToBeat;
3653 if (choice == _("Beats/3")) {
3654 snaptype = SnapToAThirdBeat;
3655 } else if (choice == _("Beats/4")) {
3656 snaptype = SnapToAQuarterBeat;
3657 } else if (choice == _("Beats/8")) {
3658 snaptype = SnapToAEighthBeat;
3659 } else if (choice == _("Beats/16")) {
3660 snaptype = SnapToASixteenthBeat;
3661 } else if (choice == _("Beats/32")) {
3662 snaptype = SnapToAThirtysecondBeat;
3663 } else if (choice == _("Beats")) {
3664 snaptype = SnapToBeat;
3665 } else if (choice == _("Bars")) {
3666 snaptype = SnapToBar;
3667 } else if (choice == _("Marks")) {
3668 snaptype = SnapToMark;
3669 } else if (choice == _("Region starts")) {
3670 snaptype = SnapToRegionStart;
3671 } else if (choice == _("Region ends")) {
3672 snaptype = SnapToRegionEnd;
3673 } else if (choice == _("Region bounds")) {
3674 snaptype = SnapToRegionBoundary;
3675 } else if (choice == _("Region syncs")) {
3676 snaptype = SnapToRegionSync;
3677 } else if (choice == _("CD Frames")) {
3678 snaptype = SnapToCDFrame;
3679 } else if (choice == _("SMPTE Frames")) {
3680 snaptype = SnapToSMPTEFrame;
3681 } else if (choice == _("SMPTE Seconds")) {
3682 snaptype = SnapToSMPTESeconds;
3683 } else if (choice == _("SMPTE Minutes")) {
3684 snaptype = SnapToSMPTEMinutes;
3685 } else if (choice == _("Seconds")) {
3686 snaptype = SnapToSeconds;
3687 } else if (choice == _("Minutes")) {
3688 snaptype = SnapToMinutes;
3691 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3693 ract->set_active ();
3698 Editor::snap_mode_selection_done ()
3700 string choice = snap_mode_selector.get_active_text();
3701 SnapMode mode = SnapNormal;
3703 if (choice == _("No Grid")) {
3705 } else if (choice == _("Grid")) {
3707 } else if (choice == _("Magnetic")) {
3708 mode = SnapMagnetic;
3711 RefPtr<RadioAction> ract = snap_mode_action (mode);
3714 ract->set_active (true);
3719 Editor::cycle_edit_point (bool with_marker)
3721 switch (_edit_point) {
3723 set_edit_point_preference (EditAtPlayhead);
3725 case EditAtPlayhead:
3727 set_edit_point_preference (EditAtSelectedMarker);
3729 set_edit_point_preference (EditAtMouse);
3732 case EditAtSelectedMarker:
3733 set_edit_point_preference (EditAtMouse);
3739 Editor::edit_point_selection_done ()
3741 string choice = edit_point_selector.get_active_text();
3742 EditPoint ep = EditAtSelectedMarker;
3744 if (choice == _("Marker")) {
3745 set_edit_point_preference (EditAtSelectedMarker);
3746 } else if (choice == _("Playhead")) {
3747 set_edit_point_preference (EditAtPlayhead);
3749 set_edit_point_preference (EditAtMouse);
3752 RefPtr<RadioAction> ract = edit_point_action (ep);
3755 ract->set_active (true);
3760 Editor::zoom_focus_selection_done ()
3762 string choice = zoom_focus_selector.get_active_text();
3763 ZoomFocus focus_type = ZoomFocusLeft;
3765 if (choice == _("Left")) {
3766 focus_type = ZoomFocusLeft;
3767 } else if (choice == _("Right")) {
3768 focus_type = ZoomFocusRight;
3769 } else if (choice == _("Center")) {
3770 focus_type = ZoomFocusCenter;
3771 } else if (choice == _("Play")) {
3772 focus_type = ZoomFocusPlayhead;
3773 } else if (choice == _("Edit")) {
3774 focus_type = ZoomFocusEdit;
3775 } else if (choice == _("Active Mark")) {
3776 focus_type = ZoomFocusEdit;
3777 } else if (choice == _("Active Mark")) {
3778 focus_type = ZoomFocusEdit;
3780 focus_type = ZoomFocusMouse;
3783 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3786 ract->set_active ();
3791 Editor::edit_controls_button_release (GdkEventButton* ev)
3793 if (Keyboard::is_context_menu_event (ev)) {
3794 ARDOUR_UI::instance()->add_route (this);
3800 Editor::mouse_select_button_release (GdkEventButton* ev)
3802 /* this handles just right-clicks */
3804 if (ev->button != 3) {
3811 Editor::TrackViewList *
3812 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3815 TrackViewList::iterator i;
3817 v = new TrackViewList;
3819 if (track == 0 && group == 0) {
3823 for (i = track_views.begin(); i != track_views.end (); ++i) {
3827 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->is_active())) {
3829 /* just the view for this track
3832 v->push_back (track);
3836 /* views for all tracks in the edit group */
3838 for (i = track_views.begin(); i != track_views.end (); ++i) {
3840 if (group == 0 || (*i)->edit_group() == group) {
3850 Editor::set_zoom_focus (ZoomFocus f)
3852 string str = zoom_focus_strings[(int)f];
3854 if (str != zoom_focus_selector.get_active_text()) {
3855 zoom_focus_selector.set_active_text (str);
3858 if (zoom_focus != f) {
3861 ZoomFocusChanged (); /* EMIT_SIGNAL */
3868 Editor::ensure_float (Window& win)
3870 win.set_transient_for (*this);
3874 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3876 /* recover or initialize pane positions. do this here rather than earlier because
3877 we don't want the positions to change the child allocations, which they seem to do.
3883 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3885 static int32_t done;
3888 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3889 width = default_width;
3890 height = default_height;
3892 width = atoi(geometry->property("x_size")->value());
3893 height = atoi(geometry->property("y_size")->value());
3896 if (which == static_cast<Paned*> (&edit_pane)) {
3902 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3903 /* initial allocation is 90% to canvas, 10% to notebook */
3904 pos = (int) floor (alloc.get_width() * 0.90f);
3905 snprintf (buf, sizeof(buf), "%d", pos);
3907 pos = atoi (prop->value());
3910 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3911 edit_pane.set_position (pos);
3912 pre_maximal_pane_position = pos;
3918 Editor::detach_tearoff (Box* b, Window* w)
3920 if (tools_tearoff->torn_off() &&
3921 mouse_mode_tearoff->torn_off()) {
3922 top_hbox.remove (toolbar_frame);
3927 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3929 if (toolbar_frame.get_parent() == 0) {
3930 top_hbox.pack_end (toolbar_frame);
3935 Editor::set_show_measures (bool yn)
3937 if (_show_measures != yn) {
3940 if ((_show_measures = yn) == true) {
3948 Editor::toggle_follow_playhead ()
3950 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3952 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3953 set_follow_playhead (tact->get_active());
3958 Editor::set_follow_playhead (bool yn)
3960 if (_follow_playhead != yn) {
3961 if ((_follow_playhead = yn) == true) {
3963 update_current_screen ();
3970 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3972 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3974 xfade->set_active (!xfade->active());
3979 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3981 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3983 xfade->set_follow_overlap (!xfade->following_overlap());
3988 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3990 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3996 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
4000 switch (cew.run ()) {
4001 case RESPONSE_ACCEPT:
4008 xfade->StateChanged (Change (~0));
4012 Editor::playlist_selector () const
4014 return *_playlist_selector;
4018 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
4022 ret = nudge_clock.current_duration (pos);
4023 next = ret + 1; /* XXXX fix me */
4029 Editor::end_location_changed (Location* location)
4031 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
4032 //reset_scrolling_region ();
4033 horizontal_adjustment.set_upper ( location->start());
4037 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
4039 ArdourDialog dialog ("playlist deletion dialog");
4040 Label label (string_compose (_("Playlist %1 is currently unused.\n"
4041 "If left alone, no audio files used by it will be cleaned.\n"
4042 "If deleted, audio files used by it alone by will cleaned."),
4045 dialog.set_position (WIN_POS_CENTER);
4046 dialog.get_vbox()->pack_start (label);
4050 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
4051 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
4052 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
4054 switch (dialog.run ()) {
4055 case RESPONSE_ACCEPT:
4056 /* delete the playlist */
4060 case RESPONSE_REJECT:
4061 /* keep the playlist */
4073 Editor::audio_region_selection_covers (nframes64_t where)
4075 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
4076 if ((*a)->region()->covers (where)) {
4085 Editor::prepare_for_cleanup ()
4087 cut_buffer->clear_regions ();
4088 cut_buffer->clear_playlists ();
4090 selection->clear_regions ();
4091 selection->clear_playlists ();
4093 no_region_list_redisplay = true;
4097 Editor::finish_cleanup ()
4099 no_region_list_redisplay = false;
4100 redisplay_regions ();
4104 Editor::transport_loop_location()
4107 return session->locations()->auto_loop_location();
4114 Editor::transport_punch_location()
4117 return session->locations()->auto_punch_location();
4124 Editor::control_layout_scroll (GdkEventScroll* ev)
4126 switch (ev->direction) {
4128 scroll_tracks_up_line ();
4132 case GDK_SCROLL_DOWN:
4133 scroll_tracks_down_line ();
4137 /* no left/right handling yet */
4145 /** A new snapshot has been selected.
4148 Editor::snapshot_display_selection_changed ()
4150 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
4152 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
4154 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
4156 if (snap_name.length() == 0) {
4160 if (session->snap_name() == snap_name) {
4164 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
4169 Editor::snapshot_display_button_press (GdkEventButton* ev)
4171 if (ev->button == 3) {
4172 /* Right-click on the snapshot list. Work out which snapshot it
4174 Gtk::TreeModel::Path path;
4175 Gtk::TreeViewColumn* col;
4178 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
4179 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
4181 Gtk::TreeModel::Row row = *iter;
4182 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
4191 /** Pop up the snapshot display context menu.
4192 * @param button Button used to open the menu.
4193 * @param time Menu open time.
4194 * @snapshot_name Name of the snapshot that the menu click was over.
4198 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
4200 using namespace Menu_Helpers;
4202 MenuList& items (snapshot_context_menu.items());
4205 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
4207 add_item_with_sensitivity (items, MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)), modification_allowed);
4209 add_item_with_sensitivity (items, MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)), modification_allowed);
4211 snapshot_context_menu.popup (button, time);
4215 Editor::rename_snapshot (Glib::ustring old_name)
4217 ArdourPrompter prompter(true);
4221 prompter.set_name ("Prompter");
4222 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
4223 prompter.set_prompt (_("New name of snapshot"));
4224 prompter.set_initial_text (old_name);
4226 if (prompter.run() == RESPONSE_ACCEPT) {
4227 prompter.get_result (new_name);
4228 if (new_name.length()) {
4229 session->rename_state (old_name, new_name);
4230 redisplay_snapshots ();
4237 Editor::remove_snapshot (Glib::ustring name)
4239 vector<string> choices;
4241 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
4243 choices.push_back (_("No, do nothing."));
4244 choices.push_back (_("Yes, remove it."));
4246 Gtkmm2ext::Choice prompter (prompt, choices);
4248 if (prompter.run () == 1) {
4249 session->remove_state (name);
4250 redisplay_snapshots ();
4255 Editor::redisplay_snapshots ()
4261 vector<sys::path> state_file_paths;
4263 get_state_files_in_directory (session->session_directory().root_path(),
4266 if (state_file_paths.empty()) return;
4268 vector<string> state_file_names(get_file_names_no_extension(state_file_paths));
4270 snapshot_display_model->clear ();
4272 for (vector<string>::iterator i = state_file_names.begin();
4273 i != state_file_names.end(); ++i)
4275 string statename = (*i);
4276 TreeModel::Row row = *(snapshot_display_model->append());
4278 /* this lingers on in case we ever want to change the visible
4279 name of the snapshot.
4282 string display_name;
4283 display_name = statename;
4285 if (statename == session->snap_name()) {
4286 snapshot_display.get_selection()->select(row);
4289 row[snapshot_display_columns.visible_name] = display_name;
4290 row[snapshot_display_columns.real_name] = statename;
4295 Editor::session_state_saved (string snap_name)
4297 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4298 redisplay_snapshots ();
4302 Editor::maximise_editing_space ()
4304 mouse_mode_tearoff->set_visible (false);
4305 tools_tearoff->set_visible (false);
4307 pre_maximal_pane_position = edit_pane.get_position();
4308 pre_maximal_editor_width = this->get_width();
4310 if(post_maximal_pane_position == 0) {
4311 post_maximal_pane_position = edit_pane.get_width();
4316 if(post_maximal_editor_width) {
4317 edit_pane.set_position (post_maximal_pane_position -
4318 abs(post_maximal_editor_width - pre_maximal_editor_width));
4320 edit_pane.set_position (post_maximal_pane_position);
4325 Editor::restore_editing_space ()
4327 // user changed width of pane during fullscreen
4329 if(post_maximal_pane_position != edit_pane.get_position()) {
4330 post_maximal_pane_position = edit_pane.get_position();
4335 mouse_mode_tearoff->set_visible (true);
4336 tools_tearoff->set_visible (true);
4337 post_maximal_editor_width = this->get_width();
4339 edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
4343 * Make new playlists for a given track and also any others that belong
4344 * to the same active edit group.
4349 Editor::new_playlists (TimeAxisView* v)
4351 begin_reversible_command (_("new playlists"));
4352 mapover_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
4353 commit_reversible_command ();
4357 * Use a copy of the current playlist for a given track and also any others that belong
4358 * to the same active edit group.
4363 Editor::copy_playlists (TimeAxisView* v)
4365 begin_reversible_command (_("copy playlists"));
4366 mapover_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
4367 commit_reversible_command ();
4371 * Clear the current playlist for a given track and also any others that belong
4372 * to the same active edit group.
4377 Editor::clear_playlists (TimeAxisView* v)
4379 begin_reversible_command (_("clear playlists"));
4380 mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
4381 commit_reversible_command ();
4385 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz)
4387 atv.use_new_playlist (sz > 1 ? false : true);
4391 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz)
4393 atv.use_copy_playlist (sz > 1 ? false : true);
4397 Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t sz)
4399 atv.clear_playlist ();
4403 Editor::on_key_press_event (GdkEventKey* ev)
4405 return key_press_focus_accelerator_handler (*this, ev);
4409 Editor::on_key_release_event (GdkEventKey* ev)
4411 return Gtk::Window::on_key_release_event (ev);
4412 // return key_press_focus_accelerator_handler (*this, ev);
4416 Editor::reset_x_origin (nframes64_t frame)
4418 //cerr << "resetting x origin" << endl;
4419 queue_visual_change (frame);
4423 Editor::reset_zoom (double fpu)
4425 queue_visual_change (fpu);
4429 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4431 //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
4432 reset_x_origin (frame);
4435 if (!no_save_visual) {
4436 undo_visual_stack.push_back (current_visual_state(false));
4440 Editor::VisualState*
4441 Editor::current_visual_state (bool with_tracks)
4443 VisualState* vs = new VisualState;
4444 vs->y_position = vertical_adjustment.get_value();
4445 vs->frames_per_unit = frames_per_unit;
4446 vs->leftmost_frame = leftmost_frame;
4447 vs->zoom_focus = zoom_focus;
4448 vs->zoomed_to_region = zoomed_to_region;
4451 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4452 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4460 Editor::undo_visual_state ()
4462 if (undo_visual_stack.empty()) {
4466 VisualState* vs = undo_visual_stack.back();
4467 undo_visual_stack.pop_back();
4468 use_visual_state (*vs);
4469 redo_visual_stack.push_back (vs);
4473 Editor::redo_visual_state ()
4475 if (redo_visual_stack.empty()) {
4479 VisualState* vs = redo_visual_stack.back();
4480 redo_visual_stack.pop_back();
4481 use_visual_state (*vs);
4482 undo_visual_stack.push_back (vs);
4486 Editor::swap_visual_state ()
4488 if (undo_visual_stack.empty()) {
4489 redo_visual_state ();
4491 undo_visual_state ();
4496 Editor::use_visual_state (VisualState& vs)
4498 no_save_visual = true;
4500 vertical_adjustment.set_value (vs.y_position);
4502 set_zoom_focus (vs.zoom_focus);
4503 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4505 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4506 TrackViewList::iterator t;
4508 /* check if the track still exists - it could have been deleted */
4510 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4511 (*t)->set_state (*(i->second));
4515 if (!vs.track_states.empty()) {
4516 update_route_visibility ();
4519 no_save_visual = false;
4523 Editor::set_frames_per_unit (double fpu)
4525 /* this is the core function that controls the zoom level of the canvas. it is called
4526 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4529 if (fpu == frames_per_unit) {
4538 /* don't allow zooms that fit more than the maximum number
4539 of frames into an 800 pixel wide space.
4542 if (max_frames / fpu < 800.0) {
4546 frames_per_unit = fpu;
4551 Editor::post_zoom ()
4553 // convert fpu to frame count
4555 nframes64_t frames = (nframes64_t) floor (frames_per_unit * canvas_width);
4557 if (frames_per_unit != zoom_range_clock.current_duration()) {
4558 zoom_range_clock.set (frames);
4561 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4562 if (!selection->tracks.empty()) {
4563 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4564 (*i)->reshow_selection (selection->time);
4567 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4568 (*i)->reshow_selection (selection->time);
4573 ZoomChanged (); /* EMIT_SIGNAL */
4575 reset_hscrollbar_stepping ();
4576 //reset_scrolling_region ();
4578 if (playhead_cursor) {
4579 playhead_cursor->set_position (playhead_cursor->current_frame);
4586 Editor::queue_visual_change (nframes64_t where)
4588 // pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4589 // pending_visual_change.time_origin = where;
4591 if (pending_visual_change.idle_handler_id < 0) {
4592 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4593 pending_visual_change.time_origin = where;
4594 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4599 Editor::queue_visual_change (double fpu)
4601 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4602 pending_visual_change.frames_per_unit = fpu;
4604 if (pending_visual_change.idle_handler_id < 0) {
4605 pending_visual_change.idle_handler_id = g_idle_add ( _idle_visual_changer, this);
4611 Editor::_idle_visual_changer (void* arg)
4613 return static_cast<Editor*>(arg)->idle_visual_changer ();
4617 Editor::idle_visual_changer ()
4619 VisualChange::Type p = pending_visual_change.pending;
4620 pending_visual_change.pending = (VisualChange::Type) 0;
4622 if (p & VisualChange::ZoomLevel) {
4623 set_frames_per_unit (pending_visual_change.frames_per_unit);
4625 compute_fixed_ruler_scale ();
4626 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));
4627 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));
4628 update_tempo_based_rulers ();
4630 if (p & VisualChange::TimeOrigin) {
4632 nframes64_t csf, cef;
4633 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4636 csf = session->current_start_frame();
4637 cef = session->current_end_frame() + (current_page_frames() / 24);// Add a little extra so we can see the end marker
4640 /* if we seek beyond the current end of the canvas, move the end */
4642 if (current_time_origin != pending_visual_change.time_origin) {
4643 //if (horizontal_adjustment.get_upper() < pending_visual_change.time_origin) {
4644 last_canvas_frame = (cef > (pending_visual_change.time_origin + current_page_frames())) ? cef : pending_visual_change.time_origin + current_page_frames();
4645 horizontal_adjustment.set_upper ((cef - csf) / frames_per_unit);
4647 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4649 update_fixed_rulers();
4650 redisplay_tempo (true);
4653 //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
4654 pending_visual_change.idle_handler_id = -1;
4655 return 0; /* this is always a one-shot call */
4658 struct EditorOrderTimeAxisSorter {
4659 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4660 return a->order < b->order;
4665 Editor::sort_track_selection (TrackSelection* sel)
4667 EditorOrderTimeAxisSorter cmp;
4672 selection->tracks.sort (cmp);
4677 Editor::get_preferred_edit_position (bool ignore_playhead)
4680 nframes64_t where = 0;
4681 EditPoint ep = _edit_point;
4683 if (entered_marker) {
4684 return entered_marker->position();
4687 if (ignore_playhead && ep == EditAtPlayhead) {
4688 ep = EditAtSelectedMarker;
4692 case EditAtPlayhead:
4693 where = session->audible_frame();
4696 case EditAtSelectedMarker:
4697 if (!selection->markers.empty()) {
4699 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4702 where = loc->start();
4713 if (!mouse_frame (where, ignored)) {
4714 /* XXX not right but what can we do ? */
4725 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4727 if (!session) return;
4729 begin_reversible_command (cmd);
4733 if ((tll = transport_loop_location()) == 0) {
4734 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4735 XMLNode &before = session->locations()->get_state();
4736 session->locations()->add (loc, true);
4737 session->set_auto_loop_location (loc);
4738 XMLNode &after = session->locations()->get_state();
4739 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4741 XMLNode &before = tll->get_state();
4742 tll->set_hidden (false, this);
4743 tll->set (start, end);
4744 XMLNode &after = tll->get_state();
4745 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4748 commit_reversible_command ();
4752 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4754 if (!session) return;
4756 begin_reversible_command (cmd);
4760 if ((tpl = transport_punch_location()) == 0) {
4761 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4762 XMLNode &before = session->locations()->get_state();
4763 session->locations()->add (loc, true);
4764 session->set_auto_loop_location (loc);
4765 XMLNode &after = session->locations()->get_state();
4766 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4769 XMLNode &before = tpl->get_state();
4770 tpl->set_hidden (false, this);
4771 tpl->set (start, end);
4772 XMLNode &after = tpl->get_state();
4773 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4776 commit_reversible_command ();
4780 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4782 const TrackSelection* tracks;
4785 tracks = &track_views;
4790 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4792 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4795 boost::shared_ptr<Diskstream> ds;
4796 boost::shared_ptr<Playlist> pl;
4798 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4800 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)where * ds->speed()));
4802 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4804 RegionView* rv = atv->audio_view()->find_view (*i);
4818 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4820 const TrackSelection* tracks;
4823 tracks = &track_views;
4828 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4830 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4833 boost::shared_ptr<Diskstream> ds;
4834 boost::shared_ptr<Playlist> pl;
4836 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4838 Playlist::RegionList* regions = pl->regions_touched ((nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4840 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4842 RegionView* rv = atv->audio_view()->find_view (*i);
4856 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4858 if (selection->regions.empty()) {
4860 if (selection->tracks.empty()) {
4862 /* no regions or tracks selected
4865 if (entered_regionview && mouse_mode == Editing::MouseObject) {
4867 /* entered regionview is valid and we're in object mode -
4868 just use entered regionview
4871 rs.add (entered_regionview);
4878 /* no regions selected, so get all regions at the edit point across
4879 all selected tracks.
4882 nframes64_t where = get_preferred_edit_position();
4883 get_regions_at (rs, where, selection->tracks);
4885 /* if the entered regionview wasn't selected and neither was its track
4889 if (entered_regionview != 0 &&
4890 !selection->selected (entered_regionview) &&
4891 !selection->selected (&entered_regionview->get_time_axis_view())) {
4892 rs.add (entered_regionview);
4898 /* just use the selected regions */
4900 rs = selection->regions;
4902 /* if the entered regionview wasn't selected and we allow this sort of thing,
4906 if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
4907 rs.add (entered_regionview);
4914 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4917 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4919 RouteTimeAxisView* tatv;
4921 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4923 boost::shared_ptr<Playlist> pl;
4924 vector<boost::shared_ptr<Region> > results;
4926 boost::shared_ptr<Diskstream> ds;
4928 if ((ds = tatv->get_diskstream()) == 0) {
4933 if ((pl = (ds->playlist())) != 0) {
4934 pl->get_region_list_equivalent_regions (region, results);
4937 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4938 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4939 regions.push_back (marv);
4948 Editor::show_rhythm_ferret ()
4950 if (rhythm_ferret == 0) {
4951 rhythm_ferret = new RhythmFerret(*this);
4954 rhythm_ferret->set_session (session);
4955 rhythm_ferret->show ();
4956 rhythm_ferret->present ();
4960 Editor::first_idle ()
4962 MessageDialog* dialog = 0;
4964 if (track_views.size() > 1) {
4965 dialog = new MessageDialog (*this,
4966 _("Please wait while Ardour loads visual data"),
4971 ARDOUR_UI::instance()->flush_pending ();
4974 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4986 Editor::start_resize_line_ops ()
4989 old_resize_line_y = -1;
4991 need_resize_line = true;
4996 Editor::end_resize_line_ops ()
4999 need_resize_line = false;
5001 if (old_resize_line_y >= 0) {
5002 Gdk::Rectangle r (0, old_resize_line_y, (int) canvas_width, 3);
5003 Glib::RefPtr<Gdk::Window> win = get_window();
5004 cerr << "Final invalidation at " << old_resize_line_y << endl;
5005 win->invalidate_rect (r, false);
5011 Editor::queue_draw_resize_line (int at)
5014 Glib::RefPtr<Gdk::Window> win = get_window();
5018 if (win && canvas_width) {
5020 int controls_width = controls_layout.get_width();
5023 controls_layout.get_window()->get_origin (xroot, discard);
5025 if (old_resize_line_y >= 0) {
5027 /* redraw where it used to be */
5030 Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) canvas_width, 3);
5031 win->invalidate_rect (r, true);
5032 cerr << "invalidate " << xroot << "," << old_resize_line_y - 1 << ' '
5033 << controls_width + canvas_width << " x 3\n";
5036 /* draw where it is */
5038 Gdk::Rectangle r (0, at - 1, controls_width + (int) canvas_width, 3);
5039 win->invalidate_rect (r, true);
5045 Editor::on_expose_event (GdkEventExpose* ev)
5047 /* cerr << "+++ editor expose "
5048 << ev->area.x << ',' << ev->area.y
5050 << ev->area.width << " x " << ev->area.height
5051 << " need reize ? " << need_resize_line
5054 bool ret = Window::on_expose_event (ev);
5057 if (need_resize_line) {
5059 int xroot, yroot, discard;
5062 /* Our root coordinates for drawing the line will be the left edge
5063 of the track controls, and the upper left edge of our own window.
5066 get_window()->get_origin (discard, yroot);
5067 controls_layout.get_window()->get_origin (xroot, discard);
5068 controls_width = controls_layout.get_width();
5071 GdkRectangle intersection;
5074 lr.y = resize_line_y;
5075 lr.width = controls_width + (int) canvas_width;
5078 if (gdk_rectangle_intersect (&lr, &ev->area, &intersection)) {
5080 Glib::RefPtr<Gtk::Style> style (get_style());
5081 Glib::RefPtr<Gdk::GC> black_gc (style->get_black_gc ());
5082 Glib::RefPtr<Gdk::GC> gc = wrap (black_gc->gobj_copy(), false);
5084 /* draw on root window */
5086 GdkWindow* win = gdk_get_default_root_window();
5088 gc->set_subwindow (Gdk::INCLUDE_INFERIORS);
5089 gc->set_line_attributes (3, Gdk::LINE_SOLID,
5093 gdk_draw_line (win, gc->gobj(),
5096 (int) canvas_width + controls_width,
5099 cerr << "drew line @ " << xroot << ", " << yroot + resize_line_y
5100 << " to " << xroot + (int) canvas_width + controls_width
5101 << ", " << yroot + resize_line_y
5104 old_resize_line_y = resize_line_y;
5105 cerr << "NEXT EXPOSE SHOULD BE AT " << old_resize_line_y << endl;
5107 cerr << "no intersect with "
5108 << lr.x << ',' << lr.y
5110 << lr.width << " x " << lr.height
5115 //cerr << "--- editor expose\n";
5122 _idle_resizer (gpointer arg)
5124 return ((Editor*)arg)->idle_resize ();
5128 Editor::add_to_idle_resize (TimeAxisView* view, uint32_t h)
5130 if (resize_idle_id < 0) {
5131 resize_idle_id = g_idle_add (_idle_resizer, this);
5134 resize_idle_target = h;
5136 pending_resizes.push_back (view);
5138 if (selection->selected (view) && !selection->tracks.empty()) {
5139 pending_resizes.insert (pending_resizes.end(), selection->tracks.begin(), selection->tracks.end());
5144 Editor::idle_resize ()
5146 for (vector<TimeAxisView*>::iterator i = pending_resizes.begin(); i != pending_resizes.end(); ++i) {
5147 (*i)->idle_resize (resize_idle_target);
5149 pending_resizes.clear();
5150 resize_idle_id = -1;