1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 00:29:41 +02:00

Bug1696: Drag-and-drop should import Midi file as a Note track

This commit is contained in:
Paul Licameli 2017-07-20 13:26:37 -04:00
parent bb4a1b862a
commit 69d6f36ef6
4 changed files with 18 additions and 5 deletions

View File

@ -460,8 +460,12 @@ public:
mProject->HandleResize(); // Adjust scrollers for NEW track sizes.
} );
for (const auto &name : sortednames)
mProject->Import(name);
for (const auto &name : sortednames) {
if (Importer::IsMidi(name))
AudacityProject::DoImportMIDI(mProject, name);
else
mProject->Import(name);
}
mProject->ZoomAfterImport(nullptr);

View File

@ -328,6 +328,14 @@ movable_ptr<ExtImportItem> Importer::CreateDefaultImportItem()
return new_item;
}
bool Importer::IsMidi(const wxString &fName)
{
const auto extension = fName.AfterLast(wxT('.'));
return
extension.IsSameAs(wxT("midi"), false) ||
extension.IsSameAs(wxT("mid"), false);
}
// returns number of tracks imported
bool Importer::Import(const wxString &fName,
TrackFactory *trackFactory,
@ -343,7 +351,7 @@ bool Importer::Import(const wxString &fName,
// Always refuse to import MIDI, even though the FFmpeg plugin pretends to know how (but makes very bad renderings)
#ifdef USE_MIDI
// MIDI files must be imported, not opened
if ((extension.IsSameAs(wxT("midi"), false)) || (extension.IsSameAs(wxT("mid"), false))) {
if (IsMidi(fName)) {
errorMessage.Printf(_("\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI."), fName.c_str());
return false;
}

View File

@ -137,6 +137,8 @@ public:
*/
movable_ptr<ExtImportItem> CreateDefaultImportItem();
static bool IsMidi(const wxString &fName);
// if false, the import failed and errorMessage will be set.
bool Import(const wxString &fName,
TrackFactory *trackFactory,

View File

@ -388,8 +388,7 @@ void LOFImportFileHandle::lofOpenFiles(wxString* ln)
#ifdef USE_MIDI
// If file is a midi
if (targetfile.AfterLast(wxT('.')).IsSameAs(wxT("mid"), false)
|| targetfile.AfterLast(wxT('.')).IsSameAs(wxT("midi"), false))
if (Importer::IsMidi(targetfile))
{
mProject = AudacityProject::DoImportMIDI(mProject, targetfile);
}