private void sendEnvelopeFrequency(Receiver rx, int channel, byte[] regs) throws Exception { int data = (regs[0xc] & 0xff) + ((regs[0xd] << 8) & 0x0f00); data = data >> FREQ_SCALE_FACTOR; // 16 bit value, divided into 7/7/2 byte high = (byte) ((data >> 9) & 0x7f); // top 7 bits byte med = (byte) ((data >> 7) & 0x7f); // middle 7 bits byte low = (byte) (((data >> 2) & 0x03) << 5); // bottom 2 bits rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_HIGH, high), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_MED, med), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_LOW, low), -1); }
/** * Play one bell sound immediately, bypassing Sequencer * * @param bell */ public void play(int bell) { MidiEvent evt; try { evt = createBellNote(bell, 0); fMidiOut.send(evt.getMessage(), -1); } catch (InvalidMidiDataException e) { System.out.println("Failed to play note; " + e); } }
private void sendLatch(Receiver rx, int channel, boolean enabled) throws Exception { byte value = enabled ? (byte) 64 : (byte) 0; if (!enabled) { // save registers for (int i = 0; i < registers.length; i++) { prevRegisters[i] = registers[i]; } } rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_LATCH, value), -1); }
/** * Send a Program Change on this output * * @param channel Channel on which to send the message * @param value Program Change value * @return 1 on success, 0 on error */ public int sendProgramChange(int value) { ShortMessage msg = new ShortMessage(); try { msg.setMessage(MidiEvent.PROGRAM_CHANGE, value, -1); receiver.send(msg, -1); return 1; } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
/** * Send a SYSEX MIDI message on this output * * @param msg Bytes of the sysex message, have to contain 0xF0 at the beginning and 0xF7 at the * end * @return 1 on success, 0 on error */ public int sendSysex(byte[] msg) { javax.sound.midi.SysexMessage msg2 = new javax.sound.midi.SysexMessage(); try { msg2.setMessage(msg, msg.length); receiver.send(msg2, 0); return 1; } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
/** * Send a NOTE OFF message on this output. * * @param channel Channel on which to send the message * @param note Note pitch * @param velocity Note velocity * @return 1 on success, 0 on error */ public int sendNoteOff(int channel, int note, int velocity) { ShortMessage msg = new ShortMessage(); try { msg.setMessage(MidiEvent.NOTE_OFF, channel, note, velocity); receiver.send(msg, -1); return 1; } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
/** * Send a Controller change message on this output. * * @param channel Channel on which to send the message * @param cc Controller Change number * @param value Controller Change value * @return 1 on success, 0 on error */ public int sendController(int channel, int cc, int value) { ShortMessage msg = new ShortMessage(); try { msg.setMessage(MidiEvent.CONTROL_CHANGE, channel, cc, value); receiver.send(msg, -1); return 1; } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
private void sendFrequency(Receiver rx, int channel, byte[] regs, int startRegister) throws Exception { int data = (regs[startRegister] & 0xff) + ((regs[startRegister + 1] << 8) & 0x0f00); data = data >> FREQ_SCALE_FACTOR; byte msb = (byte) ((data >> 5) & 0x7f); // top 7 bits byte lsb = (byte) ((data << 2) & 0x7c); // lower 5 bits int cc1 = ((startRegister / 2) + CC_CHANNEL_A_FREQ_MSB); int cc2 = ((startRegister / 2) + CC_CHANNEL_A_FREQ_LSB); rx.send(new ShortMessage(CONTROL_CHANGE, channel, (byte) cc1, msb), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, (byte) cc2, lsb), -1); }
/** * Send entry MIDI Sequence into Receiver using time stamps. * * @return The total length of the sequence. */ private double send(final Sequence seq, final Receiver recv) { assert seq.getDivisionType() == Sequence.PPQ; final float divtype = seq.getDivisionType(); final Track[] tracks = seq.getTracks(); tune(recv); final int[] trackspos = new int[tracks.length]; int mpq = 500000; final int seqres = seq.getResolution(); long lasttick = 0; long curtime = 0; while (true) { MidiEvent selevent = null; int seltrack = -1; for (int i = 0; i < tracks.length; i++) { final int trackpos = trackspos[i]; final Track track = tracks[i]; if (trackpos < track.size()) { final MidiEvent event = track.get(trackpos); if (selevent == null || event.getTick() < selevent.getTick()) { selevent = event; seltrack = i; } } } if (seltrack == -1) { break; } trackspos[seltrack]++; final long tick = selevent.getTick(); if (divtype == Sequence.PPQ) { curtime += (tick - lasttick) * mpq / seqres; } else { curtime = (long) (tick * 1000000.0 * divtype / seqres); } lasttick = tick; final MidiMessage msg = selevent.getMessage(); if (msg instanceof MetaMessage) { if (divtype == Sequence.PPQ && ((MetaMessage) msg).getType() == 0x51) { final byte[] data = ((MetaMessage) msg).getData(); mpq = (data[0] & 0xff) << 16 | (data[1] & 0xff) << 8 | data[2] & 0xff; } } else if (recv != null) { recv.send(msg, curtime); } } return curtime / 1000000.0; }
public void outputFirstEvents() { if (notes.get(currentNote).getTime() == 0) { Event currentEvent = notes.get(currentNote); for (int note : currentEvent.getAllNotes()) { try { MidiMessage message = new ShortMessage(ShortMessage.NOTE_ON, 0, note, 97); receiver.send(message, System.nanoTime()); } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } } currentNote++; } }
/** * Send a Pitch Bend on this output * * @param channel Channel on which to send the message * @param value Program Change value * @return 1 on success, 0 on error */ public int sendPitchBend(int channel, int value) { ShortMessage msg = new ShortMessage(); try { // int ub = (int)Math.floor( value / 128 ); // int bb = value-(128*ub); int bb = value & 0x7f; int ub = value >> 7; // if( ub>0 ){ bb = bb | 0x80; } // System.out.println("ub="+ub); // System.out.println("bb="+bb); msg.setMessage(MidiEvent.PITCH_BEND, channel, bb, ub); receiver.send(msg, -1); return 1; } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
public static double send(Sequence seq, Receiver recv) { float divtype = seq.getDivisionType(); assert (seq.getDivisionType() == Sequence.PPQ); Track[] tracks = seq.getTracks(); int[] trackspos = new int[tracks.length]; int mpq = 60000000 / 100; int seqres = seq.getResolution(); long lasttick = 0; long curtime = 0; while (true) { MidiEvent selevent = null; int seltrack = -1; for (int i = 0; i < tracks.length; i++) { int trackpos = trackspos[i]; Track track = tracks[i]; if (trackpos < track.size()) { MidiEvent event = track.get(trackpos); if (selevent == null || event.getTick() < selevent.getTick()) { selevent = event; seltrack = i; } } } if (seltrack == -1) break; trackspos[seltrack]++; long tick = selevent.getTick(); if (divtype == Sequence.PPQ) curtime += ((tick - lasttick) * mpq) / seqres; else curtime = (long) ((tick * 1000000.0 * divtype) / seqres); lasttick = tick; MidiMessage msg = selevent.getMessage(); if (msg instanceof MetaMessage) { if (divtype == Sequence.PPQ) if (((MetaMessage) msg).getType() == 0x51) { byte[] data = ((MetaMessage) msg).getData(); mpq = ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff); } } else { if (recv != null) recv.send(msg, curtime); } } return curtime / 1000000.0; }
private void sendIfReady() { // send event if ready while (ready()) { Event currentEvent = notes.get(currentNote); for (int note : currentEvent.getAllNotes()) { try { MidiMessage message = new ShortMessage(ShortMessage.NOTE_ON, 0, note, 97); receiver.send(message, System.nanoTime()); } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } } currentNote++; } if (currentNote >= notes.size()) { done = true; } }
public void close() { sequencerReceiver.close(); }
public void send(MidiMessage message, long timestamp) { parser.parse(message, timestamp / (1000 * 4)); sequencerReceiver.send(message, timestamp); }
@Override public void send(MidiMessage message, long timeStamp) { receiver.send(message, timeStamp); }
// Receiver implementation @Override public void close() { receiver.close(); }
private void sendValue(Receiver rx, int channel, byte cc, byte value) throws Exception { rx.send(new ShortMessage(CONTROL_CHANGE, channel, cc, value), -1); }
private void resetController(Receiver rx, int channel, byte[] regs) throws Exception { for (int i = 0; i < 15; i++) { regs[i] = 0; } rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_LATCH, 127), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_A_FREQ_MSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_A_FREQ_LSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_B_FREQ_MSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_B_FREQ_LSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_C_FREQ_MSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_C_FREQ_LSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_NOISE_FREQ, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_MIXER, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_A_LEVEL, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_B_LEVEL, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_C_LEVEL, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_HIGH, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_MED, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_LOW, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_SHAPE, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_LATCH, 0), -1); }
public void stop() { fSequencer.stop(); fSequencer.close(); fSynthesizer.close(); fMidiOut.close(); }
public void closeObjectMidiSystem() { receiverMidiSystem.close(); }
public void closeObjectDevice() { receiverDevice.close(); }