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"
85 #include "analysis_window.h"
91 #include "imageframe_socket_handler.h"
92 /* </CMT Additions> */
96 using namespace ARDOUR;
100 using namespace Gtkmm2ext;
101 using namespace Editing;
105 const double Editor::timebar_height = 15.0;
107 #include "editor_xpms"
109 static const gchar *_snap_type_strings[] = {
131 static const gchar *_snap_mode_strings[] = {
138 static const gchar *_edit_point_strings[] = {
145 static const gchar *_zoom_focus_strings[] = {
155 #ifdef USE_RUBBERBAND
156 static const gchar *_rb_opt_strings[] = {
159 N_("Balanced multitimbral mixture"),
160 N_("Unpitched percussion with stable notes"),
161 N_("Crisp monophonic instrumental"),
162 N_("Unpitched solo percussion"),
167 /* Soundfile drag-n-drop */
169 Gdk::Cursor* Editor::cross_hair_cursor = 0;
170 Gdk::Cursor* Editor::selector_cursor = 0;
171 Gdk::Cursor* Editor::trimmer_cursor = 0;
172 Gdk::Cursor* Editor::grabber_cursor = 0;
173 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
174 Gdk::Cursor* Editor::zoom_cursor = 0;
175 Gdk::Cursor* Editor::time_fx_cursor = 0;
176 Gdk::Cursor* Editor::fader_cursor = 0;
177 Gdk::Cursor* Editor::speaker_cursor = 0;
178 Gdk::Cursor* Editor::wait_cursor = 0;
179 Gdk::Cursor* Editor::timebar_cursor = 0;
180 Gdk::Cursor* Editor::transparent_cursor = 0;
183 show_me_the_size (Requisition* r, const char* what)
185 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
190 /* time display buttons */
191 minsec_label (_("Mins:Secs")),
192 bbt_label (_("Bars:Beats")),
193 smpte_label (_("Timecode")),
194 frame_label (_("Samples")),
195 tempo_label (_("Tempo")),
196 meter_label (_("Meter")),
197 mark_label (_("Location Markers")),
198 range_mark_label (_("Range Markers")),
199 transport_mark_label (_("Loop/Punch Ranges")),
200 cd_mark_label (_("CD Markers")),
202 edit_packer (3, 3, true),
204 /* the values here don't matter: layout widgets
205 reset them as needed.
208 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
209 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
211 /* tool bar related */
213 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
214 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
216 toolbar_selection_clock_table (2,3),
218 automation_mode_button (_("mode")),
219 global_automation_button (_("automation")),
221 /* <CMT Additions> */
222 image_socket_listener(0),
223 /* </CMT Additions> */
227 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
228 meters_running(false)
233 /* we are a singleton */
235 PublicEditor::_instance = this;
239 selection = new Selection;
240 cut_buffer = new Selection;
242 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
243 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
244 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
245 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
246 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
248 clicked_regionview = 0;
249 clicked_trackview = 0;
250 clicked_audio_trackview = 0;
251 clicked_crossfadeview = 0;
252 clicked_control_point = 0;
253 last_update_frame = 0;
255 current_mixer_strip = 0;
256 current_bbt_points = 0;
258 snap_type_strings = I18N (_snap_type_strings);
259 snap_mode_strings = I18N (_snap_mode_strings);
260 zoom_focus_strings = I18N (_zoom_focus_strings);
261 edit_point_strings = I18N (_edit_point_strings);
262 #ifdef USE_RUBBERBAND
263 rb_opt_strings = I18N (_rb_opt_strings);
266 snap_threshold = 5.0;
267 bbt_beat_subdivision = 4;
270 autoscroll_active = false;
271 autoscroll_timeout_tag = -1;
272 interthread_progress_window = 0;
279 current_interthread_info = 0;
280 _show_measures = true;
281 _show_waveforms = true;
282 _show_waveforms_recording = true;
283 first_action_message = 0;
285 export_range_markers_dialog = 0;
286 show_gain_after_trim = false;
287 ignore_route_list_reorder = false;
288 no_route_list_redisplay = false;
289 verbose_cursor_on = true;
290 route_removal = false;
291 show_automatic_regions_in_region_list = true;
292 last_item_entered = 0;
293 last_item_entered_n = 0;
295 region_list_sort_type = (Editing::RegionListSortType) 0;
296 have_pending_keyboard_selection = false;
297 _follow_playhead = true;
298 _xfade_visibility = true;
299 editor_ruler_menu = 0;
300 no_ruler_shown_update = false;
301 edit_group_list_menu = 0;
303 region_list_menu = 0;
305 start_end_marker_menu = 0;
306 range_marker_menu = 0;
307 marker_menu_item = 0;
309 transport_marker_menu = 0;
310 new_transport_marker_menu = 0;
311 editor_mixer_strip_width = Wide;
312 show_editor_mixer_when_tracks_arrive = false;
313 region_edit_menu_split_item = 0;
315 region_edit_menu_split_multichannel_item = 0;
317 ignore_mouse_mode_toggle = false;
318 current_stepping_trackview = 0;
320 entered_regionview = 0;
322 clear_entered_track = false;
323 _new_regionviews_show_envelope = false;
325 in_edit_group_row_change = false;
326 last_canvas_frame = 0;
328 button_release_can_deselect = true;
329 canvas_idle_queued = false;
330 _dragging_playhead = false;
331 _dragging_edit_point = false;
332 _dragging_hscrollbar = false;
333 select_new_marker = false;
334 zoomed_to_region = false;
338 scrubbing_direction = 0;
341 ignore_route_order_sync = false;
343 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
344 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
345 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
346 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
347 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
349 range_marker_drag_rect = 0;
350 marker_drag_line = 0;
352 set_mouse_mode (MouseObject, true);
354 last_visual_state.frames_per_unit = 0;
356 frames_per_unit = 2048; /* too early to use reset_zoom () */
357 reset_hscrollbar_stepping ();
359 zoom_focus = ZoomFocusLeft;
360 set_zoom_focus (ZoomFocusLeft);
361 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
363 initialize_rulers ();
364 initialize_canvas ();
366 edit_controls_vbox.set_spacing (0);
367 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::canvas_horizontally_scrolled), false);
368 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
370 track_canvas.set_hadjustment (horizontal_adjustment);
371 track_canvas.set_vadjustment (vertical_adjustment);
372 time_canvas.set_hadjustment (horizontal_adjustment);
374 track_canvas.signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
375 time_canvas.signal_map_event().connect (mem_fun (*this, &Editor::time_canvas_map_handler));
377 controls_layout.add (edit_controls_vbox);
378 controls_layout.set_name ("EditControlsBase");
379 controls_layout.add_events (Gdk::SCROLL_MASK);
380 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
382 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
383 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
384 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
386 edit_vscrollbar.set_adjustment (vertical_adjustment);
387 edit_hscrollbar.set_adjustment (horizontal_adjustment);
389 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
390 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
391 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
393 edit_hscrollbar.set_name ("EditorHScrollbar");
398 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
400 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
401 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
402 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
403 time_canvas_vbox.pack_start (*frames_ruler, false, false);
404 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
405 time_canvas_vbox.pack_start (time_canvas, true, true);
406 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
408 bbt_label.set_name ("EditorTimeButton");
409 bbt_label.set_size_request (-1, (int)timebar_height);
410 bbt_label.set_alignment (1.0, 0.5);
411 bbt_label.set_padding (5,0);
412 minsec_label.set_name ("EditorTimeButton");
413 minsec_label.set_size_request (-1, (int)timebar_height);
414 minsec_label.set_alignment (1.0, 0.5);
415 minsec_label.set_padding (5,0);
416 smpte_label.set_name ("EditorTimeButton");
417 smpte_label.set_size_request (-1, (int)timebar_height);
418 smpte_label.set_alignment (1.0, 0.5);
419 smpte_label.set_padding (5,0);
420 frame_label.set_name ("EditorTimeButton");
421 frame_label.set_size_request (-1, (int)timebar_height);
422 frame_label.set_alignment (1.0, 0.5);
423 frame_label.set_padding (5,0);
424 tempo_label.set_name ("EditorTimeButton");
425 tempo_label.set_size_request (-1, (int)timebar_height);
426 tempo_label.set_alignment (1.0, 0.5);
427 tempo_label.set_padding (5,0);
428 meter_label.set_name ("EditorTimeButton");
429 meter_label.set_size_request (-1, (int)timebar_height);
430 meter_label.set_alignment (1.0, 0.5);
431 meter_label.set_padding (5,0);
432 mark_label.set_name ("EditorTimeButton");
433 mark_label.set_size_request (-1, (int)timebar_height);
434 mark_label.set_alignment (1.0, 0.5);
435 mark_label.set_padding (5,0);
436 cd_mark_label.set_name ("EditorTimeButton");
437 cd_mark_label.set_size_request (-1, (int)timebar_height);
438 cd_mark_label.set_alignment (1.0, 0.5);
439 cd_mark_label.set_padding (5,0);
440 range_mark_label.set_name ("EditorTimeButton");
441 range_mark_label.set_size_request (-1, (int)timebar_height);
442 range_mark_label.set_alignment (1.0, 0.5);
443 range_mark_label.set_padding (5,0);
444 transport_mark_label.set_name ("EditorTimeButton");
445 transport_mark_label.set_size_request (-1, (int)timebar_height);
446 transport_mark_label.set_alignment (1.0, 0.5);
447 transport_mark_label.set_padding (5,0);
449 time_button_vbox.pack_start (minsec_label, false, false);
450 time_button_vbox.pack_start (smpte_label, false, false);
451 time_button_vbox.pack_start (frame_label, false, false);
452 time_button_vbox.pack_start (bbt_label, false, false);
453 time_button_vbox.pack_start (meter_label, false, false);
454 time_button_vbox.pack_start (tempo_label, false, false);
455 time_button_vbox.pack_start (mark_label, false, false);
457 time_button_event_box.add (time_button_vbox);
459 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
460 time_button_event_box.set_name ("TimebarLabelBase");
461 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
463 time_button_frame.add(time_button_event_box);
464 time_button_frame.property_shadow_type() = Gtk::SHADOW_OUT;
466 /* these enable us to have a dedicated window (for cursor setting, etc.)
467 for the canvas areas.
470 track_canvas_event_box.add (track_canvas);
472 time_canvas_event_box.add (time_canvas_vbox);
473 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
475 edit_packer.set_col_spacings (0);
476 edit_packer.set_row_spacings (0);
477 edit_packer.set_homogeneous (false);
478 edit_packer.set_border_width (0);
479 edit_packer.set_name ("EditorWindow");
481 edit_packer.attach (edit_vscrollbar, 0, 1, 1, 3, FILL, FILL|EXPAND, 0, 0);
483 edit_packer.attach (time_button_frame, 0, 2, 0, 1, FILL, FILL, 0, 0);
484 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
486 edit_packer.attach (controls_layout, 1, 2, 1, 2, FILL, FILL|EXPAND, 0, 0);
487 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 2, FILL|EXPAND, FILL|EXPAND, 0, 0);
489 edit_packer.attach (zoom_box, 1, 2, 2, 3, FILL, FILL, 0, 0);
490 edit_packer.attach (edit_hscrollbar, 2, 3, 2, 3, FILL|EXPAND, FILL, 0, 0);
492 bottom_hbox.set_border_width (2);
493 bottom_hbox.set_spacing (3);
495 route_display_model = ListStore::create(route_display_columns);
496 route_list_display.set_model (route_display_model);
497 route_list_display.append_column (_("Show"), route_display_columns.visible);
498 route_list_display.append_column (_("Name"), route_display_columns.text);
499 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
500 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
501 route_list_display.set_headers_visible (true);
502 route_list_display.set_name ("TrackListDisplay");
503 route_list_display.get_selection()->set_mode (SELECTION_NONE);
504 route_list_display.set_reorderable (true);
505 route_list_display.set_size_request (100,-1);
507 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
508 route_list_visible_cell->property_activatable() = true;
509 route_list_visible_cell->property_radio() = false;
511 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
512 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
513 route_display_model->signal_rows_reordered().connect (mem_fun (*this, &Editor::track_list_reorder));
515 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
517 route_list_scroller.add (route_list_display);
518 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
520 group_model = ListStore::create(group_columns);
521 edit_group_display.set_model (group_model);
522 edit_group_display.append_column (_("Name"), group_columns.text);
523 edit_group_display.append_column (_("Active"), group_columns.is_active);
524 edit_group_display.append_column (_("Show"), group_columns.is_visible);
525 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
526 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
527 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
528 edit_group_display.get_column (0)->set_expand (true);
529 edit_group_display.get_column (1)->set_expand (false);
530 edit_group_display.get_column (2)->set_expand (false);
531 edit_group_display.set_headers_visible (true);
533 /* name is directly editable */
535 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
536 name_cell->property_editable() = true;
537 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
539 /* use checkbox for the active + visible columns */
541 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
542 active_cell->property_activatable() = true;
543 active_cell->property_radio() = false;
545 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
546 active_cell->property_activatable() = true;
547 active_cell->property_radio() = false;
549 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
551 edit_group_display.set_name ("EditGroupList");
552 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
553 edit_group_display.set_headers_visible (true);
554 edit_group_display.set_reorderable (false);
555 edit_group_display.set_rules_hint (true);
556 edit_group_display.set_size_request (75, -1);
558 edit_group_display_scroller.add (edit_group_display);
559 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
561 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
563 VBox* edit_group_display_packer = manage (new VBox());
564 HBox* edit_group_display_button_box = manage (new HBox());
565 edit_group_display_button_box->set_homogeneous (true);
567 Button* edit_group_add_button = manage (new Button ());
568 Button* edit_group_remove_button = manage (new Button ());
572 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
574 edit_group_add_button->add (*w);
576 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
578 edit_group_remove_button->add (*w);
580 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
581 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
583 edit_group_display_button_box->pack_start (*edit_group_add_button);
584 edit_group_display_button_box->pack_start (*edit_group_remove_button);
586 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
587 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
589 region_list_display.set_size_request (100, -1);
590 region_list_display.set_name ("RegionListDisplay");
592 region_list_model = TreeStore::create (region_list_columns);
593 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
594 region_list_model->set_sort_column (0, SORT_ASCENDING);
596 region_list_display.set_model (region_list_model);
597 region_list_display.append_column (_("Regions"), region_list_columns.name);
598 region_list_display.set_headers_visible (false);
600 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
601 region_name_cell->property_editable() = true;
602 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
604 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
606 TreeViewColumn* tv_col = region_list_display.get_column(0);
607 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
608 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
609 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
611 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
612 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
614 /* setup DnD handling */
616 list<TargetEntry> region_list_target_table;
618 region_list_target_table.push_back (TargetEntry ("text/plain"));
619 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
620 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
622 region_list_display.add_drop_targets (region_list_target_table);
623 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
625 region_list_scroller.add (region_list_display);
626 region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
628 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
629 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
630 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
631 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
632 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
633 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
635 named_selection_scroller.add (named_selection_display);
636 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
638 named_selection_model = TreeStore::create (named_selection_columns);
639 named_selection_display.set_model (named_selection_model);
640 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
641 named_selection_display.set_headers_visible (false);
642 named_selection_display.set_size_request (100, -1);
643 named_selection_display.set_name ("NamedSelectionDisplay");
645 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
646 named_selection_display.set_size_request (100, -1);
647 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
648 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
649 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
653 snapshot_display_model = ListStore::create (snapshot_display_columns);
654 snapshot_display.set_model (snapshot_display_model);
655 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
656 snapshot_display.set_name ("SnapshotDisplay");
657 snapshot_display.set_size_request (75, -1);
658 snapshot_display.set_headers_visible (false);
659 snapshot_display.set_reorderable (false);
660 snapshot_display_scroller.add (snapshot_display);
661 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
663 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
664 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
668 nlabel = manage (new Label (_("Regions")));
669 nlabel->set_angle (-90);
670 the_notebook.append_page (region_list_scroller, *nlabel);
671 nlabel = manage (new Label (_("Tracks/Busses")));
672 nlabel->set_angle (-90);
673 the_notebook.append_page (route_list_scroller, *nlabel);
674 nlabel = manage (new Label (_("Snapshots")));
675 nlabel->set_angle (-90);
676 the_notebook.append_page (snapshot_display_scroller, *nlabel);
677 nlabel = manage (new Label (_("Edit Groups")));
678 nlabel->set_angle (-90);
679 the_notebook.append_page (*edit_group_display_packer, *nlabel);
681 if (!Profile->get_sae()) {
682 nlabel = manage (new Label (_("Chunks")));
683 nlabel->set_angle (-90);
684 the_notebook.append_page (named_selection_scroller, *nlabel);
687 the_notebook.set_show_tabs (true);
688 the_notebook.set_scrollable (true);
689 the_notebook.popup_enable ();
690 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
692 post_maximal_editor_width = 0;
693 post_maximal_pane_position = 0;
694 edit_pane.pack1 (edit_packer, true, true);
695 edit_pane.pack2 (the_notebook, false, true);
697 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
699 top_hbox.pack_start (toolbar_frame, true, true);
701 HBox *hbox = manage (new HBox);
702 hbox->pack_start (edit_pane, true, true);
704 global_vpacker.pack_start (top_hbox, false, false);
705 global_vpacker.pack_start (*hbox, true, true);
707 global_hpacker.pack_start (global_vpacker, true, true);
709 set_name ("EditorWindow");
710 add_accel_group (ActionManager::ui_manager->get_accel_group());
712 status_bar_hpacker.show ();
714 vpacker.pack_end (status_bar_hpacker, false, false);
715 vpacker.pack_end (global_hpacker, true, true);
717 /* register actions now so that set_state() can find them and set toggles/checks etc */
721 snap_type = SnapToBeat;
722 set_snap_to (snap_type);
724 set_snap_mode (snap_mode);
725 _edit_point = EditAtMouse;
726 set_edit_point_preference (_edit_point);
728 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
731 _playlist_selector = new PlaylistSelector();
732 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
734 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
738 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
739 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
741 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
742 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
744 nudge_forward_button.set_name ("TransportButton");
745 nudge_backward_button.set_name ("TransportButton");
747 fade_context_menu.set_name ("ArdourContextMenu");
749 /* icons, titles, WM stuff */
751 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
752 Glib::RefPtr<Gdk::Pixbuf> icon;
754 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
755 window_icons.push_back (icon);
757 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
758 window_icons.push_back (icon);
760 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
761 window_icons.push_back (icon);
763 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
764 window_icons.push_back (icon);
766 if (!window_icons.empty()) {
767 set_icon_list (window_icons);
768 set_default_icon_list (window_icons);
771 WindowTitle title(Glib::get_application_name());
772 title += _("Editor");
773 set_title (title.get_string());
774 set_wmclass (X_("ardour_editor"), "Ardour");
777 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
779 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
780 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
782 /* allow external control surfaces/protocols to do various things */
784 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
785 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
786 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
787 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
789 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
790 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
798 /* <CMT Additions> */
799 if(image_socket_listener)
801 if(image_socket_listener->is_connected())
803 image_socket_listener->close_connection() ;
806 delete image_socket_listener ;
807 image_socket_listener = 0 ;
809 /* </CMT Additions> */
813 Editor::add_toplevel_controls (Container& cont)
815 vpacker.pack_start (cont, false, false);
820 Editor::catch_vanishing_regionview (RegionView *rv)
822 /* note: the selection will take care of the vanishing
823 audioregionview by itself.
826 if (clicked_regionview == rv) {
827 clicked_regionview = 0;
830 if (entered_regionview == rv) {
831 set_entered_regionview (0);
836 Editor::set_entered_regionview (RegionView* rv)
838 if (rv == entered_regionview) {
842 if (entered_regionview) {
843 entered_regionview->exited ();
846 if ((entered_regionview = rv) != 0) {
847 entered_regionview->entered ();
852 Editor::set_entered_track (TimeAxisView* tav)
855 entered_track->exited ();
858 if ((entered_track = tav) != 0) {
859 entered_track->entered ();
864 Editor::show_window ()
869 /* now reset all audio_time_axis heights, because widgets might need
875 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
876 tv = (static_cast<TimeAxisView*>(*i));
882 Editor::instant_save ()
884 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
889 session->add_instant_xml(get_state(), session->path());
891 Config->add_instant_xml(get_state(), get_user_ardour_path());
896 Editor::edit_point_clock_changed()
898 if (_dragging_edit_point) {
902 if (selection->markers.empty()) {
907 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
913 loc->move_to (edit_point_clock.current_time());
917 Editor::zoom_adjustment_changed ()
923 double fpu = zoom_range_clock.current_duration() / canvas_width;
927 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
928 } else if (fpu > session->current_end_frame() / canvas_width) {
929 fpu = session->current_end_frame() / canvas_width;
930 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
937 Editor::control_scroll (float fraction)
939 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
945 double step = fraction * current_page_frames();
948 _control_scroll_target is an optional<T>
950 it acts like a pointer to an nframes_t, with
951 a operator conversion to boolean to check
952 that it has a value could possibly use
953 playhead_cursor->current_frame to store the
954 value and a boolean in the class to know
955 when it's out of date
958 if (!_control_scroll_target) {
959 _control_scroll_target = session->transport_frame();
960 _dragging_playhead = true;
963 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes_t) fabs(step))) {
964 *_control_scroll_target = 0;
965 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
966 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
968 *_control_scroll_target += (nframes_t) floor (step);
971 /* move visuals, we'll catch up with it later */
973 playhead_cursor->set_position (*_control_scroll_target);
974 UpdateAllTransportClocks (*_control_scroll_target);
976 if (*_control_scroll_target > (current_page_frames() / 2)) {
977 /* try to center PH in window */
978 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
984 Now we do a timeout to actually bring the session to the right place
985 according to the playhead. This is to avoid reading disk buffers on every
986 call to control_scroll, which is driven by ScrollTimeline and therefore
987 probably by a control surface wheel which can generate lots of events.
989 /* cancel the existing timeout */
991 control_scroll_connection.disconnect ();
993 /* add the next timeout */
995 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
999 Editor::deferred_control_scroll (nframes_t target)
1001 session->request_locate (*_control_scroll_target, session->transport_rolling());
1002 // reset for next stream
1003 _control_scroll_target = boost::none;
1004 _dragging_playhead = false;
1009 Editor::on_realize ()
1011 Window::on_realize ();
1016 Editor::start_scrolling ()
1018 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1019 (mem_fun(*this, &Editor::update_current_screen));
1023 Editor::stop_scrolling ()
1025 scroll_connection.disconnect ();
1029 Editor::map_position_change (nframes_t frame)
1031 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1033 if (session == 0 || !_follow_playhead) {
1037 center_screen (frame);
1038 playhead_cursor->set_position (frame);
1042 Editor::center_screen (nframes_t frame)
1044 double page = canvas_width * frames_per_unit;
1046 /* if we're off the page, then scroll.
1049 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1050 center_screen_internal (frame, page);
1055 Editor::center_screen_internal (nframes_t frame, float page)
1060 frame -= (nframes_t) page;
1065 reset_x_origin (frame);
1069 Editor::handle_new_duration ()
1071 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1073 nframes_t new_end = session->get_maximum_extent() + (nframes_t) floorf (current_page_frames() * 0.10f);
1075 if (new_end > last_canvas_frame) {
1076 last_canvas_frame = new_end;
1077 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1078 reset_scrolling_region ();
1081 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1085 Editor::update_title_s (const string & snap_name)
1087 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1093 Editor::update_title ()
1095 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1098 bool dirty = session->dirty();
1100 string session_name;
1102 if (session->snap_name() != session->name()) {
1103 session_name = session->snap_name();
1105 session_name = session->name();
1109 session_name = "*" + session_name;
1112 WindowTitle title(session_name);
1113 title += Glib::get_application_name();
1114 set_title (title.get_string());
1119 Editor::connect_to_session (Session *t)
1123 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1126 /* catch up with the playhead */
1128 session->request_locate (playhead_cursor->current_frame);
1130 if (first_action_message) {
1131 first_action_message->hide();
1136 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1137 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1139 /* These signals can all be emitted by a non-GUI thread. Therefore the
1140 handlers for them must not attempt to directly interact with the GUI,
1141 but use Gtkmm2ext::UI::instance()->call_slot();
1144 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1145 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1146 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1147 session_connections.push_back (session->AudioRegionsAdded.connect (mem_fun(*this, &Editor::handle_new_audio_regions)));
1148 session_connections.push_back (session->AudioRegionRemoved.connect (mem_fun(*this, &Editor::handle_audio_region_removed)));
1149 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1150 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1151 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1152 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1153 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1154 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1155 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1156 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1157 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1159 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1161 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1163 edit_groups_changed ();
1165 edit_point_clock.set_session (session);
1166 zoom_range_clock.set_session (session);
1167 _playlist_selector->set_session (session);
1168 nudge_clock.set_session (session);
1170 if (rhythm_ferret) {
1171 rhythm_ferret->set_session (session);
1175 if (analysis_window != 0)
1176 analysis_window->set_session (session);
1179 Location* loc = session->locations()->auto_loop_location();
1181 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1182 if (loc->start() == loc->end()) {
1183 loc->set_end (loc->start() + 1);
1185 session->locations()->add (loc, false);
1186 session->set_auto_loop_location (loc);
1189 loc->set_name (_("Loop"));
1192 loc = session->locations()->auto_punch_location();
1194 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1195 if (loc->start() == loc->end()) {
1196 loc->set_end (loc->start() + 1);
1198 session->locations()->add (loc, false);
1199 session->set_auto_punch_location (loc);
1202 loc->set_name (_("Punch"));
1205 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1207 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1209 refresh_location_display ();
1210 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1211 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1212 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1213 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1214 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1217 sfbrowser->set_session (session);
1220 handle_new_duration ();
1222 redisplay_regions ();
1223 redisplay_named_selections ();
1224 redisplay_snapshots ();
1226 initial_route_list_display ();
1228 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1229 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1232 restore_ruler_visibility ();
1233 //tempo_map_changed (Change (0));
1234 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1238 /* don't show master bus in a new session */
1240 if (ARDOUR_UI::instance()->session_is_new ()) {
1242 TreeModel::Children rows = route_display_model->children();
1243 TreeModel::Children::iterator i;
1245 no_route_list_redisplay = true;
1247 for (i = rows.begin(); i != rows.end(); ++i) {
1248 TimeAxisView *tv = (*i)[route_display_columns.tv];
1249 AudioTimeAxisView *atv;
1251 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1252 if (atv->route()->master()) {
1253 route_list_display.get_selection()->unselect (i);
1258 no_route_list_redisplay = false;
1259 redisplay_route_list ();
1262 /* register for undo history */
1264 session->register_with_memento_command_factory(_id, this);
1270 Editor::build_cursors ()
1272 using namespace Gdk;
1274 Gdk::Color mbg ("#000000" ); /* Black */
1275 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1278 RefPtr<Bitmap> source, mask;
1279 source = Bitmap::create (mag_bits, mag_width, mag_height);
1280 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1281 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1284 Gdk::Color fbg ("#ffffff" );
1285 Gdk::Color ffg ("#000000" );
1288 RefPtr<Bitmap> source, mask;
1290 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1291 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1292 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1296 RefPtr<Bitmap> source, mask;
1297 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1298 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1299 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1303 RefPtr<Bitmap> bits;
1304 char pix[4] = { 0, 0, 0, 0 };
1305 bits = Bitmap::create (pix, 2, 2);
1307 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1311 grabber_cursor = new Gdk::Cursor (HAND2);
1314 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1315 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1318 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1319 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1320 selector_cursor = new Gdk::Cursor (XTERM);
1321 time_fx_cursor = new Gdk::Cursor (SIZING);
1322 wait_cursor = new Gdk::Cursor (WATCH);
1323 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1327 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1329 using namespace Menu_Helpers;
1330 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1333 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1337 MenuList& items (fade_context_menu.items());
1341 switch (item_type) {
1343 case FadeInHandleItem:
1344 if (arv->audio_region()->fade_in_active()) {
1345 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1347 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1350 items.push_back (SeparatorElem());
1352 if (Profile->get_sae()) {
1353 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1354 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1356 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1357 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1358 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1359 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1360 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1365 case FadeOutHandleItem:
1366 if (arv->audio_region()->fade_out_active()) {
1367 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1369 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1372 items.push_back (SeparatorElem());
1374 if (Profile->get_sae()) {
1375 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1376 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1378 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1379 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1380 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1381 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1382 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1387 fatal << _("programming error: ")
1388 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1393 fade_context_menu.popup (button, time);
1397 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes_t frame)
1399 using namespace Menu_Helpers;
1400 Menu* (Editor::*build_menu_function)(nframes_t);
1403 switch (item_type) {
1405 case RegionViewName:
1406 case RegionViewNameHighlight:
1407 if (with_selection) {
1408 build_menu_function = &Editor::build_track_selection_context_menu;
1410 build_menu_function = &Editor::build_track_region_context_menu;
1415 if (with_selection) {
1416 build_menu_function = &Editor::build_track_selection_context_menu;
1418 build_menu_function = &Editor::build_track_context_menu;
1422 case CrossfadeViewItem:
1423 build_menu_function = &Editor::build_track_crossfade_context_menu;
1427 if (clicked_audio_trackview->get_diskstream()) {
1428 build_menu_function = &Editor::build_track_context_menu;
1430 build_menu_function = &Editor::build_track_bus_context_menu;
1435 /* probably shouldn't happen but if it does, we don't care */
1439 menu = (this->*build_menu_function)(frame);
1440 menu->set_name ("ArdourContextMenu");
1442 /* now handle specific situations */
1444 switch (item_type) {
1446 case RegionViewName:
1447 case RegionViewNameHighlight:
1448 if (!with_selection) {
1449 if (region_edit_menu_split_item) {
1450 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1451 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1453 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1457 if (region_edit_menu_split_multichannel_item) {
1458 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1459 // GTK2FIX find the action, change its sensitivity
1460 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1462 // GTK2FIX see above
1463 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1472 case CrossfadeViewItem:
1479 /* probably shouldn't happen but if it does, we don't care */
1483 if (item_type != SelectionItem && clicked_audio_trackview && clicked_audio_trackview->audio_track()) {
1485 /* Bounce to disk */
1487 using namespace Menu_Helpers;
1488 MenuList& edit_items = menu->items();
1490 edit_items.push_back (SeparatorElem());
1492 switch (clicked_audio_trackview->audio_track()->freeze_state()) {
1493 case AudioTrack::NoFreeze:
1494 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1497 case AudioTrack::Frozen:
1498 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1501 case AudioTrack::UnFrozen:
1502 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1508 menu->popup (button, time);
1512 Editor::build_track_context_menu (nframes_t ignored)
1514 using namespace Menu_Helpers;
1516 MenuList& edit_items = track_context_menu.items();
1519 add_dstream_context_items (edit_items);
1520 return &track_context_menu;
1524 Editor::build_track_bus_context_menu (nframes_t ignored)
1526 using namespace Menu_Helpers;
1528 MenuList& edit_items = track_context_menu.items();
1531 add_bus_context_items (edit_items);
1532 return &track_context_menu;
1536 Editor::build_track_region_context_menu (nframes_t frame)
1538 using namespace Menu_Helpers;
1539 MenuList& edit_items = track_region_context_menu.items();
1542 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1545 boost::shared_ptr<Diskstream> ds;
1546 boost::shared_ptr<Playlist> pl;
1548 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
1549 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)frame * ds->speed()));
1550 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1551 add_region_context_items (atv->audio_view(), (*i), edit_items);
1557 add_dstream_context_items (edit_items);
1559 return &track_region_context_menu;
1563 Editor::build_track_crossfade_context_menu (nframes_t frame)
1565 using namespace Menu_Helpers;
1566 MenuList& edit_items = track_crossfade_context_menu.items();
1567 edit_items.clear ();
1569 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1572 boost::shared_ptr<Diskstream> ds;
1573 boost::shared_ptr<Playlist> pl;
1574 boost::shared_ptr<AudioPlaylist> apl;
1576 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1578 Playlist::RegionList* regions = pl->regions_at (frame);
1579 AudioPlaylist::Crossfades xfades;
1581 apl->crossfades_at (frame, xfades);
1583 bool many = xfades.size() > 1;
1585 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1586 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1589 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1590 add_region_context_items (atv->audio_view(), (*i), edit_items);
1597 add_dstream_context_items (edit_items);
1599 return &track_crossfade_context_menu;
1604 Editor::analyze_region_selection()
1606 if (analysis_window == 0) {
1607 analysis_window = new AnalysisWindow();
1610 analysis_window->set_session(session);
1612 analysis_window->show_all();
1615 analysis_window->set_regionmode();
1616 analysis_window->analyze();
1618 analysis_window->present();
1622 Editor::analyze_range_selection()
1624 if (analysis_window == 0) {
1625 analysis_window = new AnalysisWindow();
1628 analysis_window->set_session(session);
1630 analysis_window->show_all();
1633 analysis_window->set_rangemode();
1634 analysis_window->analyze();
1636 analysis_window->present();
1638 #endif /* FFT_ANALYSIS */
1643 Editor::build_track_selection_context_menu (nframes_t ignored)
1645 using namespace Menu_Helpers;
1646 MenuList& edit_items = track_selection_context_menu.items();
1647 edit_items.clear ();
1649 add_selection_context_items (edit_items);
1650 // edit_items.push_back (SeparatorElem());
1651 // add_dstream_context_items (edit_items);
1653 return &track_selection_context_menu;
1657 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1659 using namespace Menu_Helpers;
1660 Menu *xfade_menu = manage (new Menu);
1661 MenuList& items = xfade_menu->items();
1662 xfade_menu->set_name ("ArdourContextMenu");
1665 if (xfade->active()) {
1671 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1672 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1674 if (xfade->can_follow_overlap()) {
1676 if (xfade->following_overlap()) {
1677 str = _("Convert to short");
1679 str = _("Convert to full");
1682 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1686 str = xfade->out()->name();
1688 str += xfade->in()->name();
1690 str = _("Crossfade");
1693 edit_items.push_back (MenuElem (str, *xfade_menu));
1694 edit_items.push_back (SeparatorElem());
1698 Editor::xfade_edit_left_region ()
1700 if (clicked_crossfadeview) {
1701 clicked_crossfadeview->left_view.show_region_editor ();
1706 Editor::xfade_edit_right_region ()
1708 if (clicked_crossfadeview) {
1709 clicked_crossfadeview->right_view.show_region_editor ();
1714 Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1716 using namespace Menu_Helpers;
1717 Menu *region_menu = manage (new Menu);
1718 MenuList& items = region_menu->items();
1719 region_menu->set_name ("ArdourContextMenu");
1721 boost::shared_ptr<AudioRegion> ar;
1724 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1727 /* when this particular menu pops up, make the relevant region
1731 region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1733 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1734 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1735 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1736 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1737 items.push_back (SeparatorElem());
1738 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1739 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1740 items.push_back (SeparatorElem());
1742 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1743 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1744 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1747 items.push_back (MenuElem (_("Analyze region"), mem_fun(*this, &Editor::analyze_region_selection)));
1750 items.push_back (SeparatorElem());
1752 sigc::connection fooc;
1754 items.push_back (CheckMenuElem (_("Lock")));
1755 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1756 if (region->locked()) {
1757 region_lock_item->set_active();
1759 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1761 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1762 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1764 switch (region->positional_lock_style()) {
1765 case Region::MusicTime:
1766 bbt_glue_item->set_active (true);
1769 bbt_glue_item->set_active (false);
1773 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1775 items.push_back (CheckMenuElem (_("Mute")));
1776 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1777 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1778 if (region->muted()) {
1780 region_mute_item->set_active();
1784 if (!Profile->get_sae()) {
1785 items.push_back (CheckMenuElem (_("Opaque")));
1786 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1787 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1788 if (region->opaque()) {
1790 region_opaque_item->set_active();
1795 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1796 if (region->at_natural_position()) {
1797 items.back().set_sensitive (false);
1800 items.push_back (SeparatorElem());
1804 RegionView* rv = sv->find_view (ar);
1805 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1807 if (!Profile->get_sae()) {
1808 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1810 items.push_back (CheckMenuElem (_("Envelope Visible")));
1811 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1812 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1813 if (arv->envelope_visible()) {
1815 region_envelope_visible_item->set_active (true);
1819 items.push_back (CheckMenuElem (_("Envelope Active")));
1820 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1821 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1823 if (ar->envelope_active()) {
1825 region_envelope_active_item->set_active (true);
1829 items.push_back (SeparatorElem());
1832 if (ar->scale_amplitude() != 1.0f) {
1833 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1835 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1839 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1840 items.push_back (SeparatorElem());
1842 /* range related stuff */
1844 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1845 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_audio_region)));
1846 items.push_back (SeparatorElem());
1850 Menu *nudge_menu = manage (new Menu());
1851 MenuList& nudge_items = nudge_menu->items();
1852 nudge_menu->set_name ("ArdourContextMenu");
1854 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1855 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1856 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1857 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1859 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1860 items.push_back (SeparatorElem());
1862 Menu *trim_menu = manage (new Menu);
1863 MenuList& trim_items = trim_menu->items();
1864 trim_menu->set_name ("ArdourContextMenu");
1866 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1867 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1868 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1869 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1871 items.push_back (MenuElem (_("Trim"), *trim_menu));
1872 items.push_back (SeparatorElem());
1874 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1875 region_edit_menu_split_item = &items.back();
1877 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1878 region_edit_menu_split_multichannel_item = &items.back();
1880 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1881 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1882 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1883 items.push_back (SeparatorElem());
1884 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_clicked_region)));
1886 /* OK, stick the region submenu at the top of the list, and then add
1890 /* we have to hack up the region name because "_" has a special
1891 meaning for menu titles.
1894 string::size_type pos = 0;
1895 string menu_item_name = region->name();
1897 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1898 menu_item_name.replace (pos, 1, "__");
1902 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1903 edit_items.push_back (SeparatorElem());
1907 Editor::add_selection_context_items (Menu_Helpers::MenuList& items)
1909 using namespace Menu_Helpers;
1911 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
1912 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
1915 items.push_back (SeparatorElem());
1916 items.push_back (MenuElem (_("Analyze range"), mem_fun(*this, &Editor::analyze_range_selection)));
1919 items.push_back (SeparatorElem());
1920 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1921 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1923 items.push_back (SeparatorElem());
1924 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
1925 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
1927 items.push_back (SeparatorElem());
1928 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1930 items.push_back (SeparatorElem());
1931 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
1932 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
1934 items.push_back (SeparatorElem());
1935 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
1936 items.push_back (SeparatorElem());
1937 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
1938 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
1939 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
1940 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
1941 items.push_back (SeparatorElem());
1942 items.push_back (MenuElem (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection)));
1943 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
1947 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1949 using namespace Menu_Helpers;
1953 Menu *play_menu = manage (new Menu);
1954 MenuList& play_items = play_menu->items();
1955 play_menu->set_name ("ArdourContextMenu");
1957 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
1958 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
1959 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
1960 play_items.push_back (SeparatorElem());
1961 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
1963 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1967 Menu *select_menu = manage (new Menu);
1968 MenuList& select_items = select_menu->items();
1969 select_menu->set_name ("ArdourContextMenu");
1971 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1972 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
1973 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
1974 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
1975 select_items.push_back (SeparatorElem());
1976 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
1977 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
1978 select_items.push_back (SeparatorElem());
1979 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1980 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1981 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1982 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1983 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
1984 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
1985 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
1987 select_items.push_back (SeparatorElem());
1989 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1993 Menu *cutnpaste_menu = manage (new Menu);
1994 MenuList& cutnpaste_items = cutnpaste_menu->items();
1995 cutnpaste_menu->set_name ("ArdourContextMenu");
1997 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
1998 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
1999 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2001 cutnpaste_items.push_back (SeparatorElem());
2003 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2004 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2006 cutnpaste_items.push_back (SeparatorElem());
2008 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2010 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2012 /* Adding new material */
2014 edit_items.push_back (SeparatorElem());
2015 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2016 edit_items.push_back (MenuElem (_("Insert Existing Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2020 Menu *nudge_menu = manage (new Menu());
2021 MenuList& nudge_items = nudge_menu->items();
2022 nudge_menu->set_name ("ArdourContextMenu");
2024 edit_items.push_back (SeparatorElem());
2025 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2026 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2027 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2028 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2030 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2034 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2036 using namespace Menu_Helpers;
2040 Menu *play_menu = manage (new Menu);
2041 MenuList& play_items = play_menu->items();
2042 play_menu->set_name ("ArdourContextMenu");
2044 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2045 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2046 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2050 Menu *select_menu = manage (new Menu);
2051 MenuList& select_items = select_menu->items();
2052 select_menu->set_name ("ArdourContextMenu");
2054 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2055 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2056 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2057 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2058 select_items.push_back (SeparatorElem());
2059 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2060 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2061 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2062 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2064 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2068 Menu *cutnpaste_menu = manage (new Menu);
2069 MenuList& cutnpaste_items = cutnpaste_menu->items();
2070 cutnpaste_menu->set_name ("ArdourContextMenu");
2072 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2073 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2074 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2076 Menu *nudge_menu = manage (new Menu());
2077 MenuList& nudge_items = nudge_menu->items();
2078 nudge_menu->set_name ("ArdourContextMenu");
2080 edit_items.push_back (SeparatorElem());
2081 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2082 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2083 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2084 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2086 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2089 /* CURSOR SETTING AND MARKS AND STUFF */
2092 Editor::set_snap_to (SnapType st)
2094 unsigned int snap_ind = (unsigned int)st;
2097 if ( snap_ind > snap_type_strings.size() - 1 ) {
2099 snap_type = (SnapType)snap_ind;
2102 string str = snap_type_strings[snap_ind];
2104 if (str != snap_type_selector.get_active_text()) {
2105 snap_type_selector.set_active_text (str);
2110 switch (snap_type) {
2111 case SnapToAThirtysecondBeat:
2112 case SnapToASixteenthBeat:
2113 case SnapToAEighthBeat:
2114 case SnapToAQuarterBeat:
2115 case SnapToAThirdBeat:
2116 update_tempo_based_rulers ();
2124 Editor::set_snap_mode (SnapMode mode)
2127 string str = snap_mode_strings[(int)mode];
2129 if (str != snap_mode_selector.get_active_text ()) {
2130 snap_mode_selector.set_active_text (str);
2136 Editor::set_edit_point_preference (EditPoint ep)
2138 bool changed = _edit_point != ep;
2141 string str = edit_point_strings[(int)ep];
2143 if (str != edit_point_selector.get_active_text ()) {
2144 edit_point_selector.set_active_text (str);
2147 set_canvas_cursor ();
2153 if (Profile->get_sae()) {
2155 switch (zoom_focus) {
2156 case ZoomFocusMouse:
2157 case ZoomFocusPlayhead:
2159 switch (_edit_point) {
2161 set_zoom_focus (ZoomFocusMouse);
2163 case EditAtPlayhead:
2164 set_zoom_focus (ZoomFocusPlayhead);
2166 case EditAtSelectedMarker:
2167 set_zoom_focus (ZoomFocusEdit);
2180 Editor::set_state (const XMLNode& node)
2182 const XMLProperty* prop;
2184 int x, y, xoff, yoff;
2187 if ((prop = node.property ("id")) != 0) {
2188 _id = prop->value ();
2191 if ((geometry = find_named_node (node, "geometry")) == 0) {
2193 g.base_width = default_width;
2194 g.base_height = default_height;
2202 g.base_width = atoi(geometry->property("x_size")->value());
2203 g.base_height = atoi(geometry->property("y_size")->value());
2204 x = atoi(geometry->property("x_pos")->value());
2205 y = atoi(geometry->property("y_pos")->value());
2206 xoff = atoi(geometry->property("x_off")->value());
2207 yoff = atoi(geometry->property("y_off")->value());
2210 set_default_size (g.base_width, g.base_height);
2213 if (session && (prop = node.property ("playhead"))) {
2214 nframes_t pos = atol (prop->value().c_str());
2215 playhead_cursor->set_position (pos);
2217 playhead_cursor->set_position (0);
2219 /* reset_x_origin() doesn't work right here, since the old
2220 position may be zero already, and it does nothing in such
2225 horizontal_adjustment.set_value (0);
2228 if ((prop = node.property ("mixer-width"))) {
2229 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2232 if ((prop = node.property ("zoom-focus"))) {
2233 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2236 if ((prop = node.property ("zoom"))) {
2237 reset_zoom (PBD::atof (prop->value()));
2240 if ((prop = node.property ("snap-to"))) {
2241 set_snap_to ((SnapType) atoi (prop->value()));
2244 if ((prop = node.property ("snap-mode"))) {
2245 set_snap_mode ((SnapMode) atoi (prop->value()));
2248 if ((prop = node.property ("edit-point"))) {
2249 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point));
2252 if ((prop = node.property ("mouse-mode"))) {
2253 MouseMode m = str2mousemode(prop->value());
2254 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2255 set_mouse_mode (m, true);
2257 mouse_mode = MouseGain; /* lie, to force the mode switch */
2258 set_mouse_mode (MouseObject, true);
2261 if ((prop = node.property ("show-waveforms"))) {
2262 bool yn = (prop->value() == "yes");
2263 _show_waveforms = !yn;
2264 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformVisibility"));
2266 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2267 /* do it twice to force the change */
2268 tact->set_active (!yn);
2269 tact->set_active (yn);
2273 if ((prop = node.property ("show-waveforms-recording"))) {
2274 bool yn = (prop->value() == "yes");
2275 _show_waveforms_recording = !yn;
2276 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2278 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2279 /* do it twice to force the change */
2280 tact->set_active (!yn);
2281 tact->set_active (yn);
2285 if ((prop = node.property ("show-measures"))) {
2286 bool yn = (prop->value() == "yes");
2287 _show_measures = !yn;
2288 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2290 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2291 /* do it twice to force the change */
2292 tact->set_active (!yn);
2293 tact->set_active (yn);
2297 if ((prop = node.property ("follow-playhead"))) {
2298 bool yn = (prop->value() == "yes");
2299 set_follow_playhead (yn);
2300 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2302 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2303 if (tact->get_active() != yn) {
2304 tact->set_active (yn);
2309 if ((prop = node.property ("region-list-sort-type"))) {
2310 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2311 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2314 if ((prop = node.property ("xfades-visible"))) {
2315 bool yn = (prop->value() == "yes");
2316 _xfade_visibility = !yn;
2317 // set_xfade_visibility (yn);
2320 if ((prop = node.property ("show-editor-mixer"))) {
2322 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2325 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2326 bool yn = (prop->value() == X_("yes"));
2328 /* do it twice to force the change */
2330 tact->set_active (!yn);
2331 tact->set_active (yn);
2340 Editor::get_state ()
2342 XMLNode* node = new XMLNode ("Editor");
2345 _id.print (buf, sizeof (buf));
2346 node->add_property ("id", buf);
2348 if (is_realized()) {
2349 Glib::RefPtr<Gdk::Window> win = get_window();
2351 int x, y, xoff, yoff, width, height;
2352 win->get_root_origin(x, y);
2353 win->get_position(xoff, yoff);
2354 win->get_size(width, height);
2356 XMLNode* geometry = new XMLNode ("geometry");
2358 snprintf(buf, sizeof(buf), "%d", width);
2359 geometry->add_property("x_size", string(buf));
2360 snprintf(buf, sizeof(buf), "%d", height);
2361 geometry->add_property("y_size", string(buf));
2362 snprintf(buf, sizeof(buf), "%d", x);
2363 geometry->add_property("x_pos", string(buf));
2364 snprintf(buf, sizeof(buf), "%d", y);
2365 geometry->add_property("y_pos", string(buf));
2366 snprintf(buf, sizeof(buf), "%d", xoff);
2367 geometry->add_property("x_off", string(buf));
2368 snprintf(buf, sizeof(buf), "%d", yoff);
2369 geometry->add_property("y_off", string(buf));
2370 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2371 geometry->add_property("edit_pane_pos", string(buf));
2373 node->add_child_nocopy (*geometry);
2376 maybe_add_mixer_strip_width (*node);
2378 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2379 node->add_property ("zoom-focus", buf);
2380 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2381 node->add_property ("zoom", buf);
2382 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2383 node->add_property ("snap-to", buf);
2384 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2385 node->add_property ("snap-mode", buf);
2387 node->add_property ("edit-point", enum_2_string (_edit_point));
2389 snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
2390 node->add_property ("playhead", buf);
2392 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2393 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2394 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2395 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2396 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2397 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2398 node->add_property ("mouse-mode", enum2str(mouse_mode));
2400 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2402 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2403 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2412 Editor::trackview_by_y_position (double y)
2414 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2418 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2427 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2429 Location* before = 0;
2430 Location* after = 0;
2432 if (!session || snap_mode == SnapOff) {
2436 const nframes64_t one_second = session->frame_rate();
2437 const nframes64_t one_minute = session->frame_rate() * 60;
2438 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2439 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2440 nframes64_t presnap = start;
2442 switch (snap_type) {
2445 start = (nframes_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2447 start = (nframes_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2451 case SnapToSMPTEFrame:
2452 if (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2)) {
2453 start = (nframes_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2455 start = (nframes_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2459 case SnapToSMPTESeconds:
2460 if (session->smpte_offset_negative())
2462 start += session->smpte_offset ();
2464 start -= session->smpte_offset ();
2466 if (start % one_smpte_second > one_smpte_second / 2) {
2467 start = (nframes_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2469 start = (nframes_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2472 if (session->smpte_offset_negative())
2474 start -= session->smpte_offset ();
2476 start += session->smpte_offset ();
2480 case SnapToSMPTEMinutes:
2481 if (session->smpte_offset_negative())
2483 start += session->smpte_offset ();
2485 start -= session->smpte_offset ();
2487 if (start % one_smpte_minute > one_smpte_minute / 2) {
2488 start = (nframes_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2490 start = (nframes_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2492 if (session->smpte_offset_negative())
2494 start -= session->smpte_offset ();
2496 start += session->smpte_offset ();
2501 if (start % one_second > one_second / 2) {
2502 start = (nframes_t) ceil ((double) start / one_second) * one_second;
2504 start = (nframes_t) floor ((double) start / one_second) * one_second;
2509 if (start % one_minute > one_minute / 2) {
2510 start = (nframes_t) ceil ((double) start / one_minute) * one_minute;
2512 start = (nframes_t) floor ((double) start / one_minute) * one_minute;
2517 start = session->tempo_map().round_to_bar (start, direction);
2521 start = session->tempo_map().round_to_beat (start, direction);
2524 case SnapToAThirtysecondBeat:
2525 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2528 case SnapToASixteenthBeat:
2529 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2532 case SnapToAEighthBeat:
2533 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2536 case SnapToAQuarterBeat:
2537 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2540 case SnapToAThirdBeat:
2541 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2549 before = session->locations()->first_location_before (start);
2550 after = session->locations()->first_location_after (start);
2552 if (direction < 0) {
2554 start = before->start();
2558 } else if (direction > 0) {
2560 start = after->start();
2562 start = session->current_end_frame();
2567 /* find nearest of the two */
2568 if ((start - before->start()) < (after->start() - start)) {
2569 start = before->start();
2571 start = after->start();
2574 start = before->start();
2577 start = after->start();
2584 case SnapToRegionStart:
2585 case SnapToRegionEnd:
2586 case SnapToRegionSync:
2587 case SnapToRegionBoundary:
2588 if (!region_boundary_cache.empty()) {
2589 vector<nframes_t>::iterator i;
2591 if (direction > 0) {
2592 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2594 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2597 if (i != region_boundary_cache.end()) {
2600 start = region_boundary_cache.back();
2606 switch (snap_mode) {
2612 if (presnap > start) {
2613 if (presnap > (start + unit_to_frame(snap_threshold))) {
2617 } else if (presnap < start) {
2618 if (presnap < (start - unit_to_frame(snap_threshold))) {
2624 /* handled at entry */
2631 Editor::setup_toolbar ()
2636 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2638 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2641 /* Mode Buttons (tool selection) */
2643 vector<ToggleButton *> mouse_mode_buttons;
2645 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2646 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2647 mouse_mode_buttons.push_back (&mouse_move_button);
2649 if (!Profile->get_sae()) {
2650 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2651 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2652 mouse_mode_buttons.push_back (&mouse_select_button);
2654 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2655 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2656 mouse_mode_buttons.push_back (&mouse_gain_button);
2659 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2660 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2661 mouse_mode_buttons.push_back (&mouse_zoom_button);
2662 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2663 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2664 mouse_mode_buttons.push_back (&mouse_timefx_button);
2665 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2666 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2667 mouse_mode_buttons.push_back (&mouse_audition_button);
2669 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2671 HBox* mode_box = manage(new HBox);
2672 mode_box->set_border_width (2);
2673 mode_box->set_spacing(4);
2674 mouse_mode_button_box.set_spacing(1);
2675 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2676 if (!Profile->get_sae()) {
2677 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2679 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2680 if (!Profile->get_sae()) {
2681 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2683 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2684 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2685 mouse_mode_button_box.set_homogeneous(true);
2687 vector<string> edit_mode_strings;
2688 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2689 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2690 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2692 edit_mode_selector.set_name ("EditModeSelector");
2693 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2694 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2695 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2697 mode_box->pack_start(edit_mode_selector);
2698 mode_box->pack_start(mouse_mode_button_box);
2700 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2701 mouse_mode_tearoff->set_name ("MouseModeBase");
2703 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2704 &mouse_mode_tearoff->tearoff_window()));
2705 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2706 &mouse_mode_tearoff->tearoff_window(), 1));
2707 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2708 &mouse_mode_tearoff->tearoff_window()));
2709 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2710 &mouse_mode_tearoff->tearoff_window(), 1));
2712 mouse_move_button.set_name ("MouseModeButton");
2713 mouse_select_button.set_name ("MouseModeButton");
2714 mouse_gain_button.set_name ("MouseModeButton");
2715 mouse_zoom_button.set_name ("MouseModeButton");
2716 mouse_timefx_button.set_name ("MouseModeButton");
2717 mouse_audition_button.set_name ("MouseModeButton");
2719 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2720 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2721 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2722 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2723 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2724 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2726 mouse_move_button.unset_flags (CAN_FOCUS);
2727 mouse_select_button.unset_flags (CAN_FOCUS);
2728 mouse_gain_button.unset_flags (CAN_FOCUS);
2729 mouse_zoom_button.unset_flags (CAN_FOCUS);
2730 mouse_timefx_button.unset_flags (CAN_FOCUS);
2731 mouse_audition_button.unset_flags (CAN_FOCUS);
2733 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2734 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2736 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2737 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2738 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2739 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2740 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2742 // mouse_move_button.set_active (true);
2747 zoom_box.set_spacing (1);
2748 zoom_box.set_border_width (2);
2750 zoom_in_button.set_name ("EditorTimeButton");
2751 zoom_in_button.set_size_request(-1,16);
2752 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2753 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2754 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2756 zoom_out_button.set_name ("EditorTimeButton");
2757 zoom_out_button.set_size_request(-1,16);
2758 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2759 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2760 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2762 zoom_out_full_button.set_name ("EditorTimeButton");
2763 zoom_out_full_button.set_size_request(-1,16);
2764 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2765 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2766 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2768 zoom_focus_selector.set_name ("ZoomFocusSelector");
2769 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
2770 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
2771 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2772 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2774 zoom_box.pack_start (zoom_focus_selector, true, true);
2775 zoom_box.pack_start (zoom_out_button, false, false);
2776 zoom_box.pack_start (zoom_in_button, false, false);
2777 zoom_box.pack_start (zoom_out_full_button, false, false);
2779 snap_box.set_spacing (1);
2780 snap_box.set_border_width (2);
2782 snap_type_selector.set_name ("SnapTypeSelector");
2783 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
2784 set_popdown_strings (snap_type_selector, snap_type_strings);
2785 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2786 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2788 snap_mode_selector.set_name ("SnapModeSelector");
2789 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
2790 set_popdown_strings (snap_mode_selector, snap_mode_strings);
2791 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2792 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2794 edit_point_selector.set_name ("SnapModeSelector");
2795 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
2796 set_popdown_strings (edit_point_selector, edit_point_strings);
2797 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2798 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2800 snap_box.pack_start (edit_point_clock, false, false);
2801 snap_box.pack_start (snap_mode_selector, false, false);
2802 snap_box.pack_start (snap_type_selector, false, false);
2803 snap_box.pack_start (edit_point_selector, false, false);
2807 HBox *nudge_box = manage (new HBox);
2808 nudge_box->set_spacing(1);
2809 nudge_box->set_border_width (2);
2811 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
2812 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
2814 nudge_box->pack_start (nudge_backward_button, false, false);
2815 nudge_box->pack_start (nudge_forward_button, false, false);
2816 nudge_box->pack_start (nudge_clock, false, false);
2819 /* Pack everything in... */
2821 HBox* hbox = new HBox;
2822 hbox->set_spacing(10);
2824 tools_tearoff = new TearOff (*hbox);
2825 tools_tearoff->set_name ("MouseModeBase");
2827 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2828 &tools_tearoff->tearoff_window()));
2829 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2830 &tools_tearoff->tearoff_window(), 0));
2831 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2832 &tools_tearoff->tearoff_window()));
2833 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2834 &tools_tearoff->tearoff_window(), 0));
2836 toolbar_hbox.set_spacing (10);
2837 toolbar_hbox.set_border_width (1);
2839 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2840 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2843 hbox->pack_start (snap_box, false, false);
2844 // hbox->pack_start (zoom_box, false, false);
2845 hbox->pack_start (*nudge_box, false, false);
2849 toolbar_base.set_name ("ToolBarBase");
2850 toolbar_base.add (toolbar_hbox);
2852 toolbar_frame.set_shadow_type (SHADOW_OUT);
2853 toolbar_frame.set_name ("BaseFrame");
2854 toolbar_frame.add (toolbar_base);
2858 Editor::convert_drop_to_paths (vector<ustring>& paths,
2859 const RefPtr<Gdk::DragContext>& context,
2862 const SelectionData& data,
2871 vector<ustring> uris = data.get_uris();
2875 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
2876 are actually URI lists. So do it by hand.
2879 if (data.get_target() != "text/plain") {
2883 /* Parse the "uri-list" format that Nautilus provides,
2884 where each pathname is delimited by \r\n
2887 const char* p = data.get_text().c_str();
2894 while (g_ascii_isspace (*p))
2898 while (*q && (*q != '\n') && (*q != '\r'))
2904 while (q > p && g_ascii_isspace (*q))
2909 uris.push_back (ustring (p, q - p + 1));
2913 p = strchr (p, '\n');
2923 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
2925 if ((*i).substr (0,7) == "file://") {
2929 PBD::url_decode (p);
2931 // scan forward past three slashes
2933 ustring::size_type slashcnt = 0;
2934 ustring::size_type n = 0;
2935 ustring::iterator x = p.begin();
2937 while (slashcnt < 3 && x != p.end()) {
2940 } else if (slashcnt == 3) {
2947 if (slashcnt != 3 || x == p.end()) {
2948 error << _("malformed URL passed to drag-n-drop code") << endmsg;
2952 paths.push_back (p.substr (n - 1));
2960 Editor::new_tempo_section ()
2966 Editor::map_transport_state ()
2968 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
2970 if (session->transport_stopped()) {
2971 have_pending_keyboard_selection = false;
2974 update_loop_range_view (true);
2979 Editor::State::State ()
2981 selection = new Selection;
2984 Editor::State::~State ()
2990 Editor::get_memento () const
2992 State *state = new State;
2994 store_state (*state);
2995 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
2999 Editor::store_state (State& state) const
3001 *state.selection = *selection;
3005 Editor::restore_state (State *state)
3007 if (*selection == *state->selection) {
3011 *selection = *state->selection;
3012 time_selection_changed ();
3013 region_selection_changed ();
3015 /* XXX other selection change handlers? */
3019 Editor::begin_reversible_command (string name)
3022 // before = &get_state();
3023 session->begin_reversible_command (name);
3028 Editor::commit_reversible_command ()
3031 // session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3032 session->commit_reversible_command ();
3037 Editor::set_edit_group_solo (Route& route, bool yn)
3039 RouteGroup *edit_group;
3041 if ((edit_group = route.edit_group()) != 0) {
3042 edit_group->apply (&Route::set_solo, yn, this);
3044 route.set_solo (yn, this);
3049 Editor::set_edit_group_mute (Route& route, bool yn)
3051 RouteGroup *edit_group = 0;
3053 if ((edit_group == route.edit_group()) != 0) {
3054 edit_group->apply (&Route::set_mute, yn, this);
3056 route.set_mute (yn, this);
3061 Editor::history_changed ()
3065 if (undo_action && session) {
3066 if (session->undo_depth() == 0) {
3069 label = string_compose(_("Undo (%1)"), session->next_undo());
3071 undo_action->property_label() = label;
3074 if (redo_action && session) {
3075 if (session->redo_depth() == 0) {
3078 label = string_compose(_("Redo (%1)"), session->next_redo());
3080 redo_action->property_label() = label;
3085 Editor::duplicate_dialog (bool with_dialog)
3089 if (mouse_mode == MouseRange) {
3090 if (selection->time.length() == 0) {
3096 get_regions_for_action (rs);
3098 if (mouse_mode != MouseRange) {
3107 ArdourDialog win ("Duplication Dialog");
3108 Label label (_("Number of Duplications:"));
3109 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3110 SpinButton spinner (adjustment, 0.0, 1);
3113 win.get_vbox()->set_spacing (12);
3114 win.get_vbox()->pack_start (hbox);
3115 hbox.set_border_width (6);
3116 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3118 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3119 place, visually. so do this by hand.
3122 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3123 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3124 spinner.grab_focus();
3130 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3131 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3132 win.set_default_response (RESPONSE_ACCEPT);
3134 win.set_position (WIN_POS_MOUSE);
3136 spinner.grab_focus ();
3138 switch (win.run ()) {
3139 case RESPONSE_ACCEPT:
3145 times = adjustment.get_value();
3148 if (mouse_mode == MouseRange) {
3149 duplicate_selection (times);
3151 duplicate_some_regions (rs, times);
3156 Editor::show_verbose_canvas_cursor ()
3158 verbose_canvas_cursor->raise_to_top();
3159 verbose_canvas_cursor->show();
3160 verbose_cursor_visible = true;
3164 Editor::hide_verbose_canvas_cursor ()
3166 verbose_canvas_cursor->hide();
3167 verbose_cursor_visible = false;
3171 Editor::clamp_verbose_cursor_x (double x)
3173 return min (horizontal_adjustment.get_value() + canvas_width - 75.0, x);
3177 Editor::clamp_verbose_cursor_y (double y)
3179 return min (vertical_adjustment.get_value() + canvas_height - 50.0, y);
3183 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3185 verbose_canvas_cursor->property_text() = txt.c_str();
3186 /* don't get too close to the edge */
3187 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3188 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_x (y);
3192 Editor::set_verbose_canvas_cursor_text (const string & txt)
3194 verbose_canvas_cursor->property_text() = txt.c_str();
3198 Editor::set_edit_mode (EditMode m)
3200 Config->set_edit_mode (m);
3204 Editor::cycle_edit_mode ()
3206 switch (Config->get_edit_mode()) {
3208 Config->set_edit_mode (Splice);
3211 Config->set_edit_mode (Lock);
3214 Config->set_edit_mode (Slide);
3220 Editor::edit_mode_selection_done ()
3226 string choice = edit_mode_selector.get_active_text();
3227 EditMode mode = Slide;
3229 if (choice == _("Splice Edit")) {
3231 } else if (choice == _("Slide Edit")) {
3233 } else if (choice == _("Lock Edit")) {
3237 Config->set_edit_mode (mode);
3241 Editor::snap_type_selection_done ()
3243 string choice = snap_type_selector.get_active_text();
3244 SnapType snaptype = SnapToBeat;
3246 if (choice == _("Beats/3")) {
3247 snaptype = SnapToAThirdBeat;
3248 } else if (choice == _("Beats/4")) {
3249 snaptype = SnapToAQuarterBeat;
3250 } else if (choice == _("Beats/8")) {
3251 snaptype = SnapToAEighthBeat;
3252 } else if (choice == _("Beats/16")) {
3253 snaptype = SnapToASixteenthBeat;
3254 } else if (choice == _("Beats/32")) {
3255 snaptype = SnapToAThirtysecondBeat;
3256 } else if (choice == _("Beats")) {
3257 snaptype = SnapToBeat;
3258 } else if (choice == _("Bars")) {
3259 snaptype = SnapToBar;
3260 } else if (choice == _("Marks")) {
3261 snaptype = SnapToMark;
3262 } else if (choice == _("Region starts")) {
3263 snaptype = SnapToRegionStart;
3264 } else if (choice == _("Region ends")) {
3265 snaptype = SnapToRegionEnd;
3266 } else if (choice == _("Region bounds")) {
3267 snaptype = SnapToRegionBoundary;
3268 } else if (choice == _("Region syncs")) {
3269 snaptype = SnapToRegionSync;
3270 } else if (choice == _("CD Frames")) {
3271 snaptype = SnapToCDFrame;
3272 } else if (choice == _("SMPTE Frames")) {
3273 snaptype = SnapToSMPTEFrame;
3274 } else if (choice == _("SMPTE Seconds")) {
3275 snaptype = SnapToSMPTESeconds;
3276 } else if (choice == _("SMPTE Minutes")) {
3277 snaptype = SnapToSMPTEMinutes;
3278 } else if (choice == _("Seconds")) {
3279 snaptype = SnapToSeconds;
3280 } else if (choice == _("Minutes")) {
3281 snaptype = SnapToMinutes;
3284 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3286 ract->set_active ();
3291 Editor::snap_mode_selection_done ()
3293 string choice = snap_mode_selector.get_active_text();
3294 SnapMode mode = SnapNormal;
3296 if (choice == _("No Grid")) {
3298 } else if (choice == _("Grid")) {
3300 } else if (choice == _("Magnetic")) {
3301 mode = SnapMagnetic;
3304 RefPtr<RadioAction> ract = snap_mode_action (mode);
3307 ract->set_active (true);
3312 Editor::cycle_edit_point (bool with_marker)
3314 switch (_edit_point) {
3316 set_edit_point_preference (EditAtPlayhead);
3318 case EditAtPlayhead:
3320 set_edit_point_preference (EditAtSelectedMarker);
3322 set_edit_point_preference (EditAtMouse);
3325 case EditAtSelectedMarker:
3326 set_edit_point_preference (EditAtMouse);
3332 Editor::edit_point_selection_done ()
3334 string choice = edit_point_selector.get_active_text();
3335 EditPoint ep = EditAtSelectedMarker;
3337 if (choice == _("Marker")) {
3338 set_edit_point_preference (EditAtSelectedMarker);
3339 } else if (choice == _("Playhead")) {
3340 set_edit_point_preference (EditAtPlayhead);
3342 set_edit_point_preference (EditAtMouse);
3345 RefPtr<RadioAction> ract = edit_point_action (ep);
3348 ract->set_active (true);
3353 Editor::zoom_focus_selection_done ()
3355 string choice = zoom_focus_selector.get_active_text();
3356 ZoomFocus focus_type = ZoomFocusLeft;
3358 if (choice == _("Left")) {
3359 focus_type = ZoomFocusLeft;
3360 } else if (choice == _("Right")) {
3361 focus_type = ZoomFocusRight;
3362 } else if (choice == _("Center")) {
3363 focus_type = ZoomFocusCenter;
3364 } else if (choice == _("Playhead")) {
3365 focus_type = ZoomFocusPlayhead;
3366 } else if (choice == _("Mouse")) {
3367 focus_type = ZoomFocusMouse;
3368 } else if (choice == _("Edit Point")) {
3369 focus_type = ZoomFocusEdit;
3372 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3375 ract->set_active ();
3380 Editor::edit_controls_button_release (GdkEventButton* ev)
3382 if (Keyboard::is_context_menu_event (ev)) {
3383 ARDOUR_UI::instance()->add_route (this);
3389 Editor::mouse_select_button_release (GdkEventButton* ev)
3391 /* this handles just right-clicks */
3393 if (ev->button != 3) {
3400 Editor::TrackViewList *
3401 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3404 TrackViewList::iterator i;
3406 v = new TrackViewList;
3408 if (track == 0 && group == 0) {
3412 for (i = track_views.begin(); i != track_views.end (); ++i) {
3416 } else if (track != 0 && group == 0 || (track != 0 && group != 0 && !group->is_active())) {
3418 /* just the view for this track
3421 v->push_back (track);
3425 /* views for all tracks in the edit group */
3427 for (i = track_views.begin(); i != track_views.end (); ++i) {
3429 if (group == 0 || (*i)->edit_group() == group) {
3439 Editor::set_zoom_focus (ZoomFocus f)
3441 string str = zoom_focus_strings[(int)f];
3443 if (str != zoom_focus_selector.get_active_text()) {
3444 zoom_focus_selector.set_active_text (str);
3447 if (zoom_focus != f) {
3450 ZoomFocusChanged (); /* EMIT_SIGNAL */
3457 Editor::ensure_float (Window& win)
3459 win.set_transient_for (*this);
3463 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3465 /* recover or initialize pane positions. do this here rather than earlier because
3466 we don't want the positions to change the child allocations, which they seem to do.
3472 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3474 static int32_t done;
3477 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3478 width = default_width;
3479 height = default_height;
3481 width = atoi(geometry->property("x_size")->value());
3482 height = atoi(geometry->property("y_size")->value());
3485 if (which == static_cast<Paned*> (&edit_pane)) {
3491 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3492 /* initial allocation is 90% to canvas, 10% to notebook */
3493 pos = (int) floor (alloc.get_width() * 0.90f);
3494 snprintf (buf, sizeof(buf), "%d", pos);
3496 pos = atoi (prop->value());
3499 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3500 edit_pane.set_position (pos);
3501 pre_maximal_pane_position = pos;
3507 Editor::detach_tearoff (Box* b, Window* w)
3509 if (tools_tearoff->torn_off() &&
3510 mouse_mode_tearoff->torn_off()) {
3511 top_hbox.remove (toolbar_frame);
3516 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3518 if (toolbar_frame.get_parent() == 0) {
3519 top_hbox.pack_end (toolbar_frame);
3524 Editor::set_show_measures (bool yn)
3526 if (_show_measures != yn) {
3529 if ((_show_measures = yn) == true) {
3537 Editor::toggle_follow_playhead ()
3539 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3541 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3542 set_follow_playhead (tact->get_active());
3547 Editor::set_follow_playhead (bool yn)
3549 if (_follow_playhead != yn) {
3550 if ((_follow_playhead = yn) == true) {
3552 update_current_screen ();
3559 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3561 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3563 xfade->set_active (!xfade->active());
3568 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3570 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3572 xfade->set_follow_overlap (!xfade->following_overlap());
3577 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3579 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3585 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3589 switch (cew.run ()) {
3590 case RESPONSE_ACCEPT:
3597 xfade->StateChanged (Change (~0));
3601 Editor::playlist_selector () const
3603 return *_playlist_selector;
3607 Editor::get_nudge_distance (nframes_t pos, nframes_t& next)
3611 ret = nudge_clock.current_duration (pos);
3612 next = ret + 1; /* XXXX fix me */
3618 Editor::end_location_changed (Location* location)
3620 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3621 reset_scrolling_region ();
3625 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3627 ArdourDialog dialog ("playlist deletion dialog");
3628 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3629 "If left alone, no audio files used by it will be cleaned.\n"
3630 "If deleted, audio files used by it alone by will cleaned."),
3633 dialog.set_position (WIN_POS_CENTER);
3634 dialog.get_vbox()->pack_start (label);
3638 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3639 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3640 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3642 switch (dialog.run ()) {
3643 case RESPONSE_ACCEPT:
3644 /* delete the playlist */
3648 case RESPONSE_REJECT:
3649 /* keep the playlist */
3661 Editor::audio_region_selection_covers (nframes_t where)
3663 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3664 if ((*a)->region()->covers (where)) {
3673 Editor::prepare_for_cleanup ()
3675 cut_buffer->clear_regions ();
3676 cut_buffer->clear_playlists ();
3678 selection->clear_regions ();
3679 selection->clear_playlists ();
3683 Editor::transport_loop_location()
3686 return session->locations()->auto_loop_location();
3693 Editor::transport_punch_location()
3696 return session->locations()->auto_punch_location();
3703 Editor::control_layout_scroll (GdkEventScroll* ev)
3705 switch (ev->direction) {
3707 scroll_tracks_up_line ();
3711 case GDK_SCROLL_DOWN:
3712 scroll_tracks_down_line ();
3716 /* no left/right handling yet */
3724 /** A new snapshot has been selected.
3727 Editor::snapshot_display_selection_changed ()
3729 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
3731 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
3733 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
3735 if (snap_name.length() == 0) {
3739 if (session->snap_name() == snap_name) {
3743 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
3748 Editor::snapshot_display_button_press (GdkEventButton* ev)
3750 if (ev->button == 3) {
3751 /* Right-click on the snapshot list. Work out which snapshot it
3753 Gtk::TreeModel::Path path;
3754 Gtk::TreeViewColumn* col;
3757 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
3758 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
3760 Gtk::TreeModel::Row row = *iter;
3761 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
3770 /** Pop up the snapshot display context menu.
3771 * @param button Button used to open the menu.
3772 * @param time Menu open time.
3773 * @snapshot_name Name of the snapshot that the menu click was over.
3777 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
3779 using namespace Menu_Helpers;
3781 MenuList& items (snapshot_context_menu.items());
3784 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
3786 items.push_back (MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)));
3787 if (!modification_allowed) {
3788 items.back().set_sensitive (false);
3791 items.push_back (MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)));
3792 if (!modification_allowed) {
3793 items.back().set_sensitive (false);
3796 snapshot_context_menu.popup (button, time);
3800 Editor::rename_snapshot (Glib::ustring old_name)
3802 ArdourPrompter prompter(true);
3806 prompter.set_name ("Prompter");
3807 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
3808 prompter.set_prompt (_("New name of snapshot"));
3809 prompter.set_initial_text (old_name);
3811 if (prompter.run() == RESPONSE_ACCEPT) {
3812 prompter.get_result (new_name);
3813 if (new_name.length()) {
3814 session->rename_state (old_name, new_name);
3815 redisplay_snapshots ();
3822 Editor::remove_snapshot (Glib::ustring name)
3824 vector<string> choices;
3826 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
3828 choices.push_back (_("No, do nothing."));
3829 choices.push_back (_("Yes, remove it."));
3831 Gtkmm2ext::Choice prompter (prompt, choices);
3833 if (prompter.run () == 1) {
3834 session->remove_state (name);
3835 redisplay_snapshots ();
3840 Editor::redisplay_snapshots ()
3846 vector<string*>* states;
3848 if ((states = session->possible_states()) == 0) {
3852 snapshot_display_model->clear ();
3854 for (vector<string*>::iterator i = states->begin(); i != states->end(); ++i) {
3855 string statename = *(*i);
3856 TreeModel::Row row = *(snapshot_display_model->append());
3858 /* this lingers on in case we ever want to change the visible
3859 name of the snapshot.
3862 string display_name;
3863 display_name = statename;
3865 if (statename == session->snap_name()) {
3866 snapshot_display.get_selection()->select(row);
3869 row[snapshot_display_columns.visible_name] = display_name;
3870 row[snapshot_display_columns.real_name] = statename;
3877 Editor::session_state_saved (string snap_name)
3879 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
3880 redisplay_snapshots ();
3884 Editor::maximise_editing_space ()
3886 initial_ruler_update_required = true;
3888 mouse_mode_tearoff->set_visible (false);
3889 tools_tearoff->set_visible (false);
3891 pre_maximal_pane_position = edit_pane.get_position();
3892 pre_maximal_editor_width = this->get_width();
3894 if(post_maximal_pane_position == 0) {
3895 post_maximal_pane_position = edit_pane.get_width();
3900 if(post_maximal_editor_width) {
3901 edit_pane.set_position (post_maximal_pane_position -
3902 abs(post_maximal_editor_width - pre_maximal_editor_width));
3904 edit_pane.set_position (post_maximal_pane_position);
3909 Editor::restore_editing_space ()
3911 initial_ruler_update_required = true;
3913 // user changed width of pane during fullscreen
3914 if(post_maximal_pane_position != edit_pane.get_position()) {
3915 post_maximal_pane_position = edit_pane.get_position();
3920 mouse_mode_tearoff->set_visible (true);
3921 tools_tearoff->set_visible (true);
3922 post_maximal_editor_width = this->get_width();
3925 edit_pane.set_position (
3926 pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width)
3931 * Make new playlists for a given track and also any others that belong
3932 * to the same active edit group.
3937 Editor::new_playlists (TimeAxisView* v)
3939 begin_reversible_command (_("new playlists"));
3940 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
3941 commit_reversible_command ();
3946 * Use a copy of the current playlist for a given track and also any others that belong
3947 * to the same active edit group.
3952 Editor::copy_playlists (TimeAxisView* v)
3954 begin_reversible_command (_("copy playlists"));
3955 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
3956 commit_reversible_command ();
3961 * Clear the current playlist for a given track and also any others that belong
3962 * to the same active edit group.
3967 Editor::clear_playlists (TimeAxisView* v)
3969 begin_reversible_command (_("clear playlists"));
3970 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
3971 commit_reversible_command ();
3975 Editor::mapped_use_new_playlist (AudioTimeAxisView& atv, uint32_t sz)
3977 atv.use_new_playlist (sz > 1 ? false : true);
3981 Editor::mapped_use_copy_playlist (AudioTimeAxisView& atv, uint32_t sz)
3983 atv.use_copy_playlist (sz > 1 ? false : true);
3987 Editor::mapped_clear_playlist (AudioTimeAxisView& atv, uint32_t sz)
3989 atv.clear_playlist ();
3993 Editor::on_key_press_event (GdkEventKey* ev)
3995 return key_press_focus_accelerator_handler (*this, ev);
3999 Editor::on_key_release_event (GdkEventKey* ev)
4001 return Gtk::Window::on_key_release_event (ev);
4002 // return key_press_focus_accelerator_handler (*this, ev);
4006 Editor::reset_x_origin (nframes_t frame)
4008 queue_visual_change (frame);
4012 Editor::reset_zoom (double fpu)
4014 queue_visual_change (fpu);
4018 Editor::reposition_and_zoom (nframes_t frame, double fpu)
4020 reset_x_origin (frame);
4025 Editor::swap_visual_state ()
4027 if (last_visual_state.frames_per_unit == 0) {
4032 /* note: the correct functionality here is very dependent on the ordering of
4033 setting zoom focus, horizontal position and finally zoom. this is because
4034 it is set_frames_per_unit() that overwrites last_visual_state.
4037 set_zoom_focus (last_visual_state.zoom_focus);
4038 reposition_and_zoom (last_visual_state.leftmost_frame, last_visual_state.frames_per_unit);
4039 zoomed_to_region = false;
4043 Editor::set_frames_per_unit (double fpu)
4045 /* this is the core function that controls the zoom level of the canvas. it is called
4046 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4049 if (fpu == frames_per_unit) {
4058 /* don't allow zooms that fit more than the maximum number
4059 of frames into an 800 pixel wide space.
4062 if (max_frames / fpu < 800.0) {
4066 if (fpu == frames_per_unit) {
4070 last_visual_state.frames_per_unit = frames_per_unit;
4071 last_visual_state.leftmost_frame = leftmost_frame;
4072 last_visual_state.zoom_focus = zoom_focus;
4074 frames_per_unit = fpu;
4079 Editor::post_zoom ()
4081 // convert fpu to frame count
4083 nframes_t frames = (nframes_t) floor (frames_per_unit * canvas_width);
4085 if (frames_per_unit != zoom_range_clock.current_duration()) {
4086 zoom_range_clock.set (frames);
4089 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4090 if (!selection->tracks.empty()) {
4091 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4092 (*i)->reshow_selection (selection->time);
4095 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4096 (*i)->reshow_selection (selection->time);
4101 ZoomChanged (); /* EMIT_SIGNAL */
4103 reset_hscrollbar_stepping ();
4104 reset_scrolling_region ();
4106 if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
4112 Editor::queue_visual_change (nframes_t where)
4114 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4115 pending_visual_change.time_origin = where;
4117 if (pending_visual_change.idle_handler_id < 0) {
4118 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4123 Editor::queue_visual_change (double fpu)
4125 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4126 pending_visual_change.frames_per_unit = fpu;
4128 if (pending_visual_change.idle_handler_id < 0) {
4129 pending_visual_change.idle_handler_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, _idle_visual_changer, this, 0);
4134 Editor::_idle_visual_changer (void* arg)
4136 return static_cast<Editor*>(arg)->idle_visual_changer ();
4140 Editor::idle_visual_changer ()
4142 VisualChange::Type p = pending_visual_change.pending;
4144 pending_visual_change.pending = (VisualChange::Type) 0;
4145 pending_visual_change.idle_handler_id = -1;
4147 if (p & VisualChange::ZoomLevel) {
4148 set_frames_per_unit (pending_visual_change.frames_per_unit);
4151 if (p & VisualChange::TimeOrigin) {
4153 nframes_t time_origin = (nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4155 if (time_origin != pending_visual_change.time_origin) {
4156 horizontal_adjustment.set_value (pending_visual_change.time_origin/frames_per_unit);
4158 update_fixed_rulers();
4159 redisplay_tempo (true);
4163 return 0; /* this is always a one-shot call */
4166 struct EditorOrderTimeAxisSorter {
4167 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4168 return a->order < b->order;
4173 Editor::sort_track_selection (TrackSelection* sel)
4175 EditorOrderTimeAxisSorter cmp;
4180 selection->tracks.sort (cmp);
4185 Editor::get_preferred_edit_position (bool ignore_playhead)
4188 nframes64_t where = 0;
4189 EditPoint ep = _edit_point;
4191 if (entered_marker) {
4192 return entered_marker->position();
4195 if (ignore_playhead && ep == EditAtPlayhead) {
4196 ep = EditAtSelectedMarker;
4200 case EditAtPlayhead:
4201 where = session->audible_frame();
4204 case EditAtSelectedMarker:
4205 if (!selection->markers.empty()) {
4207 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4210 where = loc->start();
4221 if (!mouse_frame (where, ignored)) {
4222 /* XXX not right but what can we do ? */
4233 Editor::set_loop_range (nframes_t start, nframes_t end, string cmd)
4235 if (!session) return;
4237 begin_reversible_command (cmd);
4241 if ((tll = transport_loop_location()) == 0) {
4242 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4243 XMLNode &before = session->locations()->get_state();
4244 session->locations()->add (loc, true);
4245 session->set_auto_loop_location (loc);
4246 XMLNode &after = session->locations()->get_state();
4247 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4250 XMLNode &before = tll->get_state();
4251 tll->set_hidden (false, this);
4252 tll->set (start, end);
4253 XMLNode &after = tll->get_state();
4254 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4257 commit_reversible_command ();
4261 Editor::set_punch_range (nframes_t start, nframes_t end, string cmd)
4263 if (!session) return;
4265 begin_reversible_command (cmd);
4269 if ((tpl = transport_punch_location()) == 0) {
4270 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4271 XMLNode &before = session->locations()->get_state();
4272 session->locations()->add (loc, true);
4273 session->set_auto_loop_location (loc);
4274 XMLNode &after = session->locations()->get_state();
4275 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4278 XMLNode &before = tpl->get_state();
4279 tpl->set_hidden (false, this);
4280 tpl->set (start, end);
4281 XMLNode &after = tpl->get_state();
4282 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4285 commit_reversible_command ();
4289 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4291 const TrackSelection* tracks;
4294 tracks = &track_views;
4299 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4301 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4304 boost::shared_ptr<Diskstream> ds;
4305 boost::shared_ptr<Playlist> pl;
4307 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4309 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)where * ds->speed()));
4311 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4313 RegionView* rv = atv->audio_view()->find_view (*i);
4327 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4329 const TrackSelection* tracks;
4332 tracks = &track_views;
4337 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4339 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4342 boost::shared_ptr<Diskstream> ds;
4343 boost::shared_ptr<Playlist> pl;
4345 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4347 Playlist::RegionList* regions = pl->regions_touched ((nframes_t) floor ( (double)where * ds->speed()), max_frames);
4349 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4351 RegionView* rv = atv->audio_view()->find_view (*i);
4365 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4367 bool use_regions_at = true;
4369 if (selection->regions.empty()) {
4371 if (selection->tracks.empty()) {
4373 /* no regions or tracks selected, but entered regionview is valid
4374 and we're in object mode - just use entered regionview
4377 if (entered_regionview && (mouse_mode == Editing::MouseObject)) {
4378 rs.add (entered_regionview);
4384 /* no regions selected, so get all regions at the edit point across
4385 all selected tracks.
4388 nframes64_t where = get_preferred_edit_position();
4389 get_regions_at (rs, where, selection->tracks);
4391 /* if the entered regionview wasn't selected and neither was its track
4395 if (entered_regionview != 0 &&
4396 !selection->selected (entered_regionview) &&
4397 !selection->selected (&entered_regionview->get_time_axis_view())) {
4398 rs.add (entered_regionview);
4404 /* just use the selected regions */
4406 rs = selection->regions;
4408 /* if the entered regionview wasn't selected and we allow this sort of thing,
4412 if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
4413 rs.add (entered_regionview);
4420 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4423 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4425 RouteTimeAxisView* tatv;
4427 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4429 boost::shared_ptr<Playlist> pl;
4430 vector<boost::shared_ptr<Region> > results;
4432 boost::shared_ptr<Diskstream> ds;
4434 if ((ds = tatv->get_diskstream()) == 0) {
4439 if ((pl = (ds->playlist())) != 0) {
4440 pl->get_region_list_equivalent_regions (region, results);
4443 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4444 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4445 regions.push_back (marv);
4454 Editor::show_rhythm_ferret ()
4456 if (rhythm_ferret == 0) {
4457 rhythm_ferret = new RhythmFerret(*this);
4460 rhythm_ferret->set_session (session);
4461 rhythm_ferret->show ();
4462 rhythm_ferret->present ();