本文整理汇总了Java中javax.sound.midi.ShortMessage类的典型用法代码示例。如果您正苦于以下问题:Java ShortMessage类的具体用法?Java ShortMessage怎么用?Java ShortMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShortMessage类属于javax.sound.midi包,在下文中一共展示了ShortMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.sound.midi.ShortMessage; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
Receiver recv = synth.getReceiver();
assertTrue(recv != null);
ShortMessage sm = new ShortMessage();
sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
synth.open(new DummySourceDataLine(), null);
recv.send(sm, -1);
synth.close();
try
{
recv.send(sm, -1);
throw new RuntimeException("Exception not thrown!");
}
catch(Exception e)
{
// Just checking if exception is thrown
}
}
示例2: send
import javax.sound.midi.ShortMessage; //导入依赖的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);
}
}
示例3: send
import javax.sound.midi.ShortMessage; //导入依赖的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);
}
}
示例4: send
import javax.sound.midi.ShortMessage; //导入依赖的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);
}
}
示例5: sendControllerEvents
import javax.sound.midi.ShortMessage; //导入依赖的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: notesOff
import javax.sound.midi.ShortMessage; //导入依赖的package包/类
void notesOff(boolean doControllers) {
int done = 0;
for (int ch=0; ch<16; ch++) {
int channelMask = (1<<ch);
for (int i=0; i<128; i++) {
if ((noteOnCache[i] & channelMask) != 0) {
noteOnCache[i] ^= channelMask;
// send note on with velocity 0
getTransmitterList().sendMessage((ShortMessage.NOTE_ON | ch) | (i<<8), -1);
done++;
}
}
/* all notes off */
getTransmitterList().sendMessage((ShortMessage.CONTROL_CHANGE | ch) | (123<<8), -1);
/* sustain off */
getTransmitterList().sendMessage((ShortMessage.CONTROL_CHANGE | ch) | (64<<8), -1);
if (doControllers) {
/* reset all controllers */
getTransmitterList().sendMessage((ShortMessage.CONTROL_CHANGE | ch) | (121<<8), -1);
done++;
}
}
if (DEBUG_PUMP) Printer.println(" noteOff: sent "+done+" messages.");
}
示例7: testReceiverSend
import javax.sound.midi.ShortMessage; //导入依赖的package包/类
/**
* Execute Receiver.send() and expect that there is no exception.
*/
private static boolean testReceiverSend() {
boolean result = true;
Receiver receiver;
ShortMessage shMsg = new ShortMessage();
try {
receiver = MidiSystem.getReceiver();
shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
try {
receiver.send( shMsg, -1 );
} catch(IllegalStateException ilEx) {
ilEx.printStackTrace(System.out);
out("IllegalStateException was thrown incorrectly!");
result = false;
}
receiver.close();
} catch(MidiUnavailableException e) {
out("Midi unavailable, cannot test.");
} catch(InvalidMidiDataException ine) {
out("InvalidMidiDataException, cannot test.");
}
return result;
}
示例8: parseMessage
import javax.sound.midi.ShortMessage; //导入依赖的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));
}
}
}
示例9: send
import javax.sound.midi.ShortMessage; //导入依赖的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;
}
}
}
示例10: send
import javax.sound.midi.ShortMessage; //导入依赖的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);
}
}
示例11: render
import javax.sound.midi.ShortMessage; //导入依赖的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));
}
}
示例12: handle
import javax.sound.midi.ShortMessage; //导入依赖的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));
}
示例13: addMidiNote
import javax.sound.midi.ShortMessage; //导入依赖的package包/类
/**
* Add the given MidiNote into the {@link #sequence}.
*
* @param note The note to add.
*
* @throws InvalidMidiDataException If the MidiNote contains invalid Midi data.
*/
public void addMidiNote(MidiNote note) throws InvalidMidiDataException {
int correctVoice = note.getCorrectVoice();
// Pad with enough tracks
while (sequence.getTracks().length <= correctVoice) {
sequence.createTrack();
}
// Get the correct track
Track track = sequence.getTracks()[correctVoice];
ShortMessage noteOn = new ShortMessage();
noteOn.setMessage(ShortMessage.NOTE_ON | correctVoice, note.getPitch(), note.getVelocity());
MidiEvent noteOnEvent = new MidiEvent(noteOn, note.getOnsetTick());
ShortMessage noteOff = new ShortMessage();
noteOff.setMessage(ShortMessage.NOTE_OFF | correctVoice, note.getPitch(), 0);
MidiEvent noteOffEvent = new MidiEvent(noteOff, note.getOffsetTick());
track.add(noteOnEvent);
track.add(noteOffEvent);
}
示例14: send
import javax.sound.midi.ShortMessage; //导入依赖的package包/类
public void send(MidiMessage message, long timeStamp) {
if (message instanceof ShortMessage) {
ShortMessage sm = ((ShortMessage)message);
switch(sm.getCommand()) {
case ShortMessage.CONTROL_CHANGE:
System.out.println(sm.getChannel());
System.out.println(sm.getData1());
System.out.println(sm.getData2());
MidiControlChangedListener listener = listenersDic.get(sm.getData1());
if(listener != null){
listener.changed(sm.getData1(), sm.getData2());
}
break;
}
}
System.out.println("midi received");
}
示例15: send
import javax.sound.midi.ShortMessage; //导入依赖的package包/类
public void send(MidiMessage mess, long timeStamp) {
if (mess.getStatus() >= ShortMessage.MIDI_TIME_CODE) {
// System.out.println(mess + " " + mess.getStatus() );
return;
}
// make time stamp -1 (otherwise bad timing)
if (mess instanceof ShortMessage) {
ShortMessage shm = (ShortMessage) mess;
int cmd = shm.getCommand();
if (cmd != 240) {
int chn = shm.getChannel();
int dat1 = shm.getData1();
int dat2 = shm.getData2();
System.out.println(" cmd:" + cmd + " chn:" + chn + " data:"
+ dat1 + " " + dat2);
}
}
chained.send(mess, -1);
}