Audacity  3.0.3
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
LegacyBlockFile Class Referencefinal

Audacity 1.1.0 block file format: More...

#include <LegacyBlockFile.h>

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

Public Member Functions

 LegacyBlockFile (wxFileNameWrapper &&existingFile, sampleFormat format, size_t summaryLen, size_t len, bool noRMS)
 Create the memory structure to refer to the given block file. More...
 
virtual ~LegacyBlockFile ()
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary section of the disk file. More...
 
size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
 Read the data section of the disk file. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&newFileName) override
 Create a NEW block file identical to this one. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Write an XML representation of this file. More...
 
DiskByteCount GetSpaceUsage () const override
 
void Recover () override
 

Static Public Member Functions

static BlockFilePtr BuildFromXML (const FilePath &dir, const wxChar **attrs, size_t len, sampleFormat format)
 static More...
 

Protected Attributes

sampleFormat mFormat
 

Detailed Description

Audacity 1.1.0 block file format:

Definition at line 34 of file LegacyBlockFile.h.

Constructor & Destructor Documentation

◆ LegacyBlockFile()

LegacyBlockFile::LegacyBlockFile ( wxFileNameWrapper &&  existingFile,
sampleFormat  format,
size_t  summaryLen,
size_t  len,
bool  noRMS 
)

Create the memory structure to refer to the given block file.

Construct a LegacyBlockFile memory structure that will point to an existing block file. This file must exist and be a valid block file.

Parameters
existingFileThe disk file this LegacyBlockFile should use.

Definition at line 126 of file LegacyBlockFile.cpp.

130  :
131  BlockFile{ std::move(existingFile), len },
132  mFormat(format)
133 {
134 
135  sampleFormat summaryFormat;
136 
137  if (noRMS)
138  summaryFormat = int16Sample;
139  else
140  summaryFormat = floatSample;
141 
142  ComputeLegacySummaryInfo(mFileName,
143  summaryLen, summaryFormat,
144  &mSummaryInfo, noRMS, FALSE,
145  &mMin, &mMax, &mRMS);
146 }

◆ ~LegacyBlockFile()

LegacyBlockFile::~LegacyBlockFile ( )
virtual

Definition at line 148 of file LegacyBlockFile.cpp.

149 {
150 }

Member Function Documentation

◆ BuildFromXML()

BlockFilePtr LegacyBlockFile::BuildFromXML ( const FilePath dir,
const wxChar **  attrs,
size_t  len,
sampleFormat  format 
)
static

static

Definition at line 223 of file LegacyBlockFile.cpp.

225 {
226  wxFileNameWrapper fileName;
227  size_t summaryLen = 0;
228  bool noRMS = false;
229  long nValue;
230 
231  while(*attrs)
232  {
233  const wxChar *attr = *attrs++;
234  const wxChar *value = *attrs++;
235  if (!value)
236  break;
237 
238  const wxString strValue = value;
239  if (!wxStricmp(attr, wxT("name")) && XMLValueChecker::IsGoodFileName(strValue, projDir))
240  //v Should this be
241  // dm.AssignFile(fileName, strValue, false);
242  // as in PCMAliasBlockFile::BuildFromXML? Test with an old project.
243  fileName.Assign(projDir, strValue);
244  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
245  { // integer parameters
246  if (!wxStrcmp(attr, wxT("len")) && (nValue >= 0))
247  len = nValue;
248  else if (!wxStrcmp(attr, wxT("norms")))
249  noRMS = (nValue != 0);
250  else if (!wxStrcmp(attr, wxT("format")) && XMLValueChecker::IsValidSampleFormat(nValue))
251  format = (sampleFormat)nValue;
252  else if (!wxStrcmp(attr, wxT("summarylen")) && (nValue > 0))
253  // Note attribute "summarylen" was written as int, no need for 64 bits
254  summaryLen = nValue;
255  }
256  }
257 
258  return make_blockfile<LegacyBlockFile>
259  (std::move(fileName), format, summaryLen, len, noRMS);
260 }

References format, XMLValueChecker::IsGoodFileName(), and XMLValueChecker::IsGoodInt().

Here is the call graph for this function:

◆ Copy()

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

Create a NEW block file identical to this one.

Create a copy of this BlockFile, but using a different disk file.

Parameters
newFileNameThe name of the NEW file to use.

Definition at line 265 of file LegacyBlockFile.cpp.

266 {
267  return make_blockfile<LegacyBlockFile>
268  (std::move(newFileName),
269  mFormat, mSummaryInfo.totalSummaryBytes,
270  mLen, mSummaryInfo.fields < 3);
271 }

