Audacity  3.0.3
Public Member Functions | Static Public Member Functions | List of all members
PCMAliasBlockFile Class Reference

An AliasBlockFile that references uncompressed data in an existing file. More...

#include <PCMAliasBlockFile.h>

Inheritance diagram for PCMAliasBlockFile:
[legend]
Collaboration diagram for PCMAliasBlockFile:
[legend]

Public Member Functions

 PCMAliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs a PCMAliasBlockFile, writing the summary to disk. More...
 
 PCMAliasBlockFile (wxFileNameWrapper &&fileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, bool writeSummary)
 Constructs a PCMAliasBlockFile with the option of not writing to disk. More...
 
 PCMAliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float rms)
 
virtual ~PCMAliasBlockFile ()
 
size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
 Reads the specified data from the aliased file using libsndfile. More...
 
void SaveXML (XMLWriter &xmlFile) override
 
BlockFilePtr Copy (wxFileNameWrapper &&fileName) override
 
void Recover () override
 

Static Public Member Functions

static BlockFilePtr BuildFromXML (DirManager &dm, const wxChar **attrs)
 

Detailed Description

An AliasBlockFile that references uncompressed data in an existing file.

Definition at line 19 of file PCMAliasBlockFile.h.

Constructor & Destructor Documentation

◆ PCMAliasBlockFile() [1/3]

PCMAliasBlockFile::PCMAliasBlockFile ( wxFileNameWrapper &&  baseFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel 
)

Constructs a PCMAliasBlockFile, writing the summary to disk.

Definition at line 25 of file PCMAliasBlockFile.cpp.

30 : AliasBlockFile{ std::move(fileName), std::move(aliasedFileName),
31  aliasStart, aliasLen, aliasChannel }
32 {
33  AliasBlockFile::WriteSummary();
34 }

◆ PCMAliasBlockFile() [2/3]

PCMAliasBlockFile::PCMAliasBlockFile ( wxFileNameWrapper &&  fileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
bool  writeSummary 
)

Constructs a PCMAliasBlockFile with the option of not writing to disk.

Definition at line 36 of file PCMAliasBlockFile.cpp.

41 : AliasBlockFile{ std::move(fileName), std::move(aliasedFileName),
42  aliasStart, aliasLen, aliasChannel }
43 {
44  if(writeSummary)
45  AliasBlockFile::WriteSummary();
46 }

◆ PCMAliasBlockFile() [3/3]

PCMAliasBlockFile::PCMAliasBlockFile ( wxFileNameWrapper &&  existingSummaryFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
float  min,
float  max,
float  rms 
)

Definition at line 48 of file PCMAliasBlockFile.cpp.

54 : AliasBlockFile{ std::move(existingSummaryFileName), std::move(aliasedFileName),
55  aliasStart, aliasLen,
56  aliasChannel, min, max, rms }
57 {
58 }

References min().

Here is the call graph for this function:

◆ ~PCMAliasBlockFile()

PCMAliasBlockFile::~PCMAliasBlockFile ( )
virtual

Definition at line 60 of file PCMAliasBlockFile.cpp.

61 {
62 }

Member Function Documentation

◆ BuildFromXML()

BlockFilePtr PCMAliasBlockFile::BuildFromXML ( DirManager &  dm,
const wxChar **  attrs 
)
static

Definition at line 118 of file PCMAliasBlockFile.cpp.

119 {
120  wxFileNameWrapper summaryFileName;
121  wxFileNameWrapper aliasFileName;
122  int aliasStart=0, aliasLen=0, aliasChannel=0;
123  float min = 0.0f, max = 0.0f, rms = 0.0f;
124  double dblValue;
125  long nValue;
126  long long nnValue;
127 
128  while(*attrs)
129  {
130  const wxChar *attr = *attrs++;
131  const wxChar *value = *attrs++;
132  if (!value)
133  break;
134 
135  const wxString strValue = value;
136  if (!wxStricmp(attr, wxT("summaryfile")) &&
137  // Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
139  (strValue.length() + 1 + dm.GetProjectDataDir().length() <= PLATFORM_MAX_PATH))
140  {
141  if (!dm.AssignFile(summaryFileName, strValue, false))
142  // Make sure summaryFileName is back to uninitialized state so we can detect problem later.
143  summaryFileName.Clear();
144  }
145  else if (!wxStricmp(attr, wxT("aliasfile")))
146  {
147  if (XMLValueChecker::IsGoodPathName(strValue))
148  aliasFileName.Assign(strValue);
149  else if (XMLValueChecker::IsGoodFileName(strValue, dm.GetProjectDataDir()))
150  // Allow fallback of looking for the file name, located in the data directory.
151  aliasFileName.Assign(dm.GetProjectDataDir(), strValue);
152  else if (XMLValueChecker::IsGoodPathString(strValue))
153  // If the aliased file is missing, we failed XMLValueChecker::IsGoodPathName()
154  // and XMLValueChecker::IsGoodFileName, because both do existence tests,
155  // but we want to keep the reference to the missing file because it's a good path string.
156  aliasFileName.Assign(strValue);
157  }
158  else if ( !wxStricmp(attr, wxT("aliasstart")) )
159  {
160  if (XMLValueChecker::IsGoodInt64(strValue) &&
161  strValue.ToLongLong(&nnValue) && (nnValue >= 0))
162  aliasStart = nnValue;
163  }
164  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
165  { // integer parameters
166  if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
167  aliasLen = nValue;
168  else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
169  aliasChannel = nValue;
170  else if (!wxStricmp(attr, wxT("min")))
171  min = nValue;
172  else if (!wxStricmp(attr, wxT("max")))
173  max = nValue;
174  else if (!wxStricmp(attr, wxT("rms")) && (nValue >= 0))
175  rms = nValue;
176  }
177  // mchinen: the min/max can be (are?) doubles as well, so handle those cases.
178  // Vaughan: The code to which I added the XMLValueChecker checks
179  // used wxAtoi to convert the string to an int.
180  // So it's possible some prior project formats used ints (?), so am keeping
181  // those above, but yes, we need to handle floats.
182  else if (XMLValueChecker::IsGoodString(strValue) && Internat::CompatibleToDouble(strValue, &dblValue))
183  { // double parameters
184  if (!wxStricmp(attr, wxT("min")))
185  min = dblValue;
186  else if (!wxStricmp(attr, wxT("max")))
187  max = dblValue;
188  else if (!wxStricmp(attr, wxT("rms")) && (dblValue >= 0.0))
189  rms = dblValue;
190  }
191  }
192 
193  return make_blockfile<PCMAliasBlockFile>
194  (std::move(summaryFileName), std::move(aliasFileName),
195  aliasStart, aliasLen, aliasChannel, min, max, rms);
196 }

