Update of /cvsroot/audacity/audacity-src/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv26260/src
Modified Files: WaveClip.cpp WaveClip.h WaveTrack.cpp Log Message: Add more consistent time range comparisons to WaveClip class, and a couple changes to WaveTrack::ClearAndPaste() to help eliminate zero-length clip creation in Change Speed and similar effects (much inspired by Vidyashankar's notes on zero-length clips). Changes in ChangeSpeed.cpp are mostly just replacing tabs with spaces, but also fix a recently-introduced bug in parameters to TimeWarper. Index: WaveClip.h =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/WaveClip.h,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- WaveClip.h 18 Oct 2009 19:58:17 -0000 1.41 +++ WaveClip.h 19 Nov 2009 05:02:26 -0000 1.42 @@ -97,6 +97,13 @@ sampleCount GetEndSample() const; sampleCount GetNumSamples() const { return mSequence->GetNumSamples(); } + // One and only one of the following is true for a given t (unless the clip + // has zero length -- then BeforeClip() and AfterClip() can both be true). + // Within() is true if the time is substantially within the clip + bool WithinClip(double t) const; + bool BeforeClip(double t) const; + bool AfterClip(double t) const; + bool GetSamples(samplePtr buffer, sampleFormat format, sampleCount start, sampleCount len) const; bool SetSamples(samplePtr buffer, sampleFormat format, Index: WaveTrack.cpp =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/WaveTrack.cpp,v retrieving revision 1.171 retrieving revision 1.172 diff -u -d -r1.171 -r1.172 --- WaveTrack.cpp 20 Oct 2009 23:29:17 -0000 1.171 +++ WaveTrack.cpp 19 Nov 2009 05:02:26 -0000 1.172 @@ -562,16 +562,15 @@ double st; clip = ic->GetData(); - st = LongSamplesToTime(TimeToLongSamples(clip->GetStartTime())); - // Remember split line - if (st >= t0 && st <= t1) { + // Remember clip boundaries as locations to split + st = LongSamplesToTime(TimeToLongSamples(clip->GetStartTime())); + if (st >= t0 && st <= t1 && splits.Index(st) == wxNOT_FOUND) { splits.Add(st); } - // Also remember the end of the clip st = LongSamplesToTime(TimeToLongSamples(clip->GetEndTime())); - if (st >= t0 && st <= t1) { + if (st >= t0 && st <= t1 && splits.Index(st) == wxNOT_FOUND) { splits.Add(st); } @@ -774,9 +773,8 @@ { WaveClip *clip = it->GetData(); - if (t1 > clip->GetStartTime() && t0 < clip->GetEndTime() && - (t0 + 1.0/mRate < clip->GetStartTime() || - t1 - 1.0/mRate > clip->GetEndTime())) + if (!clip->BeforeClip(t1) && !clip->AfterClip(t0) && + (clip->BeforeClip(t0) || clip->AfterClip(t1))) { addCutLines = false; break; @@ -788,12 +786,12 @@ { WaveClip *clip = it->GetData(); - if (t0 <= clip->GetStartTime() && t1 >= clip->GetEndTime()) + if (clip->BeforeClip(t0) && clip->AfterClip(t1)) { // Whole clip must be deleted - remember this clipsToDelete.Append(clip); } else - if (t1 > clip->GetStartTime() && t0 < clip->GetEndTime()) + if (!clip->BeforeClip(t1) && !clip->AfterClip(t0)) { // Clip data is affected by command if (addCutLines) @@ -805,12 +803,12 @@ if (split) { // Three cases: - if (t0 <= clip->GetStartTime()) { + if (clip->BeforeClip(t0)) { // Delete from the left edge clip->Clear(clip->GetStartTime(), t1); clip->Offset(t1-clip->GetStartTime()); } else - if (t1 >= clip->GetEndTime()) { + if (clip->AfterClip(t1)) { // Delete to right edge clip->Clear(t0, clip->GetEndTime()); } else @@ -830,7 +828,7 @@ clipsToDelete.Append(clip); } } - else { + else { // (We are not doing a split cut) /* We are going to delete part of the clip here. The clip may * have envelope points, and we need to ensure that the envelope * outside of the cleared region is not affected. This means @@ -840,13 +838,13 @@ // clip->Clear keeps points < t0 and >= t1 via Envelope::CollapseRegion if (clip->GetEnvelope()->GetNumberOfPoints() > 0) { // don't insert env pts if none exist double val; - if (t0 > clip->GetStartTime()) - { // start of clip is before start of region to clear + if (clip->WithinClip(t0)) + { // start of region within clip val = clip->GetEnvelope()->GetValue(t0); clip->GetEnvelope()->Insert(t0 - clip->GetOffset() - 1.0/clip->GetRate(), val); } - if (t1 < clip->GetEndTime()) - { // end of clip is after end of region + if (clip->WithinClip(t1)) + { // end of region within clip val = clip->GetEnvelope()->GetValue(t1); clip->GetEnvelope()->Insert(t1 - clip->GetOffset(), val); } @@ -1062,14 +1060,9 @@ { WaveClip *clip = it->GetData(); - // The 1.0/mRate is the time for one sample - kind of a fudge factor, - // because an overlap of less than a sample should not trigger - // traditional behaviour. - if (editClipCanMove) { - if (t0+src->GetEndTime()-1.0/mRate > clip->GetStartTime() && - t0 < clip->GetEndTime() - 1.0/mRate) + if (clip->WithinClip(t0)) { //printf("t0=%.6f: inside clip is %.6f ... %.6f\n", // t0, clip->GetStartTime(), clip->GetEndTime()); @@ -1078,7 +1071,9 @@ } } else { - if (t0 >= clip->GetStartTime() && t0 < clip->GetEndTime()) + // If clips are immovable we also allow prepending to clips + if (clip->WithinClip(t0) || + TimeToLongSamples(t0) == clip->GetStartSample()) { insideClip = clip; break; @@ -2041,14 +2036,15 @@ for (WaveClipList::compatibility_iterator it=GetClipIterator(); it; it=it->GetNext()) { WaveClip* c = it->GetData(); - if (t > c->GetStartTime() && t < c->GetEndTime()) + + if (c->WithinClip(t)) { double val; t = LongSamplesToTime(TimeToLongSamples(t)); // put t on a sample val = c->GetEnvelope()->GetValue(t); //make two envelope points to preserve the value. //handle the case where we split on the 1st sample (without this we hit an assert) - if(t != c->GetOffset()) + if(t - 1.0/c->GetRate() >= c->GetOffset()) c->GetEnvelope()->Insert(t - c->GetOffset() - 1.0/c->GetRate(), val); // frame end points c->GetEnvelope()->Insert(t - c->GetOffset(), val); WaveClip* newClip = new WaveClip(*c, mDirManager); Index: WaveClip.cpp =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/WaveClip.cpp,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- WaveClip.cpp 18 Oct 2009 19:58:17 -0000 1.58 +++ WaveClip.cpp 19 Nov 2009 05:02:26 -0000 1.59 @@ -411,6 +411,24 @@ return GetStartSample() + mSequence->GetNumSamples(); } +bool WaveClip::WithinClip(double t) const +{ + sampleCount ts = (sampleCount)floor(t * mRate + 0.5); + return ts > GetStartSample() && ts < GetEndSample() + mAppendBufferLen; +} + +bool WaveClip::BeforeClip(double t) const +{ + sampleCount ts = (sampleCount)floor(t * mRate + 0.5); + return ts <= GetStartSample(); +} + +bool WaveClip::AfterClip(double t) const +{ + sampleCount ts = (sampleCount)floor(t * mRate + 0.5); + return ts >= GetEndSample() + mAppendBufferLen; +} + ///Delete the wave cache - force redraw. Thread-safe void WaveClip::DeleteWaveCache() { ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Audacity-cvs mailing list Audacity-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/audacity-cvs