+
+ commit_reversible_command ();
+}
+
+void
+Editor::toggle_selected_region_fades (int dir)
+{
+ RegionSelection rs;
+ RegionSelection::iterator i;
+ boost::shared_ptr<AudioRegion> ar;
+ bool yn;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ for (i = rs.begin(); i != rs.end(); ++i) {
+ if ((ar = boost::dynamic_pointer_cast<AudioRegion>((*i)->region())) != 0) {
+ if (dir == -1) {
+ yn = ar->fade_out_active ();
+ } else {
+ yn = ar->fade_in_active ();
+ }
+ break;
+ }
+ }
+
+ if (i == rs.end()) {
+ return;
+ }
+
+ /* XXX should this undo-able? */
+
+ for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
+ if ((ar = boost::dynamic_pointer_cast<AudioRegion>((*i)->region())) == 0) {
+ continue;
+ }
+ if (dir == 1 || dir == 0) {
+ ar->set_fade_in_active (!yn);
+ }
+
+ if (dir == -1 || dir == 0) {
+ ar->set_fade_out_active (!yn);
+ }
+ }
+}
+
+
+/** Update region fade visibility after its configuration has been changed */
+void
+Editor::update_region_fade_visibility ()
+{
+ bool _fade_visibility = session->config.get_show_region_fades ();
+
+ for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+ AudioTimeAxisView* v = dynamic_cast<AudioTimeAxisView*>(*i);
+ if (v) {
+ if (_fade_visibility) {
+ v->audio_view()->show_all_fades ();
+ } else {
+ v->audio_view()->hide_all_fades ();
+ }
+ }
+ }
+}
+
+/** Update crossfade visibility after its configuration has been changed */
+void
+Editor::update_xfade_visibility ()
+{
+ _xfade_visibility = session->config.get_xfades_visible ();
+
+ for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+ AudioTimeAxisView* v = dynamic_cast<AudioTimeAxisView*>(*i);
+ if (v) {
+ if (_xfade_visibility) {
+ v->show_all_xfades ();
+ } else {
+ v->hide_all_xfades ();
+ }
+ }
+ }
+}
+
+void
+Editor::set_edit_point ()
+{
+ nframes64_t where;
+ bool ignored;
+
+ if (!mouse_frame (where, ignored)) {
+ return;
+ }
+
+ snap_to (where);
+
+ if (selection->markers.empty()) {
+
+ mouse_add_new_marker (where);
+
+ } else {
+ bool ignored;
+
+ Location* loc = find_location_from_marker (selection->markers.front(), ignored);
+
+ if (loc) {
+ loc->move_to (where);
+ }
+ }
+}
+
+void
+Editor::set_playhead_cursor ()
+{
+ if (entered_marker) {
+ session->request_locate (entered_marker->position(), session->transport_rolling());
+ } else {
+ nframes64_t where;
+ bool ignored;
+
+ if (!mouse_frame (where, ignored)) {
+ return;
+ }
+
+ snap_to (where);
+
+ if (session) {
+ session->request_locate (where, session->transport_rolling());
+ }
+ }
+}
+
+void
+Editor::split ()
+{
+ RegionSelection rs;
+
+ get_regions_for_action (rs, true);
+
+ nframes64_t where = get_preferred_edit_position();
+
+ if (rs.empty()) {
+ return;
+ }
+
+ split_regions_at (where, rs);
+}
+
+void
+Editor::ensure_entered_track_selected (bool op_really_wants_one_track_if_none_are_selected)
+{
+ if (entered_track && mouse_mode == MouseObject) {
+ if (!selection->tracks.empty()) {
+ if (!selection->selected (entered_track)) {
+ selection->add (entered_track);
+ }
+ } else {
+ /* there is no selection, but this operation requires/prefers selected objects */
+
+ if (op_really_wants_one_track_if_none_are_selected) {
+ selection->set (entered_track);
+ }
+ }
+ }
+}
+
+struct EditorOrderRouteSorter {
+ bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
+ /* use of ">" forces the correct sort order */
+ return a->order_key ("editor") < b->order_key ("editor");
+ }
+};
+
+void
+Editor::select_next_route()
+{
+ if (selection->tracks.empty()) {
+ selection->set (track_views.front());
+ return;
+ }
+
+ TimeAxisView* current = selection->tracks.front();
+
+ RouteUI *rui;
+ do {
+ for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+ if (*i == current) {
+ ++i;
+ if (i != track_views.end()) {
+ current = (*i);
+ } else {
+ current = (*(track_views.begin()));
+ //selection->set (*(track_views.begin()));
+ }
+ break;
+ }
+ }
+ rui = dynamic_cast<RouteUI *>(current);
+ } while ( current->hidden() || (rui != NULL && !rui->route()->active()));
+
+ selection->set(current);
+
+ ensure_track_visible(current);
+}
+
+void
+Editor::select_prev_route()
+{
+ if (selection->tracks.empty()) {
+ selection->set (track_views.front());
+ return;
+ }
+
+ TimeAxisView* current = selection->tracks.front();
+
+ RouteUI *rui;
+ do {
+ for (TrackViewList::reverse_iterator i = track_views.rbegin(); i != track_views.rend(); ++i) {
+ if (*i == current) {
+ ++i;
+ if (i != track_views.rend()) {
+ current = (*i);
+ } else {
+ current = *(track_views.rbegin());
+ }
+ break;
+ }
+ }
+ rui = dynamic_cast<RouteUI *>(current);
+ } while ( current->hidden() || (rui != NULL && !rui->route()->active()));
+
+ selection->set (current);
+
+ ensure_track_visible(current);
+}
+
+void
+Editor::ensure_track_visible(TimeAxisView *track)
+{
+ if (track->hidden())
+ return;
+
+ double const current_view_min_y = vertical_adjustment.get_value();
+ double const current_view_max_y = vertical_adjustment.get_value() + vertical_adjustment.get_page_size() - canvas_timebars_vsize;
+
+ double const track_min_y = track->y_position ();
+ double const track_max_y = track->y_position () + track->effective_height ();
+
+ if (track_min_y >= current_view_min_y &&
+ track_max_y <= current_view_max_y) {
+ return;
+ }
+
+ double new_value;
+
+ if (track_min_y < current_view_min_y) {
+ // Track is above the current view
+ new_value = track_min_y;
+ } else {
+ // Track is below the current view
+ new_value = track->y_position () + track->effective_height() + canvas_timebars_vsize - vertical_adjustment.get_page_size();
+ }
+
+ vertical_adjustment.set_value(new_value);
+}
+
+void
+Editor::set_loop_from_selection (bool play)
+{
+ if (session == 0 || selection->time.empty()) {
+ return;
+ }
+
+ nframes64_t start = selection->time[clicked_selection].start;
+ nframes64_t end = selection->time[clicked_selection].end;
+
+ set_loop_range (start, end, _("set loop range from selection"));
+
+ if (play) {
+ session->request_play_loop (true);
+ session->request_locate (start, true);
+ }
+}
+
+void
+Editor::set_loop_from_edit_range (bool play)
+{
+ if (session == 0) {
+ return;
+ }
+
+ nframes64_t start;
+ nframes64_t end;
+
+ if (!get_edit_op_range (start, end)) {
+ return;
+ }
+
+ set_loop_range (start, end, _("set loop range from edit range"));
+
+ if (play) {
+ session->request_play_loop (true);
+ session->request_locate (start, true);
+ }
+}
+
+void
+Editor::set_loop_from_region (bool play)
+{
+ nframes64_t start = max_frames;
+ nframes64_t end = 0;
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
+ if ((*i)->region()->position() < start) {
+ start = (*i)->region()->position();
+ }
+ if ((*i)->region()->last_frame() + 1 > end) {
+ end = (*i)->region()->last_frame() + 1;
+ }
+ }
+
+ set_loop_range (start, end, _("set loop range from region"));
+
+ if (play) {
+ session->request_play_loop (true);
+ session->request_locate (start, true);
+ }
+}
+
+void
+Editor::set_punch_from_selection ()
+{
+ if (session == 0 || selection->time.empty()) {
+ return;
+ }
+
+ nframes64_t start = selection->time[clicked_selection].start;
+ nframes64_t end = selection->time[clicked_selection].end;
+
+ set_punch_range (start, end, _("set punch range from selection"));
+}
+
+void
+Editor::set_punch_from_edit_range ()
+{
+ if (session == 0) {
+ return;
+ }
+
+ nframes64_t start;
+ nframes64_t end;
+
+ if (!get_edit_op_range (start, end)) {
+ return;
+ }
+
+ set_punch_range (start, end, _("set punch range from edit range"));
+}
+
+void
+Editor::set_punch_from_region ()
+{
+ nframes64_t start = max_frames;
+ nframes64_t end = 0;
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
+ if ((*i)->region()->position() < start) {
+ start = (*i)->region()->position();
+ }
+ if ((*i)->region()->last_frame() + 1 > end) {
+ end = (*i)->region()->last_frame() + 1;
+ }
+ }
+
+ set_punch_range (start, end, _("set punch range from region"));
+}
+
+void
+Editor::pitch_shift_regions ()
+{
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ pitch_shift (rs, 1.2);
+}
+
+void
+Editor::use_region_as_bar ()
+{
+ if (!session) {
+ return;
+ }
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ RegionView* rv = rs.front();
+
+ define_one_bar (rv->region()->position(), rv->region()->last_frame() + 1);
+}
+
+void
+Editor::use_range_as_bar ()
+{
+ nframes64_t start, end;
+ if (get_edit_op_range (start, end)) {
+ define_one_bar (start, end);
+ }
+}
+
+void
+Editor::define_one_bar (nframes64_t start, nframes64_t end)
+{
+ nframes64_t length = end - start;
+
+ const Meter& m (session->tempo_map().meter_at (start));
+
+ /* length = 1 bar */
+
+ /* now we want frames per beat.
+ we have frames per bar, and beats per bar, so ...
+ */
+
+ double frames_per_beat = length / m.beats_per_bar();
+
+ /* beats per minute = */
+
+ double beats_per_minute = (session->frame_rate() * 60.0) / frames_per_beat;
+
+ /* now decide whether to:
+
+ (a) set global tempo
+ (b) add a new tempo marker
+
+ */
+
+ const TempoSection& t (session->tempo_map().tempo_section_at (start));
+
+ bool do_global = false;
+
+ if ((session->tempo_map().n_tempos() == 1) && (session->tempo_map().n_meters() == 1)) {
+
+ /* only 1 tempo & 1 meter: ask if the user wants to set the tempo
+ at the start, or create a new marker
+ */
+
+ vector<string> options;
+ options.push_back (_("Cancel"));
+ options.push_back (_("Add new marker"));
+ options.push_back (_("Set global tempo"));
+ Choice c (_("Do you want to set the global tempo or add new tempo marker?"),
+ options);
+ c.set_default_response (2);
+
+ switch (c.run()) {
+ case 0:
+ return;
+
+ case 2:
+ do_global = true;
+ break;
+
+ default:
+ do_global = false;
+ }
+
+ } else {
+
+ /* more than 1 tempo and/or meter section already, go ahead do the "usual":
+ if the marker is at the region starter, change it, otherwise add
+ a new tempo marker
+ */
+ }
+
+ begin_reversible_command (_("set tempo from region"));
+ XMLNode& before (session->tempo_map().get_state());
+
+ if (do_global) {
+ session->tempo_map().change_initial_tempo (beats_per_minute, t.note_type());
+ } else if (t.frame() == start) {
+ session->tempo_map().change_existing_tempo_at (start, beats_per_minute, t.note_type());
+ } else {
+ session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), start);
+ }
+
+ XMLNode& after (session->tempo_map().get_state());
+
+ session->add_command (new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
+ commit_reversible_command ();
+}
+
+void
+Editor::split_region_at_transients ()
+{
+ AnalysisFeatureList positions;
+
+ if (!session) {
+ return;
+ }
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ session->begin_reversible_command (_("split regions"));
+
+ for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ) {
+
+ RegionSelection::iterator tmp;
+
+ tmp = i;
+ ++tmp;
+
+ boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> ((*i)->region());
+
+ if (ar && (ar->get_transients (positions) == 0)) {
+ split_region_at_points ((*i)->region(), positions, true);
+ positions.clear ();
+ }
+
+ i = tmp;
+ }
+
+ session->commit_reversible_command ();
+
+}
+
+void
+Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList& positions, bool can_ferret)
+{
+ bool use_rhythmic_rodent = false;
+
+ boost::shared_ptr<Playlist> pl = r->playlist();
+
+ if (!pl) {
+ return;
+ }
+
+ if (positions.empty()) {
+ return;
+ }
+
+
+ if (positions.size() > 20) {
+ Glib::ustring msgstr = string_compose (_("You are about to split\n%1\ninto %2 pieces.\nThis could take a long time."), r->name(), positions.size() + 1);
+ MessageDialog msg (msgstr,
+ false,
+ Gtk::MESSAGE_INFO,
+ Gtk::BUTTONS_OK_CANCEL);
+
+ if (can_ferret) {
+ msg.add_button (_("Call for the Ferret!"), RESPONSE_APPLY);
+ msg.set_secondary_text (_("Press OK to continue with this split operation\nor ask the Ferret dialog to tune the analysis"));
+ } else {
+ msg.set_secondary_text (_("Press OK to continue with this split operation"));
+ }
+
+ msg.set_title (_("Excessive split?"));
+ msg.present ();
+
+ int response = msg.run();
+ msg.hide ();
+ switch (response) {
+ case RESPONSE_OK:
+ break;
+ case RESPONSE_APPLY:
+ use_rhythmic_rodent = true;
+ break;
+ default:
+ return;
+ }
+ }
+
+ if (use_rhythmic_rodent) {
+ show_rhythm_ferret ();
+ return;
+ }
+
+ AnalysisFeatureList::const_iterator x;
+
+ nframes64_t pos = r->position();
+
+ XMLNode& before (pl->get_state());
+
+ x = positions.begin();
+
+ while (x != positions.end()) {
+ if ((*x) > pos) {
+ break;
+ }
+ ++x;
+ }
+
+ if (x == positions.end()) {
+ return;
+ }
+
+ pl->freeze ();
+ pl->remove_region (r);
+
+ while (x != positions.end()) {
+
+ /* file start = original start + how far we from the initial position ?
+ */
+
+ nframes64_t file_start = r->start() + (pos - r->position());
+
+ /* length = next position - current position
+ */
+
+ nframes64_t len = (*x) - pos;
+
+ /* XXX we do we really want to allow even single-sample regions?
+ shouldn't we have some kind of lower limit on region size?
+ */
+
+ if (len <= 0) {
+ break;
+ }
+
+ string new_name;
+
+ if (session->region_name (new_name, r->name())) {
+ break;
+ }
+
+ /* do NOT announce new regions 1 by one, just wait till they are all done */
+
+ boost::shared_ptr<Region> nr = RegionFactory::create (r->sources(), file_start, len, new_name, 0, Region::DefaultFlags, false);
+ pl->add_region (nr, pos);
+
+ pos += len;
+ ++x;
+
+ if (*x > r->last_frame()) {
+
+ /* add final fragment */
+
+ file_start = r->start() + (pos - r->position());
+ len = r->last_frame() - pos;
+
+ nr = RegionFactory::create (r->sources(), file_start, len, new_name, 0, Region::DefaultFlags);
+ pl->add_region (nr, pos);
+
+ break;
+ }
+ }
+
+ pl->thaw ();
+
+ XMLNode& after (pl->get_state());
+
+ session->add_command (new MementoCommand<Playlist>(*pl, &before, &after));
+}
+
+void
+Editor::tab_to_transient (bool forward)
+{
+ AnalysisFeatureList positions;
+
+ if (!session) {
+ return;
+ }
+
+ nframes64_t pos = session->audible_frame ();
+
+ if (!selection->tracks.empty()) {
+
+ for (TrackSelection::iterator t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
+
+ RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*t);
+
+ if (rtv) {
+ boost::shared_ptr<Diskstream> ds = rtv->get_diskstream();
+ if (ds) {
+ boost::shared_ptr<Playlist> pl = rtv->get_diskstream()->playlist ();
+ if (pl) {
+ nframes64_t result = pl->find_next_transient (pos, forward ? 1 : -1);
+
+ if (result >= 0) {
+ positions.push_back (result);
+ }
+ }
+ }
+ }
+ }
+
+ } else {
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
+ (*r)->region()->get_transients (positions);
+ }
+ }
+
+ TransientDetector::cleanup_transients (positions, session->frame_rate(), 3.0);
+
+ if (forward) {
+ AnalysisFeatureList::iterator x;
+
+ for (x = positions.begin(); x != positions.end(); ++x) {
+ if ((*x) > pos) {
+ break;
+ }
+ }
+
+ if (x != positions.end ()) {
+ session->request_locate (*x);
+ }
+
+ } else {
+ AnalysisFeatureList::reverse_iterator x;
+
+ for (x = positions.rbegin(); x != positions.rend(); ++x) {
+ if ((*x) < pos) {
+ break;
+ }
+ }
+
+ if (x != positions.rend ()) {
+ session->request_locate (*x);
+ }
+ }
+}
+void
+Editor::playhead_forward_to_grid ()
+{
+ if (!session) return;
+ nframes64_t pos = playhead_cursor->current_frame;
+ if (pos < max_frames - 1) {
+ pos += 2;
+ snap_to_internal (pos, 1, false);
+ session->request_locate (pos);
+ }
+}
+
+
+void
+Editor::playhead_backward_to_grid ()
+{
+ if (!session) return;
+ nframes64_t pos = playhead_cursor->current_frame;
+ if (pos > 2) {
+ pos -= 2;
+ snap_to_internal (pos, -1, false);
+ session->request_locate (pos);
+ }
+}
+
+void
+Editor::set_track_height (uint32_t h)
+{
+ TrackSelection& ts (selection->tracks);
+
+ for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
+ (*x)->set_height (h);
+ }
+}
+
+void
+Editor::toggle_tracks_active ()
+{
+ TrackSelection& ts (selection->tracks);
+ bool first = true;
+ bool target = false;
+
+ if (ts.empty()) {
+ return;
+ }
+
+ for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
+ RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*x);
+
+ if (rtv) {
+ if (first) {
+ target = !rtv->_route->active();
+ first = false;
+ }
+ rtv->_route->set_active (target);
+ }
+ }
+}
+
+void
+Editor::remove_tracks ()
+{
+ TrackSelection& ts (selection->tracks);
+
+ if (ts.empty()) {
+ return;
+ }
+
+ vector<string> choices;
+ string prompt;
+ int ntracks = 0;
+ int nbusses = 0;
+ const char* trackstr;
+ const char* busstr;
+ vector<boost::shared_ptr<Route> > routes;
+
+ for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
+ RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*x);
+ if (rtv) {
+ if (rtv->is_track()) {
+ ntracks++;
+ } else {
+ nbusses++;
+ }
+ }
+ routes.push_back (rtv->_route);
+ }
+
+ if (ntracks + nbusses == 0) {
+ return;
+ }
+
+ if (ntracks > 1) {
+ trackstr = _("tracks");
+ } else {
+ trackstr = _("track");
+ }
+
+ if (nbusses > 1) {
+ busstr = _("busses");
+ } else {
+ busstr = _("bus");
+ }
+
+ if (ntracks) {
+ if (nbusses) {
+ prompt = string_compose (_("Do you really want to remove %1 %2 and %3 %4?\n"
+ "(You may also lose the playlists associated with the %2)\n\n"
+ "This action cannot be undone!"),
+ ntracks, trackstr, nbusses, busstr);
+ } else {
+ prompt = string_compose (_("Do you really want to remove %1 %2?\n"
+ "(You may also lose the playlists associated with the %2)\n\n"
+ "This action cannot be undone!"),
+ ntracks, trackstr);
+ }
+ } else if (nbusses) {
+ prompt = string_compose (_("Do you really want to remove %1 %2?"),
+ nbusses, busstr);
+ }
+
+ choices.push_back (_("No, do nothing."));
+ if (ntracks + nbusses > 1) {
+ choices.push_back (_("Yes, remove them."));
+ } else {
+ choices.push_back (_("Yes, remove it."));
+ }
+
+ Choice prompter (prompt, choices);
+
+ if (prompter.run () != 1) {
+ return;
+ }
+
+ for (vector<boost::shared_ptr<Route> >::iterator x = routes.begin(); x != routes.end(); ++x) {
+ session->remove_route (*x);
+ }
+}
+
+void
+Editor::do_insert_time ()
+{
+ if (selection->tracks.empty()) {
+ return;
+ }
+
+ ArdourDialog d (*this, _("Insert Time"));
+
+ nframes64_t const pos = get_preferred_edit_position ();
+
+ d.get_vbox()->set_border_width (12);
+ d.get_vbox()->set_spacing (4);
+
+ Table table (2, 2);
+ table.set_spacings (4);
+
+ Label time_label (_("Time to insert:"));
+ time_label.set_alignment (1, 0.5);
+ table.attach (time_label, 0, 1, 0, 1, FILL | EXPAND);
+ AudioClock clock ("insertTimeClock", true, X_("InsertTimeClock"), true, true, true);
+ clock.set (0);
+ clock.set_session (session);
+ clock.set_bbt_reference (pos);
+ table.attach (clock, 1, 2, 0, 1);
+
+ Label intersected_label (_("Intersected regions should:"));
+ intersected_label.set_alignment (1, 0.5);
+ table.attach (intersected_label, 0, 1, 1, 2, FILL | EXPAND);
+ ComboBoxText intersected_combo;
+ intersected_combo.append_text (_("stay in position"));
+ intersected_combo.append_text (_("move"));
+ intersected_combo.append_text (_("be split"));
+ intersected_combo.set_active (0);
+ table.attach (intersected_combo, 1, 2, 1, 2);
+
+ d.get_vbox()->pack_start (table);
+
+ CheckButton move_glued (_("Move glued regions"));
+ d.get_vbox()->pack_start (move_glued);
+ CheckButton move_markers (_("Move markers"));
+ d.get_vbox()->pack_start (move_markers);
+ CheckButton move_tempos (_("Move tempo and meter changes"));
+ d.get_vbox()->pack_start (move_tempos);
+
+ d.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ d.add_button (_("Insert time"), Gtk::RESPONSE_OK);
+ d.show_all ();
+
+ int response = d.run ();
+
+ if (response != RESPONSE_OK) {
+ return;
+ }
+
+ nframes64_t distance = clock.current_duration (pos);
+
+ if (distance == 0) {
+ return;
+ }
+
+ InsertTimeOption opt;
+
+ switch (intersected_combo.get_active_row_number ()) {
+ case 0:
+ opt = LeaveIntersected;
+ break;
+ case 1:
+ opt = MoveIntersected;
+ break;
+ case 2:
+ opt = SplitIntersected;
+ break;
+ }
+
+ insert_time (pos, distance, opt, move_glued.get_active(), move_markers.get_active(), move_tempos.get_active());
+}
+
+void
+Editor::insert_time (nframes64_t pos, nframes64_t frames, InsertTimeOption opt,
+ bool ignore_music_glue, bool markers_too, bool tempo_too)
+{
+ bool commit = false;
+
+ if (Config->get_edit_mode() == Lock) {
+ return;
+ }
+
+ begin_reversible_command (_("insert time"));
+
+ for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) {
+ /* regions */
+ boost::shared_ptr<Playlist> pl = (*x)->playlist();
+
+ if (pl) {
+
+ XMLNode &before = pl->get_state();
+
+ if (opt == SplitIntersected) {
+ pl->split (pos);
+ }
+
+ pl->shift (pos, frames, (opt == MoveIntersected), ignore_music_glue);
+
+ XMLNode &after = pl->get_state();
+
+ session->add_command (new MementoCommand<Playlist> (*pl, &before, &after));
+ commit = true;
+ }
+
+ /* automation */
+ RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
+ if (rtav) {
+ rtav->route ()->shift (pos, frames);
+ commit = true;
+ }
+ }
+
+ /* markers */
+ if (markers_too) {
+ bool moved = false;
+ XMLNode& before (session->locations()->get_state());
+ Locations::LocationList copy (session->locations()->list());
+
+ for (Locations::LocationList::iterator i = copy.begin(); i != copy.end(); ++i) {
+
+ Locations::LocationList::const_iterator tmp;
+
+ if ((*i)->start() >= pos) {
+ (*i)->set_start ((*i)->start() + frames);
+ if (!(*i)->is_mark()) {
+ (*i)->set_end ((*i)->end() + frames);
+ }
+ moved = true;
+ }
+ }
+
+ if (moved) {
+ XMLNode& after (session->locations()->get_state());
+ session->add_command (new MementoCommand<Locations>(*session->locations(), &before, &after));
+ }
+ }
+
+ if (tempo_too) {
+ session->tempo_map().insert_time (pos, frames);
+ }
+
+ if (commit) {
+ commit_reversible_command ();
+ }
+}
+
+void
+Editor::fit_selected_tracks ()
+{
+ fit_tracks (selection->tracks);
+}
+
+void
+Editor::fit_tracks (TrackSelection & tracks)
+{
+ if (tracks.empty()) {
+ return;
+ }
+
+ uint32_t child_heights = 0;
+
+ for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
+
+ if (!(*t)->marked_for_display()) {
+ continue;
+ }
+
+ child_heights += (*t)->effective_height() - (*t)->current_height();
+ }
+
+ uint32_t h = (uint32_t) floor ((_canvas_height - child_heights - canvas_timebars_vsize) / tracks.size());
+ double first_y_pos = DBL_MAX;
+
+ if (h < TimeAxisView::hSmall) {
+ MessageDialog msg (*this, _("There are too many tracks to fit in the current window"));
+ /* too small to be displayed */
+ return;
+ }
+
+ undo_visual_stack.push_back (current_visual_state());
+
+ /* operate on all tracks, hide unselected ones that are in the middle of selected ones */
+
+ bool prev_was_selected = false;
+ bool is_selected = tracks.contains (track_views.front());
+ bool next_is_selected;
+
+ for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
+
+ TrackViewList::iterator next;
+
+ next = t;
+ ++next;
+
+ if (next != track_views.end()) {
+ next_is_selected = tracks.contains (*next);
+ } else {
+ next_is_selected = false;
+ }
+
+ if (is_selected) {
+ (*t)->set_height (h);
+ first_y_pos = std::min ((*t)->y_position (), first_y_pos);
+ } else {
+ if (prev_was_selected && next_is_selected) {
+ hide_track_in_display (**t);
+ }
+ }
+
+ prev_was_selected = is_selected;
+ is_selected = next_is_selected;
+ }
+
+ /*
+ set the controls_layout height now, because waiting for its size
+ request signal handler will cause the vertical adjustment setting to fail
+ */
+
+ controls_layout.property_height () = full_canvas_height - canvas_timebars_vsize;
+ vertical_adjustment.set_value (first_y_pos);
+
+ redo_visual_stack.push_back (current_visual_state());
+}
+
+void
+Editor::save_visual_state (uint32_t n)
+{
+ while (visual_states.size() <= n) {
+ visual_states.push_back (0);
+ }
+
+ delete visual_states[n];
+
+ visual_states[n] = current_visual_state (true);
+ gdk_beep ();
+}
+
+void
+Editor::goto_visual_state (uint32_t n)
+{
+ if (visual_states.size() <= n) {
+ return;
+ }
+
+ if (visual_states[n] == 0) {
+ return;
+ }
+
+ use_visual_state (*visual_states[n]);
+}
+
+void
+Editor::start_visual_state_op (uint32_t n)
+{
+ if (visual_state_op_connection.empty()) {
+ visual_state_op_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::end_visual_state_op), n), 1000);
+ }
+}
+
+void
+Editor::cancel_visual_state_op (uint32_t n)
+{
+ if (!visual_state_op_connection.empty()) {
+ visual_state_op_connection.disconnect();
+ goto_visual_state (n);
+ } else {
+ //we land here if called from the menu OR if end_visual_state_op has been called
+ //so check if we are already in visual state n
+ // XXX not yet checking it at all, but redoing does not hurt
+ goto_visual_state (n);
+ }
+}
+
+bool
+Editor::end_visual_state_op (uint32_t n)
+{
+ visual_state_op_connection.disconnect();
+ save_visual_state (n);
+
+ PopUp* pup = new PopUp (WIN_POS_MOUSE, 1000, true);
+ char buf[32];
+ snprintf (buf, sizeof (buf), _("Saved view %u"), n+1);
+ pup->set_text (buf);
+ pup->touch();
+
+ return false; // do not call again