2 Copyright (C) 2000-2006 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.
26 #include <sigc++/bind.h>
28 #include <pbd/convert.h>
29 #include <pbd/error.h>
30 #include <pbd/stacktrace.h>
31 #include <pbd/memento_command.h>
33 #include <gtkmm/image.h>
34 #include <gdkmm/color.h>
35 #include <gdkmm/bitmap.h>
37 #include <gtkmm2ext/grouped_buttons.h>
38 #include <gtkmm2ext/gtk_ui.h>
39 #include <gtkmm2ext/tearoff.h>
40 #include <gtkmm2ext/utils.h>
42 #include <ardour/audio_track.h>
43 #include <ardour/audio_diskstream.h>
44 #include <ardour/plugin_manager.h>
45 #include <ardour/location.h>
46 #include <ardour/audioplaylist.h>
47 #include <ardour/audioregion.h>
48 #include <ardour/region.h>
49 #include <ardour/session_route.h>
50 #include <ardour/tempo.h>
51 #include <ardour/utils.h>
53 #include <control_protocol/control_protocol.h>
55 #include "ardour_ui.h"
59 #include "playlist_selector.h"
60 #include "audio_region_view.h"
61 #include "rgb_macros.h"
62 #include "selection.h"
63 #include "audio_streamview.h"
64 #include "time_axis_view.h"
65 #include "audio_time_axis.h"
67 #include "crossfade_view.h"
69 #include "public_editor.h"
70 #include "crossfade_edit.h"
71 #include "canvas_impl.h"
73 #include "gui_thread.h"
76 #include "analysis_window.h"
82 #include "imageframe_socket_handler.h"
83 /* </CMT Additions> */
87 using namespace ARDOUR;
91 using namespace Gtkmm2ext;
92 using namespace Editing;
96 const double Editor::timebar_height = 15.0;
98 #include "editor_xpms"
100 static const gchar *_snap_type_strings[] = {
124 static const gchar *_snap_mode_strings[] = {
130 static const gchar *_zoom_focus_strings[] = {
139 /* Soundfile drag-n-drop */
141 Gdk::Cursor* Editor::cross_hair_cursor = 0;
142 Gdk::Cursor* Editor::selector_cursor = 0;
143 Gdk::Cursor* Editor::trimmer_cursor = 0;
144 Gdk::Cursor* Editor::grabber_cursor = 0;
145 Gdk::Cursor* Editor::zoom_cursor = 0;
146 Gdk::Cursor* Editor::time_fx_cursor = 0;
147 Gdk::Cursor* Editor::fader_cursor = 0;
148 Gdk::Cursor* Editor::speaker_cursor = 0;
149 Gdk::Cursor* Editor::wait_cursor = 0;
150 Gdk::Cursor* Editor::timebar_cursor = 0;
153 show_me_the_size (Requisition* r, const char* what)
155 cerr << "size of " << what << " = " << r->width << " x " << r->height << endl;
159 check_adjustment (Gtk::Adjustment* adj)
161 cerr << "CHANGE adj = "
162 << adj->get_lower () << ' '
163 << adj->get_upper () << ' '
164 << adj->get_value () << ' '
165 << adj->get_step_increment () << ' '
166 << adj->get_page_increment () << ' '
167 << adj->get_page_size () << ' '
174 /* time display buttons */
176 minsec_label (_("Mins:Secs")),
177 bbt_label (_("Bars:Beats")),
178 smpte_label (_("Timecode")),
179 frame_label (_("Frames")),
180 tempo_label (_("Tempo")),
181 meter_label (_("Meter")),
182 mark_label (_("Location Markers")),
183 range_mark_label (_("Range Markers")),
184 transport_mark_label (_("Loop/Punch Ranges")),
186 edit_packer (3, 3, false),
188 /* the values here don't matter: layout widgets
189 reset them as needed.
192 vertical_adjustment (0.0, 0.0, 10.0, 400.0),
193 horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
195 /* tool bar related */
197 edit_cursor_clock (X_("editcursor"), false, X_("EditCursorClock"), true),
198 zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
200 toolbar_selection_clock_table (2,3),
202 automation_mode_button (_("mode")),
203 global_automation_button (_("automation")),
205 /* <CMT Additions> */
206 image_socket_listener(0),
207 /* </CMT Additions> */
211 nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true)
216 /* we are a singleton */
218 PublicEditor::_instance = this;
222 selection = new Selection;
223 cut_buffer = new Selection;
225 selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
226 selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
227 selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
228 selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
230 clicked_regionview = 0;
231 clicked_trackview = 0;
232 clicked_audio_trackview = 0;
233 clicked_crossfadeview = 0;
234 clicked_control_point = 0;
235 latest_regionview = 0;
236 last_update_frame = 0;
238 current_mixer_strip = 0;
239 current_bbt_points = 0;
241 snap_type_strings = I18N (_snap_type_strings);
242 snap_mode_strings = I18N (_snap_mode_strings);
243 zoom_focus_strings = I18N(_zoom_focus_strings);
245 snap_type = SnapToFrame;
246 set_snap_to (snap_type);
247 snap_mode = SnapNormal;
248 set_snap_mode (snap_mode);
249 snap_threshold = 5.0;
250 bbt_beat_subdivision = 4;
253 autoscroll_active = false;
254 autoscroll_timeout_tag = -1;
255 interthread_progress_window = 0;
261 current_interthread_info = 0;
262 _show_measures = true;
263 _show_waveforms = true;
264 _show_waveforms_recording = true;
265 first_action_message = 0;
267 show_gain_after_trim = false;
268 ignore_route_list_reorder = false;
269 no_route_list_redisplay = false;
270 verbose_cursor_on = true;
271 route_removal = false;
273 show_automatic_regions_in_region_list = true;
274 region_list_sort_type = (Editing::RegionListSortType) 0;
275 have_pending_keyboard_selection = false;
276 _follow_playhead = true;
277 _xfade_visibility = true;
278 editor_ruler_menu = 0;
279 no_ruler_shown_update = false;
280 edit_group_list_menu = 0;
282 region_list_menu = 0;
284 start_end_marker_menu = 0;
285 range_marker_menu = 0;
286 marker_menu_item = 0;
288 transport_marker_menu = 0;
289 new_transport_marker_menu = 0;
290 editor_mixer_strip_width = Wide;
291 show_editor_mixer_when_tracks_arrive = false;
292 region_edit_menu_split_item = 0;
294 region_edit_menu_split_multichannel_item = 0;
296 ignore_mouse_mode_toggle = false;
297 current_stepping_trackview = 0;
299 entered_regionview = 0;
300 clear_entered_track = false;
301 _new_regionviews_show_envelope = false;
302 current_timestretch = 0;
303 in_edit_group_row_change = false;
304 last_canvas_frame = 0;
307 button_release_can_deselect = true;
308 canvas_idle_queued = false;
309 _dragging_playhead = false;
310 _dragging_hscrollbar = false;
312 location_marker_color = color_map[cLocationMarker];
313 location_range_color = color_map[cLocationRange];
314 location_cd_marker_color = color_map[cLocationCDMarker];
315 location_loop_color = color_map[cLocationLoop];
316 location_punch_color = color_map[cLocationPunch];
318 range_marker_drag_rect = 0;
319 marker_drag_line = 0;
321 set_mouse_mode (MouseObject, true);
323 frames_per_unit = 2048; /* too early to use reset_zoom () */
324 reset_hscrollbar_stepping ();
326 zoom_focus = ZoomFocusLeft;
327 set_zoom_focus (ZoomFocusLeft);
328 zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
330 initialize_rulers ();
331 initialize_canvas ();
333 edit_controls_vbox.set_spacing (0);
334 horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::canvas_horizontally_scrolled));
335 vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling));
337 track_canvas.set_hadjustment (horizontal_adjustment);
338 track_canvas.set_vadjustment (vertical_adjustment);
339 time_canvas.set_hadjustment (horizontal_adjustment);
341 track_canvas.signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
342 time_canvas.signal_map_event().connect (mem_fun (*this, &Editor::time_canvas_map_handler));
344 controls_layout.add (edit_controls_vbox);
345 controls_layout.set_name ("EditControlsBase");
346 controls_layout.add_events (Gdk::SCROLL_MASK);
347 controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
349 controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
350 controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
351 controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
353 edit_vscrollbar.set_adjustment (vertical_adjustment);
354 edit_hscrollbar.set_adjustment (horizontal_adjustment);
356 edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
357 edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
358 edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
360 edit_hscrollbar.set_name ("EditorHScrollbar");
365 edit_cursor_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_cursor_clock_changed));
367 time_canvas_vbox.pack_start (*minsec_ruler, false, false);
368 time_canvas_vbox.pack_start (*smpte_ruler, false, false);
369 time_canvas_vbox.pack_start (*frames_ruler, false, false);
370 time_canvas_vbox.pack_start (*bbt_ruler, false, false);
371 time_canvas_vbox.pack_start (time_canvas, true, true);
372 time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars));
374 bbt_label.set_name ("EditorTimeButton");
375 bbt_label.set_size_request (-1, (int)timebar_height);
376 bbt_label.set_alignment (1.0, 0.5);
377 bbt_label.set_padding (5,0);
378 minsec_label.set_name ("EditorTimeButton");
379 minsec_label.set_size_request (-1, (int)timebar_height);
380 minsec_label.set_alignment (1.0, 0.5);
381 minsec_label.set_padding (5,0);
382 smpte_label.set_name ("EditorTimeButton");
383 smpte_label.set_size_request (-1, (int)timebar_height);
384 smpte_label.set_alignment (1.0, 0.5);
385 smpte_label.set_padding (5,0);
386 frame_label.set_name ("EditorTimeButton");
387 frame_label.set_size_request (-1, (int)timebar_height);
388 frame_label.set_alignment (1.0, 0.5);
389 frame_label.set_padding (5,0);
390 tempo_label.set_name ("EditorTimeButton");
391 tempo_label.set_size_request (-1, (int)timebar_height);
392 tempo_label.set_alignment (1.0, 0.5);
393 tempo_label.set_padding (5,0);
394 meter_label.set_name ("EditorTimeButton");
395 meter_label.set_size_request (-1, (int)timebar_height);
396 meter_label.set_alignment (1.0, 0.5);
397 meter_label.set_padding (5,0);
398 mark_label.set_name ("EditorTimeButton");
399 mark_label.set_size_request (-1, (int)timebar_height);
400 mark_label.set_alignment (1.0, 0.5);
401 mark_label.set_padding (5,0);
402 range_mark_label.set_name ("EditorTimeButton");
403 range_mark_label.set_size_request (-1, (int)timebar_height);
404 range_mark_label.set_alignment (1.0, 0.5);
405 range_mark_label.set_padding (5,0);
406 transport_mark_label.set_name ("EditorTimeButton");
407 transport_mark_label.set_size_request (-1, (int)timebar_height);
408 transport_mark_label.set_alignment (1.0, 0.5);
409 transport_mark_label.set_padding (5,0);
411 time_button_vbox.pack_start (minsec_label, false, false);
412 time_button_vbox.pack_start (smpte_label, false, false);
413 time_button_vbox.pack_start (frame_label, false, false);
414 time_button_vbox.pack_start (bbt_label, false, false);
415 time_button_vbox.pack_start (meter_label, false, false);
416 time_button_vbox.pack_start (tempo_label, false, false);
417 time_button_vbox.pack_start (mark_label, false, false);
419 time_button_event_box.add (time_button_vbox);
421 time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
422 time_button_event_box.set_name ("TimebarLabelBase");
423 time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
425 /* these enable us to have a dedicated window (for cursor setting, etc.)
426 for the canvas areas.
429 track_canvas_event_box.add (track_canvas);
431 time_canvas_event_box.add (time_canvas_vbox);
432 time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
434 edit_packer.set_col_spacings (0);
435 edit_packer.set_row_spacings (0);
436 edit_packer.set_homogeneous (false);
437 edit_packer.set_border_width (0);
438 edit_packer.set_name ("EditorWindow");
440 edit_packer.attach (edit_vscrollbar, 0, 1, 1, 3, FILL, FILL|EXPAND, 0, 0);
442 edit_packer.attach (time_button_event_box, 1, 2, 0, 1, FILL, FILL, 0, 0);
443 edit_packer.attach (time_canvas_event_box, 2, 3, 0, 1, FILL|EXPAND, FILL, 0, 0);
445 edit_packer.attach (controls_layout, 1, 2, 1, 2, FILL, FILL|EXPAND, 0, 0);
446 edit_packer.attach (track_canvas_event_box, 2, 3, 1, 2, FILL|EXPAND, FILL|EXPAND, 0, 0);
448 edit_packer.attach (zoom_box, 1, 2, 2, 3, FILL, FILL, 0, 0);
449 edit_packer.attach (edit_hscrollbar, 2, 3, 2, 3, FILL|EXPAND, FILL, 0, 0);
451 bottom_hbox.set_border_width (2);
452 bottom_hbox.set_spacing (3);
454 route_display_model = ListStore::create(route_display_columns);
455 route_list_display.set_model (route_display_model);
456 route_list_display.append_column (_("Show"), route_display_columns.visible);
457 route_list_display.append_column (_("Name"), route_display_columns.text);
458 route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
459 route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
460 route_list_display.set_headers_visible (true);
461 route_list_display.set_name ("TrackListDisplay");
462 route_list_display.get_selection()->set_mode (SELECTION_NONE);
463 route_list_display.set_reorderable (true);
464 route_list_display.set_size_request (100,-1);
466 CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
467 route_list_visible_cell->property_activatable() = true;
468 route_list_visible_cell->property_radio() = false;
470 route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
471 route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
473 route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
475 route_list_scroller.add (route_list_display);
476 route_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
478 group_model = ListStore::create(group_columns);
479 edit_group_display.set_model (group_model);
480 edit_group_display.append_column (_("Name"), group_columns.text);
481 edit_group_display.append_column (_("Active"), group_columns.is_active);
482 edit_group_display.append_column (_("Show"), group_columns.is_visible);
483 edit_group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
484 edit_group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
485 edit_group_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
486 edit_group_display.get_column (0)->set_expand (true);
487 edit_group_display.get_column (1)->set_expand (false);
488 edit_group_display.get_column (2)->set_expand (false);
489 edit_group_display.set_headers_visible (true);
491 /* name is directly editable */
493 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
494 name_cell->property_editable() = true;
495 name_cell->signal_edited().connect (mem_fun (*this, &Editor::edit_group_name_edit));
497 /* use checkbox for the active + visible columns */
499 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
500 active_cell->property_activatable() = true;
501 active_cell->property_radio() = false;
503 active_cell = dynamic_cast<CellRendererToggle*>(edit_group_display.get_column_cell_renderer (1));
504 active_cell->property_activatable() = true;
505 active_cell->property_radio() = false;
507 group_model->signal_row_changed().connect (mem_fun (*this, &Editor::edit_group_row_change));
509 edit_group_display.set_name ("EditGroupList");
510 edit_group_display.get_selection()->set_mode (SELECTION_SINGLE);
511 edit_group_display.set_headers_visible (false);
512 edit_group_display.set_reorderable (false);
513 edit_group_display.set_rules_hint (true);
514 edit_group_display.set_size_request (75, -1);
516 edit_group_display_scroller.add (edit_group_display);
517 edit_group_display_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
519 edit_group_display.signal_button_press_event().connect (mem_fun(*this, &Editor::edit_group_list_button_press_event), false);
521 VBox* edit_group_display_packer = manage (new VBox());
522 HBox* edit_group_display_button_box = manage (new HBox());
523 edit_group_display_button_box->set_homogeneous (true);
525 Button* edit_group_add_button = manage (new Button ());
526 Button* edit_group_remove_button = manage (new Button ());
530 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
532 edit_group_add_button->add (*w);
534 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
536 edit_group_remove_button->add (*w);
538 edit_group_add_button->signal_clicked().connect (mem_fun (*this, &Editor::new_edit_group));
539 edit_group_remove_button->signal_clicked().connect (mem_fun (*this, &Editor::remove_selected_edit_group));
541 edit_group_display_button_box->pack_start (*edit_group_add_button);
542 edit_group_display_button_box->pack_start (*edit_group_remove_button);
544 edit_group_display_packer->pack_start (edit_group_display_scroller, true, true);
545 edit_group_display_packer->pack_start (*edit_group_display_button_box, false, false);
547 region_list_display.set_size_request (100, -1);
548 region_list_display.set_name ("RegionListDisplay");
550 region_list_model = TreeStore::create (region_list_columns);
551 region_list_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
552 region_list_model->set_sort_column (0, SORT_ASCENDING);
554 region_list_display.set_model (region_list_model);
555 region_list_display.append_column (_("Regions"), region_list_columns.name);
556 region_list_display.set_headers_visible (false);
558 region_list_display.get_selection()->set_select_function (mem_fun (*this, &Editor::region_list_selection_filter));
560 TreeViewColumn* tv_col = region_list_display.get_column(0);
561 CellRendererText* renderer = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
562 tv_col->add_attribute(renderer->property_text(), region_list_columns.name);
563 tv_col->add_attribute(renderer->property_foreground_gdk(), region_list_columns.color_);
565 region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
566 region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
568 /* setup DnD handling */
570 list<TargetEntry> region_list_target_table;
572 region_list_target_table.push_back (TargetEntry ("text/plain"));
573 region_list_target_table.push_back (TargetEntry ("text/uri-list"));
574 region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
576 region_list_display.add_drop_targets (region_list_target_table);
577 region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
579 region_list_scroller.add (region_list_display);
580 region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
582 region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
583 region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
584 region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
585 region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
586 region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
587 // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
589 named_selection_scroller.add (named_selection_display);
590 named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
592 named_selection_model = TreeStore::create (named_selection_columns);
593 named_selection_display.set_model (named_selection_model);
594 named_selection_display.append_column (_("Chunks"), named_selection_columns.text);
595 named_selection_display.set_headers_visible (false);
596 named_selection_display.set_size_request (100, -1);
597 named_selection_display.set_name ("NamedSelectionDisplay");
599 named_selection_display.get_selection()->set_mode (SELECTION_SINGLE);
600 named_selection_display.set_size_request (100, -1);
601 named_selection_display.signal_button_release_event().connect (mem_fun(*this, &Editor::named_selection_display_button_release), false);
602 named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
603 named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
607 snapshot_display_model = ListStore::create (snapshot_display_columns);
608 snapshot_display.set_model (snapshot_display_model);
609 snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
610 snapshot_display.set_name ("SnapshotDisplay");
611 snapshot_display.set_size_request (75, -1);
612 snapshot_display.set_headers_visible (false);
613 snapshot_display.set_reorderable (false);
614 snapshot_display_scroller.add (snapshot_display);
615 snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
617 snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
618 snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
622 nlabel = manage (new Label (_("Regions")));
623 nlabel->set_angle (-90);
624 the_notebook.append_page (region_list_scroller, *nlabel);
625 nlabel = manage (new Label (_("Tracks/Busses")));
626 nlabel->set_angle (-90);
627 the_notebook.append_page (route_list_scroller, *nlabel);
628 nlabel = manage (new Label (_("Snapshots")));
629 nlabel->set_angle (-90);
630 the_notebook.append_page (snapshot_display_scroller, *nlabel);
631 nlabel = manage (new Label (_("Edit Groups")));
632 nlabel->set_angle (-90);
633 the_notebook.append_page (*edit_group_display_packer, *nlabel);
634 nlabel = manage (new Label (_("Chunks")));
635 nlabel->set_angle (-90);
636 the_notebook.append_page (named_selection_scroller, *nlabel);
638 the_notebook.set_show_tabs (true);
639 the_notebook.set_scrollable (true);
640 the_notebook.popup_enable ();
641 the_notebook.set_tab_pos (Gtk::POS_RIGHT);
643 post_maximal_editor_width = 0;
644 post_maximal_pane_position = 0;
645 edit_pane.pack1 (edit_packer, true, true);
646 edit_pane.pack2 (the_notebook, false, true);
648 edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
650 top_hbox.pack_start (toolbar_frame, true, true);
652 HBox *hbox = manage (new HBox);
653 hbox->pack_start (edit_pane, true, true);
655 global_vpacker.pack_start (top_hbox, false, false);
656 global_vpacker.pack_start (*hbox, true, true);
658 global_hpacker.pack_start (global_vpacker, true, true);
660 set_name ("EditorWindow");
661 add_accel_group (ActionManager::ui_manager->get_accel_group());
663 vpacker.pack_end (global_hpacker, true, true);
665 /* register actions now so that set_state() can find them and set toggles/checks etc */
669 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
672 _playlist_selector = new PlaylistSelector();
673 _playlist_selector->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (_playlist_selector)));
675 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &Editor::catch_vanishing_regionview));
679 nudge_forward_button.add (*(manage (new Image (::get_icon("nudge_right")))));
680 nudge_backward_button.add (*(manage (new Image (::get_icon("nudge_left")))));
682 ARDOUR_UI::instance()->tooltips().set_tip (nudge_forward_button, _("Nudge Region/Selection Forwards"));
683 ARDOUR_UI::instance()->tooltips().set_tip (nudge_backward_button, _("Nudge Region/Selection Backwards"));
685 nudge_forward_button.set_name ("TransportButton");
686 nudge_backward_button.set_name ("TransportButton");
688 fade_context_menu.set_name ("ArdourContextMenu");
690 /* icons, titles, WM stuff */
692 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
693 Glib::RefPtr<Gdk::Pixbuf> icon;
695 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
696 window_icons.push_back (icon);
698 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
699 window_icons.push_back (icon);
701 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
702 window_icons.push_back (icon);
704 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
705 window_icons.push_back (icon);
707 if (!window_icons.empty()) {
708 set_icon_list (window_icons);
709 set_default_icon_list (window_icons);
711 set_title (_("ardour: editor"));
712 set_wmclass (X_("ardour_editor"), "Ardour");
715 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
717 signal_configure_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
718 signal_delete_event().connect (mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
720 /* allow external control surfaces/protocols to do various things */
722 ControlProtocol::ZoomToSession.connect (mem_fun (*this, &Editor::temporal_zoom_session));
723 ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
724 ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
725 ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
727 Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
735 /* <CMT Additions> */
736 if(image_socket_listener)
738 if(image_socket_listener->is_connected())
740 image_socket_listener->close_connection() ;
743 delete image_socket_listener ;
744 image_socket_listener = 0 ;
746 /* </CMT Additions> */
750 Editor::add_toplevel_controls (Container& cont)
752 vpacker.pack_start (cont, false, false);
757 Editor::catch_vanishing_regionview (RegionView *rv)
759 /* note: the selection will take care of the vanishing
760 audioregionview by itself.
763 if (clicked_regionview == rv) {
764 clicked_regionview = 0;
767 if (entered_regionview == rv) {
768 set_entered_regionview (0);
773 Editor::set_entered_regionview (RegionView* rv)
775 if (rv == entered_regionview) {
779 if (entered_regionview) {
780 entered_regionview->exited ();
783 if ((entered_regionview = rv) != 0) {
784 entered_regionview->entered ();
789 Editor::set_entered_track (TimeAxisView* tav)
792 entered_track->exited ();
795 if ((entered_track = tav) != 0) {
796 entered_track->entered ();
801 Editor::show_window ()
806 /* now reset all audio_time_axis heights, because widgets might need
812 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
813 tv = (static_cast<TimeAxisView*>(*i));
819 Editor::tie_vertical_scrolling ()
821 double y1 = vertical_adjustment.get_value();
822 controls_layout.get_vadjustment()->set_value (y1);
823 playhead_cursor->set_y_axis(y1);
824 edit_cursor->set_y_axis(y1);
828 Editor::instant_save ()
830 if (!constructed || !ARDOUR_UI::instance()->session_loaded) {
835 session->add_instant_xml(get_state(), session->path());
837 Config->add_instant_xml(get_state(), get_user_ardour_path());
842 Editor::edit_cursor_clock_changed()
844 if (edit_cursor->current_frame != edit_cursor_clock.current_time()) {
845 edit_cursor->set_position (edit_cursor_clock.current_time());
851 Editor::zoom_adjustment_changed ()
857 double fpu = zoom_range_clock.current_duration() / canvas_width;
861 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
862 } else if (fpu > session->current_end_frame() / canvas_width) {
863 fpu = session->current_end_frame() / canvas_width;
864 zoom_range_clock.set ((nframes_t) floor (fpu * canvas_width));
871 Editor::control_scroll (float fraction)
873 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::control_scroll), fraction));
879 double step = fraction * current_page_frames();
882 if ((fraction < 0.0f) && (session->transport_frame() < (nframes_t) fabs(step))) {
884 } else if ((fraction > 0.0f) && (max_frames - session->transport_frame() < step)) {
885 target = (max_frames - (current_page_frames()*2)); // allow room for slop in where the PH is on the screen
887 target = (session->transport_frame() + (nframes_t) floor ((fraction * current_page_frames())));
890 /* move visuals, we'll catch up with it later */
892 playhead_cursor->set_position (target);
894 if (target > (current_page_frames() / 2)) {
895 /* try to center PH in window */
896 reset_x_origin (target - (current_page_frames()/2));
901 /* cancel the existing */
903 control_scroll_connection.disconnect ();
905 /* add the next one */
907 control_scroll_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::deferred_control_scroll), target), 50);
911 Editor::deferred_control_scroll (nframes_t target)
913 session->request_locate (target);
918 Editor::on_realize ()
920 Window::on_realize ();
925 Editor::start_scrolling ()
927 scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect
928 (mem_fun(*this, &Editor::update_current_screen));
932 Editor::stop_scrolling ()
934 scroll_connection.disconnect ();
938 Editor::map_position_change (nframes_t frame)
940 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
942 if (session == 0 || !_follow_playhead) {
946 center_screen (frame);
947 playhead_cursor->set_position (frame);
951 Editor::center_screen (nframes_t frame)
953 double page = canvas_width * frames_per_unit;
955 /* if we're off the page, then scroll.
958 if (frame < leftmost_frame || frame >= leftmost_frame + page) {
959 center_screen_internal (frame, page);
964 Editor::center_screen_internal (nframes_t frame, float page)
969 frame -= (nframes_t) page;
974 reset_x_origin (frame);
978 Editor::handle_new_duration ()
980 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
982 nframes_t new_end = session->get_maximum_extent() + (nframes_t) floorf (current_page_frames() * 0.10f);
984 if (new_end > last_canvas_frame) {
985 last_canvas_frame = new_end;
986 horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
987 reset_scrolling_region ();
990 horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
994 Editor::update_title_s (const string & snap_name)
996 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::update_title_s), snap_name));
1002 Editor::update_title ()
1004 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_title));
1007 bool dirty = session->dirty();
1009 string wintitle = _("ardour: editor: ");
1015 wintitle += session->name();
1017 if (session->snap_name() != session->name()) {
1019 wintitle += session->snap_name();
1026 set_title (wintitle);
1031 Editor::connect_to_session (Session *t)
1035 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
1038 /* catch up with the playhead */
1040 session->request_locate (playhead_cursor->current_frame);
1042 if (first_action_message) {
1043 first_action_message->hide();
1048 session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
1049 session->history().Changed.connect (mem_fun (*this, &Editor::history_changed));
1051 /* These signals can all be emitted by a non-GUI thread. Therefore the
1052 handlers for them must not attempt to directly interact with the GUI,
1053 but use Gtkmm2ext::UI::instance()->call_slot();
1056 session_connections.push_back (session->TransportStateChange.connect (mem_fun(*this, &Editor::map_transport_state)));
1057 session_connections.push_back (session->PositionChanged.connect (mem_fun(*this, &Editor::map_position_change)));
1058 session_connections.push_back (session->RouteAdded.connect (mem_fun(*this, &Editor::handle_new_route)));
1059 session_connections.push_back (session->AudioRegionAdded.connect (mem_fun(*this, &Editor::handle_new_audio_region)));
1060 session_connections.push_back (session->AudioRegionRemoved.connect (mem_fun(*this, &Editor::handle_audio_region_removed)));
1061 session_connections.push_back (session->DurationChanged.connect (mem_fun(*this, &Editor::handle_new_duration)));
1062 session_connections.push_back (session->edit_group_added.connect (mem_fun(*this, &Editor::add_edit_group)));
1063 session_connections.push_back (session->edit_group_removed.connect (mem_fun(*this, &Editor::edit_groups_changed)));
1064 session_connections.push_back (session->NamedSelectionAdded.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1065 session_connections.push_back (session->NamedSelectionRemoved.connect (mem_fun(*this, &Editor::handle_new_named_selection)));
1066 session_connections.push_back (session->DirtyChanged.connect (mem_fun(*this, &Editor::update_title)));
1067 session_connections.push_back (session->StateSaved.connect (mem_fun(*this, &Editor::update_title_s)));
1068 session_connections.push_back (session->AskAboutPlaylistDeletion.connect (mem_fun(*this, &Editor::playlist_deletion_dialog)));
1069 session_connections.push_back (session->RegionHiddenChange.connect (mem_fun(*this, &Editor::region_hidden)));
1071 session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
1073 session_connections.push_back (session->tempo_map().StateChanged.connect (bind (mem_fun(*this, &Editor::tempo_map_changed), false)));
1075 edit_groups_changed ();
1077 edit_cursor_clock.set_session (session);
1078 zoom_range_clock.set_session (session);
1079 _playlist_selector->set_session (session);
1080 nudge_clock.set_session (session);
1083 if (analysis_window != 0)
1084 analysis_window->set_session (session);
1087 Location* loc = session->locations()->auto_loop_location();
1089 loc = new Location (0, session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
1090 if (loc->start() == loc->end()) {
1091 loc->set_end (loc->start() + 1);
1093 session->locations()->add (loc, false);
1094 session->set_auto_loop_location (loc);
1097 loc->set_name (_("Loop"));
1100 loc = session->locations()->auto_punch_location();
1102 loc = new Location (0, session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
1103 if (loc->start() == loc->end()) {
1104 loc->set_end (loc->start() + 1);
1106 session->locations()->add (loc, false);
1107 session->set_auto_punch_location (loc);
1110 loc->set_name (_("Punch"));
1113 Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
1115 session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
1117 refresh_location_display ();
1118 session->locations()->added.connect (mem_fun(*this, &Editor::add_new_location));
1119 session->locations()->removed.connect (mem_fun(*this, &Editor::location_gone));
1120 session->locations()->changed.connect (mem_fun(*this, &Editor::refresh_location_display));
1121 session->locations()->StateChanged.connect (mem_fun(*this, &Editor::refresh_location_display_s));
1122 session->locations()->end_location()->changed.connect (mem_fun(*this, &Editor::end_location_changed));
1124 handle_new_duration ();
1126 redisplay_regions ();
1127 redisplay_named_selections ();
1128 redisplay_snapshots ();
1130 initial_route_list_display ();
1132 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1133 (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
1136 restore_ruler_visibility ();
1137 //tempo_map_changed (Change (0));
1138 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
1142 /* don't show master bus in a new session */
1144 if (ARDOUR_UI::instance()->session_is_new ()) {
1146 TreeModel::Children rows = route_display_model->children();
1147 TreeModel::Children::iterator i;
1149 no_route_list_redisplay = true;
1151 for (i = rows.begin(); i != rows.end(); ++i) {
1152 TimeAxisView *tv = (*i)[route_display_columns.tv];
1153 AudioTimeAxisView *atv;
1155 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1156 if (atv->route()->master()) {
1157 route_list_display.get_selection()->unselect (i);
1162 no_route_list_redisplay = false;
1163 redisplay_route_list ();
1166 /* register for undo history */
1168 session->register_with_memento_command_factory(_id, this);
1172 Editor::build_cursors ()
1174 using namespace Gdk;
1176 Gdk::Color mbg ("#000000" ); /* Black */
1177 Gdk::Color mfg ("#0000ff" ); /* Blue. */
1180 RefPtr<Bitmap> source, mask;
1181 source = Bitmap::create (mag_bits, mag_width, mag_height);
1182 mask = Bitmap::create (magmask_bits, mag_width, mag_height);
1183 zoom_cursor = new Gdk::Cursor (source, mask, mfg, mbg, mag_x_hot, mag_y_hot);
1186 Gdk::Color fbg ("#ffffff" );
1187 Gdk::Color ffg ("#000000" );
1190 RefPtr<Bitmap> source, mask;
1192 source = Bitmap::create (fader_cursor_bits, fader_cursor_width, fader_cursor_height);
1193 mask = Bitmap::create (fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
1194 fader_cursor = new Gdk::Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
1198 RefPtr<Bitmap> source, mask;
1199 source = Bitmap::create (speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
1200 mask = Bitmap::create (speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
1201 speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
1204 grabber_cursor = new Gdk::Cursor (HAND2);
1205 cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
1206 trimmer_cursor = new Gdk::Cursor (SB_H_DOUBLE_ARROW);
1207 selector_cursor = new Gdk::Cursor (XTERM);
1208 time_fx_cursor = new Gdk::Cursor (SIZING);
1209 wait_cursor = new Gdk::Cursor (WATCH);
1210 timebar_cursor = new Gdk::Cursor(LEFT_PTR);
1214 Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* item, ItemType item_type)
1216 using namespace Menu_Helpers;
1217 AudioRegionView* arv = static_cast<AudioRegionView*> (item->get_data ("regionview"));
1220 fatal << _("programming error: fade in canvas item has no regionview data pointer!") << endmsg;
1224 MenuList& items (fade_context_menu.items());
1228 switch (item_type) {
1230 case FadeInHandleItem:
1231 if (arv->audio_region()->fade_in_active()) {
1232 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_in_active), false)));
1234 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_in_active), true)));
1237 items.push_back (SeparatorElem());
1239 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Linear)));
1240 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Fast)));
1241 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogB)));
1242 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::LogA)));
1243 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_in_shape), AudioRegion::Slow)));
1247 case FadeOutHandleItem:
1248 if (arv->audio_region()->fade_out_active()) {
1249 items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*this, &Editor::set_fade_out_active), false)));
1251 items.push_back (MenuElem (_("Activate"), bind (mem_fun (*this, &Editor::set_fade_out_active), true)));
1254 items.push_back (SeparatorElem());
1256 items.push_back (MenuElem (_("Linear"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Linear)));
1257 items.push_back (MenuElem (_("Slowest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Slow)));
1258 items.push_back (MenuElem (_("Slow"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogA)));
1259 items.push_back (MenuElem (_("Fast"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::LogB)));
1260 items.push_back (MenuElem (_("Fastest"), bind (mem_fun (*this, &Editor::set_fade_out_shape), AudioRegion::Fast)));
1265 fatal << _("programming error: ")
1266 << X_("non-fade canvas item passed to popup_fade_context_menu()")
1271 fade_context_menu.popup (button, time);
1275 Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes_t frame)
1277 using namespace Menu_Helpers;
1278 Menu* (Editor::*build_menu_function)(nframes_t);
1281 switch (item_type) {
1283 case RegionViewName:
1284 case RegionViewNameHighlight:
1285 if (with_selection) {
1286 build_menu_function = &Editor::build_track_selection_context_menu;
1288 build_menu_function = &Editor::build_track_region_context_menu;
1293 if (with_selection) {
1294 build_menu_function = &Editor::build_track_selection_context_menu;
1296 build_menu_function = &Editor::build_track_context_menu;
1300 case CrossfadeViewItem:
1301 build_menu_function = &Editor::build_track_crossfade_context_menu;
1305 if (clicked_audio_trackview->get_diskstream()) {
1306 build_menu_function = &Editor::build_track_context_menu;
1308 build_menu_function = &Editor::build_track_bus_context_menu;
1313 /* probably shouldn't happen but if it does, we don't care */
1317 menu = (this->*build_menu_function)(frame);
1318 menu->set_name ("ArdourContextMenu");
1320 /* now handle specific situations */
1322 switch (item_type) {
1324 case RegionViewName:
1325 case RegionViewNameHighlight:
1326 if (!with_selection) {
1327 if (region_edit_menu_split_item) {
1328 if (clicked_regionview && clicked_regionview->region()->covers (edit_cursor->current_frame)) {
1329 ActionManager::set_sensitive (ActionManager::edit_cursor_in_region_sensitive_actions, true);
1331 ActionManager::set_sensitive (ActionManager::edit_cursor_in_region_sensitive_actions, false);
1335 if (region_edit_menu_split_multichannel_item) {
1336 if (clicked_regionview && clicked_regionview->region().n_channels() > 1) {
1337 // GTK2FIX find the action, change its sensitivity
1338 // region_edit_menu_split_multichannel_item->set_sensitive (true);
1340 // GTK2FIX see above
1341 // region_edit_menu_split_multichannel_item->set_sensitive (false);
1350 case CrossfadeViewItem:
1357 /* probably shouldn't happen but if it does, we don't care */
1361 if (clicked_audio_trackview && clicked_audio_trackview->audio_track()) {
1363 /* Bounce to disk */
1365 using namespace Menu_Helpers;
1366 MenuList& edit_items = menu->items();
1368 edit_items.push_back (SeparatorElem());
1370 switch (clicked_audio_trackview->audio_track()->freeze_state()) {
1371 case AudioTrack::NoFreeze:
1372 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1375 case AudioTrack::Frozen:
1376 edit_items.push_back (MenuElem (_("Unfreeze"), mem_fun(*this, &Editor::unfreeze_route)));
1379 case AudioTrack::UnFrozen:
1380 edit_items.push_back (MenuElem (_("Freeze"), mem_fun(*this, &Editor::freeze_route)));
1386 menu->popup (button, time);
1390 Editor::build_track_context_menu (nframes_t ignored)
1392 using namespace Menu_Helpers;
1394 MenuList& edit_items = track_context_menu.items();
1397 add_dstream_context_items (edit_items);
1398 return &track_context_menu;
1402 Editor::build_track_bus_context_menu (nframes_t ignored)
1404 using namespace Menu_Helpers;
1406 MenuList& edit_items = track_context_menu.items();
1409 add_bus_context_items (edit_items);
1410 return &track_context_menu;
1414 Editor::build_track_region_context_menu (nframes_t frame)
1416 using namespace Menu_Helpers;
1417 MenuList& edit_items = track_region_context_menu.items();
1420 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1423 boost::shared_ptr<Diskstream> ds;
1424 boost::shared_ptr<Playlist> pl;
1426 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
1427 Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)frame * ds->speed()));
1428 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1429 add_region_context_items (atv->audio_view(), (*i), edit_items);
1435 add_dstream_context_items (edit_items);
1437 return &track_region_context_menu;
1441 Editor::build_track_crossfade_context_menu (nframes_t frame)
1443 using namespace Menu_Helpers;
1444 MenuList& edit_items = track_crossfade_context_menu.items();
1445 edit_items.clear ();
1447 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_trackview);
1450 boost::shared_ptr<Diskstream> ds;
1451 boost::shared_ptr<Playlist> pl;
1452 boost::shared_ptr<AudioPlaylist> apl;
1454 if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
1456 Playlist::RegionList* regions = pl->regions_at (frame);
1457 AudioPlaylist::Crossfades xfades;
1459 apl->crossfades_at (frame, xfades);
1461 bool many = xfades.size() > 1;
1463 for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
1464 add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
1467 for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
1468 add_region_context_items (atv->audio_view(), (*i), edit_items);
1475 add_dstream_context_items (edit_items);
1477 return &track_crossfade_context_menu;
1482 Editor::analyze_region_selection()
1484 if (analysis_window == 0) {
1485 analysis_window = new AnalysisWindow();
1488 analysis_window->set_session(session);
1490 analysis_window->show_all();
1493 analysis_window->set_regionmode();
1494 analysis_window->analyze();
1496 analysis_window->present();
1500 Editor::analyze_range_selection()
1502 if (analysis_window == 0) {
1503 analysis_window = new AnalysisWindow();
1506 analysis_window->set_session(session);
1508 analysis_window->show_all();
1511 analysis_window->set_rangemode();
1512 analysis_window->analyze();
1514 analysis_window->present();
1516 #endif /* FFT_ANALYSIS */
1521 Editor::build_track_selection_context_menu (nframes_t ignored)
1523 using namespace Menu_Helpers;
1524 MenuList& edit_items = track_selection_context_menu.items();
1525 edit_items.clear ();
1527 add_selection_context_items (edit_items);
1528 add_dstream_context_items (edit_items);
1530 return &track_selection_context_menu;
1534 Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
1536 using namespace Menu_Helpers;
1537 Menu *xfade_menu = manage (new Menu);
1538 MenuList& items = xfade_menu->items();
1539 xfade_menu->set_name ("ArdourContextMenu");
1542 if (xfade->active()) {
1548 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
1549 items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
1551 if (xfade->can_follow_overlap()) {
1553 if (xfade->following_overlap()) {
1554 str = _("Convert to short");
1556 str = _("Convert to full");
1559 items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_length), xfade)));
1563 str = xfade->out()->name();
1565 str += xfade->in()->name();
1567 str = _("Crossfade");
1570 edit_items.push_back (MenuElem (str, *xfade_menu));
1571 edit_items.push_back (SeparatorElem());
1575 Editor::xfade_edit_left_region ()
1577 if (clicked_crossfadeview) {
1578 clicked_crossfadeview->left_view.show_region_editor ();
1583 Editor::xfade_edit_right_region ()
1585 if (clicked_crossfadeview) {
1586 clicked_crossfadeview->right_view.show_region_editor ();
1591 Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
1593 using namespace Menu_Helpers;
1594 Menu *region_menu = manage (new Menu);
1595 MenuList& items = region_menu->items();
1596 region_menu->set_name ("ArdourContextMenu");
1598 boost::shared_ptr<AudioRegion> ar;
1601 ar = boost::dynamic_pointer_cast<AudioRegion> (region);
1604 /* when this particular menu pops up, make the relevant region
1608 region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
1610 items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
1611 items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
1612 items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun (*this, &Editor::lower_region_to_bottom)));
1613 items.push_back (SeparatorElem());
1614 items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_cursor)));
1615 items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
1616 items.push_back (SeparatorElem());
1618 items.push_back (MenuElem (_("Audition"), mem_fun(*this, &Editor::audition_selected_region)));
1619 items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
1620 items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
1623 items.push_back (MenuElem (_("Analyze region"), mem_fun(*this, &Editor::analyze_region_selection)));
1626 items.push_back (SeparatorElem());
1628 items.push_back (CheckMenuElem (_("Lock"), mem_fun(*this, &Editor::toggle_region_lock)));
1629 region_lock_item = static_cast<CheckMenuItem*>(&items.back());
1630 if (region->locked()) {
1631 region_lock_item->set_active();
1633 items.push_back (CheckMenuElem (_("Mute"), mem_fun(*this, &Editor::toggle_region_mute)));
1634 region_mute_item = static_cast<CheckMenuItem*>(&items.back());
1635 if (region->muted()) {
1636 region_mute_item->set_active();
1638 items.push_back (CheckMenuElem (_("Opaque"), mem_fun(*this, &Editor::toggle_region_opaque)));
1639 region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
1640 if (region->opaque()) {
1641 region_opaque_item->set_active();
1644 items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
1645 if (region->at_natural_position()) {
1646 items.back().set_sensitive (false);
1649 items.push_back (SeparatorElem());
1653 RegionView* rv = sv->find_view (ar);
1654 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
1656 items.push_back (MenuElem (_("Reset Envelope"), mem_fun(*this, &Editor::reset_region_gain_envelopes)));
1658 items.push_back (CheckMenuElem (_("Envelope Visible"), mem_fun(*this, &Editor::toggle_gain_envelope_visibility)));
1659 region_envelope_visible_item = static_cast<CheckMenuItem*> (&items.back());
1661 if (arv->envelope_visible()) {
1662 region_envelope_visible_item->set_active (true);
1665 items.push_back (CheckMenuElem (_("Envelope Active"), mem_fun(*this, &Editor::toggle_gain_envelope_active)));
1666 region_envelope_active_item = static_cast<CheckMenuItem*> (&items.back());
1668 if (ar->envelope_active()) {
1669 region_envelope_active_item->set_active (true);
1672 items.push_back (SeparatorElem());
1674 if (ar->scale_amplitude() != 1.0f) {
1675 items.push_back (MenuElem (_("DeNormalize"), mem_fun(*this, &Editor::denormalize_region)));
1677 items.push_back (MenuElem (_("Normalize"), mem_fun(*this, &Editor::normalize_region)));
1680 items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
1681 items.push_back (SeparatorElem());
1684 /* range related stuff */
1686 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
1687 items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_audio_region)));
1688 items.push_back (SeparatorElem());
1692 Menu *nudge_menu = manage (new Menu());
1693 MenuList& nudge_items = nudge_menu->items();
1694 nudge_menu->set_name ("ArdourContextMenu");
1696 nudge_items.push_back (MenuElem (_("Nudge fwd"), (bind (mem_fun(*this, &Editor::nudge_forward), false))));
1697 nudge_items.push_back (MenuElem (_("Nudge bwd"), (bind (mem_fun(*this, &Editor::nudge_backward), false))));
1698 nudge_items.push_back (MenuElem (_("Nudge fwd by capture offset"), (mem_fun(*this, &Editor::nudge_forward_capture_offset))));
1699 nudge_items.push_back (MenuElem (_("Nudge bwd by capture offset"), (mem_fun(*this, &Editor::nudge_backward_capture_offset))));
1701 items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1702 items.push_back (SeparatorElem());
1704 Menu *trim_menu = manage (new Menu);
1705 MenuList& trim_items = trim_menu->items();
1706 trim_menu->set_name ("ArdourContextMenu");
1708 trim_items.push_back (MenuElem (_("Start to edit cursor"), mem_fun(*this, &Editor::trim_region_from_edit_cursor)));
1709 trim_items.push_back (MenuElem (_("Edit cursor to end"), mem_fun(*this, &Editor::trim_region_to_edit_cursor)));
1711 items.push_back (MenuElem (_("Trim"), *trim_menu));
1712 items.push_back (SeparatorElem());
1714 items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
1715 region_edit_menu_split_item = &items.back();
1717 items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
1718 region_edit_menu_split_multichannel_item = &items.back();
1720 items.push_back (MenuElem (_("Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
1721 items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
1722 items.push_back (SeparatorElem());
1723 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_clicked_region)));
1725 /* OK, stick the region submenu at the top of the list, and then add
1729 /* we have to hack up the region name because "_" has a special
1730 meaning for menu titles.
1733 string::size_type pos = 0;
1734 string menu_item_name = region->name();
1736 while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
1737 menu_item_name.replace (pos, 1, "__");
1741 edit_items.push_back (MenuElem (menu_item_name, *region_menu));
1742 edit_items.push_back (SeparatorElem());
1746 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
1748 using namespace Menu_Helpers;
1749 Menu *selection_menu = manage (new Menu);
1750 MenuList& items = selection_menu->items();
1751 selection_menu->set_name ("ArdourContextMenu");
1753 items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
1754 items.push_back (MenuElem (_("Loop range"), mem_fun(*this, &Editor::set_route_loop_selection)));
1757 items.push_back (SeparatorElem());
1758 items.push_back (MenuElem (_("Analyze range"), mem_fun(*this, &Editor::analyze_range_selection)));
1761 items.push_back (SeparatorElem());
1762 items.push_back (MenuElem (_("Separate range to track"), mem_fun(*this, &Editor::separate_region_from_selection)));
1763 items.push_back (MenuElem (_("Separate range to region list"), mem_fun(*this, &Editor::new_region_from_selection)));
1765 items.push_back (SeparatorElem());
1766 items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
1767 items.push_back (SeparatorElem());
1768 items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
1769 items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
1770 items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
1771 items.push_back (SeparatorElem());
1772 items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
1773 items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
1774 items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
1775 items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
1776 items.push_back (SeparatorElem());
1777 items.push_back (MenuElem (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection)));
1778 items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
1780 edit_items.push_back (MenuElem (_("Range"), *selection_menu));
1781 edit_items.push_back (SeparatorElem());
1785 Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
1787 using namespace Menu_Helpers;
1791 Menu *play_menu = manage (new Menu);
1792 MenuList& play_items = play_menu->items();
1793 play_menu->set_name ("ArdourContextMenu");
1795 play_items.push_back (MenuElem (_("Play from edit cursor"), mem_fun(*this, &Editor::play_from_edit_cursor)));
1796 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
1797 play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
1798 play_items.push_back (SeparatorElem());
1799 play_items.push_back (MenuElem (_("Loop Region"), mem_fun(*this, &Editor::loop_selected_region)));
1801 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1805 Menu *select_menu = manage (new Menu);
1806 MenuList& select_items = select_menu->items();
1807 select_menu->set_name ("ArdourContextMenu");
1809 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1810 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
1811 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
1812 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
1813 select_items.push_back (SeparatorElem());
1814 select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
1815 select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
1816 select_items.push_back (SeparatorElem());
1817 select_items.push_back (MenuElem (_("Select all after edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, true)));
1818 select_items.push_back (MenuElem (_("Select all before edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, false)));
1819 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1820 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1821 select_items.push_back (MenuElem (_("Select all between cursors"), bind (mem_fun(*this, &Editor::select_all_selectables_between_cursors), playhead_cursor, edit_cursor)));
1822 select_items.push_back (SeparatorElem());
1824 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1828 Menu *cutnpaste_menu = manage (new Menu);
1829 MenuList& cutnpaste_items = cutnpaste_menu->items();
1830 cutnpaste_menu->set_name ("ArdourContextMenu");
1832 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
1833 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
1834 cutnpaste_items.push_back (MenuElem (_("Paste at edit cursor"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
1835 cutnpaste_items.push_back (MenuElem (_("Paste at mouse"), mem_fun(*this, &Editor::mouse_paste)));
1837 cutnpaste_items.push_back (SeparatorElem());
1839 cutnpaste_items.push_back (MenuElem (_("Align"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint)));
1840 cutnpaste_items.push_back (MenuElem (_("Align Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint)));
1842 cutnpaste_items.push_back (SeparatorElem());
1844 cutnpaste_items.push_back (MenuElem (_("Insert chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f)));
1846 edit_items.push_back (MenuElem (_("Edit"), *cutnpaste_menu));
1848 /* Adding new material */
1850 edit_items.push_back (SeparatorElem());
1851 edit_items.push_back (MenuElem (_("Insert Selected Region"), bind (mem_fun(*this, &Editor::insert_region_list_selection), 1.0f)));
1852 edit_items.push_back (MenuElem (_("Insert Existing Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportToTrack)));
1856 Menu *nudge_menu = manage (new Menu());
1857 MenuList& nudge_items = nudge_menu->items();
1858 nudge_menu->set_name ("ArdourContextMenu");
1860 edit_items.push_back (SeparatorElem());
1861 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
1862 nudge_items.push_back (MenuElem (_("Nudge track after edit cursor fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
1863 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
1864 nudge_items.push_back (MenuElem (_("Nudge track after edit cursor bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
1866 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1870 Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
1872 using namespace Menu_Helpers;
1876 Menu *play_menu = manage (new Menu);
1877 MenuList& play_items = play_menu->items();
1878 play_menu->set_name ("ArdourContextMenu");
1880 play_items.push_back (MenuElem (_("Play from edit cursor"), mem_fun(*this, &Editor::play_from_edit_cursor)));
1881 play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
1882 edit_items.push_back (MenuElem (_("Play"), *play_menu));
1886 Menu *select_menu = manage (new Menu);
1887 MenuList& select_items = select_menu->items();
1888 select_menu->set_name ("ArdourContextMenu");
1890 select_items.push_back (MenuElem (_("Select All in track"), bind (mem_fun(*this, &Editor::select_all_in_track), Selection::Set)));
1891 select_items.push_back (MenuElem (_("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set)));
1892 select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
1893 select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
1894 select_items.push_back (SeparatorElem());
1895 select_items.push_back (MenuElem (_("Select all after edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, true)));
1896 select_items.push_back (MenuElem (_("Select all before edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, false)));
1897 select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
1898 select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
1900 edit_items.push_back (MenuElem (_("Select"), *select_menu));
1904 Menu *cutnpaste_menu = manage (new Menu);
1905 MenuList& cutnpaste_items = cutnpaste_menu->items();
1906 cutnpaste_menu->set_name ("ArdourContextMenu");
1908 cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
1909 cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
1910 cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
1912 Menu *nudge_menu = manage (new Menu());
1913 MenuList& nudge_items = nudge_menu->items();
1914 nudge_menu->set_name ("ArdourContextMenu");
1916 edit_items.push_back (SeparatorElem());
1917 nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
1918 nudge_items.push_back (MenuElem (_("Nudge track after edit cursor fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
1919 nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
1920 nudge_items.push_back (MenuElem (_("Nudge track after edit cursor bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
1922 edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
1925 /* CURSOR SETTING AND MARKS AND STUFF */
1928 Editor::set_snap_to (SnapType st)
1931 string str = snap_type_strings[(int) st];
1933 if (str != snap_type_selector.get_active_text()) {
1934 snap_type_selector.set_active_text (str);
1939 switch (snap_type) {
1940 case SnapToAThirtysecondBeat:
1941 case SnapToASixteenthBeat:
1942 case SnapToAEighthBeat:
1943 case SnapToAQuarterBeat:
1944 case SnapToAThirdBeat:
1945 update_tempo_based_rulers ();
1953 Editor::set_snap_mode (SnapMode mode)
1956 string str = snap_mode_strings[(int)mode];
1958 if (str != snap_mode_selector.get_active_text ()) {
1959 snap_mode_selector.set_active_text (str);
1966 Editor::set_state (const XMLNode& node)
1968 const XMLProperty* prop;
1970 int x, y, xoff, yoff;
1973 if ((prop = node.property ("id")) != 0) {
1974 _id = prop->value ();
1977 if ((geometry = find_named_node (node, "geometry")) == 0) {
1979 g.base_width = default_width;
1980 g.base_height = default_height;
1988 g.base_width = atoi(geometry->property("x_size")->value());
1989 g.base_height = atoi(geometry->property("y_size")->value());
1990 x = atoi(geometry->property("x_pos")->value());
1991 y = atoi(geometry->property("y_pos")->value());
1992 xoff = atoi(geometry->property("x_off")->value());
1993 yoff = atoi(geometry->property("y_off")->value());
1996 set_default_size (g.base_width, g.base_height);
1999 if (session && (prop = node.property ("playhead"))) {
2000 nframes_t pos = atol (prop->value().c_str());
2001 playhead_cursor->set_position (pos);
2003 playhead_cursor->set_position (0);
2005 /* reset_x_origin() doesn't work right here, since the old
2006 position may be zero already, and it does nothing in such
2011 horizontal_adjustment.set_value (0);
2014 if (session && (prop = node.property ("edit-cursor"))) {
2015 nframes_t pos = atol (prop->value().c_str());
2016 edit_cursor->set_position (pos);
2018 edit_cursor->set_position (0);
2021 if ((prop = node.property ("zoom-focus"))) {
2022 set_zoom_focus ((ZoomFocus) atoi (prop->value()));
2025 if ((prop = node.property ("zoom"))) {
2026 reset_zoom (PBD::atof (prop->value()));
2029 if ((prop = node.property ("snap-to"))) {
2030 set_snap_to ((SnapType) atoi (prop->value()));
2033 if ((prop = node.property ("snap-mode"))) {
2034 set_snap_mode ((SnapMode) atoi (prop->value()));
2037 if ((prop = node.property ("mouse-mode"))) {
2038 MouseMode m = str2mousemode(prop->value());
2039 mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
2040 set_mouse_mode (m, true);
2042 mouse_mode = MouseGain; /* lie, to force the mode switch */
2043 set_mouse_mode (MouseObject, true);
2046 if ((prop = node.property ("show-waveforms"))) {
2047 bool yn = (prop->value() == "yes");
2048 _show_waveforms = !yn;
2049 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformVisibility"));
2051 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2052 /* do it twice to force the change */
2053 tact->set_active (!yn);
2054 tact->set_active (yn);
2058 if ((prop = node.property ("show-waveforms-recording"))) {
2059 bool yn = (prop->value() == "yes");
2060 _show_waveforms_recording = !yn;
2061 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
2063 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2064 /* do it twice to force the change */
2065 tact->set_active (!yn);
2066 tact->set_active (yn);
2070 if ((prop = node.property ("show-measures"))) {
2071 bool yn = (prop->value() == "yes");
2072 _show_measures = !yn;
2073 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
2075 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2076 /* do it twice to force the change */
2077 tact->set_active (!yn);
2078 tact->set_active (yn);
2082 if ((prop = node.property ("follow-playhead"))) {
2083 bool yn = (prop->value() == "yes");
2084 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
2086 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
2087 /* do it twice to force the change */
2088 tact->set_active (!yn);
2089 tact->set_active (yn);
2094 if ((prop = node.property ("region-list-sort-type"))) {
2095 region_list_sort_type = (Editing::RegionListSortType) -1; // force change
2096 reset_region_list_sort_type(str2regionlistsorttype(prop->value()));
2099 if ((prop = node.property ("xfades-visible"))) {
2100 bool yn = (prop->value() == "yes");
2101 _xfade_visibility = !yn;
2102 // set_xfade_visibility (yn);
2105 if ((prop = node.property ("show-editor-mixer"))) {
2107 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2110 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2111 bool yn = (prop->value() == X_("yes"));
2113 /* do it twice to force the change */
2115 tact->set_active (!yn);
2116 tact->set_active (yn);
2125 Editor::get_state ()
2127 XMLNode* node = new XMLNode ("Editor");
2130 _id.print (buf, sizeof (buf));
2131 node->add_property ("id", buf);
2133 if (is_realized()) {
2134 Glib::RefPtr<Gdk::Window> win = get_window();
2136 int x, y, xoff, yoff, width, height;
2137 win->get_root_origin(x, y);
2138 win->get_position(xoff, yoff);
2139 win->get_size(width, height);
2141 XMLNode* geometry = new XMLNode ("geometry");
2143 snprintf(buf, sizeof(buf), "%d", width);
2144 geometry->add_property("x_size", string(buf));
2145 snprintf(buf, sizeof(buf), "%d", height);
2146 geometry->add_property("y_size", string(buf));
2147 snprintf(buf, sizeof(buf), "%d", x);
2148 geometry->add_property("x_pos", string(buf));
2149 snprintf(buf, sizeof(buf), "%d", y);
2150 geometry->add_property("y_pos", string(buf));
2151 snprintf(buf, sizeof(buf), "%d", xoff);
2152 geometry->add_property("x_off", string(buf));
2153 snprintf(buf, sizeof(buf), "%d", yoff);
2154 geometry->add_property("y_off", string(buf));
2155 snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
2156 geometry->add_property("edit_pane_pos", string(buf));
2158 node->add_child_nocopy (*geometry);
2161 snprintf (buf, sizeof(buf), "%d", (int) zoom_focus);
2162 node->add_property ("zoom-focus", buf);
2163 snprintf (buf, sizeof(buf), "%f", frames_per_unit);
2164 node->add_property ("zoom", buf);
2165 snprintf (buf, sizeof(buf), "%d", (int) snap_type);
2166 node->add_property ("snap-to", buf);
2167 snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
2168 node->add_property ("snap-mode", buf);
2170 snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
2171 node->add_property ("playhead", buf);
2172 snprintf (buf, sizeof (buf), "%" PRIu32, edit_cursor->current_frame);
2173 node->add_property ("edit-cursor", buf);
2175 node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
2176 node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
2177 node->add_property ("show-measures", _show_measures ? "yes" : "no");
2178 node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
2179 node->add_property ("xfades-visible", _xfade_visibility ? "yes" : "no");
2180 node->add_property ("region-list-sort-type", enum2str(region_list_sort_type));
2181 node->add_property ("mouse-mode", enum2str(mouse_mode));
2183 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
2185 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2186 node->add_property (X_("show-editor-mixer"), tact->get_active() ? "yes" : "no");
2195 Editor::trackview_by_y_position (double y)
2197 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
2201 if ((tv = (*iter)->covers_y_position (y)) != 0) {
2210 Editor::snap_to (nframes_t& start, int32_t direction, bool for_mark)
2212 Location* before = 0;
2213 Location* after = 0;
2219 const nframes_t one_second = session->frame_rate();
2220 const nframes_t one_minute = session->frame_rate() * 60;
2221 const nframes_t one_smpte_second = (nframes_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame());
2222 nframes_t one_smpte_minute = (nframes_t)(rint(session->smpte_frames_per_second()) * session->frames_per_smpte_frame() * 60);
2223 nframes_t presnap = start;
2225 switch (snap_type) {
2231 start = (nframes_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
2233 start = (nframes_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
2237 case SnapToSMPTEFrame:
2238 if (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2)) {
2239 start = (nframes_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2241 start = (nframes_t) (floor ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
2245 case SnapToSMPTESeconds:
2246 if (session->smpte_offset_negative())
2248 start += session->smpte_offset ();
2250 start -= session->smpte_offset ();
2252 if (start % one_smpte_second > one_smpte_second / 2) {
2253 start = (nframes_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
2255 start = (nframes_t) floor ((double) start / one_smpte_second) * one_smpte_second;
2258 if (session->smpte_offset_negative())
2260 start -= session->smpte_offset ();
2262 start += session->smpte_offset ();
2266 case SnapToSMPTEMinutes:
2267 if (session->smpte_offset_negative())
2269 start += session->smpte_offset ();
2271 start -= session->smpte_offset ();
2273 if (start % one_smpte_minute > one_smpte_minute / 2) {
2274 start = (nframes_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
2276 start = (nframes_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
2278 if (session->smpte_offset_negative())
2280 start -= session->smpte_offset ();
2282 start += session->smpte_offset ();
2287 if (start % one_second > one_second / 2) {
2288 start = (nframes_t) ceil ((double) start / one_second) * one_second;
2290 start = (nframes_t) floor ((double) start / one_second) * one_second;
2295 if (start % one_minute > one_minute / 2) {
2296 start = (nframes_t) ceil ((double) start / one_minute) * one_minute;
2298 start = (nframes_t) floor ((double) start / one_minute) * one_minute;
2303 start = session->tempo_map().round_to_bar (start, direction);
2307 start = session->tempo_map().round_to_beat (start, direction);
2310 case SnapToAThirtysecondBeat:
2311 start = session->tempo_map().round_to_beat_subdivision (start, 32);
2314 case SnapToASixteenthBeat:
2315 start = session->tempo_map().round_to_beat_subdivision (start, 16);
2318 case SnapToAEighthBeat:
2319 start = session->tempo_map().round_to_beat_subdivision (start, 8);
2322 case SnapToAQuarterBeat:
2323 start = session->tempo_map().round_to_beat_subdivision (start, 4);
2326 case SnapToAThirdBeat:
2327 start = session->tempo_map().round_to_beat_subdivision (start, 3);
2330 case SnapToEditCursor:
2331 start = edit_cursor->current_frame;
2339 before = session->locations()->first_location_before (start);
2340 after = session->locations()->first_location_after (start);
2342 if (direction < 0) {
2344 start = before->start();
2348 } else if (direction > 0) {
2350 start = after->start();
2352 start = session->current_end_frame();
2357 /* find nearest of the two */
2358 if ((start - before->start()) < (after->start() - start)) {
2359 start = before->start();
2361 start = after->start();
2364 start = before->start();
2367 start = after->start();
2374 case SnapToRegionStart:
2375 case SnapToRegionEnd:
2376 case SnapToRegionSync:
2377 case SnapToRegionBoundary:
2378 if (!region_boundary_cache.empty()) {
2379 vector<nframes_t>::iterator i;
2381 if (direction > 0) {
2382 i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2384 i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
2387 if (i != region_boundary_cache.end()) {
2390 start = region_boundary_cache.back();
2396 switch (snap_mode) {
2402 if (presnap > start) {
2403 if (presnap > (start + unit_to_frame(snap_threshold))) {
2407 } else if (presnap < start) {
2408 if (presnap < (start - unit_to_frame(snap_threshold))) {
2420 Editor::setup_toolbar ()
2424 const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
2427 /* Mode Buttons (tool selection) */
2429 vector<ToggleButton *> mouse_mode_buttons;
2431 mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
2432 mouse_move_button.set_relief(Gtk::RELIEF_NONE);
2433 mouse_mode_buttons.push_back (&mouse_move_button);
2434 mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
2435 mouse_select_button.set_relief(Gtk::RELIEF_NONE);
2436 mouse_mode_buttons.push_back (&mouse_select_button);
2437 mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
2438 mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
2439 mouse_mode_buttons.push_back (&mouse_gain_button);
2440 mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
2441 mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
2442 mouse_mode_buttons.push_back (&mouse_zoom_button);
2443 mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
2444 mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
2445 mouse_mode_buttons.push_back (&mouse_timefx_button);
2446 mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
2447 mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
2448 mouse_mode_buttons.push_back (&mouse_audition_button);
2450 mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
2452 HBox* mode_box = manage(new HBox);
2453 mode_box->set_border_width (2);
2454 mode_box->set_spacing(4);
2455 mouse_mode_button_box.set_spacing(1);
2456 mouse_mode_button_box.pack_start(mouse_move_button, true, true);
2457 mouse_mode_button_box.pack_start(mouse_select_button, true, true);
2458 mouse_mode_button_box.pack_start(mouse_zoom_button, true, true);
2459 mouse_mode_button_box.pack_start(mouse_gain_button, true, true);
2460 mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
2461 mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
2462 mouse_mode_button_box.set_homogeneous(true);
2464 vector<string> edit_mode_strings;
2465 edit_mode_strings.push_back (edit_mode_to_string (Splice));
2466 edit_mode_strings.push_back (edit_mode_to_string (Slide));
2468 edit_mode_selector.set_name ("EditModeSelector");
2469 Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
2470 set_popdown_strings (edit_mode_selector, edit_mode_strings);
2471 edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
2473 mode_box->pack_start(edit_mode_selector);
2474 mode_box->pack_start(mouse_mode_button_box);
2476 mouse_mode_tearoff = manage (new TearOff (*mode_box));
2477 mouse_mode_tearoff->set_name ("MouseModeBase");
2479 mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2480 &mouse_mode_tearoff->tearoff_window()));
2481 mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2482 &mouse_mode_tearoff->tearoff_window(), 1));
2483 mouse_mode_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2484 &mouse_mode_tearoff->tearoff_window()));
2485 mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2486 &mouse_mode_tearoff->tearoff_window(), 1));
2488 mouse_move_button.set_name ("MouseModeButton");
2489 mouse_select_button.set_name ("MouseModeButton");
2490 mouse_gain_button.set_name ("MouseModeButton");
2491 mouse_zoom_button.set_name ("MouseModeButton");
2492 mouse_timefx_button.set_name ("MouseModeButton");
2493 mouse_audition_button.set_name ("MouseModeButton");
2495 ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
2496 ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
2497 ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
2498 ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
2499 ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
2500 ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
2502 mouse_move_button.unset_flags (CAN_FOCUS);
2503 mouse_select_button.unset_flags (CAN_FOCUS);
2504 mouse_gain_button.unset_flags (CAN_FOCUS);
2505 mouse_zoom_button.unset_flags (CAN_FOCUS);
2506 mouse_timefx_button.unset_flags (CAN_FOCUS);
2507 mouse_audition_button.unset_flags (CAN_FOCUS);
2509 mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
2510 mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
2512 mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
2513 mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
2514 mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
2515 mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
2516 mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
2518 // mouse_move_button.set_active (true);
2523 zoom_box.set_spacing (1);
2524 zoom_box.set_border_width (2);
2526 zoom_in_button.set_name ("EditorTimeButton");
2527 zoom_in_button.set_size_request(-1,16);
2528 zoom_in_button.add (*(manage (new Image (::get_icon("zoom_in")))));
2529 zoom_in_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
2530 ARDOUR_UI::instance()->tooltips().set_tip (zoom_in_button, _("Zoom In"));
2532 zoom_out_button.set_name ("EditorTimeButton");
2533 zoom_out_button.set_size_request(-1,16);
2534 zoom_out_button.add (*(manage (new Image (::get_icon("zoom_out")))));
2535 zoom_out_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
2536 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_button, _("Zoom Out"));
2538 zoom_out_full_button.set_name ("EditorTimeButton");
2539 zoom_out_full_button.set_size_request(-1,16);
2540 zoom_out_full_button.add (*(manage (new Image (::get_icon("zoom_full")))));
2541 zoom_out_full_button.signal_clicked().connect (mem_fun(*this, &Editor::temporal_zoom_session));
2542 ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
2544 zoom_focus_selector.set_name ("ZoomFocusSelector");
2545 Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, "Edit Cursor", FUDGE, 0);
2546 set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
2547 zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
2548 ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
2550 zoom_box.pack_start (zoom_focus_selector, true, true);
2551 zoom_box.pack_start (zoom_out_button, false, false);
2552 zoom_box.pack_start (zoom_in_button, false, false);
2553 zoom_box.pack_start (zoom_out_full_button, false, false);
2555 /* Edit Cursor / Snap */
2557 snap_box.set_spacing (1);
2558 snap_box.set_border_width (2);
2560 snap_type_selector.set_name ("SnapTypeSelector");
2561 Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, "SMPTE Seconds", 2+FUDGE, 10);
2562 set_popdown_strings (snap_type_selector, snap_type_strings);
2563 snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
2564 ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Unit to snap cursors and ranges to"));
2566 snap_mode_selector.set_name ("SnapModeSelector");
2567 Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, "Magnetic Snap", 2+FUDGE, 10);
2568 set_popdown_strings (snap_mode_selector, snap_mode_strings);
2569 snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
2571 snap_box.pack_start (edit_cursor_clock, false, false);
2572 snap_box.pack_start (snap_mode_selector, false, false);
2573 snap_box.pack_start (snap_type_selector, false, false);
2578 HBox *nudge_box = manage (new HBox);
2579 nudge_box->set_spacing(1);
2580 nudge_box->set_border_width (2);
2582 nudge_forward_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::nudge_forward), false));
2583 nudge_backward_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::nudge_backward), false));
2585 nudge_box->pack_start (nudge_backward_button, false, false);
2586 nudge_box->pack_start (nudge_forward_button, false, false);
2587 nudge_box->pack_start (nudge_clock, false, false);
2590 /* Pack everything in... */
2592 HBox* hbox = new HBox;
2593 hbox->set_spacing(10);
2595 tools_tearoff = new TearOff (*hbox);
2596 tools_tearoff->set_name ("MouseModeBase");
2598 tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2599 &tools_tearoff->tearoff_window()));
2600 tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2601 &tools_tearoff->tearoff_window(), 0));
2602 tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
2603 &tools_tearoff->tearoff_window()));
2604 tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
2605 &tools_tearoff->tearoff_window(), 0));
2607 toolbar_hbox.set_spacing (10);
2608 toolbar_hbox.set_border_width (1);
2610 toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
2611 toolbar_hbox.pack_start (*tools_tearoff, false, false);
2614 hbox->pack_start (snap_box, false, false);
2615 // hbox->pack_start (zoom_box, false, false);
2616 hbox->pack_start (*nudge_box, false, false);
2620 toolbar_base.set_name ("ToolBarBase");
2621 toolbar_base.add (toolbar_hbox);
2623 toolbar_frame.set_shadow_type (SHADOW_OUT);
2624 toolbar_frame.set_name ("BaseFrame");
2625 toolbar_frame.add (toolbar_base);
2629 Editor::convert_drop_to_paths (vector<ustring>& paths,
2630 const RefPtr<Gdk::DragContext>& context,
2633 const SelectionData& data,
2642 vector<ustring> uris = data.get_uris();
2646 /* This is seriously fucked up. Nautilus doesn't say that its URI lists
2647 are actually URI lists. So do it by hand.
2650 if (data.get_target() != "text/plain") {
2654 /* Parse the "uri-list" format that Nautilus provides,
2655 where each pathname is delimited by \r\n
2658 const char* p = data.get_text().c_str();
2665 while (g_ascii_isspace (*p))
2669 while (*q && (*q != '\n') && (*q != '\r'))
2675 while (q > p && g_ascii_isspace (*q))
2680 uris.push_back (ustring (p, q - p + 1));
2684 p = strchr (p, '\n');
2694 for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) {
2695 if ((*i).substr (0,7) == "file://") {
2697 PBD::url_decode (p);
2698 paths.push_back (p.substr (7));
2706 Editor::new_tempo_section ()
2712 Editor::map_transport_state ()
2714 ENSURE_GUI_THREAD (mem_fun(*this, &Editor::map_transport_state));
2716 if (session->transport_stopped()) {
2717 have_pending_keyboard_selection = false;
2723 Editor::State::State ()
2725 selection = new Selection;
2728 Editor::State::~State ()
2734 Editor::get_memento () const
2736 State *state = new State;
2738 store_state (*state);
2739 return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
2743 Editor::store_state (State& state) const
2745 *state.selection = *selection;
2749 Editor::restore_state (State *state)
2751 if (*selection == *state->selection) {
2755 *selection = *state->selection;
2756 time_selection_changed ();
2757 region_selection_changed ();
2759 /* XXX other selection change handlers? */
2763 Editor::begin_reversible_command (string name)
2766 before = &get_state();
2767 session->begin_reversible_command (name);
2772 Editor::commit_reversible_command ()
2775 session->commit_reversible_command (new MementoCommand<Editor>(*this, before, &get_state()));
2780 Editor::set_edit_group_solo (Route& route, bool yn)
2782 RouteGroup *edit_group;
2784 if ((edit_group = route.edit_group()) != 0) {
2785 edit_group->apply (&Route::set_solo, yn, this);
2787 route.set_solo (yn, this);
2792 Editor::set_edit_group_mute (Route& route, bool yn)
2794 RouteGroup *edit_group = 0;
2796 if ((edit_group == route.edit_group()) != 0) {
2797 edit_group->apply (&Route::set_mute, yn, this);
2799 route.set_mute (yn, this);
2804 Editor::history_changed ()
2808 if (undo_action && session) {
2809 if (session->undo_depth() == 0) {
2812 label = string_compose(_("Undo (%1)"), session->next_undo());
2814 undo_action->property_label() = label;
2817 if (redo_action && session) {
2818 if (session->redo_depth() == 0) {
2821 label = string_compose(_("Redo (%1)"), session->next_redo());
2823 redo_action->property_label() = label;
2828 Editor::duplicate_dialog (bool dup_region)
2831 if (clicked_regionview == 0) {
2835 if (selection->time.length() == 0) {
2840 ArdourDialog win ("duplicate dialog");
2842 Label label (_("Duplicate how many times?"));
2844 win.get_vbox()->pack_start (label);
2845 win.add_action_widget (entry, RESPONSE_ACCEPT);
2846 win.add_button (Stock::OK, RESPONSE_ACCEPT);
2847 win.add_button (Stock::CANCEL, RESPONSE_CANCEL);
2849 win.set_position (WIN_POS_MOUSE);
2851 entry.set_text ("1");
2852 set_size_request_to_display_given_text (entry, X_("12345678"), 20, 15);
2853 entry.select_region (0, -1);
2854 entry.grab_focus ();
2857 switch (win.run ()) {
2858 case RESPONSE_ACCEPT:
2864 string text = entry.get_text();
2867 if (sscanf (text.c_str(), "%f", ×) == 1) {
2869 RegionSelection regions;
2870 regions.add (clicked_regionview);
2871 duplicate_some_regions (regions, times);
2873 duplicate_selection (times);
2879 Editor::show_verbose_canvas_cursor ()
2881 verbose_canvas_cursor->raise_to_top();
2882 verbose_canvas_cursor->show();
2883 verbose_cursor_visible = true;
2887 Editor::hide_verbose_canvas_cursor ()
2889 verbose_canvas_cursor->hide();
2890 verbose_cursor_visible = false;
2894 Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
2896 /* XXX get origin of canvas relative to root window,
2897 add x and y and check compared to gdk_screen_{width,height}
2899 verbose_canvas_cursor->property_text() = txt.c_str();
2900 verbose_canvas_cursor->property_x() = x;
2901 verbose_canvas_cursor->property_y() = y;
2905 Editor::set_verbose_canvas_cursor_text (const string & txt)
2907 verbose_canvas_cursor->property_text() = txt.c_str();
2911 Editor::edit_mode_selection_done ()
2917 string choice = edit_mode_selector.get_active_text();
2918 EditMode mode = Slide;
2920 if (choice == _("Splice Edit")) {
2922 } else if (choice == _("Slide Edit")) {
2926 Config->set_edit_mode (mode);
2930 Editor::snap_type_selection_done ()
2932 string choice = snap_type_selector.get_active_text();
2933 SnapType snaptype = SnapToFrame;
2935 if (choice == _("Beats/3")) {
2936 snaptype = SnapToAThirdBeat;
2937 } else if (choice == _("Beats/4")) {
2938 snaptype = SnapToAQuarterBeat;
2939 } else if (choice == _("Beats/8")) {
2940 snaptype = SnapToAEighthBeat;
2941 } else if (choice == _("Beats/16")) {
2942 snaptype = SnapToASixteenthBeat;
2943 } else if (choice == _("Beats/32")) {
2944 snaptype = SnapToAThirtysecondBeat;
2945 } else if (choice == _("Beats")) {
2946 snaptype = SnapToBeat;
2947 } else if (choice == _("Bars")) {
2948 snaptype = SnapToBar;
2949 } else if (choice == _("Marks")) {
2950 snaptype = SnapToMark;
2951 } else if (choice == _("Edit Cursor")) {
2952 snaptype = SnapToEditCursor;
2953 } else if (choice == _("Region starts")) {
2954 snaptype = SnapToRegionStart;
2955 } else if (choice == _("Region ends")) {
2956 snaptype = SnapToRegionEnd;
2957 } else if (choice == _("Region bounds")) {
2958 snaptype = SnapToRegionBoundary;
2959 } else if (choice == _("Region syncs")) {
2960 snaptype = SnapToRegionSync;
2961 } else if (choice == _("CD Frames")) {
2962 snaptype = SnapToCDFrame;
2963 } else if (choice == _("SMPTE Frames")) {
2964 snaptype = SnapToSMPTEFrame;
2965 } else if (choice == _("SMPTE Seconds")) {
2966 snaptype = SnapToSMPTESeconds;
2967 } else if (choice == _("SMPTE Minutes")) {
2968 snaptype = SnapToSMPTEMinutes;
2969 } else if (choice == _("Seconds")) {
2970 snaptype = SnapToSeconds;
2971 } else if (choice == _("Minutes")) {
2972 snaptype = SnapToMinutes;
2973 } else if (choice == _("None")) {
2974 snaptype = SnapToFrame;
2977 RefPtr<RadioAction> ract = snap_type_action (snaptype);
2979 ract->set_active ();
2984 Editor::snap_mode_selection_done ()
2986 string choice = snap_mode_selector.get_active_text();
2987 SnapMode mode = SnapNormal;
2989 if (choice == _("Normal")) {
2991 } else if (choice == _("Magnetic")) {
2992 mode = SnapMagnetic;
2995 RefPtr<RadioAction> ract = snap_mode_action (mode);
2998 ract->set_active (true);
3003 Editor::zoom_focus_selection_done ()
3005 string choice = zoom_focus_selector.get_active_text();
3006 ZoomFocus focus_type = ZoomFocusLeft;
3008 if (choice == _("Left")) {
3009 focus_type = ZoomFocusLeft;
3010 } else if (choice == _("Right")) {
3011 focus_type = ZoomFocusRight;
3012 } else if (choice == _("Center")) {
3013 focus_type = ZoomFocusCenter;
3014 } else if (choice == _("Playhead")) {
3015 focus_type = ZoomFocusPlayhead;
3016 } else if (choice == _("Edit Cursor")) {
3017 focus_type = ZoomFocusEdit;
3020 RefPtr<RadioAction> ract = zoom_focus_action (focus_type);
3023 ract->set_active ();
3028 Editor::edit_controls_button_release (GdkEventButton* ev)
3030 if (Keyboard::is_context_menu_event (ev)) {
3031 ARDOUR_UI::instance()->add_route (this);
3037 Editor::mouse_select_button_release (GdkEventButton* ev)
3039 /* this handles just right-clicks */
3041 if (ev->button != 3) {
3048 Editor::TrackViewList *
3049 Editor::get_valid_views (TimeAxisView* track, RouteGroup* group)
3052 TrackViewList::iterator i;
3054 v = new TrackViewList;
3056 if (track == 0 && group == 0) {
3060 for (i = track_views.begin(); i != track_views.end (); ++i) {
3064 } else if (track != 0 && group == 0 || (track != 0 && group != 0 && !group->is_active())) {
3066 /* just the view for this track
3069 v->push_back (track);
3073 /* views for all tracks in the edit group */
3075 for (i = track_views.begin(); i != track_views.end (); ++i) {
3077 if (group == 0 || (*i)->edit_group() == group) {
3087 Editor::set_zoom_focus (ZoomFocus f)
3089 string str = zoom_focus_strings[(int)f];
3091 if (str != zoom_focus_selector.get_active_text()) {
3092 zoom_focus_selector.set_active_text (str);
3095 if (zoom_focus != f) {
3098 ZoomFocusChanged (); /* EMIT_SIGNAL */
3105 Editor::ensure_float (Window& win)
3107 win.set_transient_for (*this);
3111 Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
3113 /* recover or initialize pane positions. do this here rather than earlier because
3114 we don't want the positions to change the child allocations, which they seem to do.
3120 XMLNode* node = ARDOUR_UI::instance()->editor_settings();
3122 static int32_t done;
3125 if ((geometry = find_named_node (*node, "geometry")) == 0) {
3126 width = default_width;
3127 height = default_height;
3129 width = atoi(geometry->property("x_size")->value());
3130 height = atoi(geometry->property("y_size")->value());
3133 if (which == static_cast<Paned*> (&edit_pane)) {
3139 if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
3140 /* initial allocation is 90% to canvas, 10% to notebook */
3141 pos = (int) floor (alloc.get_width() * 0.90f);
3142 snprintf (buf, sizeof(buf), "%d", pos);
3144 pos = atoi (prop->value());
3147 if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
3148 edit_pane.set_position (pos);
3149 pre_maximal_pane_position = pos;
3155 Editor::detach_tearoff (Box* b, Window* w)
3157 if (tools_tearoff->torn_off() &&
3158 mouse_mode_tearoff->torn_off()) {
3159 top_hbox.remove (toolbar_frame);
3164 Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
3166 if (toolbar_frame.get_parent() == 0) {
3167 top_hbox.pack_end (toolbar_frame);
3172 Editor::set_show_measures (bool yn)
3174 if (_show_measures != yn) {
3177 if ((_show_measures = yn) == true) {
3185 Editor::toggle_follow_playhead ()
3187 RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
3189 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
3190 set_follow_playhead (tact->get_active());
3195 Editor::set_follow_playhead (bool yn)
3197 if (_follow_playhead != yn) {
3198 if ((_follow_playhead = yn) == true) {
3200 update_current_screen ();
3207 Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
3209 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3211 xfade->set_active (!xfade->active());
3216 Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
3218 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3220 xfade->set_follow_overlap (!xfade->following_overlap());
3225 Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
3227 boost::shared_ptr<Crossfade> xfade (wxfade.lock());
3233 CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
3237 switch (cew.run ()) {
3238 case RESPONSE_ACCEPT:
3245 xfade->StateChanged (Change (~0));
3249 Editor::playlist_selector () const
3251 return *_playlist_selector;
3255 Editor::get_nudge_distance (nframes_t pos, nframes_t& next)
3259 ret = nudge_clock.current_duration (pos);
3260 next = ret + 1; /* XXXX fix me */
3266 Editor::end_location_changed (Location* location)
3268 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
3269 reset_scrolling_region ();
3273 Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
3275 ArdourDialog dialog ("playlist deletion dialog");
3276 Label label (string_compose (_("Playlist %1 is currently unused.\n"
3277 "If left alone, no audio files used by it will be cleaned.\n"
3278 "If deleted, audio files used by it alone by will cleaned."),
3281 dialog.set_position (WIN_POS_CENTER);
3282 dialog.get_vbox()->pack_start (label);
3286 dialog.add_button (_("Delete playlist"), RESPONSE_ACCEPT);
3287 dialog.add_button (_("Keep playlist"), RESPONSE_CANCEL);
3288 dialog.add_button (_("Cancel"), RESPONSE_CANCEL);
3290 switch (dialog.run ()) {
3291 case RESPONSE_ACCEPT:
3292 /* delete the playlist */
3296 case RESPONSE_REJECT:
3297 /* keep the playlist */
3309 Editor::audio_region_selection_covers (nframes_t where)
3311 for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
3312 if ((*a)->region()->covers (where)) {
3321 Editor::prepare_for_cleanup ()
3323 cut_buffer->clear_regions ();
3324 cut_buffer->clear_playlists ();
3326 selection->clear_regions ();
3327 selection->clear_playlists ();
3331 Editor::transport_loop_location()
3334 return session->locations()->auto_loop_location();
3341 Editor::transport_punch_location()
3344 return session->locations()->auto_punch_location();
3351 Editor::control_layout_scroll (GdkEventScroll* ev)
3353 switch (ev->direction) {
3355 scroll_tracks_up_line ();
3359 case GDK_SCROLL_DOWN:
3360 scroll_tracks_down_line ();
3364 /* no left/right handling yet */
3372 Editor::snapshot_display_selection_changed ()
3374 if (snapshot_display.get_selection()->count_selected_rows() > 0) {
3376 TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
3378 Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
3380 if (snap_name.length() == 0) {
3384 if (session->snap_name() == snap_name) {
3388 ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
3393 Editor::snapshot_display_button_press (GdkEventButton* ev)
3399 Editor::redisplay_snapshots ()
3405 vector<string*>* states;
3407 if ((states = session->possible_states()) == 0) {
3411 snapshot_display_model->clear ();
3413 for (vector<string*>::iterator i = states->begin(); i != states->end(); ++i) {
3414 string statename = *(*i);
3415 TreeModel::Row row = *(snapshot_display_model->append());
3417 /* this lingers on in case we ever want to change the visible
3418 name of the snapshot.
3421 string display_name;
3422 display_name = statename;
3424 if (statename == session->snap_name()) {
3425 snapshot_display.get_selection()->select(row);
3428 row[snapshot_display_columns.visible_name] = display_name;
3429 row[snapshot_display_columns.real_name] = statename;
3436 Editor::session_state_saved (string snap_name)
3438 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
3439 redisplay_snapshots ();
3443 Editor::maximise_editing_space ()
3445 initial_ruler_update_required = true;
3447 mouse_mode_tearoff->set_visible (false);
3448 tools_tearoff->set_visible (false);
3450 pre_maximal_pane_position = edit_pane.get_position();
3451 pre_maximal_editor_width = this->get_width();
3453 if(post_maximal_pane_position == 0) {
3454 post_maximal_pane_position = edit_pane.get_width();
3459 if(post_maximal_editor_width) {
3460 edit_pane.set_position (post_maximal_pane_position -
3461 abs(post_maximal_editor_width - pre_maximal_editor_width));
3463 edit_pane.set_position (post_maximal_pane_position);
3468 Editor::restore_editing_space ()
3470 initial_ruler_update_required = true;
3472 // user changed width of pane during fullscreen
3473 if(post_maximal_pane_position != edit_pane.get_position()) {
3474 post_maximal_pane_position = edit_pane.get_position();
3479 mouse_mode_tearoff->set_visible (true);
3480 tools_tearoff->set_visible (true);
3481 post_maximal_editor_width = this->get_width();
3484 edit_pane.set_position (
3485 pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width)
3490 Editor::new_playlists ()
3492 begin_reversible_command (_("new playlists"));
3493 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist));
3494 commit_reversible_command ();
3498 Editor::copy_playlists ()
3500 begin_reversible_command (_("copy playlists"));
3501 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist));
3502 commit_reversible_command ();
3506 Editor::clear_playlists ()
3508 begin_reversible_command (_("clear playlists"));
3509 mapover_audio_tracks (mem_fun (*this, &Editor::mapped_clear_playlist));
3510 commit_reversible_command ();
3514 Editor::mapped_use_new_playlist (AudioTimeAxisView& atv, uint32_t sz)
3516 atv.use_new_playlist (sz > 1 ? false : true);
3520 Editor::mapped_use_copy_playlist (AudioTimeAxisView& atv, uint32_t sz)
3522 atv.use_copy_playlist (sz > 1 ? false : true);
3526 Editor::mapped_clear_playlist (AudioTimeAxisView& atv, uint32_t sz)
3528 atv.clear_playlist ();
3532 Editor::on_key_press_event (GdkEventKey* ev)
3534 return key_press_focus_accelerator_handler (*this, ev);
3538 Editor::reset_x_origin (nframes_t frame)
3540 queue_visual_change (frame);
3544 Editor::reset_zoom (double fpu)
3546 queue_visual_change (fpu);
3550 Editor::reposition_and_zoom (nframes_t frame, double fpu)
3552 reset_x_origin (frame);
3557 Editor::set_frames_per_unit (double fpu)
3561 /* this is the core function that controls the zoom level of the canvas. it is called
3562 whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
3565 if (fpu == frames_per_unit) {
3573 // convert fpu to frame count
3575 frames = (nframes_t) floor (fpu * canvas_width);
3577 /* don't allow zooms that fit more than the maximum number
3578 of frames into an 800 pixel wide space.
3581 if (max_frames / fpu < 800.0) {
3585 if (fpu == frames_per_unit) {
3589 frames_per_unit = fpu;
3591 if (frames != zoom_range_clock.current_duration()) {
3592 zoom_range_clock.set (frames);
3595 if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
3596 if (!selection->tracks.empty()) {
3597 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3598 (*i)->reshow_selection (selection->time);
3601 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
3602 (*i)->reshow_selection (selection->time);
3607 ZoomChanged (); /* EMIT_SIGNAL */
3609 reset_hscrollbar_stepping ();
3610 reset_scrolling_region ();
3612 if (edit_cursor) edit_cursor->set_position (edit_cursor->current_frame);
3613 if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
3619 Editor::queue_visual_change (nframes_t where)
3621 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
3622 pending_visual_change.time_origin = where;
3624 if (pending_visual_change.idle_handler_id < 0) {
3625 pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
3630 Editor::queue_visual_change (double fpu)
3632 pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
3633 pending_visual_change.frames_per_unit = fpu;
3635 if (pending_visual_change.idle_handler_id < 0) {
3636 pending_visual_change.idle_handler_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, _idle_visual_changer, this, 0);
3641 Editor::_idle_visual_changer (void* arg)
3643 return static_cast<Editor*>(arg)->idle_visual_changer ();
3647 Editor::idle_visual_changer ()
3649 VisualChange::Type p = pending_visual_change.pending;
3651 pending_visual_change.pending = (VisualChange::Type) 0;
3652 pending_visual_change.idle_handler_id = -1;
3654 if (p & VisualChange::ZoomLevel) {
3655 set_frames_per_unit (pending_visual_change.frames_per_unit);
3658 if (p & VisualChange::TimeOrigin) {
3659 if (pending_visual_change.time_origin != leftmost_frame) {
3660 horizontal_adjustment.set_value (pending_visual_change.time_origin/frames_per_unit);
3661 /* the signal handler will do the rest */
3663 update_fixed_rulers();
3664 tempo_map_changed (Change (0), true);
3671 struct EditorOrderTimeAxisSorter {
3672 bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
3673 return a->order < b->order;
3678 Editor::sort_track_selection ()
3680 EditorOrderTimeAxisSorter cmp;
3681 selection->tracks.sort (cmp);
3685 Editor::edit_cursor_position(bool sync)
3687 if (sync && edit_cursor->current_frame != edit_cursor_clock.current_time()) {
3688 edit_cursor_clock.set(edit_cursor->current_frame, true);
3691 return edit_cursor->current_frame;