make bounce range and bounce region work properly (wrong boundaries before); add "Consolidate Range" which writes a new audio file and uses it to replace whatever was in the playlist within the range

git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3478 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2008-06-18 22:28:16 +00:00
parent 35b0a000c3
commit 0622d3c06a
9 changed files with 49 additions and 27 deletions

View File

@ -2021,7 +2021,8 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& items)
items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
items.push_back (SeparatorElem());
items.push_back (MenuElem (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection)));
items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
}

View File

@ -1858,7 +1858,7 @@ public:
bool write_region (string path, boost::shared_ptr<ARDOUR::AudioRegion>);
void export_region ();
void bounce_region_selection ();
void bounce_range_selection ();
void bounce_range_selection (bool replace);
void external_edit_region ();
int write_audio_selection (TimeSelection&);

View File

@ -149,7 +149,12 @@ Editor::bounce_region_selection ()
itt.cancel = false;
itt.progress = 0.0f;
track->bounce_range (region->position(), region->position() + region->length(), itt);
boost::shared_ptr<Region> r = track->bounce_range (region->position(), region->position() + region->length(), itt);
cerr << "Result of bounce of "
<< region->name() << " len = " << region->length()
<< " was "
<< r->name() << " len = " << r->length()
<< endl;
}
}

View File

@ -3614,7 +3614,7 @@ Editor::freeze_route ()
}
void
Editor::bounce_range_selection ()
Editor::bounce_range_selection (bool replace)
{
if (selection->time.empty()) {
return;
@ -3649,7 +3649,15 @@ Editor::bounce_range_selection ()
itt.progress = false;
XMLNode &before = playlist->get_state();
atv->audio_track()->bounce_range (start, cnt, itt);
boost::shared_ptr<Region> r = atv->audio_track()->bounce_range (start, start+cnt, itt);
if (replace) {
list<AudioRange> ranges;
ranges.push_back (AudioRange (start, start+cnt, 0));
playlist->cut (ranges); // discard result
playlist->add_region (r, start);
}
XMLNode &after = playlist->get_state();
session->add_command (new MementoCommand<Playlist> (*playlist, &before, &after));
}

View File

@ -58,8 +58,8 @@ class AudioTrack : public Track
void freeze (InterThreadInfo&);
void unfreeze ();
void bounce (InterThreadInfo&);
void bounce_range (nframes_t start, nframes_t end, InterThreadInfo&);
boost::shared_ptr<Region> bounce (InterThreadInfo&);
boost::shared_ptr<Region> bounce_range (nframes_t start, nframes_t end, InterThreadInfo&);
int set_state(const XMLNode& node);

View File

@ -690,8 +690,8 @@ class Session : public PBD::StatefulDestructible
/* flattening stuff */
int write_one_audio_track (AudioTrack&, nframes_t start, nframes_t cnt, bool overwrite, vector<boost::shared_ptr<AudioSource> >&,
InterThreadInfo& wot);
boost::shared_ptr<Region> write_one_audio_track (AudioTrack&, nframes_t start, nframes_t end, bool overwrite, vector<boost::shared_ptr<AudioSource> >&,
InterThreadInfo& wot);
int freeze (InterThreadInfo&);
/* session-wide solo/mute/rec-enable */

View File

@ -76,8 +76,8 @@ class Track : public Route
virtual void freeze (InterThreadInfo&) = 0;
virtual void unfreeze () = 0;
virtual void bounce (InterThreadInfo&) = 0;
virtual void bounce_range (nframes_t start, nframes_t end, InterThreadInfo&) = 0;
virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
virtual boost::shared_ptr<Region> bounce_range (nframes_t start, nframes_t end, InterThreadInfo&) = 0;
XMLNode& get_state();
XMLNode& get_template();

View File

@ -763,19 +763,20 @@ AudioTrack::export_stuff (vector<Sample*>& buffers, uint32_t nbufs, nframes_t st
return 0;
}
void
boost::shared_ptr<Region>
AudioTrack::bounce (InterThreadInfo& itt)
{
vector<boost::shared_ptr<AudioSource> > srcs;
_session.write_one_audio_track (*this, 0, _session.current_end_frame(), false, srcs, itt);
return _session.write_one_audio_track (*this, _session.current_start_frame(), _session.current_end_frame(),
false, srcs, itt);
}
void
boost::shared_ptr<Region>
AudioTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt)
{
vector<boost::shared_ptr<AudioSource> > srcs;
_session.write_one_audio_track (*this, start, end, false, srcs, itt);
return _session.write_one_audio_track (*this, start, end, false, srcs, itt);
}
void
@ -816,7 +817,9 @@ AudioTrack::freeze (InterThreadInfo& itt)
return;
}
if (_session.write_one_audio_track (*this, _session.current_start_frame(), _session.current_end_frame(), true, srcs, itt)) {
boost::shared_ptr<Region> res;
if ((res = _session.write_one_audio_track (*this, _session.current_start_frame(), _session.current_end_frame(), true, srcs, itt)) == 0) {
return;
}

View File

@ -3949,11 +3949,11 @@ Session::freeze (InterThreadInfo& itt)
return 0;
}
int
Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t len,
boost::shared_ptr<Region>
Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t end,
bool overwrite, vector<boost::shared_ptr<AudioSource> >& srcs, InterThreadInfo& itt)
{
int ret = -1;
boost::shared_ptr<Region> result;
boost::shared_ptr<Playlist> playlist;
boost::shared_ptr<AudioFileSource> fsource;
uint32_t x;
@ -3963,8 +3963,15 @@ Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t le
nframes_t position;
nframes_t this_chunk;
nframes_t to_do;
nframes_t len = end - start;
vector<Sample*> buffers;
if (end <= start) {
error << string_compose (_("Cannot write a range where end <= start (e.g. %1 <= %2)"),
end, start) << endmsg;
return result;
}
// any bigger than this seems to cause stack overflows in called functions
const nframes_t chunk_size = (128 * 1024)/4;
@ -4077,21 +4084,19 @@ Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t le
/* construct a region to represent the bounced material */
boost::shared_ptr<Region> aregion = RegionFactory::create (srcs, 0, srcs.front()->length(),
region_name_from_path (srcs.front()->name(), true));
ret = 0;
result = RegionFactory::create (srcs, 0, srcs.front()->length(),
region_name_from_path (srcs.front()->name(), true));
}
out:
if (ret) {
if (!result) {
for (vector<boost::shared_ptr<AudioSource> >::iterator src = srcs.begin(); src != srcs.end(); ++src) {
boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*src);
if (afs) {
afs->mark_for_remove ();
}
(*src)->drop_references ();
}
@ -4102,14 +4107,14 @@ Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t le
}
for (vector<Sample*>::iterator i = buffers.begin(); i != buffers.end(); ++i) {
free(*i);
free (*i);
}
g_atomic_int_set (&processing_prohibited, 0);
itt.done = true;
return ret;
return result;
}
vector<Sample*>&