73#include <wx/textfile.h>
74#include <wx/tokenzr.h>
88#define BINARY_FILE_CHECK_BUFFER_SIZE 1024
90#define DESC XO("List of Files in basic text format")
108 std::unique_ptr<ImportFileHandle>
Open(
117 const FilePath &
name, std::unique_ptr<wxTextFile> &&file);
125 std::optional<LibFileFormats::AcidizerTags>& outAcidTags)
override;
131 void Stop()
override;
167 const FilePath &
name, std::unique_ptr<wxTextFile> &&file)
168: mTextFile(
std::move(file))
170 , mProject{ pProject }
185 if (!binaryFile.Open(filename))
191 bool isTextFile =
false;
192 const std::string lofToken(
"file");
195 if (count > (lofToken.length() +
sizeof(
' ') + 1))
201 auto IsUtf16_BE = [](
const char*
str) ->
bool
203 return str[0] ==
static_cast<char>(0xFE) &&
str[1] ==
static_cast<char>(0xFF);
205 auto IsUtf16_LE = [](
const char*
str) ->
bool
207 return str[0] ==
static_cast<char>(0xFF) &&
str[1] ==
static_cast<char>(0xFE);
211 auto IsUtf32_BE = [](
const char*
str) ->
bool
213 return str[0] ==
static_cast<char>(0x00) &&
214 str[1] ==
static_cast<char>(0x00) &&
215 str[2] ==
static_cast<char>(0xFE) &&
216 str[3] ==
static_cast<char>(0xFF);
218 auto IsUtf32_LE = [](
const char*
str) ->
bool
220 return str[0] ==
static_cast<char>(0xFF) &&
221 str[1] ==
static_cast<char>(0xFE) &&
222 str[2] ==
static_cast<char>(0x00) &&
223 str[3] ==
static_cast<char>(0x00);
227 if (IsUtf16_BE(buf) || IsUtf16_LE(buf) || IsUtf32_BE(buf) || IsUtf32_LE(buf))
234 buf[
sizeof(buf) - 1] =
'\0';
236 std::string importedText(buf);
251 auto file = std::make_unique<wxTextFile>(filename);
254 if (!file->IsOpened())
257 return std::make_unique<LOFImportFileHandle>(
258 pProject, filename, std::move(file));
273 TrackHolders& outTracks,
Tags*, std::optional<LibFileFormats::AcidizerTags>&)
298 wxString line =
mTextFile->GetFirstLine();
335 std::make_unique< LOFImportPlugin >()
346 wxStringTokenizer tok(*ln,
wxT(
" "));
347 wxStringTokenizer temptok1(*ln,
wxT(
"\""));
348 wxStringTokenizer temptok2(*ln,
wxT(
" "));
352 wxString tokenholder = tok.GetNextToken();
355 if (tokenholder.IsSameAs(
wxT(
"window"),
false))
366 while (tok.HasMoreTokens())
368 tokenholder = tok.GetNextToken();
370 if (tokenholder.IsSameAs(
wxT(
"offset"),
false))
372 if (tok.HasMoreTokens())
373 tokenholder = tok.GetNextToken();
383 XO(
"Invalid window offset in LOF file."));
386 if (tok.HasMoreTokens())
387 tokenholder = tok.GetNextToken();
390 if (tokenholder.IsSameAs(
wxT(
"duration"),
false))
392 if (tok.HasMoreTokens())
393 tokenholder = tok.GetNextToken();
403 XO(
"Invalid duration in LOF file."));
407 if (tokenholder ==
wxT(
"#"))
410 tok = wxStringTokenizer(
wxT(
""),
wxT(
" "));
415 else if (tokenholder.IsSameAs(
wxT(
"file"),
false))
419 tokenholder = temptok1.GetNextToken();
420 wxString targettoken = temptok1.GetNextToken();
421 targetfile = targettoken;
424 if(!wxIsAbsolutePath(targetfile)) {
425 wxFileName fName(targetfile);
426 fName.Normalize(wxPATH_NORM_ALL,
mLOFFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
427 if(fName.FileExists()) {
428 targetfile = fName.GetFullPath();
437 temptok2.SetString(targettoken);
438 tokenplace = temptok2.CountTokens();
440 for (
int i = 0; i < tokenplace; i++)
441 tokenholder = tok.GetNextToken();
443 if (tok.HasMoreTokens())
445 tokenholder = tok.GetNextToken();
447 if (tokenholder ==
wxT(
"#"))
450 tok = wxStringTokenizer(
wxT(
""),
wxT(
" "));
453 if (tokenholder.IsSameAs(
wxT(
"offset"),
false))
455 if (tok.HasMoreTokens())
456 tokenholder = tok.GetNextToken();
467 auto t = *
tracks.rbegin();
475 if (targetfile.AfterLast(
wxT(
'.')).IsSameAs(
wxT(
"mid"),
false) ||
476 targetfile.AfterLast(
wxT(
'.')).IsSameAs(
wxT(
"midi"),
false))
491 XO(
"Invalid track offset in LOF file."));
497 else if (tokenholder ==
wxT(
"#"))
500 tok = wxStringTokenizer(
wxT(
""),
wxT(
" "));
static Importer::RegisteredImportPlugin registered
#define BINARY_FILE_CHECK_BUFFER_SIZE
The interface that all file import "plugins" (if you want to call them that) must implement....
std::vector< std::shared_ptr< Track > > TrackHolders
accessors for certain important windows associated with each project
std::vector< TranslatableString > TranslatableStrings
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Base class for FlacImportFileHandle, LOFImportFileHandle, MP3ImportFileHandle, OggImportFileHandle an...
unsigned long long ByteCount
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Interface used to report on import state and progress.
virtual void OnImportResult(ImportResult result)=0
Used to report on import result for file handle passed as argument to OnImportFileOpened.
static void ShowMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Import Project"))
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
An ImportFileHandle for LOF data.
const TranslatableStrings & GetStreamInfo() override
const wxFileName mLOFFileName
void SetStreamUsage(wxInt32 WXUNUSED(StreamID), bool WXUNUSED(Use)) override
void lofOpenFiles(wxString *ln)
Processes a single line from a LOF text file, doing whatever is indicated on the line.
LOFImportFileHandle(AudacityProject *pProject, const FilePath &name, std::unique_ptr< wxTextFile > &&file)
ByteCount GetFileUncompressedBytes() override
FilePath GetFilename() const override
std::unique_ptr< wxTextFile > mTextFile
void Import(ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &outAcidTags) override
wxInt32 GetStreamCount() override
AudacityProject * mProject
void doDurationAndScrollOffset()
TranslatableString GetFileDescription() override
An ImportPlugin for LOF data.
std::unique_ptr< ImportFileHandle > Open(const FilePath &Filename, AudacityProject *pProject) override
TranslatableString GetPluginFormatDescription() override
wxString GetPluginStringID() override
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static AudacityProject * OpenProject(AudacityProject *pGivenProject, const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject)
Open a file into an AudacityProject, returning the project, or nullptr for failure.
double GetEndTime() const
Return the greatest end time of the tracks, or 0 when no tracks.
static TrackList & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
void ZoomBy(double multiplier)
Multiply the magnification; unchanged left edge time.
void SetHorizontalThumb(double scrollto, bool doScroll=true)
static Viewport & Get(AudacityProject &project)
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
constexpr size_t npos(-1)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept