+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ nframes64_t where = get_preferred_edit_position();
+
+ _session->begin_reversible_command (_("place transient"));
+
+ for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
+ framepos_t position = (*r)->region()->position();
+ (*r)->region()->add_transient(where - position);
+ }
+
+ _session->commit_reversible_command ();
+}
+
+void
+Editor::remove_transient(ArdourCanvas::Item* item)
+{
+ if (!_session) {
+ return;
+ }
+
+ ArdourCanvas::SimpleLine* _line = reinterpret_cast<ArdourCanvas::SimpleLine*> (item);
+ assert (_line);
+
+ AudioRegionView* _arv = reinterpret_cast<AudioRegionView*> (item->get_data ("regionview"));
+ _arv->remove_transient(_line->property_x1());
+}
+
+void
+Editor::snap_regions_to_grid()
+{
+ if (!_session) {
+ return;
+ }
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ _session->begin_reversible_command (_("snap regions to grid"));
+
+ for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
+ framepos_t start_frame = (*r)->region()->first_frame ();
+ snap_to (start_frame);
+ (*r)->region()->set_position (start_frame, this);
+ }
+
+ _session->commit_reversible_command ();
+}
+
+void
+Editor::close_region_gaps()
+{
+ if (!_session) {
+ return;
+ }
+
+ RegionSelection rs;
+
+ get_regions_for_action (rs);
+
+ if (rs.empty()) {
+ return;
+ }
+
+ Dialog dialog (rs.size() > 1 ? _("Conform regions") : _("Conform region"));
+
+ HBox hbox_crossfade;
+ hbox_crossfade.set_spacing (10);
+ //hbox_crossfade.set_border_width (3);
+ hbox_crossfade.pack_start (*manage (new Label (_("Crossfade length:"))));
+
+ SpinButton spin_crossfade (1, 0);
+ spin_crossfade.set_range (0, 15);
+ spin_crossfade.set_increments (1, 1);
+ spin_crossfade.set_value (3);
+
+ hbox_crossfade.pack_start (spin_crossfade);
+ hbox_crossfade.pack_start (*manage (new Label (_("ms"))));
+ hbox_crossfade.show_all ();
+
+ HBox hbox_pullback;
+
+ hbox_pullback.set_spacing (10);
+ //hbox_pullback.set_border_width (3);
+ hbox_pullback.pack_start (*manage (new Label (_("Pull-back length:"))));
+
+ SpinButton spin_pullback (1, 0);
+ spin_pullback.set_range (0, 15);
+ spin_pullback.set_increments (1, 1);
+ spin_pullback.set_value (5);
+
+ hbox_pullback.pack_start (spin_pullback);
+ hbox_pullback.pack_start (*manage (new Label (_("ms"))));
+ hbox_pullback.show_all ();
+
+ dialog.get_vbox()->set_spacing (6);
+ dialog.get_vbox()->pack_start (hbox_crossfade);
+ dialog.get_vbox()->pack_start (hbox_pullback);
+ dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
+ dialog.add_button (_("Ok"), RESPONSE_ACCEPT);
+
+ if (dialog.run () == RESPONSE_CANCEL) {
+ return;
+ }
+
+ nframes64_t crossfade_len = spin_crossfade.get_value();
+ nframes64_t pull_back_frames = spin_pullback.get_value();
+
+ crossfade_len = lrintf (crossfade_len * _session->frame_rate()/1000);
+ pull_back_frames = lrintf (pull_back_frames * _session->frame_rate()/1000);
+
+ /* Iterate over the region list and make adjacent regions overlap by crossfade_len_ms */
+
+ _session->begin_reversible_command (_("close region gaps"));
+
+ int idx = 0;
+ boost::shared_ptr<Region> last_region;
+
+ rs.sort_by_position_and_track();
+
+ for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
+
+ nframes64_t position = (*r)->region()->position();
+
+ if (idx == 0 || position < last_region->position()){
+ last_region = (*r)->region();
+ idx++;
+ continue;
+ }
+
+ (*r)->region()->trim_front( (position - pull_back_frames), this );
+ last_region->trim_end( (position - pull_back_frames + crossfade_len), this );
+
+ last_region = (*r)->region();
+
+ idx++;
+ }
+
+ _session->commit_reversible_command ();