Fix time stretch if region-start > 0

For some reason applying the property change
  plist.add (Properties::start, std::numeric_limits<timepos_t>::min());
does not correctly reset the offset of the newly created region.
This commit is contained in:
Robin Gareus 2022-09-27 03:50:52 +02:00
parent 28d11df6f6
commit 8c83149c4c
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 17 additions and 7 deletions

View File

@ -135,11 +135,13 @@ Filter::finish (boost::shared_ptr<Region> region, SourceList& nsrcs, string regi
PropertyList plist (region->properties ());
plist.add (Properties::start, std::numeric_limits<timecnt_t>::min());
plist.add (Properties::start, std::numeric_limits<timepos_t>::min());
plist.add (Properties::name, region_name);
plist.add (Properties::whole_file, true);
boost::shared_ptr<Region> r = RegionFactory::create (nsrcs, plist);
r->set_start (timepos_t(0));
r->set_whole_file (true);
results.push_back (r);
return 0;

View File

@ -1227,16 +1227,22 @@ LuaAPI::Rubberband::finalize ()
std::string region_name = RegionFactory::new_region_name (_region->name ());
PropertyList plist (_region->properties ());
plist.add (Properties::start, 0);
plist.add (Properties::length, _region->length_samples ());
plist.add (Properties::start, std::numeric_limits<timepos_t>::min());
plist.add (Properties::name, region_name);
plist.add (Properties::whole_file, true);
boost::shared_ptr<Region> r = RegionFactory::create (sl, plist);
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (r);
ar->set_ancestral_data (timepos_t (_read_start), timecnt_t (_read_len), _stretch_ratio, _pitch_ratio);
ar->set_length (ar->length ().scale (_stretch_ratio)); // XXX
ar->set_ancestral_data (timepos_t (_read_start), timecnt_t (_read_len, timepos_t (_read_start)), _stretch_ratio, _pitch_ratio);
ar->set_master_sources (_region->master_sources ());
ar->set_start (timepos_t(0));
#if 0 // TODO construct ratio_t from double
ar->set_length (ar->length ().scale (_stretch_ratio));
#else
ar->set_length (timecnt_t (_stretch_ratio * ar->length_samples (), ar->position()));
#endif
ar->set_whole_file (true);
if (_stretch_ratio != 1.0) {
// TODO: apply mapping
ar->envelope ()->x_scale (_stretch_ratio);

View File

@ -360,7 +360,8 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress* progress)
/* multiply the old (possibly previously stretched) region length by the extra
* stretch this time around to get its new length. this is a non-music based edit atm.
*/
(*x)->set_length (timecnt_t (tsr.time_fraction.to_double() * (*x)->length_samples (), (*x)->position()));
(*x)->set_length ((*x)->length ().scale (tsr.time_fraction));
(*x)->set_whole_file (true);
}
/* stretch region gain envelope */

View File

@ -304,7 +304,8 @@ STStretch::run (boost::shared_ptr<Region> r, Progress* progress)
/* multiply the old (possibly previously stretched) region length by the extra
* stretch this time around to get its new length. this is a non-music based edit atm.
*/
(*x)->set_length ((*x)->length () * tsr.time_fraction, 0);
(*x)->set_length ((*x)->length ().scale (tsr.time_fraction));
(*x)->set_whole_file (true);
}
/* stretch region gain envelope */