Re: Calling MIDIPacketListAdd from NSTimer
Re: Calling MIDIPacketListAdd from NSTimer
- Subject: Re: Calling MIDIPacketListAdd from NSTimer
- From: Robert Martin <email@hidden>
- Date: Wed, 12 Oct 2011 14:02:16 -0400
Let's say you want to send a midi message to change a bank: Use MIDISend to send the MIDIPacket with a timestamp of 'now'. It will be transmitted as soon as possible.
A MIDIPacketList is just a list of MIDIPackets - each of which has a timestamp. The simplest example of playing a stored sequence might be:
1 Use MIDIPacketListInit to initialize a 'queue' of MIDI events (MIDIPackets)
2 Use MIDIPacketListAdd to add each event in your sequence using a time base where the start of the sequence = 0, and each event is stamped relative to that.
3 In a loop, read each event from the MIDIPacketList, and increment the timestamp to: the event's time + timeNow + a slop factor (e.g. 50ms or whatever)
4 MIDISend the event and continue the loop.
MIDISend gives control of the MIDIPacket to coreMIDI. coreMIDI will transmit each MIDIPacket at exactly the right time.
When you call MIDISend, you're just 'handing' the packet over to coreMIDI - IT does the transmitting…
Rob
On Oct 12, 2011, at 1:26 PM, Tom Jeffries wrote:
> So if I do:
>
> MIDIPacketListInit
> MIDIPacketListAdd
> MIDISend
>
> with all the correct parameters, does the packet get played when I do
> the MIDISend or at the time given in MIDIPacketListAdd (provided, of
> course, it is in the future rather than the past)?
>
> I haven't been involved with the application level of audio on Mac
> products for a number of years, my company has done quite a bit of
> driver work but that seems to be better documented.
>
> On Wed, Oct 12, 2011 at 10:14 AM, Robert Martin
> <email@hidden> wrote:
>> No - I don't think you've missed a 'secret' documentation cache. I learned to move my MIDI code from OS9 to OSX by looking at the source code from Kurt Revis' projects at snoize.com - MIDI Monitor, SysEx Librarian, & SnoizeMIDI - great stuff. Peter Yandell also wrote a great MIDI 'toolkit' for his 'MIDI Patchbay' app - the source is also available. The MIDIPacketxxx routines simply manipulate 'midi' bytes stored in structs called MIDIPackets. The important thing to get is what Brian pointed out - that the coreMIDI engine handles the 'exact time' that a message is transmitted - as long as you provide a timestamp and enough 'slop' for it to do its job. In other words, adding a packet to the 'queue' does not in fact 'send' it - coreMIDI sends it for you at the right time - provided it's been added to the queue with a valid timestamp for when it should be sent.
>>
>> Rob
_______________________________________________
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