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;
190 DragInfo::clear_copied_locations ()
192 for (list<Location*>::iterator i = copied_locations.begin(); i != copied_locations.end(); ++i) {
195 copied_locations.clear ();
200 /* time display buttons */
201 minsec_label (_("Mins:Secs")),
202 bbt_label (_("Bars:Beats")),
203 smpte_label (_("Timecode")),
204 frame_label (_("Samples")),
205 tempo_label (_("Tempo")),
206 meter_label (_("Meter")),
207 mark_label (_("Location Markers")),
208 range_mark_label (_("Range Markers")),
209 transport_mark_label (_("Loop/Punch Ranges")),
210 cd_mark_label (_("CD Markers")),
211 edit_packer (3, 4, true),
213 /* the values here don't matter: layout widgets
214 reset them as needed.
217 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
218 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
220 /* tool bar related */
222 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
223 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
225 toolbar_selection_clock_table (2,3),
227 automation_mode_button (_("mode")),
228 global_automation_button (_("automation")),
230 /* <CMT Additions> */
231 image_socket_listener(0),
232 /* </CMT Additions> */
236 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
237 meters_running(false)
242 /* we are a singleton */
244 PublicEditor::_instance = this;
249 selection = new Selection;
250 cut_buffer = new Selection;
252 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
253 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
254 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
255 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
256 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
258 clicked_regionview = 0;
259 clicked_trackview = 0;
260 clicked_audio_trackview = 0;
261 clicked_crossfadeview = 0;
262 clicked_control_point = 0;
263 last_update_frame = 0;
265 current_mixer_strip = 0;
266 current_bbt_points = 0;
268 snap_type_strings = I18N (_snap_type_strings);
269 snap_mode_strings = I18N (_snap_mode_strings);
270 zoom_focus_strings = I18N (_zoom_focus_strings);
271 edit_point_strings = I18N (_edit_point_strings);
272 #ifdef USE_RUBBERBAND
273 rb_opt_strings = I18N (_rb_opt_strings);
276 snap_threshold = 5.0;
277 bbt_beat_subdivision = 4;
280 last_autoscroll_x = 0;
281 last_autoscroll_y = 0;
282 autoscroll_active = false;
283 autoscroll_timeout_tag = -1;
284 interthread_progress_window = 0;
291 current_interthread_info = 0;
292 _show_measures = true;
293 _show_waveforms = true;
294 _show_waveforms_recording = true;
295 first_action_message = 0;
297 export_range_markers_dialog = 0;
298 show_gain_after_trim = false;
299 ignore_route_list_reorder = false;
300 no_route_list_redisplay = false;
301 verbose_cursor_on = true;
302 route_removal = false;
303 show_automatic_regions_in_region_list = true;
304 last_item_entered = 0;
305 last_item_entered_n = 0;
307 region_list_sort_type = (Editing::RegionListSortType) 0;
308 have_pending_keyboard_selection = false;
309 _follow_playhead = true;
310 _xfade_visibility = true;
311 editor_ruler_menu = 0;
312 no_ruler_shown_update = false;
313 edit_group_list_menu = 0;
315 region_list_menu = 0;
317 start_end_marker_menu = 0;
318 range_marker_menu = 0;
319 marker_menu_item = 0;
321 transport_marker_menu = 0;
322 new_transport_marker_menu = 0;
323 editor_mixer_strip_width = Wide;
324 show_editor_mixer_when_tracks_arrive = false;
325 region_edit_menu_split_item = 0;
327 region_edit_menu_split_multichannel_item = 0;
329 ignore_mouse_mode_toggle = false;
330 current_stepping_trackview = 0;
332 entered_regionview = 0;
334 clear_entered_track = false;
335 _new_regionviews_show_envelope = false;
337 in_edit_group_row_change = false;
338 last_canvas_frame = 0;
340 button_release_can_deselect = true;
341 _dragging_playhead = false;
342 _dragging_edit_point = false;
343 _dragging_hscrollbar = false;
344 select_new_marker = false;
345 zoomed_to_region = false;
347 allow_vertical_scroll = false;
348 no_save_visual = false;
349 need_resize_line = false;
351 old_resize_line_y = -1;
352 no_region_list_redisplay = false;
356 scrubbing_direction = 0;
359 ignore_route_order_sync = false;
361 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
362 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
363 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
364 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
365 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
367 range_marker_drag_rect = 0;
368 marker_drag_line = 0;
370 set_mouse_mode (MouseObject, true);
372 frames_per_unit = 2048; /* too early to use reset_zoom () */
373 reset_hscrollbar_stepping ();
375 zoom_focus = ZoomFocusLeft;
376 set_zoom_focus (ZoomFocusLeft);
377 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
379 initialize_rulers ();
380 initialize_canvas ();
382 edit_controls_vbox.set_spacing (0);
383 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
384 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
385 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
387 controls_layout.add (edit_controls_vbox);
388 controls_layout.set_name ("EditControlsBase");
389 controls_layout.add_events (Gdk::SCROLL_MASK);
390 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
392 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
393 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
394 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
396 edit_vscrollbar.set_adjustment (vertical_adjustment);
397 edit_hscrollbar.set_adjustment (horizontal_adjustment);
399 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
400 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
401 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
403 edit_hscrollbar.set_name ("EditorHScrollbar");
408 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
410 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
411 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
412 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
413 time_canvas_vbox.pack_start (*frames_ruler, false, false);
414 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
415 //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
416 time_canvas_vbox.set_size_request (-1, -1);
417 bbt_label.set_name ("EditorTimeButton");
418 bbt_label.set_size_request (-1, (int)timebar_height);
419 bbt_label.set_alignment (1.0, 0.5);
420 bbt_label.set_padding (5,0);
421 minsec_label.set_name ("EditorTimeButton");
422 minsec_label.set_size_request (-1, (int)timebar_height);
423 minsec_label.set_alignment (1.0, 0.5);
424 minsec_label.set_padding (5,0);
425 smpte_label.set_name ("EditorTimeButton");
426 smpte_label.set_size_request (-1, (int)timebar_height);
427 smpte_label.set_alignment (1.0, 0.5);
428 smpte_label.set_padding (5,0);
429 frame_label.set_name ("EditorTimeButton");
430 frame_label.set_size_request (-1, (int)timebar_height);
431 frame_label.set_alignment (1.0, 0.5);
432 frame_label.set_padding (5,0);
434 tempo_label.set_name ("EditorTimeButton");
435 tempo_label.set_size_request (-1, (int)timebar_height);
436 tempo_label.set_alignment (1.0, 0.5);
437 tempo_label.set_padding (5,0);
438 meter_label.set_name ("EditorTimeButton");
439 meter_label.set_size_request (-1, (int)timebar_height);
440 meter_label.set_alignment (1.0, 0.5);
441 meter_label.set_padding (5,0);
442 mark_label.set_name ("EditorTimeButton");
443 mark_label.set_size_request (-1, (int)timebar_height);
444 mark_label.set_alignment (1.0, 0.5);
445 mark_label.set_padding (5,0);
446 cd_mark_label.set_name ("EditorTimeButton");
447 cd_mark_label.set_size_request (-1, (int)timebar_height);
448 cd_mark_label.set_alignment (1.0, 0.5);
449 cd_mark_label.set_padding (5,0);
450 range_mark_label.set_name ("EditorTimeButton");
451 range_mark_label.set_size_request (-1, (int)timebar_height);
452 range_mark_label.set_alignment (1.0, 0.5);
453 range_mark_label.set_padding (5,0);
454 transport_mark_label.set_name ("EditorTimeButton");
455 transport_mark_label.set_size_request (-1, (int)timebar_height);
456 transport_mark_label.set_alignment (1.0, 0.5);
457 transport_mark_label.set_padding (5,0);
459 ruler_label_vbox.pack_start (minsec_label, false, false);
460 ruler_label_vbox.pack_start (smpte_label, false, false);
461 ruler_label_vbox.pack_start (frame_label, false, false);
462 ruler_label_vbox.pack_start (bbt_label, false, false);
464 ruler_label_event_box.add (ruler_label_vbox);
465 ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
466 ruler_label_event_box.set_name ("TimebarLabelBase");
467 ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
469 time_button_vbox.pack_start (meter_label, false, false);
470 time_button_vbox.pack_start (tempo_label, false, false);
471 time_button_vbox.pack_start (mark_label, false, false);
473 time_button_event_box.add (time_button_vbox);
475 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
476 time_button_event_box.set_name ("TimebarLabelBase");
477 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
479 /* these enable us to have a dedicated window (for cursor setting, etc.)
480 for the canvas areas.
483 track_canvas_event_box.add (*track_canvas);
485 time_canvas_event_box.add (time_canvas_vbox);
486 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
488 edit_packer.set_col_spacings (0);
489 edit_packer.set_row_spacings (0);
490 edit_packer.set_homogeneous (false);
491 edit_packer.set_border_width (0);
492 edit_packer.set_name ("EditorWindow");
494 edit_packer.attach (edit_vscrollbar, 0, 1, 0, 4, FILL, FILL|EXPAND, 0, 0);
496 edit_packer.attach (ruler_label_event_box, 1, 2, 0, 1, FILL, SHRINK, 0, 0);
497 edit_packer.attach (time_button_event_box, 1, 2, 1, 2, FILL, SHRINK, 0, 0);
498 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
500 edit_packer.attach (controls_layout, 1, 2, 2, 3, FILL, FILL|EXPAND, 0, 0);
501 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 3, FILL|EXPAND, FILL|EXPAND, 0, 0);
503 edit_packer.attach (zoom_box, 1, 2, 3, 4, FILL, FILL, 0, 0);
504 edit_packer.attach (edit_hscrollbar, 2, 3, 3, 4, FILL|EXPAND, FILL, 0, 0);
506 bottom_hbox.set_border_width (2);
507 bottom_hbox.set_spacing (3);
509 route_display_model = ListStore::create(route_display_columns);
510 route_list_display.set_model (route_display_model);
511 route_list_display.append_column (_("Show"), route_display_columns.visible);
512 route_list_display.append_column (_("Name"), route_display_columns.text);
513 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
514 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
515 route_list_display.set_headers_visible (true);
516 route_list_display.set_name ("TrackListDisplay");
517 route_list_display.get_selection()->set_mode (SELECTION_NONE);
518 route_list_display.set_reorderable (true);
519 route_list_display.set_size_request (100,-1);
521 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
522 route_list_visible_cell->property_activatable() = true;
523 route_list_visible_cell->property_radio() = false;
525 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
526 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
527 route_display_model->signal_rows_reordered().connect (mem_fun (*this, &Editor::track_list_reorder));
529 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
531 route_list_scroller.add (route_list_display);
532 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
534 group_model = ListStore::create(group_columns);
535 edit_group_display.set_model (group_model);
536 edit_group_display.append_column (_("Name"), group_columns.text);
537 edit_group_display.append_column (_("Active"), group_columns.is_active);
538 edit_group_display.append_column (_("Show"), group_columns.is_visible);
539 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
540 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
541 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
542 edit_group_display.get_column (0)->set_expand (true);
543 edit_group_display.get_column (1)->set_expand (false);
544 edit_group_display.get_column (2)->set_expand (false);
545 edit_group_display.set_headers_visible (true);
547 /* name is directly editable */
549 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
550 name_cell->property_editable() = true;
551 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
553 /* use checkbox for the active + visible columns */
555 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
556 active_cell->property_activatable() = true;
557 active_cell->property_radio() = false;
559 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
560 active_cell->property_activatable() = true;
561 active_cell->property_radio() = false;
563 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
565 edit_group_display.set_name ("EditGroupList");
566 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
567 edit_group_display.set_headers_visible (true);
568 edit_group_display.set_reorderable (false);
569 edit_group_display.set_rules_hint (true);
570 edit_group_display.set_size_request (75, -1);
572 edit_group_display_scroller.add (edit_group_display);
573 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
575 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
577 VBox* edit_group_display_packer = manage (new VBox());
578 HBox* edit_group_display_button_box = manage (new HBox());
579 edit_group_display_button_box->set_homogeneous (true);
581 Button* edit_group_add_button = manage (new Button ());
582 Button* edit_group_remove_button = manage (new Button ());
586 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
588 edit_group_add_button->add (*w);
590 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
592 edit_group_remove_button->add (*w);
594 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
595 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
597 edit_group_display_button_box->pack_start (*edit_group_add_button);
598 edit_group_display_button_box->pack_start (*edit_group_remove_button);
600 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
601 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
603 region_list_display.set_size_request (100, -1);
604 region_list_display.set_name ("RegionListDisplay");
605 /* Try to prevent single mouse presses from initiating edits.
606 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
608 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
610 region_list_model = TreeStore::create (region_list_columns);
611 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
612 region_list_model->set_sort_column (0, SORT_ASCENDING);
614 region_list_display.set_model (region_list_model);
615 region_list_display.append_column (_("Regions"), region_list_columns.name);
616 region_list_display.set_headers_visible (false);
618 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
619 region_name_cell->property_editable() = true;
620 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
622 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
624 TreeViewColumn* tv_col = region_list_display.get_column(0);
625 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
626 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
627 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
629 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
630 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
632 /* setup DnD handling */
634 list<TargetEntry> region_list_target_table;
636 region_list_target_table.push_back (TargetEntry ("text/plain"));
637 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
638 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
640 region_list_display.add_drop_targets (region_list_target_table);
641 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
643 region_list_scroller.add (region_list_display);
644 region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
646 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
647 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
648 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
649 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
650 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
651 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
653 named_selection_scroller.add (named_selection_display);
654 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
656 named_selection_model = TreeStore::create (named_selection_columns);
657 named_selection_display.set_model (named_selection_model);
658 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
659 named_selection_display.set_headers_visible (false);
660 named_selection_display.set_size_request (100, -1);
661 named_selection_display.set_name ("NamedSelectionDisplay");
663 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
664 named_selection_display.set_size_request (100, -1);
665 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
666 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
667 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
671 snapshot_display_model = ListStore::create (snapshot_display_columns);
672 snapshot_display.set_model (snapshot_display_model);
673 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
674 snapshot_display.set_name ("SnapshotDisplay");
675 snapshot_display.set_size_request (75, -1);
676 snapshot_display.set_headers_visible (false);
677 snapshot_display.set_reorderable (false);
678 snapshot_display_scroller.add (snapshot_display);
679 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
681 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
682 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
686 nlabel = manage (new Label (_("Regions")));
687 nlabel->set_angle (-90);
688 the_notebook.append_page (region_list_scroller, *nlabel);
689 nlabel = manage (new Label (_("Tracks/Busses")));
690 nlabel->set_angle (-90);
691 the_notebook.append_page (route_list_scroller, *nlabel);
692 nlabel = manage (new Label (_("Snapshots")));
693 nlabel->set_angle (-90);
694 the_notebook.append_page (snapshot_display_scroller, *nlabel);
695 nlabel = manage (new Label (_("Edit Groups")));
696 nlabel->set_angle (-90);
697 the_notebook.append_page (*edit_group_display_packer, *nlabel);
699 if (!Profile->get_sae()) {
700 nlabel = manage (new Label (_("Chunks")));
701 nlabel->set_angle (-90);
702 the_notebook.append_page (named_selection_scroller, *nlabel);
705 the_notebook.set_show_tabs (true);
706 the_notebook.set_scrollable (true);
707 the_notebook.popup_enable ();
708 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
710 post_maximal_editor_width = 0;
711 post_maximal_pane_position = 0;
712 edit_pane.pack1 (edit_packer, true, true);
713 edit_pane.pack2 (the_notebook, false, true);
715 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
717 top_hbox.pack_start (toolbar_frame, true, true);
719 HBox *hbox = manage (new HBox);
720 hbox->pack_start (edit_pane, true, true);
722 global_vpacker.pack_start (top_hbox, false, false);
723 global_vpacker.pack_start (*hbox, true, true);
725 global_hpacker.pack_start (global_vpacker, true, true);
727 set_name ("EditorWindow");
728 add_accel_group (ActionManager::ui_manager->get_accel_group());
730 status_bar_hpacker.show ();
732 vpacker.pack_end (status_bar_hpacker, false, false);
733 vpacker.pack_end (global_hpacker, true, true);
735 /* register actions now so that set_state() can find them and set toggles/checks etc */
739 snap_type = SnapToBeat;
740 set_snap_to (snap_type);
742 set_snap_mode (snap_mode);
743 set_edit_point_preference (EditAtMouse, true);
745 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
748 _playlist_selector = new PlaylistSelector();
749 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
751 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
755 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
756 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
758 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
759 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
761 nudge_forward_button.set_name ("TransportButton");
762 nudge_backward_button.set_name ("TransportButton");
764 fade_context_menu.set_name ("ArdourContextMenu");
766 /* icons, titles, WM stuff */
768 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
769 Glib::RefPtr<Gdk::Pixbuf> icon;
771 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
772 window_icons.push_back (icon);
774 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
775 window_icons.push_back (icon);
777 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
778 window_icons.push_back (icon);
780 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
781 window_icons.push_back (icon);
783 if (!window_icons.empty()) {
784 set_icon_list (window_icons);
785 set_default_icon_list (window_icons);
788 WindowTitle title(Glib::get_application_name());
789 title += _("Editor");
790 set_title (title.get_string());
791 set_wmclass (X_("ardour_editor"), "Ardour");
794 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
796 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
797 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
799 /* allow external control surfaces/protocols to do various things */
801 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
802 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
803 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
804 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
805 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
807 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
808 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
816 /* <CMT Additions> */
817 if(image_socket_listener)
819 if(image_socket_listener->is_connected())
821 image_socket_listener->close_connection() ;
824 delete image_socket_listener ;
825 image_socket_listener = 0 ;
827 /* </CMT Additions> */
836 Editor::add_toplevel_controls (Container& cont)
838 vpacker.pack_start (cont, false, false);
843 Editor::catch_vanishing_regionview (RegionView *rv)
845 /* note: the selection will take care of the vanishing
846 audioregionview by itself.
849 if (clicked_regionview == rv) {
850 clicked_regionview = 0;
853 if (entered_regionview == rv) {
854 set_entered_regionview (0);
859 Editor::set_entered_regionview (RegionView* rv)
861 if (rv == entered_regionview) {
865 if (entered_regionview) {
866 entered_regionview->exited ();
869 if ((entered_regionview = rv) != 0) {
870 entered_regionview->entered ();
875 Editor::set_entered_track (TimeAxisView* tav)
878 entered_track->exited ();
881 if ((entered_track = tav) != 0) {
882 entered_track->entered ();
887 Editor::show_window ()
892 /* now reset all audio_time_axis heights, because widgets might need
898 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
899 tv = (static_cast<TimeAxisView*>(*i));
905 Editor::instant_save ()
907 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
912 session->add_instant_xml(get_state(), session->path());
914 Config->add_instant_xml(get_state(), get_user_ardour_path());
919 Editor::edit_point_clock_changed()
921 if (_dragging_edit_point) {
925 if (selection->markers.empty()) {
930 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
936 loc->move_to (edit_point_clock.current_time());
940 Editor::zoom_adjustment_changed ()
946 double fpu = zoom_range_clock.current_duration() / canvas_width;
950 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
951 } else if (fpu > session->current_end_frame() / canvas_width) {
952 fpu = session->current_end_frame() / canvas_width;
953 zoom_range_clock.set ((nframes64_t) floor (fpu * canvas_width));
960 Editor::control_scroll (float fraction)
962 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
968 double step = fraction * current_page_frames();
971 _control_scroll_target is an optional<T>
973 it acts like a pointer to an nframes64_t, with
974 a operator conversion to boolean to check
975 that it has a value could possibly use
976 playhead_cursor->current_frame to store the
977 value and a boolean in the class to know
978 when it's out of date
981 if (!_control_scroll_target) {
982 _control_scroll_target = session->transport_frame();
983 _dragging_playhead = true;
986 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
987 *_control_scroll_target = 0;
988 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
989 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
991 *_control_scroll_target += (nframes64_t) floor (step);
994 /* move visuals, we'll catch up with it later */
996 playhead_cursor->set_position (*_control_scroll_target);
997 UpdateAllTransportClocks (*_control_scroll_target);
999 if (*_control_scroll_target > (current_page_frames() / 2)) {
1000 /* try to center PH in window */
1001 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
1007 Now we do a timeout to actually bring the session to the right place
1008 according to the playhead. This is to avoid reading disk buffers on every
1009 call to control_scroll, which is driven by ScrollTimeline and therefore
1010 probably by a control surface wheel which can generate lots of events.
1012 /* cancel the existing timeout */
1014 control_scroll_connection.disconnect ();
1016 /* add the next timeout */
1018 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
1022 Editor::deferred_control_scroll (nframes64_t target)
1024 session->request_locate (*_control_scroll_target, session->transport_rolling());
1025 // reset for next stream
1026 _control_scroll_target = boost::none;
1027 _dragging_playhead = false;
1032 Editor::access_action (std::string action_group, std::string action_item)
1038 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
1040 cout<< "OSC: Recieved: "<< action_item << endl;
1043 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1053 Editor::on_realize ()
1055 Window::on_realize ();
1060 Editor::start_scrolling ()
1062 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1063 (mem_fun(*this, &Editor::update_current_screen));
1068 Editor::stop_scrolling ()
1070 scroll_connection.disconnect ();
1074 Editor::map_position_change (nframes64_t frame)
1076 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1078 if (session == 0 || !_follow_playhead) {
1082 center_screen (frame);
1083 playhead_cursor->set_position (frame);
1087 Editor::center_screen (nframes64_t frame)
1089 double page = canvas_width * frames_per_unit;
1091 /* if we're off the page, then scroll.
1094 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1095 center_screen_internal (frame, page);
1100 Editor::center_screen_internal (nframes64_t frame, float page)
1105 frame -= (nframes64_t) page;
1110 reset_x_origin (frame);
1114 Editor::handle_new_duration ()
1116 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1118 nframes64_t new_end = session->get_maximum_extent() + (nframes64_t) floorf (current_page_frames() * 0.10f);
1120 if (new_end > last_canvas_frame) {
1121 last_canvas_frame = new_end;
1122 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1123 //reset_scrolling_region ();
1126 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1127 //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
1131 Editor::update_title_s (const string & snap_name)
1133 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1139 Editor::update_title ()
1141 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1144 bool dirty = session->dirty();
1146 string session_name;
1148 if (session->snap_name() != session->name()) {
1149 session_name = session->snap_name();
1151 session_name = session->name();
1155 session_name = "*" + session_name;
1158 WindowTitle title(session_name);
1159 title += Glib::get_application_name();
1160 set_title (title.get_string());
1165 Editor::connect_to_session (Session *t)
1169 /* there are never any selected regions at startup */
1171 sensitize_the_right_region_actions (false);
1173 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1176 /* catch up with the playhead */
1178 session->request_locate (playhead_cursor->current_frame);
1180 if (first_action_message) {
1181 first_action_message->hide();
1186 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1187 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1189 /* These signals can all be emitted by a non-GUI thread. Therefore the
1190 handlers for them must not attempt to directly interact with the GUI,
1191 but use Gtkmm2ext::UI::instance()->call_slot();
1194 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1195 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1196 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1197 session_connections.push_back (session->AudioRegionsAdded.connect (mem_fun(*this, &Editor::handle_new_audio_regions)));
1198 session_connections.push_back (session->AudioRegionRemoved.connect (mem_fun(*this, &Editor::handle_audio_region_removed)));
1199 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1200 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1201 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1202 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1203 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1204 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1205 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1206 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1207 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1209 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1211 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1213 edit_groups_changed ();
1215 edit_point_clock.set_session (session);
1216 zoom_range_clock.set_session (session);
1217 _playlist_selector->set_session (session);
1218 nudge_clock.set_session (session);
1219 nudge_clock.set (session->frame_rate() * 5); // default of 5 seconds
1221 playhead_cursor->canvas_item.show ();
1223 if (rhythm_ferret) {
1224 rhythm_ferret->set_session (session);
1228 if (analysis_window != 0)
1229 analysis_window->set_session (session);
1232 Location* loc = session->locations()->auto_loop_location();
1234 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1235 if (loc->start() == loc->end()) {
1236 loc->set_end (loc->start() + 1);
1238 session->locations()->add (loc, false);
1239 session->set_auto_loop_location (loc);
1242 loc->set_name (_("Loop"));
1245 loc = session->locations()->auto_punch_location();
1247 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1248 if (loc->start() == loc->end()) {
1249 loc->set_end (loc->start() + 1);
1251 session->locations()->add (loc, false);
1252 session->set_auto_punch_location (loc);
1255 loc->set_name (_("Punch"));
1258 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1260 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1262 refresh_location_display ();
1263 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1264 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1265 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1266 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1267 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1270 sfbrowser->set_session (session);
1273 handle_new_duration ();
1275 redisplay_regions ();
1276 redisplay_named_selections ();
1277 redisplay_snapshots ();
1279 initial_route_list_display ();
1281 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1282 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1285 restore_ruler_visibility ();
1286 //tempo_map_changed (Change (0));
1287 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1291 /* don't show master bus in a new session */
1293 if (ARDOUR_UI::instance()->session_is_new ()) {
1295 TreeModel::Children rows = route_display_model->children();
1296 TreeModel::Children::iterator i;
1298 no_route_list_redisplay = true;
1300 for (i = rows.begin(); i != rows.end(); ++i) {
1301 TimeAxisView *tv = (*i)[route_display_columns.tv];
1302 AudioTimeAxisView *atv;
1304 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1305 if (atv->route()->master()) {
1306 route_list_display.get_selection()->unselect (i);
1311 no_route_list_redisplay = false;
1312 redisplay_route_list ();
1315 switch (snap_type) {
1316 case SnapToRegionStart:
1317 case SnapToRegionEnd:
1318 case SnapToRegionSync:
1319 case SnapToRegionBoundary:
1320 build_region_boundary_cache ();
1327 /* register for undo history */
1329 session->register_with_memento_command_factory(_id, this);
1335 Editor::build_cursors ()
1337 using namespace Gdk;
1339 Gdk::Color mbg ("#000000" ); /* Black */
1340 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1343 RefPtr<Bitmap> source, mask;
1344 source = Bitmap::create (mag_bits, mag_width, mag_height);
1345 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1346 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1349 Gdk::Color fbg ("#ffffff" );
1350 Gdk::Color ffg ("#000000" );
1353 RefPtr<Bitmap> source, mask;
1355 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1356 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1357 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1361 RefPtr<Bitmap> source, mask;
1362 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1363 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1364 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1368 RefPtr<Bitmap> bits;
1369 char pix[4] = { 0, 0, 0, 0 };
1370 bits = Bitmap::create (pix, 2, 2);
1372 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1376 grabber_cursor = new Gdk::Cursor (HAND2);
1379 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1380 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1383 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1384 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1385 selector_cursor = new Gdk::Cursor (XTERM);
1386 time_fx_cursor = new Gdk::Cursor (SIZING);
1387 wait_cursor = new Gdk::Cursor (WATCH);
1388 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1392 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1394 using namespace Menu_Helpers;
1395 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1398 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1402 MenuList& items (fade_context_menu.items());
1406 switch (item_type) {
1408 case FadeInHandleItem:
1409 if (arv->audio_region()->fade_in_active()) {
1410 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1412 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1415 items.push_back (SeparatorElem());
1417 if (Profile->get_sae()) {
1418 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1419 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1421 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1422 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1423 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1424 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1425 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1430 case FadeOutHandleItem:
1431 if (arv->audio_region()->fade_out_active()) {
1432 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1434 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1437 items.push_back (SeparatorElem());
1439 if (Profile->get_sae()) {
1440 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1441 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1443 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1444 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1445 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1446 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1447 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1452 fatal << _("programming error: ")
1453 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1458 fade_context_menu.popup (button, time);
1462 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
1464 using namespace Menu_Helpers;
1465 Menu* (Editor::*build_menu_function)(nframes64_t);
1468 switch (item_type) {
1470 case RegionViewName:
1471 case RegionViewNameHighlight:
1472 if (with_selection) {
1473 build_menu_function = &Editor::build_track_selection_context_menu;
1475 build_menu_function = &Editor::build_track_region_context_menu;
1480 if (with_selection) {
1481 build_menu_function = &Editor::build_track_selection_context_menu;
1483 build_menu_function = &Editor::build_track_context_menu;
1487 case CrossfadeViewItem:
1488 build_menu_function = &Editor::build_track_crossfade_context_menu;
1492 if (clicked_audio_trackview->get_diskstream()) {
1493 build_menu_function = &Editor::build_track_context_menu;
1495 build_menu_function = &Editor::build_track_bus_context_menu;
1500 /* probably shouldn't happen but if it does, we don't care */
1504 menu = (this->*build_menu_function)(frame);
1505 menu->set_name ("ArdourContextMenu");
1507 /* now handle specific situations */
1509 switch (item_type) {
1511 case RegionViewName:
1512 case RegionViewNameHighlight:
1513 if (!with_selection) {
1514 if (region_edit_menu_split_item) {
1515 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1516 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1518 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1522 if (region_edit_menu_split_multichannel_item) {
1523 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1524 // GTK2FIX find the action, change its sensitivity
1525 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1527 // GTK2FIX see above
1528 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1537 case CrossfadeViewItem:
1544 /* probably shouldn't happen but if it does, we don't care */
1548 if (item_type != SelectionItem && clicked_audio_trackview && clicked_audio_trackview->audio_track()) {
1550 /* Bounce to disk */
1552 using namespace Menu_Helpers;
1553 MenuList& edit_items = menu->items();
1555 edit_items.push_back (SeparatorElem());
1557 switch (clicked_audio_trackview->audio_track()->freeze_state()) {
1558 case AudioTrack::NoFreeze:
1559 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1562 case AudioTrack::Frozen:
1563 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1566 case AudioTrack::UnFrozen:
1567 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1573 menu->popup (button, time);
1577 Editor::build_track_context_menu (nframes64_t ignored)
1579 using namespace Menu_Helpers;
1581 MenuList& edit_items = track_context_menu.items();
1584 add_dstream_context_items (edit_items);
1585 return &track_context_menu;
1589 Editor::build_track_bus_context_menu (nframes64_t ignored)
1591 using namespace Menu_Helpers;
1593 MenuList& edit_items = track_context_menu.items();
1596 add_bus_context_items (edit_items);
1597 return &track_context_menu;
1601 Editor::build_track_region_context_menu (nframes64_t frame)
1603 using namespace Menu_Helpers;
1604 MenuList& edit_items = track_region_context_menu.items();
1607 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1610 boost::shared_ptr<Diskstream> ds;
1611 boost::shared_ptr<Playlist> pl;
1613 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
1614 Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
1616 if (selection->regions.size() > 1) {
1617 // there's already a multiple selection: just add a
1618 // single region context menu that will act on all
1620 boost::shared_ptr<Region> dummy_region; // = NULL
1621 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1623 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1624 add_region_context_items (atv->audio_view(), (*i), edit_items);
1632 add_dstream_context_items (edit_items);
1634 return &track_region_context_menu;
1638 Editor::build_track_crossfade_context_menu (nframes64_t frame)
1640 using namespace Menu_Helpers;
1641 MenuList& edit_items = track_crossfade_context_menu.items();
1642 edit_items.clear ();
1644 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1647 boost::shared_ptr<Diskstream> ds;
1648 boost::shared_ptr<Playlist> pl;
1649 boost::shared_ptr<AudioPlaylist> apl;
1651 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1653 Playlist::RegionList* regions = pl->regions_at (frame);
1654 AudioPlaylist::Crossfades xfades;
1656 apl->crossfades_at (frame, xfades);
1658 bool many = xfades.size() > 1;
1660 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1661 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1664 if (selection->regions.size() > 1) {
1665 // there's already a multiple selection: just add a
1666 // single region context menu that will act on all
1668 boost::shared_ptr<Region> dummy_region; // = NULL
1669 add_region_context_items (atv->audio_view(), dummy_region, edit_items);
1671 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1672 add_region_context_items (atv->audio_view(), (*i), edit_items);
1679 add_dstream_context_items (edit_items);
1681 return &track_crossfade_context_menu;
1686 Editor::analyze_region_selection()
1688 if (analysis_window == 0) {
1689 analysis_window = new AnalysisWindow();
1692 analysis_window->set_session(session);
1694 analysis_window->show_all();
1697 analysis_window->set_regionmode();
1698 analysis_window->analyze();
1700 analysis_window->present();
1704 Editor::analyze_range_selection()
1706 if (analysis_window == 0) {
1707 analysis_window = new AnalysisWindow();
1710 analysis_window->set_session(session);
1712 analysis_window->show_all();
1715 analysis_window->set_rangemode();
1716 analysis_window->analyze();
1718 analysis_window->present();
1720 #endif /* FFT_ANALYSIS */
1725 Editor::build_track_selection_context_menu (nframes64_t ignored)
1727 using namespace Menu_Helpers;
1728 MenuList& edit_items = track_selection_context_menu.items();
1729 edit_items.clear ();
1731 add_selection_context_items (edit_items);
1732 // edit_items.push_back (SeparatorElem());
1733 // add_dstream_context_items (edit_items);
1735 return &track_selection_context_menu;
1739 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1741 using namespace Menu_Helpers;
1742 Menu *xfade_menu = manage (new Menu);
1743 MenuList& items = xfade_menu->items();
1744 xfade_menu->set_name ("ArdourContextMenu");
1747 if (xfade->active()) {
1753 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1754 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1756 if (xfade->can_follow_overlap()) {
1758 if (xfade->following_overlap()) {
1759 str = _("Convert to short");
1761 str = _("Convert to full");
1764 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1768 str = xfade->out()->name();
1770 str += xfade->in()->name();
1772 str = _("Crossfade");
1775 edit_items.push_back (MenuElem (str, *xfade_menu));
1776 edit_items.push_back (SeparatorElem());
1780 Editor::xfade_edit_left_region ()
1782 if (clicked_crossfadeview) {
1783 clicked_crossfadeview->left_view.show_region_editor ();
1788 Editor::xfade_edit_right_region ()
1790 if (clicked_crossfadeview) {
1791 clicked_crossfadeview->right_view.show_region_editor ();
1796 Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1798 using namespace Menu_Helpers;
1799 Menu *region_menu = manage (new Menu);
1800 MenuList& items = region_menu->items();
1801 region_menu->set_name ("ArdourContextMenu");
1803 boost::shared_ptr<AudioRegion> ar;
1806 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1808 /* when this particular menu pops up, make the relevant region
1812 region_menu->signal_map_event().connect (
1814 mem_fun(*this, &Editor::set_selected_regionview_from_map_event),
1816 boost::weak_ptr<Region>(region)
1820 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1821 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1824 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1825 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1826 items.push_back (SeparatorElem());
1827 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1828 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1829 items.push_back (SeparatorElem());
1831 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1832 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1833 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1836 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1839 items.push_back (SeparatorElem());
1841 sigc::connection fooc;
1844 items.push_back (CheckMenuElem (_("Lock")));
1845 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1846 if (region->locked()) {
1847 region_lock_item->set_active();
1849 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1851 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1852 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1854 switch (region->positional_lock_style()) {
1855 case Region::MusicTime:
1856 bbt_glue_item->set_active (true);
1859 bbt_glue_item->set_active (false);
1863 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1865 items.push_back (CheckMenuElem (_("Mute")));
1866 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1867 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1868 if (region->muted()) {
1870 region_mute_item->set_active();
1874 if (!Profile->get_sae()) {
1875 items.push_back (CheckMenuElem (_("Opaque")));
1876 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1877 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1878 if (region->opaque()) {
1880 region_opaque_item->set_active();
1885 // multiple regions selected
1886 // how should these act?
1887 // here they toggle the property of all selected regions
1889 items.push_back (MenuElem (_("Lock"), mem_fun(*this, &Editor::toggle_region_lock)));
1890 items.push_back (MenuElem (_("Mute"), mem_fun(*this, &Editor::toggle_region_mute)));
1891 if (!Profile->get_sae()) {
1892 items.push_back (MenuElem (_("Opaque"), mem_fun(*this, &Editor::toggle_region_opaque)));
1896 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1897 if (region && region->at_natural_position()) {
1898 items.back().set_sensitive (false);
1901 items.push_back (SeparatorElem());
1905 RegionView* rv = sv->find_view (ar);
1906 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1908 if (!Profile->get_sae()) {
1909 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1911 items.push_back (CheckMenuElem (_("Envelope Visible")));
1912 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1913 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1914 if (arv->envelope_visible()) {
1916 region_envelope_visible_item->set_active (true);
1920 items.push_back (CheckMenuElem (_("Envelope Active")));
1921 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1922 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1924 if (ar->envelope_active()) {
1926 region_envelope_active_item->set_active (true);
1930 items.push_back (SeparatorElem());
1933 if (ar->scale_amplitude() != 1.0f) {
1934 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1936 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1940 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1941 items.push_back (SeparatorElem());
1943 /* range related stuff */
1945 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1946 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_audio_region)));
1947 items.push_back (SeparatorElem());
1951 Menu *nudge_menu = manage (new Menu());
1952 MenuList& nudge_items = nudge_menu->items();
1953 nudge_menu->set_name ("ArdourContextMenu");
1955 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1956 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1957 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1958 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1960 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1961 items.push_back (SeparatorElem());
1963 Menu *trim_menu = manage (new Menu);
1964 MenuList& trim_items = trim_menu->items();
1965 trim_menu->set_name ("ArdourContextMenu");
1967 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1968 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1969 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1970 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1972 items.push_back (MenuElem (_("Trim"), *trim_menu));
1973 items.push_back (SeparatorElem());
1975 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1976 region_edit_menu_split_item = &items.back();
1978 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1979 region_edit_menu_split_multichannel_item = &items.back();
1981 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1982 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1983 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1984 items.push_back (SeparatorElem());
1985 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_region)));
1987 /* OK, stick the region submenu at the top of the list, and then add
1991 /* we have to hack up the region name because "_" has a special
1992 meaning for menu titles.
1995 string::size_type pos = 0;
1996 string menu_item_name = (region) ? region->name() : _("Selected regions");
1998 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1999 menu_item_name.replace (pos, 1, "__");
2003 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
2004 edit_items.push_back (SeparatorElem());
2008 Editor::add_selection_context_items (Menu_Helpers::MenuList& items)
2010 using namespace Menu_Helpers;
2012 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
2013 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
2016 items.push_back (SeparatorElem());
2017 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
2020 items.push_back (SeparatorElem());
2021 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
2022 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
2024 items.push_back (SeparatorElem());
2025 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
2026 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
2028 items.push_back (SeparatorElem());
2029 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
2031 items.push_back (SeparatorElem());
2032 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
2033 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
2035 items.push_back (SeparatorElem());
2036 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
2037 items.push_back (SeparatorElem());
2038 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
2039 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
2040 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
2041 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
2042 items.push_back (SeparatorElem());
2043 items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
2044 items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
2045 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
2049 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2051 using namespace Menu_Helpers;
2055 Menu *play_menu = manage (new Menu);
2056 MenuList& play_items = play_menu->items();
2057 play_menu->set_name ("ArdourContextMenu");
2059 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2060 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2061 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2062 play_items.push_back (SeparatorElem());
2063 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2065 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2069 Menu *select_menu = manage (new Menu);
2070 MenuList& select_items = select_menu->items();
2071 select_menu->set_name ("ArdourContextMenu");
2073 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2074 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2075 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2076 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2077 select_items.push_back (SeparatorElem());
2078 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2079 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2080 select_items.push_back (SeparatorElem());
2081 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2082 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2083 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2084 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2085 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2086 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2087 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2089 select_items.push_back (SeparatorElem());
2091 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2095 Menu *cutnpaste_menu = manage (new Menu);
2096 MenuList& cutnpaste_items = cutnpaste_menu->items();
2097 cutnpaste_menu->set_name ("ArdourContextMenu");
2099 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2100 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2101 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2103 cutnpaste_items.push_back (SeparatorElem());
2105 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2106 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2108 cutnpaste_items.push_back (SeparatorElem());
2110 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2112 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2114 /* Adding new material */
2116 edit_items.push_back (SeparatorElem());
2117 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2118 edit_items.push_back (MenuElem (_("Insert Existing Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2122 Menu *nudge_menu = manage (new Menu());
2123 MenuList& nudge_items = nudge_menu->items();
2124 nudge_menu->set_name ("ArdourContextMenu");
2126 edit_items.push_back (SeparatorElem());
2127 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2128 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2129 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2130 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2132 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2136 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2138 using namespace Menu_Helpers;
2142 Menu *play_menu = manage (new Menu);
2143 MenuList& play_items = play_menu->items();
2144 play_menu->set_name ("ArdourContextMenu");
2146 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2147 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2148 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2152 Menu *select_menu = manage (new Menu);
2153 MenuList& select_items = select_menu->items();
2154 select_menu->set_name ("ArdourContextMenu");
2156 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2157 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2158 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2159 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2160 select_items.push_back (SeparatorElem());
2161 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2162 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2163 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2164 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2166 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2170 Menu *cutnpaste_menu = manage (new Menu);
2171 MenuList& cutnpaste_items = cutnpaste_menu->items();
2172 cutnpaste_menu->set_name ("ArdourContextMenu");
2174 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2175 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2176 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2178 Menu *nudge_menu = manage (new Menu());
2179 MenuList& nudge_items = nudge_menu->items();
2180 nudge_menu->set_name ("ArdourContextMenu");
2182 edit_items.push_back (SeparatorElem());
2183 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2184 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2185 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2186 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2188 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2192 Editor::set_snap_to (SnapType st)
2194 unsigned int snap_ind = (unsigned int)st;
2197 if (snap_ind > snap_type_strings.size() - 1) {
2199 snap_type = (SnapType)snap_ind;
2202 string str = snap_type_strings[snap_ind];
2204 if (str != snap_type_selector.get_active_text()) {
2205 snap_type_selector.set_active_text (str);
2210 switch (snap_type) {
2211 case SnapToAThirtysecondBeat:
2212 case SnapToASixteenthBeat:
2213 case SnapToAEighthBeat:
2214 case SnapToAQuarterBeat:
2215 case SnapToAThirdBeat:
2216 update_tempo_based_rulers ();
2219 case SnapToRegionStart:
2220 case SnapToRegionEnd:
2221 case SnapToRegionSync:
2222 case SnapToRegionBoundary:
2223 build_region_boundary_cache ();
2233 Editor::set_snap_mode (SnapMode mode)
2236 string str = snap_mode_strings[(int)mode];
2238 if (str != snap_mode_selector.get_active_text ()) {
2239 snap_mode_selector.set_active_text (str);
2245 Editor::set_edit_point_preference (EditPoint ep, bool force)
2247 bool changed = (_edit_point != ep);
2250 string str = edit_point_strings[(int)ep];
2252 if (str != edit_point_selector.get_active_text ()) {
2253 edit_point_selector.set_active_text (str);
2256 set_canvas_cursor ();
2258 if (!force && !changed) {
2262 switch (zoom_focus) {
2263 case ZoomFocusMouse:
2264 case ZoomFocusPlayhead:
2266 switch (_edit_point) {
2268 set_zoom_focus (ZoomFocusMouse);
2270 case EditAtPlayhead:
2271 set_zoom_focus (ZoomFocusPlayhead);
2273 case EditAtSelectedMarker:
2274 set_zoom_focus (ZoomFocusEdit);
2282 const char* action=NULL;
2284 switch (_edit_point) {
2285 case EditAtPlayhead:
2286 action = "edit-at-playhead";
2288 case EditAtSelectedMarker:
2289 action = "edit-at-marker";
2292 action = "edit-at-mouse";
2296 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2298 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2302 bool in_track_canvas;
2304 if (!mouse_frame (foo, in_track_canvas)) {
2305 in_track_canvas = false;
2308 reset_canvas_action_sensitivity (in_track_canvas);
2314 Editor::set_state (const XMLNode& node)
2316 const XMLProperty* prop;
2318 int x, y, xoff, yoff;
2321 if ((prop = node.property ("id")) != 0) {
2322 _id = prop->value ();
2325 if ((geometry = find_named_node (node, "geometry")) == 0) {
2327 g.base_width = default_width;
2328 g.base_height = default_height;
2336 g.base_width = atoi(geometry->property("x_size")->value());
2337 g.base_height = atoi(geometry->property("y_size")->value());
2338 x = atoi(geometry->property("x_pos")->value());
2339 y = atoi(geometry->property("y_pos")->value());
2340 xoff = atoi(geometry->property("x_off")->value());
2341 yoff = atoi(geometry->property("y_off")->value());
2344 set_default_size (g.base_width, g.base_height);
2347 if (session && (prop = node.property ("playhead"))) {
2348 nframes64_t pos = atol (prop->value().c_str());
2349 playhead_cursor->set_position (pos);
2351 playhead_cursor->set_position (0);
2353 /* reset_x_origin() doesn't work right here, since the old
2354 position may be zero already, and it does nothing in such
2359 horizontal_adjustment.set_value (0);
2362 if ((prop = node.property ("mixer-width"))) {
2363 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2366 if ((prop = node.property ("zoom-focus"))) {
2367 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2370 if ((prop = node.property ("zoom"))) {
2371 reset_zoom (PBD::atof (prop->value()));
2374 if ((prop = node.property ("snap-to"))) {
2375 set_snap_to ((SnapType) atoi (prop->value()));
2378 if ((prop = node.property ("snap-mode"))) {
2379 set_snap_mode ((SnapMode) atoi (prop->value()));
2382 if ((prop = node.property ("edit-point"))) {
2383 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2386 if ((prop = node.property ("mouse-mode"))) {
2387 MouseMode m = str2mousemode(prop->value());
2388 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2389 set_mouse_mode (m, true);
2391 mouse_mode = MouseGain; /* lie, to force the mode switch */
2392 set_mouse_mode (MouseObject, true);
2395 if ((prop = node.property ("show-waveforms"))) {
2396 bool yn = (prop->value() == "yes");
2397 _show_waveforms = !yn;
2398 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
2400 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2401 /* do it twice to force the change */
2402 tact->set_active (!yn);
2403 tact->set_active (yn);
2407 if ((prop = node.property ("show-waveforms-recording"))) {
2408 bool yn = (prop->value() == "yes");
2409 _show_waveforms_recording = !yn;
2410 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2412 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2413 /* do it twice to force the change */
2414 tact->set_active (!yn);
2415 tact->set_active (yn);
2419 if ((prop = node.property ("show-measures"))) {
2420 bool yn = (prop->value() == "yes");
2421 _show_measures = !yn;
2422 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2424 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2425 /* do it twice to force the change */
2426 tact->set_active (!yn);
2427 tact->set_active (yn);
2431 if ((prop = node.property ("follow-playhead"))) {
2432 bool yn = (prop->value() == "yes");
2433 set_follow_playhead (yn);
2434 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2436 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2437 if (tact->get_active() != yn) {
2438 tact->set_active (yn);
2443 if ((prop = node.property ("region-list-sort-type"))) {
2444 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2445 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2448 if ((prop = node.property ("xfades-visible"))) {
2449 bool yn = (prop->value() == "yes");
2450 _xfade_visibility = !yn;
2451 // set_xfade_visibility (yn);
2454 if ((prop = node.property ("show-editor-mixer"))) {
2456 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2459 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2460 bool yn = (prop->value() == X_("yes"));
2462 /* do it twice to force the change */
2464 tact->set_active (!yn);
2465 tact->set_active (yn);
2474 Editor::get_state ()
2476 XMLNode* node = new XMLNode ("Editor");
2479 _id.print (buf, sizeof (buf));
2480 node->add_property ("id", buf);
2482 if (is_realized()) {
2483 Glib::RefPtr<Gdk::Window> win = get_window();
2485 int x, y, xoff, yoff, width, height;
2486 win->get_root_origin(x, y);
2487 win->get_position(xoff, yoff);
2488 win->get_size(width, height);
2490 XMLNode* geometry = new XMLNode ("geometry");
2492 snprintf(buf, sizeof(buf), "%d", width);
2493 geometry->add_property("x_size", string(buf));
2494 snprintf(buf, sizeof(buf), "%d", height);
2495 geometry->add_property("y_size", string(buf));
2496 snprintf(buf, sizeof(buf), "%d", x);
2497 geometry->add_property("x_pos", string(buf));
2498 snprintf(buf, sizeof(buf), "%d", y);
2499 geometry->add_property("y_pos", string(buf));
2500 snprintf(buf, sizeof(buf), "%d", xoff);
2501 geometry->add_property("x_off", string(buf));
2502 snprintf(buf, sizeof(buf), "%d", yoff);
2503 geometry->add_property("y_off", string(buf));
2504 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2505 geometry->add_property("edit_pane_pos", string(buf));
2507 node->add_child_nocopy (*geometry);
2510 maybe_add_mixer_strip_width (*node);
2512 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2513 node->add_property ("zoom-focus", buf);
2514 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2515 node->add_property ("zoom", buf);
2516 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2517 node->add_property ("snap-to", buf);
2518 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2519 node->add_property ("snap-mode", buf);
2521 node->add_property ("edit-point", enum_2_string (_edit_point));
2523 snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
2524 node->add_property ("playhead", buf);
2526 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2527 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2528 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2529 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2530 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2531 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2532 node->add_property ("mouse-mode", enum2str(mouse_mode));
2534 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2536 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2537 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2546 Editor::trackview_by_y_position (double y)
2548 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2552 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2561 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2563 if (!session || snap_mode == SnapOff) {
2567 snap_to_internal (start, direction, for_mark);
2571 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2573 Location* before = 0;
2574 Location* after = 0;
2576 const nframes64_t one_second = session->frame_rate();
2577 const nframes64_t one_minute = session->frame_rate() * 60;
2578 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2579 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2580 nframes64_t presnap = start;
2582 switch (snap_type) {
2584 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2585 start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2587 start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2591 case SnapToSMPTEFrame:
2592 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2593 start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2595 start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2599 case SnapToSMPTESeconds:
2600 if (session->smpte_offset_negative())
2602 start += session->smpte_offset ();
2604 start -= session->smpte_offset ();
2606 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2607 start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2609 start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2612 if (session->smpte_offset_negative())
2614 start -= session->smpte_offset ();
2616 start += session->smpte_offset ();
2620 case SnapToSMPTEMinutes:
2621 if (session->smpte_offset_negative())
2623 start += session->smpte_offset ();
2625 start -= session->smpte_offset ();
2627 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2628 start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2630 start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2632 if (session->smpte_offset_negative())
2634 start -= session->smpte_offset ();
2636 start += session->smpte_offset ();
2641 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2642 start = (nframes64_t) ceil ((double) start / one_second) * one_second;
2644 start = (nframes64_t) floor ((double) start / one_second) * one_second;
2649 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2650 start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
2652 start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
2657 start = session->tempo_map().round_to_bar (start, direction);
2661 start = session->tempo_map().round_to_beat (start, direction);
2664 case SnapToAThirtysecondBeat:
2665 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2668 case SnapToASixteenthBeat:
2669 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2672 case SnapToAEighthBeat:
2673 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2676 case SnapToAQuarterBeat:
2677 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2680 case SnapToAThirdBeat:
2681 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2689 before = session->locations()->first_location_before (start);
2690 after = session->locations()->first_location_after (start);
2692 if (direction < 0) {
2694 start = before->start();
2698 } else if (direction > 0) {
2700 start = after->start();
2702 start = session->current_end_frame();
2707 /* find nearest of the two */
2708 if ((start - before->start()) < (after->start() - start)) {
2709 start = before->start();
2711 start = after->start();
2714 start = before->start();
2717 start = after->start();
2724 case SnapToRegionStart:
2725 case SnapToRegionEnd:
2726 case SnapToRegionSync:
2727 case SnapToRegionBoundary:
2728 if (!region_boundary_cache.empty()) {
2729 vector<nframes64_t>::iterator i;
2731 if (direction > 0) {
2732 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2734 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2737 if (i != region_boundary_cache.end()) {
2739 /* lower bound doesn't quite to the right thing for our purposes */
2741 if (direction < 0 && i != region_boundary_cache.begin()) {
2748 start = region_boundary_cache.back();
2754 switch (snap_mode) {
2760 if (presnap > start) {
2761 if (presnap > (start + unit_to_frame(snap_threshold))) {
2765 } else if (presnap < start) {
2766 if (presnap < (start - unit_to_frame(snap_threshold))) {
2772 /* handled at entry */
2779 Editor::setup_toolbar ()
2784 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2786 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2789 /* Mode Buttons (tool selection) */
2791 vector<ToggleButton *> mouse_mode_buttons;
2793 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2794 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2795 mouse_mode_buttons.push_back (&mouse_move_button);
2797 if (!Profile->get_sae()) {
2798 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2799 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2800 mouse_mode_buttons.push_back (&mouse_select_button);
2802 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2803 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2804 mouse_mode_buttons.push_back (&mouse_gain_button);
2807 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2808 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2809 mouse_mode_buttons.push_back (&mouse_zoom_button);
2810 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2811 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2812 mouse_mode_buttons.push_back (&mouse_timefx_button);
2813 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2814 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2815 mouse_mode_buttons.push_back (&mouse_audition_button);
2817 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2819 HBox* mode_box = manage(new HBox);
2820 mode_box->set_border_width (2);
2821 mode_box->set_spacing(4);
2822 mouse_mode_button_box.set_spacing(1);
2823 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2824 if (!Profile->get_sae()) {
2825 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2827 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2828 if (!Profile->get_sae()) {
2829 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2831 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2832 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2833 mouse_mode_button_box.set_homogeneous(true);
2835 vector<string> edit_mode_strings;
2836 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2837 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2838 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2840 edit_mode_selector.set_name ("EditModeSelector");
2841 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2842 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2843 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2845 mode_box->pack_start(edit_mode_selector);
2846 mode_box->pack_start(mouse_mode_button_box);
2848 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2849 mouse_mode_tearoff->set_name ("MouseModeBase");
2851 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2852 &mouse_mode_tearoff->tearoff_window()));
2853 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2854 &mouse_mode_tearoff->tearoff_window(), 1));
2855 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2856 &mouse_mode_tearoff->tearoff_window()));
2857 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2858 &mouse_mode_tearoff->tearoff_window(), 1));
2860 mouse_move_button.set_name ("MouseModeButton");
2861 mouse_select_button.set_name ("MouseModeButton");
2862 mouse_gain_button.set_name ("MouseModeButton");
2863 mouse_zoom_button.set_name ("MouseModeButton");
2864 mouse_timefx_button.set_name ("MouseModeButton");
2865 mouse_audition_button.set_name ("MouseModeButton");
2867 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2868 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2869 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2870 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2871 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2872 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2874 mouse_move_button.unset_flags (CAN_FOCUS);
2875 mouse_select_button.unset_flags (CAN_FOCUS);
2876 mouse_gain_button.unset_flags (CAN_FOCUS);
2877 mouse_zoom_button.unset_flags (CAN_FOCUS);
2878 mouse_timefx_button.unset_flags (CAN_FOCUS);
2879 mouse_audition_button.unset_flags (CAN_FOCUS);
2881 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2882 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2884 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2885 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2886 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2887 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2888 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2890 // mouse_move_button.set_active (true);
2895 zoom_box.set_spacing (1);
2896 zoom_box.set_border_width (2);
2898 zoom_in_button.set_name ("EditorTimeButton");
2899 zoom_in_button.set_size_request(-1,16);
2900 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2901 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2902 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2904 zoom_out_button.set_name ("EditorTimeButton");
2905 zoom_out_button.set_size_request(-1,16);
2906 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2907 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2908 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2910 zoom_out_full_button.set_name ("EditorTimeButton");
2911 zoom_out_full_button.set_size_request(-1,16);
2912 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2913 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2914 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2916 zoom_focus_selector.set_name ("ZoomFocusSelector");
2917 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
2918 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
2919 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2920 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2922 zoom_box.pack_start (zoom_focus_selector, true, true);
2923 zoom_box.pack_start (zoom_out_button, false, false);
2924 zoom_box.pack_start (zoom_in_button, false, false);
2925 zoom_box.pack_start (zoom_out_full_button, false, false);
2927 snap_box.set_spacing (1);
2928 snap_box.set_border_width (2);
2930 snap_type_selector.set_name ("SnapTypeSelector");
2931 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
2932 set_popdown_strings (snap_type_selector, snap_type_strings);
2933 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2934 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2936 snap_mode_selector.set_name ("SnapModeSelector");
2937 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
2938 set_popdown_strings (snap_mode_selector, snap_mode_strings);
2939 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2940 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2942 edit_point_selector.set_name ("SnapModeSelector");
2943 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
2944 set_popdown_strings (edit_point_selector, edit_point_strings);
2945 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2946 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2948 snap_box.pack_start (edit_point_clock, false, false);
2949 snap_box.pack_start (snap_mode_selector, false, false);
2950 snap_box.pack_start (snap_type_selector, false, false);
2951 snap_box.pack_start (edit_point_selector, false, false);
2955 HBox *nudge_box = manage (new HBox);
2956 nudge_box->set_spacing(1);
2957 nudge_box->set_border_width (2);
2959 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
2960 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
2962 nudge_box->pack_start (nudge_backward_button, false, false);
2963 nudge_box->pack_start (nudge_forward_button, false, false);
2964 nudge_box->pack_start (nudge_clock, false, false);
2967 /* Pack everything in... */
2969 HBox* hbox = new HBox;
2970 hbox->set_spacing(10);
2972 tools_tearoff = new TearOff (*hbox);
2973 tools_tearoff->set_name ("MouseModeBase");
2975 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2976 &tools_tearoff->tearoff_window()));
2977 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2978 &tools_tearoff->tearoff_window(), 0));
2979 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2980 &tools_tearoff->tearoff_window()));
2981 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2982 &tools_tearoff->tearoff_window(), 0));
2984 toolbar_hbox.set_spacing (10);
2985 toolbar_hbox.set_border_width (1);
2987 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2988 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2991 hbox->pack_start (snap_box, false, false);
2992 // hbox->pack_start (zoom_box, false, false);
2993 hbox->pack_start (*nudge_box, false, false);
2997 toolbar_base.set_name ("ToolBarBase");
2998 toolbar_base.add (toolbar_hbox);
3000 toolbar_frame.set_shadow_type (SHADOW_OUT);
3001 toolbar_frame.set_name ("BaseFrame");
3002 toolbar_frame.add (toolbar_base);
3006 Editor::convert_drop_to_paths (vector<ustring>& paths,
3007 const RefPtr<Gdk::DragContext>& context,
3010 const SelectionData& data,
3019 vector<ustring> uris = data.get_uris();
3023 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
3024 are actually URI lists. So do it by hand.
3027 if (data.get_target() != "text/plain") {
3031 /* Parse the "uri-list" format that Nautilus provides,
3032 where each pathname is delimited by \r\n
3035 const char* p = data.get_text().c_str();
3042 while (g_ascii_isspace (*p))
3046 while (*q && (*q != '\n') && (*q != '\r'))
3052 while (q > p && g_ascii_isspace (*q))
3057 uris.push_back (ustring (p, q - p + 1));
3061 p = strchr (p, '\n');
3071 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3073 if ((*i).substr (0,7) == "file://") {
3077 PBD::url_decode (p);
3079 // scan forward past three slashes
3081 ustring::size_type slashcnt = 0;
3082 ustring::size_type n = 0;
3083 ustring::iterator x = p.begin();
3085 while (slashcnt < 3 && x != p.end()) {
3088 } else if (slashcnt == 3) {
3095 if (slashcnt != 3 || x == p.end()) {
3096 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3100 paths.push_back (p.substr (n - 1));
3108 Editor::new_tempo_section ()
3114 Editor::map_transport_state ()
3116 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3118 if (session->transport_stopped()) {
3119 have_pending_keyboard_selection = false;
3122 update_loop_range_view (true);
3127 Editor::State::State ()
3129 selection = new Selection;
3132 Editor::State::~State ()
3138 Editor::get_memento () const
3140 State *state = new State;
3142 store_state (*state);
3143 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
3147 Editor::store_state (State& state) const
3149 *state.selection = *selection;
3153 Editor::restore_state (State *state)
3155 if (*selection == *state->selection) {
3159 *selection = *state->selection;
3160 time_selection_changed ();
3161 region_selection_changed ();
3163 /* XXX other selection change handlers? */
3167 Editor::begin_reversible_command (string name)
3170 // before = &get_state();
3171 session->begin_reversible_command (name);
3176 Editor::commit_reversible_command ()
3179 // session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3180 session->commit_reversible_command ();
3185 Editor::set_edit_group_solo (Route& route, bool yn)
3187 RouteGroup *edit_group;
3189 if ((edit_group = route.edit_group()) != 0) {
3190 edit_group->apply (&Route::set_solo, yn, this);
3192 route.set_solo (yn, this);
3197 Editor::set_edit_group_mute (Route& route, bool yn)
3199 RouteGroup *edit_group = 0;
3201 if ((edit_group == route.edit_group()) != 0) {
3202 edit_group->apply (&Route::set_mute, yn, this);
3204 route.set_mute (yn, this);
3209 Editor::history_changed ()
3213 if (undo_action && session) {
3214 if (session->undo_depth() == 0) {
3217 label = string_compose(_("Undo (%1)"), session->next_undo());
3219 undo_action->property_label() = label;
3222 if (redo_action && session) {
3223 if (session->redo_depth() == 0) {
3226 label = string_compose(_("Redo (%1)"), session->next_redo());
3228 redo_action->property_label() = label;
3233 Editor::duplicate_dialog (bool with_dialog)
3237 if (mouse_mode == MouseRange) {
3238 if (selection->time.length() == 0) {
3244 get_regions_for_action (rs);
3246 if (mouse_mode != MouseRange) {
3255 ArdourDialog win ("Duplication Dialog");
3256 Label label (_("Number of Duplications:"));
3257 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3258 SpinButton spinner (adjustment, 0.0, 1);
3261 win.get_vbox()->set_spacing (12);
3262 win.get_vbox()->pack_start (hbox);
3263 hbox.set_border_width (6);
3264 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3266 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3267 place, visually. so do this by hand.
3270 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3271 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3272 spinner.grab_focus();
3278 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3279 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3280 win.set_default_response (RESPONSE_ACCEPT);
3282 win.set_position (WIN_POS_MOUSE);
3284 spinner.grab_focus ();
3286 switch (win.run ()) {
3287 case RESPONSE_ACCEPT:
3293 times = adjustment.get_value();
3296 if (mouse_mode == MouseRange) {
3297 duplicate_selection (times);
3299 duplicate_some_regions (rs, times);
3304 Editor::show_verbose_canvas_cursor ()
3306 verbose_canvas_cursor->raise_to_top();
3307 verbose_canvas_cursor->show();
3308 verbose_cursor_visible = true;
3312 Editor::hide_verbose_canvas_cursor ()
3314 verbose_canvas_cursor->hide();
3315 verbose_cursor_visible = false;
3319 Editor::clamp_verbose_cursor_x (double x)
3324 x = min (canvas_width - 200.0, x);
3330 Editor::clamp_verbose_cursor_y (double y)
3332 if (y < canvas_timebars_vsize) {
3333 y = canvas_timebars_vsize;
3335 y = min (canvas_height - 50, y);
3341 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3343 verbose_canvas_cursor->property_text() = txt.c_str();
3344 /* don't get too close to the edge */
3345 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3346 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
3350 Editor::set_verbose_canvas_cursor_text (const string & txt)
3352 verbose_canvas_cursor->property_text() = txt.c_str();
3356 Editor::set_edit_mode (EditMode m)
3358 Config->set_edit_mode (m);
3362 Editor::cycle_edit_mode ()
3364 switch (Config->get_edit_mode()) {
3366 Config->set_edit_mode (Splice);
3369 Config->set_edit_mode (Lock);
3372 Config->set_edit_mode (Slide);
3378 Editor::edit_mode_selection_done ()
3384 string choice = edit_mode_selector.get_active_text();
3385 EditMode mode = Slide;
3387 if (choice == _("Splice Edit")) {
3389 } else if (choice == _("Slide Edit")) {
3391 } else if (choice == _("Lock Edit")) {
3395 Config->set_edit_mode (mode);
3399 Editor::snap_type_selection_done ()
3401 string choice = snap_type_selector.get_active_text();
3402 SnapType snaptype = SnapToBeat;
3404 if (choice == _("Beats/3")) {
3405 snaptype = SnapToAThirdBeat;
3406 } else if (choice == _("Beats/4")) {
3407 snaptype = SnapToAQuarterBeat;
3408 } else if (choice == _("Beats/8")) {
3409 snaptype = SnapToAEighthBeat;
3410 } else if (choice == _("Beats/16")) {
3411 snaptype = SnapToASixteenthBeat;
3412 } else if (choice == _("Beats/32")) {
3413 snaptype = SnapToAThirtysecondBeat;
3414 } else if (choice == _("Beats")) {
3415 snaptype = SnapToBeat;
3416 } else if (choice == _("Bars")) {
3417 snaptype = SnapToBar;
3418 } else if (choice == _("Marks")) {
3419 snaptype = SnapToMark;
3420 } else if (choice == _("Region starts")) {
3421 snaptype = SnapToRegionStart;
3422 } else if (choice == _("Region ends")) {
3423 snaptype = SnapToRegionEnd;
3424 } else if (choice == _("Region bounds")) {
3425 snaptype = SnapToRegionBoundary;
3426 } else if (choice == _("Region syncs")) {
3427 snaptype = SnapToRegionSync;
3428 } else if (choice == _("CD Frames")) {
3429 snaptype = SnapToCDFrame;
3430 } else if (choice == _("SMPTE Frames")) {
3431 snaptype = SnapToSMPTEFrame;
3432 } else if (choice == _("SMPTE Seconds")) {
3433 snaptype = SnapToSMPTESeconds;
3434 } else if (choice == _("SMPTE Minutes")) {
3435 snaptype = SnapToSMPTEMinutes;
3436 } else if (choice == _("Seconds")) {
3437 snaptype = SnapToSeconds;
3438 } else if (choice == _("Minutes")) {
3439 snaptype = SnapToMinutes;
3442 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3444 ract->set_active ();
3449 Editor::snap_mode_selection_done ()
3451 string choice = snap_mode_selector.get_active_text();
3452 SnapMode mode = SnapNormal;
3454 if (choice == _("No Grid")) {
3456 } else if (choice == _("Grid")) {
3458 } else if (choice == _("Magnetic")) {
3459 mode = SnapMagnetic;
3462 RefPtr<RadioAction> ract = snap_mode_action (mode);
3465 ract->set_active (true);
3470 Editor::cycle_edit_point (bool with_marker)
3472 switch (_edit_point) {
3474 set_edit_point_preference (EditAtPlayhead);
3476 case EditAtPlayhead:
3478 set_edit_point_preference (EditAtSelectedMarker);
3480 set_edit_point_preference (EditAtMouse);
3483 case EditAtSelectedMarker:
3484 set_edit_point_preference (EditAtMouse);
3490 Editor::edit_point_selection_done ()
3492 string choice = edit_point_selector.get_active_text();
3493 EditPoint ep = EditAtSelectedMarker;
3495 if (choice == _("Marker")) {
3496 set_edit_point_preference (EditAtSelectedMarker);
3497 } else if (choice == _("Playhead")) {
3498 set_edit_point_preference (EditAtPlayhead);
3500 set_edit_point_preference (EditAtMouse);
3503 RefPtr<RadioAction> ract = edit_point_action (ep);
3506 ract->set_active (true);
3511 Editor::zoom_focus_selection_done ()
3513 string choice = zoom_focus_selector.get_active_text();
3514 ZoomFocus focus_type = ZoomFocusLeft;
3516 if (choice == _("Left")) {
3517 focus_type = ZoomFocusLeft;
3518 } else if (choice == _("Right")) {
3519 focus_type = ZoomFocusRight;
3520 } else if (choice == _("Center")) {
3521 focus_type = ZoomFocusCenter;
3522 } else if (choice == _("Playhead")) {
3523 focus_type = ZoomFocusPlayhead;
3524 } else if (choice == _("Mouse")) {
3525 focus_type = ZoomFocusMouse;
3526 } else if (choice == _("Active Mark")) {
3527 focus_type = ZoomFocusEdit;
3530 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3533 ract->set_active ();
3538 Editor::edit_controls_button_release (GdkEventButton* ev)
3540 if (Keyboard::is_context_menu_event (ev)) {
3541 ARDOUR_UI::instance()->add_route (this);
3547 Editor::mouse_select_button_release (GdkEventButton* ev)
3549 /* this handles just right-clicks */
3551 if (ev->button != 3) {
3558 Editor::TrackViewList *
3559 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3562 TrackViewList::iterator i;
3564 v = new TrackViewList;
3566 if (track == 0 && group == 0) {
3570 for (i = track_views.begin(); i != track_views.end (); ++i) {
3574 } else if ((track != 0 && group == 0) || (track != 0 && group != 0 && !group->is_active())) {
3576 /* just the view for this track
3579 v->push_back (track);
3583 /* views for all tracks in the edit group */
3585 for (i = track_views.begin(); i != track_views.end (); ++i) {
3587 if (group == 0 || (*i)->edit_group() == group) {
3597 Editor::set_zoom_focus (ZoomFocus f)
3599 string str = zoom_focus_strings[(int)f];
3601 if (str != zoom_focus_selector.get_active_text()) {
3602 zoom_focus_selector.set_active_text (str);
3605 if (zoom_focus != f) {
3608 ZoomFocusChanged (); /* EMIT_SIGNAL */
3615 Editor::ensure_float (Window& win)
3617 win.set_transient_for (*this);
3621 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3623 /* recover or initialize pane positions. do this here rather than earlier because
3624 we don't want the positions to change the child allocations, which they seem to do.
3630 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3632 static int32_t done;
3635 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3636 width = default_width;
3637 height = default_height;
3639 width = atoi(geometry->property("x_size")->value());
3640 height = atoi(geometry->property("y_size")->value());
3643 if (which == static_cast<Paned*> (&edit_pane)) {
3649 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3650 /* initial allocation is 90% to canvas, 10% to notebook */
3651 pos = (int) floor (alloc.get_width() * 0.90f);
3652 snprintf (buf, sizeof(buf), "%d", pos);
3654 pos = atoi (prop->value());
3657 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3658 edit_pane.set_position (pos);
3659 pre_maximal_pane_position = pos;
3665 Editor::detach_tearoff (Box* b, Window* w)
3667 if (tools_tearoff->torn_off() &&
3668 mouse_mode_tearoff->torn_off()) {
3669 top_hbox.remove (toolbar_frame);
3674 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3676 if (toolbar_frame.get_parent() == 0) {
3677 top_hbox.pack_end (toolbar_frame);
3682 Editor::set_show_measures (bool yn)
3684 if (_show_measures != yn) {
3687 if ((_show_measures = yn) == true) {
3695 Editor::toggle_follow_playhead ()
3697 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3699 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3700 set_follow_playhead (tact->get_active());
3705 Editor::set_follow_playhead (bool yn)
3707 if (_follow_playhead != yn) {
3708 if ((_follow_playhead = yn) == true) {
3710 update_current_screen ();
3717 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3719 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3721 xfade->set_active (!xfade->active());
3726 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3728 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3730 xfade->set_follow_overlap (!xfade->following_overlap());
3735 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3737 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3743 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3747 switch (cew.run ()) {
3748 case RESPONSE_ACCEPT:
3755 xfade->StateChanged (Change (~0));
3759 Editor::playlist_selector () const
3761 return *_playlist_selector;
3765 Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
3769 ret = nudge_clock.current_duration (pos);
3770 next = ret + 1; /* XXXX fix me */
3776 Editor::end_location_changed (Location* location)
3778 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3779 //reset_scrolling_region ();
3780 horizontal_adjustment.set_upper ( location->start());
3784 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3786 ArdourDialog dialog ("playlist deletion dialog");
3787 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3788 "If left alone, no audio files used by it will be cleaned.\n"
3789 "If deleted, audio files used by it alone by will cleaned."),
3792 dialog.set_position (WIN_POS_CENTER);
3793 dialog.get_vbox()->pack_start (label);
3797 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3798 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3799 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3801 switch (dialog.run ()) {
3802 case RESPONSE_ACCEPT:
3803 /* delete the playlist */
3807 case RESPONSE_REJECT:
3808 /* keep the playlist */
3820 Editor::audio_region_selection_covers (nframes64_t where)
3822 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3823 if ((*a)->region()->covers (where)) {
3832 Editor::prepare_for_cleanup ()
3834 cut_buffer->clear_regions ();
3835 cut_buffer->clear_playlists ();
3837 selection->clear_regions ();
3838 selection->clear_playlists ();
3840 no_region_list_redisplay = true;
3844 Editor::finish_cleanup ()
3846 no_region_list_redisplay = false;
3847 redisplay_regions ();
3851 Editor::transport_loop_location()
3854 return session->locations()->auto_loop_location();
3861 Editor::transport_punch_location()
3864 return session->locations()->auto_punch_location();
3871 Editor::control_layout_scroll (GdkEventScroll* ev)
3873 switch (ev->direction) {
3875 scroll_tracks_up_line ();
3879 case GDK_SCROLL_DOWN:
3880 scroll_tracks_down_line ();
3884 /* no left/right handling yet */
3892 /** A new snapshot has been selected.
3895 Editor::snapshot_display_selection_changed ()
3897 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
3899 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
3901 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
3903 if (snap_name.length() == 0) {
3907 if (session->snap_name() == snap_name) {
3911 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
3916 Editor::snapshot_display_button_press (GdkEventButton* ev)
3918 if (ev->button == 3) {
3919 /* Right-click on the snapshot list. Work out which snapshot it
3921 Gtk::TreeModel::Path path;
3922 Gtk::TreeViewColumn* col;
3925 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
3926 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
3928 Gtk::TreeModel::Row row = *iter;
3929 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
3938 /** Pop up the snapshot display context menu.
3939 * @param button Button used to open the menu.
3940 * @param time Menu open time.
3941 * @snapshot_name Name of the snapshot that the menu click was over.
3945 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
3947 using namespace Menu_Helpers;
3949 MenuList& items (snapshot_context_menu.items());
3952 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
3954 items.push_back (MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)));
3955 if (!modification_allowed) {
3956 items.back().set_sensitive (false);
3959 items.push_back (MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)));
3960 if (!modification_allowed) {
3961 items.back().set_sensitive (false);
3964 snapshot_context_menu.popup (button, time);
3968 Editor::rename_snapshot (Glib::ustring old_name)
3970 ArdourPrompter prompter(true);
3974 prompter.set_name ("Prompter");
3975 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
3976 prompter.set_prompt (_("New name of snapshot"));
3977 prompter.set_initial_text (old_name);
3979 if (prompter.run() == RESPONSE_ACCEPT) {
3980 prompter.get_result (new_name);
3981 if (new_name.length()) {
3982 session->rename_state (old_name, new_name);
3983 redisplay_snapshots ();
3990 Editor::remove_snapshot (Glib::ustring name)
3992 vector<string> choices;
3994 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
3996 choices.push_back (_("No, do nothing."));
3997 choices.push_back (_("Yes, remove it."));
3999 Gtkmm2ext::Choice prompter (prompt, choices);
4001 if (prompter.run () == 1) {
4002 session->remove_state (name);
4003 redisplay_snapshots ();
4008 Editor::redisplay_snapshots ()
4014 vector<string*>* states;
4016 if ((states = session->possible_states()) == 0) {
4020 snapshot_display_model->clear ();
4022 for (vector<string*>::iterator i = states->begin(); i != states->end(); ++i) {
4023 string statename = *(*i);
4024 TreeModel::Row row = *(snapshot_display_model->append());
4026 /* this lingers on in case we ever want to change the visible
4027 name of the snapshot.
4030 string display_name;
4031 display_name = statename;
4033 if (statename == session->snap_name()) {
4034 snapshot_display.get_selection()->select(row);
4037 row[snapshot_display_columns.visible_name] = display_name;
4038 row[snapshot_display_columns.real_name] = statename;
4045 Editor::session_state_saved (string snap_name)
4047 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
4048 redisplay_snapshots ();
4052 Editor::maximise_editing_space ()
4054 mouse_mode_tearoff->set_visible (false);
4055 tools_tearoff->set_visible (false);
4057 pre_maximal_pane_position = edit_pane.get_position();
4058 pre_maximal_editor_width = this->get_width();
4060 if(post_maximal_pane_position == 0) {
4061 post_maximal_pane_position = edit_pane.get_width();
4066 if(post_maximal_editor_width) {
4067 edit_pane.set_position (post_maximal_pane_position -
4068 abs(post_maximal_editor_width - pre_maximal_editor_width));
4070 edit_pane.set_position (post_maximal_pane_position);
4075 Editor::restore_editing_space ()
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=0, cef=0;
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;