• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
iOS - Receiving MIDI Event from MusicPlayer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iOS - Receiving MIDI Event from MusicPlayer


  • Subject: iOS - Receiving MIDI Event from MusicPlayer
  • From: Takeshi Yokemura <email@hidden>
  • Date: Mon, 12 May 2014 00:30:06 +0900

Hi, all

I'm making a sequencer app
with synthesizer function that synthesizes the sound from scratch.

My approach is using MusicPlayer/MusicSequence for the sequencer part,
and give the MIDI information to the synthesizer part as it plays.

The basic structure is based on this one
http://www.deluge.co/?q=midi-driven-animation-core-audio-objective-c
and my code is like below.

Running this code I can see "Notification message" twice,
but never see "ReadProc called".
I can hear the DLSMusicDevice is playing my SMF file,
so sequence itself must not be broken.

Are there something missing? Or any misunderstanding?


//
//  MySequencerEngine.m
//
#import "MySequencerEngine.h"
@implementation MySequencerEngine

// singleton
static MySequencerEngine* _instance;
+ (void)load{ … }
+ (id)sharedObject{ … }

// make MusicPlayer in init
-(id)init
{
    if([super init]){
        OSStatus result = NewMusicPlayer(&player);
        sequence = NULL;
    }
    return self;
}

// read SMF from file
-(OSStatus) loadSequenceFromFile:(NSString*)inFile
{
    OSStatus result;
    if(sequence){
        DisposeMusicSequence(sequence);
    }
    result = NewMusicSequence(&sequence);

    NSURL* url = [[NSBundle mainBundle] URLForResource:inFile
withExtension:@""];
    MusicSequenceLoadFlags loadFlags = 0;

    result = MusicSequenceFileLoad (sequence, (CFURLRef)url, 0, loadFlags);
    [self setSequence:sequence];

    return result;
}
-(OSStatus) setSequence:(MusicSequence)inSequence
{
    OSStatus result = MusicPlayerSetSequence (player, sequence);
    return result;
}


-(OSStatus) play
{
    OSStatus result = MusicPlayerStart(player);
    return result;
}

-(OSStatus) connectToDestination:(MIDIEndpointRef)inDestination
{
    OSStatus result = MusicSequenceSetMIDIEndpoint(sequence, inDestination);
    return result;
}
@end



//
//  HelloWorldLayer.m
//  ( I use Cocos2d for UI )
//
#import "HelloWorldLayer.h"
#import "MySequencerEngine.h"

static void MyMIDIReadProc(const MIDIPacketList *pktlist,
                           void *refCon,
                           void *connRefCon)
{
    NSLog(@"ReadProc called");
}

void MyMIDINotifyProc (const MIDINotification  *message, void *refCon)
{
    NSLog(@"Notification. message=%ld", message->messageID);
}

@implementation HelloWorldLayer

+(CCScene *) scene { … }

-(id) init
{
if( (self=[super init])) {
        // View Initialization
        …
        // MIDI Initialization
        MIDIClientRef midiClient;
        MIDIEndpointRef virtualEndpoint;

        OSStatus result;
        NSString* fileName = @"midifile.mid";

        MySequencerEngine* sq = [MySequencerEngine sharedObject];
        [sq loadSequenceFromFile:fileName];

        result = MIDIClientCreate(CFSTR("Example MIDI client"),
                         MyMIDINotifyProc, NULL, &midiClient);
        result = MIDIDestinationCreate(midiClient, CFSTR("My Synth"),
MyMIDIReadProc, 0, &virtualEndpoint);

        [sq connectToDestination:virtualEndpoint];
        [sq play];

}
return self;
}
@end



Any help appreciated.

Thanks,

  Takeshi Yokemura

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: iOS - Receiving MIDI Event from MusicPlayer
      • From: Takeshi Yokemura <email@hidden>
  • Prev by Date: Re: Could someone correct my code, about a AUGraph, an audio file player and a multimode filter?
  • Next by Date: Report level in AudioUnit to parameter
  • Previous by thread: Re: Recording in MACE 3:1 and 6:1
  • Next by thread: Re: iOS - Receiving MIDI Event from MusicPlayer
  • Index(es):
    • Date
    • Thread