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.
27 #include <boost/none.hpp>
29 #include <sigc++/bind.h>
31 #include <pbd/convert.h>
32 #include <pbd/error.h>
33 #include <pbd/enumwriter.h>
34 #include <pbd/memento_command.h>
36 #include <glibmm/miscutils.h>
37 #include <gtkmm/image.h>
38 #include <gdkmm/color.h>
39 #include <gdkmm/bitmap.h>
41 #include <gtkmm2ext/grouped_buttons.h>
42 #include <gtkmm2ext/gtk_ui.h>
43 #include <gtkmm2ext/tearoff.h>
44 #include <gtkmm2ext/utils.h>
45 #include <gtkmm2ext/window_title.h>
46 #include <gtkmm2ext/choice.h>
48 #include <ardour/audio_track.h>
49 #include <ardour/audio_diskstream.h>
50 #include <ardour/plugin_manager.h>
51 #include <ardour/location.h>
52 #include <ardour/audioplaylist.h>
53 #include <ardour/audioregion.h>
54 #include <ardour/region.h>
55 #include <ardour/session_route.h>
56 #include <ardour/tempo.h>
57 #include <ardour/utils.h>
58 #include <ardour/profile.h>
60 #include <control_protocol/control_protocol.h>
62 #include "ardour_ui.h"
66 #include "playlist_selector.h"
67 #include "audio_region_view.h"
68 #include "rgb_macros.h"
69 #include "selection.h"
70 #include "audio_streamview.h"
71 #include "time_axis_view.h"
72 #include "audio_time_axis.h"
74 #include "crossfade_view.h"
76 #include "public_editor.h"
77 #include "crossfade_edit.h"
78 #include "canvas_impl.h"
80 #include "gui_thread.h"
82 #include "rhythm_ferret.h"
86 #include "analysis_window.h"
92 #include "imageframe_socket_handler.h"
93 /* </CMT Additions> */
97 using namespace ARDOUR;
100 using namespace Glib;
101 using namespace Gtkmm2ext;
102 using namespace Editing;
106 const double Editor::timebar_height = 15.0;
108 #include "editor_xpms"
110 static const gchar *_snap_type_strings[] = {
132 static const gchar *_snap_mode_strings[] = {
139 static const gchar *_edit_point_strings[] = {
146 static const gchar *_zoom_focus_strings[] = {
156 #ifdef USE_RUBBERBAND
157 static const gchar *_rb_opt_strings[] = {
160 N_("Balanced multitimbral mixture"),
161 N_("Unpitched percussion with stable notes"),
162 N_("Crisp monophonic instrumental"),
163 N_("Unpitched solo percussion"),
168 /* Soundfile drag-n-drop */
170 Gdk::Cursor* Editor::cross_hair_cursor = 0;
171 Gdk::Cursor* Editor::selector_cursor = 0;
172 Gdk::Cursor* Editor::trimmer_cursor = 0;
173 Gdk::Cursor* Editor::grabber_cursor = 0;
174 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
175 Gdk::Cursor* Editor::zoom_cursor = 0;
176 Gdk::Cursor* Editor::time_fx_cursor = 0;
177 Gdk::Cursor* Editor::fader_cursor = 0;
178 Gdk::Cursor* Editor::speaker_cursor = 0;
179 Gdk::Cursor* Editor::wait_cursor = 0;
180 Gdk::Cursor* Editor::timebar_cursor = 0;
181 Gdk::Cursor* Editor::transparent_cursor = 0;
184 show_me_the_size (Requisition* r, const char* what)
186 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
191 /* time display buttons */
192 minsec_label (_("Mins:Secs")),
193 bbt_label (_("Bars:Beats")),
194 smpte_label (_("Timecode")),
195 frame_label (_("Samples")),
196 tempo_label (_("Tempo")),
197 meter_label (_("Meter")),
198 mark_label (_("Location Markers")),
199 range_mark_label (_("Range Markers")),
200 transport_mark_label (_("Loop/Punch Ranges")),
201 cd_mark_label (_("CD Markers")),
202 edit_packer (3, 4, true),
204 /* the values here don't matter: layout widgets
205 reset them as needed.
208 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
209 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
211 /* tool bar related */
213 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
214 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
216 toolbar_selection_clock_table (2,3),
218 automation_mode_button (_("mode")),
219 global_automation_button (_("automation")),
221 /* <CMT Additions> */
222 image_socket_listener(0),
223 /* </CMT Additions> */
227 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
228 meters_running(false)
233 /* we are a singleton */
235 PublicEditor::_instance = this;
240 selection = new Selection;
241 cut_buffer = new Selection;
243 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
244 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
245 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
246 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
247 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
249 clicked_regionview = 0;
250 clicked_trackview = 0;
251 clicked_audio_trackview = 0;
252 clicked_crossfadeview = 0;
253 clicked_control_point = 0;
254 last_update_frame = 0;
256 drag_info.copied_location = 0;
257 current_mixer_strip = 0;
258 current_bbt_points = 0;
260 snap_type_strings = I18N (_snap_type_strings);
261 snap_mode_strings = I18N (_snap_mode_strings);
262 zoom_focus_strings = I18N (_zoom_focus_strings);
263 edit_point_strings = I18N (_edit_point_strings);
264 #ifdef USE_RUBBERBAND
265 rb_opt_strings = I18N (_rb_opt_strings);
268 snap_threshold = 5.0;
269 bbt_beat_subdivision = 4;
272 last_autoscroll_x = 0;
273 last_autoscroll_y = 0;
274 autoscroll_active = false;
275 autoscroll_timeout_tag = -1;
276 interthread_progress_window = 0;
283 current_interthread_info = 0;
284 _show_measures = true;
285 _show_waveforms = true;
286 _show_waveforms_recording = true;
287 first_action_message = 0;
289 export_range_markers_dialog = 0;
290 show_gain_after_trim = false;
291 ignore_route_list_reorder = false;
292 no_route_list_redisplay = false;
293 verbose_cursor_on = true;
294 route_removal = false;
295 show_automatic_regions_in_region_list = true;
296 last_item_entered = 0;
297 last_item_entered_n = 0;
299 region_list_sort_type = (Editing::RegionListSortType) 0;
300 have_pending_keyboard_selection = false;
301 _follow_playhead = true;
302 _xfade_visibility = true;
303 editor_ruler_menu = 0;
304 no_ruler_shown_update = false;
305 edit_group_list_menu = 0;
307 region_list_menu = 0;
309 start_end_marker_menu = 0;
310 range_marker_menu = 0;
311 marker_menu_item = 0;
313 transport_marker_menu = 0;
314 new_transport_marker_menu = 0;
315 editor_mixer_strip_width = Wide;
316 show_editor_mixer_when_tracks_arrive = false;
317 region_edit_menu_split_item = 0;
319 region_edit_menu_split_multichannel_item = 0;
321 ignore_mouse_mode_toggle = false;
322 current_stepping_trackview = 0;
324 entered_regionview = 0;
326 clear_entered_track = false;
327 _new_regionviews_show_envelope = false;
329 in_edit_group_row_change = false;
330 last_canvas_frame = 0;
332 button_release_can_deselect = true;
333 canvas_idle_queued = false;
334 _dragging_playhead = false;
335 _dragging_edit_point = false;
336 _dragging_hscrollbar = false;
337 select_new_marker = false;
338 zoomed_to_region = false;
340 allow_vertical_scroll = false;
341 no_save_visual = false;
342 need_resize_line = false;
344 old_resize_line_y = -1;
345 no_region_list_redisplay = false;
349 scrubbing_direction = 0;
352 ignore_route_order_sync = false;
354 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
355 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
356 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
357 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
358 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
360 range_marker_drag_rect = 0;
361 marker_drag_line = 0;
363 set_mouse_mode (MouseObject, true);
365 frames_per_unit = 2048; /* too early to use reset_zoom () */
366 reset_hscrollbar_stepping ();
368 zoom_focus = ZoomFocusLeft;
369 set_zoom_focus (ZoomFocusLeft);
370 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
372 initialize_rulers ();
373 initialize_canvas ();
375 edit_controls_vbox.set_spacing (0);
376 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
377 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
378 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
380 controls_layout.add (edit_controls_vbox);
381 controls_layout.set_name ("EditControlsBase");
382 controls_layout.add_events (Gdk::SCROLL_MASK);
383 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
385 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
386 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
387 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
389 edit_vscrollbar.set_adjustment (vertical_adjustment);
390 edit_hscrollbar.set_adjustment (horizontal_adjustment);
392 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
393 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
394 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
396 edit_hscrollbar.set_name ("EditorHScrollbar");
401 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
403 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
404 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
405 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
406 time_canvas_vbox.pack_start (*frames_ruler, false, false);
407 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
408 //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
409 time_canvas_vbox.set_size_request (-1, -1);
410 bbt_label.set_name ("EditorTimeButton");
411 bbt_label.set_size_request (-1, (int)timebar_height);
412 bbt_label.set_alignment (1.0, 0.5);
413 bbt_label.set_padding (5,0);
414 minsec_label.set_name ("EditorTimeButton");
415 minsec_label.set_size_request (-1, (int)timebar_height);
416 minsec_label.set_alignment (1.0, 0.5);
417 minsec_label.set_padding (5,0);
418 smpte_label.set_name ("EditorTimeButton");
419 smpte_label.set_size_request (-1, (int)timebar_height);
420 smpte_label.set_alignment (1.0, 0.5);
421 smpte_label.set_padding (5,0);
422 frame_label.set_name ("EditorTimeButton");
423 frame_label.set_size_request (-1, (int)timebar_height);
424 frame_label.set_alignment (1.0, 0.5);
425 frame_label.set_padding (5,0);
427 tempo_label.set_name ("EditorTimeButton");
428 tempo_label.set_size_request (-1, (int)timebar_height);
429 tempo_label.set_alignment (1.0, 0.5);
430 tempo_label.set_padding (5,0);
431 meter_label.set_name ("EditorTimeButton");
432 meter_label.set_size_request (-1, (int)timebar_height);
433 meter_label.set_alignment (1.0, 0.5);
434 meter_label.set_padding (5,0);
435 mark_label.set_name ("EditorTimeButton");
436 mark_label.set_size_request (-1, (int)timebar_height);
437 mark_label.set_alignment (1.0, 0.5);
438 mark_label.set_padding (5,0);
439 cd_mark_label.set_name ("EditorTimeButton");
440 cd_mark_label.set_size_request (-1, (int)timebar_height);
441 cd_mark_label.set_alignment (1.0, 0.5);
442 cd_mark_label.set_padding (5,0);
443 range_mark_label.set_name ("EditorTimeButton");
444 range_mark_label.set_size_request (-1, (int)timebar_height);
445 range_mark_label.set_alignment (1.0, 0.5);
446 range_mark_label.set_padding (5,0);
447 transport_mark_label.set_name ("EditorTimeButton");
448 transport_mark_label.set_size_request (-1, (int)timebar_height);
449 transport_mark_label.set_alignment (1.0, 0.5);
450 transport_mark_label.set_padding (5,0);
452 ruler_label_vbox.pack_start (minsec_label, false, false);
453 ruler_label_vbox.pack_start (smpte_label, false, false);
454 ruler_label_vbox.pack_start (frame_label, false, false);
455 ruler_label_vbox.pack_start (bbt_label, false, false);
457 ruler_label_event_box.add (ruler_label_vbox);
458 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
459 ruler_label_event_box.set_name ("TimebarLabelBase");
460 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
461 ruler_label_frame.add(ruler_label_event_box);
462 ruler_label_frame.property_shadow_type() = Gtk::SHADOW_OUT;
464 time_button_vbox.pack_start (meter_label, false, false);
465 time_button_vbox.pack_start (tempo_label, false, false);
466 time_button_vbox.pack_start (mark_label, false, false);
468 time_button_event_box.add (time_button_vbox);
470 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
471 time_button_event_box.set_name ("TimebarLabelBase");
472 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
474 time_button_frame.add(time_button_event_box);
475 time_button_frame.property_shadow_type() = Gtk::SHADOW_OUT;
477 /* these enable us to have a dedicated window (for cursor setting, etc.)
478 for the canvas areas.
481 track_canvas_event_box.add (*track_canvas);
483 time_canvas_event_box.add (time_canvas_vbox);
484 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
486 edit_packer.set_col_spacings (0);
487 edit_packer.set_row_spacings (0);
488 edit_packer.set_homogeneous (false);
489 edit_packer.set_border_width (0);
490 edit_packer.set_name ("EditorWindow");
492 edit_packer.attach (edit_vscrollbar, 0, 1, 0, 4, FILL, FILL|EXPAND, 0, 0);
494 edit_packer.attach (ruler_label_frame, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
495 edit_packer.attach (time_button_frame, 1, 2, 1, 2, FILL, FILL, 0, 0);
496 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
498 edit_packer.attach (controls_layout, 1, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
499 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
501 edit_packer.attach (zoom_box, 1, 2, 3, 4, FILL, FILL, 0, 0);
502 edit_packer.attach (edit_hscrollbar, 2, 3, 3, 4, FILL|EXPAND, FILL, 0, 0);
504 bottom_hbox.set_border_width (2);
505 bottom_hbox.set_spacing (3);
507 route_display_model = ListStore::create(route_display_columns);
508 route_list_display.set_model (route_display_model);
509 route_list_display.append_column (_("Show"), route_display_columns.visible);
510 route_list_display.append_column (_("Name"), route_display_columns.text);
511 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
512 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
513 route_list_display.set_headers_visible (true);
514 route_list_display.set_name ("TrackListDisplay");
515 route_list_display.get_selection()->set_mode (SELECTION_NONE);
516 route_list_display.set_reorderable (true);
517 route_list_display.set_size_request (100,-1);
519 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
520 route_list_visible_cell->property_activatable() = true;
521 route_list_visible_cell->property_radio() = false;
523 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
524 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
525 route_display_model->signal_rows_reordered().connect (mem_fun (*this, &Editor::track_list_reorder));
527 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
529 route_list_scroller.add (route_list_display);
530 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
532 group_model = ListStore::create(group_columns);
533 edit_group_display.set_model (group_model);
534 edit_group_display.append_column (_("Name"), group_columns.text);
535 edit_group_display.append_column (_("Active"), group_columns.is_active);
536 edit_group_display.append_column (_("Show"), group_columns.is_visible);
537 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
538 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
539 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
540 edit_group_display.get_column (0)->set_expand (true);
541 edit_group_display.get_column (1)->set_expand (false);
542 edit_group_display.get_column (2)->set_expand (false);
543 edit_group_display.set_headers_visible (true);
545 /* name is directly editable */
547 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
548 name_cell->property_editable() = true;
549 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
551 /* use checkbox for the active + visible columns */
553 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
554 active_cell->property_activatable() = true;
555 active_cell->property_radio() = false;
557 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
558 active_cell->property_activatable() = true;
559 active_cell->property_radio() = false;
561 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
563 edit_group_display.set_name ("EditGroupList");
564 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
565 edit_group_display.set_headers_visible (true);
566 edit_group_display.set_reorderable (false);
567 edit_group_display.set_rules_hint (true);
568 edit_group_display.set_size_request (75, -1);
570 edit_group_display_scroller.add (edit_group_display);
571 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
573 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
575 VBox* edit_group_display_packer = manage (new VBox());
576 HBox* edit_group_display_button_box = manage (new HBox());
577 edit_group_display_button_box->set_homogeneous (true);
579 Button* edit_group_add_button = manage (new Button ());
580 Button* edit_group_remove_button = manage (new Button ());
584 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
586 edit_group_add_button->add (*w);
588 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
590 edit_group_remove_button->add (*w);
592 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
593 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
595 edit_group_display_button_box->pack_start (*edit_group_add_button);
596 edit_group_display_button_box->pack_start (*edit_group_remove_button);
598 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
599 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
601 region_list_display.set_size_request (100, -1);
602 region_list_display.set_name ("RegionListDisplay");
603 /* Try to prevent single mouse presses from initiating edits.
604 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
606 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
608 region_list_model = TreeStore::create (region_list_columns);
609 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
610 region_list_model->set_sort_column (0, SORT_ASCENDING);
612 region_list_display.set_model (region_list_model);
613 region_list_display.append_column (_("Regions"), region_list_columns.name);
614 region_list_display.set_headers_visible (false);
616 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
617 region_name_cell->property_editable() = true;
618 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
620 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
622 TreeViewColumn* tv_col = region_list_display.get_column(0);
623 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
624 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
625 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
627 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
628 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
630 /* setup DnD handling */
632 list<TargetEntry> region_list_target_table;
634 region_list_target_table.push_back (TargetEntry ("text/plain"));
635 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
636 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
638 region_list_display.add_drop_targets (region_list_target_table);
639 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
641 region_list_scroller.add (region_list_display);
642 region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
644 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
645 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
646 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
647 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
648 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
649 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
651 named_selection_scroller.add (named_selection_display);
652 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
654 named_selection_model = TreeStore::create (named_selection_columns);
655 named_selection_display.set_model (named_selection_model);
656 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
657 named_selection_display.set_headers_visible (false);
658 named_selection_display.set_size_request (100, -1);
659 named_selection_display.set_name ("NamedSelectionDisplay");
661 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
662 named_selection_display.set_size_request (100, -1);
663 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
664 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
665 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
669 snapshot_display_model = ListStore::create (snapshot_display_columns);
670 snapshot_display.set_model (snapshot_display_model);
671 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
672 snapshot_display.set_name ("SnapshotDisplay");
673 snapshot_display.set_size_request (75, -1);
674 snapshot_display.set_headers_visible (false);
675 snapshot_display.set_reorderable (false);
676 snapshot_display_scroller.add (snapshot_display);
677 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
679 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
680 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
684 nlabel = manage (new Label (_("Regions")));
685 nlabel->set_angle (-90);
686 the_notebook.append_page (region_list_scroller, *nlabel);
687 nlabel = manage (new Label (_("Tracks/Busses")));
688 nlabel->set_angle (-90);
689 the_notebook.append_page (route_list_scroller, *nlabel);
690 nlabel = manage (new Label (_("Snapshots")));
691 nlabel->set_angle (-90);
692 the_notebook.append_page (snapshot_display_scroller, *nlabel);
693 nlabel = manage (new Label (_("Edit Groups")));
694 nlabel->set_angle (-90);
695 the_notebook.append_page (*edit_group_display_packer, *nlabel);
697 if (!Profile->get_sae()) {
698 nlabel = manage (new Label (_("Chunks")));
699 nlabel->set_angle (-90);
700 the_notebook.append_page (named_selection_scroller, *nlabel);
703 the_notebook.set_show_tabs (true);
704 the_notebook.set_scrollable (true);
705 the_notebook.popup_enable ();
706 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
708 post_maximal_editor_width = 0;
709 post_maximal_pane_position = 0;
710 edit_pane.pack1 (edit_packer, true, true);
711 edit_pane.pack2 (the_notebook, false, true);
713 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
715 top_hbox.pack_start (toolbar_frame, true, true);
717 HBox *hbox = manage (new HBox);
718 hbox->pack_start (edit_pane, true, true);
720 global_vpacker.pack_start (top_hbox, false, false);
721 global_vpacker.pack_start (*hbox, true, true);
723 global_hpacker.pack_start (global_vpacker, true, true);
725 set_name ("EditorWindow");
726 add_accel_group (ActionManager::ui_manager->get_accel_group());
728 status_bar_hpacker.show ();
730 vpacker.pack_end (status_bar_hpacker, false, false);
731 vpacker.pack_end (global_hpacker, true, true);
733 /* register actions now so that set_state() can find them and set toggles/checks etc */
737 snap_type = SnapToBeat;
738 set_snap_to (snap_type);
740 set_snap_mode (snap_mode);
741 set_edit_point_preference (EditAtMouse, true);
743 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
746 _playlist_selector = new PlaylistSelector();
747 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
749 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
753 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
754 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
756 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
757 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
759 nudge_forward_button.set_name ("TransportButton");
760 nudge_backward_button.set_name ("TransportButton");
762 fade_context_menu.set_name ("ArdourContextMenu");
764 /* icons, titles, WM stuff */
766 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
767 Glib::RefPtr<Gdk::Pixbuf> icon;
769 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
770 window_icons.push_back (icon);
772 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
773 window_icons.push_back (icon);
775 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
776 window_icons.push_back (icon);
778 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
779 window_icons.push_back (icon);
781 if (!window_icons.empty()) {
782 set_icon_list (window_icons);
783 set_default_icon_list (window_icons);
786 WindowTitle title(Glib::get_application_name());
787 title += _("Editor");
788 set_title (title.get_string());
789 set_wmclass (X_("ardour_editor"), "Ardour");
792 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
794 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
795 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
797 /* allow external control surfaces/protocols to do various things */
799 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
800 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
801 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
802 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
803 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
805 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
806 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
814 /* <CMT Additions> */
815 if(image_socket_listener)
817 if(image_socket_listener->is_connected())
819 image_socket_listener->close_connection() ;
822 delete image_socket_listener ;
823 image_socket_listener = 0 ;
825 /* </CMT Additions> */
834 Editor::add_toplevel_controls (Container& cont)
836 vpacker.pack_start (cont, false, false);
841 Editor::catch_vanishing_regionview (RegionView *rv)
843 /* note: the selection will take care of the vanishing
844 audioregionview by itself.
847 if (clicked_regionview == rv) {
848 clicked_regionview = 0;
851 if (entered_regionview == rv) {
852 set_entered_regionview (0);
857 Editor::set_entered_regionview (RegionView* rv)
859 if (rv == entered_regionview) {
863 if (entered_regionview) {
864 entered_regionview->exited ();
867 if ((entered_regionview = rv) != 0) {
868 entered_regionview->entered ();
873 Editor::set_entered_track (TimeAxisView* tav)
876 entered_track->exited ();
879 if ((entered_track = tav) != 0) {
880 entered_track->entered ();
885 Editor::show_window ()
890 /* now reset all audio_time_axis heights, because widgets might need
896 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
897 tv = (static_cast<TimeAxisView*>(*i));
903 Editor::instant_save ()
905 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
910 session->add_instant_xml(get_state(), session->path());
912 Config->add_instant_xml(get_state(), get_user_ardour_path());
917 Editor::edit_point_clock_changed()
919 if (_dragging_edit_point) {
923 if (selection->markers.empty()) {
928 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
934 loc->move_to (edit_point_clock.current_time());
938 Editor::zoom_adjustment_changed ()
944 double fpu = zoom_range_clock.current_duration() / canvas_width;
948 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
949 } else if (fpu > session->current_end_frame() / canvas_width) {
950 fpu = session->current_end_frame() / canvas_width;
951 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
958 Editor::control_scroll (float fraction)
960 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
966 double step = fraction * current_page_frames();
969 _control_scroll_target is an optional<T>
971 it acts like a pointer to an nframes64_t, with
972 a operator conversion to boolean to check
973 that it has a value could possibly use
974 playhead_cursor->current_frame to store the
975 value and a boolean in the class to know
976 when it's out of date
979 if (!_control_scroll_target) {
980 _control_scroll_target = session->transport_frame();
981 _dragging_playhead = true;
984 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
985 *_control_scroll_target = 0;
986 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
987 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
989 *_control_scroll_target += (nframes64_t) floor (step);
992 /* move visuals, we'll catch up with it later */
994 playhead_cursor->set_position (*_control_scroll_target);
995 UpdateAllTransportClocks (*_control_scroll_target);
997 if (*_control_scroll_target > (current_page_frames() / 2)) {
998 /* try to center PH in window */
999 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
1005 Now we do a timeout to actually bring the session to the right place
1006 according to the playhead. This is to avoid reading disk buffers on every
1007 call to control_scroll, which is driven by ScrollTimeline and therefore
1008 probably by a control surface wheel which can generate lots of events.
1010 /* cancel the existing timeout */
1012 control_scroll_connection.disconnect ();
1014 /* add the next timeout */
1016 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
1020 Editor::deferred_control_scroll (nframes64_t target)
1022 session->request_locate (*_control_scroll_target, session->transport_rolling());
1023 // reset for next stream
1024 _control_scroll_target = boost::none;
1025 _dragging_playhead = false;
1030 Editor::access_action (std::string action_group, std::string action_item)
1036 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
1038 cout<< "OSC: Recieved: "<< action_item << endl;
1041 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1051 Editor::on_realize ()
1053 Window::on_realize ();
1058 Editor::start_scrolling ()
1060 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1061 (mem_fun(*this, &Editor::update_current_screen));
1066 Editor::stop_scrolling ()
1068 scroll_connection.disconnect ();
1072 Editor::map_position_change (nframes64_t frame)
1074 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1076 if (session == 0 || !_follow_playhead) {
1080 center_screen (frame);
1081 playhead_cursor->set_position (frame);
1085 Editor::center_screen (nframes64_t frame)
1087 double page = canvas_width * frames_per_unit;
1089 /* if we're off the page, then scroll.
1092 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1093 center_screen_internal (frame, page);
1098 Editor::center_screen_internal (nframes64_t frame, float page)
1103 frame -= (nframes64_t) page;
1108 reset_x_origin (frame);
1112 Editor::handle_new_duration ()
1114 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1116 nframes64_t new_end = session->get_maximum_extent() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1118 if (new_end > last_canvas_frame) {
1119 last_canvas_frame = new_end;
1120 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1121 //reset_scrolling_region ();
1124 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1125 //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
1129 Editor::update_title_s (const string & snap_name)
1131 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1137 Editor::update_title ()
1139 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1142 bool dirty = session->dirty();
1144 string session_name;
1146 if (session->snap_name() != session->name()) {
1147 session_name = session->snap_name();
1149 session_name = session->name();
1153 session_name = "*" + session_name;
1156 WindowTitle title(session_name);
1157 title += Glib::get_application_name();
1158 set_title (title.get_string());
1163 Editor::connect_to_session (Session *t)
1167 /* there are never any selected regions at startup */
1169 sensitize_the_right_region_actions (false);
1171 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1174 /* catch up with the playhead */
1176 session->request_locate (playhead_cursor->current_frame);
1178 if (first_action_message) {
1179 first_action_message->hide();
1184 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1185 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1187 /* These signals can all be emitted by a non-GUI thread. Therefore the
1188 handlers for them must not attempt to directly interact with the GUI,
1189 but use Gtkmm2ext::UI::instance()->call_slot();
1192 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1193 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1194 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1195 session_connections.push_back (session->AudioRegionsAdded.connect (mem_fun(*this, &Editor::handle_new_audio_regions)));
1196 session_connections.push_back (session->AudioRegionRemoved.connect (mem_fun(*this, &Editor::handle_audio_region_removed)));
1197 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1198 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1199 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1200 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1201 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1202 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1203 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1204 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1205 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1207 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1209 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1211 edit_groups_changed ();
1213 edit_point_clock.set_session (session);
1214 zoom_range_clock.set_session (session);
1215 _playlist_selector->set_session (session);
1216 nudge_clock.set_session (session);
1217 nudge_clock.set (session->frame_rate() * 5); // default of 5 seconds
1219 if (rhythm_ferret) {
1220 rhythm_ferret->set_session (session);
1224 if (analysis_window != 0)
1225 analysis_window->set_session (session);
1228 Location* loc = session->locations()->auto_loop_location();
1230 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1231 if (loc->start() == loc->end()) {
1232 loc->set_end (loc->start() + 1);
1234 session->locations()->add (loc, false);
1235 session->set_auto_loop_location (loc);
1238 loc->set_name (_("Loop"));
1241 loc = session->locations()->auto_punch_location();
1243 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1244 if (loc->start() == loc->end()) {
1245 loc->set_end (loc->start() + 1);
1247 session->locations()->add (loc, false);
1248 session->set_auto_punch_location (loc);
1251 loc->set_name (_("Punch"));
1254 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1256 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1258 refresh_location_display ();
1259 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1260 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1261 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1262 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1263 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1266 sfbrowser->set_session (session);
1269 handle_new_duration ();
1271 redisplay_regions ();
1272 redisplay_named_selections ();
1273 redisplay_snapshots ();
1275 initial_route_list_display ();
1277 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1278 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1281 restore_ruler_visibility ();
1282 //tempo_map_changed (Change (0));
1283 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1287 /* don't show master bus in a new session */
1289 if (ARDOUR_UI::instance()->session_is_new ()) {
1291 TreeModel::Children rows = route_display_model->children();
1292 TreeModel::Children::iterator i;
1294 no_route_list_redisplay = true;
1296 for (i = rows.begin(); i != rows.end(); ++i) {
1297 TimeAxisView *tv = (*i)[route_display_columns.tv];
1298 AudioTimeAxisView *atv;
1300 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1301 if (atv->route()->master()) {
1302 route_list_display.get_selection()->unselect (i);
1307 no_route_list_redisplay = false;
1308 redisplay_route_list ();
1311 switch (snap_type) {
1312 case SnapToRegionStart:
1313 case SnapToRegionEnd:
1314 case SnapToRegionSync:
1315 case SnapToRegionBoundary:
1316 build_region_boundary_cache ();
1323 /* register for undo history */
1325 session->register_with_memento_command_factory(_id, this);
1331 Editor::build_cursors ()
1333 using namespace Gdk;
1335 Gdk::Color mbg ("#000000" ); /* Black */
1336 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1339 RefPtr<Bitmap> source, mask;
1340 source = Bitmap::create (mag_bits, mag_width, mag_height);
1341 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1342 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1345 Gdk::Color fbg ("#ffffff" );
1346 Gdk::Color ffg ("#000000" );
1349 RefPtr<Bitmap> source, mask;
1351 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1352 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1353 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1357 RefPtr<Bitmap> source, mask;
1358 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1359 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1360 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1364 RefPtr<Bitmap> bits;
1365 char pix[4] = { 0, 0, 0, 0 };
1366 bits = Bitmap::create (pix, 2, 2);
1368 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1372 grabber_cursor = new Gdk::Cursor (HAND2);
1375 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1376 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1379 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1380 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1381 selector_cursor = new Gdk::Cursor (XTERM);
1382 time_fx_cursor = new Gdk::Cursor (SIZING);
1383 wait_cursor = new Gdk::Cursor (WATCH);
1384 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1388 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1390 using namespace Menu_Helpers;
1391 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1394 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1398 MenuList& items (fade_context_menu.items());
1402 switch (item_type) {
1404 case FadeInHandleItem:
1405 if (arv->audio_region()->fade_in_active()) {
1406 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1408 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1411 items.push_back (SeparatorElem());
1413 if (Profile->get_sae()) {
1414 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1415 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1417 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1418 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1419 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1420 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1421 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1426 case FadeOutHandleItem:
1427 if (arv->audio_region()->fade_out_active()) {
1428 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1430 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1433 items.push_back (SeparatorElem());
1435 if (Profile->get_sae()) {
1436 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1437 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1439 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1440 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1441 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1442 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1443 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1448 fatal << _("programming error: ")
1449 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1454 fade_context_menu.popup (button, time);
1458 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1460 using namespace Menu_Helpers;
1461 Menu* (Editor::*build_menu_function)(nframes64_t);
1464 switch (item_type) {
1466 case RegionViewName:
1467 case RegionViewNameHighlight:
1468 if (with_selection) {
1469 build_menu_function = &Editor::build_track_selection_context_menu;
1471 build_menu_function = &Editor::build_track_region_context_menu;
1476 if (with_selection) {
1477 build_menu_function = &Editor::build_track_selection_context_menu;
1479 build_menu_function = &Editor::build_track_context_menu;
1483 case CrossfadeViewItem:
1484 build_menu_function = &Editor::build_track_crossfade_context_menu;
1488 if (clicked_audio_trackview->get_diskstream()) {
1489 build_menu_function = &Editor::build_track_context_menu;
1491 build_menu_function = &Editor::build_track_bus_context_menu;
1496 /* probably shouldn't happen but if it does, we don't care */
1500 menu = (this->*build_menu_function)(frame);
1501 menu->set_name ("ArdourContextMenu");
1503 /* now handle specific situations */
1505 switch (item_type) {
1507 case RegionViewName:
1508 case RegionViewNameHighlight:
1509 if (!with_selection) {
1510 if (region_edit_menu_split_item) {
1511 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1512 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1514 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1518 if (region_edit_menu_split_multichannel_item) {
1519 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1520 // GTK2FIX find the action, change its sensitivity
1521 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1523 // GTK2FIX see above
1524 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1533 case CrossfadeViewItem:
1540 /* probably shouldn't happen but if it does, we don't care */
1544 if (item_type != SelectionItem && clicked_audio_trackview && clicked_audio_trackview->audio_track()) {
1546 /* Bounce to disk */
1548 using namespace Menu_Helpers;
1549 MenuList& edit_items = menu->items();
1551 edit_items.push_back (SeparatorElem());
1553 switch (clicked_audio_trackview->audio_track()->freeze_state()) {
1554 case AudioTrack::NoFreeze:
1555 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1558 case AudioTrack::Frozen:
1559 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1562 case AudioTrack::UnFrozen:
1563 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1569 menu->popup (button, time);
1573 Editor::build_track_context_menu (nframes64_t ignored)
1575 using namespace Menu_Helpers;
1577 MenuList& edit_items = track_context_menu.items();
1580 add_dstream_context_items (edit_items);
1581 return &track_context_menu;
1585 Editor::build_track_bus_context_menu (nframes64_t ignored)
1587 using namespace Menu_Helpers;
1589 MenuList& edit_items = track_context_menu.items();
1592 add_bus_context_items (edit_items);
1593 return &track_context_menu;
1597 Editor::build_track_region_context_menu (nframes64_t frame)
1599 using namespace Menu_Helpers;
1600 MenuList& edit_items = track_region_context_menu.items();
1603 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1606 boost::shared_ptr<Diskstream> ds;
1607 boost::shared_ptr<Playlist> pl;
1609 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
1610 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1612 if (selection->regions.size() > 1) {
1613 // there's already a multiple selection: just add a
1614 // single region context menu that will act on all
1616 boost::shared_ptr<Region> dummy_region; // = NULL
1617 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1619 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1620 add_region_context_items (atv->audio_view(), (*i), edit_items);
1628 add_dstream_context_items (edit_items);
1630 return &track_region_context_menu;
1634 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1636 using namespace Menu_Helpers;
1637 MenuList& edit_items = track_crossfade_context_menu.items();
1638 edit_items.clear ();
1640 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1643 boost::shared_ptr<Diskstream> ds;
1644 boost::shared_ptr<Playlist> pl;
1645 boost::shared_ptr<AudioPlaylist> apl;
1647 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1649 Playlist::RegionList* regions = pl->regions_at (frame);
1650 AudioPlaylist::Crossfades xfades;
1652 apl->crossfades_at (frame, xfades);
1654 bool many = xfades.size() > 1;
1656 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1657 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1660 if (selection->regions.size() > 1) {
1661 // there's already a multiple selection: just add a
1662 // single region context menu that will act on all
1664 boost::shared_ptr<Region> dummy_region; // = NULL
1665 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1667 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1668 add_region_context_items (atv->audio_view(), (*i), edit_items);
1675 add_dstream_context_items (edit_items);
1677 return &track_crossfade_context_menu;
1682 Editor::analyze_region_selection()
1684 if (analysis_window == 0) {
1685 analysis_window = new AnalysisWindow();
1688 analysis_window->set_session(session);
1690 analysis_window->show_all();
1693 analysis_window->set_regionmode();
1694 analysis_window->analyze();
1696 analysis_window->present();
1700 Editor::analyze_range_selection()
1702 if (analysis_window == 0) {
1703 analysis_window = new AnalysisWindow();
1706 analysis_window->set_session(session);
1708 analysis_window->show_all();
1711 analysis_window->set_rangemode();
1712 analysis_window->analyze();
1714 analysis_window->present();
1716 #endif /* FFT_ANALYSIS */
1721 Editor::build_track_selection_context_menu (nframes64_t ignored)
1723 using namespace Menu_Helpers;
1724 MenuList& edit_items = track_selection_context_menu.items();
1725 edit_items.clear ();
1727 add_selection_context_items (edit_items);
1728 // edit_items.push_back (SeparatorElem());
1729 // add_dstream_context_items (edit_items);
1731 return &track_selection_context_menu;
1735 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1737 using namespace Menu_Helpers;
1738 Menu *xfade_menu = manage (new Menu);
1739 MenuList& items = xfade_menu->items();
1740 xfade_menu->set_name ("ArdourContextMenu");
1743 if (xfade->active()) {
1749 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1750 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1752 if (xfade->can_follow_overlap()) {
1754 if (xfade->following_overlap()) {
1755 str = _("Convert to short");
1757 str = _("Convert to full");
1760 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1764 str = xfade->out()->name();
1766 str += xfade->in()->name();
1768 str = _("Crossfade");
1771 edit_items.push_back (MenuElem (str, *xfade_menu));
1772 edit_items.push_back (SeparatorElem());
1776 Editor::xfade_edit_left_region ()
1778 if (clicked_crossfadeview) {
1779 clicked_crossfadeview->left_view.show_region_editor ();
1784 Editor::xfade_edit_right_region ()
1786 if (clicked_crossfadeview) {
1787 clicked_crossfadeview->right_view.show_region_editor ();
1792 Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1794 using namespace Menu_Helpers;
1795 Menu *region_menu = manage (new Menu);
1796 MenuList& items = region_menu->items();
1797 region_menu->set_name ("ArdourContextMenu");
1799 boost::shared_ptr<AudioRegion> ar;
1802 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1804 /* when this particular menu pops up, make the relevant region
1808 region_menu->signal_map_event().connect (
1810 mem_fun(*this, &Editor::set_selected_regionview_from_map_event),
1812 boost::weak_ptr<Region>(region)
1816 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1817 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1820 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1821 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1822 items.push_back (SeparatorElem());
1823 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1824 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1825 items.push_back (SeparatorElem());
1827 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1828 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1829 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1832 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1835 items.push_back (SeparatorElem());
1837 sigc::connection fooc;
1840 items.push_back (CheckMenuElem (_("Lock")));
1841 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1842 if (region->locked()) {
1843 region_lock_item->set_active();
1845 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1847 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1848 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1850 switch (region->positional_lock_style()) {
1851 case Region::MusicTime:
1852 bbt_glue_item->set_active (true);
1855 bbt_glue_item->set_active (false);
1859 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1861 items.push_back (CheckMenuElem (_("Mute")));
1862 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1863 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1864 if (region->muted()) {
1866 region_mute_item->set_active();
1870 if (!Profile->get_sae()) {
1871 items.push_back (CheckMenuElem (_("Opaque")));
1872 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1873 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1874 if (region->opaque()) {
1876 region_opaque_item->set_active();
1881 // multiple regions selected
1882 // how should these act?
1883 // here they toggle the property of all selected regions
1885 items.push_back (MenuElem (_("Lock"), mem_fun(*this, &Editor::toggle_region_lock)));
1886 items.push_back (MenuElem (_("Mute"), mem_fun(*this, &Editor::toggle_region_mute)));
1887 if (!Profile->get_sae()) {
1888 items.push_back (MenuElem (_("Opaque"), mem_fun(*this, &Editor::toggle_region_opaque)));
1892 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1893 if (region && region->at_natural_position()) {
1894 items.back().set_sensitive (false);
1897 items.push_back (SeparatorElem());
1901 RegionView* rv = sv->find_view (ar);
1902 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1904 if (!Profile->get_sae()) {
1905 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1907 items.push_back (CheckMenuElem (_("Envelope Visible")));
1908 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1909 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1910 if (arv->envelope_visible()) {
1912 region_envelope_visible_item->set_active (true);
1916 items.push_back (CheckMenuElem (_("Envelope Active")));
1917 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1918 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1920 if (ar->envelope_active()) {
1922 region_envelope_active_item->set_active (true);
1926 items.push_back (SeparatorElem());
1929 if (ar->scale_amplitude() != 1.0f) {
1930 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1932 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1936 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1937 items.push_back (SeparatorElem());
1939 /* range related stuff */
1941 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1942 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_audio_region)));
1943 items.push_back (SeparatorElem());
1947 Menu *nudge_menu = manage (new Menu());
1948 MenuList& nudge_items = nudge_menu->items();
1949 nudge_menu->set_name ("ArdourContextMenu");
1951 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1952 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1953 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1954 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1956 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1957 items.push_back (SeparatorElem());
1959 Menu *trim_menu = manage (new Menu);
1960 MenuList& trim_items = trim_menu->items();
1961 trim_menu->set_name ("ArdourContextMenu");
1963 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1964 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1965 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1966 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1968 items.push_back (MenuElem (_("Trim"), *trim_menu));
1969 items.push_back (SeparatorElem());
1971 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1972 region_edit_menu_split_item = &items.back();
1974 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1975 region_edit_menu_split_multichannel_item = &items.back();
1977 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1978 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1979 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1980 items.push_back (SeparatorElem());
1981 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_region)));
1983 /* OK, stick the region submenu at the top of the list, and then add
1987 /* we have to hack up the region name because "_" has a special
1988 meaning for menu titles.
1991 string::size_type pos = 0;
1992 string menu_item_name = (region) ? region->name() : _("Selected regions");
1994 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1995 menu_item_name.replace (pos, 1, "__");
1999 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
2000 edit_items.push_back (SeparatorElem());
2004 Editor::add_selection_context_items (Menu_Helpers::MenuList& items)
2006 using namespace Menu_Helpers;
2008 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
2009 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
2012 items.push_back (SeparatorElem());
2013 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
2016 items.push_back (SeparatorElem());
2017 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
2018 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
2020 items.push_back (SeparatorElem());
2021 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
2022 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
2024 items.push_back (SeparatorElem());
2025 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
2027 items.push_back (SeparatorElem());
2028 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
2029 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
2031 items.push_back (SeparatorElem());
2032 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
2033 items.push_back (SeparatorElem());
2034 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
2035 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
2036 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
2037 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
2038 items.push_back (SeparatorElem());
2039 items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
2040 items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
2041 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
2045 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2047 using namespace Menu_Helpers;
2051 Menu *play_menu = manage (new Menu);
2052 MenuList& play_items = play_menu->items();
2053 play_menu->set_name ("ArdourContextMenu");
2055 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2056 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2057 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2058 play_items.push_back (SeparatorElem());
2059 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2061 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2065 Menu *select_menu = manage (new Menu);
2066 MenuList& select_items = select_menu->items();
2067 select_menu->set_name ("ArdourContextMenu");
2069 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2070 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2071 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2072 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2073 select_items.push_back (SeparatorElem());
2074 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2075 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2076 select_items.push_back (SeparatorElem());
2077 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2078 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2079 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2080 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2081 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2082 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2083 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2085 select_items.push_back (SeparatorElem());
2087 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2091 Menu *cutnpaste_menu = manage (new Menu);
2092 MenuList& cutnpaste_items = cutnpaste_menu->items();
2093 cutnpaste_menu->set_name ("ArdourContextMenu");
2095 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2096 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2097 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2099 cutnpaste_items.push_back (SeparatorElem());
2101 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2102 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2104 cutnpaste_items.push_back (SeparatorElem());
2106 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2108 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2110 /* Adding new material */
2112 edit_items.push_back (SeparatorElem());
2113 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2114 edit_items.push_back (MenuElem (_("Insert Existing Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2118 Menu *nudge_menu = manage (new Menu());
2119 MenuList& nudge_items = nudge_menu->items();
2120 nudge_menu->set_name ("ArdourContextMenu");
2122 edit_items.push_back (SeparatorElem());
2123 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2124 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2125 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2126 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2128 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2132 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2134 using namespace Menu_Helpers;
2138 Menu *play_menu = manage (new Menu);
2139 MenuList& play_items = play_menu->items();
2140 play_menu->set_name ("ArdourContextMenu");
2142 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2143 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2144 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2148 Menu *select_menu = manage (new Menu);
2149 MenuList& select_items = select_menu->items();
2150 select_menu->set_name ("ArdourContextMenu");
2152 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2153 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2154 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2155 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2156 select_items.push_back (SeparatorElem());
2157 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2158 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2159 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2160 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2162 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2166 Menu *cutnpaste_menu = manage (new Menu);
2167 MenuList& cutnpaste_items = cutnpaste_menu->items();
2168 cutnpaste_menu->set_name ("ArdourContextMenu");
2170 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2171 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2172 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2174 Menu *nudge_menu = manage (new Menu());
2175 MenuList& nudge_items = nudge_menu->items();
2176 nudge_menu->set_name ("ArdourContextMenu");
2178 edit_items.push_back (SeparatorElem());
2179 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2180 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2181 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2182 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2184 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2188 Editor::set_snap_to (SnapType st)
2190 unsigned int snap_ind = (unsigned int)st;
2193 if (snap_ind > snap_type_strings.size() - 1) {
2195 snap_type = (SnapType)snap_ind;
2198 string str = snap_type_strings[snap_ind];
2200 if (str != snap_type_selector.get_active_text()) {
2201 snap_type_selector.set_active_text (str);
2206 switch (snap_type) {
2207 case SnapToAThirtysecondBeat:
2208 case SnapToASixteenthBeat:
2209 case SnapToAEighthBeat:
2210 case SnapToAQuarterBeat:
2211 case SnapToAThirdBeat:
2212 update_tempo_based_rulers ();
2215 case SnapToRegionStart:
2216 case SnapToRegionEnd:
2217 case SnapToRegionSync:
2218 case SnapToRegionBoundary:
2219 build_region_boundary_cache ();
2229 Editor::set_snap_mode (SnapMode mode)
2232 string str = snap_mode_strings[(int)mode];
2234 if (str != snap_mode_selector.get_active_text ()) {
2235 snap_mode_selector.set_active_text (str);
2241 Editor::set_edit_point_preference (EditPoint ep, bool force)
2243 bool changed = (_edit_point != ep);
2246 string str = edit_point_strings[(int)ep];
2248 if (str != edit_point_selector.get_active_text ()) {
2249 edit_point_selector.set_active_text (str);
2252 set_canvas_cursor ();
2254 if (!force && !changed) {
2258 switch (zoom_focus) {
2259 case ZoomFocusMouse:
2260 case ZoomFocusPlayhead:
2262 switch (_edit_point) {
2264 set_zoom_focus (ZoomFocusMouse);
2266 case EditAtPlayhead:
2267 set_zoom_focus (ZoomFocusPlayhead);
2269 case EditAtSelectedMarker:
2270 set_zoom_focus (ZoomFocusEdit);
2280 switch (_edit_point) {
2281 case EditAtPlayhead:
2282 action = "edit-at-playhead";
2284 case EditAtSelectedMarker:
2285 action = "edit-at-marker";
2288 action = "edit-at-mouse";
2292 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2294 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2298 bool in_track_canvas;
2300 if (!mouse_frame (foo, in_track_canvas)) {
2301 in_track_canvas = false;
2304 reset_canvas_action_sensitivity (in_track_canvas);
2310 Editor::set_state (const XMLNode& node)
2312 const XMLProperty* prop;
2314 int x, y, xoff, yoff;
2317 if ((prop = node.property ("id")) != 0) {
2318 _id = prop->value ();
2321 if ((geometry = find_named_node (node, "geometry")) == 0) {
2323 g.base_width = default_width;
2324 g.base_height = default_height;
2332 g.base_width = atoi(geometry->property("x_size")->value());
2333 g.base_height = atoi(geometry->property("y_size")->value());
2334 x = atoi(geometry->property("x_pos")->value());
2335 y = atoi(geometry->property("y_pos")->value());
2336 xoff = atoi(geometry->property("x_off")->value());
2337 yoff = atoi(geometry->property("y_off")->value());
2340 set_default_size (g.base_width, g.base_height);
2343 if (session && (prop = node.property ("playhead"))) {
2344 nframes64_t pos = atol (prop->value().c_str());
2345 playhead_cursor->set_position (pos);
2347 playhead_cursor->set_position (0);
2349 /* reset_x_origin() doesn't work right here, since the old
2350 position may be zero already, and it does nothing in such
2355 horizontal_adjustment.set_value (0);
2358 if ((prop = node.property ("mixer-width"))) {
2359 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2362 if ((prop = node.property ("zoom-focus"))) {
2363 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2366 if ((prop = node.property ("zoom"))) {
2367 reset_zoom (PBD::atof (prop->value()));
2370 if ((prop = node.property ("snap-to"))) {
2371 set_snap_to ((SnapType) atoi (prop->value()));
2374 if ((prop = node.property ("snap-mode"))) {
2375 set_snap_mode ((SnapMode) atoi (prop->value()));
2378 if ((prop = node.property ("edit-point"))) {
2379 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2382 if ((prop = node.property ("mouse-mode"))) {
2383 MouseMode m = str2mousemode(prop->value());
2384 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2385 set_mouse_mode (m, true);
2387 mouse_mode = MouseGain; /* lie, to force the mode switch */
2388 set_mouse_mode (MouseObject, true);
2391 if ((prop = node.property ("show-waveforms"))) {
2392 bool yn = (prop->value() == "yes");
2393 _show_waveforms = !yn;
2394 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
2396 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2397 /* do it twice to force the change */
2398 tact->set_active (!yn);
2399 tact->set_active (yn);
2403 if ((prop = node.property ("show-waveforms-recording"))) {
2404 bool yn = (prop->value() == "yes");
2405 _show_waveforms_recording = !yn;
2406 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2408 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2409 /* do it twice to force the change */
2410 tact->set_active (!yn);
2411 tact->set_active (yn);
2415 if ((prop = node.property ("show-measures"))) {
2416 bool yn = (prop->value() == "yes");
2417 _show_measures = !yn;
2418 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2420 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2421 /* do it twice to force the change */
2422 tact->set_active (!yn);
2423 tact->set_active (yn);
2427 if ((prop = node.property ("follow-playhead"))) {
2428 bool yn = (prop->value() == "yes");
2429 set_follow_playhead (yn);
2430 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2432 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2433 if (tact->get_active() != yn) {
2434 tact->set_active (yn);
2439 if ((prop = node.property ("region-list-sort-type"))) {
2440 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2441 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2444 if ((prop = node.property ("xfades-visible"))) {
2445 bool yn = (prop->value() == "yes");
2446 _xfade_visibility = !yn;
2447 // set_xfade_visibility (yn);
2450 if ((prop = node.property ("show-editor-mixer"))) {
2452 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2455 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2456 bool yn = (prop->value() == X_("yes"));
2458 /* do it twice to force the change */
2460 tact->set_active (!yn);
2461 tact->set_active (yn);
2470 Editor::get_state ()
2472 XMLNode* node = new XMLNode ("Editor");
2475 _id.print (buf, sizeof (buf));
2476 node->add_property ("id", buf);
2478 if (is_realized()) {
2479 Glib::RefPtr<Gdk::Window> win = get_window();
2481 int x, y, xoff, yoff, width, height;
2482 win->get_root_origin(x, y);
2483 win->get_position(xoff, yoff);
2484 win->get_size(width, height);
2486 XMLNode* geometry = new XMLNode ("geometry");
2488 snprintf(buf, sizeof(buf), "%d", width);
2489 geometry->add_property("x_size", string(buf));
2490 snprintf(buf, sizeof(buf), "%d", height);
2491 geometry->add_property("y_size", string(buf));
2492 snprintf(buf, sizeof(buf), "%d", x);
2493 geometry->add_property("x_pos", string(buf));
2494 snprintf(buf, sizeof(buf), "%d", y);
2495 geometry->add_property("y_pos", string(buf));
2496 snprintf(buf, sizeof(buf), "%d", xoff);
2497 geometry->add_property("x_off", string(buf));
2498 snprintf(buf, sizeof(buf), "%d", yoff);
2499 geometry->add_property("y_off", string(buf));
2500 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2501 geometry->add_property("edit_pane_pos", string(buf));
2503 node->add_child_nocopy (*geometry);
2506 maybe_add_mixer_strip_width (*node);
2508 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2509 node->add_property ("zoom-focus", buf);
2510 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2511 node->add_property ("zoom", buf);
2512 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2513 node->add_property ("snap-to", buf);
2514 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2515 node->add_property ("snap-mode", buf);
2517 node->add_property ("edit-point", enum_2_string (_edit_point));
2519 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2520 node->add_property ("playhead", buf);
2522 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2523 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2524 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2525 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2526 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2527 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2528 node->add_property ("mouse-mode", enum2str(mouse_mode));
2530 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2532 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2533 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2542 Editor::trackview_by_y_position (double y)
2544 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2548 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2557 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2559 if (!session || snap_mode == SnapOff) {
2563 snap_to_internal (start, direction, for_mark);
2567 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2569 Location* before = 0;
2570 Location* after = 0;
2572 const nframes64_t one_second = session->frame_rate();
2573 const nframes64_t one_minute = session->frame_rate() * 60;
2574 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2575 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2576 nframes64_t presnap = start;
2578 switch (snap_type) {
2580 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2581 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2583 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2587 case SnapToSMPTEFrame:
2588 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2589 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2591 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2595 case SnapToSMPTESeconds:
2596 if (session->smpte_offset_negative())
2598 start += session->smpte_offset ();
2600 start -= session->smpte_offset ();
2602 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2603 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2605 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2608 if (session->smpte_offset_negative())
2610 start -= session->smpte_offset ();
2612 start += session->smpte_offset ();
2616 case SnapToSMPTEMinutes:
2617 if (session->smpte_offset_negative())
2619 start += session->smpte_offset ();
2621 start -= session->smpte_offset ();
2623 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2624 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2626 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2628 if (session->smpte_offset_negative())
2630 start -= session->smpte_offset ();
2632 start += session->smpte_offset ();
2637 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2638 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2640 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2645 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2646 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2648 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2653 start = session->tempo_map().round_to_bar (start, direction);
2657 start = session->tempo_map().round_to_beat (start, direction);
2660 case SnapToAThirtysecondBeat:
2661 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2664 case SnapToASixteenthBeat:
2665 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2668 case SnapToAEighthBeat:
2669 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2672 case SnapToAQuarterBeat:
2673 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2676 case SnapToAThirdBeat:
2677 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2685 before = session->locations()->first_location_before (start);
2686 after = session->locations()->first_location_after (start);
2688 if (direction < 0) {
2690 start = before->start();
2694 } else if (direction > 0) {
2696 start = after->start();
2698 start = session->current_end_frame();
2703 /* find nearest of the two */
2704 if ((start - before->start()) < (after->start() - start)) {
2705 start = before->start();
2707 start = after->start();
2710 start = before->start();
2713 start = after->start();
2720 case SnapToRegionStart:
2721 case SnapToRegionEnd:
2722 case SnapToRegionSync:
2723 case SnapToRegionBoundary:
2724 if (!region_boundary_cache.empty()) {
2725 vector<nframes64_t>::iterator i;
2727 if (direction > 0) {
2728 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2730 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2733 if (i != region_boundary_cache.end()) {
2735 /* lower bound doesn't quite to the right thing for our purposes */
2737 if (direction < 0 && i != region_boundary_cache.begin()) {
2744 start = region_boundary_cache.back();
2750 switch (snap_mode) {
2756 if (presnap > start) {
2757 if (presnap > (start + unit_to_frame(snap_threshold))) {
2761 } else if (presnap < start) {
2762 if (presnap < (start - unit_to_frame(snap_threshold))) {
2768 /* handled at entry */
2775 Editor::setup_toolbar ()
2780 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2782 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2785 /* Mode Buttons (tool selection) */
2787 vector<ToggleButton *> mouse_mode_buttons;
2789 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2790 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2791 mouse_mode_buttons.push_back (&mouse_move_button);
2793 if (!Profile->get_sae()) {
2794 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2795 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2796 mouse_mode_buttons.push_back (&mouse_select_button);
2798 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2799 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2800 mouse_mode_buttons.push_back (&mouse_gain_button);
2803 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2804 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2805 mouse_mode_buttons.push_back (&mouse_zoom_button);
2806 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2807 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2808 mouse_mode_buttons.push_back (&mouse_timefx_button);
2809 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2810 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2811 mouse_mode_buttons.push_back (&mouse_audition_button);
2813 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2815 HBox* mode_box = manage(new HBox);
2816 mode_box->set_border_width (2);
2817 mode_box->set_spacing(4);
2818 mouse_mode_button_box.set_spacing(1);
2819 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2820 if (!Profile->get_sae()) {
2821 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2823 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2824 if (!Profile->get_sae()) {
2825 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2827 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2828 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2829 mouse_mode_button_box.set_homogeneous(true);
2831 vector<string> edit_mode_strings;
2832 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2833 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2834 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2836 edit_mode_selector.set_name ("EditModeSelector");
2837 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2838 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2839 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2841 mode_box->pack_start(edit_mode_selector);
2842 mode_box->pack_start(mouse_mode_button_box);
2844 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2845 mouse_mode_tearoff->set_name ("MouseModeBase");
2847 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2848 &mouse_mode_tearoff->tearoff_window()));
2849 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2850 &mouse_mode_tearoff->tearoff_window(), 1));
2851 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2852 &mouse_mode_tearoff->tearoff_window()));
2853 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2854 &mouse_mode_tearoff->tearoff_window(), 1));
2856 mouse_move_button.set_name ("MouseModeButton");
2857 mouse_select_button.set_name ("MouseModeButton");
2858 mouse_gain_button.set_name ("MouseModeButton");
2859 mouse_zoom_button.set_name ("MouseModeButton");
2860 mouse_timefx_button.set_name ("MouseModeButton");
2861 mouse_audition_button.set_name ("MouseModeButton");
2863 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2864 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2865 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2866 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2867 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2868 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2870 mouse_move_button.unset_flags (CAN_FOCUS);
2871 mouse_select_button.unset_flags (CAN_FOCUS);
2872 mouse_gain_button.unset_flags (CAN_FOCUS);
2873 mouse_zoom_button.unset_flags (CAN_FOCUS);
2874 mouse_timefx_button.unset_flags (CAN_FOCUS);
2875 mouse_audition_button.unset_flags (CAN_FOCUS);
2877 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2878 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2880 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2881 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2882 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2883 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2884 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2886 // mouse_move_button.set_active (true);
2891 zoom_box.set_spacing (1);
2892 zoom_box.set_border_width (2);
2894 zoom_in_button.set_name ("EditorTimeButton");
2895 zoom_in_button.set_size_request(-1,16);
2896 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2897 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2898 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2900 zoom_out_button.set_name ("EditorTimeButton");
2901 zoom_out_button.set_size_request(-1,16);
2902 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2903 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2904 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2906 zoom_out_full_button.set_name ("EditorTimeButton");
2907 zoom_out_full_button.set_size_request(-1,16);
2908 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2909 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2910 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2912 zoom_focus_selector.set_name ("ZoomFocusSelector");
2913 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
2914 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
2915 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2916 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2918 zoom_box.pack_start (zoom_focus_selector, true, true);
2919 zoom_box.pack_start (zoom_out_button, false, false);
2920 zoom_box.pack_start (zoom_in_button, false, false);
2921 zoom_box.pack_start (zoom_out_full_button, false, false);
2923 snap_box.set_spacing (1);
2924 snap_box.set_border_width (2);
2926 snap_type_selector.set_name ("SnapTypeSelector");
2927 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
2928 set_popdown_strings (snap_type_selector, snap_type_strings);
2929 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2930 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2932 snap_mode_selector.set_name ("SnapModeSelector");
2933 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
2934 set_popdown_strings (snap_mode_selector, snap_mode_strings);
2935 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2936 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2938 edit_point_selector.set_name ("SnapModeSelector");
2939 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
2940 set_popdown_strings (edit_point_selector, edit_point_strings);
2941 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2942 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2944 snap_box.pack_start (edit_point_clock, false, false);
2945 snap_box.pack_start (snap_mode_selector, false, false);
2946 snap_box.pack_start (snap_type_selector, false, false);
2947 snap_box.pack_start (edit_point_selector, false, false);
2951 HBox *nudge_box = manage (new HBox);
2952 nudge_box->set_spacing(1);
2953 nudge_box->set_border_width (2);
2955 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
2956 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
2958 nudge_box->pack_start (nudge_backward_button, false, false);
2959 nudge_box->pack_start (nudge_forward_button, false, false);
2960 nudge_box->pack_start (nudge_clock, false, false);
2963 /* Pack everything in... */
2965 HBox* hbox = new HBox;
2966 hbox->set_spacing(10);
2968 tools_tearoff = new TearOff (*hbox);
2969 tools_tearoff->set_name ("MouseModeBase");
2971 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2972 &tools_tearoff->tearoff_window()));
2973 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2974 &tools_tearoff->tearoff_window(), 0));
2975 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2976 &tools_tearoff->tearoff_window()));
2977 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2978 &tools_tearoff->tearoff_window(), 0));
2980 toolbar_hbox.set_spacing (10);
2981 toolbar_hbox.set_border_width (1);
2983 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2984 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2987 hbox->pack_start (snap_box, false, false);
2988 // hbox->pack_start (zoom_box, false, false);
2989 hbox->pack_start (*nudge_box, false, false);
2993 toolbar_base.set_name ("ToolBarBase");
2994 toolbar_base.add (toolbar_hbox);
2996 toolbar_frame.set_shadow_type (SHADOW_OUT);
2997 toolbar_frame.set_name ("BaseFrame");
2998 toolbar_frame.add (toolbar_base);
3002 Editor::convert_drop_to_paths (vector<ustring>& paths,
3003 const RefPtr<Gdk::DragContext>& context,
3006 const SelectionData& data,
3015 vector<ustring> uris = data.get_uris();
3019 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3020 are actually URI lists. So do it by hand.
3023 if (data.get_target() != "text/plain") {
3027 /* Parse the "uri-list" format that Nautilus provides,
3028 where each pathname is delimited by \r\n
3031 const char* p = data.get_text().c_str();
3038 while (g_ascii_isspace (*p))
3042 while (*q && (*q != '\n') && (*q != '\r'))
3048 while (q > p && g_ascii_isspace (*q))
3053 uris.push_back (ustring (p, q - p + 1));
3057 p = strchr (p, '\n');
3067 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3069 if ((*i).substr (0,7) == "file://") {
3073 PBD::url_decode (p);
3075 // scan forward past three slashes
3077 ustring::size_type slashcnt = 0;
3078 ustring::size_type n = 0;
3079 ustring::iterator x = p.begin();
3081 while (slashcnt < 3 && x != p.end()) {
3084 } else if (slashcnt == 3) {
3091 if (slashcnt != 3 || x == p.end()) {
3092 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3096 paths.push_back (p.substr (n - 1));
3104 Editor::new_tempo_section ()
3110 Editor::map_transport_state ()
3112 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3114 if (session->transport_stopped()) {
3115 have_pending_keyboard_selection = false;
3118 update_loop_range_view (true);
3123 Editor::State::State ()
3125 selection = new Selection;
3128 Editor::State::~State ()
3134 Editor::get_memento () const
3136 State *state = new State;
3138 store_state (*state);
3139 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
3143 Editor::store_state (State& state) const
3145 *state.selection = *selection;
3149 Editor::restore_state (State *state)
3151 if (*selection == *state->selection) {
3155 *selection = *state->selection;
3156 time_selection_changed ();
3157 region_selection_changed ();
3159 /* XXX other selection change handlers? */
3163 Editor::begin_reversible_command (string name)
3166 // before = &get_state();
3167 session->begin_reversible_command (name);
3172 Editor::commit_reversible_command ()
3175 // session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3176 session->commit_reversible_command ();
3181 Editor::set_edit_group_solo (Route& route, bool yn)
3183 RouteGroup *edit_group;
3185 if ((edit_group = route.edit_group()) != 0) {
3186 edit_group->apply (&Route::set_solo, yn, this);
3188 route.set_solo (yn, this);
3193 Editor::set_edit_group_mute (Route& route, bool yn)
3195 RouteGroup *edit_group = 0;
3197 if ((edit_group == route.edit_group()) != 0) {
3198 edit_group->apply (&Route::set_mute, yn, this);
3200 route.set_mute (yn, this);
3205 Editor::history_changed ()
3209 if (undo_action && session) {
3210 if (session->undo_depth() == 0) {
3213 label = string_compose(_("Undo (%1)"), session->next_undo());
3215 undo_action->property_label() = label;
3218 if (redo_action && session) {
3219 if (session->redo_depth() == 0) {
3222 label = string_compose(_("Redo (%1)"), session->next_redo());
3224 redo_action->property_label() = label;
3229 Editor::duplicate_dialog (bool with_dialog)
3233 if (mouse_mode == MouseRange) {
3234 if (selection->time.length() == 0) {
3240 get_regions_for_action (rs);
3242 if (mouse_mode != MouseRange) {
3251 ArdourDialog win ("Duplication Dialog");
3252 Label label (_("Number of Duplications:"));
3253 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3254 SpinButton spinner (adjustment, 0.0, 1);
3257 win.get_vbox()->set_spacing (12);
3258 win.get_vbox()->pack_start (hbox);
3259 hbox.set_border_width (6);
3260 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3262 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3263 place, visually. so do this by hand.
3266 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3267 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3268 spinner.grab_focus();
3274 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3275 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3276 win.set_default_response (RESPONSE_ACCEPT);
3278 win.set_position (WIN_POS_MOUSE);
3280 spinner.grab_focus ();
3282 switch (win.run ()) {
3283 case RESPONSE_ACCEPT:
3289 times = adjustment.get_value();
3292 if (mouse_mode == MouseRange) {
3293 duplicate_selection (times);
3295 duplicate_some_regions (rs, times);
3300 Editor::show_verbose_canvas_cursor ()
3302 verbose_canvas_cursor->raise_to_top();
3303 verbose_canvas_cursor->show();
3304 verbose_cursor_visible = true;
3308 Editor::hide_verbose_canvas_cursor ()
3310 verbose_canvas_cursor->hide();
3311 verbose_cursor_visible = false;
3315 Editor::clamp_verbose_cursor_x (double x)
3320 x = min (canvas_width - 200.0, x);
3326 Editor::clamp_verbose_cursor_y (double y)
3328 if (y < canvas_timebars_vsize) {
3329 y = canvas_timebars_vsize;
3331 y = min (canvas_height - 50, y);
3337 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3339 verbose_canvas_cursor->property_text() = txt.c_str();
3340 /* don't get too close to the edge */
3341 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3342 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3346 Editor::set_verbose_canvas_cursor_text (const string & txt)
3348 verbose_canvas_cursor->property_text() = txt.c_str();
3352 Editor::set_edit_mode (EditMode m)
3354 Config->set_edit_mode (m);
3358 Editor::cycle_edit_mode ()
3360 switch (Config->get_edit_mode()) {
3362 Config->set_edit_mode (Splice);
3365 Config->set_edit_mode (Lock);
3368 Config->set_edit_mode (Slide);
3374 Editor::edit_mode_selection_done ()
3380 string choice = edit_mode_selector.get_active_text();
3381 EditMode mode = Slide;
3383 if (choice == _("Splice Edit")) {
3385 } else if (choice == _("Slide Edit")) {
3387 } else if (choice == _("Lock Edit")) {
3391 Config->set_edit_mode (mode);
3395 Editor::snap_type_selection_done ()
3397 string choice = snap_type_selector.get_active_text();
3398 SnapType snaptype = SnapToBeat;
3400 if (choice == _("Beats/3")) {
3401 snaptype = SnapToAThirdBeat;
3402 } else if (choice == _("Beats/4")) {
3403 snaptype = SnapToAQuarterBeat;
3404 } else if (choice == _("Beats/8")) {
3405 snaptype = SnapToAEighthBeat;
3406 } else if (choice == _("Beats/16")) {
3407 snaptype = SnapToASixteenthBeat;
3408 } else if (choice == _("Beats/32")) {
3409 snaptype = SnapToAThirtysecondBeat;
3410 } else if (choice == _("Beats")) {
3411 snaptype = SnapToBeat;
3412 } else if (choice == _("Bars")) {
3413 snaptype = SnapToBar;
3414 } else if (choice == _("Marks")) {
3415 snaptype = SnapToMark;
3416 } else if (choice == _("Region starts")) {
3417 snaptype = SnapToRegionStart;
3418 } else if (choice == _("Region ends")) {
3419 snaptype = SnapToRegionEnd;
3420 } else if (choice == _("Region bounds")) {
3421 snaptype = SnapToRegionBoundary;
3422 } else if (choice == _("Region syncs")) {
3423 snaptype = SnapToRegionSync;
3424 } else if (choice == _("CD Frames")) {
3425 snaptype = SnapToCDFrame;
3426 } else if (choice == _("SMPTE Frames")) {
3427 snaptype = SnapToSMPTEFrame;
3428 } else if (choice == _("SMPTE Seconds")) {
3429 snaptype = SnapToSMPTESeconds;
3430 } else if (choice == _("SMPTE Minutes")) {
3431 snaptype = SnapToSMPTEMinutes;
3432 } else if (choice == _("Seconds")) {
3433 snaptype = SnapToSeconds;
3434 } else if (choice == _("Minutes")) {
3435 snaptype = SnapToMinutes;
3438 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3440 ract->set_active ();
3445 Editor::snap_mode_selection_done ()
3447 string choice = snap_mode_selector.get_active_text();
3448 SnapMode mode = SnapNormal;
3450 if (choice == _("No Grid")) {
3452 } else if (choice == _("Grid")) {
3454 } else if (choice == _("Magnetic")) {
3455 mode = SnapMagnetic;
3458 RefPtr<RadioAction> ract = snap_mode_action (mode);
3461 ract->set_active (true);
3466 Editor::cycle_edit_point (bool with_marker)
3468 switch (_edit_point) {
3470 set_edit_point_preference (EditAtPlayhead);
3472 case EditAtPlayhead:
3474 set_edit_point_preference (EditAtSelectedMarker);
3476 set_edit_point_preference (EditAtMouse);
3479 case EditAtSelectedMarker:
3480 set_edit_point_preference (EditAtMouse);
3486 Editor::edit_point_selection_done ()
3488 string choice = edit_point_selector.get_active_text();
3489 EditPoint ep = EditAtSelectedMarker;
3491 if (choice == _("Marker")) {
3492 set_edit_point_preference (EditAtSelectedMarker);
3493 } else if (choice == _("Playhead")) {
3494 set_edit_point_preference (EditAtPlayhead);
3496 set_edit_point_preference (EditAtMouse);
3499 RefPtr<RadioAction> ract = edit_point_action (ep);
3502 ract->set_active (true);
3507 Editor::zoom_focus_selection_done ()
3509 string choice = zoom_focus_selector.get_active_text();
3510 ZoomFocus focus_type = ZoomFocusLeft;
3512 if (choice == _("Left")) {
3513 focus_type = ZoomFocusLeft;
3514 } else if (choice == _("Right")) {
3515 focus_type = ZoomFocusRight;
3516 } else if (choice == _("Center")) {
3517 focus_type = ZoomFocusCenter;
3518 } else if (choice == _("Playhead")) {
3519 focus_type = ZoomFocusPlayhead;
3520 } else if (choice == _("Mouse")) {
3521 focus_type = ZoomFocusMouse;
3522 } else if (choice == _("Active Mark")) {
3523 focus_type = ZoomFocusEdit;
3526 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3529 ract->set_active ();
3534 Editor::edit_controls_button_release (GdkEventButton* ev)
3536 if (Keyboard::is_context_menu_event (ev)) {
3537 ARDOUR_UI::instance()->add_route (this);
3543 Editor::mouse_select_button_release (GdkEventButton* ev)
3545 /* this handles just right-clicks */
3547 if (ev->button != 3) {
3554 Editor::TrackViewList *
3555 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3558 TrackViewList::iterator i;
3560 v = new TrackViewList;
3562 if (track == 0 && group == 0) {
3566 for (i = track_views.begin(); i != track_views.end (); ++i) {
3570 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->is_active())) {
3572 /* just the view for this track
3575 v->push_back (track);
3579 /* views for all tracks in the edit group */
3581 for (i = track_views.begin(); i != track_views.end (); ++i) {
3583 if (group == 0 || (*i)->edit_group() == group) {
3593 Editor::set_zoom_focus (ZoomFocus f)
3595 string str = zoom_focus_strings[(int)f];
3597 if (str != zoom_focus_selector.get_active_text()) {
3598 zoom_focus_selector.set_active_text (str);
3601 if (zoom_focus != f) {
3604 ZoomFocusChanged (); /* EMIT_SIGNAL */
3611 Editor::ensure_float (Window& win)
3613 win.set_transient_for (*this);
3617 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3619 /* recover or initialize pane positions. do this here rather than earlier because
3620 we don't want the positions to change the child allocations, which they seem to do.
3626 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3628 static int32_t done;
3631 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3632 width = default_width;
3633 height = default_height;
3635 width = atoi(geometry->property("x_size")->value());
3636 height = atoi(geometry->property("y_size")->value());
3639 if (which == static_cast<Paned*> (&edit_pane)) {
3645 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3646 /* initial allocation is 90% to canvas, 10% to notebook */
3647 pos = (int) floor (alloc.get_width() * 0.90f);
3648 snprintf (buf, sizeof(buf), "%d", pos);
3650 pos = atoi (prop->value());
3653 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3654 edit_pane.set_position (pos);
3655 pre_maximal_pane_position = pos;
3661 Editor::detach_tearoff (Box* b, Window* w)
3663 if (tools_tearoff->torn_off() &&
3664 mouse_mode_tearoff->torn_off()) {
3665 top_hbox.remove (toolbar_frame);
3670 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3672 if (toolbar_frame.get_parent() == 0) {
3673 top_hbox.pack_end (toolbar_frame);
3678 Editor::set_show_measures (bool yn)
3680 if (_show_measures != yn) {
3683 if ((_show_measures = yn) == true) {
3691 Editor::toggle_follow_playhead ()
3693 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3695 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3696 set_follow_playhead (tact->get_active());
3701 Editor::set_follow_playhead (bool yn)
3703 if (_follow_playhead != yn) {
3704 if ((_follow_playhead = yn) == true) {
3706 update_current_screen ();
3713 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3715 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3717 xfade->set_active (!xfade->active());
3722 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3724 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3726 xfade->set_follow_overlap (!xfade->following_overlap());
3731 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3733 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3739 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3743 switch (cew.run ()) {
3744 case RESPONSE_ACCEPT:
3751 xfade->StateChanged (Change (~0));
3755 Editor::playlist_selector () const
3757 return *_playlist_selector;
3761 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3765 ret = nudge_clock.current_duration (pos);
3766 next = ret + 1; /* XXXX fix me */
3772 Editor::end_location_changed (Location* location)
3774 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3775 //reset_scrolling_region ();
3776 horizontal_adjustment.set_upper ( location->start());
3780 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3782 ArdourDialog dialog ("playlist deletion dialog");
3783 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3784 "If left alone, no audio files used by it will be cleaned.\n"
3785 "If deleted, audio files used by it alone by will cleaned."),
3788 dialog.set_position (WIN_POS_CENTER);
3789 dialog.get_vbox()->pack_start (label);
3793 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3794 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3795 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3797 switch (dialog.run ()) {
3798 case RESPONSE_ACCEPT:
3799 /* delete the playlist */
3803 case RESPONSE_REJECT:
3804 /* keep the playlist */
3816 Editor::audio_region_selection_covers (nframes64_t where)
3818 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3819 if ((*a)->region()->covers (where)) {
3828 Editor::prepare_for_cleanup ()
3830 cut_buffer->clear_regions ();
3831 cut_buffer->clear_playlists ();
3833 selection->clear_regions ();
3834 selection->clear_playlists ();
3836 no_region_list_redisplay = true;
3840 Editor::finish_cleanup ()
3842 no_region_list_redisplay = false;
3843 redisplay_regions ();
3847 Editor::transport_loop_location()
3850 return session->locations()->auto_loop_location();
3857 Editor::transport_punch_location()
3860 return session->locations()->auto_punch_location();
3867 Editor::control_layout_scroll (GdkEventScroll* ev)
3869 switch (ev->direction) {
3871 scroll_tracks_up_line ();
3875 case GDK_SCROLL_DOWN:
3876 scroll_tracks_down_line ();
3880 /* no left/right handling yet */
3888 /** A new snapshot has been selected.
3891 Editor::snapshot_display_selection_changed ()
3893 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
3895 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
3897 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
3899 if (snap_name.length() == 0) {
3903 if (session->snap_name() == snap_name) {
3907 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
3912 Editor::snapshot_display_button_press (GdkEventButton* ev)
3914 if (ev->button == 3) {
3915 /* Right-click on the snapshot list. Work out which snapshot it
3917 Gtk::TreeModel::Path path;
3918 Gtk::TreeViewColumn* col;
3921 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
3922 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
3924 Gtk::TreeModel::Row row = *iter;
3925 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
3934 /** Pop up the snapshot display context menu.
3935 * @param button Button used to open the menu.
3936 * @param time Menu open time.
3937 * @snapshot_name Name of the snapshot that the menu click was over.
3941 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
3943 using namespace Menu_Helpers;
3945 MenuList& items (snapshot_context_menu.items());
3948 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
3950 items.push_back (MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)));
3951 if (!modification_allowed) {
3952 items.back().set_sensitive (false);
3955 items.push_back (MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)));
3956 if (!modification_allowed) {
3957 items.back().set_sensitive (false);
3960 snapshot_context_menu.popup (button, time);
3964 Editor::rename_snapshot (Glib::ustring old_name)
3966 ArdourPrompter prompter(true);
3970 prompter.set_name ("Prompter");
3971 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
3972 prompter.set_prompt (_("New name of snapshot"));
3973 prompter.set_initial_text (old_name);
3975 if (prompter.run() == RESPONSE_ACCEPT) {
3976 prompter.get_result (new_name);
3977 if (new_name.length()) {
3978 session->rename_state (old_name, new_name);
3979 redisplay_snapshots ();
3986 Editor::remove_snapshot (Glib::ustring name)
3988 vector<string> choices;
3990 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
3992 choices.push_back (_("No, do nothing."));
3993 choices.push_back (_("Yes, remove it."));
3995 Gtkmm2ext::Choice prompter (prompt, choices);
3997 if (prompter.run () == 1) {
3998 session->remove_state (name);
3999 redisplay_snapshots ();
4004 Editor::redisplay_snapshots ()
4010 vector<string*>* states;
4012 if ((states = session->possible_states()) == 0) {
4016 snapshot_display_model->clear ();
4018 for (vector<string*>::iterator i = states->begin(); i != states->end(); ++i) {
4019 string statename = *(*i);
4020 TreeModel::Row row = *(snapshot_display_model->append());
4022 /* this lingers on in case we ever want to change the visible
4023 name of the snapshot.
4026 string display_name;
4027 display_name = statename;
4029 if (statename == session->snap_name()) {
4030 snapshot_display.get_selection()->select(row);
4033 row[snapshot_display_columns.visible_name] = display_name;
4034 row[snapshot_display_columns.real_name] = statename;
4041 Editor::session_state_saved (string snap_name)
4043 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4044 redisplay_snapshots ();
4048 Editor::maximise_editing_space ()
4050 initial_ruler_update_required = true;
4052 mouse_mode_tearoff->set_visible (false);
4053 tools_tearoff->set_visible (false);
4055 pre_maximal_pane_position = edit_pane.get_position();
4056 pre_maximal_editor_width = this->get_width();
4058 if(post_maximal_pane_position == 0) {
4059 post_maximal_pane_position = edit_pane.get_width();
4064 if(post_maximal_editor_width) {
4065 edit_pane.set_position (post_maximal_pane_position -
4066 abs(post_maximal_editor_width - pre_maximal_editor_width));
4068 edit_pane.set_position (post_maximal_pane_position);
4073 Editor::restore_editing_space ()
4075 initial_ruler_update_required = true;
4077 // user changed width of pane during fullscreen
4078 if(post_maximal_pane_position != edit_pane.get_position()) {
4079 post_maximal_pane_position = edit_pane.get_position();
4084 mouse_mode_tearoff->set_visible (true);
4085 tools_tearoff->set_visible (true);
4086 post_maximal_editor_width = this->get_width();
4089 edit_pane.set_position (
4090 pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width)
4095 * Make new playlists for a given track and also any others that belong
4096 * to the same active edit group.
4101 Editor::new_playlists (TimeAxisView* v)
4103 begin_reversible_command (_("new playlists"));
4104 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
4105 commit_reversible_command ();
4110 * Use a copy of the current playlist for a given track and also any others that belong
4111 * to the same active edit group.
4116 Editor::copy_playlists (TimeAxisView* v)
4118 begin_reversible_command (_("copy playlists"));
4119 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
4120 commit_reversible_command ();
4125 * Clear the current playlist for a given track and also any others that belong
4126 * to the same active edit group.
4131 Editor::clear_playlists (TimeAxisView* v)
4133 begin_reversible_command (_("clear playlists"));
4134 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
4135 commit_reversible_command ();
4139 Editor::mapped_use_new_playlist (AudioTimeAxisView& atv, uint32_t sz)
4141 atv.use_new_playlist (sz > 1 ? false : true);
4145 Editor::mapped_use_copy_playlist (AudioTimeAxisView& atv, uint32_t sz)
4147 atv.use_copy_playlist (sz > 1 ? false : true);
4151 Editor::mapped_clear_playlist (AudioTimeAxisView& atv, uint32_t sz)
4153 atv.clear_playlist ();
4157 Editor::on_key_press_event (GdkEventKey* ev)
4159 return key_press_focus_accelerator_handler (*this, ev);
4163 Editor::on_key_release_event (GdkEventKey* ev)
4165 return Gtk::Window::on_key_release_event (ev);
4166 // return key_press_focus_accelerator_handler (*this, ev);
4170 Editor::reset_x_origin (nframes64_t frame)
4172 //cerr << "resetting x origin" << endl;
4173 queue_visual_change (frame);
4177 Editor::reset_zoom (double fpu)
4179 queue_visual_change (fpu);
4183 Editor::reposition_and_zoom (nframes64_t frame, double fpu)
4185 //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
4186 reset_x_origin (frame);
4189 if (!no_save_visual) {
4190 undo_visual_stack.push_back (current_visual_state(false));
4194 Editor::VisualState*
4195 Editor::current_visual_state (bool with_tracks)
4197 VisualState* vs = new VisualState;
4198 vs->y_position = vertical_adjustment.get_value();
4199 vs->frames_per_unit = frames_per_unit;
4200 vs->leftmost_frame = leftmost_frame;
4201 vs->zoom_focus = zoom_focus;
4202 vs->zoomed_to_region = zoomed_to_region;
4205 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4206 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4214 Editor::undo_visual_state ()
4216 if (undo_visual_stack.empty()) {
4220 VisualState* vs = undo_visual_stack.back();
4221 undo_visual_stack.pop_back();
4222 use_visual_state (*vs);
4223 redo_visual_stack.push_back (vs);
4227 Editor::redo_visual_state ()
4229 if (redo_visual_stack.empty()) {
4233 VisualState* vs = redo_visual_stack.back();
4234 redo_visual_stack.pop_back();
4235 use_visual_state (*vs);
4236 undo_visual_stack.push_back (vs);
4240 Editor::swap_visual_state ()
4242 if (undo_visual_stack.empty()) {
4243 redo_visual_state ();
4245 undo_visual_state ();
4250 Editor::use_visual_state (VisualState& vs)
4252 no_save_visual = true;
4254 vertical_adjustment.set_value (vs.y_position);
4256 set_zoom_focus (vs.zoom_focus);
4257 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4259 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4260 TrackViewList::iterator t;
4262 /* check if the track still exists - it could have been deleted */
4264 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4265 (*t)->set_state (*(i->second));
4269 if (!vs.track_states.empty()) {
4270 update_route_visibility ();
4273 no_save_visual = false;
4277 Editor::set_frames_per_unit (double fpu)
4279 /* this is the core function that controls the zoom level of the canvas. it is called
4280 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4283 if (fpu == frames_per_unit) {
4292 /* don't allow zooms that fit more than the maximum number
4293 of frames into an 800 pixel wide space.
4296 if (max_frames / fpu < 800.0) {
4300 frames_per_unit = fpu;
4305 Editor::post_zoom ()
4307 // convert fpu to frame count
4309 nframes64_t frames = (nframes64_t) floor (frames_per_unit * canvas_width);
4311 if (frames_per_unit != zoom_range_clock.current_duration()) {
4312 zoom_range_clock.set (frames);
4315 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4316 if (!selection->tracks.empty()) {
4317 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4318 (*i)->reshow_selection (selection->time);
4321 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4322 (*i)->reshow_selection (selection->time);
4327 ZoomChanged (); /* EMIT_SIGNAL */
4329 reset_hscrollbar_stepping ();
4330 //reset_scrolling_region ();
4332 if (playhead_cursor) {
4333 playhead_cursor->set_position (playhead_cursor->current_frame);
4340 Editor::queue_visual_change (nframes64_t where)
4342 // pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4343 // pending_visual_change.time_origin = where;
4345 if (pending_visual_change.idle_handler_id < 0) {
4346 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4347 pending_visual_change.time_origin = where;
4348 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4353 Editor::queue_visual_change (double fpu)
4355 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4356 pending_visual_change.frames_per_unit = fpu;
4358 if (pending_visual_change.idle_handler_id < 0) {
4359 pending_visual_change.idle_handler_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, _idle_visual_changer, this, 0);
4364 Editor::_idle_visual_changer (void* arg)
4366 return static_cast<Editor*>(arg)->idle_visual_changer ();
4370 Editor::idle_visual_changer ()
4372 VisualChange::Type p = pending_visual_change.pending;
4373 pending_visual_change.pending = (VisualChange::Type) 0;
4376 if (p & VisualChange::ZoomLevel) {
4377 set_frames_per_unit (pending_visual_change.frames_per_unit);
4380 if (p & VisualChange::TimeOrigin) {
4382 nframes64_t csf, cef;
4383 nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4386 csf = session->current_start_frame();
4387 cef = session->current_end_frame() + (current_page_frames() / 24);// Add a little extra so we can see the end marker
4390 /* if we seek beyond the current end of the canvas, move the end */
4392 if (current_time_origin != pending_visual_change.time_origin) {
4393 //if (horizontal_adjustment.get_upper() < pending_visual_change.time_origin) {
4394 last_canvas_frame = (cef > (pending_visual_change.time_origin + current_page_frames())) ? cef : pending_visual_change.time_origin + current_page_frames();
4395 horizontal_adjustment.set_upper ((cef - csf) / frames_per_unit);
4397 horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
4399 update_fixed_rulers();
4400 redisplay_tempo (true);
4404 //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
4405 pending_visual_change.idle_handler_id = -1;
4406 return 0; /* this is always a one-shot call */
4409 struct EditorOrderTimeAxisSorter {
4410 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4411 return a->order < b->order;
4416 Editor::sort_track_selection (TrackSelection* sel)
4418 EditorOrderTimeAxisSorter cmp;
4423 selection->tracks.sort (cmp);
4428 Editor::get_preferred_edit_position (bool ignore_playhead)
4431 nframes64_t where = 0;
4432 EditPoint ep = _edit_point;
4434 if (entered_marker) {
4435 return entered_marker->position();
4438 if (ignore_playhead && ep == EditAtPlayhead) {
4439 ep = EditAtSelectedMarker;
4443 case EditAtPlayhead:
4444 where = session->audible_frame();
4447 case EditAtSelectedMarker:
4448 if (!selection->markers.empty()) {
4450 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4453 where = loc->start();
4464 if (!mouse_frame (where, ignored)) {
4465 /* XXX not right but what can we do ? */
4476 Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
4478 if (!session) return;
4480 begin_reversible_command (cmd);
4484 if ((tll = transport_loop_location()) == 0) {
4485 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4486 XMLNode &before = session->locations()->get_state();
4487 session->locations()->add (loc, true);
4488 session->set_auto_loop_location (loc);
4489 XMLNode &after = session->locations()->get_state();
4490 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4492 XMLNode &before = tll->get_state();
4493 tll->set_hidden (false, this);
4494 tll->set (start, end);
4495 XMLNode &after = tll->get_state();
4496 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4499 commit_reversible_command ();
4503 Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
4505 if (!session) return;
4507 begin_reversible_command (cmd);
4511 if ((tpl = transport_punch_location()) == 0) {
4512 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4513 XMLNode &before = session->locations()->get_state();
4514 session->locations()->add (loc, true);
4515 session->set_auto_loop_location (loc);
4516 XMLNode &after = session->locations()->get_state();
4517 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4520 XMLNode &before = tpl->get_state();
4521 tpl->set_hidden (false, this);
4522 tpl->set (start, end);
4523 XMLNode &after = tpl->get_state();
4524 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4527 commit_reversible_command ();
4531 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4533 const TrackSelection* tracks;
4536 tracks = &track_views;
4541 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4543 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4546 boost::shared_ptr<Diskstream> ds;
4547 boost::shared_ptr<Playlist> pl;
4549 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4551 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)where * ds->speed()));
4553 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4555 RegionView* rv = atv->audio_view()->find_view (*i);
4569 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4571 const TrackSelection* tracks;
4574 tracks = &track_views;
4579 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4581 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4584 boost::shared_ptr<Diskstream> ds;
4585 boost::shared_ptr<Playlist> pl;
4587 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4589 Playlist::RegionList* regions = pl->regions_touched ((nframes64_t) floor ( (double)where * ds->speed()), max_frames);
4591 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4593 RegionView* rv = atv->audio_view()->find_view (*i);
4607 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4609 if (selection->regions.empty()) {
4611 if (selection->tracks.empty()) {
4613 /* no regions or tracks selected
4616 if (entered_regionview && mouse_mode == Editing::MouseObject) {
4618 /* entered regionview is valid and we're in object mode -
4619 just use entered regionview
4622 rs.add (entered_regionview);
4629 /* no regions selected, so get all regions at the edit point across
4630 all selected tracks.
4633 nframes64_t where = get_preferred_edit_position();
4634 get_regions_at (rs, where, selection->tracks);
4636 /* if the entered regionview wasn't selected and neither was its track
4640 if (entered_regionview != 0 &&
4641 !selection->selected (entered_regionview) &&
4642 !selection->selected (&entered_regionview->get_time_axis_view())) {
4643 rs.add (entered_regionview);
4649 /* just use the selected regions */
4651 rs = selection->regions;
4653 /* if the entered regionview wasn't selected and we allow this sort of thing,
4657 if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
4658 rs.add (entered_regionview);
4665 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4668 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4670 RouteTimeAxisView* tatv;
4672 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4674 boost::shared_ptr<Playlist> pl;
4675 vector<boost::shared_ptr<Region> > results;
4677 boost::shared_ptr<Diskstream> ds;
4679 if ((ds = tatv->get_diskstream()) == 0) {
4684 if ((pl = (ds->playlist())) != 0) {
4685 pl->get_region_list_equivalent_regions (region, results);
4688 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4689 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4690 regions.push_back (marv);
4699 Editor::show_rhythm_ferret ()
4701 if (rhythm_ferret == 0) {
4702 rhythm_ferret = new RhythmFerret(*this);
4705 rhythm_ferret->set_session (session);
4706 rhythm_ferret->show ();
4707 rhythm_ferret->present ();
4711 Editor::first_idle ()
4713 MessageDialog* dialog = 0;
4715 if (track_views.size() > 1) {
4716 dialog = new MessageDialog (*this,
4717 _("Please wait while Ardour loads visual data"),
4722 ARDOUR_UI::instance()->flush_pending ();
4725 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
4737 Editor::start_resize_line_ops ()
4740 old_resize_line_y = -1;
4742 need_resize_line = true;
4747 Editor::end_resize_line_ops ()
4750 need_resize_line = false;
4752 if (old_resize_line_y >= 0) {
4753 Gdk::Rectangle r (0, old_resize_line_y, (int) canvas_width, 3);
4754 Glib::RefPtr<Gdk::Window> win = get_window();
4755 cerr << "Final invalidation at " << old_resize_line_y << endl;
4756 win->invalidate_rect (r, false);
4762 Editor::queue_draw_resize_line (int at)
4765 Glib::RefPtr<Gdk::Window> win = get_window();
4769 if (win && canvas_width) {
4771 int controls_width = controls_layout.get_width();
4774 controls_layout.get_window()->get_origin (xroot, discard);
4776 if (old_resize_line_y >= 0) {
4778 /* redraw where it used to be */
4781 Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) canvas_width, 3);
4782 win->invalidate_rect (r, true);
4783 cerr << "invalidate " << xroot << "," << old_resize_line_y - 1 << ' '
4784 << controls_width + canvas_width << " x 3\n";
4787 /* draw where it is */
4789 Gdk::Rectangle r (0, at - 1, controls_width + (int) canvas_width, 3);
4790 win->invalidate_rect (r, true);
4796 Editor::on_expose_event (GdkEventExpose* ev)
4798 /* cerr << "+++ editor expose "
4799 << ev->area.x << ',' << ev->area.y
4801 << ev->area.width << " x " << ev->area.height
4802 << " need reize ? " << need_resize_line
4805 bool ret = Window::on_expose_event (ev);
4808 if (need_resize_line) {
4810 int xroot, yroot, discard;
4813 /* Our root coordinates for drawing the line will be the left edge
4814 of the track controls, and the upper left edge of our own window.
4817 get_window()->get_origin (discard, yroot);
4818 controls_layout.get_window()->get_origin (xroot, discard);
4819 controls_width = controls_layout.get_width();
4822 GdkRectangle intersection;
4825 lr.y = resize_line_y;
4826 lr.width = controls_width + (int) canvas_width;
4829 if (gdk_rectangle_intersect (&lr, &ev->area, &intersection)) {
4831 Glib::RefPtr<Gtk::Style> style (get_style());
4832 Glib::RefPtr<Gdk::GC> black_gc (style->get_black_gc ());
4833 Glib::RefPtr<Gdk::GC> gc = wrap (black_gc->gobj_copy(), false);
4835 /* draw on root window */
4837 GdkWindow* win = gdk_get_default_root_window();
4839 gc->set_subwindow (Gdk::INCLUDE_INFERIORS);
4840 gc->set_line_attributes (3, Gdk::LINE_SOLID,
4844 gdk_draw_line (win, gc->gobj(),
4847 (int) canvas_width + controls_width,
4850 cerr << "drew line @ " << xroot << ", " << yroot + resize_line_y
4851 << " to " << xroot + (int) canvas_width + controls_width
4852 << ", " << yroot + resize_line_y
4855 old_resize_line_y = resize_line_y;
4856 cerr << "NEXT EXPOSE SHOULD BE AT " << old_resize_line_y << endl;
4858 cerr << "no intersect with "
4859 << lr.x << ',' << lr.y
4861 << lr.width << " x " << lr.height
4866 //cerr << "--- editor expose\n";
4873 _idle_resizer (gpointer arg)
4875 return ((Editor*)arg)->idle_resize ();
4879 Editor::add_to_idle_resize (TimeAxisView* view, uint32_t h)
4881 if (resize_idle_id < 0) {
4882 resize_idle_id = g_idle_add (_idle_resizer, this);
4885 resize_idle_target = h;
4887 pending_resizes.push_back (view);
4889 if (selection->selected (view) && !selection->tracks.empty()) {
4890 pending_resizes.insert (pending_resizes.end(), selection->tracks.begin(), selection->tracks.end());
4895 Editor::idle_resize ()
4897 for (vector<TimeAxisView*>::iterator i = pending_resizes.begin(); i != pending_resizes.end(); ++i) {
4898 (*i)->idle_resize (resize_idle_target);
4900 pending_resizes.clear();
4901 resize_idle_id = -1;