promote Playlist::RegionList to ARDOUR::RegionList; fix timefx on multiple regions, even regions of mixed type. this mostly involved some trivial code changes but to make the code simpler and less error prone, the API switched away from using RegionSelection (list of regionviews that catches regionviews vanishing) and used RegionList (lists of regions, no semantics) instead.

git-svn-id: svn://localhost/ardour2/branches/3.0@11362 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2012-01-27 16:29:01 +00:00
parent fc3be1d42c
commit 33c61757fc
12 changed files with 112 additions and 87 deletions

View file

@ -4430,10 +4430,10 @@ Editor::get_regions_at (RegionSelection& rs, framepos_t where, const TrackViewLi
if ((tr = rtv->track()) && ((pl = tr->playlist()))) { if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
boost::shared_ptr<Playlist::RegionList> regions = pl->regions_at ( boost::shared_ptr<RegionList> regions = pl->regions_at (
(framepos_t) floor ( (double) where * tr->speed())); (framepos_t) floor ( (double) where * tr->speed()));
for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) { for (RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
RegionView* rv = rtv->view()->find_view (*i); RegionView* rv = rtv->view()->find_view (*i);
if (rv) { if (rv) {
rs.add (rv); rs.add (rv);
@ -4463,10 +4463,10 @@ Editor::get_regions_after (RegionSelection& rs, framepos_t where, const TrackVie
if ((tr = rtv->track()) && ((pl = tr->playlist()))) { if ((tr = rtv->track()) && ((pl = tr->playlist()))) {
boost::shared_ptr<Playlist::RegionList> regions = pl->regions_touched ( boost::shared_ptr<RegionList> regions = pl->regions_touched (
(framepos_t) floor ( (double)where * tr->speed()), max_framepos); (framepos_t) floor ( (double)where * tr->speed()), max_framepos);
for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) { for (RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
RegionView* rv = rtv->view()->find_view (*i); RegionView* rv = rtv->view()->find_view (*i);

View file

@ -1834,7 +1834,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
int time_stretch (RegionSelection&, float fraction); int time_stretch (RegionSelection&, float fraction);
int pitch_shift (RegionSelection&, float cents); int pitch_shift (RegionSelection&, float cents);
void pitch_shift_region (); void pitch_shift_region ();
int time_fx (RegionSelection&, float val, bool pitching);
void transpose_region (); void transpose_region ();
@ -2081,6 +2080,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
void follow_mixer_selection (); void follow_mixer_selection ();
bool _following_mixer_selection; bool _following_mixer_selection;
int time_fx (ARDOUR::RegionList&, float val, bool pitching);
friend class Drag; friend class Drag;
friend class RegionDrag; friend class RegionDrag;
friend class RegionMoveDrag; friend class RegionMoveDrag;

View file

@ -568,7 +568,7 @@ Editor::canvas_crossfade_view_event (GdkEvent* event, ArdourCanvas::Item* item,
boost::shared_ptr<AudioPlaylist> pl; boost::shared_ptr<AudioPlaylist> pl;
if ((pl = boost::dynamic_pointer_cast<AudioPlaylist> (atv->track()->playlist())) != 0) { if ((pl = boost::dynamic_pointer_cast<AudioPlaylist> (atv->track()->playlist())) != 0) {
boost::shared_ptr<Playlist::RegionList> rl = pl->regions_at (event_frame (event)); boost::shared_ptr<RegionList> rl = pl->regions_at (event_frame (event));
if (!rl->empty()) { if (!rl->empty()) {
if (atv->layer_display() == Overlaid) { if (atv->layer_display() == Overlaid) {
@ -618,7 +618,7 @@ Editor::canvas_crossfade_view_event (GdkEvent* event, ArdourCanvas::Item* item,
layer_t const l = pl->top_layer () + 1 - (cy / c); layer_t const l = pl->top_layer () + 1 - (cy / c);
/* hence region */ /* hence region */
Playlist::RegionList::iterator i = rl->begin(); RegionList::iterator i = rl->begin();
while (i != rl->end() && (*i)->layer() != l) { while (i != rl->end() && (*i)->layer() != l) {
++i; ++i;
} }

View file

@ -3304,15 +3304,16 @@ TimeFXDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
} }
#endif #endif
// XXX how do timeFX on multiple regions ? if (!_editor->get_selection().regions.empty()) {
/* primary will already be included in the selection, and edit
group shared editing will propagate selection across
equivalent regions, so just use the current region
selection.
*/
RegionSelection rs; if (_editor->time_stretch (_editor->get_selection().regions, percentage) == -1) {
rs.add (_primary); error << _("An error occurred while executing time stretch operation") << endmsg;
}
RegionSelection all = _editor->get_equivalent_regions (rs, ARDOUR::Properties::edit.property_id);
if (_editor->time_stretch (all, percentage) == -1) {
error << _("An error occurred while executing time stretch operation") << endmsg;
} }
} }

View file

@ -21,8 +21,8 @@
#include <cstdlib> #include <cstdlib>
#include <cmath> #include <cmath>
#include <ctime> #include <ctime>
#include <string> #include <string>
#include <set>
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/pthread_utils.h" #include "pbd/pthread_utils.h"
@ -63,45 +63,87 @@ using namespace Gtkmm2ext;
int int
Editor::time_stretch (RegionSelection& regions, float fraction) Editor::time_stretch (RegionSelection& regions, float fraction)
{ {
// FIXME: kludge, implement stretching of selection of both types RegionList audio;
RegionList midi;
int aret;
if (regions.front()->region()->data_type() == DataType::AUDIO) { begin_reversible_command (_("stretch/shrink"));
// Audio, pop up timefx dialog
return time_fx (regions, fraction, false);
} else {
// MIDI, just stretch
RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&regions.front()->get_time_axis_view());
if (!rtv)
return -1;
boost::shared_ptr<Playlist> playlist = rtv->track()->playlist(); for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
if ((*i)->region()->data_type() == DataType::AUDIO) {
ARDOUR::TimeFXRequest request; audio.push_back ((*i)->region());
request.time_fraction = fraction; } else if ((*i)->region()->data_type() == DataType::MIDI) {
MidiStretch stretch(*_session, request); midi.push_back ((*i)->region());
begin_reversible_command ("midi stretch"); }
stretch.run(regions.front()->region());
playlist->clear_changes ();
playlist->replace_region (regions.front()->region(), stretch.results[0],
regions.front()->region()->position());
_session->add_command (new StatefulDiffCommand (playlist));
commit_reversible_command ();
} }
if ((aret = time_fx (audio, fraction, false)) != 0) {
return aret;
}
set<boost::shared_ptr<Playlist> > midi_playlists_affected;
for (RegionList::iterator i = midi.begin(); i != midi.end(); ++i) {
boost::shared_ptr<Playlist> playlist = (*i)->playlist();
if (playlist) {
playlist->clear_changes ();
}
}
ARDOUR::TimeFXRequest request;
request.time_fraction = fraction;
for (RegionList::iterator i = midi.begin(); i != midi.end(); ++i) {
boost::shared_ptr<Playlist> playlist = (*i)->playlist();
if (!playlist) {
continue;
}
MidiStretch stretch (*_session, request);
stretch.run (*i);
playlist->replace_region (regions.front()->region(), stretch.results[0],
regions.front()->region()->position());
midi_playlists_affected.insert (playlist);
}
for (set<boost::shared_ptr<Playlist> >::iterator p = midi_playlists_affected.begin(); p != midi_playlists_affected.end(); ++p) {
_session->add_command (new StatefulDiffCommand (*p));
}
commit_reversible_command ();
return 0; return 0;
} }
int int
Editor::pitch_shift (RegionSelection& regions, float fraction) Editor::pitch_shift (RegionSelection& regions, float fraction)
{ {
return time_fx (regions, fraction, true); RegionList rl;
for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
rl.push_back ((*i)->region());
}
begin_reversible_command (_("pitch shift"));
int ret = time_fx (rl, fraction, true);
if (ret == 0) {
commit_reversible_command ();
}
return ret;
} }
/** @param val Percentage to time stretch by; ignored if pitch-shifting. /** @param val Percentage to time stretch by; ignored if pitch-shifting.
* @param pitching true to pitch shift, false to time stretch. * @param pitching true to pitch shift, false to time stretch.
* @return -1 in case of error, 1 if operation was cancelled by the user, 0 if everything went ok */ * @return -1 in case of error, 1 if operation was cancelled by the user, 0 if everything went ok */
int int
Editor::time_fx (RegionSelection& regions, float val, bool pitching) Editor::time_fx (RegionList& regions, float val, bool pitching)
{ {
delete current_timefx; delete current_timefx;
@ -264,45 +306,31 @@ Editor::time_fx (RegionSelection& regions, float val, bool pitching)
void void
Editor::do_timefx (TimeFXDialog& dialog) Editor::do_timefx (TimeFXDialog& dialog)
{ {
Track* t;
boost::shared_ptr<Playlist> playlist; boost::shared_ptr<Playlist> playlist;
boost::shared_ptr<Region> new_region; boost::shared_ptr<Region> new_region;
bool in_command = false; set<boost::shared_ptr<Playlist> > playlists_affected;
uint32_t const N = dialog.regions.size (); uint32_t const N = dialog.regions.size ();
for (RegionSelection::iterator i = dialog.regions.begin(); i != dialog.regions.end(); ) { for (RegionList::iterator i = dialog.regions.begin(); i != dialog.regions.end(); ++i) {
AudioRegionView* arv = dynamic_cast<AudioRegionView*>(*i); boost::shared_ptr<Playlist> playlist = (*i)->playlist();
if (!arv) { if (playlist) {
continue; playlist->clear_changes ();
} }
}
boost::shared_ptr<AudioRegion> region (arv->audio_region()); for (RegionList::iterator i = dialog.regions.begin(); i != dialog.regions.end(); ++i) {
TimeAxisView* tv = &(arv->get_time_axis_view());
RouteTimeAxisView* rtv;
RegionSelection::iterator tmp;
tmp = i; boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (*i);
++tmp;
if ((rtv = dynamic_cast<RouteTimeAxisView*> (tv)) == 0) { if (!region || (playlist = region->playlist()) == 0) {
i = tmp;
continue;
}
if ((t = dynamic_cast<Track*> (rtv->route().get())) == 0) {
i = tmp;
continue;
}
if ((playlist = t->playlist()) == 0) {
i = tmp;
continue; continue;
} }
if (dialog.request.cancel) { if (dialog.request.cancel) {
/* we were cancelled */ /* we were cancelled */
/* XXX what to do about playlists already affected ? */
dialog.status = 1; dialog.status = 1;
return; return;
} }
@ -331,24 +359,16 @@ Editor::do_timefx (TimeFXDialog& dialog)
if (!fx->results.empty()) { if (!fx->results.empty()) {
new_region = fx->results.front(); new_region = fx->results.front();
if (!in_command) {
_session->begin_reversible_command (dialog.pitching ? _("pitch shift") : _("time stretch"));
in_command = true;
}
playlist->clear_changes ();
playlist->replace_region (region, new_region, region->position()); playlist->replace_region (region, new_region, region->position());
_session->add_command (new StatefulDiffCommand (playlist)); playlists_affected.insert (playlist);
} }
current_timefx->ascend (); current_timefx->ascend ();
i = tmp;
delete fx; delete fx;
} }
if (in_command) { for (set<boost::shared_ptr<Playlist> >::iterator p = playlists_affected.begin(); p != playlists_affected.end(); ++p) {
_session->commit_reversible_command (); _session->add_command (new StatefulDiffCommand (*p));
} }
dialog.status = 0; dialog.status = 0;

View file

@ -2416,7 +2416,7 @@ RouteTimeAxisView::create_gain_automation_child (const Evoral::Parameter& param,
} }
static static
void add_region_to_list (RegionView* rv, Playlist::RegionList* l) void add_region_to_list (RegionView* rv, RegionList* l)
{ {
l->push_back (rv->region()); l->push_back (rv->region());
} }
@ -2435,7 +2435,7 @@ RouteTimeAxisView::combine_regions ()
return 0; return 0;
} }
Playlist::RegionList selected_regions; RegionList selected_regions;
boost::shared_ptr<Playlist> playlist = track()->playlist(); boost::shared_ptr<Playlist> playlist = track()->playlist();
_view->foreach_selected_regionview (sigc::bind (sigc::ptr_fun (add_region_to_list), &selected_regions)); _view->foreach_selected_regionview (sigc::bind (sigc::ptr_fun (add_region_to_list), &selected_regions));
@ -2466,7 +2466,7 @@ RouteTimeAxisView::uncombine_regions ()
return; return;
} }
Playlist::RegionList selected_regions; RegionList selected_regions;
boost::shared_ptr<Playlist> playlist = track()->playlist(); boost::shared_ptr<Playlist> playlist = track()->playlist();
/* have to grab selected regions first because the uncombine is going /* have to grab selected regions first because the uncombine is going
@ -2477,7 +2477,7 @@ RouteTimeAxisView::uncombine_regions ()
playlist->clear_changes (); playlist->clear_changes ();
for (Playlist::RegionList::iterator i = selected_regions.begin(); i != selected_regions.end(); ++i) { for (RegionList::iterator i = selected_regions.begin(); i != selected_regions.end(); ++i) {
playlist->uncombine (*i); playlist->uncombine (*i);
} }

View file

@ -22,6 +22,8 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "ardour/playlist.h"
#include "ardour_dialog.h" #include "ardour_dialog.h"
#include "region_selection.h" #include "region_selection.h"
#include "progress_reporter.h" #include "progress_reporter.h"
@ -40,8 +42,8 @@ public:
Gtk::SpinButton pitch_octave_spinner; Gtk::SpinButton pitch_octave_spinner;
Gtk::SpinButton pitch_semitone_spinner; Gtk::SpinButton pitch_semitone_spinner;
Gtk::SpinButton pitch_cent_spinner; Gtk::SpinButton pitch_cent_spinner;
RegionSelection regions;
Gtk::ProgressBar progress_bar; Gtk::ProgressBar progress_bar;
ARDOUR::RegionList regions;
/* SoundTouch */ /* SoundTouch */
Gtk::CheckButton quick_button; Gtk::CheckButton quick_button;

View file

@ -26,13 +26,13 @@ namespace ARDOUR {
class MidiStretch : public Filter { class MidiStretch : public Filter {
public: public:
MidiStretch (ARDOUR::Session&, TimeFXRequest&); MidiStretch (ARDOUR::Session&, const TimeFXRequest&);
~MidiStretch (); ~MidiStretch ();
int run (boost::shared_ptr<ARDOUR::Region>, Progress* progress = 0); int run (boost::shared_ptr<ARDOUR::Region>, Progress* progress = 0);
private: private:
TimeFXRequest& _request; const TimeFXRequest& _request;
}; };
} /* namespace ARDOUR */ } /* namespace ARDOUR */

View file

@ -81,7 +81,6 @@ class RegionListProperty : public PBD::SequenceProperty<std::list<boost::shared_
class Playlist : public SessionObject , public boost::enable_shared_from_this<Playlist> class Playlist : public SessionObject , public boost::enable_shared_from_this<Playlist>
{ {
public: public:
typedef std::list<boost::shared_ptr<Region> > RegionList;
static void make_property_quarks (); static void make_property_quarks ();
Playlist (Session&, const XMLNode&, DataType type, bool hidden = false); Playlist (Session&, const XMLNode&, DataType type, bool hidden = false);

View file

@ -82,6 +82,8 @@ namespace ARDOUR {
// associate a set of intervals with regions (e.g. for silence detection) // associate a set of intervals with regions (e.g. for silence detection)
typedef std::map<boost::shared_ptr<ARDOUR::Region>,AudioIntervalResult> AudioIntervalMap; typedef std::map<boost::shared_ptr<ARDOUR::Region>,AudioIntervalResult> AudioIntervalMap;
typedef std::list<boost::shared_ptr<Region> > RegionList;
struct IOChange { struct IOChange {
enum Type { enum Type {

View file

@ -33,7 +33,7 @@ using namespace std;
using namespace ARDOUR; using namespace ARDOUR;
using namespace PBD; using namespace PBD;
MidiStretch::MidiStretch (Session& s, TimeFXRequest& req) MidiStretch::MidiStretch (Session& s, const TimeFXRequest& req)
: Filter (s) : Filter (s)
, _request (req) , _request (req)
{ {

View file

@ -1634,7 +1634,7 @@ Playlist::flush_notifications (bool from_undo)
FINDING THINGS FINDING THINGS
**********************************************************************/ **********************************************************************/
boost::shared_ptr<Playlist::RegionList> boost::shared_ptr<RegionList>
Playlist::regions_at (framepos_t frame) Playlist::regions_at (framepos_t frame)
{ {
RegionLock rlock (this); RegionLock rlock (this);
@ -1703,7 +1703,7 @@ Playlist::regions_at (framepos_t frame)
return region; return region;
} }
boost::shared_ptr<Playlist::RegionList> boost::shared_ptr<RegionList>
Playlist::regions_to_read (framepos_t start, framepos_t end) Playlist::regions_to_read (framepos_t start, framepos_t end)
{ {
/* Caller must hold lock */ /* Caller must hold lock */
@ -1838,7 +1838,7 @@ Playlist::regions_to_read (framepos_t start, framepos_t end)
return rlist; return rlist;
} }
boost::shared_ptr<Playlist::RegionList> boost::shared_ptr<RegionList>
Playlist::find_regions_at (framepos_t frame) Playlist::find_regions_at (framepos_t frame)
{ {
/* Caller must hold lock */ /* Caller must hold lock */
@ -1854,7 +1854,7 @@ Playlist::find_regions_at (framepos_t frame)
return rlist; return rlist;
} }
boost::shared_ptr<Playlist::RegionList> boost::shared_ptr<RegionList>
Playlist::regions_touched (framepos_t start, framepos_t end) Playlist::regions_touched (framepos_t start, framepos_t end)
{ {
RegionLock rlock (this); RegionLock rlock (this);