Re: Calculating size for MIDIPacketListAdd
Re: Calculating size for MIDIPacketListAdd
- Subject: Re: Calculating size for MIDIPacketListAdd
- From: email@hidden
- Date: Thu, 19 Sep 2002 09:17:14 -0400
Thanks for the info Kurt. I'll see if I understand what you and the
docs are saying:
When a MIDIPacketList is init'ed it has single MIDIPacket inside (an
array
with a single element.) Can/should I assume that this is how the
MIDIPacketList
coming into my Read Proc is sized?
MIDIPackets are actually stored inside MIDIPackets (from what I could
see in
the MIDIPacketNextMacro()). I was planning to calculate the size of the
list by doing something like: sizeof(MIDIPacketList) +
(sizeof(MIDIPacket)*(pktlist->numPackets-1))
Which I now realize would be 100% incorrect! :-)
There is no way to "resize" a MIDIPacketList once you've created it, so
you can fill it
up if you add enough MIDIPackets to it. But you can create larger
MIDIPacketLists by
creating them yourself.
Question: Is MIDIPacketListInit creating a MIDIPacketList or *blessing*
a block of data
as a MIDIPacketList? I read it originally as a way to create lists but
now I think I'm wrong.
The problem is - if I'm adding to someone else's MIDIPacketList (like
the one I get passed
in my Read Proc) I've got no guarantee of it's maximum size - just that
it's *at least* sizeof(MIDIPacketList). That makes me think that I
shouldn't be adding my packets to someone else's packet list?
Your tips got my test program to start working but I'm concerned about
the robustness of messing with the incoming packet list.
Thanks,
Robert.
On Wednesday, September 18, 2002, at 11:46 PM, Kurt Revis wrote:
On Wednesday, September 18, 2002, at 06:50 PM, email@hidden wrote:
I'm trying to add a packet to a MIDIPacketList but the function needs
to know
the length of the packet list to which I'm trying to add.
Why can't the add function figure this out for itself (the
calculation doesn't look easy)?
The idea is that you have a fixed-size buffer of data, in which the
MIDIPacketList is stored. MIDIPackets (and thus MIDIPacketLists) can
vary in size. You want to tell MIDIPacketListAdd() the total size of
the buffer, so it doesn't write over the end, and stomp on whatever
random data is after it.
If you are just using a struct MIDIPacketList, then sizeof(struct
MIDIPacketList) will tell you the size. If you allocated memory, you
should know how big it was.
Finally can/should I even be trying to modify the PacketList that
came into my read proc? I know it's const but the examples cast it
away :-)
You're probably OK. The only case in which this could break would be
if you have multiple input ports which are listening to the same
endpoint in the same application. In that case, it's possible that
CoreMIDI could call the input callback for each port with the same
packet list. (I don't know if it does or not, though.) It's fairly
unlikely that you are going to do this.
(Of course, you shouldn't rely on the packet list staying valid after
your callback returns. CoreMIDI can do whatever it wants to that
memory afterwards.)
If you really want to be safe, you can copy the contents of the packet
list. You can walk through each packet in the packet list to find its
total size. It's a little bit of a pain but you should only have to
write it once.
Would it be better to create my own packet list and copy the data
into there? But then
there's no nice dispose function to throw it away...
Just malloc() some memory, cast it to a (struct MIDIPacketList *), use
it, and free() it when you're done.
--
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.