mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-15 16:17:41 +02:00
Separate versions of DoImportMIDI that do and don't assume a project
This commit is contained in:
parent
ff2cf496cd
commit
8eca219d57
@ -106,6 +106,9 @@ public:
|
|||||||
|
|
||||||
/// Namespace for functions for File menu
|
/// Namespace for functions for File menu
|
||||||
namespace FileActions {
|
namespace FileActions {
|
||||||
|
// Import into existing project
|
||||||
|
bool DoImportMIDI( AudacityProject &project, const FilePath &fileName );
|
||||||
|
// Import file, creating a project if the first argument is null
|
||||||
AudacityProject *DoImportMIDI(
|
AudacityProject *DoImportMIDI(
|
||||||
AudacityProject *pProject, const FilePath &fileName );
|
AudacityProject *pProject, const FilePath &fileName );
|
||||||
}
|
}
|
||||||
|
@ -1303,7 +1303,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||||||
{
|
{
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
if (FileNames::IsMidi(fileName))
|
if (FileNames::IsMidi(fileName))
|
||||||
FileActions::DoImportMIDI( &project, fileName );
|
FileActions::DoImportMIDI( project, fileName );
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
Import( fileName );
|
Import( fileName );
|
||||||
|
@ -326,7 +326,7 @@ public:
|
|||||||
for (const auto &name : sortednames) {
|
for (const auto &name : sortednames) {
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
if (FileNames::IsMidi(name))
|
if (FileNames::IsMidi(name))
|
||||||
FileActions::DoImportMIDI(mProject, name);
|
FileActions::DoImportMIDI( *mProject, name);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
ProjectFileManager::Get( *mProject ).Import(name);
|
ProjectFileManager::Get( *mProject ).Import(name);
|
||||||
|
@ -112,36 +112,46 @@ namespace FileActions {
|
|||||||
// exported helper functions
|
// exported helper functions
|
||||||
|
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
|
// Given an existing project, try to import into it, return true on success
|
||||||
|
bool DoImportMIDI( AudacityProject &project, const FilePath &fileName )
|
||||||
|
{
|
||||||
|
auto &tracks = TrackList::Get( project );
|
||||||
|
auto newTrack = TrackFactory::Get( project ).NewNoteTrack();
|
||||||
|
|
||||||
|
if (::ImportMIDI(fileName, newTrack.get())) {
|
||||||
|
|
||||||
|
SelectUtilities::SelectNone( project );
|
||||||
|
auto pTrack = tracks.Add( newTrack );
|
||||||
|
pTrack->SetSelected(true);
|
||||||
|
|
||||||
|
ProjectHistory::Get( project )
|
||||||
|
.PushState(
|
||||||
|
wxString::Format(_("Imported MIDI from '%s'"),
|
||||||
|
fileName),
|
||||||
|
_("Import MIDI")
|
||||||
|
);
|
||||||
|
|
||||||
|
ProjectWindow::Get( project ).ZoomAfterImport(pTrack);
|
||||||
|
FileHistory::Global().AddFileToHistory(fileName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// return null on failure; if success, return the given project, or a NEW
|
// return null on failure; if success, return the given project, or a NEW
|
||||||
// one, if the given was null; create no NEW project if failure
|
// one, if the given was null; create no NEW project if failure
|
||||||
AudacityProject *DoImportMIDI(
|
AudacityProject *DoImportMIDI(
|
||||||
AudacityProject *pProject, const FilePath &fileName)
|
AudacityProject *pProject, const FilePath &fileName)
|
||||||
{
|
{
|
||||||
auto &tracks = TrackList::Get( *pProject );
|
|
||||||
|
|
||||||
AudacityProject *pNewProject {};
|
AudacityProject *pNewProject {};
|
||||||
if ( !pProject )
|
if ( !pProject )
|
||||||
pProject = pNewProject = ProjectManager::New();
|
pProject = pNewProject = ProjectManager::New();
|
||||||
auto cleanup = finally( [&]
|
auto cleanup = finally( [&]
|
||||||
{ if ( pNewProject ) GetProjectFrame( *pNewProject ).Close(true); } );
|
{ if ( pNewProject ) GetProjectFrame( *pNewProject ).Close(true); } );
|
||||||
|
|
||||||
auto newTrack = TrackFactory::Get( *pProject ).NewNoteTrack();
|
if ( DoImportMIDI( *pProject, fileName ) ) {
|
||||||
|
|
||||||
if (::ImportMIDI(fileName, newTrack.get())) {
|
|
||||||
|
|
||||||
SelectUtilities::SelectNone( *pProject );
|
|
||||||
auto pTrack = tracks.Add( newTrack );
|
|
||||||
pTrack->SetSelected(true);
|
|
||||||
|
|
||||||
ProjectHistory::Get( *pProject )
|
|
||||||
.PushState(wxString::Format(_("Imported MIDI from '%s'"),
|
|
||||||
fileName), _("Import MIDI"));
|
|
||||||
|
|
||||||
ProjectWindow::Get( *pProject ).ZoomAfterImport(pTrack);
|
|
||||||
pNewProject = nullptr;
|
pNewProject = nullptr;
|
||||||
|
|
||||||
FileHistory::Global().AddFileToHistory(fileName);
|
|
||||||
|
|
||||||
return pProject;
|
return pProject;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -512,7 +522,7 @@ void OnImportMIDI(const CommandContext &context)
|
|||||||
&window); // Parent
|
&window); // Parent
|
||||||
|
|
||||||
if (!fileName.empty())
|
if (!fileName.empty())
|
||||||
DoImportMIDI(&project, fileName);
|
DoImportMIDI(project, fileName);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user