• 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
Re: iOS - Receiving MIDI Event from MusicPlayer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iOS - Receiving MIDI Event from MusicPlayer


  • Subject: Re: iOS - Receiving MIDI Event from MusicPlayer
  • From: Takeshi Yokemura <email@hidden>
  • Date: Sun, 25 May 2014 20:54:30 +0900

I have got it worked but I still don't know why it worked.

The fix is
to change the timing of making MusicPlayer.
In the code in my last post, MusicPlayer is created beforehand,
and I moved it to after MusicSequenceFileLoad.

I suspected kinds of memory problem at first, but if so the app will
crash by bad access.
Have anybody experienced same kind of thing??

Thanks,
----
  Takeshi Yokemura




2014-05-12 0:30 GMT+09:00 Takeshi Yokemura <email@hidden>:
> 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


References: 
 >iOS - Receiving MIDI Event from MusicPlayer (From: Takeshi Yokemura <email@hidden>)

  • Prev by Date: Re: AUGraphStart(graph) failure
  • Next by Date: deactivating audio session and [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
  • Previous by thread: iOS - Receiving MIDI Event from MusicPlayer
  • Next by thread: Report level in AudioUnit to parameter
  • Index(es):
    • Date
    • Thread