Re: MidiReadProc to Text Field
Re: MidiReadProc to Text Field
- Subject: Re: MidiReadProc to Text Field
- From: Kevin Dixon <email@hidden>
- Date: Wed, 06 Mar 2013 18:03:54 -0800
Your assumption is correct, the void* refCon pointer is for you to
pass "context" data to your callback procedure.
Typically when I'm doing this for Core Audio callbacks, I pass a
pointer to the Objective C class controlling it, then it is easy to
cast this back to an instance of the ObjC class and call methods on
it.
For example
MIDIInputPortCreate(
midiInfo.client,
CFSTR("Input port"),
MIDIEchoReadProc,
self, // change to self
&midiInfo.inPort),
Be careful, if the midi proc is called in a realtime context, remember
that objc_messageSend can be blocking and non constant time.
-Kevin
On Wed, Mar 6, 2013 at 7:54 AM, Haynes Electronics
<email@hidden> wrote:
> I've put together a Midi application that takes input from my source
> (electronic) piano, modifies the velocity per a pre-defined curve, and
> echoes the midi packet back to the same piano. I thought this would be hard,
> but the Core Audio book showed me what to do. Now for the "easy" part - I
> would simply like to write the velocity values to a text field as the notes
> are played. I haven't been able to figure out how to do it ! The
> midiReadProc must be in another world - it apparently doesn't know anything
> about my world except what it gets from my midiInfo refCon :
>
> typedef struct MIDIEchoStruct {
> MIDIClientRef client;
> MIDIEndpointRef dest;
> MIDIPortRef inPort;
> MIDIPortRef outPort;
> MIDIPacketList outList;
> int mNote;
> int mVelIn; // from source
> int mVelOut; // to destination
> int mCommand;
> NSMutableArray *velocityCurve;
> } MIDIEchoStruct;
> MIDIEchoStruct midiInfo;
> (I may have more stuff in the struct than necessary, but I like having it
> all together)
>
> 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
> }
>
> (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 ?
>
> Thanks !
> - William
>
> _______________________________________________
> 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