Audacity  3.0.3
Public Member Functions | Private Attributes | Friends | List of all members
FLACImportFileHandle Class Referencefinal

An ImportFileHandle for FLAC data. More...

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

Public Member Functions

 FLACImportFileHandle (const FilePath &name)
 
 ~FLACImportFileHandle ()
 
bool Init ()
 
TranslatableString GetFileDescription () override
 
ByteCount GetFileUncompressedBytes () override
 
ProgressResult Import (WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) override
 
wxInt32 GetStreamCount () override
 
const TranslatableStringsGetStreamInfo () override
 
void SetStreamUsage (wxInt32 WXUNUSED(StreamID), bool WXUNUSED(Use)) override
 
- Public Member Functions inherited from ImportFileHandle
 ImportFileHandle (const FilePath &filename)
 
virtual ~ImportFileHandle ()
 
void CreateProgress ()
 
virtual void SetStreamUsage (wxInt32 StreamID, bool Use)=0
 

Private Attributes

sampleFormat mFormat
 
std::unique_ptr< MyFLACFilemFile
 
wxFFile mHandle
 
unsigned long mSampleRate
 
unsigned long mNumChannels
 
unsigned long mBitsPerSample
 
FLAC__uint64 mNumSamples
 
FLAC__uint64 mSamplesDone
 
bool mStreamInfoDone
 
ProgressResult mUpdateResult
 
NewChannelGroup mChannels
 

Friends

class MyFLACFile
 

Additional Inherited Members

- Public Types inherited from ImportFileHandle
using ProgressResult = BasicUI::ProgressResult
 
using ByteCount = unsigned long long
 
- Static Public Member Functions inherited from ImportFileHandle
static sampleFormat ChooseFormat (sampleFormat effectiveFormat)
 Choose appropriate format, which will not be narrower than the specified one. More...
 
- Protected Member Functions inherited from ImportFileHandle
std::shared_ptr< WaveTrackNewWaveTrack (WaveTrackFactory &trackFactory, sampleFormat effectiveFormat, double rate)
 Build a wave track with appropriate format, which will not be narrower than the specified one. More...
 
- Protected Attributes inherited from ImportFileHandle
FilePath mFilename
 
std::unique_ptr< ProgressDialogmProgress
 

Detailed Description

An ImportFileHandle for FLAC data.

Definition at line 137 of file ImportFLAC.cpp.

Constructor & Destructor Documentation

◆ FLACImportFileHandle()

FLACImportFileHandle::FLACImportFileHandle ( const FilePath name)

Definition at line 335 of file ImportFLAC.cpp.

337  mSamplesDone(0),
338  mStreamInfoDone(false),
340 {
341  // Initialize mFormat as narrowest
343  mFile = std::make_unique<MyFLACFile>(this);
344 }

References mFile, mFormat, and narrowestSampleFormat.

◆ ~FLACImportFileHandle()

FLACImportFileHandle::~FLACImportFileHandle ( )

Definition at line 487 of file ImportFLAC.cpp.

488 {
489  mFile->finish();
490 }

References mFile.

Member Function Documentation

◆ GetFileDescription()

TranslatableString FLACImportFileHandle::GetFileDescription ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 398 of file ImportFLAC.cpp.

399 {
400  return DESC;
401 }

References DESC.

◆ GetFileUncompressedBytes()

auto FLACImportFileHandle::GetFileUncompressedBytes ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 404 of file ImportFLAC.cpp.

405 {
406  // TODO: Get Uncompressed byte count.
407  return 0;
408 }

◆ GetStreamCount()

wxInt32 FLACImportFileHandle::GetStreamCount ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 151 of file ImportFLAC.cpp.

151 { return 1; }

◆ GetStreamInfo()

const TranslatableStrings& FLACImportFileHandle::GetStreamInfo ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 153 of file ImportFLAC.cpp.

154  {
155  static TranslatableStrings empty;
156  return empty;
157  }

◆ Import()

ProgressResult FLACImportFileHandle::Import ( WaveTrackFactory trackFactory,
TrackHolders outTracks,
Tags tags 
)
overridevirtual

Implements ImportFileHandle.

Definition at line 411 of file ImportFLAC.cpp.

