43{
44 auto &project = context.
project;
47
48
49
50 const auto range = tracks.Selected<
const NoteTrack >();
51 const auto numNoteTracksSelected = range.
size();
52
53 if(numNoteTracksSelected > 1) {
55 XO(
"Please select only one Note Track at a time.") );
56 return;
57 }
58 else if(numNoteTracksSelected < 1) {
60 XO(
"Please select a Note Track.") );
61 return;
62 }
63
64 wxASSERT(numNoteTracksSelected);
65 if (!numNoteTracksSelected)
66 return;
67
68 const auto nt = *range.begin();
69
70 while(true) {
71
72 wxString fName;
73
74 fName =
SelectFile(FileNames::Operation::Export,
75 XO(
"Export MIDI As:"),
76 wxEmptyString,
77 fName,
79 {
80 {
XO(
"MIDI file"), {
wxT(
"mid") },
true },
81 {
XO(
"Allegro file"), {
wxT(
"gro") },
true },
82 },
83 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
84 &window);
85
86 if (fName.empty())
87 return;
88
89 if(!fName.Contains(
wxT(
"."))) {
90 fName = fName +
wxT(
".mid");
91 }
92
93
94
95
96 if (wxFileExists(fName)) {
97#ifdef __WXGTK__
98 wxString safetyFileName = fName +
wxT(
"~");
99#else
100 wxString safetyFileName = fName +
wxT(
".bak");
101#endif
102
103 if (wxFileExists(safetyFileName))
104 wxRemoveFile(safetyFileName);
105
106 wxRename(fName, safetyFileName);
107 }
108
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);
113 } else {
115"You have selected a filename with an unrecognized file extension.\nDo you want to continue?");
116 auto title =
XO(
"Export MIDI");
118 if (id == wxNO) {
119 continue;
120 } else if (id == wxYES) {
121 nt->ExportMIDI(fName);
122 }
123 }
124 break;
125 }
126}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
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)
size_t size() const
How many attachment pointers are in the Site.
AudacityProject & project