• 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: Kyle Sluder <email@hidden>
  • Date: Wed, 06 Mar 2013 08:27:05 -0800

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

  • Follow-Ups:
    • Re: MidiReadProc to Text Field
      • From: Michael Ellis <email@hidden>
References: 
 >MidiReadProc to Text Field (From: Haynes Electronics <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