2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <boost/none.hpp>
29 #include <sigc++/bind.h>
31 #include <pbd/convert.h>
32 #include <pbd/error.h>
33 #include <pbd/enumwriter.h>
34 #include <pbd/memento_command.h>
36 #include <glibmm/miscutils.h>
37 #include <gtkmm/image.h>
38 #include <gdkmm/color.h>
39 #include <gdkmm/bitmap.h>
41 #include <gtkmm2ext/grouped_buttons.h>
42 #include <gtkmm2ext/gtk_ui.h>
43 #include <gtkmm2ext/tearoff.h>
44 #include <gtkmm2ext/utils.h>
45 #include <gtkmm2ext/window_title.h>
46 #include <gtkmm2ext/choice.h>
48 #include <ardour/audio_track.h>
49 #include <ardour/audio_diskstream.h>
50 #include <ardour/plugin_manager.h>
51 #include <ardour/location.h>
52 #include <ardour/audioplaylist.h>
53 #include <ardour/audioregion.h>
54 #include <ardour/region.h>
55 #include <ardour/session_route.h>
56 #include <ardour/tempo.h>
57 #include <ardour/utils.h>
58 #include <ardour/profile.h>
60 #include <control_protocol/control_protocol.h>
62 #include "ardour_ui.h"
66 #include "playlist_selector.h"
67 #include "audio_region_view.h"
68 #include "rgb_macros.h"
69 #include "selection.h"
70 #include "audio_streamview.h"
71 #include "time_axis_view.h"
72 #include "audio_time_axis.h"
74 #include "crossfade_view.h"
76 #include "public_editor.h"
77 #include "crossfade_edit.h"
78 #include "canvas_impl.h"
80 #include "gui_thread.h"
82 #include "rhythm_ferret.h"
86 #include "analysis_window.h"
92 #include "imageframe_socket_handler.h"
93 /* </CMT Additions> */
97 using namespace ARDOUR;
100 using namespace Glib;
101 using namespace Gtkmm2ext;
102 using namespace Editing;
106 const double Editor::timebar_height = 15.0;
108 #include "editor_xpms"
110 static const gchar *_snap_type_strings[] = {
132 static const gchar *_snap_mode_strings[] = {
139 static const gchar *_edit_point_strings[] = {
146 static const gchar *_zoom_focus_strings[] = {
156 #ifdef USE_RUBBERBAND
157 static const gchar *_rb_opt_strings[] = {
160 N_("Balanced multitimbral mixture"),
161 N_("Unpitched percussion with stable notes"),
162 N_("Crisp monophonic instrumental"),
163 N_("Unpitched solo percussion"),
168 /* Soundfile drag-n-drop */
170 Gdk::Cursor* Editor::cross_hair_cursor = 0;
171 Gdk::Cursor* Editor::selector_cursor = 0;
172 Gdk::Cursor* Editor::trimmer_cursor = 0;
173 Gdk::Cursor* Editor::grabber_cursor = 0;
174 Gdk::Cursor* Editor::grabber_edit_point_cursor = 0;
175 Gdk::Cursor* Editor::zoom_cursor = 0;
176 Gdk::Cursor* Editor::time_fx_cursor = 0;
177 Gdk::Cursor* Editor::fader_cursor = 0;
178 Gdk::Cursor* Editor::speaker_cursor = 0;
179 Gdk::Cursor* Editor::wait_cursor = 0;
180 Gdk::Cursor* Editor::timebar_cursor = 0;
181 Gdk::Cursor* Editor::transparent_cursor = 0;
184 show_me_the_size (Requisition* r, const char* what)
186 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
191 /* time display buttons */
192 minsec_label (_("Mins:Secs")),
193 bbt_label (_("Bars:Beats")),
194 smpte_label (_("Timecode")),
195 frame_label (_("Samples")),
196 tempo_label (_("Tempo")),
197 meter_label (_("Meter")),
198 mark_label (_("Location Markers")),
199 range_mark_label (_("Range Markers")),
200 transport_mark_label (_("Loop/Punch Ranges")),
201 cd_mark_label (_("CD Markers")),
203 edit_packer (3, 3, true),
205 /* the values here don't matter: layout widgets
206 reset them as needed.
209 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
210 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
212 /* tool bar related */
214 edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
215 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
217 toolbar_selection_clock_table (2,3),
219 automation_mode_button (_("mode")),
220 global_automation_button (_("automation")),
222 /* <CMT Additions> */
223 image_socket_listener(0),
224 /* </CMT Additions> */
228 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
229 meters_running(false)
234 /* we are a singleton */
236 PublicEditor::_instance = this;
241 selection = new Selection;
242 cut_buffer = new Selection;
244 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
245 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
246 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
247 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
248 selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
250 clicked_regionview = 0;
251 clicked_trackview = 0;
252 clicked_audio_trackview = 0;
253 clicked_crossfadeview = 0;
254 clicked_control_point = 0;
255 last_update_frame = 0;
257 current_mixer_strip = 0;
258 current_bbt_points = 0;
260 snap_type_strings = I18N (_snap_type_strings);
261 snap_mode_strings = I18N (_snap_mode_strings);
262 zoom_focus_strings = I18N (_zoom_focus_strings);
263 edit_point_strings = I18N (_edit_point_strings);
264 #ifdef USE_RUBBERBAND
265 rb_opt_strings = I18N (_rb_opt_strings);
268 snap_threshold = 5.0;
269 bbt_beat_subdivision = 4;
272 last_autoscroll_x = 0;
273 last_autoscroll_y = 0;
274 autoscroll_active = false;
275 autoscroll_timeout_tag = -1;
276 interthread_progress_window = 0;
283 current_interthread_info = 0;
284 _show_measures = true;
285 _show_waveforms = true;
286 _show_waveforms_recording = true;
287 first_action_message = 0;
289 export_range_markers_dialog = 0;
290 show_gain_after_trim = false;
291 ignore_route_list_reorder = false;
292 no_route_list_redisplay = false;
293 verbose_cursor_on = true;
294 route_removal = false;
295 show_automatic_regions_in_region_list = true;
296 last_item_entered = 0;
297 last_item_entered_n = 0;
299 region_list_sort_type = (Editing::RegionListSortType) 0;
300 have_pending_keyboard_selection = false;
301 _follow_playhead = true;
302 _xfade_visibility = true;
303 editor_ruler_menu = 0;
304 no_ruler_shown_update = false;
305 edit_group_list_menu = 0;
307 region_list_menu = 0;
309 start_end_marker_menu = 0;
310 range_marker_menu = 0;
311 marker_menu_item = 0;
313 transport_marker_menu = 0;
314 new_transport_marker_menu = 0;
315 editor_mixer_strip_width = Wide;
316 show_editor_mixer_when_tracks_arrive = false;
317 region_edit_menu_split_item = 0;
319 region_edit_menu_split_multichannel_item = 0;
321 ignore_mouse_mode_toggle = false;
322 current_stepping_trackview = 0;
324 entered_regionview = 0;
326 clear_entered_track = false;
327 _new_regionviews_show_envelope = false;
329 in_edit_group_row_change = false;
330 last_canvas_frame = 0;
332 button_release_can_deselect = true;
333 canvas_idle_queued = false;
334 _dragging_playhead = false;
335 _dragging_edit_point = false;
336 _dragging_hscrollbar = false;
337 select_new_marker = false;
338 zoomed_to_region = false;
340 allow_vertical_scroll = false;
341 no_save_visual = false;
344 scrubbing_direction = 0;
347 ignore_route_order_sync = false;
349 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
350 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
351 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
352 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
353 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
355 range_marker_drag_rect = 0;
356 marker_drag_line = 0;
358 set_mouse_mode (MouseObject, true);
360 frames_per_unit = 2048; /* too early to use reset_zoom () */
361 reset_hscrollbar_stepping ();
363 zoom_focus = ZoomFocusLeft;
364 set_zoom_focus (ZoomFocusLeft);
365 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
367 initialize_rulers ();
368 initialize_canvas ();
370 edit_controls_vbox.set_spacing (0);
371 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::canvas_horizontally_scrolled), false);
372 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
374 track_canvas->set_hadjustment (horizontal_adjustment);
375 track_canvas->set_vadjustment (vertical_adjustment);
376 time_canvas->set_hadjustment (horizontal_adjustment);
378 track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
379 time_canvas->signal_map_event().connect (mem_fun (*this, &Editor::time_canvas_map_handler));
381 controls_layout.add (edit_controls_vbox);
382 controls_layout.set_name ("EditControlsBase");
383 controls_layout.add_events (Gdk::SCROLL_MASK);
384 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
386 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
387 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
388 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
390 edit_vscrollbar.set_adjustment (vertical_adjustment);
391 edit_hscrollbar.set_adjustment (horizontal_adjustment);
393 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
394 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
395 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
397 edit_hscrollbar.set_name ("EditorHScrollbar");
402 edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
404 time_canvas_vbox.pack_start (*_ruler_separator, false, false);
405 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
406 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
407 time_canvas_vbox.pack_start (*frames_ruler, false, false);
408 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
409 time_canvas_vbox.pack_start (*time_canvas, true, true);
410 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
412 bbt_label.set_name ("EditorTimeButton");
413 bbt_label.set_size_request (-1, (int)timebar_height);
414 bbt_label.set_alignment (1.0, 0.5);
415 bbt_label.set_padding (5,0);
416 minsec_label.set_name ("EditorTimeButton");
417 minsec_label.set_size_request (-1, (int)timebar_height);
418 minsec_label.set_alignment (1.0, 0.5);
419 minsec_label.set_padding (5,0);
420 smpte_label.set_name ("EditorTimeButton");
421 smpte_label.set_size_request (-1, (int)timebar_height);
422 smpte_label.set_alignment (1.0, 0.5);
423 smpte_label.set_padding (5,0);
424 frame_label.set_name ("EditorTimeButton");
425 frame_label.set_size_request (-1, (int)timebar_height);
426 frame_label.set_alignment (1.0, 0.5);
427 frame_label.set_padding (5,0);
428 tempo_label.set_name ("EditorTimeButton");
429 tempo_label.set_size_request (-1, (int)timebar_height);
430 tempo_label.set_alignment (1.0, 0.5);
431 tempo_label.set_padding (5,0);
432 meter_label.set_name ("EditorTimeButton");
433 meter_label.set_size_request (-1, (int)timebar_height);
434 meter_label.set_alignment (1.0, 0.5);
435 meter_label.set_padding (5,0);
436 mark_label.set_name ("EditorTimeButton");
437 mark_label.set_size_request (-1, (int)timebar_height);
438 mark_label.set_alignment (1.0, 0.5);
439 mark_label.set_padding (5,0);
440 cd_mark_label.set_name ("EditorTimeButton");
441 cd_mark_label.set_size_request (-1, (int)timebar_height);
442 cd_mark_label.set_alignment (1.0, 0.5);
443 cd_mark_label.set_padding (5,0);
444 range_mark_label.set_name ("EditorTimeButton");
445 range_mark_label.set_size_request (-1, (int)timebar_height);
446 range_mark_label.set_alignment (1.0, 0.5);
447 range_mark_label.set_padding (5,0);
448 transport_mark_label.set_name ("EditorTimeButton");
449 transport_mark_label.set_size_request (-1, (int)timebar_height);
450 transport_mark_label.set_alignment (1.0, 0.5);
451 transport_mark_label.set_padding (5,0);
453 time_button_vbox.pack_start (minsec_label, false, false);
454 time_button_vbox.pack_start (smpte_label, false, false);
455 time_button_vbox.pack_start (frame_label, false, false);
456 time_button_vbox.pack_start (bbt_label, false, false);
457 time_button_vbox.pack_start (meter_label, false, false);
458 time_button_vbox.pack_start (tempo_label, false, false);
459 time_button_vbox.pack_start (mark_label, false, false);
461 time_button_event_box.add (time_button_vbox);
463 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
464 time_button_event_box.set_name ("TimebarLabelBase");
465 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
467 time_button_frame.add(time_button_event_box);
468 time_button_frame.property_shadow_type() = Gtk::SHADOW_OUT;
470 /* these enable us to have a dedicated window (for cursor setting, etc.)
471 for the canvas areas.
474 track_canvas_event_box.add (*track_canvas);
476 time_canvas_event_box.add (time_canvas_vbox);
477 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
479 edit_packer.set_col_spacings (0);
480 edit_packer.set_row_spacings (0);
481 edit_packer.set_homogeneous (false);
482 edit_packer.set_border_width (0);
483 edit_packer.set_name ("EditorWindow");
485 edit_packer.attach (edit_vscrollbar, 0, 1, 1, 3, FILL, FILL|EXPAND, 0, 0);
487 edit_packer.attach (time_button_frame, 0, 2, 0, 1, FILL, FILL, 0, 0);
488 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
490 edit_packer.attach (controls_layout, 1, 2, 1, 2, FILL, FILL|EXPAND, 0, 0);
491 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 2, FILL|EXPAND, FILL|EXPAND, 0, 0);
493 edit_packer.attach (zoom_box, 1, 2, 2, 3, FILL, FILL, 0, 0);
494 edit_packer.attach (edit_hscrollbar, 2, 3, 2, 3, FILL|EXPAND, FILL, 0, 0);
496 bottom_hbox.set_border_width (2);
497 bottom_hbox.set_spacing (3);
499 route_display_model = ListStore::create(route_display_columns);
500 route_list_display.set_model (route_display_model);
501 route_list_display.append_column (_("Show"), route_display_columns.visible);
502 route_list_display.append_column (_("Name"), route_display_columns.text);
503 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
504 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
505 route_list_display.set_headers_visible (true);
506 route_list_display.set_name ("TrackListDisplay");
507 route_list_display.get_selection()->set_mode (SELECTION_NONE);
508 route_list_display.set_reorderable (true);
509 route_list_display.set_size_request (100,-1);
511 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
512 route_list_visible_cell->property_activatable() = true;
513 route_list_visible_cell->property_radio() = false;
515 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
516 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
517 route_display_model->signal_rows_reordered().connect (mem_fun (*this, &Editor::track_list_reorder));
519 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
521 route_list_scroller.add (route_list_display);
522 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
524 group_model = ListStore::create(group_columns);
525 edit_group_display.set_model (group_model);
526 edit_group_display.append_column (_("Name"), group_columns.text);
527 edit_group_display.append_column (_("Active"), group_columns.is_active);
528 edit_group_display.append_column (_("Show"), group_columns.is_visible);
529 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
530 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
531 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
532 edit_group_display.get_column (0)->set_expand (true);
533 edit_group_display.get_column (1)->set_expand (false);
534 edit_group_display.get_column (2)->set_expand (false);
535 edit_group_display.set_headers_visible (true);
537 /* name is directly editable */
539 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
540 name_cell->property_editable() = true;
541 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
543 /* use checkbox for the active + visible columns */
545 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
546 active_cell->property_activatable() = true;
547 active_cell->property_radio() = false;
549 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
550 active_cell->property_activatable() = true;
551 active_cell->property_radio() = false;
553 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
555 edit_group_display.set_name ("EditGroupList");
556 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
557 edit_group_display.set_headers_visible (true);
558 edit_group_display.set_reorderable (false);
559 edit_group_display.set_rules_hint (true);
560 edit_group_display.set_size_request (75, -1);
562 edit_group_display_scroller.add (edit_group_display);
563 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
565 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
567 VBox* edit_group_display_packer = manage (new VBox());
568 HBox* edit_group_display_button_box = manage (new HBox());
569 edit_group_display_button_box->set_homogeneous (true);
571 Button* edit_group_add_button = manage (new Button ());
572 Button* edit_group_remove_button = manage (new Button ());
576 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
578 edit_group_add_button->add (*w);
580 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
582 edit_group_remove_button->add (*w);
584 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
585 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
587 edit_group_display_button_box->pack_start (*edit_group_add_button);
588 edit_group_display_button_box->pack_start (*edit_group_remove_button);
590 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
591 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
593 region_list_display.set_size_request (100, -1);
594 region_list_display.set_name ("RegionListDisplay");
595 /* Try to prevent single mouse presses from initiating edits.
596 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
598 region_list_display.set_data ("mouse-edits-require-mod1", (gpointer) 0x1);
600 region_list_model = TreeStore::create (region_list_columns);
601 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
602 region_list_model->set_sort_column (0, SORT_ASCENDING);
604 region_list_display.set_model (region_list_model);
605 region_list_display.append_column (_("Regions"), region_list_columns.name);
606 region_list_display.set_headers_visible (false);
608 CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
609 region_name_cell->property_editable() = true;
610 region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
612 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
614 TreeViewColumn* tv_col = region_list_display.get_column(0);
615 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
616 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
617 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
619 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
620 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
622 /* setup DnD handling */
624 list<TargetEntry> region_list_target_table;
626 region_list_target_table.push_back (TargetEntry ("text/plain"));
627 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
628 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
630 region_list_display.add_drop_targets (region_list_target_table);
631 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
633 region_list_scroller.add (region_list_display);
634 region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
636 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
637 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
638 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
639 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
640 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
641 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
643 named_selection_scroller.add (named_selection_display);
644 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
646 named_selection_model = TreeStore::create (named_selection_columns);
647 named_selection_display.set_model (named_selection_model);
648 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
649 named_selection_display.set_headers_visible (false);
650 named_selection_display.set_size_request (100, -1);
651 named_selection_display.set_name ("NamedSelectionDisplay");
653 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
654 named_selection_display.set_size_request (100, -1);
655 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
656 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
657 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
661 snapshot_display_model = ListStore::create (snapshot_display_columns);
662 snapshot_display.set_model (snapshot_display_model);
663 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
664 snapshot_display.set_name ("SnapshotDisplay");
665 snapshot_display.set_size_request (75, -1);
666 snapshot_display.set_headers_visible (false);
667 snapshot_display.set_reorderable (false);
668 snapshot_display_scroller.add (snapshot_display);
669 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
671 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
672 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
676 nlabel = manage (new Label (_("Regions")));
677 nlabel->set_angle (-90);
678 the_notebook.append_page (region_list_scroller, *nlabel);
679 nlabel = manage (new Label (_("Tracks/Busses")));
680 nlabel->set_angle (-90);
681 the_notebook.append_page (route_list_scroller, *nlabel);
682 nlabel = manage (new Label (_("Snapshots")));
683 nlabel->set_angle (-90);
684 the_notebook.append_page (snapshot_display_scroller, *nlabel);
685 nlabel = manage (new Label (_("Edit Groups")));
686 nlabel->set_angle (-90);
687 the_notebook.append_page (*edit_group_display_packer, *nlabel);
689 if (!Profile->get_sae()) {
690 nlabel = manage (new Label (_("Chunks")));
691 nlabel->set_angle (-90);
692 the_notebook.append_page (named_selection_scroller, *nlabel);
695 the_notebook.set_show_tabs (true);
696 the_notebook.set_scrollable (true);
697 the_notebook.popup_enable ();
698 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
700 post_maximal_editor_width = 0;
701 post_maximal_pane_position = 0;
702 edit_pane.pack1 (edit_packer, true, true);
703 edit_pane.pack2 (the_notebook, false, true);
705 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
707 top_hbox.pack_start (toolbar_frame, true, true);
709 HBox *hbox = manage (new HBox);
710 hbox->pack_start (edit_pane, true, true);
712 global_vpacker.pack_start (top_hbox, false, false);
713 global_vpacker.pack_start (*hbox, true, true);
715 global_hpacker.pack_start (global_vpacker, true, true);
717 set_name ("EditorWindow");
718 add_accel_group (ActionManager::ui_manager->get_accel_group());
720 status_bar_hpacker.show ();
722 vpacker.pack_end (status_bar_hpacker, false, false);
723 vpacker.pack_end (global_hpacker, true, true);
725 /* register actions now so that set_state() can find them and set toggles/checks etc */
729 snap_type = SnapToBeat;
730 set_snap_to (snap_type);
732 set_snap_mode (snap_mode);
733 set_edit_point_preference (EditAtMouse, true);
735 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
738 _playlist_selector = new PlaylistSelector();
739 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
741 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
745 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
746 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
748 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
749 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
751 nudge_forward_button.set_name ("TransportButton");
752 nudge_backward_button.set_name ("TransportButton");
754 fade_context_menu.set_name ("ArdourContextMenu");
756 /* icons, titles, WM stuff */
758 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
759 Glib::RefPtr<Gdk::Pixbuf> icon;
761 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
762 window_icons.push_back (icon);
764 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
765 window_icons.push_back (icon);
767 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
768 window_icons.push_back (icon);
770 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
771 window_icons.push_back (icon);
773 if (!window_icons.empty()) {
774 set_icon_list (window_icons);
775 set_default_icon_list (window_icons);
778 WindowTitle title(Glib::get_application_name());
779 title += _("Editor");
780 set_title (title.get_string());
781 set_wmclass (X_("ardour_editor"), "Ardour");
784 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
786 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
787 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
789 /* allow external control surfaces/protocols to do various things */
791 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
792 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
793 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
794 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
795 BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
797 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
798 Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
806 /* <CMT Additions> */
807 if(image_socket_listener)
809 if(image_socket_listener->is_connected())
811 image_socket_listener->close_connection() ;
814 delete image_socket_listener ;
815 image_socket_listener = 0 ;
817 /* </CMT Additions> */
831 Editor::add_toplevel_controls (Container& cont)
833 vpacker.pack_start (cont, false, false);
838 Editor::catch_vanishing_regionview (RegionView *rv)
840 /* note: the selection will take care of the vanishing
841 audioregionview by itself.
844 if (clicked_regionview == rv) {
845 clicked_regionview = 0;
848 if (entered_regionview == rv) {
849 set_entered_regionview (0);
854 Editor::set_entered_regionview (RegionView* rv)
856 if (rv == entered_regionview) {
860 if (entered_regionview) {
861 entered_regionview->exited ();
864 if ((entered_regionview = rv) != 0) {
865 entered_regionview->entered ();
870 Editor::set_entered_track (TimeAxisView* tav)
873 entered_track->exited ();
876 if ((entered_track = tav) != 0) {
877 entered_track->entered ();
882 Editor::show_window ()
887 /* now reset all audio_time_axis heights, because widgets might need
893 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
894 tv = (static_cast<TimeAxisView*>(*i));
900 Editor::instant_save ()
902 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
907 session->add_instant_xml(get_state(), session->path());
909 Config->add_instant_xml(get_state(), get_user_ardour_path());
914 Editor::edit_point_clock_changed()
916 if (_dragging_edit_point) {
920 if (selection->markers.empty()) {
925 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
931 loc->move_to (edit_point_clock.current_time());
935 Editor::zoom_adjustment_changed ()
941 double fpu = zoom_range_clock.current_duration() / canvas_width;
945 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
946 } else if (fpu > session->current_end_frame() / canvas_width) {
947 fpu = session->current_end_frame() / canvas_width;
948 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
955 Editor::control_scroll (float fraction)
957 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
963 double step = fraction * current_page_frames();
966 _control_scroll_target is an optional<T>
968 it acts like a pointer to an nframes_t, with
969 a operator conversion to boolean to check
970 that it has a value could possibly use
971 playhead_cursor->current_frame to store the
972 value and a boolean in the class to know
973 when it's out of date
976 if (!_control_scroll_target) {
977 _control_scroll_target = session->transport_frame();
978 _dragging_playhead = true;
981 if ((fraction < 0.0f) && (*_control_scroll_target < (nframes_t) fabs(step))) {
982 *_control_scroll_target = 0;
983 } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
984 *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
986 *_control_scroll_target += (nframes_t) floor (step);
989 /* move visuals, we'll catch up with it later */
991 playhead_cursor->set_position (*_control_scroll_target);
992 UpdateAllTransportClocks (*_control_scroll_target);
994 if (*_control_scroll_target > (current_page_frames() / 2)) {
995 /* try to center PH in window */
996 reset_x_origin (*_control_scroll_target - (current_page_frames()/2));
1002 Now we do a timeout to actually bring the session to the right place
1003 according to the playhead. This is to avoid reading disk buffers on every
1004 call to control_scroll, which is driven by ScrollTimeline and therefore
1005 probably by a control surface wheel which can generate lots of events.
1007 /* cancel the existing timeout */
1009 control_scroll_connection.disconnect ();
1011 /* add the next timeout */
1013 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), *_control_scroll_target), 250);
1017 Editor::deferred_control_scroll (nframes_t target)
1019 session->request_locate (*_control_scroll_target, session->transport_rolling());
1020 // reset for next stream
1021 _control_scroll_target = boost::none;
1022 _dragging_playhead = false;
1027 Editor::access_action (std::string action_group, std::string action_item)
1033 cout<< "OSC: Recieved: "<< action_item << endl;
1036 act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
1044 Editor::on_realize ()
1046 Window::on_realize ();
1051 Editor::start_scrolling ()
1053 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
1054 (mem_fun(*this, &Editor::update_current_screen));
1058 Editor::stop_scrolling ()
1060 scroll_connection.disconnect ();
1064 Editor::map_position_change (nframes_t frame)
1066 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
1068 if (session == 0 || !_follow_playhead) {
1072 center_screen (frame);
1073 playhead_cursor->set_position (frame);
1077 Editor::center_screen (nframes_t frame)
1079 double page = canvas_width * frames_per_unit;
1081 /* if we're off the page, then scroll.
1084 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
1085 center_screen_internal (frame, page);
1090 Editor::center_screen_internal (nframes_t frame, float page)
1095 frame -= (nframes_t) page;
1100 reset_x_origin (frame);
1104 Editor::handle_new_duration ()
1106 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
1108 nframes_t new_end = session->get_maximum_extent() + (nframes_t) floorf (current_page_frames() * 0.10f);
1110 if (new_end > last_canvas_frame) {
1111 last_canvas_frame = new_end;
1112 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
1113 reset_scrolling_region ();
1116 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
1120 Editor::update_title_s (const string & snap_name)
1122 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1128 Editor::update_title ()
1130 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1133 bool dirty = session->dirty();
1135 string session_name;
1137 if (session->snap_name() != session->name()) {
1138 session_name = session->snap_name();
1140 session_name = session->name();
1144 session_name = "*" + session_name;
1147 WindowTitle title(session_name);
1148 title += Glib::get_application_name();
1149 set_title (title.get_string());
1154 Editor::connect_to_session (Session *t)
1158 /* there are never any selected regions at startup */
1160 sensitize_the_right_region_actions (false);
1162 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1165 /* catch up with the playhead */
1167 session->request_locate (playhead_cursor->current_frame);
1169 if (first_action_message) {
1170 first_action_message->hide();
1175 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1176 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1178 /* These signals can all be emitted by a non-GUI thread. Therefore the
1179 handlers for them must not attempt to directly interact with the GUI,
1180 but use Gtkmm2ext::UI::instance()->call_slot();
1183 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1184 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1185 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1186 session_connections.push_back (session->AudioRegionsAdded.connect (mem_fun(*this, &Editor::handle_new_audio_regions)));
1187 session_connections.push_back (session->AudioRegionRemoved.connect (mem_fun(*this, &Editor::handle_audio_region_removed)));
1188 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1189 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1190 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1191 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1192 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1193 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1194 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1195 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1196 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1198 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1200 session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
1202 edit_groups_changed ();
1204 edit_point_clock.set_session (session);
1205 zoom_range_clock.set_session (session);
1206 _playlist_selector->set_session (session);
1207 nudge_clock.set_session (session);
1209 if (rhythm_ferret) {
1210 rhythm_ferret->set_session (session);
1214 if (analysis_window != 0)
1215 analysis_window->set_session (session);
1218 Location* loc = session->locations()->auto_loop_location();
1220 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1221 if (loc->start() == loc->end()) {
1222 loc->set_end (loc->start() + 1);
1224 session->locations()->add (loc, false);
1225 session->set_auto_loop_location (loc);
1228 loc->set_name (_("Loop"));
1231 loc = session->locations()->auto_punch_location();
1233 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1234 if (loc->start() == loc->end()) {
1235 loc->set_end (loc->start() + 1);
1237 session->locations()->add (loc, false);
1238 session->set_auto_punch_location (loc);
1241 loc->set_name (_("Punch"));
1244 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1246 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1248 refresh_location_display ();
1249 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1250 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1251 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1252 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1253 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1256 sfbrowser->set_session (session);
1259 handle_new_duration ();
1261 redisplay_regions ();
1262 redisplay_named_selections ();
1263 redisplay_snapshots ();
1265 initial_route_list_display ();
1267 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1268 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1271 restore_ruler_visibility ();
1272 //tempo_map_changed (Change (0));
1273 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1277 /* don't show master bus in a new session */
1279 if (ARDOUR_UI::instance()->session_is_new ()) {
1281 TreeModel::Children rows = route_display_model->children();
1282 TreeModel::Children::iterator i;
1284 no_route_list_redisplay = true;
1286 for (i = rows.begin(); i != rows.end(); ++i) {
1287 TimeAxisView *tv = (*i)[route_display_columns.tv];
1288 AudioTimeAxisView *atv;
1290 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1291 if (atv->route()->master()) {
1292 route_list_display.get_selection()->unselect (i);
1297 no_route_list_redisplay = false;
1298 redisplay_route_list ();
1301 switch (snap_type) {
1302 case SnapToRegionStart:
1303 case SnapToRegionEnd:
1304 case SnapToRegionSync:
1305 case SnapToRegionBoundary:
1306 build_region_boundary_cache ();
1313 /* register for undo history */
1315 session->register_with_memento_command_factory(_id, this);
1321 Editor::build_cursors ()
1323 using namespace Gdk;
1325 Gdk::Color mbg ("#000000" ); /* Black */
1326 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1329 RefPtr<Bitmap> source, mask;
1330 source = Bitmap::create (mag_bits, mag_width, mag_height);
1331 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1332 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1335 Gdk::Color fbg ("#ffffff" );
1336 Gdk::Color ffg ("#000000" );
1339 RefPtr<Bitmap> source, mask;
1341 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1342 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1343 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1347 RefPtr<Bitmap> source, mask;
1348 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1349 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1350 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1354 RefPtr<Bitmap> bits;
1355 char pix[4] = { 0, 0, 0, 0 };
1356 bits = Bitmap::create (pix, 2, 2);
1358 transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
1362 grabber_cursor = new Gdk::Cursor (HAND2);
1365 Glib::RefPtr<Gdk::Pixbuf> grabber_edit_point_pixbuf (::get_icon ("grabber_edit_point"));
1366 grabber_edit_point_cursor = new Gdk::Cursor (Gdk::Display::get_default(), grabber_edit_point_pixbuf, 5, 17);
1369 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1370 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1371 selector_cursor = new Gdk::Cursor (XTERM);
1372 time_fx_cursor = new Gdk::Cursor (SIZING);
1373 wait_cursor = new Gdk::Cursor (WATCH);
1374 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1378 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1380 using namespace Menu_Helpers;
1381 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1384 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1388 MenuList& items (fade_context_menu.items());
1392 switch (item_type) {
1394 case FadeInHandleItem:
1395 if (arv->audio_region()->fade_in_active()) {
1396 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1398 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1401 items.push_back (SeparatorElem());
1403 if (Profile->get_sae()) {
1404 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1405 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1407 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1408 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1409 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1410 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1411 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1416 case FadeOutHandleItem:
1417 if (arv->audio_region()->fade_out_active()) {
1418 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1420 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1423 items.push_back (SeparatorElem());
1425 if (Profile->get_sae()) {
1426 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1427 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1429 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1430 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1431 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1432 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1433 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1438 fatal << _("programming error: ")
1439 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1444 fade_context_menu.popup (button, time);
1448 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes_t frame)
1450 using namespace Menu_Helpers;
1451 Menu* (Editor::*build_menu_function)(nframes_t);
1454 switch (item_type) {
1456 case RegionViewName:
1457 case RegionViewNameHighlight:
1458 if (with_selection) {
1459 build_menu_function = &Editor::build_track_selection_context_menu;
1461 build_menu_function = &Editor::build_track_region_context_menu;
1466 if (with_selection) {
1467 build_menu_function = &Editor::build_track_selection_context_menu;
1469 build_menu_function = &Editor::build_track_context_menu;
1473 case CrossfadeViewItem:
1474 build_menu_function = &Editor::build_track_crossfade_context_menu;
1478 if (clicked_audio_trackview->get_diskstream()) {
1479 build_menu_function = &Editor::build_track_context_menu;
1481 build_menu_function = &Editor::build_track_bus_context_menu;
1486 /* probably shouldn't happen but if it does, we don't care */
1490 menu = (this->*build_menu_function)(frame);
1491 menu->set_name ("ArdourContextMenu");
1493 /* now handle specific situations */
1495 switch (item_type) {
1497 case RegionViewName:
1498 case RegionViewNameHighlight:
1499 if (!with_selection) {
1500 if (region_edit_menu_split_item) {
1501 if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
1502 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
1504 ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
1508 if (region_edit_menu_split_multichannel_item) {
1509 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1510 // GTK2FIX find the action, change its sensitivity
1511 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1513 // GTK2FIX see above
1514 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1523 case CrossfadeViewItem:
1530 /* probably shouldn't happen but if it does, we don't care */
1534 if (item_type != SelectionItem && clicked_audio_trackview && clicked_audio_trackview->audio_track()) {
1536 /* Bounce to disk */
1538 using namespace Menu_Helpers;
1539 MenuList& edit_items = menu->items();
1541 edit_items.push_back (SeparatorElem());
1543 switch (clicked_audio_trackview->audio_track()->freeze_state()) {
1544 case AudioTrack::NoFreeze:
1545 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1548 case AudioTrack::Frozen:
1549 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1552 case AudioTrack::UnFrozen:
1553 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1559 menu->popup (button, time);
1563 Editor::build_track_context_menu (nframes_t ignored)
1565 using namespace Menu_Helpers;
1567 MenuList& edit_items = track_context_menu.items();
1570 add_dstream_context_items (edit_items);
1571 return &track_context_menu;
1575 Editor::build_track_bus_context_menu (nframes_t ignored)
1577 using namespace Menu_Helpers;
1579 MenuList& edit_items = track_context_menu.items();
1582 add_bus_context_items (edit_items);
1583 return &track_context_menu;
1587 Editor::build_track_region_context_menu (nframes_t frame)
1589 using namespace Menu_Helpers;
1590 MenuList& edit_items = track_region_context_menu.items();
1593 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1596 boost::shared_ptr<Diskstream> ds;
1597 boost::shared_ptr<Playlist> pl;
1599 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
1600 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)frame * ds->speed()));
1601 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1602 add_region_context_items (atv->audio_view(), (*i), edit_items);
1608 add_dstream_context_items (edit_items);
1610 return &track_region_context_menu;
1614 Editor::build_track_crossfade_context_menu (nframes_t frame)
1616 using namespace Menu_Helpers;
1617 MenuList& edit_items = track_crossfade_context_menu.items();
1618 edit_items.clear ();
1620 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1623 boost::shared_ptr<Diskstream> ds;
1624 boost::shared_ptr<Playlist> pl;
1625 boost::shared_ptr<AudioPlaylist> apl;
1627 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1629 Playlist::RegionList* regions = pl->regions_at (frame);
1630 AudioPlaylist::Crossfades xfades;
1632 apl->crossfades_at (frame, xfades);
1634 bool many = xfades.size() > 1;
1636 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1637 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1640 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1641 add_region_context_items (atv->audio_view(), (*i), edit_items);
1648 add_dstream_context_items (edit_items);
1650 return &track_crossfade_context_menu;
1655 Editor::analyze_region_selection()
1657 if (analysis_window == 0) {
1658 analysis_window = new AnalysisWindow();
1661 analysis_window->set_session(session);
1663 analysis_window->show_all();
1666 analysis_window->set_regionmode();
1667 analysis_window->analyze();
1669 analysis_window->present();
1673 Editor::analyze_range_selection()
1675 if (analysis_window == 0) {
1676 analysis_window = new AnalysisWindow();
1679 analysis_window->set_session(session);
1681 analysis_window->show_all();
1684 analysis_window->set_rangemode();
1685 analysis_window->analyze();
1687 analysis_window->present();
1689 #endif /* FFT_ANALYSIS */
1694 Editor::build_track_selection_context_menu (nframes_t ignored)
1696 using namespace Menu_Helpers;
1697 MenuList& edit_items = track_selection_context_menu.items();
1698 edit_items.clear ();
1700 add_selection_context_items (edit_items);
1701 // edit_items.push_back (SeparatorElem());
1702 // add_dstream_context_items (edit_items);
1704 return &track_selection_context_menu;
1708 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1710 using namespace Menu_Helpers;
1711 Menu *xfade_menu = manage (new Menu);
1712 MenuList& items = xfade_menu->items();
1713 xfade_menu->set_name ("ArdourContextMenu");
1716 if (xfade->active()) {
1722 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1723 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1725 if (xfade->can_follow_overlap()) {
1727 if (xfade->following_overlap()) {
1728 str = _("Convert to short");
1730 str = _("Convert to full");
1733 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1737 str = xfade->out()->name();
1739 str += xfade->in()->name();
1741 str = _("Crossfade");
1744 edit_items.push_back (MenuElem (str, *xfade_menu));
1745 edit_items.push_back (SeparatorElem());
1749 Editor::xfade_edit_left_region ()
1751 if (clicked_crossfadeview) {
1752 clicked_crossfadeview->left_view.show_region_editor ();
1757 Editor::xfade_edit_right_region ()
1759 if (clicked_crossfadeview) {
1760 clicked_crossfadeview->right_view.show_region_editor ();
1765 Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1767 using namespace Menu_Helpers;
1768 Menu *region_menu = manage (new Menu);
1769 MenuList& items = region_menu->items();
1770 region_menu->set_name ("ArdourContextMenu");
1772 boost::shared_ptr<AudioRegion> ar;
1775 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1778 /* when this particular menu pops up, make the relevant region
1782 region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1784 items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
1785 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1786 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1787 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1788 items.push_back (SeparatorElem());
1789 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
1790 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1791 items.push_back (SeparatorElem());
1793 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::play_selected_region)));
1794 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1795 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1798 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
1801 items.push_back (SeparatorElem());
1803 sigc::connection fooc;
1805 items.push_back (CheckMenuElem (_("Lock")));
1806 CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1807 if (region->locked()) {
1808 region_lock_item->set_active();
1810 region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
1812 items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
1813 CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
1815 switch (region->positional_lock_style()) {
1816 case Region::MusicTime:
1817 bbt_glue_item->set_active (true);
1820 bbt_glue_item->set_active (false);
1824 bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
1826 items.push_back (CheckMenuElem (_("Mute")));
1827 CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1828 fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
1829 if (region->muted()) {
1831 region_mute_item->set_active();
1835 if (!Profile->get_sae()) {
1836 items.push_back (CheckMenuElem (_("Opaque")));
1837 CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1838 fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
1839 if (region->opaque()) {
1841 region_opaque_item->set_active();
1846 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1847 if (region->at_natural_position()) {
1848 items.back().set_sensitive (false);
1851 items.push_back (SeparatorElem());
1855 RegionView* rv = sv->find_view (ar);
1856 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1858 if (!Profile->get_sae()) {
1859 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1861 items.push_back (CheckMenuElem (_("Envelope Visible")));
1862 CheckMenuItem* region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1863 fooc = region_envelope_visible_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_visibility));
1864 if (arv->envelope_visible()) {
1866 region_envelope_visible_item->set_active (true);
1870 items.push_back (CheckMenuElem (_("Envelope Active")));
1871 CheckMenuItem* region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1872 fooc = region_envelope_active_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_gain_envelope_active));
1874 if (ar->envelope_active()) {
1876 region_envelope_active_item->set_active (true);
1880 items.push_back (SeparatorElem());
1883 if (ar->scale_amplitude() != 1.0f) {
1884 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1886 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1890 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1891 items.push_back (SeparatorElem());
1893 /* range related stuff */
1895 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1896 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_audio_region)));
1897 items.push_back (SeparatorElem());
1901 Menu *nudge_menu = manage (new Menu());
1902 MenuList& nudge_items = nudge_menu->items();
1903 nudge_menu->set_name ("ArdourContextMenu");
1905 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false, false))));
1906 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false, false))));
1907 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1908 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1910 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1911 items.push_back (SeparatorElem());
1913 Menu *trim_menu = manage (new Menu);
1914 MenuList& trim_items = trim_menu->items();
1915 trim_menu->set_name ("ArdourContextMenu");
1917 trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
1918 trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
1919 trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
1920 trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
1922 items.push_back (MenuElem (_("Trim"), *trim_menu));
1923 items.push_back (SeparatorElem());
1925 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1926 region_edit_menu_split_item = &items.back();
1928 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1929 region_edit_menu_split_multichannel_item = &items.back();
1931 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), false))));
1932 items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1933 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1934 items.push_back (SeparatorElem());
1935 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_clicked_region)));
1937 /* OK, stick the region submenu at the top of the list, and then add
1941 /* we have to hack up the region name because "_" has a special
1942 meaning for menu titles.
1945 string::size_type pos = 0;
1946 string menu_item_name = region->name();
1948 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1949 menu_item_name.replace (pos, 1, "__");
1953 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1954 edit_items.push_back (SeparatorElem());
1958 Editor::add_selection_context_items (Menu_Helpers::MenuList& items)
1960 using namespace Menu_Helpers;
1962 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
1963 items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
1966 items.push_back (SeparatorElem());
1967 items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
1970 items.push_back (SeparatorElem());
1971 items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
1972 items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
1974 items.push_back (SeparatorElem());
1975 items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
1976 items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
1978 items.push_back (SeparatorElem());
1979 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1981 items.push_back (SeparatorElem());
1982 items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
1983 items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
1985 items.push_back (SeparatorElem());
1986 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
1987 items.push_back (SeparatorElem());
1988 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
1989 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
1990 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
1991 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
1992 items.push_back (SeparatorElem());
1993 items.push_back (MenuElem (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection)));
1994 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
1998 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
2000 using namespace Menu_Helpers;
2004 Menu *play_menu = manage (new Menu);
2005 MenuList& play_items = play_menu->items();
2006 play_menu->set_name ("ArdourContextMenu");
2008 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2009 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2010 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
2011 play_items.push_back (SeparatorElem());
2012 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
2014 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2018 Menu *select_menu = manage (new Menu);
2019 MenuList& select_items = select_menu->items();
2020 select_menu->set_name ("ArdourContextMenu");
2022 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2023 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2024 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2025 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2026 select_items.push_back (SeparatorElem());
2027 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
2028 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
2029 select_items.push_back (SeparatorElem());
2030 select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2031 select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2032 select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2033 select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2034 select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
2035 select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
2036 select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
2038 select_items.push_back (SeparatorElem());
2040 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2044 Menu *cutnpaste_menu = manage (new Menu);
2045 MenuList& cutnpaste_items = cutnpaste_menu->items();
2046 cutnpaste_menu->set_name ("ArdourContextMenu");
2048 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2049 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2050 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2052 cutnpaste_items.push_back (SeparatorElem());
2054 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
2055 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
2057 cutnpaste_items.push_back (SeparatorElem());
2059 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
2061 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
2063 /* Adding new material */
2065 edit_items.push_back (SeparatorElem());
2066 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
2067 edit_items.push_back (MenuElem (_("Insert Existing Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
2071 Menu *nudge_menu = manage (new Menu());
2072 MenuList& nudge_items = nudge_menu->items();
2073 nudge_menu->set_name ("ArdourContextMenu");
2075 edit_items.push_back (SeparatorElem());
2076 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2077 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2078 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2079 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2081 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2085 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
2087 using namespace Menu_Helpers;
2091 Menu *play_menu = manage (new Menu);
2092 MenuList& play_items = play_menu->items();
2093 play_menu->set_name ("ArdourContextMenu");
2095 play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
2096 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
2097 edit_items.push_back (MenuElem (_("Play"), *play_menu));
2101 Menu *select_menu = manage (new Menu);
2102 MenuList& select_items = select_menu->items();
2103 select_menu->set_name ("ArdourContextMenu");
2105 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
2106 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
2107 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
2108 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
2109 select_items.push_back (SeparatorElem());
2110 select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
2111 select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
2112 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
2113 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
2115 edit_items.push_back (MenuElem (_("Select"), *select_menu));
2119 Menu *cutnpaste_menu = manage (new Menu);
2120 MenuList& cutnpaste_items = cutnpaste_menu->items();
2121 cutnpaste_menu->set_name ("ArdourContextMenu");
2123 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
2124 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
2125 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
2127 Menu *nudge_menu = manage (new Menu());
2128 MenuList& nudge_items = nudge_menu->items();
2129 nudge_menu->set_name ("ArdourContextMenu");
2131 edit_items.push_back (SeparatorElem());
2132 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
2133 nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
2134 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
2135 nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
2137 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
2141 Editor::set_snap_to (SnapType st)
2143 unsigned int snap_ind = (unsigned int)st;
2146 if (snap_ind > snap_type_strings.size() - 1) {
2148 snap_type = (SnapType)snap_ind;
2151 string str = snap_type_strings[snap_ind];
2153 if (str != snap_type_selector.get_active_text()) {
2154 snap_type_selector.set_active_text (str);
2159 switch (snap_type) {
2160 case SnapToAThirtysecondBeat:
2161 case SnapToASixteenthBeat:
2162 case SnapToAEighthBeat:
2163 case SnapToAQuarterBeat:
2164 case SnapToAThirdBeat:
2165 update_tempo_based_rulers ();
2168 case SnapToRegionStart:
2169 case SnapToRegionEnd:
2170 case SnapToRegionSync:
2171 case SnapToRegionBoundary:
2172 build_region_boundary_cache ();
2182 Editor::set_snap_mode (SnapMode mode)
2185 string str = snap_mode_strings[(int)mode];
2187 if (str != snap_mode_selector.get_active_text ()) {
2188 snap_mode_selector.set_active_text (str);
2194 Editor::set_edit_point_preference (EditPoint ep, bool force)
2196 bool changed = (_edit_point != ep);
2199 string str = edit_point_strings[(int)ep];
2201 if (str != edit_point_selector.get_active_text ()) {
2202 edit_point_selector.set_active_text (str);
2205 set_canvas_cursor ();
2207 if (!force && !changed) {
2211 switch (zoom_focus) {
2212 case ZoomFocusMouse:
2213 case ZoomFocusPlayhead:
2215 switch (_edit_point) {
2217 set_zoom_focus (ZoomFocusMouse);
2219 case EditAtPlayhead:
2220 set_zoom_focus (ZoomFocusPlayhead);
2222 case EditAtSelectedMarker:
2223 set_zoom_focus (ZoomFocusEdit);
2233 switch (_edit_point) {
2234 case EditAtPlayhead:
2235 action = "edit-at-playhead";
2237 case EditAtSelectedMarker:
2238 action = "edit-at-marker";
2241 action = "edit-at-mouse";
2245 Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
2247 Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
2251 bool in_track_canvas;
2253 if (!mouse_frame (foo, in_track_canvas)) {
2254 in_track_canvas = false;
2257 reset_canvas_action_sensitivity (in_track_canvas);
2263 Editor::set_state (const XMLNode& node)
2265 const XMLProperty* prop;
2267 int x, y, xoff, yoff;
2270 if ((prop = node.property ("id")) != 0) {
2271 _id = prop->value ();
2274 if ((geometry = find_named_node (node, "geometry")) == 0) {
2276 g.base_width = default_width;
2277 g.base_height = default_height;
2285 g.base_width = atoi(geometry->property("x_size")->value());
2286 g.base_height = atoi(geometry->property("y_size")->value());
2287 x = atoi(geometry->property("x_pos")->value());
2288 y = atoi(geometry->property("y_pos")->value());
2289 xoff = atoi(geometry->property("x_off")->value());
2290 yoff = atoi(geometry->property("y_off")->value());
2293 set_default_size (g.base_width, g.base_height);
2296 if (session && (prop = node.property ("playhead"))) {
2297 nframes_t pos = atol (prop->value().c_str());
2298 playhead_cursor->set_position (pos);
2300 playhead_cursor->set_position (0);
2302 /* reset_x_origin() doesn't work right here, since the old
2303 position may be zero already, and it does nothing in such
2308 horizontal_adjustment.set_value (0);
2311 if ((prop = node.property ("mixer-width"))) {
2312 editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
2315 if ((prop = node.property ("zoom-focus"))) {
2316 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2319 if ((prop = node.property ("zoom"))) {
2320 reset_zoom (PBD::atof (prop->value()));
2323 if ((prop = node.property ("snap-to"))) {
2324 set_snap_to ((SnapType) atoi (prop->value()));
2327 if ((prop = node.property ("snap-mode"))) {
2328 set_snap_mode ((SnapMode) atoi (prop->value()));
2331 if ((prop = node.property ("edit-point"))) {
2332 set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
2335 if ((prop = node.property ("mouse-mode"))) {
2336 MouseMode m = str2mousemode(prop->value());
2337 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2338 set_mouse_mode (m, true);
2340 mouse_mode = MouseGain; /* lie, to force the mode switch */
2341 set_mouse_mode (MouseObject, true);
2344 if ((prop = node.property ("show-waveforms"))) {
2345 bool yn = (prop->value() == "yes");
2346 _show_waveforms = !yn;
2347 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
2349 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2350 /* do it twice to force the change */
2351 tact->set_active (!yn);
2352 tact->set_active (yn);
2356 if ((prop = node.property ("show-waveforms-recording"))) {
2357 bool yn = (prop->value() == "yes");
2358 _show_waveforms_recording = !yn;
2359 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2361 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2362 /* do it twice to force the change */
2363 tact->set_active (!yn);
2364 tact->set_active (yn);
2368 if ((prop = node.property ("show-measures"))) {
2369 bool yn = (prop->value() == "yes");
2370 _show_measures = !yn;
2371 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2373 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2374 /* do it twice to force the change */
2375 tact->set_active (!yn);
2376 tact->set_active (yn);
2380 if ((prop = node.property ("follow-playhead"))) {
2381 bool yn = (prop->value() == "yes");
2382 set_follow_playhead (yn);
2383 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2385 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2386 if (tact->get_active() != yn) {
2387 tact->set_active (yn);
2392 if ((prop = node.property ("region-list-sort-type"))) {
2393 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2394 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2397 if ((prop = node.property ("xfades-visible"))) {
2398 bool yn = (prop->value() == "yes");
2399 _xfade_visibility = !yn;
2400 // set_xfade_visibility (yn);
2403 if ((prop = node.property ("show-editor-mixer"))) {
2405 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2408 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2409 bool yn = (prop->value() == X_("yes"));
2411 /* do it twice to force the change */
2413 tact->set_active (!yn);
2414 tact->set_active (yn);
2423 Editor::get_state ()
2425 XMLNode* node = new XMLNode ("Editor");
2428 _id.print (buf, sizeof (buf));
2429 node->add_property ("id", buf);
2431 if (is_realized()) {
2432 Glib::RefPtr<Gdk::Window> win = get_window();
2434 int x, y, xoff, yoff, width, height;
2435 win->get_root_origin(x, y);
2436 win->get_position(xoff, yoff);
2437 win->get_size(width, height);
2439 XMLNode* geometry = new XMLNode ("geometry");
2441 snprintf(buf, sizeof(buf), "%d", width);
2442 geometry->add_property("x_size", string(buf));
2443 snprintf(buf, sizeof(buf), "%d", height);
2444 geometry->add_property("y_size", string(buf));
2445 snprintf(buf, sizeof(buf), "%d", x);
2446 geometry->add_property("x_pos", string(buf));
2447 snprintf(buf, sizeof(buf), "%d", y);
2448 geometry->add_property("y_pos", string(buf));
2449 snprintf(buf, sizeof(buf), "%d", xoff);
2450 geometry->add_property("x_off", string(buf));
2451 snprintf(buf, sizeof(buf), "%d", yoff);
2452 geometry->add_property("y_off", string(buf));
2453 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2454 geometry->add_property("edit_pane_pos", string(buf));
2456 node->add_child_nocopy (*geometry);
2459 maybe_add_mixer_strip_width (*node);
2461 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2462 node->add_property ("zoom-focus", buf);
2463 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2464 node->add_property ("zoom", buf);
2465 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2466 node->add_property ("snap-to", buf);
2467 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2468 node->add_property ("snap-mode", buf);
2470 node->add_property ("edit-point", enum_2_string (_edit_point));
2472 snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
2473 node->add_property ("playhead", buf);
2475 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2476 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2477 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2478 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2479 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2480 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2481 node->add_property ("mouse-mode", enum2str(mouse_mode));
2483 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2485 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2486 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2495 Editor::trackview_by_y_position (double y)
2497 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2501 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2510 Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
2512 if (!session || snap_mode == SnapOff) {
2516 snap_to_internal (start, direction, for_mark);
2520 Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
2522 Location* before = 0;
2523 Location* after = 0;
2525 const nframes64_t one_second = session->frame_rate();
2526 const nframes64_t one_minute = session->frame_rate() * 60;
2527 const nframes64_t one_smpte_second = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2528 nframes64_t one_smpte_minute = (nframes64_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2529 nframes64_t presnap = start;
2531 switch (snap_type) {
2533 if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
2534 start = (nframes_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2536 start = (nframes_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2540 case SnapToSMPTEFrame:
2541 if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
2542 start = (nframes_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2544 start = (nframes_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2548 case SnapToSMPTESeconds:
2549 if (session->smpte_offset_negative())
2551 start += session->smpte_offset ();
2553 start -= session->smpte_offset ();
2555 if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
2556 start = (nframes_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2558 start = (nframes_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2561 if (session->smpte_offset_negative())
2563 start -= session->smpte_offset ();
2565 start += session->smpte_offset ();
2569 case SnapToSMPTEMinutes:
2570 if (session->smpte_offset_negative())
2572 start += session->smpte_offset ();
2574 start -= session->smpte_offset ();
2576 if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
2577 start = (nframes_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2579 start = (nframes_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2581 if (session->smpte_offset_negative())
2583 start -= session->smpte_offset ();
2585 start += session->smpte_offset ();
2590 if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
2591 start = (nframes_t) ceil ((double) start / one_second) * one_second;
2593 start = (nframes_t) floor ((double) start / one_second) * one_second;
2598 if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
2599 start = (nframes_t) ceil ((double) start / one_minute) * one_minute;
2601 start = (nframes_t) floor ((double) start / one_minute) * one_minute;
2606 start = session->tempo_map().round_to_bar (start, direction);
2610 start = session->tempo_map().round_to_beat (start, direction);
2613 case SnapToAThirtysecondBeat:
2614 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2617 case SnapToASixteenthBeat:
2618 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2621 case SnapToAEighthBeat:
2622 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2625 case SnapToAQuarterBeat:
2626 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2629 case SnapToAThirdBeat:
2630 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2638 before = session->locations()->first_location_before (start);
2639 after = session->locations()->first_location_after (start);
2641 if (direction < 0) {
2643 start = before->start();
2647 } else if (direction > 0) {
2649 start = after->start();
2651 start = session->current_end_frame();
2656 /* find nearest of the two */
2657 if ((start - before->start()) < (after->start() - start)) {
2658 start = before->start();
2660 start = after->start();
2663 start = before->start();
2666 start = after->start();
2673 case SnapToRegionStart:
2674 case SnapToRegionEnd:
2675 case SnapToRegionSync:
2676 case SnapToRegionBoundary:
2677 if (!region_boundary_cache.empty()) {
2678 vector<nframes_t>::iterator i;
2680 if (direction > 0) {
2681 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2683 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2686 if (i != region_boundary_cache.end()) {
2688 /* lower bound doesn't quite to the right thing for our purposes */
2690 if (direction < 0 && i != region_boundary_cache.begin()) {
2697 start = region_boundary_cache.back();
2703 switch (snap_mode) {
2709 if (presnap > start) {
2710 if (presnap > (start + unit_to_frame(snap_threshold))) {
2714 } else if (presnap < start) {
2715 if (presnap < (start - unit_to_frame(snap_threshold))) {
2721 /* handled at entry */
2728 Editor::setup_toolbar ()
2733 const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
2735 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2738 /* Mode Buttons (tool selection) */
2740 vector<ToggleButton *> mouse_mode_buttons;
2742 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2743 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2744 mouse_mode_buttons.push_back (&mouse_move_button);
2746 if (!Profile->get_sae()) {
2747 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2748 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2749 mouse_mode_buttons.push_back (&mouse_select_button);
2751 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2752 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2753 mouse_mode_buttons.push_back (&mouse_gain_button);
2756 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2757 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2758 mouse_mode_buttons.push_back (&mouse_zoom_button);
2759 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2760 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2761 mouse_mode_buttons.push_back (&mouse_timefx_button);
2762 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2763 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2764 mouse_mode_buttons.push_back (&mouse_audition_button);
2766 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2768 HBox* mode_box = manage(new HBox);
2769 mode_box->set_border_width (2);
2770 mode_box->set_spacing(4);
2771 mouse_mode_button_box.set_spacing(1);
2772 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2773 if (!Profile->get_sae()) {
2774 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2776 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2777 if (!Profile->get_sae()) {
2778 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2780 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2781 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2782 mouse_mode_button_box.set_homogeneous(true);
2784 vector<string> edit_mode_strings;
2785 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2786 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2787 edit_mode_strings.push_back (edit_mode_to_string (Lock));
2789 edit_mode_selector.set_name ("EditModeSelector");
2790 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2791 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2792 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2794 mode_box->pack_start(edit_mode_selector);
2795 mode_box->pack_start(mouse_mode_button_box);
2797 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2798 mouse_mode_tearoff->set_name ("MouseModeBase");
2800 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2801 &mouse_mode_tearoff->tearoff_window()));
2802 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2803 &mouse_mode_tearoff->tearoff_window(), 1));
2804 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2805 &mouse_mode_tearoff->tearoff_window()));
2806 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2807 &mouse_mode_tearoff->tearoff_window(), 1));
2809 mouse_move_button.set_name ("MouseModeButton");
2810 mouse_select_button.set_name ("MouseModeButton");
2811 mouse_gain_button.set_name ("MouseModeButton");
2812 mouse_zoom_button.set_name ("MouseModeButton");
2813 mouse_timefx_button.set_name ("MouseModeButton");
2814 mouse_audition_button.set_name ("MouseModeButton");
2816 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2817 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2818 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2819 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2820 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2821 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2823 mouse_move_button.unset_flags (CAN_FOCUS);
2824 mouse_select_button.unset_flags (CAN_FOCUS);
2825 mouse_gain_button.unset_flags (CAN_FOCUS);
2826 mouse_zoom_button.unset_flags (CAN_FOCUS);
2827 mouse_timefx_button.unset_flags (CAN_FOCUS);
2828 mouse_audition_button.unset_flags (CAN_FOCUS);
2830 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2831 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2833 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2834 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2835 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2836 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2837 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2839 // mouse_move_button.set_active (true);
2844 zoom_box.set_spacing (1);
2845 zoom_box.set_border_width (2);
2847 zoom_in_button.set_name ("EditorTimeButton");
2848 zoom_in_button.set_size_request(-1,16);
2849 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2850 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2851 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2853 zoom_out_button.set_name ("EditorTimeButton");
2854 zoom_out_button.set_size_request(-1,16);
2855 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2856 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2857 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2859 zoom_out_full_button.set_name ("EditorTimeButton");
2860 zoom_out_full_button.set_size_request(-1,16);
2861 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2862 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2863 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2865 zoom_focus_selector.set_name ("ZoomFocusSelector");
2866 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
2867 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
2868 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2869 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2871 zoom_box.pack_start (zoom_focus_selector, true, true);
2872 zoom_box.pack_start (zoom_out_button, false, false);
2873 zoom_box.pack_start (zoom_in_button, false, false);
2874 zoom_box.pack_start (zoom_out_full_button, false, false);
2876 snap_box.set_spacing (1);
2877 snap_box.set_border_width (2);
2879 snap_type_selector.set_name ("SnapTypeSelector");
2880 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
2881 set_popdown_strings (snap_type_selector, snap_type_strings);
2882 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2883 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
2885 snap_mode_selector.set_name ("SnapModeSelector");
2886 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
2887 set_popdown_strings (snap_mode_selector, snap_mode_strings);
2888 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2889 ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
2891 edit_point_selector.set_name ("SnapModeSelector");
2892 Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
2893 set_popdown_strings (edit_point_selector, edit_point_strings);
2894 edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
2895 ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
2897 snap_box.pack_start (edit_point_clock, false, false);
2898 snap_box.pack_start (snap_mode_selector, false, false);
2899 snap_box.pack_start (snap_type_selector, false, false);
2900 snap_box.pack_start (edit_point_selector, false, false);
2904 HBox *nudge_box = manage (new HBox);
2905 nudge_box->set_spacing(1);
2906 nudge_box->set_border_width (2);
2908 nudge_forward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_forward_release), false);
2909 nudge_backward_button.signal_button_release_event().connect (mem_fun(*this, &Editor::nudge_backward_release), false);
2911 nudge_box->pack_start (nudge_backward_button, false, false);
2912 nudge_box->pack_start (nudge_forward_button, false, false);
2913 nudge_box->pack_start (nudge_clock, false, false);
2916 /* Pack everything in... */
2918 HBox* hbox = new HBox;
2919 hbox->set_spacing(10);
2921 tools_tearoff = new TearOff (*hbox);
2922 tools_tearoff->set_name ("MouseModeBase");
2924 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2925 &tools_tearoff->tearoff_window()));
2926 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2927 &tools_tearoff->tearoff_window(), 0));
2928 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2929 &tools_tearoff->tearoff_window()));
2930 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2931 &tools_tearoff->tearoff_window(), 0));
2933 toolbar_hbox.set_spacing (10);
2934 toolbar_hbox.set_border_width (1);
2936 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2937 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2940 hbox->pack_start (snap_box, false, false);
2941 // hbox->pack_start (zoom_box, false, false);
2942 hbox->pack_start (*nudge_box, false, false);
2946 toolbar_base.set_name ("ToolBarBase");
2947 toolbar_base.add (toolbar_hbox);
2949 toolbar_frame.set_shadow_type (SHADOW_OUT);
2950 toolbar_frame.set_name ("BaseFrame");
2951 toolbar_frame.add (toolbar_base);
2955 Editor::convert_drop_to_paths (vector<ustring>& paths,
2956 const RefPtr<Gdk::DragContext>& context,
2959 const SelectionData& data,
2968 vector<ustring> uris = data.get_uris();
2972 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
2973 are actually URI lists. So do it by hand.
2976 if (data.get_target() != "text/plain") {
2980 /* Parse the "uri-list" format that Nautilus provides,
2981 where each pathname is delimited by \r\n
2984 const char* p = data.get_text().c_str();
2991 while (g_ascii_isspace (*p))
2995 while (*q && (*q != '\n') && (*q != '\r'))
3001 while (q > p && g_ascii_isspace (*q))
3006 uris.push_back (ustring (p, q - p + 1));
3010 p = strchr (p, '\n');
3020 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
3022 if ((*i).substr (0,7) == "file://") {
3026 PBD::url_decode (p);
3028 // scan forward past three slashes
3030 ustring::size_type slashcnt = 0;
3031 ustring::size_type n = 0;
3032 ustring::iterator x = p.begin();
3034 while (slashcnt < 3 && x != p.end()) {
3037 } else if (slashcnt == 3) {
3044 if (slashcnt != 3 || x == p.end()) {
3045 error << _("malformed URL passed to drag-n-drop code") << endmsg;
3049 paths.push_back (p.substr (n - 1));
3057 Editor::new_tempo_section ()
3063 Editor::map_transport_state ()
3065 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
3067 if (session->transport_stopped()) {
3068 have_pending_keyboard_selection = false;
3071 update_loop_range_view (true);
3076 Editor::State::State ()
3078 selection = new Selection;
3081 Editor::State::~State ()
3087 Editor::get_memento () const
3089 State *state = new State;
3091 store_state (*state);
3092 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
3096 Editor::store_state (State& state) const
3098 *state.selection = *selection;
3102 Editor::restore_state (State *state)
3104 if (*selection == *state->selection) {
3108 *selection = *state->selection;
3109 time_selection_changed ();
3110 region_selection_changed ();
3112 /* XXX other selection change handlers? */
3116 Editor::begin_reversible_command (string name)
3119 // before = &get_state();
3120 session->begin_reversible_command (name);
3125 Editor::commit_reversible_command ()
3128 // session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
3129 session->commit_reversible_command ();
3134 Editor::set_edit_group_solo (Route& route, bool yn)
3136 RouteGroup *edit_group;
3138 if ((edit_group = route.edit_group()) != 0) {
3139 edit_group->apply (&Route::set_solo, yn, this);
3141 route.set_solo (yn, this);
3146 Editor::set_edit_group_mute (Route& route, bool yn)
3148 RouteGroup *edit_group = 0;
3150 if ((edit_group == route.edit_group()) != 0) {
3151 edit_group->apply (&Route::set_mute, yn, this);
3153 route.set_mute (yn, this);
3158 Editor::history_changed ()
3162 if (undo_action && session) {
3163 if (session->undo_depth() == 0) {
3166 label = string_compose(_("Undo (%1)"), session->next_undo());
3168 undo_action->property_label() = label;
3171 if (redo_action && session) {
3172 if (session->redo_depth() == 0) {
3175 label = string_compose(_("Redo (%1)"), session->next_redo());
3177 redo_action->property_label() = label;
3182 Editor::duplicate_dialog (bool with_dialog)
3186 if (mouse_mode == MouseRange) {
3187 if (selection->time.length() == 0) {
3193 get_regions_for_action (rs);
3195 if (mouse_mode != MouseRange) {
3204 ArdourDialog win ("Duplication Dialog");
3205 Label label (_("Number of Duplications:"));
3206 Adjustment adjustment (1.0, 1.0, 1000000.0, 1.0, 5.0);
3207 SpinButton spinner (adjustment, 0.0, 1);
3210 win.get_vbox()->set_spacing (12);
3211 win.get_vbox()->pack_start (hbox);
3212 hbox.set_border_width (6);
3213 hbox.pack_start (label, PACK_EXPAND_PADDING, 12);
3215 /* dialogs have ::add_action_widget() but that puts the spinner in the wrong
3216 place, visually. so do this by hand.
3219 hbox.pack_start (spinner, PACK_EXPAND_PADDING, 12);
3220 spinner.signal_activate().connect (sigc::bind (mem_fun (win, &ArdourDialog::response), RESPONSE_ACCEPT));
3221 spinner.grab_focus();
3227 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
3228 win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
3229 win.set_default_response (RESPONSE_ACCEPT);
3231 win.set_position (WIN_POS_MOUSE);
3233 spinner.grab_focus ();
3235 switch (win.run ()) {
3236 case RESPONSE_ACCEPT:
3242 times = adjustment.get_value();
3245 if (mouse_mode == MouseRange) {
3246 duplicate_selection (times);
3248 duplicate_some_regions (rs, times);
3253 Editor::show_verbose_canvas_cursor ()
3255 verbose_canvas_cursor->raise_to_top();
3256 verbose_canvas_cursor->show();
3257 verbose_cursor_visible = true;
3261 Editor::hide_verbose_canvas_cursor ()
3263 verbose_canvas_cursor->hide();
3264 verbose_cursor_visible = false;
3268 Editor::clamp_verbose_cursor_x (double x)
3270 return min (horizontal_adjustment.get_value() + canvas_width - 75.0, x);
3274 Editor::clamp_verbose_cursor_y (double y)
3276 return min (vertical_adjustment.get_value() + canvas_height - 50.0, y);
3280 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
3282 verbose_canvas_cursor->property_text() = txt.c_str();
3283 /* don't get too close to the edge */
3284 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
3285 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_x (y);
3289 Editor::set_verbose_canvas_cursor_text (const string & txt)
3291 verbose_canvas_cursor->property_text() = txt.c_str();
3295 Editor::set_edit_mode (EditMode m)
3297 Config->set_edit_mode (m);
3301 Editor::cycle_edit_mode ()
3303 switch (Config->get_edit_mode()) {
3305 Config->set_edit_mode (Splice);
3308 Config->set_edit_mode (Lock);
3311 Config->set_edit_mode (Slide);
3317 Editor::edit_mode_selection_done ()
3323 string choice = edit_mode_selector.get_active_text();
3324 EditMode mode = Slide;
3326 if (choice == _("Splice Edit")) {
3328 } else if (choice == _("Slide Edit")) {
3330 } else if (choice == _("Lock Edit")) {
3334 Config->set_edit_mode (mode);
3338 Editor::snap_type_selection_done ()
3340 string choice = snap_type_selector.get_active_text();
3341 SnapType snaptype = SnapToBeat;
3343 if (choice == _("Beats/3")) {
3344 snaptype = SnapToAThirdBeat;
3345 } else if (choice == _("Beats/4")) {
3346 snaptype = SnapToAQuarterBeat;
3347 } else if (choice == _("Beats/8")) {
3348 snaptype = SnapToAEighthBeat;
3349 } else if (choice == _("Beats/16")) {
3350 snaptype = SnapToASixteenthBeat;
3351 } else if (choice == _("Beats/32")) {
3352 snaptype = SnapToAThirtysecondBeat;
3353 } else if (choice == _("Beats")) {
3354 snaptype = SnapToBeat;
3355 } else if (choice == _("Bars")) {
3356 snaptype = SnapToBar;
3357 } else if (choice == _("Marks")) {
3358 snaptype = SnapToMark;
3359 } else if (choice == _("Region starts")) {
3360 snaptype = SnapToRegionStart;
3361 } else if (choice == _("Region ends")) {
3362 snaptype = SnapToRegionEnd;
3363 } else if (choice == _("Region bounds")) {
3364 snaptype = SnapToRegionBoundary;
3365 } else if (choice == _("Region syncs")) {
3366 snaptype = SnapToRegionSync;
3367 } else if (choice == _("CD Frames")) {
3368 snaptype = SnapToCDFrame;
3369 } else if (choice == _("SMPTE Frames")) {
3370 snaptype = SnapToSMPTEFrame;
3371 } else if (choice == _("SMPTE Seconds")) {
3372 snaptype = SnapToSMPTESeconds;
3373 } else if (choice == _("SMPTE Minutes")) {
3374 snaptype = SnapToSMPTEMinutes;
3375 } else if (choice == _("Seconds")) {
3376 snaptype = SnapToSeconds;
3377 } else if (choice == _("Minutes")) {
3378 snaptype = SnapToMinutes;
3381 RefPtr<RadioAction> ract = snap_type_action (snaptype);
3383 ract->set_active ();
3388 Editor::snap_mode_selection_done ()
3390 string choice = snap_mode_selector.get_active_text();
3391 SnapMode mode = SnapNormal;
3393 if (choice == _("No Grid")) {
3395 } else if (choice == _("Grid")) {
3397 } else if (choice == _("Magnetic")) {
3398 mode = SnapMagnetic;
3401 RefPtr<RadioAction> ract = snap_mode_action (mode);
3404 ract->set_active (true);
3409 Editor::cycle_edit_point (bool with_marker)
3411 switch (_edit_point) {
3413 set_edit_point_preference (EditAtPlayhead);
3415 case EditAtPlayhead:
3417 set_edit_point_preference (EditAtSelectedMarker);
3419 set_edit_point_preference (EditAtMouse);
3422 case EditAtSelectedMarker:
3423 set_edit_point_preference (EditAtMouse);
3429 Editor::edit_point_selection_done ()
3431 string choice = edit_point_selector.get_active_text();
3432 EditPoint ep = EditAtSelectedMarker;
3434 if (choice == _("Marker")) {
3435 set_edit_point_preference (EditAtSelectedMarker);
3436 } else if (choice == _("Playhead")) {
3437 set_edit_point_preference (EditAtPlayhead);
3439 set_edit_point_preference (EditAtMouse);
3442 RefPtr<RadioAction> ract = edit_point_action (ep);
3445 ract->set_active (true);
3450 Editor::zoom_focus_selection_done ()
3452 string choice = zoom_focus_selector.get_active_text();
3453 ZoomFocus focus_type = ZoomFocusLeft;
3455 if (choice == _("Left")) {
3456 focus_type = ZoomFocusLeft;
3457 } else if (choice == _("Right")) {
3458 focus_type = ZoomFocusRight;
3459 } else if (choice == _("Center")) {
3460 focus_type = ZoomFocusCenter;
3461 } else if (choice == _("Playhead")) {
3462 focus_type = ZoomFocusPlayhead;
3463 } else if (choice == _("Mouse")) {
3464 focus_type = ZoomFocusMouse;
3465 } else if (choice == _("Active Mark")) {
3466 focus_type = ZoomFocusEdit;
3469 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3472 ract->set_active ();
3477 Editor::edit_controls_button_release (GdkEventButton* ev)
3479 if (Keyboard::is_context_menu_event (ev)) {
3480 ARDOUR_UI::instance()->add_route (this);
3486 Editor::mouse_select_button_release (GdkEventButton* ev)
3488 /* this handles just right-clicks */
3490 if (ev->button != 3) {
3497 Editor::TrackViewList *
3498 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3501 TrackViewList::iterator i;
3503 v = new TrackViewList;
3505 if (track == 0 && group == 0) {
3509 for (i = track_views.begin(); i != track_views.end (); ++i) {
3513 } else if (track != 0 && group == 0 || (track != 0 && group != 0 && !group->is_active())) {
3515 /* just the view for this track
3518 v->push_back (track);
3522 /* views for all tracks in the edit group */
3524 for (i = track_views.begin(); i != track_views.end (); ++i) {
3526 if (group == 0 || (*i)->edit_group() == group) {
3536 Editor::set_zoom_focus (ZoomFocus f)
3538 string str = zoom_focus_strings[(int)f];
3540 if (str != zoom_focus_selector.get_active_text()) {
3541 zoom_focus_selector.set_active_text (str);
3544 if (zoom_focus != f) {
3547 ZoomFocusChanged (); /* EMIT_SIGNAL */
3554 Editor::ensure_float (Window& win)
3556 win.set_transient_for (*this);
3560 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3562 /* recover or initialize pane positions. do this here rather than earlier because
3563 we don't want the positions to change the child allocations, which they seem to do.
3569 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3571 static int32_t done;
3574 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3575 width = default_width;
3576 height = default_height;
3578 width = atoi(geometry->property("x_size")->value());
3579 height = atoi(geometry->property("y_size")->value());
3582 if (which == static_cast<Paned*> (&edit_pane)) {
3588 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3589 /* initial allocation is 90% to canvas, 10% to notebook */
3590 pos = (int) floor (alloc.get_width() * 0.90f);
3591 snprintf (buf, sizeof(buf), "%d", pos);
3593 pos = atoi (prop->value());
3596 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3597 edit_pane.set_position (pos);
3598 pre_maximal_pane_position = pos;
3604 Editor::detach_tearoff (Box* b, Window* w)
3606 if (tools_tearoff->torn_off() &&
3607 mouse_mode_tearoff->torn_off()) {
3608 top_hbox.remove (toolbar_frame);
3613 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3615 if (toolbar_frame.get_parent() == 0) {
3616 top_hbox.pack_end (toolbar_frame);
3621 Editor::set_show_measures (bool yn)
3623 if (_show_measures != yn) {
3626 if ((_show_measures = yn) == true) {
3634 Editor::toggle_follow_playhead ()
3636 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3638 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3639 set_follow_playhead (tact->get_active());
3644 Editor::set_follow_playhead (bool yn)
3646 if (_follow_playhead != yn) {
3647 if ((_follow_playhead = yn) == true) {
3649 update_current_screen ();
3656 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3658 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3660 xfade->set_active (!xfade->active());
3665 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3667 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3669 xfade->set_follow_overlap (!xfade->following_overlap());
3674 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3676 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3682 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3686 switch (cew.run ()) {
3687 case RESPONSE_ACCEPT:
3694 xfade->StateChanged (Change (~0));
3698 Editor::playlist_selector () const
3700 return *_playlist_selector;
3704 Editor::get_nudge_distance (nframes_t pos, nframes_t& next)
3708 ret = nudge_clock.current_duration (pos);
3709 next = ret + 1; /* XXXX fix me */
3715 Editor::end_location_changed (Location* location)
3717 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3718 reset_scrolling_region ();
3722 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3724 ArdourDialog dialog ("playlist deletion dialog");
3725 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3726 "If left alone, no audio files used by it will be cleaned.\n"
3727 "If deleted, audio files used by it alone by will cleaned."),
3730 dialog.set_position (WIN_POS_CENTER);
3731 dialog.get_vbox()->pack_start (label);
3735 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3736 dialog.add_button (_("Keep playlist"), RESPONSE_REJECT);
3737 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3739 switch (dialog.run ()) {
3740 case RESPONSE_ACCEPT:
3741 /* delete the playlist */
3745 case RESPONSE_REJECT:
3746 /* keep the playlist */
3758 Editor::audio_region_selection_covers (nframes_t where)
3760 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3761 if ((*a)->region()->covers (where)) {
3770 Editor::prepare_for_cleanup ()
3772 cut_buffer->clear_regions ();
3773 cut_buffer->clear_playlists ();
3775 selection->clear_regions ();
3776 selection->clear_playlists ();
3780 Editor::transport_loop_location()
3783 return session->locations()->auto_loop_location();
3790 Editor::transport_punch_location()
3793 return session->locations()->auto_punch_location();
3800 Editor::control_layout_scroll (GdkEventScroll* ev)
3802 switch (ev->direction) {
3804 scroll_tracks_up_line ();
3808 case GDK_SCROLL_DOWN:
3809 scroll_tracks_down_line ();
3813 /* no left/right handling yet */
3821 /** A new snapshot has been selected.
3824 Editor::snapshot_display_selection_changed ()
3826 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
3828 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
3830 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
3832 if (snap_name.length() == 0) {
3836 if (session->snap_name() == snap_name) {
3840 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
3845 Editor::snapshot_display_button_press (GdkEventButton* ev)
3847 if (ev->button == 3) {
3848 /* Right-click on the snapshot list. Work out which snapshot it
3850 Gtk::TreeModel::Path path;
3851 Gtk::TreeViewColumn* col;
3854 snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
3855 Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
3857 Gtk::TreeModel::Row row = *iter;
3858 popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
3867 /** Pop up the snapshot display context menu.
3868 * @param button Button used to open the menu.
3869 * @param time Menu open time.
3870 * @snapshot_name Name of the snapshot that the menu click was over.
3874 Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
3876 using namespace Menu_Helpers;
3878 MenuList& items (snapshot_context_menu.items());
3881 const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
3883 items.push_back (MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)));
3884 if (!modification_allowed) {
3885 items.back().set_sensitive (false);
3888 items.push_back (MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)));
3889 if (!modification_allowed) {
3890 items.back().set_sensitive (false);
3893 snapshot_context_menu.popup (button, time);
3897 Editor::rename_snapshot (Glib::ustring old_name)
3899 ArdourPrompter prompter(true);
3903 prompter.set_name ("Prompter");
3904 prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
3905 prompter.set_prompt (_("New name of snapshot"));
3906 prompter.set_initial_text (old_name);
3908 if (prompter.run() == RESPONSE_ACCEPT) {
3909 prompter.get_result (new_name);
3910 if (new_name.length()) {
3911 session->rename_state (old_name, new_name);
3912 redisplay_snapshots ();
3919 Editor::remove_snapshot (Glib::ustring name)
3921 vector<string> choices;
3923 std::string prompt = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
3925 choices.push_back (_("No, do nothing."));
3926 choices.push_back (_("Yes, remove it."));
3928 Gtkmm2ext::Choice prompter (prompt, choices);
3930 if (prompter.run () == 1) {
3931 session->remove_state (name);
3932 redisplay_snapshots ();
3937 Editor::redisplay_snapshots ()
3943 vector<string*>* states;
3945 if ((states = session->possible_states()) == 0) {
3949 snapshot_display_model->clear ();
3951 for (vector<string*>::iterator i = states->begin(); i != states->end(); ++i) {
3952 string statename = *(*i);
3953 TreeModel::Row row = *(snapshot_display_model->append());
3955 /* this lingers on in case we ever want to change the visible
3956 name of the snapshot.
3959 string display_name;
3960 display_name = statename;
3962 if (statename == session->snap_name()) {
3963 snapshot_display.get_selection()->select(row);
3966 row[snapshot_display_columns.visible_name] = display_name;
3967 row[snapshot_display_columns.real_name] = statename;
3974 Editor::session_state_saved (string snap_name)
3976 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
3977 redisplay_snapshots ();
3981 Editor::maximise_editing_space ()
3983 initial_ruler_update_required = true;
3985 mouse_mode_tearoff->set_visible (false);
3986 tools_tearoff->set_visible (false);
3988 pre_maximal_pane_position = edit_pane.get_position();
3989 pre_maximal_editor_width = this->get_width();
3991 if(post_maximal_pane_position == 0) {
3992 post_maximal_pane_position = edit_pane.get_width();
3997 if(post_maximal_editor_width) {
3998 edit_pane.set_position (post_maximal_pane_position -
3999 abs(post_maximal_editor_width - pre_maximal_editor_width));
4001 edit_pane.set_position (post_maximal_pane_position);
4006 Editor::restore_editing_space ()
4008 initial_ruler_update_required = true;
4010 // user changed width of pane during fullscreen
4011 if(post_maximal_pane_position != edit_pane.get_position()) {
4012 post_maximal_pane_position = edit_pane.get_position();
4017 mouse_mode_tearoff->set_visible (true);
4018 tools_tearoff->set_visible (true);
4019 post_maximal_editor_width = this->get_width();
4022 edit_pane.set_position (
4023 pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width)
4028 * Make new playlists for a given track and also any others that belong
4029 * to the same active edit group.
4034 Editor::new_playlists (TimeAxisView* v)
4036 begin_reversible_command (_("new playlists"));
4037 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
4038 commit_reversible_command ();
4043 * Use a copy of the current playlist for a given track and also any others that belong
4044 * to the same active edit group.
4049 Editor::copy_playlists (TimeAxisView* v)
4051 begin_reversible_command (_("copy playlists"));
4052 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
4053 commit_reversible_command ();
4058 * Clear the current playlist for a given track and also any others that belong
4059 * to the same active edit group.
4064 Editor::clear_playlists (TimeAxisView* v)
4066 begin_reversible_command (_("clear playlists"));
4067 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
4068 commit_reversible_command ();
4072 Editor::mapped_use_new_playlist (AudioTimeAxisView& atv, uint32_t sz)
4074 atv.use_new_playlist (sz > 1 ? false : true);
4078 Editor::mapped_use_copy_playlist (AudioTimeAxisView& atv, uint32_t sz)
4080 atv.use_copy_playlist (sz > 1 ? false : true);
4084 Editor::mapped_clear_playlist (AudioTimeAxisView& atv, uint32_t sz)
4086 atv.clear_playlist ();
4090 Editor::on_key_press_event (GdkEventKey* ev)
4092 return key_press_focus_accelerator_handler (*this, ev);
4096 Editor::on_key_release_event (GdkEventKey* ev)
4098 return Gtk::Window::on_key_release_event (ev);
4099 // return key_press_focus_accelerator_handler (*this, ev);
4103 Editor::reset_x_origin (nframes_t frame)
4105 queue_visual_change (frame);
4109 Editor::reset_zoom (double fpu)
4111 queue_visual_change (fpu);
4115 Editor::reposition_and_zoom (nframes_t frame, double fpu)
4117 reset_x_origin (frame);
4120 if (!no_save_visual) {
4121 undo_visual_stack.push_back (current_visual_state(false));
4125 Editor::VisualState*
4126 Editor::current_visual_state (bool with_tracks)
4128 VisualState* vs = new VisualState;
4129 vs->y_position = vertical_adjustment.get_value();
4130 vs->frames_per_unit = frames_per_unit;
4131 vs->leftmost_frame = leftmost_frame;
4132 vs->zoom_focus = zoom_focus;
4133 vs->zoomed_to_region = zoomed_to_region;
4136 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4137 vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
4145 Editor::undo_visual_state ()
4147 if (undo_visual_stack.empty()) {
4151 VisualState* vs = undo_visual_stack.back();
4152 undo_visual_stack.pop_back();
4153 use_visual_state (*vs);
4154 redo_visual_stack.push_back (vs);
4158 Editor::redo_visual_state ()
4160 if (redo_visual_stack.empty()) {
4164 VisualState* vs = redo_visual_stack.back();
4165 redo_visual_stack.pop_back();
4166 use_visual_state (*vs);
4167 undo_visual_stack.push_back (vs);
4171 Editor::swap_visual_state ()
4173 if (undo_visual_stack.empty()) {
4174 redo_visual_state ();
4176 undo_visual_state ();
4181 Editor::use_visual_state (VisualState& vs)
4183 no_save_visual = true;
4185 vertical_adjustment.set_value (vs.y_position);
4187 set_zoom_focus (vs.zoom_focus);
4188 reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
4190 for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
4191 TrackViewList::iterator t;
4193 /* check if the track still exists - it could have been deleted */
4195 if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
4196 (*t)->set_state (*(i->second));
4200 if (!vs.track_states.empty()) {
4201 update_route_visibility ();
4204 no_save_visual = false;
4208 Editor::set_frames_per_unit (double fpu)
4210 /* this is the core function that controls the zoom level of the canvas. it is called
4211 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
4214 if (fpu == frames_per_unit) {
4223 /* don't allow zooms that fit more than the maximum number
4224 of frames into an 800 pixel wide space.
4227 if (max_frames / fpu < 800.0) {
4231 if (fpu == frames_per_unit) {
4235 frames_per_unit = fpu;
4240 Editor::post_zoom ()
4242 // convert fpu to frame count
4244 nframes_t frames = (nframes_t) floor (frames_per_unit * canvas_width);
4246 if (frames_per_unit != zoom_range_clock.current_duration()) {
4247 zoom_range_clock.set (frames);
4250 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
4251 if (!selection->tracks.empty()) {
4252 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4253 (*i)->reshow_selection (selection->time);
4256 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4257 (*i)->reshow_selection (selection->time);
4262 ZoomChanged (); /* EMIT_SIGNAL */
4264 reset_hscrollbar_stepping ();
4265 reset_scrolling_region ();
4267 if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
4273 Editor::queue_visual_change (nframes_t where)
4275 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
4276 pending_visual_change.time_origin = where;
4278 if (pending_visual_change.idle_handler_id < 0) {
4279 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
4284 Editor::queue_visual_change (double fpu)
4286 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
4287 pending_visual_change.frames_per_unit = fpu;
4289 if (pending_visual_change.idle_handler_id < 0) {
4290 pending_visual_change.idle_handler_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, _idle_visual_changer, this, 0);
4295 Editor::_idle_visual_changer (void* arg)
4297 return static_cast<Editor*>(arg)->idle_visual_changer ();
4301 Editor::idle_visual_changer ()
4303 VisualChange::Type p = pending_visual_change.pending;
4305 pending_visual_change.pending = (VisualChange::Type) 0;
4306 pending_visual_change.idle_handler_id = -1;
4308 if (p & VisualChange::ZoomLevel) {
4309 set_frames_per_unit (pending_visual_change.frames_per_unit);
4312 if (p & VisualChange::TimeOrigin) {
4314 nframes_t time_origin = (nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
4316 if (time_origin != pending_visual_change.time_origin) {
4317 horizontal_adjustment.set_value (pending_visual_change.time_origin/frames_per_unit);
4319 update_fixed_rulers();
4320 redisplay_tempo (true);
4324 return 0; /* this is always a one-shot call */
4327 struct EditorOrderTimeAxisSorter {
4328 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
4329 return a->order < b->order;
4334 Editor::sort_track_selection (TrackSelection* sel)
4336 EditorOrderTimeAxisSorter cmp;
4341 selection->tracks.sort (cmp);
4346 Editor::get_preferred_edit_position (bool ignore_playhead)
4349 nframes64_t where = 0;
4350 EditPoint ep = _edit_point;
4352 if (entered_marker) {
4353 return entered_marker->position();
4356 if (ignore_playhead && ep == EditAtPlayhead) {
4357 ep = EditAtSelectedMarker;
4361 case EditAtPlayhead:
4362 where = session->audible_frame();
4365 case EditAtSelectedMarker:
4366 if (!selection->markers.empty()) {
4368 Location* loc = find_location_from_marker (selection->markers.front(), is_start);
4371 where = loc->start();
4382 if (!mouse_frame (where, ignored)) {
4383 /* XXX not right but what can we do ? */
4394 Editor::set_loop_range (nframes_t start, nframes_t end, string cmd)
4396 if (!session) return;
4398 begin_reversible_command (cmd);
4402 if ((tll = transport_loop_location()) == 0) {
4403 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
4404 XMLNode &before = session->locations()->get_state();
4405 session->locations()->add (loc, true);
4406 session->set_auto_loop_location (loc);
4407 XMLNode &after = session->locations()->get_state();
4408 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4410 XMLNode &before = tll->get_state();
4411 tll->set_hidden (false, this);
4412 tll->set (start, end);
4413 XMLNode &after = tll->get_state();
4414 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
4417 commit_reversible_command ();
4421 Editor::set_punch_range (nframes_t start, nframes_t end, string cmd)
4423 if (!session) return;
4425 begin_reversible_command (cmd);
4429 if ((tpl = transport_punch_location()) == 0) {
4430 Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
4431 XMLNode &before = session->locations()->get_state();
4432 session->locations()->add (loc, true);
4433 session->set_auto_loop_location (loc);
4434 XMLNode &after = session->locations()->get_state();
4435 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
4438 XMLNode &before = tpl->get_state();
4439 tpl->set_hidden (false, this);
4440 tpl->set (start, end);
4441 XMLNode &after = tpl->get_state();
4442 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
4445 commit_reversible_command ();
4449 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4451 const TrackSelection* tracks;
4454 tracks = &track_views;
4459 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4461 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4464 boost::shared_ptr<Diskstream> ds;
4465 boost::shared_ptr<Playlist> pl;
4467 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4469 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)where * ds->speed()));
4471 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4473 RegionView* rv = atv->audio_view()->find_view (*i);
4487 Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
4489 const TrackSelection* tracks;
4492 tracks = &track_views;
4497 for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
4499 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
4502 boost::shared_ptr<Diskstream> ds;
4503 boost::shared_ptr<Playlist> pl;
4505 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
4507 Playlist::RegionList* regions = pl->regions_touched ((nframes_t) floor ( (double)where * ds->speed()), max_frames);
4509 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
4511 RegionView* rv = atv->audio_view()->find_view (*i);
4525 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
4527 if (selection->regions.empty()) {
4529 if (selection->tracks.empty()) {
4531 /* no regions or tracks selected
4534 if (entered_regionview && mouse_mode == Editing::MouseObject) {
4536 /* entered regionview is valid and we're in object mode -
4537 just use entered regionview
4540 rs.add (entered_regionview);
4547 /* no regions selected, so get all regions at the edit point across
4548 all selected tracks.
4551 nframes64_t where = get_preferred_edit_position();
4552 get_regions_at (rs, where, selection->tracks);
4554 /* if the entered regionview wasn't selected and neither was its track
4558 if (entered_regionview != 0 &&
4559 !selection->selected (entered_regionview) &&
4560 !selection->selected (&entered_regionview->get_time_axis_view())) {
4561 rs.add (entered_regionview);
4567 /* just use the selected regions */
4569 rs = selection->regions;
4571 /* if the entered regionview wasn't selected and we allow this sort of thing,
4575 if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
4576 rs.add (entered_regionview);
4583 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
4586 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
4588 RouteTimeAxisView* tatv;
4590 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
4592 boost::shared_ptr<Playlist> pl;
4593 vector<boost::shared_ptr<Region> > results;
4595 boost::shared_ptr<Diskstream> ds;
4597 if ((ds = tatv->get_diskstream()) == 0) {
4602 if ((pl = (ds->playlist())) != 0) {
4603 pl->get_region_list_equivalent_regions (region, results);
4606 for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
4607 if ((marv = tatv->view()->find_view (*ir)) != 0) {
4608 regions.push_back (marv);
4617 Editor::show_rhythm_ferret ()
4619 if (rhythm_ferret == 0) {
4620 rhythm_ferret = new RhythmFerret(*this);
4623 rhythm_ferret->set_session (session);
4624 rhythm_ferret->show ();
4625 rhythm_ferret->present ();
4629 Editor::first_idle ()
4631 MessageDialog* dialog = 0;
4633 if (track_views.size() > 1) {
4634 dialog = new MessageDialog (*this,
4635 _("Please wait while Ardour loads visual data"),
4640 ARDOUR_UI::instance()->flush_pending ();
4643 for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {