javax.sound.midi.MidiMessage Java Examples
The following examples show how to use
javax.sound.midi.MidiMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoftReceiver.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
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); } }
Example #2
Source File: MidiReceiverImpl.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
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)); } } }
Example #3
Source File: SoftReceiver.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #4
Source File: SoftReceiver.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #5
Source File: SoftReceiver.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #6
Source File: SoftReceiver.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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); } }
Example #7
Source File: SoftReceiver.java From Bytecoder with Apache License 2.0 | 6 votes |
@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); } }
Example #8
Source File: SoftReceiver.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #9
Source File: SoftReceiver.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #10
Source File: RealTimeSequencer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example #11
Source File: MidiUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** 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; }
Example #12
Source File: RealTimeSequencer.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Send midi player events. */ void sendControllerEvents(MidiMessage message) { int size = controllerEventListeners.size(); if (size == 0) return; if (! (message 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); }
Example #13
Source File: SoftReceiver.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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); } }
Example #14
Source File: MidiMessageUtils.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage noteOff(int channel,int note,int velocity){ try { ShortMessage message = new ShortMessage(); message.setMessage(ShortMessage.NOTE_OFF, fixChannel(channel), fixValue(note), fixValue(velocity)); return message; } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #15
Source File: SoftMainMixer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void processMessage(MidiMessage message) { if (message instanceof ShortMessage) { ShortMessage sms = (ShortMessage)message; processMessage(sms.getChannel(), sms.getCommand(), sms.getData1(), sms.getData2()); return; } processMessage(message.getMessage()); }
Example #16
Source File: SoftMainMixer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void processMessage(MidiMessage message) { if (message instanceof ShortMessage) { ShortMessage sms = (ShortMessage)message; processMessage(sms.getChannel(), sms.getCommand(), sms.getData1(), sms.getData2()); return; } processMessage(message.getMessage()); }
Example #17
Source File: VolumeScalingReceiver.java From mochadoom with GNU General Public License v3.0 | 5 votes |
/** 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; }
Example #18
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage timeSignature(TGTimeSignature tgTimeSignature){ try { return new MidiTimeSignatureMessage(tgTimeSignature); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #19
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage tempoInUSQ(int usq){ try { return new MidiTempoInUsqMessage(usq); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #20
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage systemReset(){ try { return new MidiSystemResetMessage(); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #21
Source File: SeqRecordsRealTimeEvents.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); }
Example #22
Source File: FinnwMusicModule.java From mochadoom with GNU General Public License v3.0 | 5 votes |
long appendTo(Sequence sequence, int trackNum, long pos) { Track track = sequence.getTracks()[trackNum]; for (MidiMessage msg: messages) { track.add(new MidiEvent(msg, pos)); } return pos + delay * 3; }
Example #23
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage noteOn(int channel,int note,int velocity, int voice, boolean bendMode){ try { return new MidiNoteOnMessage(channel, fixValue(note), fixValue(velocity), voice, bendMode); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #24
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage noteOff(int channel,int note,int velocity, int voice, boolean bendMode){ try { return new MidiNoteOffMessage(channel, fixValue(note), fixValue(velocity), voice, bendMode); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #25
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage pitchBend(int channel,int value, int voice, boolean bendMode){ try { return new MidiPitchBendMessage(channel, fixValue(value), voice, bendMode); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #26
Source File: MidiUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** 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); }
Example #27
Source File: MidiUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** 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); }
Example #28
Source File: MidiMessageFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage controlChange(int channel,int controller,int value){ try { return new MidiControlChangeMessage(channel, fixValue(controller), fixValue(value)); } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }
Example #29
Source File: AbstractMidiDevice.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Send this message to all transmitters. */ void sendMessage(MidiMessage message, long timeStamp) { if (message instanceof FastShortMessage) { sendMessage(((FastShortMessage) message).getPackedMsg(), timeStamp); return; } synchronized(transmitters) { int size = transmitters.size(); if (optimizedReceiverCount == size) { if (midiOutReceiver != null) { if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MidiOutReceiver"); midiOutReceiver.send(message, timeStamp); } } else { if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to "+size+" transmitter's receivers"); for (int i = 0; i < size; i++) { Receiver receiver = transmitters.get(i).getReceiver(); if (receiver != null) { //$$fb 2002-04-02: ShortMessages are mutable, so // an application could change the contents of this object, // or try to use the object later. // We violate this spec here, to avoid costly (and gc-intensive) // object creation for potentially hundred of messages per second. // The spec should be changed to allow Immutable MidiMessages // (i.e. throws InvalidStateException or so in setMessage) receiver.send(message, timeStamp); } } } } }
Example #30
Source File: MidiMessageUtils.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public static MidiMessage pitchBend(int channel,int value){ try { ShortMessage message = new ShortMessage(); message.setMessage(ShortMessage.PITCH_BEND, fixChannel(channel), 0, fixValue(value)); return message; } catch (InvalidMidiDataException e) { e.printStackTrace(); } return null; }