Audacity  3.0.3
ImportPlugin.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 ImportPlugin.cpp
6 
7 Paul Licameli split from Import.cpp
8 
9 **********************************************************************/
10 
11 #include "ImportPlugin.h"
12 
13 #include <wx/filename.h>
14 #include "../WaveTrack.h"
15 #include "../widgets/ProgressDialog.h"
16 #include "QualitySettings.h"
17 
19  mExtensions( std::move( supportedExtensions ) )
20 {
21 }
22 
23 ImportPlugin::~ImportPlugin() = default;
24 
26 {
27  return mExtensions;
28 }
29 
31 {
32  // Case-insensitive check if extension is supported
33  return mExtensions.Index(extension, false) != wxNOT_FOUND;
34 }
35 
37 : mFilename(filename)
38 {
39 }
40 
42 {
43 }
44 
46 {
47  wxFileName ff( mFilename );
48 
49  auto title = XO("Importing %s").Format( GetFileDescription() );
50  mProgress = std::make_unique< ProgressDialog >(
51  title, Verbatim( ff.GetFullName() ) );
52 }
53 
55 {
56  // Consult user preference
57  auto defaultFormat = QualitySettings::SampleFormatChoice();
58 
59  // Don't choose format narrower than effective or default
60  auto format = std::max(effectiveFormat, defaultFormat);
61 
62  // But also always promote 24 bits to float
63  if (format > int16Sample)
65 
66  return format;
67 }
68 
69 std::shared_ptr<WaveTrack> ImportFileHandle::NewWaveTrack(
70  WaveTrackFactory &trackFactory, sampleFormat effectiveFormat, double rate)
71 {
72  return trackFactory.NewWaveTrack(ChooseFormat(effectiveFormat), rate);
73 }
ImportFileHandle::~ImportFileHandle
virtual ~ImportFileHandle()
Definition: ImportPlugin.cpp:41
XO
#define XO(s)
Definition: Internat.h:31
ImportFileHandle::mProgress
std::unique_ptr< ProgressDialog > mProgress
Definition: ImportPlugin.h:159
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
ImportPlugin::mExtensions
const FileExtensions mExtensions
Definition: ImportPlugin.h:99
floatSample
@ floatSample
Definition: SampleFormat.h:34
FileExtension
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
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
FilePath
wxString FilePath
Definition: Project.h:20
ImportFileHandle::ChooseFormat
static sampleFormat ChooseFormat(sampleFormat effectiveFormat)
Choose appropriate format, which will not be narrower than the specified one.
Definition: ImportPlugin.cpp:54
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
format
int format
Definition: ExportPCM.cpp:56
ImportFileHandle::mFilename
FilePath mFilename
Definition: ImportPlugin.h:158
ImportPlugin::GetSupportedExtensions
virtual FileExtensions GetSupportedExtensions()
Definition: ImportPlugin.cpp:25
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
WaveTrackFactory
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:710
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
ImportPlugin::SupportsExtension
bool SupportsExtension(const FileExtension &extension)
Definition: ImportPlugin.cpp:30
ImportFileHandle::GetFileDescription
virtual TranslatableString GetFileDescription()=0
QualitySettings.h
ImportPlugin::~ImportPlugin
virtual ~ImportPlugin()
QualitySettings::SampleFormatChoice
PROJECT_RATE_API sampleFormat SampleFormatChoice()
Definition: QualitySettings.cpp:38
ImportPlugin.h
The interface that all file import "plugins" (if you want to call them that) must implement....
Verbatim
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Definition: TranslatableString.h:321
ImportPlugin::ImportPlugin
ImportPlugin(FileExtensions supportedExtensions)
Definition: ImportPlugin.cpp:18
WaveTrackFactory::NewWaveTrack
std::shared_ptr< WaveTrack > NewWaveTrack(sampleFormat format=(sampleFormat) 0, double rate=0)
Definition: WaveTrack.cpp:113