Update of /cvsroot/audacity/audacity-src/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv25902

Modified Files:
        BlockFile.h DirManager.cpp DirManager.h Project.cpp Project.h 
        Sequence.cpp 
Log Message:
Implement block files cache (without limit/LRU so far)

Index: Project.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.h,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- Project.h   17 Oct 2006 12:28:52 -0000      1.111
+++ Project.h   6 Nov 2006 10:20:50 -0000       1.112
@@ -325,6 +325,8 @@
    
    static wxString GetImportFilesFilter();
 
+   static bool GetCacheBlockFiles();
+
    // Callbacks for backend operations
 
    bool mUserCanceledProgress;

Index: DirManager.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/DirManager.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- DirManager.h        23 Sep 2006 02:28:04 -0000      1.33
+++ DirManager.h        6 Nov 2006 10:20:49 -0000       1.34
@@ -52,8 +52,11 @@
 
    wxLongLong GetFreeDiskSpace();
 
-   BlockFile *NewSimpleBlockFile(samplePtr sampleData, sampleCount sampleLen,
-                                 sampleFormat format);
+   BlockFile *NewSimpleBlockFile(samplePtr sampleData,
+                                 sampleCount sampleLen,
+                                 sampleFormat format,
+                                 bool allowDeferredWrite = false);
+                                 
    BlockFile *NewAliasBlockFile( wxString aliasedFile, sampleCount aliasStart,
                                  sampleCount aliasLen, int aliasChannel);
 
@@ -123,6 +126,12 @@
    // Do not delete any temporary files on exit. This is only called if
    // auto recovery is cancelled and should be retried later
    static void SetDontDeleteTempFiles() { dontDeleteTempFiles = true; }
+   
+   // Write all write-cached block files to disc, if any
+   void WriteCacheToDisk();
+
+   // Fill cache of blockfiles, if caching is enabled (otherwise do nothing)
+   void FillBlockfilesCache();
 
  private:
 

Index: BlockFile.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/BlockFile.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- BlockFile.h 4 Nov 2006 19:55:20 -0000       1.20
+++ BlockFile.h 6 Nov 2006 10:20:49 -0000       1.21
@@ -55,6 +55,14 @@
                         sampleCount start, sampleCount len) = 0;
 
    // Other Properties
+   
+   // Write cache to disk, if it has any
+   virtual bool GetNeedWriteCacheToDisk() { return false; }
+   virtual void WriteCacheToDisk() { /* no cache by default */ }
+
+   // Fill read cache of block file, if it has any
+   virtual bool GetNeedFillCache() { return false; }
+   virtual void FillCache() { /* no cache by default */ }
 
    /// Stores a representation of this file in XML
    virtual void SaveXML(XMLWriter &xmlFile) = 0;

Index: DirManager.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/DirManager.cpp,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- DirManager.cpp      25 Sep 2006 01:15:30 -0000      1.73
+++ DirManager.cpp      6 Nov 2006 10:20:49 -0000       1.74
@@ -735,12 +735,14 @@
 
 BlockFile *DirManager::NewSimpleBlockFile(
                                  samplePtr sampleData, sampleCount sampleLen,
-                                 sampleFormat format)
+                                 sampleFormat format,
+                                 bool allowDeferredWrite)
 {
    wxFileName fileName = MakeBlockFileName();
 
    BlockFile *newBlockFile =
-       new SimpleBlockFile(fileName, sampleData, sampleLen, format);
+       new SimpleBlockFile(fileName, sampleData, sampleLen, format,
+                           allowDeferredWrite);
 
    blockFileHash[fileName.GetName()]=newBlockFile;
 
@@ -1399,6 +1401,90 @@
    }
 }
 
+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();
+}
+
+void DirManager::WriteCacheToDisk()
+{
+   BlockHash::iterator i;
+   int numNeed = 0;
+
+   i = blockFileHash.begin();
+   while (i != blockFileHash.end())
+   {
+      BlockFile *b = i->second;
+      if (b->GetNeedWriteCacheToDisk())
+         numNeed++;
+      i++;
+   }
+   
+   if (numNeed == 0)
+      return;
+      
+   AudacityProject *p = GetActiveProject();
+   
+   p->ProgressShow(_("Saving recorded audio"),
+      _("Saving recorded audio to disk..."));
+
+   i = blockFileHash.begin();
+   int current = 0;
+   while (i != blockFileHash.end())
+   {
+      BlockFile *b = i->second;
+      if (b->GetNeedWriteCacheToDisk())
+      {
+         b->WriteCacheToDisk();
+         p->ProgressUpdate((int)((current * 1000.0) / numNeed));
+      }
+      i++;
+      current++;
+   }
+   
+   p->ProgressHide();
+}
+
+
 // Indentation settings for Vim and Emacs and unique identifier for Arch, a
 // version control system. Please do not modify past this point.
 //

