Audacity  2.2.2
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:
AliasBlockFile BlockFile LegacyAliasBlockFile ODPCMAliasBlockFile

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
 Stores a representation of this file in XML. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&fileName) override
 
void Recover () override
 if the on-disk state disappeared, either recover it (if it was More...
 
- Public Member Functions inherited from AliasBlockFile
 AliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs an AliasBlockFile. More...
 
 AliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float RMS)
 
virtual ~AliasBlockFile ()
 
DiskByteCount GetSpaceUsage () const override
 
void SilenceAliasLog () const
 as SilentLog (which would affect Summary data access), but More...
 
const wxFileName & GetAliasedFileName () const
 
void ChangeAliasedFileName (wxFileNameWrapper &&newAliasedFile)
 
bool IsAlias () const override
 Returns TRUE if this block references another disk file. More...
 
- Public Member Functions inherited from BlockFile
 BlockFile (wxFileNameWrapper &&fileName, size_t samples)
 Construct a BlockFile. More...
 
virtual ~BlockFile ()
 
virtual bool GetNeedWriteCacheToDisk ()
 
virtual void WriteCacheToDisk ()
 
virtual bool GetNeedFillCache ()
 
virtual void FillCache ()
 
virtual GetFileNameResult GetFileName () const
 
virtual void SetFileName (wxFileNameWrapper &&name)
 sets the file name the summary info will be saved in. threadsafe. More...
 
size_t GetLength () const
 
void SetLength (size_t newLen)
 
virtual void Lock ()
 Locks this BlockFile, to prevent it from being moved. More...
 
virtual void Unlock ()
 Unlock this BlockFile, allowing it to be moved. More...
 
virtual bool IsLocked ()
 Returns TRUE if this BlockFile is locked. More...
 
virtual MinMaxRMS GetMinMaxRMS (size_t start, size_t len, bool mayThrow=true) const
 Gets extreme values for the specified region. More...
 
virtual MinMaxRMS GetMinMaxRMS (bool mayThrow=true) const
 Gets extreme values for the entire block. More...
 
virtual bool Read256 (float *buffer, size_t start, size_t len)
 Returns the 256 byte summary data block. More...
 
virtual bool Read64K (float *buffer, size_t start, size_t len)
 Returns the 64K summary data block. More...
 
virtual bool IsSummaryAvailable () const
 Returns TRUE if this block's complete summary has been computed and is ready (for OD) More...
 
virtual bool IsDataAvailable () const
 Returns TRUE if this block's complete data is ready to be accessed by Read() More...
 
virtual bool IsSummaryBeingComputed ()
 Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk. More...
 
void SilenceLog () const
 if we've detected an on-disk problem, the user opted to More...
 
virtual void CloseLock ()
 
ReadLock LockForRead () const
 

Static Public Member Functions

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

Additional Inherited Members

- Public Types inherited from BlockFile
using DiskByteCount = unsigned long long
 
- Static Public Attributes inherited from BlockFile
static unsigned long gBlockFileDestructionCount { 0 }
 
- Protected Types inherited from BlockFile
using ReadLockBase = std::unique_ptr< const BlockFile, ReadUnlocker >
 
- Protected Member Functions inherited from AliasBlockFile
virtual void WriteSummary ()
 Write the summary to disk, using the derived ReadData() to get the data. More...
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary into a buffer. More...
 
- Protected Member Functions inherited from BlockFile
virtual void LockRead () const
 Prevents a read on other threads. The basic blockfile runs on only one thread, so does nothing. More...
 
virtual void UnlockRead () const
 Allows reading on other threads. More...
 
virtual void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup)
 
void CalcSummaryFromBuffer (const float *fbuffer, size_t len, float *summary256, float *summary64K)
 
virtual void FixSummary (void *data)
 
- Static Protected Member Functions inherited from BlockFile
static size_t CommonReadData (bool mayThrow, const wxFileName &fileName, bool &mSilentLog, const AliasBlockFile *pAliasFile, sampleCount origin, unsigned channel, samplePtr data, sampleFormat format, size_t start, size_t len, const sampleFormat *pLegacyFormat=nullptr, size_t legacyLen=0)
 
- Protected Attributes inherited from AliasBlockFile
wxFileNameWrapper mAliasedFileName
 
sampleCount mAliasStart
 
const int mAliasChannel
 
bool mSilentAliasLog
 
- Protected Attributes inherited from BlockFile
wxFileNameWrapper mFileName
 
size_t mLen
 
SummaryInfo mSummaryInfo
 
float mMin
 
float mMax
 
float mRMS
 
bool mSilentLog
 

Detailed Description

An AliasBlockFile that references uncompressed data in an existing file.

Definition at line 18 of file PCMAliasBlockFile.h.

Constructor & Destructor Documentation

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

Constructs a PCMAliasBlockFile, writing the summary to disk.

Definition at line 31 of file PCMAliasBlockFile.cpp.

36 : AliasBlockFile{ std::move(fileName), std::move(aliasedFileName),
37  aliasStart, aliasLen, aliasChannel }
38 {
40 }
A BlockFile that refers to data in an existing file.
Definition: BlockFile.h:251
virtual void WriteSummary()
Write the summary to disk, using the derived ReadData() to get the data.
Definition: BlockFile.cpp:675
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 42 of file PCMAliasBlockFile.cpp.

