本文整理匯總了Java中javax.sound.midi.MidiMessage.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java MidiMessage.getMessage方法的具體用法?Java MidiMessage.getMessage怎麽用?Java MidiMessage.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.MidiMessage
的用法示例。
在下文中一共展示了MidiMessage.getMessage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: parseMessage
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
private void parseMessage(MidiMessage message) throws MidiPlayerException{
byte[] data = message.getMessage();
if( data.length > 0 ){
//NOTE ON
if(((data[0] & 0xFF) & 0xF0) == ShortMessage.NOTE_ON){
parseNoteOn(data, findChannel(message), findVoice(message), findBendMode(message));
}
//NOTE OFF
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.NOTE_OFF){
parseNoteOff(data, findChannel(message), findVoice(message), findBendMode(message));
}
//PITCH BEND
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.PITCH_BEND){
parsePitchBend(data, findChannel(message), findVoice(message), findBendMode(message));
}
//PROGRAM CHANGE
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.PROGRAM_CHANGE){
parseProgramChange(data, findChannel(message));
}
//CONTROL CHANGE
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.CONTROL_CHANGE){
parseControlChange(data, findChannel(message));
}
}
}
示例3: 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);
}
示例4: 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);
}
示例5: printEvent
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
public static void printEvent(MidiEvent event)
{
MidiMessage message = event.getMessage();
long tick = event.getTick();
byte[] data = message.getMessage();
StringBuffer sb = new StringBuffer((data.length * 3) - 1);
for (int i = 0; i < data.length; i++)
{
sb.append(toHexByteString(data[i]));
if (i < data.length - 1) sb.append(' ');
}
System.out.printf("%5d: %s%n", tick, sb);
}
示例6: 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);
}
示例7: findChannel
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
private int findChannel(MidiMessage midiMessage){
if( midiMessage instanceof MidiShortMessage ){
return ((MidiShortMessage)midiMessage).getChannel();
}
byte[] data = midiMessage.getMessage();
if( data != null && data.length > 0){
return ((data[0] & 0xFF) & 0x0F);
}
return -1;
}
示例8: send
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
@Override
public void send(MidiMessage message, long timeStamp) {
int status = message.getStatus();
System.out.println("Recieved [email protected]" + timeStamp + ", status=" + status);
if (status == 144) {
byte[] data = message.getMessage();
int note = data[1];
int velocity = data[2];
System.out.printf("note=%d, velocity=%d\n", note, velocity);
} else if (status == 128) {
}
}
示例9: 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();
}
示例10: send
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/** Forward a message to the synthesizer.
*
* If <code>message</code> is a volume change message, the volume is
* first multiplied by the global volume. Otherwise, the message is
* passed unmodified to the synthesizer.
*/
@Override
public synchronized void send(MidiMessage message, long timeStamp) {
int chan = getVolumeChangeChannel(message);
if (chan < 0) {
synthReceiver.send(message, timeStamp);
} else {
int newVolUnscaled = message.getMessage()[2];
channelVolume[chan] = newVolUnscaled;
int newVolScaled = (int) Math.round(newVolUnscaled * globalVolume);
sendVolumeChange(chan, newVolScaled, timeStamp);
}
}
示例11: 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;
}
示例12: 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.");
}
示例13: send
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
@Override
public void send( MidiMessage message, long timeStamp )
{
byte[] bytes = message.getMessage();
messageParser.parse( bytes );
}
示例14: send
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
/**
* This function is called by others to send a MIDI message to this object
* for processing.
*/
public void send(MidiMessage message, long timeStamp) {
//System.out.println("midiRecorder received " + MidiFormatting.midiMessage2polylist(message));
byte[] m = message.getMessage();
int note, channel, velocity;
int highNibble = (m[0] & 0xF0) >> 4;
int lowNibble = m[0] & 0x0F;
switch (highNibble) {
case 9: // note on
lastEvent = getTick();
if (lastEvent < 0) {
break;
}
channel = lowNibble;
note = m[1];
velocity = m[2];
if ((velocity == 0 || note < this.notate.getLow() || note > this.notate.getHigh()) && this.notate.getFilter()) {
// this is actually a note-off event, done to allow
// 'running status':
// http://www.borg.com/~jglatt/tech/midispec/run.htm
handleNoteOff(note, velocity, channel);
} else {
// System.out.println("Note: " + note + "; Velocity: " + velocity + "; Channel: " + channel);
handleNoteOn(note, velocity, channel);
}
break;
case 8: // note off
lastEvent = getTick();
if (lastEvent < 0) {
break;
}
channel = lowNibble;
note = m[1];
velocity = m[2];
handleNoteOff(note, velocity, channel);
break;
}
//System.out.println("done with " + MidiFormatting.midiMessage2polylist(message));
}
示例15: nextEvent
import javax.sound.midi.MidiMessage; //導入方法依賴的package包/類
public MidiMessage nextEvent()
{
while(true)
{
long nexttick = 0;
TrackIterator sel_iterator = null;
for(TrackIterator track_iterator : tracks_iterator)
if(track_iterator.hasNext())
if(sel_iterator == null || track_iterator.nextTick() < nexttick)
{
sel_iterator = track_iterator;
nexttick = track_iterator.nextTick();
}
if(sel_iterator == null) return null;
long tick = sel_iterator.nextTick();
MidiMessage event = sel_iterator.next();
if(tick != current_tick_pos)
{
long tickdiff = tick - current_tick_pos;
long timediff = (long)( tickdiff * (60000000f/(tempo*seqres)) );
current_tick_pos = tick;
current_event_pos += timediff;
}
byte[] msgBytes = event.getMessage();
if (msgBytes[0] == -1 && msgBytes[1] == 0x51
&& msgBytes[2] == 3) {
int mpq = ((msgBytes[3] & 0xff) << 16)
| ((msgBytes[4] & 0xff) << 8)
| (msgBytes[5] & 0xff);
// pjl removed cast to int for tempo
tempo = (60000000f / mpq);
}
if(sel_iterator.used)
{
if(event instanceof ShortMessage)
{
return processMessage(sel_iterator.track, sel_iterator.opt, (ShortMessage)event);
}
}
}
}