Move DoImportMidi out of FileMenus
This commit is contained in:
parent
8eca219d57
commit
2d11e6bda9
|
@ -104,15 +104,6 @@ public:
|
|||
// Exported helper functions from various menu handling source files
|
||||
|
||||
|
||||
/// Namespace for functions for File menu
|
||||
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 *pProject, const FilePath &fileName );
|
||||
}
|
||||
|
||||
/// Namespace for functions for Edit menu
|
||||
namespace EditActions {
|
||||
bool DoEditMetadata(
|
||||
|
|
|
@ -24,7 +24,6 @@ Paul Licameli split from AudacityProject.cpp
|
|||
#include "DirManager.h"
|
||||
#include "FileNames.h"
|
||||
#include "Legacy.h"
|
||||
#include "Menus.h"
|
||||
#include "PlatformCompatibility.h"
|
||||
#include "Project.h"
|
||||
#include "ProjectFileIO.h"
|
||||
|
@ -47,6 +46,7 @@ Paul Licameli split from AudacityProject.cpp
|
|||
#include "blockfile/ODDecodeBlockFile.h"
|
||||
#include "export/Export.h"
|
||||
#include "import/Import.h"
|
||||
#include "import/ImportMIDI.h"
|
||||
#include "commands/CommandContext.h"
|
||||
#include "ondemand/ODComputeSummaryTask.h"
|
||||
#include "ondemand/ODDecodeFlacTask.h"
|
||||
|
@ -1303,7 +1303,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
{
|
||||
#ifdef USE_MIDI
|
||||
if (FileNames::IsMidi(fileName))
|
||||
FileActions::DoImportMIDI( project, fileName );
|
||||
DoImportMIDI( project, fileName );
|
||||
else
|
||||
#endif
|
||||
Import( fileName );
|
||||
|
|
|
@ -37,6 +37,7 @@ Paul Licameli split from AudacityProject.cpp
|
|||
#include "UndoManager.h"
|
||||
#include "WaveTrack.h"
|
||||
#include "wxFileNameWrapper.h"
|
||||
#include "import/ImportMIDI.h"
|
||||
#include "ondemand/ODManager.h"
|
||||
#include "prefs/QualityPrefs.h"
|
||||
#include "toolbars/ControlToolBar.h"
|
||||
|
@ -326,7 +327,7 @@ public:
|
|||
for (const auto &name : sortednames) {
|
||||
#ifdef USE_MIDI
|
||||
if (FileNames::IsMidi(name))
|
||||
FileActions::DoImportMIDI( *mProject, name);
|
||||
DoImportMIDI( *mProject, name );
|
||||
else
|
||||
#endif
|
||||
ProjectFileManager::Get( *mProject ).Import(name);
|
||||
|
|
|
@ -84,7 +84,6 @@
|
|||
#include "../WaveTrack.h"
|
||||
#include "ImportPlugin.h"
|
||||
#include "Import.h"
|
||||
#include "../Menus.h"
|
||||
#include "../NoteTrack.h"
|
||||
#include "../Project.h"
|
||||
#include "../ProjectHistory.h"
|
||||
|
@ -277,6 +276,25 @@ static Importer::RegisteredImportPlugin registered{
|
|||
std::make_unique< LOFImportPlugin >()
|
||||
};
|
||||
|
||||
// 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
|
||||
static AudacityProject *DoImportMIDIProject(
|
||||
AudacityProject *pProject, const FilePath &fileName)
|
||||
{
|
||||
AudacityProject *pNewProject {};
|
||||
if ( !pProject )
|
||||
pProject = pNewProject = ProjectManager::New();
|
||||
auto cleanup = finally( [&]
|
||||
{ if ( pNewProject ) GetProjectFrame( *pNewProject ).Close(true); } );
|
||||
|
||||
if ( DoImportMIDI( *pProject, fileName ) ) {
|
||||
pNewProject = nullptr;
|
||||
return pProject;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** @brief Processes a single line from a LOF text file, doing whatever is
|
||||
* indicated on the line.
|
||||
*
|
||||
|
@ -382,7 +400,7 @@ void LOFImportFileHandle::lofOpenFiles(wxString* ln)
|
|||
// If file is a midi
|
||||
if (FileNames::IsMidi(targetfile))
|
||||
{
|
||||
mProject = FileActions::DoImportMIDI(mProject, targetfile);
|
||||
mProject = DoImportMIDIProject(mProject, targetfile);
|
||||
}
|
||||
|
||||
// If not a midi, open audio file
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <wx/defs.h>
|
||||
#include <wx/ffile.h>
|
||||
#include <wx/frame.h>
|
||||
#include <wx/intl.h>
|
||||
|
||||
#if defined(USE_MIDI)
|
||||
|
@ -22,7 +23,39 @@
|
|||
//#include "mfmidi.h"
|
||||
|
||||
#include "../NoteTrack.h"
|
||||
#include "../Project.h"
|
||||
#include "../ProjectHistory.h"
|
||||
#include "../ProjectWindow.h"
|
||||
#include "../SelectUtilities.h"
|
||||
#include "../widgets/AudacityMessageBox.h"
|
||||
#include "../widgets/FileHistory.h"
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
bool ImportMIDI(const FilePath &fName, NoteTrack * dest)
|
||||
{
|
||||
|
|
|
@ -24,8 +24,11 @@ into a NoteTrack.
|
|||
#if defined(USE_MIDI)
|
||||
|
||||
class wxString;
|
||||
class AudacityProject;
|
||||
class NoteTrack;
|
||||
|
||||
bool DoImportMIDI( AudacityProject &project, const FilePath &fileName );
|
||||
|
||||
bool ImportMIDI(const FilePath &fName, NoteTrack * dest);
|
||||
|
||||
class MIDIParser {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "../commands/CommandContext.h"
|
||||
#include "../commands/CommandManager.h"
|
||||
#include "../export/ExportMultiple.h"
|
||||
#include "../import/ImportMIDI.h"
|
||||
#include "../widgets/AudacityMessageBox.h"
|
||||
#include "../widgets/FileHistory.h"
|
||||
|
||||
|
@ -107,62 +108,10 @@ void DoExport
|
|||
}
|
||||
}
|
||||
|
||||
namespace FileActions {
|
||||
|
||||
// exported helper functions
|
||||
|
||||
#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
|
||||
// one, if the given was null; create no NEW project if failure
|
||||
AudacityProject *DoImportMIDI(
|
||||
AudacityProject *pProject, const FilePath &fileName)
|
||||
{
|
||||
AudacityProject *pNewProject {};
|
||||
if ( !pProject )
|
||||
pProject = pNewProject = ProjectManager::New();
|
||||
auto cleanup = finally( [&]
|
||||
{ if ( pNewProject ) GetProjectFrame( *pNewProject ).Close(true); } );
|
||||
|
||||
if ( DoImportMIDI( *pProject, fileName ) ) {
|
||||
pNewProject = nullptr;
|
||||
return pProject;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_MIDI
|
||||
|
||||
// Menu handler functions
|
||||
|
||||
namespace FileActions {
|
||||
|
||||
struct Handler : CommandHandlerObject {
|
||||
|
||||
void OnNew(const CommandContext & )
|
||||
|
@ -507,6 +456,7 @@ void OnImportLabels(const CommandContext &context)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MIDI
|
||||
void OnImportMIDI(const CommandContext &context)
|
||||
{
|
||||
auto &project = context.project;
|
||||
|
|
Loading…
Reference in New Issue