Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a soundfont to Mid file and use MIKMIDISequencer play it? #185

Closed
jessefang opened this issue Mar 22, 2017 · 2 comments
Closed

Comments

@jessefang
Copy link

hello~
I see same issue from #173.but i can't find the method to play it.how can i use MIKMIDISequencer or MIKMIDISynthesizer to play the mid file?

@RadioDisney
Copy link

` NSString *itunesDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *midiPath = [NSString stringWithFormat:@"%@/%@", itunesDir, @"song.mid"];
NSURL *midiUrl = [NSURL fileURLWithPath:midiPath];

NSError* err;
MIKMIDISequence* sequence = [MIKMIDISequence sequenceWithFileAtURL:midiUrl error:&err];
MIKMIDISequencer *sequencer = [MIKMIDISequencer sequencerWithSequence:sequence];
NSURL *soundfontURL = [[NSBundle mainBundle] URLForResource:@"MagicSFver2" withExtension:@"sf2"];

for (MIKMIDITrack *track in sequence.tracks) {
    MIKMIDISynthesizer *synth = [sequencer builtinSynthesizerForTrack:track];
    NSError *error = @"";
    if (![synth loadSoundfontFromFileAtURL:soundfontURL error:&error]) {
        NSLog(@"Error loading soundfont (%@) into synthesizer for track (%@): %@", soundfontURL, track, sequencer);
    }
}
[sequencer startPlayback];`

@catiga
Copy link

catiga commented Feb 21, 2022

i got the same problem while i played single midi file with drum tone, but startPlayback could play sound but using piano tone, not drum, and I used the above code the load target soundfont(sf2), what should i do to solve it? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants