20#include "../NoteTrack.h"
22#include "../ProjectWindows.h"
28#include "../commands/CommandContext.h"
29#include "../commands/CommandManager.h"
30#include "../CommonCommandFlags.h"
44 auto &project = context.
project;
50 const auto range = tracks.Selected<
const NoteTrack >();
51 const auto numNoteTracksSelected = range.
size();
53 if(numNoteTracksSelected > 1) {
55 XO(
"Please select only one Note Track at a time.") );
58 else if(numNoteTracksSelected < 1) {
60 XO(
"Please select a Note Track.") );
64 wxASSERT(numNoteTracksSelected);
65 if (!numNoteTracksSelected)
68 const auto nt = *range.begin();
74 fName =
SelectFile(FileNames::Operation::Export,
75 XO(
"Export MIDI As:"),
80 {
XO(
"MIDI file"), {
wxT(
"mid") },
true },
81 {
XO(
"Allegro file"), {
wxT(
"gro") },
true },
83 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
89 if(!fName.Contains(
wxT(
"."))) {
90 fName = fName +
wxT(
".mid");
96 if (wxFileExists(fName)) {
98 wxString safetyFileName = fName +
wxT(
"~");
100 wxString safetyFileName = fName +
wxT(
".bak");
103 if (wxFileExists(safetyFileName))
104 wxRemoveFile(safetyFileName);
106 wxRename(fName, safetyFileName);
109 if(fName.EndsWith(
wxT(
".mid")) || fName.EndsWith(
wxT(
".midi"))) {
110 nt->ExportMIDI(fName);
111 }
else if(fName.EndsWith(
wxT(
".gro"))) {
112 nt->ExportAllegro(fName);
115"You have selected a filename with an unrecognized file extension.\nDo you want to continue?");
116 auto title =
XO(
"Export MIDI");
120 }
else if (
id == wxYES) {
121 nt->ExportMIDI(fName);
129 {
wxT(
"File/Import-Export/Export"),
130 { OrderingHint::After, {
"ExportMultiple"} } },
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
const ReservedCommandFlag & AudioIONotBusyFlag()
XXO("&Cut/Copy/Paste Toolbar")
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
size_t size() const
How many attachment pointers are in the Site.
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
A Track that is used for Midi notes. (Somewhat old code).
auto Any() -> TrackIterRange< TrackType >
static TrackList & Get(AudacityProject &project)
void OnExportMIDI(const CommandContext &context)
const ReservedCommandFlag & NoteTracksExistFlag()