本文整理汇总了Java中javax.sound.midi.MidiMessage类的典型用法代码示例。如果您正苦于以下问题:Java MidiMessage类的具体用法?Java MidiMessage怎么用?Java MidiMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MidiMessage类属于javax.sound.midi包,在下文中一共展示了MidiMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override
public void send(MidiMessage message, long timeStamp) {
try {
if (sound) {
midiPlugin.sound(message);
}
MidiMessageEvent<?> event;
if (message instanceof ShortMessage) {
event = MidiUtils.createShortMessageEvent(midiPlugin, (ShortMessage) message, timeStamp);
} else if (message instanceof SysexMessage) {
event = new MidiSysexMessageEvent(midiPlugin.getMidiSysexMessageEventName(),
midiPlugin.getEngine().getDefaultParameters().getEventClonePolicy(), (SysexMessage) message, timeStamp);
} else if (message instanceof MetaMessage) {
event = new MidiMetaMessageEvent(midiPlugin.getMidiMetaMessageEventName(),
midiPlugin.getEngine().getDefaultParameters().getEventClonePolicy(), (MetaMessage) message, timeStamp);
} else {
throw new SpongeException("Unknown MIDI message type: " + message.getClass());
}
midiPlugin.getEngine().getOperations().event(event).send();
} catch (Exception e) {
logger.error("send", e);
}
}
示例2: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
public void send(MidiMessage message, long timeStamp) {
synchronized (control_mutex) {
if (!open)
throw new IllegalStateException("Receiver is not open");
}
if (timeStamp != -1) {
synchronized (control_mutex) {
mainmixer.activity();
while (midimessages.get(timeStamp) != null)
timeStamp++;
if (message instanceof ShortMessage
&& (((ShortMessage)message).getChannel() > 0xF)) {
midimessages.put(timeStamp, message.clone());
} else {
midimessages.put(timeStamp, message.getMessage());
}
}
} else {
mainmixer.processMessage(message);
}
}
示例3: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override
public void send(MidiMessage message, long timeStamp) {
synchronized (control_mutex) {
if (!open)
throw new IllegalStateException("Receiver is not open");
}
if (timeStamp != -1) {
synchronized (control_mutex) {
mainmixer.activity();
while (midimessages.get(timeStamp) != null)
timeStamp++;
if (message instanceof ShortMessage
&& (((ShortMessage)message).getChannel() > 0xF)) {
midimessages.put(timeStamp, message.clone());
} else {
midimessages.put(timeStamp, message.getMessage());
}
}
} else {
mainmixer.processMessage(message);
}
}
示例4: 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;
}
示例5: sendControllerEvents
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
/**
* Send midi player events.
*/
void sendControllerEvents(MidiMessage message) {
int size = controllerEventListeners.size();
if (size == 0) return;
//if (Printer.debug) Printer.debug("sending a controller event");
if (! (message instanceof ShortMessage)) {
if (Printer.debug) Printer.debug("sendControllerEvents: message is NOT instanceof ShortMessage!");
return;
}
ShortMessage msg = (ShortMessage) message;
int controller = msg.getData1();
List<Object> sendToListeners = new ArrayList<>();
for (int i = 0; i < size; i++) {
ControllerListElement cve = controllerEventListeners.get(i);
for(int j = 0; j < cve.controllers.length; j++) {
if (cve.controllers[j] == controller) {
sendToListeners.add(cve.listener);
break;
}
}
}
getEventDispatcher().sendAudioEvents(message, sendToListeners);
}
示例6: init
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
private void init() throws MidiUnavailableException {
devIn = MidiSystem.getMidiDevice(inInfo); devIn.open();
devOut = MidiSystem.getMidiDevice(outInfo); devOut.open();
midiIn = new MidiInput(); devIn.getTransmitter().setReceiver(midiIn);
midiOut = (MidiDeviceReceiver)devOut.getReceiver();
//MIDI Message Sender Thread:
midiTx = new Thread(() -> { while(true) {
int size; while((size=cue.size()) > 0) {
MidiMessage msg; synchronized(this) { msg = cue.get(0); cue.remove(0); } midiOut.send(msg, -1);
if(size > 10000) { //Keep array under 10,000...
synchronized(this) { size=cue.size(); while(size > 50) { cue.remove(size-1); size--; }}
debug("Buffer had to be force-cleared!");
} if(Thread.interrupted()) return;
} if(Thread.interrupted()) return;
}}); midiTx.setPriority(1); midiTx.start();
programMode(); setAll(-1); //Reset LaunchPad Lights.
}
示例7: 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));
}
}
}
示例8: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
public void send(MidiMessage inMessage, long inTimeStamp)
{
if(inMessage instanceof ShortMessage)
{
ShortMessage mm = (ShortMessage)inMessage;
switch(mm.getCommand())
{
case ShortMessage.NOTE_ON:
case ShortMessage.NOTE_OFF:
MiProvider.instance().noteReceived(mm, inTimeStamp);
break;
case ShortMessage.CONTROL_CHANGE:
//System.err.println("Control change");
break;
}
}
}
示例9: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
public void send(MidiMessage message, long timeStamp) {
synchronized (control_mutex) {
if (!open)
throw new IllegalStateException("Receiver is not open");
}
if (timeStamp != -1) {
synchronized (control_mutex) {
while (midimessages.get(timeStamp) != null)
timeStamp++;
if (message instanceof ShortMessage
&& (((ShortMessage)message).getChannel() > 0xF)) {
midimessages.put(timeStamp, message.clone());
} else {
midimessages.put(timeStamp, message.getMessage());
}
}
} else {
mainmixer.processMessage(message);
}
}
示例10: render
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override
public void render() throws RenderCommandException {
sleepUntil(getFrame().playOutTime);
for(MidiMessage msg : getFrame().messages) {
if(msg instanceof ShortMessage) {
final ShortMessage sm = (ShortMessage)msg;
final MidiChannel ch = synth.getChannels()[sm.getChannel()];
switch(sm.getCommand()) {
case ShortMessage.NOTE_ON:
ch.noteOn(sm.getData1(), sm.getData2());
continue;
case ShortMessage.NOTE_OFF:
ch.noteOff(sm.getData1(), sm.getData2());
continue;
case ShortMessage.PROGRAM_CHANGE:
ch.programChange(sm.getData1());
continue;
case ShortMessage.CONTROL_CHANGE:
ch.controlChange(sm.getData1(), sm.getData2());
continue;
}
}
throw new RenderCommandException("Unknown MIDI Command:" + MidiToString.toString(msg));
}
}
示例11: handle
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override
public void handle(MidiMessage msg) {
if(msg instanceof ShortMessage) {
ShortMessage smsg = (ShortMessage)msg;
switch(smsg.getCommand()) {
case ShortMessage.CONTROL_CHANGE:
int cc = smsg.getData1();
if(cc2run[cc] != null) cc2run[cc].handle(msg);
break;
case ShortMessage.NOTE_ON:
int key = smsg.getData1();
if(key2run[key] != null) key2run[key].handle(msg);
break;
case ShortMessage.PITCH_BEND:
pitchBend.set(smsg);
synchronized (processMidi) {processMidi.notifyAll();}
break;
}
}
System.out.println(MidiToString.toString(msg));
}
示例12: captureMidiMessages
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override
protected void captureMidiMessages(final Receiver receiver) throws MidiUnavailableException {
// Modify all MidiMessages so that they specify channel 10 (encoded as 9,
// which I suppose means that 0 indicates midi channel 1)
Receiver setChannelReceiver = new Receiver() {
@Override
public void send(MidiMessage message, long timeStamp) {
if (message instanceof ShortMessage) {
ShortMessage sm = (ShortMessage) message;
byte[] data = sm.getMessage();
byte orig = data[0];
data[0] = (byte) ((orig | 9) & 0xff);
message = Midi.createShortMessage(data);
}
receiver.send(message, timeStamp);
}
@Override
public void close() {
receiver.close();
}
};
super.captureMidiMessages(setChannelReceiver);
}
示例13: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override
public void send(MidiMessage message, long timeStamp) {
super.send(message, timeStamp);
if (!midiLearnService.isMidiLearning() && interpretedMessage != null
&& !interpretedSignature.equals(MidiUtils.UNKNOWN_MESSAGE)
&& !isExecuting) {
log.debug(name + " checking MIDI trigger for message: "
+ interpretedSignature);
guiAutomationsService
.activateAutomationsByMidiMessage(interpretedMessage);
isExecuting = false;
}
}
示例14: createMTCSetup
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
public static MidiMessage createMTCSetup(int channel, MTC.Time time,
MTC.FrameRate rate, int type, int event, byte[] add) throws InvalidMidiDataException {
int addlen = add == null ? 0 : 2 * add.length;
byte[] data = new byte[13+addlen];
createUniversalHeader(data, ID_UNIVERSAL_NON_REALTIME, channel, 0x04, type);
data[5] = (byte) ((time.hours & 0x0f) | (rate.getIndex() << 4));
data[6] = (byte) (time.minutes & 0x3f); // mn
data[7] = (byte) (time.seconds & 0x3f); // sc
data[8] = (byte) (time.frames & 0x1f); // fr
data[9] = (byte) (time.fractionalFrames & 0x7f); // ff
data[10] = (byte) (event & 0x7f); // sl
data[11] = (byte) ((event >> 7) & 0x7f); // sm
// nibblize additional data
if ( addlen > 0 ) {
for ( int i = 0, j = 12; i < addlen; i++, j += 2 ) {
data[j] = (byte)(add[i] & 0x0f); // ls nibble
data[j+1] = (byte)((add[i] >> 4) & 0x0f); // ms nibble
}
}
data[data.length-1] = (byte) END_OF_EXCLUSIVE;
return createSysex(data, 13);
}
示例15: send
import javax.sound.midi.MidiMessage; //导入依赖的package包/类
@Override public void send(MidiMessage message, long timeStamp)
{
if (receiver == null)
return;
if (hasAbcPart && message instanceof ShortMessage)
{
ShortMessage m = (ShortMessage) message;
int c = m.getChannel();
int cmd = m.getCommand();
int noteId = m.getData1();
int speed = m.getData2();
boolean noteOnMsg = (cmd == ShortMessage.NOTE_ON) && speed > 0;
boolean noteOffMsg = (cmd == ShortMessage.NOTE_OFF) || (cmd == ShortMessage.NOTE_ON && speed == 0);
if (!isNoteActive(noteId) && !(isNoteOn(c, noteId) && noteOffMsg))
return;
if (noteOnMsg)
setNoteOn(c, noteId, true);
else if (noteOffMsg)
setNoteOn(c, noteId, false);
}
receiver.send(message, timeStamp);
}