Re: MIDIOutputPort.send(MIDIEndpoint dest, MID IPacketList pktlist)
Re: MIDIOutputPort.send(MIDIEndpoint dest, MID IPacketList pktlist)
- Subject: Re: MIDIOutputPort.send(MIDIEndpoint dest, MID IPacketList pktlist)
- From: Kurt Revis <email@hidden>
- Date: Sun, 1 Sep 2002 17:21:58 -0700
Disclaimer: I'm not a Java guy, but I'll try to help.
On Sunday, September 1, 2002, at 03:48 PM, Craig Bakalian wrote:
I have finally gleaned through the java core audio, figuring out how
to set up a MIDIClient, give it a MIDIInputPort, iterate through a
MIDISetup.getSource(i) to get a list of MIDIEndPoints, set up one of
the MIDIEndPoints in a connectSource....
Now, that the MIDIInputPort is connected, and my app is absorbing
midi data from the user pressing keys on a midi keyboard, how do I set
the timeStamp of the midi event? Do I use an external timer? The
example MIDIGraph in the Java CoreAudio doesn't get into this.
I assume you have some object which implements the MIDIReadProc
interface, and its execute(MIDIInputPort port,
MIDIEndpoint srcEndPoint, MIDIPacketList list) method is getting
called, right?
If that's true: why do you want to set the timestamp of incoming MIDI
events? Normally you would take the MIDIPacketList, use numPackets()
and getPacket() to get each MIDIPacket within it, and then use
getTimeStamp() on the MIDIPacket to see when it arrived.
Perhaps you are going to take that same MIDIPacket and send it out
again. In that case, you should call setTimeStamp() on the packet and
then send it out through a MIDIOutputPort's send() method. If you set
the timestamp to 0, or a time in the past, it will be sent out
immediately. If you set it to a point in the future, it will not be
sent until that time.
Time stamps are in terms of "host time". Use
com.apple.audio.util.HostTime to get the current host time and to do
manipulations of timestamps. For example, if you want to send a packet
one second from now, you would do something like this:
long nowHostTime = HostTime.getCurrentHostTime();
long nowNanos = HostTime.convertHostTimeToNanos(nowHostTime);
long oneSecondLater = nowNanos + 1000000000;
long newTimeStamp = HostTime.convertNanosToHostTime(oneSecondLater);
midiPacket.setTimeStamp(newTimeStamp);
(This is typed into Mail and may not even be correct Java syntax, but
you should get the general idea.)
Also, I am a bit confused on how to set a midi sequence (that which
contains tracks with midi events in them) to a MIDIOutputPort. In the
docs I see that the MIDIOutputPort has a .send(MIDIEndPoint des,
MIDIPacketList pklist), yet, do I need to get the data out of my apps
arrays(containing the midi events), and then turn them into a
MIDIPacket and then add them to a MIDIPacketList and send that to the
MIDIOutpPort? Is a MIDIPacketList a midi sequence?
Sort of. A MIDIPacket contains the raw bytes for one or more MIDI
messages, along with a timestamp. A MIDIPacketLIst is essentially an
array of MIDIPackets (it's one or more MIDIPackets packed together).
So it's not at a high enough level to incorporate a concept of separate
tracks or tempo or anything like that. And the timestamps of each
MIDIPacket are absolute times, not relative to each other.
So, yes, in your application, you should take your own data structures,
figure out what MIDI bytes you want to send and when you want to do it,
and construct MIDIPackets and MIDIPacketLists. Then send the packet
lists through a MIDIOutputPort.
I see that the Java MIDI documentation pretty much just says
"Implements SomeClass as defined in MIDIServices.h". So I recommend
reading the comments in
/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIServices.h;
it goes into much more detail.
If you want a higher-level interface, look at MusicPlayer and
MusicSequence in com.apple.audio.toolbox. You can direct a
MusicSequence to play to a MIDI endpoint using its setMIDIEndpoint()
method.
I hope this helps...
--
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.