bool WaveTrack::InitBlock(WaveBlock * b) { wxASSERT(b); BlockFile *f = b->f; if (!f->OpenWriting()) return false; f->Write(headerTag, headerTagLen); /* * This code shouldn't be needed because UpdateSummaries * always writes exactly what's needed. sampleCount slen = summary64KLen + summary256Len; sampleType *tempSamples = new sampleType[slen]; for(int i=0; i<slen; i++) tempSamples[i] = 0; f->Write((void *)tempSamples, sizeof(sampleType) * slen); delete[] tempSamples; */ f->Close(); return true; }
void WaveTrack::AppendAlias(wxString fullPath, sampleCount start, sampleCount len, int channel) { WaveBlock *newBlock = new WaveBlock(); newBlock->start = numSamples; newBlock->len = len; newBlock->f = dirManager->NewAliasBlockFile(totalHeaderLen, fullPath, start, len, channel); InitBlock(newBlock); BlockFile *f = newBlock->f; sampleType *buffer = new sampleType[len]; Read(buffer, newBlock, 0, len); wxASSERT(f); bool opened = f->OpenWriting(); wxASSERT(opened); UpdateSummaries(buffer, newBlock, len); f->Close(); delete[]buffer; block->Add(newBlock); numSamples += newBlock->len; envelope.SetTrackLen(numSamples / rate); }
void WaveTrack::CopyWrite(sampleType * buffer, WaveBlock * b, sampleCount start, sampleCount len) { // Usually we don't write to an existing block; to support Undo, // we copy the old block entirely into memory, dereference it, // make the change, and then write the new block to disk. wxASSERT(b); wxASSERT(b->len <= maxSamples); wxASSERT(start + len <= b->len); dirty++; // forces redraw sampleType *newBuffer = 0; newBuffer = new sampleType[maxSamples]; wxASSERT(newBuffer); Read(newBuffer, b, 0, b->len); for (int i = 0; i < len; i++) newBuffer[start + i] = buffer[i]; BlockFile *oldBlockFile = b->f; b->f = dirManager->NewBlockFile(); bool inited = InitBlock(b); wxASSERT(inited); buffer = newBuffer; start = 0; len = b->len; dirManager->Deref(oldBlockFile); // Write the block BlockFile *f = b->f; wxASSERT(f); bool opened = f->OpenWriting(); wxASSERT(opened); f->SeekTo(totalHeaderLen + (start * sizeof(sampleType))); f->Write((void *) buffer, len * sizeof(sampleType)); UpdateSummaries(buffer, b, len); if (newBuffer) delete[]newBuffer; f->Close(); }
void WaveTrack::FirstWrite(sampleType * buffer, WaveBlock * b, sampleCount len) { wxASSERT(b); wxASSERT(b->len <= maxSamples); dirty++; // forces redraw BlockFile *f = b->f; wxASSERT(f); bool opened = f->OpenWriting(); wxASSERT(opened); f->SeekTo(totalHeaderLen); f->Write((void *) buffer, len * sizeof(sampleType)); UpdateSummaries(buffer, b, len); f->Close(); }