void Editor::close_region_gaps () { list > used_playlists; RegionSelection rs = get_regions_from_selection_and_entered (); if (!_session || rs.empty()) { return; } Dialog dialog (_("Close Region Gaps")); Table table (2, 3); table.set_spacings (12); table.set_border_width (12); Label* l = manage (left_aligned_label (_("Crossfade length"))); table.attach (*l, 0, 1, 0, 1); SpinButton spin_crossfade (1, 0); spin_crossfade.set_range (0, 15); spin_crossfade.set_increments (1, 1); spin_crossfade.set_value (5); table.attach (spin_crossfade, 1, 2, 0, 1); table.attach (*manage (new Label (_("ms"))), 2, 3, 0, 1); l = manage (left_aligned_label (_("Pull-back length"))); table.attach (*l, 0, 1, 1, 2); SpinButton spin_pullback (1, 0); spin_pullback.set_range (0, 100); spin_pullback.set_increments (1, 1); spin_pullback.set_value(10); table.attach (spin_pullback, 1, 2, 1, 2); table.attach (*manage (new Label (_("ms"))), 2, 3, 1, 2); dialog.get_vbox()->pack_start (table); dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL); dialog.add_button (_("Ok"), RESPONSE_ACCEPT); dialog.show_all (); if (dialog.run () == RESPONSE_CANCEL) { return; } framepos_t crossfade_len = spin_crossfade.get_value(); framepos_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 */ begin_reversible_command (_("close region gaps")); int idx = 0; boost::shared_ptr last_region; rs.sort_by_position_and_track(); for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { boost::shared_ptr pl = (*r)->region()->playlist(); if (!pl->frozen()) { /* we haven't seen this playlist before */ /* remember used playlists so we can thaw them later */ used_playlists.push_back(pl); pl->freeze(); } framepos_t position = (*r)->region()->position(); if (idx == 0 || position < last_region->position()){ last_region = (*r)->region(); idx++; continue; } framepos_t last_region_position = last_region->position(); framecnt_t last_region_length = last_region->length(); framepos_t last_region_end = (last_region_position + last_region_length); if ((last_region_end - pull_back_frames) > (position - crossfade_len)){ (*r)->region()->trim_front( (position - pull_back_frames)); last_region->trim_end( (position - pull_back_frames + crossfade_len)); } else { (*r)->region()->trim_front( (last_region_end - pull_back_frames - crossfade_len)); last_region->trim_end( (last_region_end - pull_back_frames)); } last_region = (*r)->region(); idx++; } while (used_playlists.size() > 0) { list >::iterator i = used_playlists.begin(); (*i)->thaw(); used_playlists.pop_front(); } commit_reversible_command (); }