• 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: Obj C and C with CoreMidi
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj C and C with CoreMidi


  • Subject: Re: Obj C and C with CoreMidi
  • From: Kurt Revis <email@hidden>
  • Date: Wed, 31 Dec 2003 12:34:13 -0800

On Wednesday, December 31, 2003, at 02:47 AM, Craig Bakalian wrote:

This the only way you can mix Obj C and C with CoreMidi ReadProc. You
must set up a shared instance in objective C, and place a static
instance of that shared instance directly in the .m file like so...
and the shared instance must be outside of the @implementation @end
protocols

Nonsense. There is an easier way to do it, without any static objects. Just pass in your Objective-C object as the refCon to MIDIInputPortCreate(). (If necessary, you can also use another object as the connRefCon in MIDIPortConnectSource() -- if you don't need it just use NULL.) Both of these objects will be given to your MIDIReadProc, at which time you can cast them to the appropriate type, and send Objective-C messages to them.

I'm sure code like this has been posted to the list before, but here it goes again. Let's assume you have an Obj-C class which takes MIDI input -- we'll call it MyPortRelatedObject. It creates an input port and then connects one or more endpoints to that port.

(There is also a class called MyConnectionRelatedObject which contains the information your application needs to know about the connection -- that is, the unique combination of input port and endpoint. There may be any number of these for each instance of MyPortRelatedObject. You might not need this at all in a simple application. I usually use these to hold a MIDI input parser object, so the state of the parser for each connected endpoint is independent of all the other parsers/endpoints.)


@implementation MyPortRelatedObject

- (void) makeInputPortForMIDIClient: (MIDIClientRef)client andConnectToEndpoint: (MIDIEndpointRef)sourceEndpoint
{
MIDIPortRef inputPort;
MyConnectionRelatedObject* connectionRelatedObject = nil; // if you have an object which encapsulates the idea of a connection for a given input port and endpoint, you would need to find or create it here

// make an input port, which will call MyReadProc with the MIDI packets
MIDIInputPortCreate(client, CFSTR("input port"), MyReadProc, self, &inputPort);

// and connect the endpoint to the port
MIDIPortConnectSource(inputPort, sourceEndpoint, connectionRelatedObject);
}

void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
{
MyPortRelatedObject* portRelatedObject = (MyPortRelatedObject*)refCon;
MyConnectionRelatedObject* connectionRelatedObject = (MyConnectionRelatedObject*)connRefCon;

// Then send Obj-C messages to the objects however you like
// for instance:
[portRelatedObject receivedMIDIPacketList: pktlist onConnection: connectionRelatedObject];
}

- (void) receivedMIDIPacketList: (const MIDIPacketList*)pktList onConnection: (MyConnectionRelatedObject*) connectionRelatedObject
{
// Do whatever you want with the packet list and connectionRelatedObject
}

@end

--
Kurt Revis
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

References: 
 >Obj C and C with CoreMidi (From: Craig Bakalian <email@hidden>)

  • Prev by Date: Obj C and C with CoreMidi
  • Previous by thread: Obj C and C with CoreMidi
  • Index(es):
    • Date
    • Thread