Skip to content

Commit

Permalink
Added ability to specify a .txt file on CLI and it be imported as a l…
Browse files Browse the repository at this point in the history
…abels file.

Signed-off-by: Jaggzh <[email protected]>
  • Loading branch information
jaggzh authored and Avery King committed Nov 12, 2024
1 parent 02989f0 commit 4dd0e18
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/ProjectFileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,19 @@ TenacityProject *ProjectFileManager::OpenFile( const ProjectChooserFn &chooser,
return nullptr;
}
#endif

auto &project = chooser(false);

if (fileName.AfterLast('.').IsSameAs(wxT("txt"), false)) {
// Import as labels
if (Get(project).ImportLabelsFromFile(fileName)) {
return &project;
} else {
return nullptr;
}
}


// Undo history is incremented inside this:
if (Get(project).Import(fileName)) {
// Undo history is incremented inside this:
Expand All @@ -993,6 +1005,42 @@ TenacityProject *ProjectFileManager::OpenFile( const ProjectChooserFn &chooser,
return Get(project).OpenProjectFile(fileName, addtohistory);
}

// In ProjectFileManager.cpp:
bool ProjectFileManager::ImportLabelsFromFile(const wxString &fileName)
{
auto &project = mProject;
auto &trackFactory = WaveTrackFactory::Get( project );
auto &tracks = TrackList::Get( project );
auto &window = ProjectWindow::Get( project );

wxTextFile f;

f.Open(fileName);
if (!f.IsOpened()) {
AudacityMessageBox(
XO("Could not open file: %s").Format( fileName ) );
return false;
}

auto newTrack = std::make_shared<LabelTrack>();
wxString sTrackName;
wxFileName::SplitPath(fileName, NULL, NULL, &sTrackName, NULL);
newTrack->SetName(sTrackName);

newTrack->Import(f);

SelectUtilities::SelectNone( project );
newTrack->SetSelected(true);
tracks.Add( newTrack );

ProjectHistory::Get( project ).PushState(
XO("Imported labels from '%s'").Format( fileName ),
XO("Import Labels"));

window.ZoomAfterImport(nullptr);
return true;
}

TenacityProject *ProjectFileManager::OpenProjectFile(
const FilePath &fileName, bool addtohistory)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class TENACITY_DLL_API ProjectFileManager final
bool Import(const FilePath &fileName,
bool addToHistory = true);

bool ImportLabelsFromFile(const wxString &fileName);

void Compact();

void AddImportedTracks(const FilePath &fileName,
Expand Down

0 comments on commit 4dd0e18

Please sign in to comment.