1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-10 14:46:24 +01:00

Additional autosave speed improvement and 1 fix

This changes the autosave XML file to a binary representation
during writing to speed up autosave processing.  A lot of the
time used during autosave is a result of having to convert and
print all of the values to the XML file.

Writing the same information, but in binary format, reduces
all of that to just the bare essentials and the actual write
I/O.

During recovery, the binary file is read and converted to
the real xML representation and processing happens as it
did before.

It is a noticeable difference with very long or many tracks.

The included fix has to do with append recording.

Say you have 3 tracks and you want to append recorded audio
to the middle track.  Sometime later Audacity crashes and
upon recovery, the recorded audio is actually appended to
the third track, not the second one.

This fixes that by adding an "autosaveid" to each track as
it is written to the autosave file.  The same ID is written
to the recording recovery appends to the autosave file.

Then, during recovery, the IDs are matched up and the audio
gets appended to the proper track.

These autosaveid attributes are only present in the autosave
file and not in saved project files.
This commit is contained in:
Leland Lucius
2015-04-17 16:42:30 -05:00
parent 6a84f657c3
commit 3e1fbcd5ec
10 changed files with 683 additions and 90 deletions

View File

@@ -12,9 +12,15 @@
#define __AUDACITY_AUTORECOVERY__
#include "Project.h"
#include "xml/XMLTagHandler.h"
#include "xml/XMLWriter.h"
#include <wx/debug.h>
#include <wx/dynarray.h>
#include <wx/ffile.h>
#include <wx/hashmap.h>
#include <wx/mstream.h>
//
// Show auto recovery dialog if there are projects to recover. Should be
@@ -49,6 +55,65 @@ private:
AudacityProject* mProject;
int mChannel;
int mNumChannels;
int mAutoSaveIdent;
};
///
/// AutoSaveFile
///
// Should be plain ASCII
#define AutoSaveIdent "<?xml autosave>"
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(short, NameMap, class AUDACITY_DLL_API);
WX_DECLARE_HASH_MAP(short, wxString, wxIntegerHash, wxIntegerEqual, IdMap);
WX_DECLARE_OBJARRAY(IdMap, IdMapArray);
class AUDACITY_DLL_API AutoSaveFile : public XMLWriter
{
public:
AutoSaveFile(size_t allocSize = 1024 * 1024);
virtual ~AutoSaveFile();
virtual void StartTag(const wxString & name);
virtual void EndTag(const wxString & name);
virtual void WriteAttr(const wxString & name, const wxString &value);
virtual void WriteAttr(const wxString & name, const wxChar *value);
virtual void WriteAttr(const wxString & name, int value);
virtual void WriteAttr(const wxString & name, bool value);
virtual void WriteAttr(const wxString & name, long value);
virtual void WriteAttr(const wxString & name, long long value);
virtual void WriteAttr(const wxString & name, size_t value);
virtual void WriteAttr(const wxString & name, float value, int digits = -1);
virtual void WriteAttr(const wxString & name, double value, int digits = -1);
virtual void WriteData(const wxString & value);
virtual void WriteSubTree(const AutoSaveFile & value);
virtual void Write(const wxString & data);
virtual bool Write(wxFFile & file) const;
virtual bool Append(wxFFile & file) const;
virtual bool IsEmpty() const;
virtual bool Decode(const wxString & fileName);
private:
void WriteName(const wxString & name);
void CheckSpace(wxMemoryOutputStream & buf);
private:
wxMemoryOutputStream mBuffer;
wxMemoryOutputStream mDict;
NameMap mNames;
IdMap mIds;
IdMapArray mIdStack;
size_t mAllocSize;
};
#endif