Hey i have a File which is a .midi, i have multiple tracks there with different names, how can i take each track and copy it to a new File .mid with his track name and data?
this is what i got by now:
for (int i = 0; i < midiFile.getNumTracks(); i++)
{
// Get the current track
MidiMessageSequence track = *(midiFile.getTrack(i));
// Create a new empty MidiFile for the single track
MidiFile singleTrackFile;
singleTrackFile.addTrack(track);
// Get the name of the track (if available)
String trackName = "Track_" + String(i + 1); // Default to "Track_X" if no name is found
for (auto& event : track)
{
if (event->message.isTextMetaEvent())
{
trackName = event->message.getTextFromTextMetaEvent();
break;
}
}
// Create the new file in the same directory as the original file with the track name
File newFile = file.getSiblingFile(trackName + ".mid");
// Write the single track to the new file
if (auto outputStream = newFile.createOutputStream())
{
singleTrackFile.writeTo(*outputStream);
files.add(newFile);
}
}
