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"
84 #include "analysis_window.h"
90 #include "imageframe_socket_handler.h"
91 /* </CMT Additions> */
95 using namespace ARDOUR;
99 using namespace Gtkmm2ext;
100 using namespace Editing;
104 const double Editor::timebar_height = 15.0;
106 #include "editor_xpms"
108 static const gchar *_snap_type_strings[] = {
130 static const gchar *_snap_mode_strings[] = {
137 static const gchar *_edit_point_strings[] = {
144 static const gchar *_zoom_focus_strings[] = {
154 /* Soundfile drag-n-drop */
156 Gdk::Cursor* Editor::cross_hair_cursor = 0;
157 Gdk::Cursor* Editor::selector_cursor = 0;
158 Gdk::Cursor* Editor::trimmer_cursor = 0;
159 Gdk::Cursor* Editor::grabber_cursor = 0;
160 Gdk::Cursor* Editor::zoom_cursor = 0;
161 Gdk::Cursor* Editor::time_fx_cursor = 0;
162 Gdk::Cursor* Editor::fader_cursor = 0;
163 Gdk::Cursor* Editor::speaker_cursor = 0;
164 Gdk::Cursor* Editor::wait_cursor = 0;
165 Gdk::Cursor* Editor::timebar_cursor = 0;
166 Gdk::Cursor* Editor::transparent_cursor = 0;
169 show_me_the_size (Requisition* r, const char* what)
171 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
176 /* time display buttons */
177 minsec_label (_("Mins:Secs")),
178 bbt_label (_("Bars:Beats")),
179 smpte_label (_("Timecode")),
180 frame_label (_("Samples")),
181 tempo_label (_("Tempo")),
182 meter_label (_("Meter")),
183 mark_label (_("Location Markers")),
184 range_mark_label (_("Range Markers")),
185 transport_mark_label (_("Loop/Punch Ranges")),
186 cd_mark_label (_("CD Markers")),
188 edit_packer (3, 3, true),
190 /* the values here don't matter: layout widgets
191 reset them as needed.
194 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
195 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
197 /* tool bar related */
199 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
200 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
202 toolbar_selection_clock_table (2,3),
204 automation_mode_button (_("mode")),
205 global_automation_button (_("automation")),
207 /* <CMT Additions> */
208 image_socket_listener(0),
209 /* </CMT Additions> */
213 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
214 meters_running(false)
219 /* we are a singleton */
221 PublicEditor::_instance = this;
225 selection = new Selection;
226 cut_buffer = new Selection;
228 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
229 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
230 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
231 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
232 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
234 clicked_regionview = 0;
235 clicked_trackview = 0;
236 clicked_audio_trackview = 0;
237 clicked_crossfadeview = 0;
238 clicked_control_point = 0;
239 last_update_frame = 0;
241 current_mixer_strip = 0;
242 current_bbt_points = 0;
244 snap_type_strings = I18N (_snap_type_strings);
245 snap_mode_strings = I18N (_snap_mode_strings);
246 zoom_focus_strings = I18N (_zoom_focus_strings);
247 edit_point_strings = I18N (_edit_point_strings);
249 snap_threshold = 5.0;
250 bbt_beat_subdivision = 4;
253 autoscroll_active = false;
254 autoscroll_timeout_tag = -1;
255 interthread_progress_window = 0;
262 current_interthread_info = 0;
263 _show_measures = true;
264 _show_waveforms = true;
265 _show_waveforms_recording = true;
266 first_action_message = 0;
268 export_range_markers_dialog = 0;
269 show_gain_after_trim = false;
270 ignore_route_list_reorder = false;
271 no_route_list_redisplay = false;
272 verbose_cursor_on = true;
273 route_removal = false;
274 show_automatic_regions_in_region_list = true;
276 region_list_sort_type = (Editing::RegionListSortType) 0;
277 have_pending_keyboard_selection = false;
278 _follow_playhead = true;
279 _xfade_visibility = true;
280 editor_ruler_menu = 0;
281 no_ruler_shown_update = false;
282 edit_group_list_menu = 0;
284 region_list_menu = 0;
286 start_end_marker_menu = 0;
287 range_marker_menu = 0;
288 marker_menu_item = 0;
290 transport_marker_menu = 0;
291 new_transport_marker_menu = 0;
292 editor_mixer_strip_width = Wide;
293 show_editor_mixer_when_tracks_arrive = false;
294 region_edit_menu_split_item = 0;
296 region_edit_menu_split_multichannel_item = 0;
298 ignore_mouse_mode_toggle = false;
299 current_stepping_trackview = 0;
301 entered_regionview = 0;
303 clear_entered_track = false;
304 _new_regionviews_show_envelope = false;
306 in_edit_group_row_change = false;
307 last_canvas_frame = 0;
309 button_release_can_deselect = true;
310 canvas_idle_queued = false;
311 _dragging_playhead = false;
312 _dragging_edit_point = false;
313 _dragging_hscrollbar = false;
314 select_new_marker = false;
316 scrubbing_direction = 0;
319 ignore_route_order_sync = false;
321 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
322 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
323 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
324 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
325 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
327 range_marker_drag_rect = 0;
328 marker_drag_line = 0;
330 set_mouse_mode (MouseObject, true);
332 last_visual_state.frames_per_unit = 0;
334 frames_per_unit = 2048; /* too early to use reset_zoom () */
335 reset_hscrollbar_stepping ();
337 zoom_focus = ZoomFocusLeft;
338 set_zoom_focus (ZoomFocusLeft);
339 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
341 initialize_rulers ();
342 initialize_canvas ();
344 edit_controls_vbox.set_spacing (0);
345 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::canvas_horizontally_scrolled));
346 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
348 track_canvas.set_hadjustment (horizontal_adjustment);
349 track_canvas.set_vadjustment (vertical_adjustment);
350 time_canvas.set_hadjustment (horizontal_adjustment);
352 track_canvas.signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
353 time_canvas.signal_map_event().connect (mem_fun (*this, &Editor::time_canvas_map_handler));
355 controls_layout.add (edit_controls_vbox);
356 controls_layout.set_name ("EditControlsBase");
357 controls_layout.add_events (Gdk::SCROLL_MASK);
358 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
360 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
361 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
362 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
364 edit_vscrollbar.set_adjustment (vertical_adjustment);
365 edit_hscrollbar.set_adjustment (horizontal_adjustment);
367 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
368 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
369 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
371 edit_hscrollbar.set_name ("EditorHScrollbar");
376 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
378 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
379 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
380 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
381 time_canvas_vbox.pack_start (*frames_ruler, false, false);
382 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
383 time_canvas_vbox.pack_start (time_canvas, true, true);
384 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
386 bbt_label.set_name ("EditorTimeButton");
387 bbt_label.set_size_request (-1, (int)timebar_height);
388 bbt_label.set_alignment (1.0, 0.5);
389 bbt_label.set_padding (5,0);
390 minsec_label.set_name ("EditorTimeButton");
391 minsec_label.set_size_request (-1, (int)timebar_height);
392 minsec_label.set_alignment (1.0, 0.5);
393 minsec_label.set_padding (5,0);
394 smpte_label.set_name ("EditorTimeButton");
395 smpte_label.set_size_request (-1, (int)timebar_height);
396 smpte_label.set_alignment (1.0, 0.5);
397 smpte_label.set_padding (5,0);
398 frame_label.set_name ("EditorTimeButton");
399 frame_label.set_size_request (-1, (int)timebar_height);
400 frame_label.set_alignment (1.0, 0.5);
401 frame_label.set_padding (5,0);
402 tempo_label.set_name ("EditorTimeButton");
403 tempo_label.set_size_request (-1, (int)timebar_height);
404 tempo_label.set_alignment (1.0, 0.5);
405 tempo_label.set_padding (5,0);
406 meter_label.set_name ("EditorTimeButton");
407 meter_label.set_size_request (-1, (int)timebar_height);
408 meter_label.set_alignment (1.0, 0.5);
409 meter_label.set_padding (5,0);
410 mark_label.set_name ("EditorTimeButton");
411 mark_label.set_size_request (-1, (int)timebar_height);
412 mark_label.set_alignment (1.0, 0.5);
413 mark_label.set_padding (5,0);
414 cd_mark_label.set_name ("EditorTimeButton");
415 cd_mark_label.set_size_request (-1, (int)timebar_height);
416 cd_mark_label.set_alignment (1.0, 0.5);
417 cd_mark_label.set_padding (5,0);
418 range_mark_label.set_name ("EditorTimeButton");
419 range_mark_label.set_size_request (-1, (int)timebar_height);
420 range_mark_label.set_alignment (1.0, 0.5);
421 range_mark_label.set_padding (5,0);
422 transport_mark_label.set_name ("EditorTimeButton");
423 transport_mark_label.set_size_request (-1, (int)timebar_height);
424 transport_mark_label.set_alignment (1.0, 0.5);
425 transport_mark_label.set_padding (5,0);
427 time_button_vbox.pack_start (minsec_label, false, false);
428 time_button_vbox.pack_start (smpte_label, false, false);
429 time_button_vbox.pack_start (frame_label, false, false);
430 time_button_vbox.pack_start (bbt_label, false, false);
431 time_button_vbox.pack_start (meter_label, false, false);
432 time_button_vbox.pack_start (tempo_label, false, false);
433 time_button_vbox.pack_start (mark_label, false, false);
435 time_button_event_box.add (time_button_vbox);
437 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
438 time_button_event_box.set_name ("TimebarLabelBase");
439 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
441 time_button_frame.add(time_button_event_box);
442 time_button_frame.property_shadow_type() = Gtk::SHADOW_OUT;
444 /* these enable us to have a dedicated window (for cursor setting, etc.)
445 for the canvas areas.
448 track_canvas_event_box.add (track_canvas);
450 time_canvas_event_box.add (time_canvas_vbox);
451 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
453 edit_packer.set_col_spacings (0);
454 edit_packer.set_row_spacings (0);
455 edit_packer.set_homogeneous (false);
456 edit_packer.set_border_width (0);
457 edit_packer.set_name ("EditorWindow");
459 edit_packer.attach (edit_vscrollbar, 0, 1, 1, 3, FILL, FILL|EXPAND, 0, 0);
461 edit_packer.attach (time_button_frame, 0, 2, 0, 1, FILL, FILL, 0, 0);
462 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
464 edit_packer.attach (controls_layout, 1, 2, 1, 2, FILL, FILL|EXPAND, 0, 0);
465 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 2, FILL|EXPAND, FILL|EXPAND, 0, 0);
467 edit_packer.attach (zoom_box, 1, 2, 2, 3, FILL, FILL, 0, 0);
468 edit_packer.attach (edit_hscrollbar, 2, 3, 2, 3, FILL|EXPAND, FILL, 0, 0);
470 bottom_hbox.set_border_width (2);
471 bottom_hbox.set_spacing (3);
473 route_display_model = ListStore::create(route_display_columns);
474 route_list_display.set_model (route_display_model);
475 route_list_display.append_column (_("Show"), route_display_columns.visible);
476 route_list_display.append_column (_("Name"), route_display_columns.text);
477 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
478 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
479 route_list_display.set_headers_visible (true);
480 route_list_display.set_name ("TrackListDisplay");
481 route_list_display.get_selection()->set_mode (SELECTION_NONE);
482 route_list_display.set_reorderable (true);
483 route_list_display.set_size_request (100,-1);
485 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
486 route_list_visible_cell->property_activatable() = true;
487 route_list_visible_cell->property_radio() = false;
489 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
490 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
491 route_display_model->signal_rows_reordered().connect (mem_fun (*this, &Editor::track_list_reorder));
493 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
495 route_list_scroller.add (route_list_display);
496 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
498 group_model = ListStore::create(group_columns);
499 edit_group_display.set_model (group_model);
500 edit_group_display.append_column (_("Name"), group_columns.text);
501 edit_group_display.append_column (_("Active"), group_columns.is_active);
502 edit_group_display.append_column (_("Show"), group_columns.is_visible);
503 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
504 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
505 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
506 edit_group_display.get_column (0)->set_expand (true);
507 edit_group_display.get_column (1)->set_expand (false);
508 edit_group_display.get_column (2)->set_expand (false);
509 edit_group_display.set_headers_visible (true);
511 /* name is directly editable */
513 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
514 name_cell->property_editable() = true;
515 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
517 /* use checkbox for the active + visible columns */
519 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
520 active_cell->property_activatable() = true;
521 active_cell->property_radio() = false;
523 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
524 active_cell->property_activatable() = true;
525 active_cell->property_radio() = false;
527 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
529 edit_group_display.set_name ("EditGroupList");
530 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
531 edit_group_display.set_headers_visible (true);
532 edit_group_display.set_reorderable (false);
533 edit_group_display.set_rules_hint (true);
534 edit_group_display.set_size_request (75, -1);
536 edit_group_display_scroller.add (edit_group_display);
537 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
539 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
541 VBox* edit_group_display_packer = manage (new VBox());
542 HBox* edit_group_display_button_box = manage (new HBox());
543 edit_group_display_button_box->set_homogeneous (true);
545 Button* edit_group_add_button = manage (new Button ());
546 Button* edit_group_remove_button = manage (new Button ());
550 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
552 edit_group_add_button->add (*w);
554 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
556 edit_group_remove_button->add (*w);
558 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
559 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
561 edit_group_display_button_box->pack_start (*edit_group_add_button);
562 edit_group_display_button_box->pack_start (*edit_group_remove_button);
564 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
565 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
567 region_list_display.set_size_request (100, -1);
568 region_list_display.set_name ("RegionListDisplay");
570 region_list_model = TreeStore::create (region_list_columns);
571 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
572 region_list_model->set_sort_column (0, SORT_ASCENDING);
574 region_list_display.set_model (region_list_model);
575 region_list_display.append_column (_("Regions"), region_list_columns.name);
576 region_list_display.set_headers_visible (false);
578 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
579 region_name_cell->property_editable() = true;
580 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
582 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
584 TreeViewColumn* tv_col = region_list_display.get_column(0);
585 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
586 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
587 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
589 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
590 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
592 /* setup DnD handling */
594 list<TargetEntry> region_list_target_table;
596 region_list_target_table.push_back (TargetEntry ("text/plain"));
597 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
598 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
600 region_list_display.add_drop_targets (region_list_target_table);
601 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
603 region_list_scroller.add (region_list_display);
604 region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
606 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
607 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
608 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
609 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
610 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
611 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
613 named_selection_scroller.add (named_selection_display);
614 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
616 named_selection_model = TreeStore::create (named_selection_columns);
617 named_selection_display.set_model (named_selection_model);
618 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
619 named_selection_display.set_headers_visible (false);
620 named_selection_display.set_size_request (100, -1);
621 named_selection_display.set_name ("NamedSelectionDisplay");
623 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
624 named_selection_display.set_size_request (100, -1);
625 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
626 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
627 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
631 snapshot_display_model = ListStore::create (snapshot_display_columns);
632 snapshot_display.set_model (snapshot_display_model);
633 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
634 snapshot_display.set_name ("SnapshotDisplay");
635 snapshot_display.set_size_request (75, -1);
636 snapshot_display.set_headers_visible (false);
637 snapshot_display.set_reorderable (false);
638 snapshot_display_scroller.add (snapshot_display);
639 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
641 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
642 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
646 nlabel = manage (new Label (_("Regions")));
647 nlabel->set_angle (-90);
648 the_notebook.append_page (region_list_scroller, *nlabel);
649 nlabel = manage (new Label (_("Tracks/Busses")));
650 nlabel->set_angle (-90);
651 the_notebook.append_page (route_list_scroller, *nlabel);
652 nlabel = manage (new Label (_("Snapshots")));
653 nlabel->set_angle (-90);
654 the_notebook.append_page (snapshot_display_scroller, *nlabel);
655 nlabel = manage (new Label (_("Edit Groups")));
656 nlabel->set_angle (-90);
657 the_notebook.append_page (*edit_group_display_packer, *nlabel);
659 if (!Profile->get_sae()) {
660 nlabel = manage (new Label (_("Chunks")));
661 nlabel->set_angle (-90);
662 the_notebook.append_page (named_selection_scroller, *nlabel);
665 the_notebook.set_show_tabs (true);
666 the_notebook.set_scrollable (true);
667 the_notebook.popup_enable ();
668 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
670 post_maximal_editor_width = 0;
671 post_maximal_pane_position = 0;
672 edit_pane.pack1 (edit_packer, true, true);
673 edit_pane.pack2 (the_notebook, false, true);
675 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
677 top_hbox.pack_start (toolbar_frame, true, true);
679 HBox *hbox = manage (new HBox);
680 hbox->pack_start (edit_pane, true, true);
682 global_vpacker.pack_start (top_hbox, false, false);
683 global_vpacker.pack_start (*hbox, true, true);
685 global_hpacker.pack_start (global_vpacker, true, true);
687 set_name ("EditorWindow");
688 add_accel_group (ActionManager::ui_manager->get_accel_group());
690 status_bar_hpacker.show ();
692 vpacker.pack_end (status_bar_hpacker, false, false);
693 vpacker.pack_end (global_hpacker, true, true);
695 /* register actions now so that set_state() can find them and set toggles/checks etc */
699 snap_type = SnapToBeat;
700 set_snap_to (snap_type);
702 set_snap_mode (snap_mode);
703 _edit_point = EditAtMouse;
704 set_edit_point_preference (_edit_point);
706 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
709 _playlist_selector = new PlaylistSelector();
710 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
712 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
716 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
717 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
719 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
720 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
722 nudge_forward_button.set_name ("TransportButton");
723 nudge_backward_button.set_name ("TransportButton");
725 fade_context_menu.set_name ("ArdourContextMenu");
727 /* icons, titles, WM stuff */
729 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
730 Glib::RefPtr<Gdk::Pixbuf> icon;
732 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
733 window_icons.push_back (icon);
735 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
736 window_icons.push_back (icon);
738 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
739 window_icons.push_back (icon);
741 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
742 window_icons.push_back (icon);
744 if (!window_icons.empty()) {
745 set_icon_list (window_icons);
746 set_default_icon_list (window_icons);
749 WindowTitle title(Glib::get_application_name());
750 title += _("Editor");
751 set_title (title.get_string());
752 set_wmclass (X_("ardour_editor"), "Ardour");
755 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
757 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
758 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
760 /* allow external control surfaces/protocols to do various things */
762 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
763 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
764 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
765 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
767 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
768 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
776 /* <CMT Additions> */
777 if(image_socket_listener)
779 if(image_socket_listener->is_connected())
781 image_socket_listener->close_connection() ;
784 delete image_socket_listener ;
785 image_socket_listener = 0 ;
787 /* </CMT Additions> */
791 Editor::add_toplevel_controls (Container& cont)
793 vpacker.pack_start (cont, false, false);
798 Editor::catch_vanishing_regionview (RegionView *rv)
800 /* note: the selection will take care of the vanishing
801 audioregionview by itself.
804 if (clicked_regionview == rv) {
805 clicked_regionview = 0;
808 if (entered_regionview == rv) {
809 set_entered_regionview (0);
814 Editor::set_entered_regionview (RegionView* rv)
816 if (rv == entered_regionview) {
820 if (entered_regionview) {
821 entered_regionview->exited ();
824 if ((entered_regionview = rv) != 0) {
825 entered_regionview->entered ();
830 Editor::set_entered_track (TimeAxisView* tav)
833 entered_track->exited ();
836 if ((entered_track = tav) != 0) {
837 entered_track->entered ();
842 Editor::show_window ()
847 /* now reset all audio_time_axis heights, because widgets might need
853 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
854 tv = (static_cast<TimeAxisView*>(*i));
860 Editor::tie_vertical_scrolling ()
862 double y1 = vertical_adjustment.get_value();
864 playhead_cursor->set_y_axis (y1);
866 logo_item->property_y() = y1;
869 controls_layout.get_vadjustment()->set_value (y1);
873 Editor::instant_save ()
875 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
880 session->add_instant_xml(get_state(), session->path());
882 Config->add_instant_xml(get_state(), get_user_ardour_path());
887 Editor::edit_point_clock_changed()
889 if (_dragging_edit_point) {
893 if (selection->markers.empty()) {
898 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
904 loc->move_to (edit_point_clock.current_time());
908 Editor::zoom_adjustment_changed ()
914 double fpu = zoom_range_clock.current_duration() / canvas_width;
918 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
919 } else if (fpu > session->current_end_frame() / canvas_width) {
920 fpu = session->current_end_frame() / canvas_width;
921 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
928 Editor::control_scroll (float fraction)
930 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
936 double step = fraction * current_page_frames();
939 _control_scroll_target is an optional<T>
941 it acts like a pointer to an nframes_t, with
942 a operator conversion to boolean to check
943 that it has a value could possibly use
944 playhead_cursor->current_frame to store the
945 value and a boolean in the class to know
946 when it's out of date
949 if (!_control_scroll_target) {
950 _control_scroll_target = session->transport_frame();
951 _dragging_playhead = true;
954 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes_t) fabs(step))) {
955 *_control_scroll_target = 0;
956 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
957 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
959 *_control_scroll_target += (nframes_t) floor (step);
962 /* move visuals, we'll catch up with it later */
964 playhead_cursor->set_position (*_control_scroll_target);
965 UpdateAllTransportClocks (*_control_scroll_target);
967 if (*_control_scroll_target > (current_page_frames() / 2)) {
968 /* try to center PH in window */
969 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
975 Now we do a timeout to actually bring the session to the right place
976 according to the playhead. This is to avoid reading disk buffers on every
977 call to control_scroll, which is driven by ScrollTimeline and therefore
978 probably by a control surface wheel which can generate lots of events.
980 /* cancel the existing timeout */
982 control_scroll_connection.disconnect ();
984 /* add the next timeout */
986 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
990 Editor::deferred_control_scroll (nframes_t target)
992 session->request_locate (*_control_scroll_target, session->transport_rolling());
993 // reset for next stream
994 _control_scroll_target = boost::none;
995 _dragging_playhead = false;
1000 Editor::on_realize ()
1002 Window::on_realize ();
1007 Editor::start_scrolling ()
1009 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1010 (mem_fun(*this, &Editor::update_current_screen));
1014 Editor::stop_scrolling ()
1016 scroll_connection.disconnect ();
1020 Editor::map_position_change (nframes_t frame)
1022 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1024 if (session == 0 || !_follow_playhead) {
1028 center_screen (frame);
1029 playhead_cursor->set_position (frame);
1033 Editor::center_screen (nframes_t frame)
1035 double page = canvas_width * frames_per_unit;
1037 /* if we're off the page, then scroll.
1040 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1041 center_screen_internal (frame, page);
1046 Editor::center_screen_internal (nframes_t frame, float page)
1051 frame -= (nframes_t) page;
1056 reset_x_origin (frame);
1060 Editor::handle_new_duration ()
1062 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1064 nframes_t new_end = session->get_maximum_extent() + (nframes_t) floorf (current_page_frames() * 0.10f);
1066 if (new_end > last_canvas_frame) {
1067 last_canvas_frame = new_end;
1068 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1069 reset_scrolling_region ();
1072 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1076 Editor::update_title_s (const string & snap_name)
1078 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1084 Editor::update_title ()
1086 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1089 bool dirty = session->dirty();
1091 string session_name;
1093 if (session->snap_name() != session->name()) {
1094 session_name = session->snap_name();
1096 session_name = session->name();
1100 session_name = "*" + session_name;
1103 WindowTitle title(session_name);
1104 title += Glib::get_application_name();
1105 set_title (title.get_string());
1110 Editor::connect_to_session (Session *t)
1114 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1117 /* catch up with the playhead */
1119 session->request_locate (playhead_cursor->current_frame);
1121 if (first_action_message) {
1122 first_action_message->hide();
1127 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1128 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1130 /* These signals can all be emitted by a non-GUI thread. Therefore the
1131 handlers for them must not attempt to directly interact with the GUI,
1132 but use Gtkmm2ext::UI::instance()->call_slot();
1135 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1136 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1137 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1138 session_connections.push_back (session->AudioRegionAdded.connect (mem_fun(*this, &Editor::handle_new_audio_region)));
1139 session_connections.push_back (session->AudioRegionRemoved.connect (mem_fun(*this, &Editor::handle_audio_region_removed)));
1140 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1141 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1142 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1143 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1144 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1145 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1146 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1147 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1148 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1150 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1152 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1154 edit_groups_changed ();
1156 edit_point_clock.set_session (session);
1157 zoom_range_clock.set_session (session);
1158 _playlist_selector->set_session (session);
1159 nudge_clock.set_session (session);
1162 if (analysis_window != 0)
1163 analysis_window->set_session (session);
1166 Location* loc = session->locations()->auto_loop_location();
1168 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1169 if (loc->start() == loc->end()) {
1170 loc->set_end (loc->start() + 1);
1172 session->locations()->add (loc, false);
1173 session->set_auto_loop_location (loc);
1176 loc->set_name (_("Loop"));
1179 loc = session->locations()->auto_punch_location();
1181 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | 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_punch_location (loc);
1189 loc->set_name (_("Punch"));
1192 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1194 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1196 refresh_location_display ();
1197 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1198 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1199 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1200 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1201 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1204 sfbrowser->set_session (session);
1207 handle_new_duration ();
1209 redisplay_regions ();
1210 redisplay_named_selections ();
1211 redisplay_snapshots ();
1213 initial_route_list_display ();
1215 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1216 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1219 restore_ruler_visibility ();
1220 //tempo_map_changed (Change (0));
1221 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1225 /* don't show master bus in a new session */
1227 if (ARDOUR_UI::instance()->session_is_new ()) {
1229 TreeModel::Children rows = route_display_model->children();
1230 TreeModel::Children::iterator i;
1232 no_route_list_redisplay = true;
1234 for (i = rows.begin(); i != rows.end(); ++i) {
1235 TimeAxisView *tv = (*i)[route_display_columns.tv];
1236 AudioTimeAxisView *atv;
1238 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1239 if (atv->route()->master()) {
1240 route_list_display.get_selection()->unselect (i);
1245 no_route_list_redisplay = false;
1246 redisplay_route_list ();
1249 /* register for undo history */
1251 session->register_with_memento_command_factory(_id, this);
1257 Editor::build_cursors ()
1259 using namespace Gdk;
1261 Gdk::Color mbg ("#000000" ); /* Black */
1262 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1265 RefPtr<Bitmap> source, mask;
1266 source = Bitmap::create (mag_bits, mag_width, mag_height);
1267 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1268 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1271 Gdk::Color fbg ("#ffffff" );
1272 Gdk::Color ffg ("#000000" );
1275 RefPtr<Bitmap> source, mask;
1277 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1278 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1279 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1283 RefPtr<Bitmap> source, mask;
1284 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1285 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1286 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1290 RefPtr<Bitmap> bits;
1291 char pix[4] = { 0, 0, 0, 0 };
1292 bits = Bitmap::create (pix, 2, 2);
1294 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1297 grabber_cursor = new Gdk::Cursor (HAND2);
1298 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1299 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1300 selector_cursor = new Gdk::Cursor (XTERM);
1301 time_fx_cursor = new Gdk::Cursor (SIZING);
1302 wait_cursor = new Gdk::Cursor (WATCH);
1303 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1307 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1309 using namespace Menu_Helpers;
1310 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1313 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1317 MenuList& items (fade_context_menu.items());
1321 switch (item_type) {
1323 case FadeInHandleItem:
1324 if (arv->audio_region()->fade_in_active()) {
1325 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1327 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1330 items.push_back (SeparatorElem());
1332 if (Profile->get_sae()) {
1333 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1334 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1336 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1337 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1338 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1339 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1340 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1345 case FadeOutHandleItem:
1346 if (arv->audio_region()->fade_out_active()) {
1347 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1349 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1352 items.push_back (SeparatorElem());
1354 if (Profile->get_sae()) {
1355 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1356 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1358 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1359 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1360 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1361 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1362 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1367 fatal << _("programming error: ")
1368 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1373 fade_context_menu.popup (button, time);
1377 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes_t frame)
1379 using namespace Menu_Helpers;
1380 Menu* (Editor::*build_menu_function)(nframes_t);
1383 switch (item_type) {
1385 case RegionViewName:
1386 case RegionViewNameHighlight:
1387 if (with_selection) {
1388 build_menu_function = &Editor::build_track_selection_context_menu;
1390 build_menu_function = &Editor::build_track_region_context_menu;
1395 if (with_selection) {
1396 build_menu_function = &Editor::build_track_selection_context_menu;
1398 build_menu_function = &Editor::build_track_context_menu;
1402 case CrossfadeViewItem:
1403 build_menu_function = &Editor::build_track_crossfade_context_menu;
1407 if (clicked_audio_trackview->get_diskstream()) {
1408 build_menu_function = &Editor::build_track_context_menu;
1410 build_menu_function = &Editor::build_track_bus_context_menu;
1415 /* probably shouldn't happen but if it does, we don't care */
1419 menu = (this->*build_menu_function)(frame);
1420 menu->set_name ("ArdourContextMenu");
1422 /* now handle specific situations */
1424 switch (item_type) {
1426 case RegionViewName:
1427 case RegionViewNameHighlight:
1428 if (!with_selection) {
1429 if (region_edit_menu_split_item) {
1430 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1431 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1433 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1437 if (region_edit_menu_split_multichannel_item) {
1438 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1439 // GTK2FIX find the action, change its sensitivity
1440 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1442 // GTK2FIX see above
1443 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1452 case CrossfadeViewItem:
1459 /* probably shouldn't happen but if it does, we don't care */
1463 if (item_type != SelectionItem && clicked_audio_trackview && clicked_audio_trackview->audio_track()) {
1465 /* Bounce to disk */
1467 using namespace Menu_Helpers;
1468 MenuList& edit_items = menu->items();
1470 edit_items.push_back (SeparatorElem());
1472 switch (clicked_audio_trackview->audio_track()->freeze_state()) {
1473 case AudioTrack::NoFreeze:
1474 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1477 case AudioTrack::Frozen:
1478 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1481 case AudioTrack::UnFrozen:
1482 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1488 menu->popup (button, time);
1492 Editor::build_track_context_menu (nframes_t ignored)
1494 using namespace Menu_Helpers;
1496 MenuList& edit_items = track_context_menu.items();
1499 add_dstream_context_items (edit_items);
1500 return &track_context_menu;
1504 Editor::build_track_bus_context_menu (nframes_t ignored)
1506 using namespace Menu_Helpers;
1508 MenuList& edit_items = track_context_menu.items();
1511 add_bus_context_items (edit_items);
1512 return &track_context_menu;
1516 Editor::build_track_region_context_menu (nframes_t frame)
1518 using namespace Menu_Helpers;
1519 MenuList& edit_items = track_region_context_menu.items();
1522 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1525 boost::shared_ptr<Diskstream> ds;
1526 boost::shared_ptr<Playlist> pl;
1528 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
1529 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)frame * ds->speed()));
1530 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1531 add_region_context_items (atv->audio_view(), (*i), edit_items);
1537 add_dstream_context_items (edit_items);
1539 return &track_region_context_menu;
1543 Editor::build_track_crossfade_context_menu (nframes_t frame)
1545 using namespace Menu_Helpers;
1546 MenuList& edit_items = track_crossfade_context_menu.items();
1547 edit_items.clear ();
1549 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1552 boost::shared_ptr<Diskstream> ds;
1553 boost::shared_ptr<Playlist> pl;
1554 boost::shared_ptr<AudioPlaylist> apl;
1556 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1558 Playlist::RegionList* regions = pl->regions_at (frame);
1559 AudioPlaylist::Crossfades xfades;
1561 apl->crossfades_at (frame, xfades);
1563 bool many = xfades.size() > 1;
1565 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1566 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1569 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1570 add_region_context_items (atv->audio_view(), (*i), edit_items);
1577 add_dstream_context_items (edit_items);
1579 return &track_crossfade_context_menu;
1584 Editor::analyze_region_selection()
1586 if (analysis_window == 0) {
1587 analysis_window = new AnalysisWindow();
1590 analysis_window->set_session(session);
1592 analysis_window->show_all();
1595 analysis_window->set_regionmode();
1596 analysis_window->analyze();
1598 analysis_window->present();
1602 Editor::analyze_range_selection()
1604 if (analysis_window == 0) {
1605 analysis_window = new AnalysisWindow();
1608 analysis_window->set_session(session);
1610 analysis_window->show_all();
1613 analysis_window->set_rangemode();
1614 analysis_window->analyze();
1616 analysis_window->present();
1618 #endif /* FFT_ANALYSIS */
1623 Editor::build_track_selection_context_menu (nframes_t ignored)
1625 using namespace Menu_Helpers;
1626 MenuList& edit_items = track_selection_context_menu.items();
1627 edit_items.clear ();
1629 add_selection_context_items (edit_items);
1630 // edit_items.push_back (SeparatorElem());
1631 // add_dstream_context_items (edit_items);
1633 return &track_selection_context_menu;
1637 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1639 using namespace Menu_Helpers;
1640 Menu *xfade_menu = manage (new Menu);
1641 MenuList& items = xfade_menu->items();
1642 xfade_menu->set_name ("ArdourContextMenu");
1645 if (xfade->active()) {
1651 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1652 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1654 if (xfade->can_follow_overlap()) {
1656 if (xfade->following_overlap()) {
1657 str = _("Convert to short");
1659 str = _("Convert to full");
1662 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1666 str = xfade->out()->name();
1668 str += xfade->in()->name();
1670 str = _("Crossfade");
1673 edit_items.push_back (MenuElem (str, *xfade_menu));
1674 edit_items.push_back (SeparatorElem());
1678 Editor::xfade_edit_left_region ()
1680 if (clicked_crossfadeview) {
1681 clicked_crossfadeview->left_view.show_region_editor ();
1686 Editor::xfade_edit_right_region ()
1688 if (clicked_crossfadeview) {
1689 clicked_crossfadeview->right_view.show_region_editor ();
1694 Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1696 using namespace Menu_Helpers;
1697 Menu *region_menu = manage (new Menu);
1698 MenuList& items = region_menu->items();
1699 region_menu->set_name ("ArdourContextMenu");
1701 boost::shared_ptr<AudioRegion> ar;
1704 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1707 /* when this particular menu pops up, make the relevant region
1711 region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1713 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1714 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1715 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1716 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1717 items.push_back (SeparatorElem());
1718 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1719 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1720 items.push_back (SeparatorElem());
1722 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::audition_selected_region)));
1723 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1724 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1727 items.push_back (MenuElem (_("Analyze region"), mem_fun(*this, &Editor::analyze_region_selection)));
1730 items.push_back (SeparatorElem());
1732 sigc::connection fooc;
1734 items.push_back (CheckMenuElem (_("Lock")));
1735 region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1736 fooc = region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1737 if (region->locked()) {
1739 region_lock_item->set_active();
1742 items.push_back (CheckMenuElem (_("Mute")));
1743 region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1744 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1745 if (region->muted()) {
1747 region_mute_item->set_active();
1751 if (!Profile->get_sae()) {
1752 items.push_back (CheckMenuElem (_("Opaque")));
1753 region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1754 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1755 if (region->opaque()) {
1757 region_opaque_item->set_active();
1762 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1763 if (region->at_natural_position()) {
1764 items.back().set_sensitive (false);
1767 items.push_back (SeparatorElem());
1771 RegionView* rv = sv->find_view (ar);
1772 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1774 if (!Profile->get_sae()) {
1775 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1777 items.push_back (CheckMenuElem (_("Envelope Visible")));
1778 region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1779 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1780 if (arv->envelope_visible()) {
1782 region_envelope_visible_item->set_active (true);
1786 items.push_back (CheckMenuElem (_("Envelope Active")));
1787 region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1788 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1790 if (ar->envelope_active()) {
1792 region_envelope_active_item->set_active (true);
1796 items.push_back (SeparatorElem());
1799 if (ar->scale_amplitude() != 1.0f) {
1800 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1802 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1806 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1807 items.push_back (SeparatorElem());
1809 /* range related stuff */
1811 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1812 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_audio_region)));
1813 items.push_back (SeparatorElem());
1817 Menu *nudge_menu = manage (new Menu());
1818 MenuList& nudge_items = nudge_menu->items();
1819 nudge_menu->set_name ("ArdourContextMenu");
1821 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false))));
1822 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false))));
1823 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1824 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1826 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1827 items.push_back (SeparatorElem());
1829 Menu *trim_menu = manage (new Menu);
1830 MenuList& trim_items = trim_menu->items();
1831 trim_menu->set_name ("ArdourContextMenu");
1833 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1834 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1835 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1836 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1838 items.push_back (MenuElem (_("Trim"), *trim_menu));
1839 items.push_back (SeparatorElem());
1841 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1842 region_edit_menu_split_item = &items.back();
1844 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1845 region_edit_menu_split_multichannel_item = &items.back();
1847 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1848 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1849 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1850 items.push_back (SeparatorElem());
1851 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_clicked_region)));
1853 /* OK, stick the region submenu at the top of the list, and then add
1857 /* we have to hack up the region name because "_" has a special
1858 meaning for menu titles.
1861 string::size_type pos = 0;
1862 string menu_item_name = region->name();
1864 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1865 menu_item_name.replace (pos, 1, "__");
1869 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1870 edit_items.push_back (SeparatorElem());
1874 Editor::add_selection_context_items (Menu_Helpers::MenuList& items)
1876 using namespace Menu_Helpers;
1878 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
1879 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
1882 items.push_back (SeparatorElem());
1883 items.push_back (MenuElem (_("Analyze range"), mem_fun(*this, &Editor::analyze_range_selection)));
1886 items.push_back (SeparatorElem());
1887 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1888 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1890 items.push_back (SeparatorElem());
1891 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
1892 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
1894 items.push_back (SeparatorElem());
1895 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1897 items.push_back (SeparatorElem());
1898 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
1899 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
1901 items.push_back (SeparatorElem());
1902 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
1903 items.push_back (SeparatorElem());
1904 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
1905 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
1906 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
1907 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
1908 items.push_back (SeparatorElem());
1909 items.push_back (MenuElem (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection)));
1910 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
1914 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1916 using namespace Menu_Helpers;
1920 Menu *play_menu = manage (new Menu);
1921 MenuList& play_items = play_menu->items();
1922 play_menu->set_name ("ArdourContextMenu");
1924 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
1925 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
1926 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
1927 play_items.push_back (SeparatorElem());
1928 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
1930 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1934 Menu *select_menu = manage (new Menu);
1935 MenuList& select_items = select_menu->items();
1936 select_menu->set_name ("ArdourContextMenu");
1938 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1939 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
1940 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
1941 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
1942 select_items.push_back (SeparatorElem());
1943 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
1944 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
1945 select_items.push_back (SeparatorElem());
1946 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
1947 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
1948 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1949 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1950 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
1951 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
1952 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
1954 select_items.push_back (SeparatorElem());
1956 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1960 Menu *cutnpaste_menu = manage (new Menu);
1961 MenuList& cutnpaste_items = cutnpaste_menu->items();
1962 cutnpaste_menu->set_name ("ArdourContextMenu");
1964 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
1965 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
1966 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
1968 cutnpaste_items.push_back (SeparatorElem());
1970 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
1971 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
1973 cutnpaste_items.push_back (SeparatorElem());
1975 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
1977 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
1979 /* Adding new material */
1981 edit_items.push_back (SeparatorElem());
1982 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
1983 edit_items.push_back (MenuElem (_("Insert Existing Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
1987 Menu *nudge_menu = manage (new Menu());
1988 MenuList& nudge_items = nudge_menu->items();
1989 nudge_menu->set_name ("ArdourContextMenu");
1991 edit_items.push_back (SeparatorElem());
1992 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
1993 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
1994 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
1995 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
1997 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2001 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2003 using namespace Menu_Helpers;
2007 Menu *play_menu = manage (new Menu);
2008 MenuList& play_items = play_menu->items();
2009 play_menu->set_name ("ArdourContextMenu");
2011 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2012 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2013 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2017 Menu *select_menu = manage (new Menu);
2018 MenuList& select_items = select_menu->items();
2019 select_menu->set_name ("ArdourContextMenu");
2021 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2022 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2023 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2024 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2025 select_items.push_back (SeparatorElem());
2026 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2027 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2028 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2029 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2031 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2035 Menu *cutnpaste_menu = manage (new Menu);
2036 MenuList& cutnpaste_items = cutnpaste_menu->items();
2037 cutnpaste_menu->set_name ("ArdourContextMenu");
2039 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2040 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2041 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2043 Menu *nudge_menu = manage (new Menu());
2044 MenuList& nudge_items = nudge_menu->items();
2045 nudge_menu->set_name ("ArdourContextMenu");
2047 edit_items.push_back (SeparatorElem());
2048 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2049 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2050 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2051 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2053 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2056 /* CURSOR SETTING AND MARKS AND STUFF */
2059 Editor::set_snap_to (SnapType st)
2061 unsigned int snap_ind = (unsigned int)st;
2064 if ( snap_ind > snap_type_strings.size() - 1 ) {
2066 snap_type = (SnapType)snap_ind;
2069 string str = snap_type_strings[snap_ind];
2071 if (str != snap_type_selector.get_active_text()) {
2072 snap_type_selector.set_active_text (str);
2077 switch (snap_type) {
2078 case SnapToAThirtysecondBeat:
2079 case SnapToASixteenthBeat:
2080 case SnapToAEighthBeat:
2081 case SnapToAQuarterBeat:
2082 case SnapToAThirdBeat:
2083 update_tempo_based_rulers ();
2091 Editor::set_snap_mode (SnapMode mode)
2094 string str = snap_mode_strings[(int)mode];
2096 if (str != snap_mode_selector.get_active_text ()) {
2097 snap_mode_selector.set_active_text (str);
2103 Editor::set_edit_point_preference (EditPoint ep)
2105 bool changed = _edit_point != ep;
2108 string str = edit_point_strings[(int)ep];
2110 if (str != edit_point_selector.get_active_text ()) {
2111 edit_point_selector.set_active_text (str);
2118 if (Profile->get_sae()) {
2120 switch (zoom_focus) {
2121 case ZoomFocusMouse:
2122 case ZoomFocusPlayhead:
2124 switch (_edit_point) {
2126 set_zoom_focus (ZoomFocusMouse);
2128 case EditAtPlayhead:
2129 set_zoom_focus (ZoomFocusPlayhead);
2131 case EditAtSelectedMarker:
2132 set_zoom_focus (ZoomFocusEdit);
2145 Editor::set_state (const XMLNode& node)
2147 const XMLProperty* prop;
2149 int x, y, xoff, yoff;
2152 if ((prop = node.property ("id")) != 0) {
2153 _id = prop->value ();
2156 if ((geometry = find_named_node (node, "geometry")) == 0) {
2158 g.base_width = default_width;
2159 g.base_height = default_height;
2167 g.base_width = atoi(geometry->property("x_size")->value());
2168 g.base_height = atoi(geometry->property("y_size")->value());
2169 x = atoi(geometry->property("x_pos")->value());
2170 y = atoi(geometry->property("y_pos")->value());
2171 xoff = atoi(geometry->property("x_off")->value());
2172 yoff = atoi(geometry->property("y_off")->value());
2175 set_default_size (g.base_width, g.base_height);
2178 if (session && (prop = node.property ("playhead"))) {
2179 nframes_t pos = atol (prop->value().c_str());
2180 playhead_cursor->set_position (pos);
2182 playhead_cursor->set_position (0);
2184 /* reset_x_origin() doesn't work right here, since the old
2185 position may be zero already, and it does nothing in such
2190 horizontal_adjustment.set_value (0);
2193 if ((prop = node.property ("mixer-width"))) {
2194 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2197 if ((prop = node.property ("zoom-focus"))) {
2198 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2201 if ((prop = node.property ("zoom"))) {
2202 reset_zoom (PBD::atof (prop->value()));
2205 if ((prop = node.property ("snap-to"))) {
2206 set_snap_to ((SnapType) atoi (prop->value()));
2209 if ((prop = node.property ("snap-mode"))) {
2210 set_snap_mode ((SnapMode) atoi (prop->value()));
2213 if ((prop = node.property ("edit-point"))) {
2214 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point));
2217 if ((prop = node.property ("mouse-mode"))) {
2218 MouseMode m = str2mousemode(prop->value());
2219 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2220 set_mouse_mode (m, true);
2222 mouse_mode = MouseGain; /* lie, to force the mode switch */
2223 set_mouse_mode (MouseObject, true);
2226 if ((prop = node.property ("show-waveforms"))) {
2227 bool yn = (prop->value() == "yes");
2228 _show_waveforms = !yn;
2229 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformVisibility"));
2231 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2232 /* do it twice to force the change */
2233 tact->set_active (!yn);
2234 tact->set_active (yn);
2238 if ((prop = node.property ("show-waveforms-recording"))) {
2239 bool yn = (prop->value() == "yes");
2240 _show_waveforms_recording = !yn;
2241 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2243 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2244 /* do it twice to force the change */
2245 tact->set_active (!yn);
2246 tact->set_active (yn);
2250 if ((prop = node.property ("show-measures"))) {
2251 bool yn = (prop->value() == "yes");
2252 _show_measures = !yn;
2253 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2255 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2256 /* do it twice to force the change */
2257 tact->set_active (!yn);
2258 tact->set_active (yn);
2262 if ((prop = node.property ("follow-playhead"))) {
2263 bool yn = (prop->value() == "yes");
2264 set_follow_playhead (yn);
2265 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2267 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2268 if (tact->get_active() != yn) {
2269 tact->set_active (yn);
2274 if ((prop = node.property ("region-list-sort-type"))) {
2275 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2276 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2279 if ((prop = node.property ("xfades-visible"))) {
2280 bool yn = (prop->value() == "yes");
2281 _xfade_visibility = !yn;
2282 // set_xfade_visibility (yn);
2285 if ((prop = node.property ("show-editor-mixer"))) {
2287 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2290 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2291 bool yn = (prop->value() == X_("yes"));
2293 /* do it twice to force the change */
2295 tact->set_active (!yn);
2296 tact->set_active (yn);
2305 Editor::get_state ()
2307 XMLNode* node = new XMLNode ("Editor");
2310 _id.print (buf, sizeof (buf));
2311 node->add_property ("id", buf);
2313 if (is_realized()) {
2314 Glib::RefPtr<Gdk::Window> win = get_window();
2316 int x, y, xoff, yoff, width, height;
2317 win->get_root_origin(x, y);
2318 win->get_position(xoff, yoff);
2319 win->get_size(width, height);
2321 XMLNode* geometry = new XMLNode ("geometry");
2323 snprintf(buf, sizeof(buf), "%d", width);
2324 geometry->add_property("x_size", string(buf));
2325 snprintf(buf, sizeof(buf), "%d", height);
2326 geometry->add_property("y_size", string(buf));
2327 snprintf(buf, sizeof(buf), "%d", x);
2328 geometry->add_property("x_pos", string(buf));
2329 snprintf(buf, sizeof(buf), "%d", y);
2330 geometry->add_property("y_pos", string(buf));
2331 snprintf(buf, sizeof(buf), "%d", xoff);
2332 geometry->add_property("x_off", string(buf));
2333 snprintf(buf, sizeof(buf), "%d", yoff);
2334 geometry->add_property("y_off", string(buf));
2335 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2336 geometry->add_property("edit_pane_pos", string(buf));
2338 node->add_child_nocopy (*geometry);
2341 maybe_add_mixer_strip_width (*node);
2343 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2344 node->add_property ("zoom-focus", buf);
2345 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2346 node->add_property ("zoom", buf);
2347 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2348 node->add_property ("snap-to", buf);
2349 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2350 node->add_property ("snap-mode", buf);
2352 node->add_property ("edit-point", enum_2_string (_edit_point));
2354 snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
2355 node->add_property ("playhead", buf);
2357 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2358 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2359 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2360 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2361 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2362 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2363 node->add_property ("mouse-mode", enum2str(mouse_mode));
2365 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2367 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2368 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2377 Editor::trackview_by_y_position (double y)
2379 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2383 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2392 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2394 Location* before = 0;
2395 Location* after = 0;
2397 if (!session || snap_mode == SnapOff) {
2401 const nframes64_t one_second = session->frame_rate();
2402 const nframes64_t one_minute = session->frame_rate() * 60;
2403 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2404 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2405 nframes64_t presnap = start;
2407 switch (snap_type) {
2410 start = (nframes_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2412 start = (nframes_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2416 case SnapToSMPTEFrame:
2417 if (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2)) {
2418 start = (nframes_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2420 start = (nframes_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2424 case SnapToSMPTESeconds:
2425 if (session->smpte_offset_negative())
2427 start += session->smpte_offset ();
2429 start -= session->smpte_offset ();
2431 if (start % one_smpte_second > one_smpte_second / 2) {
2432 start = (nframes_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2434 start = (nframes_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2437 if (session->smpte_offset_negative())
2439 start -= session->smpte_offset ();
2441 start += session->smpte_offset ();
2445 case SnapToSMPTEMinutes:
2446 if (session->smpte_offset_negative())
2448 start += session->smpte_offset ();
2450 start -= session->smpte_offset ();
2452 if (start % one_smpte_minute > one_smpte_minute / 2) {
2453 start = (nframes_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2455 start = (nframes_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2457 if (session->smpte_offset_negative())
2459 start -= session->smpte_offset ();
2461 start += session->smpte_offset ();
2466 if (start % one_second > one_second / 2) {
2467 start = (nframes_t) ceil ((double) start / one_second) * one_second;
2469 start = (nframes_t) floor ((double) start / one_second) * one_second;
2474 if (start % one_minute > one_minute / 2) {
2475 start = (nframes_t) ceil ((double) start / one_minute) * one_minute;
2477 start = (nframes_t) floor ((double) start / one_minute) * one_minute;
2482 start = session->tempo_map().round_to_bar (start, direction);
2486 start = session->tempo_map().round_to_beat (start, direction);
2489 case SnapToAThirtysecondBeat:
2490 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2493 case SnapToASixteenthBeat:
2494 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2497 case SnapToAEighthBeat:
2498 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2501 case SnapToAQuarterBeat:
2502 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2505 case SnapToAThirdBeat:
2506 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2514 before = session->locations()->first_location_before (start);
2515 after = session->locations()->first_location_after (start);
2517 if (direction < 0) {
2519 start = before->start();
2523 } else if (direction > 0) {
2525 start = after->start();
2527 start = session->current_end_frame();
2532 /* find nearest of the two */
2533 if ((start - before->start()) < (after->start() - start)) {
2534 start = before->start();
2536 start = after->start();
2539 start = before->start();
2542 start = after->start();
2549 case SnapToRegionStart:
2550 case SnapToRegionEnd:
2551 case SnapToRegionSync:
2552 case SnapToRegionBoundary:
2553 if (!region_boundary_cache.empty()) {
2554 vector<nframes_t>::iterator i;
2556 if (direction > 0) {
2557 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2559 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2562 if (i != region_boundary_cache.end()) {
2565 start = region_boundary_cache.back();
2571 switch (snap_mode) {
2577 if (presnap > start) {
2578 if (presnap > (start + unit_to_frame(snap_threshold))) {
2582 } else if (presnap < start) {
2583 if (presnap < (start - unit_to_frame(snap_threshold))) {
2589 /* handled at entry */
2596 Editor::setup_toolbar ()
2601 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2603 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2606 /* Mode Buttons (tool selection) */
2608 vector<ToggleButton *> mouse_mode_buttons;
2610 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2611 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2612 mouse_mode_buttons.push_back (&mouse_move_button);
2614 if (!Profile->get_sae()) {
2615 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2616 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2617 mouse_mode_buttons.push_back (&mouse_select_button);
2619 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2620 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2621 mouse_mode_buttons.push_back (&mouse_gain_button);
2624 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2625 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2626 mouse_mode_buttons.push_back (&mouse_zoom_button);
2627 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2628 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2629 mouse_mode_buttons.push_back (&mouse_timefx_button);
2630 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2631 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2632 mouse_mode_buttons.push_back (&mouse_audition_button);
2634 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2636 HBox* mode_box = manage(new HBox);
2637 mode_box->set_border_width (2);
2638 mode_box->set_spacing(4);
2639 mouse_mode_button_box.set_spacing(1);
2640 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2641 if (!Profile->get_sae()) {
2642 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2644 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2645 if (!Profile->get_sae()) {
2646 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2648 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2649 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2650 mouse_mode_button_box.set_homogeneous(true);
2652 vector<string> edit_mode_strings;
2653 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2654 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2656 edit_mode_selector.set_name ("EditModeSelector");
2657 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2658 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2659 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2661 mode_box->pack_start(edit_mode_selector);
2662 mode_box->pack_start(mouse_mode_button_box);
2664 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2665 mouse_mode_tearoff->set_name ("MouseModeBase");
2667 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2668 &mouse_mode_tearoff->tearoff_window()));
2669 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2670 &mouse_mode_tearoff->tearoff_window(), 1));
2671 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2672 &mouse_mode_tearoff->tearoff_window()));
2673 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2674 &mouse_mode_tearoff->tearoff_window(), 1));
2676 mouse_move_button.set_name ("MouseModeButton");
2677 mouse_select_button.set_name ("MouseModeButton");
2678 mouse_gain_button.set_name ("MouseModeButton");
2679 mouse_zoom_button.set_name ("MouseModeButton");
2680 mouse_timefx_button.set_name ("MouseModeButton");
2681 mouse_audition_button.set_name ("MouseModeButton");
2683 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2684 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2685 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2686 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2687 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2688 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2690 mouse_move_button.unset_flags (CAN_FOCUS);
2691 mouse_select_button.unset_flags (CAN_FOCUS);
2692 mouse_gain_button.unset_flags (CAN_FOCUS);
2693 mouse_zoom_button.unset_flags (CAN_FOCUS);
2694 mouse_timefx_button.unset_flags (CAN_FOCUS);
2695 mouse_audition_button.unset_flags (CAN_FOCUS);
2697 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2698 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2700 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2701 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2702 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2703 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2704 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2706 // mouse_move_button.set_active (true);
2711 zoom_box.set_spacing (1);
2712 zoom_box.set_border_width (2);
2714 zoom_in_button.set_name ("EditorTimeButton");
2715 zoom_in_button.set_size_request(-1,16);
2716 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2717 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2718 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2720 zoom_out_button.set_name ("EditorTimeButton");
2721 zoom_out_button.set_size_request(-1,16);
2722 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2723 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2724 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2726 zoom_out_full_button.set_name ("EditorTimeButton");
2727 zoom_out_full_button.set_size_request(-1,16);
2728 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2729 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2730 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2732 zoom_focus_selector.set_name ("ZoomFocusSelector");
2733 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, "Playhead", FUDGE, 0);
2734 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
2735 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2736 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2738 zoom_box.pack_start (zoom_focus_selector, true, true);
2739 zoom_box.pack_start (zoom_out_button, false, false);
2740 zoom_box.pack_start (zoom_in_button, false, false);
2741 zoom_box.pack_start (zoom_out_full_button, false, false);
2743 snap_box.set_spacing (1);
2744 snap_box.set_border_width (2);
2746 snap_type_selector.set_name ("SnapTypeSelector");
2747 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, "SMPTE Seconds", 2+FUDGE, 10);
2748 set_popdown_strings (snap_type_selector, snap_type_strings);
2749 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2750 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2752 snap_mode_selector.set_name ("SnapModeSelector");
2753 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, "Magnetic Snap", 2+FUDGE, 10);
2754 set_popdown_strings (snap_mode_selector, snap_mode_strings);
2755 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2756 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2758 edit_point_selector.set_name ("SnapModeSelector");
2759 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, "Playhead", 2+FUDGE, 10);
2760 set_popdown_strings (edit_point_selector, edit_point_strings);
2761 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2762 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2764 snap_box.pack_start (edit_point_clock, false, false);
2765 snap_box.pack_start (snap_mode_selector, false, false);
2766 snap_box.pack_start (snap_type_selector, false, false);
2767 snap_box.pack_start (edit_point_selector, false, false);
2771 HBox *nudge_box = manage (new HBox);
2772 nudge_box->set_spacing(1);
2773 nudge_box->set_border_width (2);
2775 nudge_forward_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::nudge_forward), false));
2776 nudge_backward_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::nudge_backward), false));
2778 nudge_box->pack_start (nudge_backward_button, false, false);
2779 nudge_box->pack_start (nudge_forward_button, false, false);
2780 nudge_box->pack_start (nudge_clock, false, false);
2783 /* Pack everything in... */
2785 HBox* hbox = new HBox;
2786 hbox->set_spacing(10);
2788 tools_tearoff = new TearOff (*hbox);
2789 tools_tearoff->set_name ("MouseModeBase");
2791 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2792 &tools_tearoff->tearoff_window()));
2793 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2794 &tools_tearoff->tearoff_window(), 0));
2795 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2796 &tools_tearoff->tearoff_window()));
2797 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2798 &tools_tearoff->tearoff_window(), 0));
2800 toolbar_hbox.set_spacing (10);
2801 toolbar_hbox.set_border_width (1);
2803 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2804 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2807 hbox->pack_start (snap_box, false, false);
2808 // hbox->pack_start (zoom_box, false, false);
2809 hbox->pack_start (*nudge_box, false, false);
2813 toolbar_base.set_name ("ToolBarBase");
2814 toolbar_base.add (toolbar_hbox);
2816 toolbar_frame.set_shadow_type (SHADOW_OUT);
2817 toolbar_frame.set_name ("BaseFrame");
2818 toolbar_frame.add (toolbar_base);
2822 Editor::convert_drop_to_paths (vector<ustring>& paths,
2823 const RefPtr<Gdk::DragContext>& context,
2826 const SelectionData& data,
2835 vector<ustring> uris = data.get_uris();
2839 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
2840 are actually URI lists. So do it by hand.
2843 if (data.get_target() != "text/plain") {
2847 /* Parse the "uri-list" format that Nautilus provides,
2848 where each pathname is delimited by \r\n
2851 const char* p = data.get_text().c_str();
2858 while (g_ascii_isspace (*p))
2862 while (*q && (*q != '\n') && (*q != '\r'))
2868 while (q > p && g_ascii_isspace (*q))
2873 uris.push_back (ustring (p, q - p + 1));
2877 p = strchr (p, '\n');
2887 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
2889 if ((*i).substr (0,7) == "file://") {
2893 PBD::url_decode (p);
2895 // scan forward past three slashes
2897 ustring::size_type slashcnt = 0;
2898 ustring::size_type n = 0;
2899 ustring::iterator x = p.begin();
2901 while (slashcnt < 3 && x != p.end()) {
2904 } else if (slashcnt == 3) {
2911 if (slashcnt != 3 || x == p.end()) {
2912 error << _("malformed URL passed to drag-n-drop code") << endmsg;
2916 paths.push_back (p.substr (n - 1));
2924 Editor::new_tempo_section ()
2930 Editor::map_transport_state ()
2932 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
2934 if (session->transport_stopped()) {
2935 have_pending_keyboard_selection = false;
2938 update_loop_range_view (true);
2943 Editor::State::State ()
2945 selection = new Selection;
2948 Editor::State::~State ()
2954 Editor::get_memento () const
2956 State *state = new State;
2958 store_state (*state);
2959 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
2963 Editor::store_state (State& state) const
2965 *state.selection = *selection;
2969 Editor::restore_state (State *state)
2971 if (*selection == *state->selection) {
2975 *selection = *state->selection;
2976 time_selection_changed ();
2977 region_selection_changed ();
2979 /* XXX other selection change handlers? */
2983 Editor::begin_reversible_command (string name)
2986 // before = &get_state();
2987 session->begin_reversible_command (name);
2992 Editor::commit_reversible_command ()
2995 // session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
2996 session->commit_reversible_command ();
3001 Editor::set_edit_group_solo (Route& route, bool yn)
3003 RouteGroup *edit_group;
3005 if ((edit_group = route.edit_group()) != 0) {
3006 edit_group->apply (&Route::set_solo, yn, this);
3008 route.set_solo (yn, this);
3013 Editor::set_edit_group_mute (Route& route, bool yn)
3015 RouteGroup *edit_group = 0;
3017 if ((edit_group == route.edit_group()) != 0) {
3018 edit_group->apply (&Route::set_mute, yn, this);
3020 route.set_mute (yn, this);
3025 Editor::history_changed ()
3029 if (undo_action && session) {
3030 if (session->undo_depth() == 0) {
3033 label = string_compose(_("Undo (%1)"), session->next_undo());
3035 undo_action->property_label() = label;
3038 if (redo_action && session) {
3039 if (session->redo_depth() == 0) {
3042 label = string_compose(_("Redo (%1)"), session->next_redo());
3044 redo_action->property_label() = label;
3049 Editor::duplicate_dialog (bool with_dialog)
3053 if (mouse_mode == MouseRange) {
3054 if (selection->time.length() == 0) {
3060 if (mouse_mode != MouseRange) {
3062 ensure_entered_region_selected (true);
3064 if (selection->regions.empty()) {
3071 ArdourDialog win ("duplicate dialog");
3072 Label label (_("Duplicate how many times?"));
3073 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3074 SpinButton spinner (adjustment);
3076 win.get_vbox()->set_spacing (12);
3077 win.get_vbox()->pack_start (label);
3079 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3080 place, visually. so do this by hand.
3083 win.get_vbox()->pack_start (spinner);
3084 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3089 win.add_button (Stock::OK, RESPONSE_ACCEPT);
3090 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3092 win.set_position (WIN_POS_MOUSE);
3094 spinner.grab_focus ();
3096 switch (win.run ()) {
3097 case RESPONSE_ACCEPT:
3103 times = adjustment.get_value();
3106 if (mouse_mode == MouseRange) {
3107 duplicate_selection (times);
3109 duplicate_some_regions (selection->regions, times);
3114 Editor::show_verbose_canvas_cursor ()
3116 verbose_canvas_cursor->raise_to_top();
3117 verbose_canvas_cursor->show();
3118 verbose_cursor_visible = true;
3122 Editor::hide_verbose_canvas_cursor ()
3124 verbose_canvas_cursor->hide();
3125 verbose_cursor_visible = false;
3129 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3131 /* XXX get origin of canvas relative to root window,
3132 add x and y and check compared to gdk_screen_{width,height}
3134 verbose_canvas_cursor->property_text() = txt.c_str();
3135 verbose_canvas_cursor->property_x() = x;
3136 verbose_canvas_cursor->property_y() = y;
3140 Editor::set_verbose_canvas_cursor_text (const string & txt)
3142 verbose_canvas_cursor->property_text() = txt.c_str();
3146 Editor::set_edit_mode (EditMode m)
3148 Config->set_edit_mode (m);
3152 Editor::cycle_edit_mode ()
3154 switch (Config->get_edit_mode()) {
3156 Config->set_edit_mode (Splice);
3159 Config->set_edit_mode (Slide);
3165 Editor::edit_mode_selection_done ()
3171 string choice = edit_mode_selector.get_active_text();
3172 EditMode mode = Slide;
3174 if (choice == _("Splice Edit")) {
3176 } else if (choice == _("Slide Edit")) {
3180 Config->set_edit_mode (mode);
3184 Editor::snap_type_selection_done ()
3186 string choice = snap_type_selector.get_active_text();
3187 SnapType snaptype = SnapToBeat;
3189 if (choice == _("Beats/3")) {
3190 snaptype = SnapToAThirdBeat;
3191 } else if (choice == _("Beats/4")) {
3192 snaptype = SnapToAQuarterBeat;
3193 } else if (choice == _("Beats/8")) {
3194 snaptype = SnapToAEighthBeat;
3195 } else if (choice == _("Beats/16")) {
3196 snaptype = SnapToASixteenthBeat;
3197 } else if (choice == _("Beats/32")) {
3198 snaptype = SnapToAThirtysecondBeat;
3199 } else if (choice == _("Beats")) {
3200 snaptype = SnapToBeat;
3201 } else if (choice == _("Bars")) {
3202 snaptype = SnapToBar;
3203 } else if (choice == _("Marks")) {
3204 snaptype = SnapToMark;
3205 } else if (choice == _("Region starts")) {
3206 snaptype = SnapToRegionStart;
3207 } else if (choice == _("Region ends")) {
3208 snaptype = SnapToRegionEnd;
3209 } else if (choice == _("Region bounds")) {
3210 snaptype = SnapToRegionBoundary;
3211 } else if (choice == _("Region syncs")) {
3212 snaptype = SnapToRegionSync;
3213 } else if (choice == _("CD Frames")) {
3214 snaptype = SnapToCDFrame;
3215 } else if (choice == _("SMPTE Frames")) {
3216 snaptype = SnapToSMPTEFrame;
3217 } else if (choice == _("SMPTE Seconds")) {
3218 snaptype = SnapToSMPTESeconds;
3219 } else if (choice == _("SMPTE Minutes")) {
3220 snaptype = SnapToSMPTEMinutes;
3221 } else if (choice == _("Seconds")) {
3222 snaptype = SnapToSeconds;
3223 } else if (choice == _("Minutes")) {
3224 snaptype = SnapToMinutes;
3227 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3229 ract->set_active ();
3234 Editor::snap_mode_selection_done ()
3236 string choice = snap_mode_selector.get_active_text();
3237 SnapMode mode = SnapNormal;
3239 if (choice == _("No Grid")) {
3241 } else if (choice == _("Grid")) {
3243 } else if (choice == _("Magnetic")) {
3244 mode = SnapMagnetic;
3247 RefPtr<RadioAction> ract = snap_mode_action (mode);
3250 ract->set_active (true);
3255 Editor::cycle_edit_point (bool with_marker)
3257 switch (_edit_point) {
3259 set_edit_point_preference (EditAtPlayhead);
3261 case EditAtPlayhead:
3263 set_edit_point_preference (EditAtSelectedMarker);
3265 set_edit_point_preference (EditAtMouse);
3268 case EditAtSelectedMarker:
3269 set_edit_point_preference (EditAtMouse);
3275 Editor::edit_point_selection_done ()
3277 string choice = edit_point_selector.get_active_text();
3278 EditPoint ep = EditAtSelectedMarker;
3280 if (choice == _("Marker")) {
3281 set_edit_point_preference (EditAtSelectedMarker);
3282 } else if (choice == _("Playhead")) {
3283 set_edit_point_preference (EditAtPlayhead);
3285 set_edit_point_preference (EditAtMouse);
3288 RefPtr<RadioAction> ract = edit_point_action (ep);
3291 ract->set_active (true);
3296 Editor::zoom_focus_selection_done ()
3298 string choice = zoom_focus_selector.get_active_text();
3299 ZoomFocus focus_type = ZoomFocusLeft;
3301 if (choice == _("Left")) {
3302 focus_type = ZoomFocusLeft;
3303 } else if (choice == _("Right")) {
3304 focus_type = ZoomFocusRight;
3305 } else if (choice == _("Center")) {
3306 focus_type = ZoomFocusCenter;
3307 } else if (choice == _("Playhead")) {
3308 focus_type = ZoomFocusPlayhead;
3309 } else if (choice == _("Mouse")) {
3310 focus_type = ZoomFocusMouse;
3311 } else if (choice == _("Edit Point")) {
3312 focus_type = ZoomFocusEdit;
3315 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3318 ract->set_active ();
3323 Editor::edit_controls_button_release (GdkEventButton* ev)
3325 if (Keyboard::is_context_menu_event (ev)) {
3326 ARDOUR_UI::instance()->add_route (this);
3332 Editor::mouse_select_button_release (GdkEventButton* ev)
3334 /* this handles just right-clicks */
3336 if (ev->button != 3) {
3343 Editor::TrackViewList *
3344 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3347 TrackViewList::iterator i;
3349 v = new TrackViewList;
3351 if (track == 0 && group == 0) {
3355 for (i = track_views.begin(); i != track_views.end (); ++i) {
3359 } else if (track != 0 && group == 0 || (track != 0 && group != 0 && !group->is_active())) {
3361 /* just the view for this track
3364 v->push_back (track);
3368 /* views for all tracks in the edit group */
3370 for (i = track_views.begin(); i != track_views.end (); ++i) {
3372 if (group == 0 || (*i)->edit_group() == group) {
3382 Editor::set_zoom_focus (ZoomFocus f)
3384 string str = zoom_focus_strings[(int)f];
3386 if (str != zoom_focus_selector.get_active_text()) {
3387 zoom_focus_selector.set_active_text (str);
3390 if (zoom_focus != f) {
3393 ZoomFocusChanged (); /* EMIT_SIGNAL */
3400 Editor::ensure_float (Window& win)
3402 win.set_transient_for (*this);
3406 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3408 /* recover or initialize pane positions. do this here rather than earlier because
3409 we don't want the positions to change the child allocations, which they seem to do.
3415 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3417 static int32_t done;
3420 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3421 width = default_width;
3422 height = default_height;
3424 width = atoi(geometry->property("x_size")->value());
3425 height = atoi(geometry->property("y_size")->value());
3428 if (which == static_cast<Paned*> (&edit_pane)) {
3434 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3435 /* initial allocation is 90% to canvas, 10% to notebook */
3436 pos = (int) floor (alloc.get_width() * 0.90f);
3437 snprintf (buf, sizeof(buf), "%d", pos);
3439 pos = atoi (prop->value());
3442 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3443 edit_pane.set_position (pos);
3444 pre_maximal_pane_position = pos;
3450 Editor::detach_tearoff (Box* b, Window* w)
3452 if (tools_tearoff->torn_off() &&
3453 mouse_mode_tearoff->torn_off()) {
3454 top_hbox.remove (toolbar_frame);
3459 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3461 if (toolbar_frame.get_parent() == 0) {
3462 top_hbox.pack_end (toolbar_frame);
3467 Editor::set_show_measures (bool yn)
3469 if (_show_measures != yn) {
3472 if ((_show_measures = yn) == true) {
3480 Editor::toggle_follow_playhead ()
3482 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3484 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3485 set_follow_playhead (tact->get_active());
3490 Editor::set_follow_playhead (bool yn)
3492 if (_follow_playhead != yn) {
3493 if ((_follow_playhead = yn) == true) {
3495 update_current_screen ();
3502 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3504 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3506 xfade->set_active (!xfade->active());
3511 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3513 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3515 xfade->set_follow_overlap (!xfade->following_overlap());
3520 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3522 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3528 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3532 switch (cew.run ()) {
3533 case RESPONSE_ACCEPT:
3540 xfade->StateChanged (Change (~0));
3544 Editor::playlist_selector () const
3546 return *_playlist_selector;
3550 Editor::get_nudge_distance (nframes_t pos, nframes_t& next)
3554 ret = nudge_clock.current_duration (pos);
3555 next = ret + 1; /* XXXX fix me */
3561 Editor::end_location_changed (Location* location)
3563 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3564 reset_scrolling_region ();
3568 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3570 ArdourDialog dialog ("playlist deletion dialog");
3571 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3572 "If left alone, no audio files used by it will be cleaned.\n"
3573 "If deleted, audio files used by it alone by will cleaned."),
3576 dialog.set_position (WIN_POS_CENTER);
3577 dialog.get_vbox()->pack_start (label);
3581 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3582 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3583 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3585 switch (dialog.run ()) {
3586 case RESPONSE_ACCEPT:
3587 /* delete the playlist */
3591 case RESPONSE_REJECT:
3592 /* keep the playlist */
3604 Editor::audio_region_selection_covers (nframes_t where)
3606 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3607 if ((*a)->region()->covers (where)) {
3616 Editor::prepare_for_cleanup ()
3618 cut_buffer->clear_regions ();
3619 cut_buffer->clear_playlists ();
3621 selection->clear_regions ();
3622 selection->clear_playlists ();
3626 Editor::transport_loop_location()
3629 return session->locations()->auto_loop_location();
3636 Editor::transport_punch_location()
3639 return session->locations()->auto_punch_location();
3646 Editor::control_layout_scroll (GdkEventScroll* ev)
3648 switch (ev->direction) {
3650 scroll_tracks_up_line ();
3654 case GDK_SCROLL_DOWN:
3655 scroll_tracks_down_line ();
3659 /* no left/right handling yet */
3667 /** A new snapshot has been selected.
3670 Editor::snapshot_display_selection_changed ()
3672 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
3674 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
3676 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
3678 if (snap_name.length() == 0) {
3682 if (session->snap_name() == snap_name) {
3686 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
3691 Editor::snapshot_display_button_press (GdkEventButton* ev)
3693 if (ev->button == 3) {
3694 /* Right-click on the snapshot list. Work out which snapshot it
3696 Gtk::TreeModel::Path path;
3697 Gtk::TreeViewColumn* col;
3700 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
3701 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
3703 Gtk::TreeModel::Row row = *iter;
3704 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
3713 /** Pop up the snapshot display context menu.
3714 * @param button Button used to open the menu.
3715 * @param time Menu open time.
3716 * @snapshot_name Name of the snapshot that the menu click was over.
3720 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
3722 using namespace Menu_Helpers;
3724 MenuList& items (snapshot_context_menu.items());
3727 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
3729 items.push_back (MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)));
3730 if (!modification_allowed) {
3731 items.back().set_sensitive (false);
3734 items.push_back (MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)));
3735 if (!modification_allowed) {
3736 items.back().set_sensitive (false);
3739 snapshot_context_menu.popup (button, time);
3743 Editor::rename_snapshot (Glib::ustring old_name)
3745 ArdourPrompter prompter(true);
3749 prompter.set_name ("Prompter");
3750 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
3751 prompter.set_prompt (_("New name of snapshot"));
3752 prompter.set_initial_text (old_name);
3754 if (prompter.run() == RESPONSE_ACCEPT) {
3755 prompter.get_result (new_name);
3756 if (new_name.length()) {
3757 session->rename_state (old_name, new_name);
3758 redisplay_snapshots ();
3765 Editor::remove_snapshot (Glib::ustring name)
3767 vector<string> choices;
3769 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
3771 choices.push_back (_("No, do nothing."));
3772 choices.push_back (_("Yes, remove it."));
3774 Gtkmm2ext::Choice prompter (prompt, choices);
3776 if (prompter.run () == 1) {
3777 session->remove_state (name);
3778 redisplay_snapshots ();
3783 Editor::redisplay_snapshots ()
3789 vector<string*>* states;
3791 if ((states = session->possible_states()) == 0) {
3795 snapshot_display_model->clear ();
3797 for (vector<string*>::iterator i = states->begin(); i != states->end(); ++i) {
3798 string statename = *(*i);
3799 TreeModel::Row row = *(snapshot_display_model->append());
3801 /* this lingers on in case we ever want to change the visible
3802 name of the snapshot.
3805 string display_name;
3806 display_name = statename;
3808 if (statename == session->snap_name()) {
3809 snapshot_display.get_selection()->select(row);
3812 row[snapshot_display_columns.visible_name] = display_name;
3813 row[snapshot_display_columns.real_name] = statename;
3820 Editor::session_state_saved (string snap_name)
3822 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
3823 redisplay_snapshots ();
3827 Editor::maximise_editing_space ()
3829 initial_ruler_update_required = true;
3831 mouse_mode_tearoff->set_visible (false);
3832 tools_tearoff->set_visible (false);
3834 pre_maximal_pane_position = edit_pane.get_position();
3835 pre_maximal_editor_width = this->get_width();
3837 if(post_maximal_pane_position == 0) {
3838 post_maximal_pane_position = edit_pane.get_width();
3843 if(post_maximal_editor_width) {
3844 edit_pane.set_position (post_maximal_pane_position -
3845 abs(post_maximal_editor_width - pre_maximal_editor_width));
3847 edit_pane.set_position (post_maximal_pane_position);
3852 Editor::restore_editing_space ()
3854 initial_ruler_update_required = true;
3856 // user changed width of pane during fullscreen
3857 if(post_maximal_pane_position != edit_pane.get_position()) {
3858 post_maximal_pane_position = edit_pane.get_position();
3863 mouse_mode_tearoff->set_visible (true);
3864 tools_tearoff->set_visible (true);
3865 post_maximal_editor_width = this->get_width();
3868 edit_pane.set_position (
3869 pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width)
3874 * Make new playlists for a given track and also any others that belong
3875 * to the same active edit group.
3880 Editor::new_playlists (TimeAxisView* v)
3882 begin_reversible_command (_("new playlists"));
3883 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
3884 commit_reversible_command ();
3889 * Use a copy of the current playlist for a given track and also any others that belong
3890 * to the same active edit group.
3895 Editor::copy_playlists (TimeAxisView* v)
3897 begin_reversible_command (_("copy playlists"));
3898 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
3899 commit_reversible_command ();
3904 * Clear the current playlist for a given track and also any others that belong
3905 * to the same active edit group.
3910 Editor::clear_playlists (TimeAxisView* v)
3912 begin_reversible_command (_("clear playlists"));
3913 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
3914 commit_reversible_command ();
3918 Editor::mapped_use_new_playlist (AudioTimeAxisView& atv, uint32_t sz)
3920 atv.use_new_playlist (sz > 1 ? false : true);
3924 Editor::mapped_use_copy_playlist (AudioTimeAxisView& atv, uint32_t sz)
3926 atv.use_copy_playlist (sz > 1 ? false : true);
3930 Editor::mapped_clear_playlist (AudioTimeAxisView& atv, uint32_t sz)
3932 atv.clear_playlist ();
3936 Editor::on_key_press_event (GdkEventKey* ev)
3938 return key_press_focus_accelerator_handler (*this, ev);
3942 Editor::on_key_release_event (GdkEventKey* ev)
3944 return Gtk::Window::on_key_release_event (ev);
3945 // return key_press_focus_accelerator_handler (*this, ev);
3949 Editor::reset_x_origin (nframes_t frame)
3951 queue_visual_change (frame);
3955 Editor::reset_zoom (double fpu)
3957 queue_visual_change (fpu);
3961 Editor::reposition_and_zoom (nframes_t frame, double fpu)
3963 reset_x_origin (frame);
3968 Editor::swap_visual_state ()
3970 if (last_visual_state.frames_per_unit == 0) {
3975 /* note: the correct functionality here is very dependent on the ordering of
3976 setting zoom focus, horizontal position and finally zoom. this is because
3977 it is set_frames_per_unit() that overwrites last_visual_state.
3980 set_zoom_focus (last_visual_state.zoom_focus);
3981 reposition_and_zoom (last_visual_state.leftmost_frame, last_visual_state.frames_per_unit);
3985 Editor::set_frames_per_unit (double fpu)
3987 /* this is the core function that controls the zoom level of the canvas. it is called
3988 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
3991 if (fpu == frames_per_unit) {
4000 /* don't allow zooms that fit more than the maximum number
4001 of frames into an 800 pixel wide space.
4004 if (max_frames / fpu < 800.0) {
4008 if (fpu == frames_per_unit) {
4012 last_visual_state.frames_per_unit = frames_per_unit;
4013 last_visual_state.leftmost_frame = leftmost_frame;
4014 last_visual_state.zoom_focus = zoom_focus;
4016 frames_per_unit = fpu;
4021 Editor::post_zoom ()
4023 // convert fpu to frame count
4025 nframes_t frames = (nframes_t) floor (frames_per_unit * canvas_width);
4027 if (frames_per_unit != zoom_range_clock.current_duration()) {
4028 zoom_range_clock.set (frames);
4031 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4032 if (!selection->tracks.empty()) {
4033 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4034 (*i)->reshow_selection (selection->time);
4037 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4038 (*i)->reshow_selection (selection->time);
4043 ZoomChanged (); /* EMIT_SIGNAL */
4045 reset_hscrollbar_stepping ();
4046 reset_scrolling_region ();
4048 if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
4054 Editor::queue_visual_change (nframes_t where)
4056 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4057 pending_visual_change.time_origin = where;
4059 if (pending_visual_change.idle_handler_id < 0) {
4060 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4065 Editor::queue_visual_change (double fpu)
4067 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4068 pending_visual_change.frames_per_unit = fpu;
4070 if (pending_visual_change.idle_handler_id < 0) {
4071 pending_visual_change.idle_handler_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, _idle_visual_changer, this, 0);
4076 Editor::_idle_visual_changer (void* arg)
4078 return static_cast<Editor*>(arg)->idle_visual_changer ();
4082 Editor::idle_visual_changer ()
4084 VisualChange::Type p = pending_visual_change.pending;
4086 pending_visual_change.pending = (VisualChange::Type) 0;
4087 pending_visual_change.idle_handler_id = -1;
4089 if (p & VisualChange::ZoomLevel) {
4090 set_frames_per_unit (pending_visual_change.frames_per_unit);
4093 if (p & VisualChange::TimeOrigin) {
4094 if (pending_visual_change.time_origin != leftmost_frame) {
4095 horizontal_adjustment.set_value (pending_visual_change.time_origin/frames_per_unit);
4096 /* the signal handler will do the rest */
4098 update_fixed_rulers();
4099 redisplay_tempo (true);
4103 return 0; /* this is always a one-shot call */
4106 struct EditorOrderTimeAxisSorter {
4107 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4108 return a->order < b->order;
4113 Editor::sort_track_selection ()
4115 EditorOrderTimeAxisSorter cmp;
4116 selection->tracks.sort (cmp);
4120 Editor::get_preferred_edit_position()
4123 nframes64_t where = 0;
4125 if (entered_marker) {
4126 return entered_marker->position();
4129 switch (_edit_point) {
4130 case EditAtPlayhead:
4131 where = session->audible_frame();
4134 case EditAtSelectedMarker:
4135 if (!selection->markers.empty()) {
4137 Location* loc = find_location_from_marker (selection->markers.front(), whocares);
4139 where = loc->start();
4147 if (!mouse_frame (where, ignored)) {
4148 /* XXX not right but what can we do ? */
4159 Editor::set_loop_range (nframes_t start, nframes_t end, string cmd)
4161 if (!session) return;
4163 begin_reversible_command (cmd);
4167 if ((tll = transport_loop_location()) == 0) {
4168 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4169 XMLNode &before = session->locations()->get_state();
4170 session->locations()->add (loc, true);
4171 session->set_auto_loop_location (loc);
4172 XMLNode &after = session->locations()->get_state();
4173 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4176 XMLNode &before = tll->get_state();
4177 tll->set_hidden (false, this);
4178 tll->set (start, end);
4179 XMLNode &after = tll->get_state();
4180 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4183 commit_reversible_command ();
4187 Editor::set_punch_range (nframes_t start, nframes_t end, string cmd)
4189 if (!session) return;
4191 begin_reversible_command (cmd);
4195 if ((tpl = transport_punch_location()) == 0) {
4196 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4197 XMLNode &before = session->locations()->get_state();
4198 session->locations()->add (loc, true);
4199 session->set_auto_loop_location (loc);
4200 XMLNode &after = session->locations()->get_state();
4201 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4204 XMLNode &before = tpl->get_state();
4205 tpl->set_hidden (false, this);
4206 tpl->set (start, end);
4207 XMLNode &after = tpl->get_state();
4208 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4211 commit_reversible_command ();
4215 Editor::get_regions_at (nframes64_t where, const TrackSelection& ts) const
4218 const TrackSelection* tracks;
4221 tracks = &track_views;
4226 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4228 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4231 boost::shared_ptr<Diskstream> ds;
4232 boost::shared_ptr<Playlist> pl;
4234 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4236 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)where * ds->speed()));
4238 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4240 RegionView* rv = atv->audio_view()->find_view (*i);
4257 Editor::get_regions_after (nframes64_t where, const TrackSelection& ts) const
4260 const TrackSelection* tracks;
4263 tracks = &track_views;
4268 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4270 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4273 boost::shared_ptr<Diskstream> ds;
4274 boost::shared_ptr<Playlist> pl;
4276 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4278 Playlist::RegionList* regions = pl->regions_touched ((nframes_t) floor ( (double)where * ds->speed()), max_frames);
4280 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4282 RegionView* rv = atv->audio_view()->find_view (*i);
4298 Editor::get_regions_for_action ()
4300 if (!selection->regions.empty()) {
4301 return selection->regions;
4304 nframes64_t where = get_preferred_edit_position();
4305 tmp_regions = get_regions_at (where, selection->tracks);
4310 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4313 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4315 RouteTimeAxisView* tatv;
4317 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4319 boost::shared_ptr<Playlist> pl;
4320 vector<boost::shared_ptr<Region> > results;
4322 boost::shared_ptr<Diskstream> ds;
4324 if ((ds = tatv->get_diskstream()) == 0) {
4329 if ((pl = (ds->playlist())) != 0) {
4330 pl->get_region_list_equivalent_regions (region, results);
4333 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4334 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4335 regions.push_back (marv);