Example #1
0
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();
}