Index: Sequence.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Sequence.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- Sequence.cpp        23 Sep 2006 02:28:04 -0000      1.38
+++ Sequence.cpp        6 Nov 2006 10:20:50 -0000       1.39
@@ -1136,7 +1136,8 @@
       int newLastBlockLen = lastBlock->f->GetLength() + addLen;
 
       newLastBlock->f =
-         mDirManager->NewSimpleBlockFile(buffer2, newLastBlockLen, 
mSampleFormat);
+         mDirManager->NewSimpleBlockFile(buffer2, newLastBlockLen, 
mSampleFormat,
+                                         blockFileLog != NULL);
       if (blockFileLog)
          ((SimpleBlockFile*)newLastBlock->f)->SaveXML(*blockFileLog);
          
@@ -1158,11 +1159,13 @@
       w->start = mNumSamples;
 
       if (format == mSampleFormat) {
-         w->f = mDirManager->NewSimpleBlockFile(buffer, l, mSampleFormat);
+         w->f = mDirManager->NewSimpleBlockFile(buffer, l, mSampleFormat,
+                                                blockFileLog != NULL);
       }
       else {
          CopySamples(buffer, format, temp, mSampleFormat, l);
-         w->f = mDirManager->NewSimpleBlockFile(temp, l, mSampleFormat);
+         w->f = mDirManager->NewSimpleBlockFile(temp, l, mSampleFormat,
+                                                blockFileLog != NULL);
       }
 
       if (blockFileLog)

Index: Project.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.cpp,v
retrieving revision 1.287
retrieving revision 1.288
diff -u -d -r1.287 -r1.288
--- Project.cpp 22 Oct 2006 19:35:36 -0000      1.287
+++ Project.cpp 6 Nov 2006 10:20:49 -0000       1.288
@@ -1750,6 +1750,8 @@
       delete mRecordingRecoveryHandler;
       mRecordingRecoveryHandler = NULL;
    }
+
+   GetDirManager()->FillBlockfilesCache();
 }
 
 bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
@@ -2340,6 +2342,8 @@
       SelectAllIfNone();
       OnEffect(ALL_EFFECTS | CONFIGURED_EFFECT, mNormalizeIndex ); // 
gNormalize);
    }
+
+   GetDirManager()->FillBlockfilesCache();
 }
 
 bool AudacityProject::SaveAs()
@@ -3098,13 +3102,21 @@
 {
    // Before recording is started, auto-save the file. The file will have
    // empty tracks at the bottom where the recording will be put into
-   if (IsAutoSaveEnabled())
+   //
+   // When block files are cached, auto recovery is disabled while recording,
+   // since no block files are written during recording that could be
+   // recovered.
+   //
+   if (IsAutoSaveEnabled() && !GetCacheBlockFiles())
       AutoSave();
 }
 
+// This is called after recording has stopped and all tracks have flushed.
 void AudacityProject::OnAudioIOStopRecording()
 {
-   // This is called after recording has stopped and all tracks have flushed.
+   // Write all cached files to disk, if any
+   mDirManager->WriteCacheToDisk();
+   
    // Now we auto-save again to get the project to a "normal" state again.
    if (IsAutoSaveEnabled())
       AutoSave();
@@ -3113,7 +3125,8 @@
 void AudacityProject::OnAudioIONewBlockFiles(const wxString& blockFileLog)
 {
    // New blockfiles have been created, so add them to the auto-save file
-   if (IsAutoSaveEnabled() && !mAutoSaveFileName.IsEmpty())
+   if (IsAutoSaveEnabled() && !GetCacheBlockFiles() &&
+       !mAutoSaveFileName.IsEmpty())
    {
       wxFFile f(mAutoSaveFileName, wxT("at"));
       if (!f.IsOpened())
@@ -3200,6 +3213,13 @@
    return _("All files (*.*)|*.*|Audacity projects (*.aup)|*.aup|WAV files 
(*.wav)|*.wav|AIFF files (*.aif)|*.aif|AU files (*.au)|*.au|MP3 files 
(*.mp3)|*.mp3|MP2/MPEG files 
(*.mp2;*.mpa;*.mpg;*.mpeg)|*.mp2;*.mpa;*.mpg;*.mpeg|Ogg Vorbis files 
(*.ogg)|*.ogg|FLAC files (*.flac)|*.flac|List of Files (*.lof)|*.lof");
 }
 
+bool AudacityProject::GetCacheBlockFiles()
+{  
+   bool cacheBlockFiles = false;
+   gPrefs->Read(wxT("/Directories/CacheBlockFiles"), &cacheBlockFiles);
+   return cacheBlockFiles;
+}
+
 // Indentation settings for Vim and Emacs and unique identifier for Arch, a
 // version control system. Please do not modify past this point.
 //


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to