References mFormat.

◆ GetSpaceUsage()

auto LegacyBlockFile::GetSpaceUsage ( ) const
override

Definition at line 273 of file LegacyBlockFile.cpp.

274 {
275  wxFFile dataFile(mFileName.GetFullPath());
276  return dataFile.Length();
277 }

◆ ReadData()

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

Read the data section of the disk file.

Read the data portion of the block file using libsndfile. Convert it to the given format if it is not already.

Parameters
dataThe buffer where the data will be stored
formatThe format the data will be stored in
startThe offset in this block file
lenThe number of samples to read

Definition at line 195 of file LegacyBlockFile.cpp.

197 {
198  sf_count_t origin = (mSummaryInfo.totalSummaryBytes / SAMPLE_SIZE(mFormat));
199  return CommonReadData( mayThrow,
200  mFileName, mSilentLog, nullptr, origin, 0, data, format, start, len,
201  &mFormat, mLen
202  );
203 }

References format, mFormat, and SAMPLE_SIZE.

◆ ReadSummary()

bool LegacyBlockFile::ReadSummary ( ArrayOf< char > &  data)
override

Read the summary section of the disk file.

Read the summary section of the disk file. Fill with zeroes and return false if data are unavailable for any reason.

Parameters
*dataThe buffer to write the data to. It must be at least mSummaryinfo.totalSummaryBytes long.

Definition at line 157 of file LegacyBlockFile.cpp.

158 {
159  data.reinit( mSummaryInfo.totalSummaryBytes );
160  wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
161  size_t read;
162  {
163  Optional<wxLogNull> silence{};
164  if (mSilentLog)
165  silence.emplace();
166 
167  if (!summaryFile.IsOpened()) {
168 
169  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
170 
171  mSilentLog = TRUE;
172 
173  return false;
174  }
175 
176  read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
177  }
178  mSilentLog = FALSE;
179 
180  if (read != mSummaryInfo.totalSummaryBytes) {
181  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
182  return false;
183  }
184 
185  return true;
186 }

References Optional< X >::emplace(), and ArrayOf< X >::reinit().

Here is the call graph for this function:

◆ Recover()

void LegacyBlockFile::Recover ( void  )
override

Definition at line 279 of file LegacyBlockFile.cpp.

280 {
281 
282 
283 }

◆ SaveXML()

void LegacyBlockFile::SaveXML ( XMLWriter xmlFile)
override

Write an XML representation of this file.

Definition at line 205 of file LegacyBlockFile.cpp.

207 {
208  xmlFile.StartTag(wxT("legacyblockfile"));
209 
210  xmlFile.WriteAttr(wxT("name"), mFileName.GetFullName());
211  xmlFile.WriteAttr(wxT("len"), mLen);
212  if (mSummaryInfo.fields < 3)
213  xmlFile.WriteAttr(wxT("norms"), 1);
214  xmlFile.WriteAttr(wxT("summarylen"), mSummaryInfo.totalSummaryBytes);
215 
216  xmlFile.EndTag(wxT("legacyblockfile"));
217 }

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

Here is the call graph for this function:

Member Data Documentation

◆ mFormat

sampleFormat LegacyBlockFile::mFormat
protected

Definition at line 67 of file LegacyBlockFile.h.

Referenced by Copy(), and ReadData().


The documentation for this class was generated from the following files:
XMLWriter::EndTag
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:99
Optional::emplace
X & emplace(Args &&... args)
Definition: MemoryX.h:193
Optional
Like a smart pointer, allows for object to not exist (nullptr)
Definition: MemoryX.h:144
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
LegacyBlockFile::mFormat
sampleFormat mFormat
Definition: LegacyBlockFile.h:67
ArrayOf::reinit
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
SAMPLE_SIZE
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
floatSample
@ floatSample
Definition: SampleFormat.h:34
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
XMLValueChecker::IsGoodFileName
static bool IsGoodFileName(const FilePath &strFileName, const FilePath &strDirName={})
Definition: XMLTagHandler.cpp:58
format
int format
Definition: ExportPCM.cpp:56
ComputeLegacySummaryInfo
void ComputeLegacySummaryInfo(const wxFileName &fileName, size_t summaryLen, sampleFormat format, SummaryInfo *info, bool noRMS, bool Silent, float *min, float *max, float *rms)
Definition: LegacyBlockFile.cpp:38
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
XMLWriter::StartTag
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:76