414 {
415  outTracks.clear();
416 
417  wxASSERT(mStreamInfoDone);
418 
419  CreateProgress();
420 
421  mChannels.resize(mNumChannels);
422 
423  {
424  auto iter = mChannels.begin();
425  for (size_t c = 0; c < mNumChannels; ++iter, ++c)
426  *iter = NewWaveTrack(*trackFactory, mFormat, mSampleRate);
427  }
428 
429  // TODO: Vigilant Sentry: Variable res unused after assignment (error code DA1)
430  // Should check the result.
431  #ifdef LEGACY_FLAC
432  bool res = (mFile->process_until_end_of_file() != 0);
433  #else
434  bool res = (mFile->process_until_end_of_stream() != 0);
435  #endif
436  wxUnusedVar(res);
437 
438  if (mUpdateResult == ProgressResult::Failed || mUpdateResult == ProgressResult::Cancelled) {
439  return mUpdateResult;
440  }
441 
442  for (const auto &channel : mChannels)
443  channel->Flush();
444 
445  if (!mChannels.empty())
446  outTracks.push_back(std::move(mChannels));
447 
448  wxString comment;
449  wxString description;
450 
451  size_t cnt = mFile->mComments.size();
452  if (cnt > 0) {
453  tags->Clear();
454  for (size_t c = 0; c < cnt; c++) {
455  wxString name = mFile->mComments[c].BeforeFirst(wxT('='));
456  wxString value = mFile->mComments[c].AfterFirst(wxT('='));
457  wxString upper = name.Upper();
458  if (upper == wxT("DATE") && !tags->HasTag(TAG_YEAR)) {
459  long val;
460  if (value.length() == 4 && value.ToLong(&val)) {
461  name = TAG_YEAR;
462  }
463  }
464  else if (upper == wxT("COMMENT") || upper == wxT("COMMENTS")) {
465  comment = value;
466  continue;
467  }
468  else if (upper == wxT("DESCRIPTION")) {
469  description = value;
470  continue;
471  }
472  tags->SetTag(name, value);
473  }
474 
475  if (comment.empty()) {
476  comment = description;
477  }
478  if (!comment.empty()) {
479  tags->SetTag(TAG_COMMENTS, comment);
480  }
481  }
482 
483  return mUpdateResult;
484 }

References RefreshCode::Cancelled, Tags::Clear(), ImportFileHandle::CreateProgress(), Tags::HasTag(), mChannels, mFile, mFormat, mNumChannels, mSampleRate, mStreamInfoDone, mUpdateResult, name, ImportFileHandle::NewWaveTrack(), Tags::SetTag(), TAG_COMMENTS, and TAG_YEAR.

Here is the call graph for this function:

◆ Init()

bool FLACImportFileHandle::Init ( )

Definition at line 346 of file ImportFLAC.cpp.

347 {
348 #ifdef LEGACY_FLAC
349  bool success = mFile->set_filename(OSINPUT(mFilename));
350  if (!success) {
351  return false;
352  }
353  mFile->set_metadata_respond(FLAC__METADATA_TYPE_STREAMINFO);
354  mFile->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT);
355  FLAC::Decoder::File::State state = mFile->init();
356  if (state != FLAC__FILE_DECODER_OK) {
357  return false;
358  }
359 #else
360  if (!mHandle.Open(mFilename, wxT("rb"))) {
361  return false;
362  }
363 
364  // Even though there is an init() method that takes a filename, use the one that
365  // takes a file handle because wxWidgets can open a file with a Unicode name and
366  // libflac can't (under Windows).
367  //
368  // Responsibility for closing the file is passed to libflac.
369  // (it happens when mFile->finish() is called)
370  bool result = mFile->init(mHandle.fp())?true:false;
371  mHandle.Detach();
372 
373  if (result != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
374  return false;
375  }
376 #endif
377  mFile->process_until_end_of_metadata();
378 
379 #ifdef LEGACY_FLAC
380  state = mFile->get_state();
381  if (state != FLAC__FILE_DECODER_OK) {
382  return false;
383  }
384 #else
385  // not necessary to check state, error callback will catch errors, but here's how:
386  if (mFile->get_state() > FLAC__STREAM_DECODER_READ_FRAME) {
387  return false;
388  }
389 #endif
390 
391  if (!mFile->is_valid() || mFile->get_was_error()) {
392  // This probably is not a FLAC file at all
393  return false;
394  }
395  return true;
396 }

References mFile, ImportFileHandle::mFilename, mHandle, and OSINPUT.

◆ SetStreamUsage()

void FLACImportFileHandle::SetStreamUsage ( wxInt32   WXUNUSEDStreamID,
bool   WXUNUSEDUse 
)
inlineoverride

Definition at line 159 of file ImportFLAC.cpp.

160  {}

Friends And Related Function Documentation

◆ MyFLACFile

friend class MyFLACFile
friend

Definition at line 139 of file ImportFLAC.cpp.

Member Data Documentation

