本文整理匯總了Java中javax.sound.midi.MidiMessage.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java MidiMessage.getLength方法的具體用法?Java MidiMessage.getLength怎麽用?Java MidiMessage.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.MidiMessage
的用法示例。
在下文中一共展示了MidiMessage.getLength方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTempoMPQ
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/** parses this message for a META tempo message and returns
* the tempo in MPQ, or -1 if this isn't a tempo message
*/
public static int getTempoMPQ(MidiMessage midiMsg) {
// first check if it is a META message at all
if (midiMsg.getLength() != 6
|| midiMsg.getStatus() != MetaMessage.META) {
return -1;
}
byte[] msg = midiMsg.getMessage();
if (((msg[1] & 0xFF) != META_TEMPO_TYPE) || (msg[2] != 3)) {
return -1;
}
int tempo = (msg[5] & 0xFF)
| ((msg[4] & 0xFF) << 8)
| ((msg[3] & 0xFF) << 16);
return tempo;
}
示例2: isMetaEndOfTrack
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/** return true if the passed message is Meta End Of Track */
public static boolean isMetaEndOfTrack(MidiMessage midiMsg) {
// first check if it is a META message at all
if (midiMsg.getLength() != 3
|| midiMsg.getStatus() != MetaMessage.META) {
return false;
}
// now get message and check for end of track
byte[] msg = midiMsg.getMessage();
return ((msg[1] & 0xFF) == META_END_OF_TRACK_TYPE) && (msg[2] == 0);
}
示例3: isMetaTempo
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/** return if the given message is a meta tempo message */
public static boolean isMetaTempo(MidiMessage midiMsg) {
// first check if it is a META message at all
if (midiMsg.getLength() != 6
|| midiMsg.getStatus() != MetaMessage.META) {
return false;
}
// now get message and check for tempo
byte[] msg = midiMsg.getMessage();
// meta type must be 0x51, and data length must be 3
return ((msg[1] & 0xFF) == META_TEMPO_TYPE) && (msg[2] == 3);
}
示例4: messagesEqual
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
private static boolean messagesEqual(MidiMessage m1, MidiMessage m2) {
if (m1 == null || m2 == null) {
return false;
}
if (m1.getLength() != m2.getLength()) {
return false;
}
byte[] array1 = m1.getMessage();
byte[] array2 = m2.getMessage();
return messagesEqual(array1, array2);
}
示例5: midiMessage2polylist
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
static public Polylist midiMessage2polylist(MidiMessage message)
{
byte[] data = message.getMessage();
int messageLength = message.getLength();
PolylistBuffer buffer = new PolylistBuffer();
// getStatus() returns status as an integer rather than byte.
// As status is the first byte in the array, it is skipped below.
buffer.append("message");
for( int i = 1; i < messageLength; i++ )
{
buffer.append(data[i]);
}
return buffer.toPolylist();
}
示例6: setData1
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/**
* Set the first data byte of a 2 or 3 byte MidiMessage.
*/
static public MidiMessage setData1(MidiMessage msg, int data1)
throws InvalidMidiDataException {
if ( msg.getLength() == 1 )
throw new InvalidMidiDataException("Can't setData1 on 1 byte message");
((ShortMessage)msg).setMessage(getStatus(msg), data1, getData2(msg));
return msg;
}
示例7: setData2
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/**
* Set the second data byte of a 3 byte MidiMessage.
*/
static public MidiMessage setData2(MidiMessage msg, int data2)
throws InvalidMidiDataException {
if ( msg.getLength() != 3 )
throw new InvalidMidiDataException("Can't setData2 on "+msg.getLength()+" byte message");
((ShortMessage)msg).setMessage(getStatus(msg), getData1(msg), data2);
return msg;
}
示例8: getVolumeChangeChannel
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/** Determine if the given message is a channel volume change.
*
* @return Channel number for which volume is being changed, or -1 if not a
* channel volume change command.
*/
private int getVolumeChangeChannel(MidiMessage message) {
if (message.getLength() >= 3) {
byte[] mBytes = message.getMessage();
if ((byte) 0xb0 <= mBytes[0] && mBytes[0] < (byte) 0xc0 &&
mBytes[1] == 7) {
return mBytes[0] & 15;
}
}
return -1;
}
示例9: sendNoteOffIfOn
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/**
* chase all events from beginning of Track
* and send note off for those events that are active
* in noteOnCache array.
* It is possible, of course, to catch notes from other tracks,
* but better than more complicated logic to detect
* which notes are really from this track
*/
private void sendNoteOffIfOn(Track track, long endTick) {
int size = track.size();
int done = 0;
try {
for (int i = 0; i < size; i++) {
MidiEvent event = track.get(i);
if (event.getTick() > endTick) break;
MidiMessage msg = event.getMessage();
int status = msg.getStatus();
int len = msg.getLength();
if (len == 3 && ((status & 0xF0) == ShortMessage.NOTE_ON)) {
int note = -1;
if (msg instanceof ShortMessage) {
ShortMessage smsg = (ShortMessage) msg;
if (smsg.getData2() > 0) {
// only consider Note On with velocity > 0
note = smsg.getData1();
}
} else {
byte[] data = msg.getMessage();
if ((data[2] & 0x7F) > 0) {
// only consider Note On with velocity > 0
note = data[1] & 0x7F;
}
}
if (note >= 0) {
int bit = 1<<(status & 0x0F);
if ((noteOnCache[note] & bit) != 0) {
// the bit is set. Send Note Off
getTransmitterList().sendMessage(status | (note<<8), -1);
// clear the bit
noteOnCache[note] &= (0xFFFF ^ bit);
done++;
}
}
}
}
} catch (ArrayIndexOutOfBoundsException aioobe) {
// this happens when messages are removed
// from the track while this method executes
}
if (DEBUG_PUMP) Printer.println(" sendNoteOffIfOn: sent "+done+" messages.");
}
示例10: testMessage
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
private static boolean testMessage(MidiMessage message) {
receivedMessage = null;
baos = new ByteArrayOutputStream();
expectedBytes = message.getLength();
receivedBytes = 0;
System.out.print("Sending message " + getMessageString(message.getMessage())+"...");
receiver.send(message, -1);
/* sending 3 bytes can roughly be done in 1 millisecond,
* so this estimate waits at max 3 times longer than the message takes,
* plus a little offset to allow the MIDI subsystem some processing time
*/
int offset = 300; // standard offset 100 millis
if (message instanceof SysexMessage) {
// add a little processing time to sysex messages
offset += 1000;
}
if (receivedBytes < expectedBytes) {
sleep(expectedBytes + offset);
}
boolean equal;
byte[] data = baos.toByteArray();
if (data.length > 0) {
equal = messagesEqual(message.getMessage(), data);
} else {
equal = messagesEqual(message, receivedMessage);
if (receivedMessage != null) {
data = receivedMessage.getMessage();
} else {
data = null;
}
}
if (!equal) {
if ((message.getStatus() & 0xF0) == ShortMessage.PITCH_BEND) {
out("NOT failed (may expose a bug in ALSA)");
equal = true;
sleep(100);
}
if ((message.getStatus() == 0xF6) && (message.getLength() == 1)) {
out("NOT failed (may expose an issue on Solaris)");
equal = true;
sleep(100);
}
else if ((message.getStatus()) == 0xF0 && message.getLength() < 4) {
out("NOT failed (not a correct sys ex message)");
equal = true;
sleep(200);
} else {
out("FAILED:");
out(" received as " + getMessageString(data));
}
} else {
System.out.println("OK");
}
return equal;
}
示例11: getLength
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
public static int getLength(MidiMessage msg) {
return msg.getLength();
}