Importing MIDI is actually fairly complex depending on what you want to do. If you just want to take a MIDI file, and create one clip, and match the tempo of the existing edit, try and copy what is done in Edit::createEditForPreviewingFile
Here is a stripped down, untested version:
if (auto fin = std::unique_ptr<juce::FileInputStream> (file.createInputStream()))
{
juce::MidiFile mf;
mf.readFrom (*fin);
mf.convertTimestampTicksToSeconds();
juce::MidiMessageSequence sequence;
for (int i = 0; i < mf.getNumTracks(); ++i)
sequence.addSequence (*mf.getTrack (i), 0.0, 0.0, 1.0e6);
sequence.updateMatchedPairs();
if (auto mc = track->insertMIDIClip ({ 0.0, 1.0 }, nullptr))
{
// add midi notes
mc->mergeInMidiSequence (sequence, MidiList::NoteAutomationType::none);
auto length = sequence.getEndTime();
mc->setPosition ({ { 0.0, length }, 0.0 });
}
}
If you have a multi track midi file with tempo changes, and you want all the tracks created, create a media object for the midi file
ProjectItem::Ptr mo;
File f (originalFile);
mo = project.createNewItem (f, ProjectItem::midiItemType(),
f.getFileNameWithoutExtension(),
TRANS("Imported from directory") + ": " + originalFile.getParentDirectory().getFullPathName(),
ProjectItem::Category::imported,
true);
and then paste it into the edit:
Clipboard::ContentType::EditPastingOptions options (editView.edit, editView.insertPoint, editView.getSelectionManager());
options.silent = silent;
options.preferredLayout = preferredLayout;
options.setTransportToEnd = setTransportToEnd;
editView.insertPoint.chooseInsertPoint (options.startTrack, options.startTime, false, editView.getSelectionManager());
if (options.startTrack != nullptr)
{
Clipboard::ProjectItems content;
for (auto& item : importedProjectItems)
content.itemIDs.push_back ({ item->getID(), {} });
content.pasteIntoEdit (options);
}