本文整理汇总了C++中BlockFile类的典型用法代码示例。如果您正苦于以下问题:C++ BlockFile类的具体用法?C++ BlockFile怎么用?C++ BlockFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlockFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wxHashTable
void DirManager::CheckHashTableSize()
{
// This method makes sure that our hash table doesn't fill up.
// When it's about halfway full (i.e. starting to exceed its
// capacity), we create a new hash table with double the size,
// and copy everything over.
if (blockFileHash->GetCount() >= hashTableSize/2) {
wxBusyCursor busy;
hashTableSize *= 2;
wxHashTable *newHash = new wxHashTable(wxKEY_STRING, hashTableSize);
blockFileHash->BeginFind();
wxNode *n = blockFileHash->Next();
while(n) {
BlockFile *b = (BlockFile *)n->GetData();
newHash->Put(b->GetName(), (wxObject *) b);
n = blockFileHash->Next();
}
delete blockFileHash;
blockFileHash = newHash;
}
}
示例2: WaveBlock
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);
}
示例3: FindDependencies
// True = success
bool FindDependencies(AudacityProject *project,
AliasedFileArray *outAliasedFiles)
{
sampleFormat format = project->GetDefaultFormat();
BlockArray blocks;
GetAllSeqBlocks(project, &blocks);
AliasedFileHash aliasedFileHash;
BoolBlockFileHash blockFileHash;
int i;
for(i=0; i<(int)blocks.GetCount(); i++) {
BlockFile *f = blocks[i]->f;
if (f->IsAlias() && !blockFileHash[f]) {
blockFileHash[f] = true; // Don't count the same blockfile twice
AliasBlockFile *aliasBlockFile = (AliasBlockFile *)f;
wxFileName fileName = aliasBlockFile->GetAliasedFile();
wxString fileNameStr = fileName.GetFullPath();
int blockBytes = (SAMPLE_SIZE(format) *
aliasBlockFile->GetLength());
if (aliasedFileHash[fileNameStr])
aliasedFileHash[fileNameStr]->bytes += blockBytes;
else {
outAliasedFiles->Add(AliasedFile(fileName, blockBytes));
aliasedFileHash[fileNameStr] =
&((*outAliasedFiles)[outAliasedFiles->GetCount()-1]);
}
}
}
return true;
}
示例4: testFileValidity
void testFileValidity() {
// Use libsndfile to read the file. Make sure:
// 1. it is correctly recognized as an AU file
// 2. it has all the header information we expect
std::cout << "\tthe created files should be valid AU files with the expected number of samples...";
std::cout << std::flush;
BlockFile *theFiles[] = {int16BlockFile, int24BlockFile, floatBlockFile};
for(int i = 0; i < 3; i++)
{
BlockFile *bf = theFiles[i];
SF_INFO info;
memset(&info, 0, sizeof(info));
SNDFILE *sf = sf_open(bf->GetFileName().GetFullPath(), SFM_READ, &info);
assert(sf);
assert(info.frames == dataLen);
assert(info.channels == 1);
assert(info.format & SF_FORMAT_AU);
sf_close(sf);
}
std::cout << "OK\n";
}
示例5: wxASSERT
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;
}
示例6: wxASSERT
BlockFile *DirManager::LoadBlockFile(wxTextFile * in, sampleFormat format)
{
wxASSERT(projFull != "");
long summaryLen;
if (!(in->GetNextLine().ToLong(&summaryLen)))
return NULL;
wxString blockName = in->GetNextLine();
bool alias = false;
wxString aliasFullPath;
long localLen, start, len, channel;
if (blockName == "Alias") {
alias = true;
aliasFullPath = in->GetNextLine();
//if (!(in->GetNextLine().ToLong(&localLen)))
// return NULL;
if (!(in->GetNextLine().ToLong(&start)))
return NULL;
if (!(in->GetNextLine().ToLong(&len)))
return NULL;
if (!(in->GetNextLine().ToLong(&channel)))
return NULL;
blockName = in->GetNextLine();
}
wxString pathName = projFull + wxFILE_SEP_PATH + blockName;
BlockFile *retrieved = (BlockFile *) blockFileHash->Get(blockName);
if (retrieved) {
wxASSERT(retrieved->IsAlias() == alias);
retrieved->Ref();
return retrieved;
} else {
BlockFile *newBlockFile =
new BlockFile(blockName, pathName, summaryLen);
if (alias) {
newBlockFile->SetAliasedData(aliasFullPath, start, len, channel);
aliasList.Add(aliasFullPath);
}
newBlockFile->mSampleFormat = format;
blockFileHash->Put(blockName, (wxObject *) newBlockFile);
CheckHashTableSize();
if (!wxFileExists(pathName))
return 0;
return newBlockFile;
}
}
示例7: iter
// get the sum of the sizes of all blocks this track list
// references. However, if a block is referred to multiple
// times it is only counted once. Return value is in bytes.
wxLongLong UndoManager::CalculateSpaceUsage(int index)
{
TrackListOfKindIterator iter(Track::Wave);
WaveTrack *wt;
WaveClipList::compatibility_iterator it;
BlockArray *blocks;
unsigned int i;
// get a map of all blocks referenced in this TrackList
std::map<BlockFile*, wxLongLong> cur;
wt = (WaveTrack *) iter.First(stack[index]->tracks);
while (wt) {
for (it = wt->GetClipIterator(); it; it = it->GetNext()) {
blocks = it->GetData()->GetSequenceBlockArray();
for (i = 0; i < blocks->GetCount(); i++)
{
BlockFile* pBlockFile = blocks->Item(i)->f;
if (pBlockFile->GetFileName().FileExists())
cur[pBlockFile] = pBlockFile->GetSpaceUsage();
}
}
wt = (WaveTrack *) iter.Next();
}
if (index > 0) {
// get a set of all blocks referenced in all prev TrackList
std::set<BlockFile*> prev;
while (--index) {
wt = (WaveTrack *) iter.First(stack[index]->tracks);
while (wt) {
for (it = wt->GetClipIterator(); it; it = it->GetNext()) {
blocks = it->GetData()->GetSequenceBlockArray();
for (i = 0; i < blocks->GetCount(); i++) {
prev.insert(blocks->Item(i)->f);
}
}
wt = (WaveTrack *) iter.Next();
}
}
// remove all blocks in prevBlockFiles from curBlockFiles
std::set<BlockFile*>::const_iterator prevIter;
for (prevIter = prev.begin(); prevIter != prev.end(); prevIter++) {
cur.erase(*prevIter);
}
}
// sum the sizes of the blocks remaining in curBlockFiles;
wxLongLong bytes = 0;
std::map<BlockFile*, wxLongLong>::const_iterator curIter;
for (curIter = cur.begin(); curIter != cur.end(); curIter++) {
bytes += curIter->second;
}
return bytes;
}
示例8: TIMER_START
void UndoManager::CalculateSpaceUsage()
{
TIMER_START( "CalculateSpaceUsage", space_calc );
TrackListOfKindIterator iter(Track::Wave);
space.Clear();
space.Add(0, stack.GetCount());
Set s1, s2;
Set *prev = &s1;
Set *cur = &s2;
for (size_t i = 0, cnt = stack.GetCount(); i < cnt; i++)
{
// Swap map pointers
std::swap(cur, prev);
// And clean out the NEW current map
cur->clear();
// Scan all tracks at current level
WaveTrack *wt = (WaveTrack *) iter.First(stack[i]->tracks);
while (wt)
{
// Scan all clips within current track
WaveClipList::compatibility_iterator it = wt->GetClipIterator();
while (it)
{
// Scan all blockfiles within current clip
BlockArray *blocks = it->GetData()->GetSequenceBlockArray();
for (size_t b = 0, cnt = blocks->size(); b < cnt; b++)
{
BlockFile *file = (*blocks)[b].f;
// Accumulate space used by the file if the file didn't exist
// in the previous level
if (prev->count(file) == 0 && cur->count(file) == 0)
{
space[i] += file->GetSpaceUsage().GetValue();
}
// Add file to current set
cur->insert(file);
}
it = it->GetNext();
}
wt = (WaveTrack *) iter.Next();
}
}
TIMER_STOP( space_calc );
}
示例9: wxASSERT
BlockFile *DirManager::LoadBlockFile(wxTextFile * in)
{
wxASSERT(projFull != "");
wxString blockName = in->GetNextLine();
bool alias = false;
wxString aliasFullPath;
long localLen, start, len, channel;
if (blockName == "Alias") {
alias = true;
aliasFullPath = in->GetNextLine();
if (!(in->GetNextLine().ToLong(&localLen)))
return NULL;
if (!(in->GetNextLine().ToLong(&start)))
return NULL;
if (!(in->GetNextLine().ToLong(&len)))
return NULL;
if (!(in->GetNextLine().ToLong(&channel)))
return NULL;
blockName = in->GetNextLine();
}
wxString pathName = projFull + pathChar + blockName;
BlockFile *retrieved = (BlockFile *) blockFileHash->Get(blockName);
if (retrieved) {
wxASSERT(retrieved->IsAlias() == alias);
retrieved->Ref();
return retrieved;
} else {
BlockFile *newBlockFile;
if (alias) {
newBlockFile = new BlockFile(blockName, pathName,
localLen,
aliasFullPath, start, len, channel);
aliasList.Add(aliasFullPath);
}
else
newBlockFile = new BlockFile(blockName, pathName);
blockFileHash->Put(blockName, (wxObject *) newBlockFile);
CheckHashTableSize();
if (!wxFileExists(pathName))
return 0;
return newBlockFile;
}
}
示例10: system
void
FaultyBlockFileUnitTest::setUp()
{
// cout << "FaultyBlockFileUnitTest::setUp()" << endl ;
system("rm -f /tmp/newblockfile*") ; // Important. Otherwise state is left between tests.
BlockFile *bfp = new BlockFile("/tmp/newblockfile") ;
assert(bfp->create(1, 10, 1024));
bf = new FaultyBlockFile(bfp);
//tb1 = new Block() ;
//tb2 = new Block() ;
}
示例11: FindDependencies
void FindDependencies(AudacityProject *project,
AliasedFileArray *outAliasedFiles)
{
sampleFormat format = project->GetDefaultFormat();
BlockArray blocks;
GetAllSeqBlocks(project, &blocks);
AliasedFileHash aliasedFileHash;
BoolBlockFileHash blockFileHash;
int i;
for (i = 0; i < (int)blocks.GetCount(); i++) {
BlockFile *f = blocks[i]->f;
if (f->IsAlias() && (blockFileHash.count(f) == 0))
{
// f is an alias block we have not yet counted.
blockFileHash[f] = true; // Don't count the same blockfile twice.
AliasBlockFile *aliasBlockFile = (AliasBlockFile *)f;
wxFileName fileName = aliasBlockFile->GetAliasedFileName();
// In DirManager::ProjectFSCK(), if the user has chosen to
// "Replace missing audio with silence", the code there puts in an empty wxFileName.
// Don't count those in dependencies.
if (!fileName.IsOk())
continue;
wxString fileNameStr = fileName.GetFullPath();
int blockBytes = (SAMPLE_SIZE(format) *
aliasBlockFile->GetLength());
if (aliasedFileHash.count(fileNameStr) > 0)
// Already put this AliasBlockFile in aliasedFileHash.
// Update block count.
aliasedFileHash[fileNameStr]->mByteCount += blockBytes;
else
{
// Haven't counted this AliasBlockFile yet.
// Add to return array and internal hash.
outAliasedFiles->Add(AliasedFile(fileName,
blockBytes,
fileName.FileExists()));
aliasedFileHash[fileNameStr] =
&((*outAliasedFiles)[outAliasedFiles->GetCount()-1]);
}
}
}
}
示例12: Load
//
// Load
//
// Load system data
//
void Load(BlockFile &bFile)
{
// Get the size of the block
U32 size;
// Open the data block
bFile.OpenBlock(SAVEBLOCK, TRUE, &size);
// Expected size of buffer
U32 bufferSize = WorldCtrl::CellMapX() * WorldCtrl::CellMapZ();
// Check the block size
if (bufferSize == size)
{
// Get the start of the buffer
Game::TeamBitfield *ptr = (Game::TeamBitfield *)(bFile.GetBlockPtr());
// Iterate through each cell
for (U32 i = 0; i < bufferSize; ++i)
{
// Setup the team bits
for (U32 team = 0; team < teamCount; team++)
{
if (Game::TeamTest(*ptr, team))
{
seeMap[0][team][0][i] |= SEENMASK;
}
}
// Move to next cell
++ptr;
}
}
else
{
LOG_WARN(("Sight: Save block was unexpected size (%d/%d)", size, bufferSize));
}
// Done
bFile.CloseBlock();
// Ensure display gets updated for new data
DirtyAllCells();
}
示例13: while
void DirManager::FillBlockfilesCache()
{
bool cacheBlockFiles = false;
gPrefs->Read(wxT("/Directories/CacheBlockFiles"), &cacheBlockFiles);
if (!cacheBlockFiles)
return; // user opted not to cache block files
BlockHash::iterator i;
int numNeed = 0;
i = blockFileHash.begin();
while (i != blockFileHash.end())
{
BlockFile *b = i->second;
if (b->GetNeedFillCache())
numNeed++;
i++;
}
if (numNeed == 0)
return;
AudacityProject *p = GetActiveProject();
p->ProgressShow(_("Caching audio"),
_("Caching audio into memory..."));
i = blockFileHash.begin();
int current = 0;
while (i != blockFileHash.end())
{
BlockFile *b = i->second;
if (b->GetNeedFillCache())
b->FillCache();
if (!p->ProgressUpdate((int)((current * 1000.0) / numNeed)))
break; // user cancelled progress dialog, stop caching
i++;
current++;
}
p->ProgressHide();
}
示例14: wxASSERT
bool Sequence::Read(samplePtr buffer, sampleFormat format,
SeqBlock * b, sampleCount start, sampleCount len) const
{
wxASSERT(b);
wxASSERT(start >= 0);
wxASSERT(start + len <= b->len);
BlockFile *f = b->f;
int result = f->ReadData(buffer, format, start, len);
if (result != len) {
// TODO err
printf(_("Expected to read %d samples, got %d samples.\n"),
len, result);
}
return true;
}
示例15: ConvertToSampleFormat
bool Sequence::ConvertToSampleFormat(sampleFormat format)
{
if (format == mSampleFormat)
return true;
if (mBlock->Count() == 0) {
mSampleFormat = format;
return true;
}
sampleFormat oldFormat = mSampleFormat;
mSampleFormat = format;
for (unsigned int i = 0; i < mBlock->Count(); i++) {
BlockFile *oldBlock = mBlock->Item(i)->f;
sampleCount len = mBlock->Item(i)->len;
if (!oldBlock->IsAlias()) {
BlockFile *newBlock =
mDirManager->NewBlockFile(mSummary->totalSummaryBytes);
samplePtr buffer1 = NewSamples(len, oldFormat);
samplePtr buffer2 = NewSamples(len, mSampleFormat);
oldBlock->ReadData(buffer1, oldFormat, 0, len);
CopySamples(buffer1, oldFormat,
buffer2, mSampleFormat, len);
newBlock->WriteData(buffer2, mSampleFormat, len);
mBlock->Item(i)->f = newBlock;
mDirManager->Deref(oldBlock);
UpdateSummaries(buffer2, mBlock->Item(i), len);
DeleteSamples(buffer2);
DeleteSamples(buffer1);
}
}
return true;
}