47 : AliasBlockFile{ std::move(fileName), std::move(aliasedFileName),
48  aliasStart, aliasLen, aliasChannel }
49 {
50  if(writeSummary)
52 }
A BlockFile that refers to data in an existing file.
Definition: BlockFile.h:251
virtual void WriteSummary()
Write the summary to disk, using the derived ReadData() to get the data.
Definition: BlockFile.cpp:675
PCMAliasBlockFile::PCMAliasBlockFile ( wxFileNameWrapper &&  existingSummaryFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
float  min,
float  max,
float  rms 
)

Definition at line 54 of file PCMAliasBlockFile.cpp.

References min().

60 : AliasBlockFile{ std::move(existingSummaryFileName), std::move(aliasedFileName),
61  aliasStart, aliasLen,
62  aliasChannel, min, max, rms }
63 {
64 }
int min(int a, int b)
A BlockFile that refers to data in an existing file.
Definition: BlockFile.h:251
PCMAliasBlockFile::~PCMAliasBlockFile ( )
virtual

Definition at line 66 of file PCMAliasBlockFile.cpp.

67 {
68 }

Member Function Documentation

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

Definition at line 124 of file PCMAliasBlockFile.cpp.

References DirManager::AssignFile(), Internat::CompatibleToDouble(), DirManager::GetProjectDataDir(), XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodFileString(), XMLValueChecker::IsGoodInt(), XMLValueChecker::IsGoodInt64(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodPathString(), XMLValueChecker::IsGoodString(), XMLValueChecker::IsValidChannel(), min(), and PLATFORM_MAX_PATH.

Referenced by DirManager::HandleXMLTag().

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

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.

Implements BlockFile.

Definition at line 94 of file PCMAliasBlockFile.cpp.

References AliasBlockFile::mAliasChannel, AliasBlockFile::mAliasedFileName, AliasBlockFile::mAliasStart, BlockFile::mLen, BlockFile::mMax, BlockFile::mMin, and BlockFile::mRMS.

95 {
96  auto newBlockFile = make_blockfile<PCMAliasBlockFile>
97  (std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
99 
100  return newBlockFile;
101 }
const int mAliasChannel
Definition: BlockFile.h:291
float mMin
Definition: BlockFile.h:238
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
float mRMS
Definition: BlockFile.h:238
sampleCount mAliasStart
Definition: BlockFile.h:290
size_t mLen
Definition: BlockFile.h:236
float mMax
Definition: BlockFile.h:238
size_t PCMAliasBlockFile::ReadData ( samplePtr  data,
sampleFormat  format,
size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

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

Implements BlockFile.

Definition at line 77 of file PCMAliasBlockFile.cpp.

References BlockFile::CommonReadData(), AliasBlockFile::mAliasChannel, AliasBlockFile::mAliasedFileName, AliasBlockFile::mAliasStart, AliasBlockFile::mSilentAliasLog, and SAMPLE_SIZE.

79 {
80  if(!mAliasedFileName.IsOk()){ // intentionally silenced
81  memset(data, 0, SAMPLE_SIZE(format) * len);
82  return len;
83  }
84 
85  return CommonReadData( mayThrow,
87  data, format, start, len);
88 }
const int mAliasChannel
Definition: BlockFile.h:291
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
int format
Definition: ExportPCM.cpp:56
bool mSilentAliasLog
Definition: BlockFile.h:292
sampleCount mAliasStart
Definition: BlockFile.h:290
static size_t CommonReadData(bool mayThrow, const wxFileName &fileName, bool &mSilentLog, const AliasBlockFile *pAliasFile, sampleCount origin, unsigned channel, samplePtr data, sampleFormat format, size_t start, size_t len, const sampleFormat *pLegacyFormat=nullptr, size_t legacyLen=0)
Definition: BlockFile.cpp:483
void PCMAliasBlockFile::Recover ( )
overridevirtual

if the on-disk state disappeared, either recover it (if it was

Implements BlockFile.

Definition at line 204 of file PCMAliasBlockFile.cpp.

References AliasBlockFile::WriteSummary().

205 {
206  WriteSummary();
207 }
virtual void WriteSummary()
Write the summary to disk, using the derived ReadData() to get the data.
Definition: BlockFile.cpp:675
void PCMAliasBlockFile::SaveXML ( XMLWriter xmlFile)
overridevirtual

Stores a representation of this file in XML.

Implements BlockFile.

Definition at line 103 of file PCMAliasBlockFile.cpp.

References sampleCount::as_long_long(), XMLWriter::EndTag(), AliasBlockFile::mAliasChannel, AliasBlockFile::mAliasedFileName, AliasBlockFile::mAliasStart, BlockFile::mFileName, BlockFile::mLen, BlockFile::mMax, BlockFile::mMin, BlockFile::mRMS, XMLWriter::StartTag(), and XMLWriter::WriteAttr().

Referenced by ODPCMAliasBlockFile::SaveXML().

105 {
106  xmlFile.StartTag(wxT("pcmaliasblockfile"));
107 
108  xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName());
109  xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath());
110  xmlFile.WriteAttr(wxT("aliasstart"),
112  xmlFile.WriteAttr(wxT("aliaslen"), mLen);
113  xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
114  xmlFile.WriteAttr(wxT("min"), mMin);
115  xmlFile.WriteAttr(wxT("max"), mMax);
116  xmlFile.WriteAttr(wxT("rms"), mRMS);
117 
118  xmlFile.EndTag(wxT("pcmaliasblockfile"));
119 }
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
float mMin
Definition: BlockFile.h:238
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
float mRMS
Definition: BlockFile.h:238
sampleCount mAliasStart
Definition: BlockFile.h:290
size_t mLen
Definition: BlockFile.h:236
long long as_long_long() const
Definition: Types.h:90
float mMax
Definition: BlockFile.h:238

The documentation for this class was generated from the following files: