bool WaveTrack::Join(double t0, double t1) { // Merge all WaveClips overlapping selection into one WaveClipList::Node* it; WaveClipList clipsToDelete; WaveClip *newClip; for (it=GetClipIterator(); it; it=it->GetNext()) { WaveClip *clip = it->GetData(); if (clip->GetStartTime() < t1-(1.0/mRate) && clip->GetEndTime()-(1.0/mRate) > t0) { // Put in sorted order int i; for(i=0; i<clipsToDelete.GetCount(); i++) if (clipsToDelete[i]->GetStartTime() > clip->GetStartTime()) break; //printf("Insert clip %.6f at position %d\n", clip->GetStartTime(), i); clipsToDelete.Insert(i, clip); } } newClip = CreateClip(); double t = clipsToDelete[0]->GetOffset(); newClip->SetOffset(t); for(it=clipsToDelete.GetFirst(); it; it=it->GetNext()) { WaveClip *clip = it->GetData(); //printf("t=%.6f adding clip (offset %.6f, %.6f ... %.6f)\n", // t, clip->GetOffset(), clip->GetStartTime(), clip->GetEndTime()); if (clip->GetOffset() - t > (1.0 / mRate)) { double addedSilence = (clip->GetOffset() - t); //printf("Adding %.6f seconds of silence\n"); newClip->InsertSilence(t, addedSilence); t += addedSilence; } //printf("Pasting at %.6f\n", t); newClip->Paste(t, clip); t = newClip->GetEndTime(); mClips.DeleteObject(clip); delete clip; } return true; }
WaveClip::WaveClip(WaveClip& orig, DirManager *projDirManager) { // essentially a copy constructor - but you must pass in the // current project's DirManager, because we might be copying // from one project to another mOffset = orig.mOffset; mRate = orig.mRate; mSequence = new Sequence(*orig.mSequence, projDirManager); mEnvelope = new Envelope(); mEnvelope->Paste(0.0, orig.mEnvelope); mEnvelope->SetOffset(orig.GetOffset()); mEnvelope->SetTrackLen(((double)orig.mSequence->GetNumSamples()) / orig.mRate); mWaveCache = new WaveCache(1); #ifdef EXPERIMENTAL_USE_REALFFTF mWindowType = -1; mWindowSize = -1; hFFT = NULL; mWindow = NULL; #endif mSpecCache = new SpecCache(1, 1, false); mSpecPxCache = new SpecPxCache(1); for (WaveClipList::compatibility_iterator it=orig.mCutLines.GetFirst(); it; it=it->GetNext()) mCutLines.Append(new WaveClip(*it->GetData(), projDirManager)); mAppendBuffer = NULL; mAppendBufferLen = 0; mDirty = 0; mIsPlaceholder = orig.GetIsPlaceholder(); }
bool WaveClip::ExpandCutLine(double cutLinePosition) { for (WaveClipList::compatibility_iterator it = mCutLines.GetFirst(); it; it=it->GetNext()) { WaveClip* cutline = it->GetData(); if (fabs(mOffset + cutline->GetOffset() - cutLinePosition) < 0.0001) { if (!Paste(mOffset+cutline->GetOffset(), cutline)) return false; delete cutline; mCutLines.DeleteNode(it); return true; } } return false; }
bool WaveClip::Clear(double t0, double t1) { sampleCount s0, s1; TimeToSamplesClip(t0, &s0); TimeToSamplesClip(t1, &s1); if (GetSequence()->Delete(s0, s1-s0)) { // msmeyer // // Delete all cutlines that are within the given area, if any. // // Note that when cutlines are active, two functions are used: // Clear() and ClearAndAddCutLine(). ClearAndAddCutLine() is called // whenever the user directly calls a command that removes some audio, e.g. // "Cut" or "Clear" from the menu. This command takes care about recursive // preserving of cutlines within clips. Clear() is called when internal // operations want to remove audio. In the latter case, it is the right // thing to just remove all cutlines within the area. // double clip_t0 = t0; double clip_t1 = t1; if (clip_t0 < GetStartTime()) clip_t0 = GetStartTime(); if (clip_t1 > GetEndTime()) clip_t1 = GetEndTime(); WaveClipList::compatibility_iterator nextIt; for (WaveClipList::compatibility_iterator it = mCutLines.GetFirst(); it; it=nextIt) { nextIt = it->GetNext(); WaveClip* clip = it->GetData(); double cutlinePosition = mOffset + clip->GetOffset(); if (cutlinePosition >= t0 && cutlinePosition <= t1) { // This cutline is within the area, delete it delete clip; mCutLines.DeleteNode(it); } else if (cutlinePosition >= t1) { clip->Offset(clip_t0-clip_t1); } } // Collapse envelope GetEnvelope()->CollapseRegion(t0, t1); if (t0 < GetStartTime()) Offset(-(GetStartTime() - t0)); MarkChanged(); return true; } return false; }
void WaveClip::OffsetCutLines(double t0, double len) { for (WaveClipList::compatibility_iterator it = mCutLines.GetFirst(); it; it=it->GetNext()) { WaveClip* cutLine = it->GetData(); if (mOffset + cutLine->GetOffset() >= t0) cutLine->Offset(len); } }
void WaveTrack::SetOffset(double o) { double delta = o - GetOffset(); for (WaveClipList::Node* it=GetClipIterator(); it; it=it->GetNext()) { WaveClip* clip = it->GetData(); clip->SetOffset(clip->GetOffset() + delta); } mOffset = o; }
bool WaveClip::FindCutLine(double cutLinePosition, double* cutlineStart /* = NULL */, double* cutlineEnd /* = NULL */) { for (WaveClipList::compatibility_iterator it = mCutLines.GetFirst(); it; it=it->GetNext()) { WaveClip* cutline = it->GetData(); if (fabs(mOffset + cutline->GetOffset() - cutLinePosition) < 0.0001) { if (cutlineStart) *cutlineStart = mOffset+cutline->GetStartTime(); if (cutlineEnd) *cutlineEnd = mOffset+cutline->GetEndTime(); return true; } } return false; }
bool WaveClip::ClearAndAddCutLine(double t0, double t1) { if (t0 > GetEndTime() || t1 < GetStartTime()) return true; // time out of bounds WaveClip *newClip = new WaveClip(mSequence->GetDirManager(), mSequence->GetSampleFormat(), mRate); double clip_t0 = t0; double clip_t1 = t1; if (clip_t0 < GetStartTime()) clip_t0 = GetStartTime(); if (clip_t1 > GetEndTime()) clip_t1 = GetEndTime(); if (!newClip->CreateFromCopy(clip_t0, clip_t1, this)) return false; newClip->SetOffset(clip_t0-mOffset); // Sort out cutlines that belong to the new cutline WaveClipList::compatibility_iterator nextIt; for (WaveClipList::compatibility_iterator it = mCutLines.GetFirst(); it; it=nextIt) { nextIt = it->GetNext(); WaveClip* clip = it->GetData(); double cutlinePosition = mOffset + clip->GetOffset(); if (cutlinePosition >= t0 && cutlinePosition <= t1) { clip->SetOffset(cutlinePosition - newClip->GetOffset() - mOffset); newClip->mCutLines.Append(clip); mCutLines.DeleteNode(it); } else if (cutlinePosition >= t1) { clip->Offset(clip_t0-clip_t1); } } // Clear actual audio data sampleCount s0, s1; TimeToSamplesClip(t0, &s0); TimeToSamplesClip(t1, &s1); if (GetSequence()->Delete(s0, s1-s0)) { // Collapse envelope GetEnvelope()->CollapseRegion(t0, t1); if (t0 < GetStartTime()) Offset(-(GetStartTime() - t0)); MarkChanged(); mCutLines.Append(newClip); return true; } else { delete newClip; return false; } }
bool WaveTrack::Copy(double t0, double t1, Track **dest) { *dest = NULL; if (t1 <= t0) return false; WaveTrack *newTrack = new WaveTrack(mDirManager); newTrack->Init(*this); WaveClipList::Node* it; for (it=GetClipIterator(); it; it=it->GetNext()) { WaveClip *clip = it->GetData(); if (t0 <= clip->GetStartTime() && t1 >= clip->GetEndTime()) { // Whole clip is in copy region //printf("copy: clip %i is in copy region\n", (int)clip); WaveClip *newClip = new WaveClip(*clip, mDirManager); newClip->RemoveAllCutLines(); newClip->Offset(-t0); newTrack->mClips.Append(newClip); } else if (t1 > clip->GetStartTime() && t0 < clip->GetEndTime()) { // Clip is affected by command //printf("copy: clip %i is affected by command\n", (int)clip); WaveClip *newClip = new WaveClip(*clip, mDirManager); newClip->RemoveAllCutLines(); double clip_t0 = t0; double clip_t1 = t1; if (clip_t0 < clip->GetStartTime()) clip_t0 = clip->GetStartTime(); if (clip_t1 > clip->GetEndTime()) clip_t1 = clip->GetEndTime(); //printf("copy: clip_t0=%f, clip_t1=%f\n", clip_t0, clip_t1); newClip->Offset(-t0); if (newClip->GetOffset() < 0) newClip->SetOffset(0); //printf("copy: clip offset is now %f\n", newClip->GetOffset()); if (!newClip->CreateFromCopy(clip_t0, clip_t1, clip)) { //printf("paste: CreateFromCopy(%f, %f, %i) returns false, quitting\n", // clip_t0, clip_t1, (int)clip); return false; } newTrack->mClips.Append(newClip); } } *dest = newTrack; return true; }