petegoodliffe / PGMidi

PGMidi iOS MIDI library and example code
297 stars 83 forks source link

How to load and play an existing MIDI file? #17

Open shuangye opened 8 years ago

shuangye commented 8 years ago

Took a glance at the header file, did't find an interface to load & play an existing MIDI file. How could I do with it? Thanks.

cpmpercussion commented 8 years ago

That's not what this library is for. From the README:

PGMidi is a simple library for access to MIDI devices presented via the CoreMidi framework

If you want to playback existing MIDI files, you could use the Audio Toolbox MusicPlayer and MusicSequence classes. For example: http://stackoverflow.com/questions/10249346/playing-midi-files-with-musicplayer-music-sequence

armadsen commented 8 years ago

I work on another Objective-C MIDI library called MIKMIDI: https://github.com/mixedinkey-opensource/MIKMIDI . It has full featured support for playing (and recording) MIDI files. Can be as simple as:

MIKMIDISequence *sequence = [MIKMIDISequence sequenceWithFileAtURL:midiFileURL error:&error];
MIKMIDISequencer *sequencer = [MIKMIDISequencer sequencerWithSequence:sequence];
[sequencer startPlayback];

MusicPlayer and MusicSequence are also relatively straightforward, but being part of CoreMIDI, they're pure C API, and take a little more than three lines of code to get up and running ;).