Audacity 3.2.0
Functions | Variables
anonymous_namespace{ExportMIDI.cpp} Namespace Reference

Functions

const ReservedCommandFlagNoteTracksExistFlag ()
 
void OnExportMIDI (const CommandContext &context)
 

Variables

AttachedItem sAttachment
 

Function Documentation

◆ NoteTracksExistFlag()

const ReservedCommandFlag & anonymous_namespace{ExportMIDI.cpp}::NoteTracksExistFlag ( )

Definition at line 34 of file ExportMIDI.cpp.

35 [](const AudacityProject &project){
36 return !TrackList::Get( project ).Any<const NoteTrack>().empty();
37 }
38 }; return flag; } //gsw
static std::once_flag flag
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:63
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1313
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385

References TrackList::Any(), flag, and TrackList::Get().

Here is the call graph for this function:

◆ OnExportMIDI()

void anonymous_namespace{ExportMIDI.cpp}::OnExportMIDI ( const CommandContext context)

Definition at line 42 of file ExportMIDI.cpp.

43{
44 auto &project = context.project;
45 auto &tracks = TrackList::Get( project );
46 auto &window = GetProjectFrame( project );
47
48 // Make sure that there is
49 // exactly one NoteTrack selected.
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,
78 wxT("mid"),
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 // Move existing files out of the way. Otherwise wxTextFile will
94 // append to (rather than replace) the current file.
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 {
114 auto msg = XO(
115"You have selected a filename with an unrecognized file extension.\nDo you want to continue?");
116 auto title = XO("Export MIDI");
117 int id = AudacityMessageBox( msg, title, wxYES_NO );
118 if (id == wxNO) {
119 continue;
120 } else if (id == wxYES) {
121 nt->ExportMIDI(fName);
122 }
123 }
124 break;
125 }
126}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
static const auto title
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)
Definition: SelectFile.cpp:17
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:251
AudacityProject & project

References AudacityMessageBox(), TrackList::Get(), GetProjectFrame(), CommandContext::project, SelectFile(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), title, wxT(), and XO().

Here is the call graph for this function:

Variable Documentation

◆ sAttachment

AttachedItem anonymous_namespace{ExportMIDI.cpp}::sAttachment
Initial value:
{
{ wxT("File/Import-Export/Export"),
{ OrderingHint::After, {"ExportMultiple"} } },
Command( wxT("ExportMIDI"), XXO("Export MI&DI..."), OnExportMIDI,
}
const ReservedCommandFlag & AudioIONotBusyFlag()
XXO("&Cut/Copy/Paste Toolbar")
constexpr auto Command
void OnExportMIDI(const CommandContext &context)
Definition: ExportMIDI.cpp:42
const ReservedCommandFlag & NoteTracksExistFlag()
Definition: ExportMIDI.cpp:34

Definition at line 128 of file ExportMIDI.cpp.