diff --git a/gtk2_ardour/ardour.menus.in b/gtk2_ardour/ardour.menus.in index 2f055bc6b8..cdea270207 100644 --- a/gtk2_ardour/ardour.menus.in +++ b/gtk2_ardour/ardour.menus.in @@ -414,6 +414,7 @@ + diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 824fec95c4..57f03094f1 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -579,6 +579,7 @@ public: void split_regions_at (ARDOUR::MusicSample, RegionSelection&); void split_region_at_points (boost::shared_ptr, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false); RegionSelection get_regions_from_selection_and_mouse (samplepos_t); + void remove_gaps (); void mouse_add_new_tempo_event (samplepos_t where); void mouse_add_new_meter_event (samplepos_t where); diff --git a/gtk2_ardour/editor_actions.cc b/gtk2_ardour/editor_actions.cc index 8230421aa6..26f66d0ba3 100644 --- a/gtk2_ardour/editor_actions.cc +++ b/gtk2_ardour/editor_actions.cc @@ -455,6 +455,10 @@ Editor::register_actions () ActionManager::session_sensitive_actions.push_back (act); ActionManager::track_selection_sensitive_actions.push_back (act); + act = reg_sens (editor_actions, "remove-gaps", _("Remove Gaps"), (sigc::mem_fun(*this, &Editor::remove_gaps))); + ActionManager::track_selection_sensitive_actions.push_back (act); + ActionManager::session_sensitive_actions.push_back (act); + act = reg_sens (editor_actions, "toggle-track-active", _("Toggle Active"), (sigc::mem_fun(*this, &Editor::toggle_tracks_active))); ActionManager::route_selection_sensitive_actions.push_back (act); diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 94a9bdcaa9..c3b6106ef9 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -8922,3 +8922,58 @@ Editor::make_region_markers_global (bool as_cd_marker) commit_reversible_command (); } } + +void +Editor::remove_gaps () +{ + bool in_command = false; + TrackViewList ts = selection->tracks.filter_to_unique_playlists (); + bool all_playlists = false; + + for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { + + /* don't operate on any playlist more than once, which could + * happen if "all playlists" is enabled, but there is more + * than 1 track using playlists "from" a given track. + */ + + set > pl; + + if (all_playlists) { + RouteTimeAxisView* rtav = dynamic_cast (*x); + if (rtav && rtav->track ()) { + vector > all = _session->playlists()->playlists_for_track (rtav->track ()); + for (vector >::iterator p = all.begin(); p != all.end(); ++p) { + pl.insert (*p); + } + } + } else { + if ((*x)->playlist ()) { + pl.insert ((*x)->playlist ()); + } + } + + for (set >::iterator i = pl.begin(); i != pl.end(); ++i) { + + (*i)->clear_changes (); + (*i)->clear_owned_changes (); + + if (!in_command) { + begin_reversible_command (_("remove gaps")); + in_command = true; + } + + (*i)->remove_gaps (24000, 4410); + + vector cmds; + (*i)->rdiff (cmds); + _session->add_commands (cmds); + + _session->add_command (new StatefulDiffCommand (*i)); + } + } + + if (in_command) { + commit_reversible_command (); + } +}