◆ mBitsPerSample

unsigned long FLACImportFileHandle::mBitsPerSample
private

Definition at line 168 of file ImportFLAC.cpp.

Referenced by MyFLACFile::metadata_callback().

◆ mChannels

NewChannelGroup FLACImportFileHandle::mChannels
private

Definition at line 173 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::write_callback().

◆ mFile

std::unique_ptr<MyFLACFile> FLACImportFileHandle::mFile
private

Definition at line 164 of file ImportFLAC.cpp.

Referenced by FLACImportFileHandle(), Import(), Init(), and ~FLACImportFileHandle().

◆ mFormat

sampleFormat FLACImportFileHandle::mFormat
private

Definition at line 163 of file ImportFLAC.cpp.

Referenced by FLACImportFileHandle(), Import(), and MyFLACFile::metadata_callback().

◆ mHandle

wxFFile FLACImportFileHandle::mHandle
private

Definition at line 165 of file ImportFLAC.cpp.

Referenced by Init().

◆ mNumChannels

unsigned long FLACImportFileHandle::mNumChannels
private

◆ mNumSamples

FLAC__uint64 FLACImportFileHandle::mNumSamples
private

Definition at line 169 of file ImportFLAC.cpp.

Referenced by MyFLACFile::metadata_callback().

◆ mSampleRate

unsigned long FLACImportFileHandle::mSampleRate
private

Definition at line 166 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::metadata_callback().

◆ mSamplesDone

FLAC__uint64 FLACImportFileHandle::mSamplesDone
private

Definition at line 170 of file ImportFLAC.cpp.

◆ mStreamInfoDone

bool FLACImportFileHandle::mStreamInfoDone
private

Definition at line 171 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::metadata_callback().

◆ mUpdateResult

ProgressResult FLACImportFileHandle::mUpdateResult
private

Definition at line 172 of file ImportFLAC.cpp.

Referenced by Import().


The documentation for this class was generated from the following file:
narrowestSampleFormat
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
Definition: SampleFormat.h:37
OSINPUT
#define OSINPUT(X)
Definition: SelectFile.h:55
BasicUI::ProgressResult::Success
@ Success
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: TranslatableString.h:295
Tags::HasTag
bool HasTag(const wxString &name) const
Definition: Tags.cpp:452
FLACImportFileHandle::mChannels
NewChannelGroup mChannels
Definition: ImportFLAC.cpp:173
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
FLACImportFileHandle::mStreamInfoDone
bool mStreamInfoDone
Definition: ImportFLAC.cpp:171
FLACImportFileHandle::mFormat
sampleFormat mFormat
Definition: ImportFLAC.cpp:163
ImportFileHandle::ImportFileHandle
ImportFileHandle(const FilePath &filename)
Definition: ImportPlugin.cpp:36
ImportFileHandle::CreateProgress
void CreateProgress()
Definition: ImportPlugin.cpp:45
ImportFileHandle::NewWaveTrack
std::shared_ptr< WaveTrack > NewWaveTrack(WaveTrackFactory &trackFactory, sampleFormat effectiveFormat, double rate)
Build a wave track with appropriate format, which will not be narrower than the specified one.
Definition: ImportPlugin.cpp:69
Tags::SetTag
void SetTag(const wxString &name, const wxString &value, const bool bSpecialTag=false)
Definition: Tags.cpp:486
DESC
#define DESC
Definition: ImportFLAC.cpp:48
FLACImportFileHandle::mNumChannels
unsigned long mNumChannels
Definition: ImportFLAC.cpp:167
name
const TranslatableString name
Definition: Distortion.cpp:98
Tags::Clear
void Clear()
Definition: Tags.cpp:337
ImportFileHandle::mFilename
FilePath mFilename
Definition: ImportPlugin.h:158
TAG_YEAR
#define TAG_YEAR
Definition: Tags.h:64
FLACImportFileHandle::mUpdateResult
ProgressResult mUpdateResult
Definition: ImportFLAC.cpp:172
FLACImportFileHandle::mHandle
wxFFile mHandle
Definition: ImportFLAC.cpp:165
TAG_COMMENTS
#define TAG_COMMENTS
Definition: Tags.h:66
FLACImportFileHandle::mSampleRate
unsigned long mSampleRate
Definition: ImportFLAC.cpp:166
FLACImportFileHandle::mFile
std::unique_ptr< MyFLACFile > mFile
Definition: ImportFLAC.cpp:164
FLACImportFileHandle::mSamplesDone
FLAC__uint64 mSamplesDone
Definition: ImportFLAC.cpp:170