Il 09/12/2010 01:21, GW Rodriguez ha scritto:
Simone,
This has been very helpful. Two questions though, you
suggest this line of code:
MusicSequenceSetUserCallback (sequence, MyCallback,
myObj);
For the second argument I have to cast it to
MusicSequenceUserCallback right?
if the callback has the correct signature and the compiler knows
about it, you shouldn't need the cast.
Also for the third argument when I put myObj (but this is
name of the instance of the class I created) I get a fail on the
complier that says it was not declared in this scope.
perhaps you should post your code. From that description, I can only
assume that myObj in your case is not a variable holding a reference
to the right instance.
Since the set user callback function is within the
@implementation section and the callback declaration is outside
of the @implementation section, how do I pass the *void
inClientData?
it seems to me that there's some confusion here (or I don't know
what you mean :). The @implementation section has nothing to do with
the C++ code.
Let's assume you have the following structure:
MyObj.h -> defines your ObjC class
MyObj.mm (or MyObj.m, depending on your preferences/compiler
settings) -> contains the implementation of your ObjC class
SomethingElse.cpp -> contains the code that sets up the callback
In the latter, you probably have something like this:
#import "MyObj.h"
//...
void SomethingElse::MyCallback( void *clientData, MusicSequence
sequence, MusicTrack track,
MusicTimeStamp eventTime, const
MusicEventUserData *eventData,
MusicTimeStamp startSliceBeat,
MusicTimeStamp endSliceBeat )
{
// ...
}
void SomethingElse::SomeMethod()
{
MyObj *myObj = [[MyObj alloc] init];
// ...
MusicSequenceSetUserCallback( sequence, MyCallback, myObj );
// ...
// ...keep a reference to myObj somewhere to release it when done,
of course...
}
or even:
void SomethingElse::SomeMethod( MyObj *myObj )
{
// ...
MusicSequenceSetUserCallback( sequence, MyCallback, myObj );
// ...
}
Btw, the code above assumes that SomethingElse.h contains:
class SomethingElse
{
// ...
private:
static void MyCallback( void *clientData, MusicSequence
sequence, MusicTrack track,
MusicTimeStamp eventTime, const
MusicEventUserData *eventData,
MusicTimeStamp startSliceBeat,
MusicTimeStamp endSliceBeat );
// ...
}
|