Audacity 3.2.0
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 TranslatableString GetFileDescription ()=0
 
virtual ByteCount GetFileUncompressedBytes ()=0
 
virtual wxInt32 GetStreamCount ()=0
 
virtual const TranslatableStringsGetStreamInfo ()=0
 
virtual void SetStreamUsage (wxInt32 StreamID, bool Use)=0
 
virtual ProgressResult Import (WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags)=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 133 of file ImportFLAC.cpp.

Constructor & Destructor Documentation

◆ FLACImportFileHandle()

FLACImportFileHandle::FLACImportFileHandle ( const FilePath name)

Definition at line 333 of file ImportFLAC.cpp.

335 mSamplesDone(0),
336 mStreamInfoDone(false),
338{
339 // Initialize mFormat as narrowest
341 mFile = std::make_unique<MyFLACFile>(this);
342}
const TranslatableString name
Definition: Distortion.cpp:76
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
FLAC__uint64 mSamplesDone
Definition: ImportFLAC.cpp:166
std::unique_ptr< MyFLACFile > mFile
Definition: ImportFLAC.cpp:160
ProgressResult mUpdateResult
Definition: ImportFLAC.cpp:168
sampleFormat mFormat
Definition: ImportFLAC.cpp:159
ImportFileHandle(const FilePath &filename)

References mFile, mFormat, and narrowestSampleFormat.

◆ ~FLACImportFileHandle()

FLACImportFileHandle::~FLACImportFileHandle ( )

Definition at line 485 of file ImportFLAC.cpp.

486{
487 mFile->finish();
488}

References mFile.

Member Function Documentation

◆ GetFileDescription()

TranslatableString FLACImportFileHandle::GetFileDescription ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 396 of file ImportFLAC.cpp.

397{
398 return DESC;
399}
#define DESC
Definition: ImportFLAC.cpp:46

References DESC.

◆ GetFileUncompressedBytes()

auto FLACImportFileHandle::GetFileUncompressedBytes ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 402 of file ImportFLAC.cpp.

403{
404 // TODO: Get Uncompressed byte count.
405 return 0;
406}

◆ GetStreamCount()

wxInt32 FLACImportFileHandle::GetStreamCount ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 147 of file ImportFLAC.cpp.

147{ return 1; }

◆ GetStreamInfo()

const TranslatableStrings & FLACImportFileHandle::GetStreamInfo ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 149 of file ImportFLAC.cpp.

150 {
151 static TranslatableStrings empty;
152 return empty;
153 }
std::vector< TranslatableString > TranslatableStrings

◆ Import()

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

Implements ImportFileHandle.

Definition at line 409 of file ImportFLAC.cpp.

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

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

Here is the call graph for this function:

◆ Init()

bool FLACImportFileHandle::Init ( )

Definition at line 344 of file ImportFLAC.cpp.

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

References mFile, ImportFileHandle::mFilename, mHandle, OSINPUT, and wxT().

Here is the call graph for this function:

◆ SetStreamUsage()

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

Definition at line 155 of file ImportFLAC.cpp.

156 {}

Friends And Related Function Documentation

◆ MyFLACFile

friend class MyFLACFile
friend

Definition at line 135 of file ImportFLAC.cpp.

Member Data Documentation

◆ mBitsPerSample

unsigned long FLACImportFileHandle::mBitsPerSample
private

Definition at line 164 of file ImportFLAC.cpp.

Referenced by MyFLACFile::metadata_callback().

◆ mChannels

NewChannelGroup FLACImportFileHandle::mChannels
private

Definition at line 169 of file ImportFLAC.cpp.

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

◆ mFile

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

Definition at line 160 of file ImportFLAC.cpp.

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

◆ mFormat

sampleFormat FLACImportFileHandle::mFormat
private

Definition at line 159 of file ImportFLAC.cpp.

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

◆ mHandle

wxFFile FLACImportFileHandle::mHandle
private

Definition at line 161 of file ImportFLAC.cpp.

Referenced by Init().

◆ mNumChannels

unsigned long FLACImportFileHandle::mNumChannels
private

◆ mNumSamples

FLAC__uint64 FLACImportFileHandle::mNumSamples
private

Definition at line 165 of file ImportFLAC.cpp.

Referenced by MyFLACFile::metadata_callback().

◆ mSampleRate

unsigned long FLACImportFileHandle::mSampleRate
private

Definition at line 162 of file ImportFLAC.cpp.

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

◆ mSamplesDone

FLAC__uint64 FLACImportFileHandle::mSamplesDone
private

Definition at line 166 of file ImportFLAC.cpp.

◆ mStreamInfoDone

bool FLACImportFileHandle::mStreamInfoDone
private

Definition at line 167 of file ImportFLAC.cpp.

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

◆ mUpdateResult

ProgressResult FLACImportFileHandle::mUpdateResult
private

Definition at line 168 of file ImportFLAC.cpp.

Referenced by Import().


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