Audacity  3.0.3
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 "../widgets/wxPanelWrapper.h" // to inherit
20 #include "FileNames.h" // for FileType
21 
22 #include "Registry.h"
23 
24 class wxArrayString;
25 class wxListBox;
26 class AudacityProject;
27 class Tags;
28 class WaveTrackFactory;
29 class Track;
30 class ImportPlugin;
31 class ImportFileHandle;
33 typedef bool (*progress_callback_t)( void *userData, float percent );
34 
35 class ExtImportItem;
36 class WaveTrack;
37 
38 using ExtImportItems = std::vector< std::unique_ptr<ExtImportItem> >;
39 using TrackHolders = std::vector< std::vector< std::shared_ptr<WaveTrack> > >;
40 
42 {
43  public:
51  wxArrayString filters;
52 
60  int divider;
61 
65  std::vector<ImportPlugin*> filter_objects;
66 
71  wxArrayString extensions;
72 
77  wxArrayString mime_types;
78 };
79 
80 class AUDACITY_DLL_API Importer {
81 public:
82 
83  // Objects of this type are statically constructed in files implementing
84  // subclasses of ImportPlugin
85  struct AUDACITY_DLL_API RegisteredImportPlugin{
87  const Identifier &id, // an internal string naming the plug-in
88  std::unique_ptr<ImportPlugin>,
89  const Registry::Placement &placement = { wxEmptyString, {} } );
90  };
91 
92  // Objects of this type are statically constructed in files, to identify
93  // unsupported import formats; typically in a conditional compilation
95  RegisteredUnusableImportPlugin( std::unique_ptr<UnusableImportPlugin> );
96  };
97 
98  Importer();
99  ~Importer();
100 
101  Importer( const Importer& ) PROHIBITED;
102  Importer &operator=( Importer& ) PROHIBITED;
103 
107  static Importer & Get();
108 
112  bool Initialize();
113  bool Terminate();
114 
120  GetFileTypes( const FileNames::FileType &extraType = {} );
121 
125  static void
126  SetLastOpenType( const FileNames::FileType &type );
127 
131  static void
132  SetDefaultOpenType( const FileNames::FileType &type );
133 
137  static size_t
138  SelectDefaultOpenType( const FileNames::FileTypes &fileTypes );
139 
144  void ReadImportItems();
145 
149  void WriteImportItems();
150 
156  void StringToList(wxString &str, wxString &delims, wxArrayString &list, wxStringTokenizerMode mod = wxTOKEN_RET_EMPTY_ALL);
157 
162  ExtImportItems &GetImportItems() { return mExtImportItems; }
163 
168  std::unique_ptr<ExtImportItem> CreateDefaultImportItem();
169 
170  // if false, the import failed and errorMessage will be set.
171  bool Import( AudacityProject &project,
172  const FilePath &fName,
173  WaveTrackFactory *trackFactory,
174  TrackHolders &tracks,
175  Tags *tags,
176  TranslatableString &errorMessage);
177 
178 private:
180 
182  static ImportPluginList &sImportPluginList();
183  static UnusableImportPluginList &sUnusableImportPluginList();
184 };
185 
186 //----------------------------------------------------------------------------
187 // ImportStreamDialog
188 //----------------------------------------------------------------------------
189 
191 {
192 public:
193  // constructors and destructors
195  wxWindow *parent, wxWindowID id, const TranslatableString &title,
196  const wxPoint& pos = wxDefaultPosition,
197  const wxSize& size = wxDefaultSize,
198  long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
199  virtual ~ImportStreamDialog();
200 
201 private:
203  wxInt32 scount;
204  wxListBox *StreamList;
205 
206 private:
207  void OnOk( wxCommandEvent &event );
208  void OnCancel( wxCommandEvent &event );
209 
210 private:
211  DECLARE_EVENT_TABLE()
212 };
213 
214 #endif
Importer::GetImportItems
ExtImportItems & GetImportItems()
Definition: Import.h:162
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
ImportForwards.h
Importer::mExtImportItems
ExtImportItems mExtImportItems
Definition: Import.h:181
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
TrackHolders
std::vector< std::vector< std::shared_ptr< WaveTrack > > > TrackHolders
Definition: Import.h:39
Importer
Class which actually imports the auido, using functions defined in ImportPCM.cpp, ImportMP3....
Definition: Import.h:80
ImportPlugin
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Definition: ImportPlugin.h:67
Tags
ID3 Tags (for MP3)
Definition: Tags.h:74
ImportStreamDialog::OnOk
void OnOk(wxCommandEvent &event)
Definition: Import.cpp:883
UnusableImportPlugin
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:165
ExtImportItem::divider
int divider
Definition: Import.h:60
ExtImportItem::filter_objects
std::vector< ImportPlugin * > filter_objects
Definition: Import.h:65
ImportStreamDialog::mFile
ImportFileHandle * mFile
Definition: Import.h:202
Registry::Placement
Definition: Registry.h:219
ImportPluginList
std::vector< ImportPlugin * > ImportPluginList
Definition: ImportForwards.h:19
Identifier
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
ExtImportItem::extensions
wxArrayString extensions
Definition: Import.h:71
FilePath
wxString FilePath
Definition: Project.h:20
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
Importer::Importer
Importer(const Importer &) PROHIBITED
progress_callback_t
bool(* progress_callback_t)(void *userData, float percent)
Definition: Import.h:33
ImportStreamDialog::StreamList
wxListBox * StreamList
Definition: Import.h:204
Identifier.h
ImportFileHandle
An ImportFileHandle for data.
Definition: ImportPlugin.h:107
Journal::Events::Initialize
void Initialize()
Definition: JournalEvents.cpp:421
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
Importer::mInstance
static Importer mInstance
Definition: Import.h:179
WaveTrackFactory
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:710
Registry.h
ExtImportItem::filters
wxArrayString filters
Definition: Import.h:51
ImportStreamDialog::scount
wxInt32 scount
Definition: Import.h:203
wxDialogWrapper
Definition: wxPanelWrapper.h:81
ExtImportItems
std::vector< std::unique_ptr< ExtImportItem > > ExtImportItems
Definition: Import.h:38
UnusableImportPluginList
std::vector< std::unique_ptr< UnusableImportPlugin > > UnusableImportPluginList
Definition: ImportForwards.h:21
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
ImportStreamDialog
Definition: Import.h:191
FileNames.h
Importer::RegisteredImportPlugin
Definition: Import.h:85
ImportStreamDialog::OnCancel
void OnCancel(wxCommandEvent &event)
Definition: Import.cpp:892
Importer::operator=
Importer & operator=(Importer &) PROHIBITED
FileNames::FileTypes
std::vector< FileType > FileTypes
Definition: FileNames.h:76
ExtImportItem::mime_types
wxArrayString mime_types
Definition: Import.h:77
ExtImportItem
Definition: Import.h:42
FileNames::FileType
Definition: FileNames.h:52
ImportStreamDialog::ImportStreamDialog
ImportStreamDialog(ImportFileHandle *_mFile, wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
Definition: Import.cpp:844
Importer::RegisteredUnusableImportPlugin
Definition: Import.h:94
ImportStreamDialog::~ImportStreamDialog
virtual ~ImportStreamDialog()
Definition: Import.cpp:878