If I play a MIDI file (in .mid format) utilizing AVMIDIPlayer
, it simply performs instrument tracks, not vocal tracks.
Right here is how I’m taking part in the MIDI file:
func playMIDIAndSyncCursor() {
guard let midiURL = Bundle.fundamental.url(forResource: midiFileName, withExtension: "mid"),
let soundFontURL = Bundle.fundamental.url(forResource: soundFontName, withExtension: soundFontExt) else {
print("β Lacking MIDI or DLS file")
return
}
extractTrackNames(from: midiURL)
inspectMIDIFile(midiURL)
do {
let information = attempt Knowledge(contentsOf: midiURL)
midiPlayer = attempt AVMIDIPlayer(information: information, soundBankURL: soundFontURL)
midiPlayer?.prepareToPlay()
playbackStartTime = CACurrentMediaTime()
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
self.updateCursor()
}
print("π΅ Beginning playback")
midiPlayer?.play {
print("β
Playback completed")
self.displayLink?.invalidate()
}
} catch {
print("β MIDI error: (error)")
}
I scanned the .mid file, and I can see that there are 8 tracks:
func inspectMIDIFile(_ url: URL) {
var sequence: MusicSequence?
NewMusicSequence(&sequence) // allocate
guard let seq = sequence else {
print("Didn't create MusicSequence")
return
}
// Load the MIDI file into the sequence
let standing = MusicSequenceFileLoad(seq, url as CFURL, .midiType, MusicSequenceLoadFlags())
if standing != noErr {
print("Error loading MIDI file: (standing)")
return
}
var trackCount: UInt32 = 0
MusicSequenceGetTrackCount(seq, &trackCount)
print("MIDI has (trackCount) tracks")
}
It prints:
MIDI has 8 tracks
For displaying the musical sheet (rating), I’m utilizing OpenSheetMusicDisplay in a WKWebView
and loading the .musicxml/.mxl information. I can see vocal components within the rating sheet as properly, as proven within the under picture:
Vocal components:
- Soprano
- Alto
- Tenor
- Bass
Instrument components:
- Violino 1
- Violino 2
- Viola
- Contrabasso e Organo
Nevertheless, if I add a .mxl file for a similar association (not a .mid file) on MuseScore, it performs the vocal components as properly.
I downloaded .mid and .mxl information from:
https://www.cpdl.org/wiki/index.php/Ave_verum_corpus,KV_618(Wolfgang_Amadeus_Mozart)
So am I lacking / misunderstanding one thing with my code above? Do I want a .musicxml or .mid file for audio playback, or one thing?
Be aware: I’m not speaking about playback of lyrics (in human voice). I do know I should use solely an .mp3 file for that.