References Internat::CompatibleToDouble(), XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodFileString(), XMLValueChecker::IsGoodInt(), XMLValueChecker::IsGoodInt64(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodPathString(), XMLValueChecker::IsGoodString(), anonymous_namespace{WaveTrack.cpp}::IsValidChannel(), min(), and PLATFORM_MAX_PATH.

Here is the call graph for this function:

◆ Copy()

BlockFilePtr PCMAliasBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
override

Construct a NEW PCMAliasBlockFile based on this one, but writing the summary data to a NEW file.

Parameters
newFileNameThe filename to copy the summary data to.

Definition at line 88 of file PCMAliasBlockFile.cpp.

89 {
90  auto newBlockFile = make_blockfile<PCMAliasBlockFile>
91  (std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
92  mAliasStart, mLen, mAliasChannel, mMin, mMax, mRMS);
93 
94  return newBlockFile;
95 }

◆ ReadData()

size_t PCMAliasBlockFile::ReadData ( samplePtr  data,
sampleFormat  format,
size_t  start,
size_t  len,
bool  mayThrow 
) const
override

Reads the specified data from the aliased file using libsndfile.

Reads the specified data from the aliased file, using libsndfile, and converts it to the given sample format.

Parameters
dataThe buffer to read the sample data into.
formatThe format to convert the data into
startThe offset within the block to begin reading
lenThe number of samples to read

Definition at line 71 of file PCMAliasBlockFile.cpp.

73 {
74  if(!mAliasedFileName.IsOk()){ // intentionally silenced
75  memset(data, 0, SAMPLE_SIZE(format) * len);
76  return len;
77  }
78 
79  return CommonReadData( mayThrow,
80  mAliasedFileName, mSilentAliasLog, this, mAliasStart, mAliasChannel,
81  data, format, start, len);
82 }

References format, and SAMPLE_SIZE.

◆ Recover()

void PCMAliasBlockFile::Recover ( void  )
override

Definition at line 198 of file PCMAliasBlockFile.cpp.

199 {
200  WriteSummary();
201 }

◆ SaveXML()

void PCMAliasBlockFile::SaveXML ( XMLWriter xmlFile)
override

Definition at line 97 of file PCMAliasBlockFile.cpp.

99 {
100  xmlFile.StartTag(wxT("pcmaliasblockfile"));
101 
102  xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName());
103  xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath());
104  xmlFile.WriteAttr(wxT("aliasstart"),
105  mAliasStart.as_long_long());
106  xmlFile.WriteAttr(wxT("aliaslen"), mLen);
107  xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
108  xmlFile.WriteAttr(wxT("min"), mMin);
109  xmlFile.WriteAttr(wxT("max"), mMax);
110  xmlFile.WriteAttr(wxT("rms"), mRMS);
111 
112  xmlFile.EndTag(wxT("pcmaliasblockfile"));
113 }

References XMLWriter::EndTag(), XMLWriter::StartTag(), and XMLWriter::WriteAttr().

Referenced by ODPCMAliasBlockFile::SaveXML().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
XMLWriter::EndTag
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:99
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
XMLValueChecker::IsGoodInt
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
Definition: XMLTagHandler.cpp:157
XMLValueChecker::IsGoodPathName
static bool IsGoodPathName(const FilePath &strPathName)
Definition: XMLTagHandler.cpp:98
XMLValueChecker::IsGoodInt64
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
Definition: XMLTagHandler.cpp:163
SAMPLE_SIZE
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
XMLValueChecker::IsGoodString
static bool IsGoodString(const wxString &str)
Definition: XMLTagHandler.cpp:38
XMLValueChecker::IsGoodFileName
static bool IsGoodFileName(const FilePath &strFileName, const FilePath &strDirName={})
Definition: XMLTagHandler.cpp:58
format
int format
Definition: ExportPCM.cpp:56
XMLValueChecker::IsGoodFileString
static bool IsGoodFileString(const FilePath &str)
Definition: XMLTagHandler.cpp:70
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
anonymous_namespace{WaveTrack.cpp}::IsValidChannel
bool IsValidChannel(const int nValue)
Definition: WaveTrack.cpp:1706
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
PLATFORM_MAX_PATH
#define PLATFORM_MAX_PATH
Definition: FileNames.h:22
XMLValueChecker::IsGoodPathString
static bool IsGoodPathString(const FilePath &str)
Definition: XMLTagHandler.cpp:105
XMLWriter::StartTag
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:76
Internat::CompatibleToDouble
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:134