File: DirManager.h

package info (click to toggle)
audacity 0.98-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,896 kB
  • ctags: 4,089
  • sloc: cpp: 26,099; ansic: 4,961; sh: 2,465; makefile: 156; perl: 23
file content (130 lines) | stat: -rw-r--r-- 3,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**********************************************************************

  Audacity: A Digital Audio Editor

  DirManager.h

  Dominic Mazzoni

  This class manages the files that a project uses to store most
  of its data.  It creates new BlockFile objects, which can
  be used to store any type of data.  BlockFiles support all of
  the common file operations, but they also support reference
  counting, so two different parts of a project can point to
  the same block of data.

  For example, a track might contain 10 blocks of data representing
  its audio.  If you copy the last 5 blocks and paste at the
  end of the file, no new blocks need to be created - we just store
  pointers to new ones.  When part of a track is deleted, the
  affected blocks decrement their reference counts, and when they
  reach zero they are deleted.  This same mechanism is also used
  to implement Undo.

  The DirManager, besides mapping filenames to absolute paths,
  also hashes all of the block names used in a project, so that
  when reading a project from disk, multiple copies of the
  same block still get mapped to the same BlockFile object.

**********************************************************************/

#ifndef _DIRMANAGER_
#define _DIRMANAGER_

#include <wx/string.h>
#include <wx/hash.h>
#include <wx/list.h>

#include "BlockFile.h"
#include "WaveTrack.h"

class wxTextFile;

class DirManager {
 public:
   DirManager();
   ~DirManager();

   // Returns true on success.
   // If SetProject is told NOT to create the directory
   // but it doesn't already exist, SetProject fails and returns false.
   bool SetProject(wxString & projPath, wxString & projName, bool create);

   wxString GetProjectName();

   // Create new unique track name
   wxString NewTrackName();

   void MakeBlockFileName(wxString inProjDir,
                          wxString &outFileName, wxString &outPathName);

   BlockFile *NewTempBlockFile();
   BlockFile *NewBlockFile();

   BlockFile *NewTempAliasBlockFile(int localLen,
                                    wxString fullPath,
                                    sampleCount start,
                                    sampleCount len, int channel);
   BlockFile *NewAliasBlockFile(int localLen,
                                wxString fullPath,
                                sampleCount start,
                                sampleCount len, int channel);

   // Adds one to the reference count of the block file,
   // UNLESS it is "locked", then it makes a new copy of
   // the BlockFile.
   BlockFile *CopyBlockFile(BlockFile *b);

   BlockFile *LoadBlockFile(wxTextFile * in);
   void SaveBlockFile(BlockFile * f, wxTextFile * out);

   // If this filename is one we depend on, tries to rename
   // the existing file so that we can save a new file by this name.
   bool EnsureSafeFilename(wxString fName);

   void Ref(BlockFile * f);
   void Deref(BlockFile * f);

   static wxString GetHomeDir() {
      return home;
   } static wxString GetPathChar() {
      return pathChar;
   }

 private:
   void CleanTempDir();

   // Create new unique names
   wxString NewTempBlockName();
   wxString NewBlockName();

   bool MoveToNewProjectDirectory(BlockFile *b);
   bool CopyToNewProjectDirectory(BlockFile *b);

   //////////////////////////

   wxHashTable *blockFileHash;

   static int defaultHashTableSize;
   int hashTableSize;
   void CheckHashTableSize();

   wxStringList aliasList;

   wxString projName;
   wxString projPath;
   wxString projFull;

   wxString lastProject;

   static wxString pathChar;
   static wxString home;
   static wxString temp;

   static bool firstCtor;
   static int numDirManagers;
   static int fileIndex;
   static wxString tempDirName;
};

#endif