Audacity  2.2.2
LegacyAliasBlockFile.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LegacyAliasBlockFile.cpp
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #include "../Audacity.h"
12 #include "LegacyAliasBlockFile.h"
13 
14 #include <wx/utils.h>
15 #include <wx/wxchar.h>
16 
17 #include <sndfile.h>
18 
19 #include "LegacyBlockFile.h"
20 #include "../FileFormats.h"
21 #include "../Internat.h"
22 
24  wxFileNameWrapper &&aliasedFileName,
25  sampleCount aliasStart,
26  size_t aliasLen,
27  int aliasChannel,
28  size_t summaryLen,
29  bool noRMS)
30 : PCMAliasBlockFile{ std::move(fileName), std::move(aliasedFileName), aliasStart, aliasLen,
31  aliasChannel, 0.0, 0.0, 0.0 }
32 {
34 
35  if (noRMS)
36  format = int16Sample;
37  else
38  format = floatSample;
39 
40  ComputeLegacySummaryInfo(mFileName,
41  summaryLen, format,
42  &mSummaryInfo, noRMS, FALSE,
43  &mMin, &mMax, &mRMS);
44 }
45 
47 {
48 }
49 
55 {
56  auto newBlockFile = make_blockfile<LegacyAliasBlockFile>
57  (std::move(newFileName), wxFileNameWrapper{ mAliasedFileName },
60 
61  return newBlockFile;
62 }
63 
65 // may throw
66 {
67  xmlFile.StartTag(wxT("legacyblockfile"));
68 
69  xmlFile.WriteAttr(wxT("alias"), 1);
70  xmlFile.WriteAttr(wxT("name"), mFileName.GetFullName());
71  xmlFile.WriteAttr(wxT("aliaspath"), mAliasedFileName.GetFullPath());
72  xmlFile.WriteAttr(wxT("aliasstart"),
74  xmlFile.WriteAttr(wxT("aliaslen"), mLen);
75  xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
76  xmlFile.WriteAttr(wxT("summarylen"), mSummaryInfo.totalSummaryBytes);
77  if (mSummaryInfo.fields < 3)
78  xmlFile.WriteAttr(wxT("norms"), 1);
79 
80  xmlFile.EndTag(wxT("legacyblockfile"));
81 }
82 
83 // BuildFromXML methods should always return a BlockFile, not NULL,
84 // even if the result is flawed (e.g., refers to nonexistent file),
85 // as testing will be done in DirManager::ProjectFSCK().
86 BlockFilePtr LegacyAliasBlockFile::BuildFromXML(const wxString &projDir, const wxChar **attrs)
87 {
88  wxFileNameWrapper summaryFileName;
89  wxFileNameWrapper aliasFileName;
90  int aliasStart=0, aliasLen=0, aliasChannel=0;
91  int summaryLen=0;
92  bool noRMS = false;
93  long nValue;
94  long long nnValue;
95 
96  while(*attrs)
97  {
98  const wxChar *attr = *attrs++;
99  const wxChar *value = *attrs++;
100  if (!value)
101  break;
102 
103  const wxString strValue = value;
104  if (!wxStricmp(attr, wxT("name")) && XMLValueChecker::IsGoodFileName(strValue, projDir))
105  //v Should this be
106  // dm.AssignFile(summaryFileName, strValue, false);
107  // as in PCMAliasBlockFile::BuildFromXML? Test with an old project.
108  summaryFileName.Assign(projDir, strValue, wxT(""));
109  else if ( !wxStricmp(attr, wxT("aliaspath")) )
110  {
111  if (XMLValueChecker::IsGoodPathName(strValue))
112  aliasFileName.Assign(strValue);
113  else if (XMLValueChecker::IsGoodFileName(strValue, projDir))
114  // Allow fallback of looking for the file name, located in the data directory.
115  aliasFileName.Assign(projDir, strValue);
116  else if (XMLValueChecker::IsGoodPathString(strValue))
117  // If the aliased file is missing, we failed XMLValueChecker::IsGoodPathName()
118  // and XMLValueChecker::IsGoodFileName, because both do existence tests,
119  // but we want to keep the reference to the missing file because it's a good path string.
120  aliasFileName.Assign(strValue);
121  }
122  else if ( !wxStricmp(attr, wxT("aliasstart")) )
123  {
124  if (XMLValueChecker::IsGoodInt64(strValue) &&
125  strValue.ToLongLong(&nnValue) && (nnValue >= 0))
126  aliasStart = nnValue;
127  }
128  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
129  { // integer parameters
130  if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
131  aliasLen = nValue;
132  else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
133  aliasChannel = nValue;
134  else if (!wxStricmp(attr, wxT("summarylen")) && (nValue > 0))
135  summaryLen = nValue;
136  else if (!wxStricmp(attr, wxT("norms")))
137  noRMS = (nValue != 0);
138  }
139  }
140 
141  return make_blockfile<LegacyAliasBlockFile>
142  (std::move(summaryFileName), std::move(aliasFileName),
143  aliasStart, aliasLen, aliasChannel, summaryLen, noRMS);
144 }
145 
146 // regenerates the summary info, doesn't deal with missing alias files
148  WriteSummary();
149 }
const int mAliasChannel
Definition: BlockFile.h:291
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
void ComputeLegacySummaryInfo(const wxFileName &fileName, size_t summaryLen, sampleFormat format, SummaryInfo *info, bool noRMS, bool Silent, float *min, float *max, float *rms)
static bool IsValidChannel(const int nValue)
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
static bool IsGoodPathName(const wxString &strPathName)
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
static bool IsGoodPathString(const wxString &str)
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
std::shared_ptr< BlockFile > BlockFilePtr
Definition: BlockFile.h:48
int format
Definition: ExportPCM.cpp:56
sampleFormat
Definition: Types.h:188
size_t totalSummaryBytes
Definition: BlockFile.h:41
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
LegacyAliasBlockFile(wxFileNameWrapper &&fileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, size_t summaryLen, bool noRMS)
Constructs a LegacyAliasBlockFile, writing the summary to disk.
sampleCount mAliasStart
Definition: BlockFile.h:290
size_t mLen
Definition: BlockFile.h:236
int fields
Definition: BlockFile.h:34
void SaveXML(XMLWriter &xmlFile) override
Stores a representation of this file in XML.
static bool IsGoodFileName(const wxString &strFileName, const wxString &strDirName=wxEmptyString)
long long as_long_long() const
Definition: Types.h:90
virtual void WriteSummary()
Write the summary to disk, using the derived ReadData() to get the data.
Definition: BlockFile.cpp:675
static BlockFilePtr BuildFromXML(const wxString &projDir, const wxChar **attrs)
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:22
An AliasBlockFile that references uncompressed data in an existing file.
void Recover() override
if the on-disk state disappeared, either recover it (if it was