Re: Calculating size for MIDIPacketListAdd
Re: Calculating size for MIDIPacketListAdd
- Subject: Re: Calculating size for MIDIPacketListAdd
- From: Philippe Wicker <email@hidden>
- Date: Thu, 19 Sep 2002 18:01:55 +0200
On Thursday, September 19, 2002, at 03:17 PM, email@hidden wrote:
>
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.
>
To initialize a list you can do something like:
Byte list_buffer[kMySize] ;
MIDIPacketList* packet_list = (MIDIPacketList*)list_buffer ;
MIDIPacket* current_packet = MIDIPacketListInit (packet_list) ;
Your packet list will then contains a buffer which size is kMySize.
However it does not Contain yet a packet (or at most an empty packet).
If you don't want to provide your own buffer, do:
MIDIPacketList the_packet_list ;
MIDIPacketList* packet_list = &the_packet_list ;
MIDIPacket* current_packet = MIDIPacketListInit (packet_list) ;
Your list will then contains a buffer which can contain 256 bytes of
packet data (+ bytes for packet header, ie time stamp and data length
fields).
To add data to the current packet in this list, you can do something
like:
current_packet = MIDIPacketListAdd (
packet_list
, sizeof(list_buffer) // you could have written kMySize
, current_packet
, the_event_time
, the_event_size // the size in Byte of your MIDI event (eg
a NOTE ON)
, the_event_data // the address of your MIDI event data
) ;
If there is no more room in the buffer you passed when calling
MIDIPacketListInit(), then MIDIPacketListAdd() returns NULL. So check
the returned pointer to initialize a new list if needed. If you have to
deal with packets with "a priori" unknown size, get the length of the
packet in the field "length" (struct MIDIPacket in MIDIServices.h),
calculate the size needed for your list buffer (sizeof(numPackets) for
the list length + sizeof(timeStamp +length) for the packet header +
packet length for the packet data), allocate a buffer of that size,
initialize a new list with that buffer, add the packet to the list, and
you're done.
Regards.
>
_______________________________________________
>
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.
_______________________________________________
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.