• 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: How to use srcConnRefCon in MIDIReadProc function.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use srcConnRefCon in MIDIReadProc function.


  • Subject: Re: How to use srcConnRefCon in MIDIReadProc function.
  • From: tin <email@hidden>
  • Date: Fri, 19 Dec 2014 10:19:05 +0800

(Continue… )

I find that if I use MIDIReceive() to trigger MyMIDIReadProc(),  the *srcConnRefCon would be correct value!

// in viewDidLoad

   unsigned long sourceCount = MIDIGetNumberOfSources();
    for (int i = 0; i < sourceCount; ++i) {
        MIDIEndpointRef src = "">

        MIDIUniqueID sourceUniqueID = NULL;

        MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &sourceUniqueID);

        NSString *s = [NSString stringWithFormat:@"sourceUniqueID %u",(int)sourceUniqueID];
        MIDIPortConnectSource(inPort,  src,(__bridge_retained void*)s);

    }


// in any IBAction of ViewController.m

-(IBAction)testReceive:(id)sender{

    Byte buffer[1024];         
    MIDIPacketList *packetlist = (MIDIPacketList*)buffer;
    MIDIPacket *currentpacket = MIDIPacketListInit(packetlist);
    Byte msgs[3] = {0x90, 40, 100};

    currentpacket = MIDIPacketListAdd(packetlist, sizeof(buffer),currentpacket, 0, 3, msgs);


    MIDIReceived(self.sourcePoint, packetlist);

}


// in MyMIDIReadProc()

void MyMIDIReadProc(const MIDIPacketList *pktlist, void *refCon,void *srcConnRefCon) {

   NSString *str = (__bridge NSString*)srcConnRefCon;
   NSLog(@"receive Str is %@",str);



// NSLogs result: 
1. trigger from MIDIReceived() in IBAction.  it logs “receive Str is 3762660402”  
2. trigger from other app or MIDI device, it logs “receive Str is (null)”


is there any one know the reason?

Thank
Tin


On 2014年12月19日, at 上午8:59, tin <email@hidden> wrote:

Hi Paul,

Thanks for your answer.

in fact the MyMIDIPreadProc() can fire successfully. but the trouble is it can not get correct incoming parameter value“void *srcConnRefCon”.

I put more codes here:

// in viewDidLoad:

   unsigned long sourceCount = MIDIGetNumberOfSources();
    for (int i = 0; i < sourceCount; ++i) {
        MIDIEndpointRef src = "">MIDIGetSource(i);

        MIDIUniqueID sourceUniqueID = NULL;

        MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &sourceUniqueID);

        NSString *s = [NSString stringWithFormat:@"sourceUniqueID %i",sourceUniqueID];
        MIDIPortConnectSource(inPort,  src,(__bridge_retained  void*)s);

    }


// in MyMIDIPreadProc()


void MyMIDIReadProc(const MIDIPacketList *pktlist, void *refCon,void *srcConnRefCon) {
    
    NSString *str = (__bridge NSString*)srcConnRefCon;
    NSLog(@“ The sourceUniqueID is : %@", str);

    
    for (int i=0; i < pktlist->numPackets; i++) {  ….. 



Then when it receive MIDI notes.   it will logs “ The sourceUniqueID is : (null)”

why it logs  "(null)”  ?    I’m  using ARC by the way.

Thanks
Tin




On 2014年12月18日, at 下午10:37, email@hidden wrote:

Hey tin,

still figuring all this stuff too, but from what I understand:

your MyMIDIReadProc will never get fired unless you’ve discovered and connected to a specific MIDI Source:

nSrcs = MIDIGetNumberOfSources();
int yourChosenSource;
MIDIEndpointRef src = "">MIDIGetSource (yourChosenSource);
MIDIPortConnectSource (inPort, src, NULL);

then your MyMIDIReadProc will fire with incoming MIDI on that specific source..

Hope this helps…
Paul.






On 18 Dec 2014, at 14:10, tin <email@hidden> wrote:

Hi All,

I want to pass a refCon to identify each MIDI source in MIDIReadProc(). 
but I don’t know why the  srcConnRefCon point always be “null”.

// codes

NSString *str = @“sourceName"
        MIDIPortConnectSource(inPort,  src,(__bridge_retained void*) str);


// use in “ void MyMIDIReadProc(const MIDIPacketList *pktlist, void *refCon,void *srcConnRefCon) "


     NSString *receiveStr = (__bridge  NSString*)srcConnRefCon;
    NSLog(@"%@", receiveStr);

Where is wrong ?  any help is appreciate.

Thanks
Tin





 _______________________________________________
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: 
 >How to use srcConnRefCon in MIDIReadProc function. (From: tin <email@hidden>)
 >Re: How to use srcConnRefCon in MIDIReadProc function. (From: tin <email@hidden>)

  • Prev by Date: Re: How to use srcConnRefCon in MIDIReadProc function.
  • Next by Date: Re: Coreaudio-api Digest, Vol 11, Issue 237
  • Previous by thread: Re: How to use srcConnRefCon in MIDIReadProc function.
  • Next by thread: How to use srcConnRefCon in MIDIReadProc function.
  • Index(es):
    • Date
    • Thread