• 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: MidiReadProc to Text Field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MidiReadProc to Text Field


  • Subject: Re: MidiReadProc to Text Field
  • From: Michael Ellis <email@hidden>
  • Date: Wed, 06 Mar 2013 11:40:18 -0500

Along the lines of Kyle's answer, here are a couple of possibly useful Stack Overflow links on  referencing C structs from ObjC and using NSTimer


http://stackoverflow.com/questions/2172887/use-c-struct-in-objective-c

http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer

I'll be interested to hear how this works out 'cause I've been procrastinating writing a Cocoa GUI wrapper for a real-time harmonizer I'm developing :-)

Cheers,
Mike


On Wed, Mar 6, 2013 at 11:27 AM, Kyle Sluder <email@hidden> wrote:
On Mar 6, 2013, at 7:54 AM, Haynes Electronics <email@hidden> wrote:


The program closely follows the CABook - here's the callback part :
MIDIInputPortCreate(
midiInfo.client,
CFSTR("Input port"),
MIDIEchoReadProc,
&midiInfo,
&midiInfo.inPort),
and the read proc :
void MIDIEchoReadProc(const MIDIPacketList *pktlist,
                           void *refCon,
                           void *connRefCon) {
MIDIEchoStruct *midiInfo = (MIDIEchoStruct*) refCon;
---  do midi processing --- works
--- echo to destination --- works
--- printf to console ---   works
[myTextField setIntValue:midiInfo->mVelIn];doesn't work
- or -
[self myWriteToTextfieldMethod];doesn't work - self is undefined

Your callback is a C function, not an instance method. Of course self is undefined.

}

(I can manually read out the values in my text field by pressing an IBAction button, so
 the values are available)
How can I get the midiReadProc to communicate with the rest of my program ?

It sounds like you need to work on your Objective-C fundamentals. If the object that sets up the MIDI callback struct is the one you want to message (or has a handle to it), you can stuff a pointer to that object into your MIDIEchoStruct. Otherwise, you could post a notification, or if you know you only have one window, adopt the singleton pattern for its window controller.

But this being audio, you were probably on the right track having the UI layer read the current state rather than pushing the current state to the UI from your callback. I'm not sure if MIDIEchoReadProc is executed in a realtime context, but if it is then sending an ObjC message can introduce latency and is not a good idea.

Instead, your ReadProc should append values locklessly to a buffer, and your UI layer should periodically (perhaps using NSTimer) read the newest values from this data structure. In other words, a producer/consumer model where readers can't block writers.

--Kyle Sluder

 _______________________________________________
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


 _______________________________________________
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: 
 >MidiReadProc to Text Field (From: Haynes Electronics <email@hidden>)
 >Re: MidiReadProc to Text Field (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: MidiReadProc to Text Field
  • Next by Date: Re: MidiReadProc to Text Field
  • Previous by thread: Re: MidiReadProc to Text Field
  • Next by thread: Re: MidiReadProc to Text Field
  • Index(es):
    • Date
    • Thread