Audacity 3.2.0
Import.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Import.h
6
7 Dominic Mazzoni
8
9**********************************************************************/
10
11#ifndef _IMPORT_
12#define _IMPORT_
13
14#include "ImportForwards.h"
15#include "Identifier.h"
16#include <vector>
17#include <wx/tokenzr.h> // for enum wxStringTokenizerMode
18
19#include "FileNames.h" // for FileType
20
21#include "Registry.h"
22
23class wxArrayString;
24class AudacityProject;
25class Tags;
27class Track;
28class TrackList;
29class ImportPlugin;
32typedef bool (*progress_callback_t)( void *userData, float percent );
33
34class ExtImportItem;
35class WaveTrack;
36
37namespace LibFileFormats
38{
39struct AcidizerTags;
40}
41
42using ExtImportItems = std::vector<std::unique_ptr<ExtImportItem>>;
43using TrackHolders = std::vector<std::shared_ptr<TrackList>>;
44
46{
47 public:
55 wxArrayString filters;
56
65
69 std::vector<ImportPlugin*> filter_objects;
70
75 wxArrayString extensions;
76
81 wxArrayString mime_types;
82};
83
84class IMPORT_EXPORT_API Importer {
85 struct ImporterItem;
86public:
87
88 // Objects of this type are statically constructed in files implementing
89 // subclasses of ImportPlugin
90 struct IMPORT_EXPORT_API RegisteredImportPlugin final
91 : Registry::RegisteredItem<ImporterItem>
92 {
94 const Identifier &id, // an internal string naming the plug-in
95 std::unique_ptr<ImportPlugin>,
96 const Registry::Placement &placement = { wxEmptyString, {} } );
97 };
98
99 // Objects of this type are statically constructed in files, to identify
100 // unsupported import formats; typically in a conditional compilation
102 RegisteredUnusableImportPlugin( std::unique_ptr<UnusableImportPlugin> );
103 };
104
105 Importer();
106 ~Importer();
107
108 Importer( const Importer& ) = delete;
110
114 static Importer & Get();
115
119 bool Initialize();
120 bool Terminate();
121
127 GetFileTypes( const FileNames::FileType &extraType = {} );
128
132 static void
133 SetLastOpenType( const FileNames::FileType &type );
134
138 static void
139 SetDefaultOpenType( const FileNames::FileType &type );
140
144 static size_t
145 SelectDefaultOpenType( const FileNames::FileTypes &fileTypes );
146
151 void ReadImportItems();
152
156 void WriteImportItems();
157
163 void StringToList(wxString &str, wxString &delims, wxArrayString &list, wxStringTokenizerMode mod = wxTOKEN_RET_EMPTY_ALL);
164
169 ExtImportItems &GetImportItems() { return mExtImportItems; }
170
175 std::unique_ptr<ExtImportItem> CreateDefaultImportItem();
176
177 // if false, the import failed and errorMessage will be set.
178 bool Import(
179 AudacityProject& project, const FilePath& fName,
180 ImportProgressListener* importProgressListener,
181 WaveTrackFactory* trackFactory, TrackHolders& tracks, Tags* tags,
182 std::optional<LibFileFormats::AcidizerTags>& outAcidTags,
183 TranslatableString& errorMessage);
184
185 private:
187 {
189 };
190 struct IMPORT_EXPORT_API ImporterItem final : Registry::SingleItem {
192
193 ImporterItem( const Identifier &id, std::unique_ptr<ImportPlugin> pPlugin );
195 std::unique_ptr<ImportPlugin> mpPlugin;
196 };
197
199
201 static ImportPluginList &sImportPluginList();
202 static UnusableImportPluginList &sUnusableImportPluginList();
203};
204
205extern IMPORT_EXPORT_API BoolSetting NewImportingSession;
206
207#endif
#define str(a)
std::vector< std::unique_ptr< ExtImportItem > > ExtImportItems
Definition: Import.h:42
bool(* progress_callback_t)(void *userData, float percent)
Definition: Import.h:32
IMPORT_EXPORT_API BoolSetting NewImportingSession
Definition: Import.cpp:846
std::vector< std::unique_ptr< UnusableImportPlugin > > UnusableImportPluginList
std::vector< ImportPlugin * > ImportPluginList
std::vector< std::shared_ptr< TrackList > > TrackHolders
Definition: ImportRaw.h:24
wxString FilePath
Definition: Project.h:21
const auto tracks
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:346
wxArrayString filters
Definition: Import.h:55
int divider
Definition: Import.h:64
wxArrayString extensions
Definition: Import.h:75
wxArrayString mime_types
Definition: Import.h:81
std::vector< ImportPlugin * > filter_objects
Definition: Import.h:69
std::vector< FileType > FileTypes
Definition: FileNames.h:75
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Definition: ImportPlugin.h:67
Interface used to report on import state and progress.
Singleton class which actually imports the audio, using ImportPlugin objects that are registered by m...
Definition: Import.h:84
Importer & operator=(Importer &)=delete
static Importer mInstance
Definition: Import.h:198
Importer(const Importer &)=delete
ExtImportItems mExtImportItems
Definition: Import.h:200
ExtImportItems & GetImportItems()
Definition: Import.h:169
Generates classes whose instances register items at construction.
Definition: Registry.h:388
ID3 Tags (for MP3)
Definition: Tags.h:73
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
Holds a msgid for the translation catalog; may also bind format arguments.
Used in place of a real plug in for plug ins that have not been compiled or are not available in this...
Definition: ImportPlugin.h:177
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:1279
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
std::unique_ptr< ImportPlugin > mpPlugin
Definition: Import.h:195
Common abstract base class for items that are not groups.
Definition: Registry.h:224
Primary template for a list of arbitrary types.
Definition: TypeList.h:61