Audacity  2.3.1
Classes | Functions
FileActions Namespace Reference

Namespace for functions for File menu. More...

Classes

struct  Handler
 

Functions

AudacityProjectDoImportMIDI (AudacityProject *pProject, const wxString &fileName)
 

Detailed Description

Namespace for functions for File menu.

Function Documentation

AudacityProject * FileActions::DoImportMIDI ( AudacityProject pProject,
const wxString &  fileName 
)

Definition at line 104 of file FileMenus.cpp.

References _(), AudacityApp::AddFileToHistory(), CreateNewAudacityProject(), AudacityProject::GetTrackFactory(), AudacityProject::GetTracks(), ImportMIDI(), TrackFactory::NewNoteTrack(), AudacityProject::PushState(), AudacityProject::SelectNone(), wxGetApp(), and AudacityProject::ZoomAfterImport().

Referenced by LOFImportFileHandle::lofOpenFiles(), FileActions::Handler::OnImportMIDI(), and AudacityProject::OpenFile().

106 {
107  auto tracks = pProject->GetTracks();
108 
109  AudacityProject *pNewProject {};
110  if ( !pProject )
111  pProject = pNewProject = CreateNewAudacityProject();
112  auto cleanup = finally( [&]
113  { if ( pNewProject ) pNewProject->Close(true); } );
114 
115  auto newTrack = pProject->GetTrackFactory()->NewNoteTrack();
116 
117  if (::ImportMIDI(fileName, newTrack.get())) {
118 
119  pProject->SelectNone();
120  auto pTrack = tracks->Add(std::move(newTrack));
121  pTrack->SetSelected(true);
122 
123  pProject->PushState(wxString::Format(_("Imported MIDI from '%s'"),
124  fileName), _("Import MIDI"));
125 
126  pProject->ZoomAfterImport(pTrack);
127  pNewProject = nullptr;
128 
129  wxGetApp().AddFileToHistory(fileName);
130 
131  return pProject;
132  }
133  else
134  return nullptr;
135 }
std::unique_ptr< NoteTrack > NewNoteTrack()
Definition: NoteTrack.cpp:105
void AddFileToHistory(const wxString &name)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
void ZoomAfterImport(Track *pTrack)
Definition: Project.cpp:4292
bool ImportMIDI(const wxString &fName, NoteTrack *dest)
Definition: ImportMIDI.cpp:28
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4629
void SelectNone()
Definition: Project.cpp:5653
AudacityApp & wxGetApp()
TrackList * GetTracks()
Definition: Project.h:209
TrackFactory * GetTrackFactory()
Definition: Project.cpp:1513
AudacityProject * CreateNewAudacityProject()
Definition: Project.cpp:552