How to use MIDIData.newMIDIMetaEvent?
How to use MIDIData.newMIDIMetaEvent?
- Subject: How to use MIDIData.newMIDIMetaEvent?
- From: Scott Ruda <email@hidden>
- Date: Sat, 23 Aug 2003 14:50:10 -0700
I am trying to add a meta event to a MusicTrack and can't seem to get
it to work. The documentation on this area is a bit sparse...
(note: I'm using the Java API, but I believe this is a coreaudio-api
question, not a java-dev question)
In the MusicTtrack class there is this method:
public void newMetaEvent(double inTimeStamp, MIDIData metaData)
Which means I have to first create a new MIDIData object. To create the
meta event data object I use this method of MIDIData:
public static MIDIData newMIDIMetaEvent(int metaEventType,
int numMetaBytes)
I am trying to add a Text Event, which is meta event type 1. I have a
String "foo". I assumed that the numMetaBytes parm was for the length
of the data portion of the message only, considering I'm passing the
type parm explicitly. I have seen that when parsing meta events using
MusicEventIterator the meta event type byte is at byte 0 of the
MIDIData object and the rest of the message is at dataOffset (as
retrieved by MIDIData.getMIDIDataOffset and MIDIData.getMIDIDataLength)
(this is not documented, but I got that from inspection).
If I inspect the MIDIData object returned after constructing with a
length of 3 I see that that the midiDataLength field of the object
reports as 0. Subsequently, if I try to copy data into the object at
dataOffset, an exception is throw saying the destination buffer is not
big enough.
Here is a code snippet of what I'm doing (simplified here):
byte[] textBytes = text.getBytes("US-ASCII");
int textSize = bytes.length;
double time = 0.0;
MIDIData e = MIDIData.newMIDIMetaEvent(1, textSize);
int dataOffset = e.getMIDIDataOffset();
int dataLength = e.getMIDIDataLength();
e.copyFromArray(dataOffset, textBytes, 0, textSize);
track.newMetaEvent(time, e);
Empirically I have found that when setting numMetaBytes to anything
below 3 the midiDataLength reports as 0. Once I go above 3 it starts
reporting non-zero values of numMetaBytes-3. But even if I add 3 bytes
to the numMetaBytes parm I still get exceptions and SIGBUS errors and
such being thrown (further details upon request)
Maybe I've run across a bug, or maybe I am guessing wrong how I'm to do
this. Any information on the subject would be appreciated.
_______________________________________________
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.