• 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: Is there something wrong here (AU Properties)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there something wrong here (AU Properties)


  • Subject: Re: Is there something wrong here (AU Properties)
  • From: Stephen Blinkhorn <email@hidden>
  • Date: Mon, 31 Oct 2011 16:20:05 -0600

Thanks Ian and Kyle. Apologies for the slow reply. None of the Apple lists I am subscribed to were accessible for the past few days for some reason. Anyway, reply below.

On 29 Oct 2011, at 15:51, Kyle Sluder wrote:

On Wed, Oct 26, 2011 at 10:09 AM, Stephen Blinkhorn
<email@hidden> wrote:
typedef struct Event
{
       int mMIDINote
       int mMIDIVelocity;
} Event;

typedef struct EventProperty
{
       int     mNumEvents;
       Event   *mEvents; // << array of C structs
} AS_SequencerTrackProperty;


..then in GetPropertyInfo():

case kAudioUnitCustomProperty_event:
       outWritable = false;
       outDataSize = sizeof(EventProperty);
       return noErr;


..and in GetProperty():

case kAudioUnitCustomProperty_event:
       EventProperty *event_property = (EventProperty*)outData;
       event_property->mEvents[0]->mMIDINote = 64;
       event_property->mEvents[0]->mMIDIVelocity = 127;
       return noErr;

This doesn't match up, and will not compile. struct EventProperty is defined to have an array of struct Events at the end, but you're treating it as if it has an array of pointers to struct Event. Since your definition of struct Event is missing a semicolon after int mMIDINote, I suspect you didn't actually copy-paste your code, and have therefore introduced errors. You also aren't allocating any space for the array at all; this only magically works on 64-bit machines because sizeof(struct Event) == sizeof(struct Event *) since struct Event is composed of two 32-bit ints.

If mEvents really is an array of pointers to struct Event, then you
are indeed violating the host/AU separation. If you did in fact intend
for mEvents to be an array of struct Event, you need to replace your
dereferences (mEvents[0]->mMIDINote) with struct member accesses
(mEvents[0].mMIDINote) and you need to actually allocate the proper
space for an array of structs.

mEvents is indeed an array of struct Event so you're right about the - > dereference. I omitted the memory claim call purely to make the example less cluttered.


Currently I do this to claim the memory for the array (in the view):

int numEvents = 64;
Event *EventArray = (Event*)malloc(sizeof(Event) * numEvents);

And when I call GetProperty() I do this:

UInt32 dataSize = sizeof(EventProperty);
EventProperty event_struct;
event_struct.mNumEvents = numEvents;
event_struct.mEvents = EventArray; << pointer to array

ComponentResult result = AudioUnitGetProperty(	mAU,
						kAudioUnitCustomProperty_event,
						kAudioUnitScope_Global,
						0,
						&event_struct,
						&dataSize);

The dataSize value is simply sizeof(EventProperty) but this can't possibly know how large my mEvents array actually is, can it? Would it be better to define the array like this:

Event EventArray[numEvents];

Seems like I'm doing something wrong here. Any help appreciated.

Thanks,
Stephen


_______________________________________________ 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: 
 >Is there something wrong here (AU Properties) (From: Stephen Blinkhorn <email@hidden>)
 >Re: Is there something wrong here (AU Properties) (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Missing Cocoa GUI
  • Next by Date: Re: ExtAudioFileWriteAsync is... semi-broken?
  • Previous by thread: Re: Is there something wrong here (AU Properties)
  • Next by thread: Re: Is there something wrong here (AU Properties)
  • Index(es):
    • Date
    • Thread