public void setLine(int line, String text) { try { byte[] msg = new byte[77]; Arrays.fill(msg, (byte)' '); int idx = 0; msg[idx++] = (byte) SysexMessage.SYSTEM_EXCLUSIVE; msg[idx++] = 71; msg[idx++] = 127; msg[idx++] = 21; msg[idx++] = (byte) (24+line); msg[idx++] = 0; msg[idx++] = 69; msg[idx++] = 0; for(int i = 0; i < Math.min(68, text.length()); i++) msg[idx++] = (byte) (text.charAt(i) & 0x7F); msg[msg.length-1] = (byte) 247; send(new SysexMessage(msg, msg.length)); } catch(Throwable t) { log.warning(t); } }
@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); } }
/** * Delegator method that calls specific parsers depending on the * type of MidiMessage passed in. * @param message the message to parse * @param timestamp the time at which the message was encountered in this track */ public void parse(MidiMessage message, long timestamp) { if (message instanceof ShortMessage) { parseShortMessage((ShortMessage)message, timestamp); } else if (message instanceof SysexMessage) { parseSysexMessage((SysexMessage)message, timestamp); } else if (message instanceof MetaMessage) { parseMetaMessage((MetaMessage)message, timestamp); } }
private void addSysexBytes(byte bytes[]) { for (byte b : bytes) { if (b == (byte)0xF7) { currentMessage.add((byte)0xF7); byte msg[] = new byte[currentMessage.size()]; for (int i = 0; i < currentMessage.size(); i++) { msg[i] = ((Byte)currentMessage.get(i)).byteValue(); } javax.sound.midi.SysexMessage newMsg = new javax.sound.midi.SysexMessage(); try { newMsg.setMessage(msg, msg.length); for (Plug plug : plugList) plug.callPlug(this, newMsg); } catch (InvalidMidiDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { currentMessage.add(b); } } }
public void send(final MidiMessage message, final long timeStamp) { // if ((message.getLength() >= 1)) { // System.out.println("message " + message); // printHex(message.getMessage()); // } if (message instanceof javax.sound.midi.SysexMessage || message.getStatus() == (byte)0xF7) { if (message.getStatus() == 0xF0) { // System.out.println("clear message and start new "); currentMessage.clear(); // no shortcut for sysex messages currentMessage.add((byte)0xF0); } addSysexBytes(((javax.sound.midi.SysexMessage)message).getData()); /// } else { if (message.getStatus() >= 0xF8) { return; } else { if (message.getStatus() == 0xF7) { addSysexBytes(message.getMessage()); return; } } for (Plug plug : plugList) plug.callPlug(this, message); } }
private static SysexMessage setDeviceControl(int targetDevice, int control, int value) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(DEVICE_CONTROL); baos.write((byte) control); baos.write((byte) (value % 128)); baos.write((byte) (value / 128)); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage setGlobalParameter(int targetDevice, short[] slotpath, byte[] parameter, byte[] value) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(DEVICE_CONTROL); baos.write(GLOBAL_PARAMETER_CONTROL); baos.write((byte) slotpath.length); baos.write((byte) parameter.length); baos.write((byte) value.length); for (int i = 0; i < slotpath.length; i++) { short x = slotpath[0]; baos.write((byte) (x >>> 8)); baos.write((byte) x); } baos.write(parameter); baos.write(value); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage setKeyBasedControl(int targetDevice, int midi_channel, int key_number, int[] controls, int[] values) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(KEY_BASED_INSTRUMENT_CONTROL); baos.write(BASIC_MESSAGE); baos.write((byte) midi_channel); baos.write((byte) key_number); for (int i = 0; i < controls.length; i++) { baos.write((byte) controls[i]); baos.write((byte) values[i]); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage setControllerDestinationForChannelPressure( int targetDevice, int channel, int[] controls, int[] ranges) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(CONTROLLER_DESTINATION_SETTINGS); baos.write(CONTROLLER_CHANNEL_PRESSURE); baos.write((byte) channel); for (int i = 0; i < controls.length; i++) { baos.write((byte) controls[i]); baos.write((byte) ranges[i]); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage setControllerDestinationForPolyPressure( int targetDevice, int channel, int[] controls, int[] ranges) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(CONTROLLER_DESTINATION_SETTINGS); baos.write(CONTROLLER_POLY_PRESSURE); baos.write((byte) channel); for (int i = 0; i < controls.length; i++) { baos.write((byte) controls[i]); baos.write((byte) ranges[i]); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage setControllerDestinationForControlChange( int targetDevice, int channel, byte control, int[] controls, int[] ranges) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(CONTROLLER_DESTINATION_SETTINGS); baos.write(CONTROLLER_CONTROL_CHANGE); baos.write((byte) channel); baos.write((byte) control); for (int i = 0; i < controls.length; i++) { baos.write((byte) controls[i]); baos.write((byte) ranges[i]); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage singleNoteTuningChange(int targetDevice, int preset, int[] key_numbers, int[] key_tunings) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(SINGLE_NOTE_TUNING_CHANGE); baos.write((byte) preset); baos.write((byte) key_numbers.length); for (int i = 0; i < key_numbers.length; i++) { baos.write((byte) key_numbers[i]); int t = key_tunings[i]; baos.write((byte) ((t / 16384) % 128)); baos.write((byte) ((t / 128) % 128)); baos.write((byte) (t % 128)); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
private void sysex(ChuList<Integer> data) { data.addAll(0, new Integer[]{0,32,41,2,16}); data.add(247); SysexMessage msg = new SysexMessage(); byte[] dBytes = new byte[data.length]; for(int i=0,l=data.length; i<l; i++) dBytes[i] = data.get(i).byteValue(); try { msg.setMessage(240, dBytes, dBytes.length); synchronized(this) { cue.add(msg); }} catch (InvalidMidiDataException e) { debug("Error in LaunchPad:SysEx: Invalid data!"); } }
private void sysexDirect(ChuList<Byte> data) { data.addAll(0, new Byte[]{0,32,41,2,16}); data.add((byte)247); SysexMessage msg = new SysexMessage(); byte[] dBytes = new byte[data.length]; for(int i=0,l=data.length; i<l; i++) dBytes[i] = data.get(i); try { msg.setMessage(240, dBytes, dBytes.length); midiOut.send(msg, -1); } catch (InvalidMidiDataException e) { debug("Error in LaunchPad:SysEx: Invalid data!"); } }
static SysexMessage sysex(int ... data) { try { byte[] msg = new byte[data.length]; for(int i = 0; i < msg.length; i++) msg[i] = (byte) data[i]; return new SysexMessage(msg, msg.length); } catch(Throwable t) { log.warning(t); return null; } }
public static String toString(MidiMessage message) { String result = "unknown message type"; if (message instanceof ShortMessage) result = decodeMessage((ShortMessage) message); else if (message instanceof SysexMessage) result = decodeMessage((SysexMessage) message); else if (message instanceof MetaMessage) result = decodeMessage((MetaMessage) message); return result; }
private static String decodeMessage(SysexMessage message) { byte[] abData = message.getData(); String result = null; if (message.getStatus() == SysexMessage.SYSTEM_EXCLUSIVE) result = "Sysex message: F0" + TextUtilities.toHex(abData); else if (message.getStatus() == SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) result = "Continued Sysex message F7" + TextUtilities.toHex(abData); return result; }
/** * Formats a midi message to a readable String. * * @param message * The midi message * @return a readable String */ public static String messageToString(MidiMessage message) { if (message instanceof ShortMessage) { return decodeMessage((ShortMessage) message); } else if (message instanceof SysexMessage) { return decodeMessage((SysexMessage) message); } else if (message instanceof MetaMessage) { return decodeMessage((MetaMessage) message); } else { return MidiUtils.UNKNOWN_MESSAGE; } }
/** * Entry method called from SysexEvent. * Default implementation assumes a single sysex message to be parsed * and thus delegates to parse(String). * @param macro * @return */ public MidiMessage[] parseMessages(String macro) throws InvalidMidiDataException { byte[] data = parse(macro); SysexMessage syxm = new SysexMessage(); syxm.setMessage(data, data.length); MidiMessage[] mm = { syxm }; return mm; }
public void setData(byte[] data) { // single raw sysex message try { SysexMessage syxm = new SysexMessage(); syxm.setMessage(data, data.length); midiEvents = new MidiEvent[] { new MidiEvent(syxm, startTick) }; } catch (InvalidMidiDataException imde) { imde.printStackTrace(); } }
/** * Macro: e70fx <reverb-type> <reverb-intensity> <chorus-type> <chorus-intensity> [ <user-prg> ] [ <use-prg-change> ] * * Sets the built-in reverb-effect style on one of the user-programs. * There are two modes of operation: * In order to overcome the limitation that the actively * selected user-program cannot be configured via sysex, the current * user-program will be changed to before sending the sysex message * and after having made the changes will be switched back again. * This has the effect that after setting the effect this way, the * <user-prg> will be the actively selected one, even if it hadn't * been selected before. * To disable the special behaviour of switching user-programs, use * * arg[0]: reverb-type (0: none, 1: room1, 2: room2, 3: room3, 4: hall1, etc.) * arg[1]: reverb-intensity (0-7) * arg[2]: chorus-type (0: none, 1: chorus1, 2: chorus2, etc.) * arg[3]: chorus-intensity (0-7) * arg[4] (optional): user-program to modify, default "11" (0) * arg[5] (optional): channel on which to send user program switch, may differ * from current Frinika-track's channel. Default is 16 (i.e. * 15 if counting from 0 to 15), use -1 to disable sending * user-program changes before and after the sysex data. */ public MidiMessage[] parseMessages(String macro) throws InvalidMidiDataException { String[] args = splitArgs(macro); int usrPrg = 0; int chn = 15; if (args.length > 4) { usrPrg = parseInt(args[4], 10); } if (args.length > 5) { chn = parseInt(args[5], 10); } byte[] data = parse(args); // get sysex data SysexMessage syxm = new SysexMessage(); syxm.setMessage(data, data.length); if ((chn >= 0) && (chn <= 15)) { int otherUsrPrg = (usrPrg == 0) ? 1 : 0; MidiMessage[] prgChg = usrPrgChg( otherUsrPrg, chn ); MidiMessage[] prgChgBack = usrPrgChg( usrPrg, chn ); MidiMessage[] mm = { prgChg[0], prgChg[1], prgChg[2], syxm, prgChgBack[0], prgChgBack[1], prgChgBack[2] }; return mm; } else { return new MidiMessage[] { syxm }; } }
private static void sendSysexMessage(Receiver receiver, byte... message) { SysexMessage msg = new SysexMessage(); try { msg.setMessage(message, message.length); } catch (InvalidMidiDataException ex) { throw new RuntimeException(ex); } receiver.send(msg, -1); }
private void addSysExMessage(int status, byte... data) { try { SysexMessage msg = new SysexMessage(); msg.setMessage(status, data, data.length); messages.add(msg); } catch (InvalidMidiDataException ex) { throw new RuntimeException(ex); } }
public static void sendScaleOctaveTunings(Receiver recv, int bank, int preset, String name, double[] tunings) throws IOException, InvalidMidiDataException { int[] itunings = new int[12]; for (int i = 0; i < itunings.length; i++) { itunings[i] = (int) (tunings[i] * 8192.0 / 100.0); } SysexMessage msg = UniversalSysExBuilder.MidiTuningStandard .scaleOctaveTuningDump2ByteForm(UniversalSysExBuilder.ALL_DEVICES, bank, preset, name, itunings); recv.send(msg, -1); }
private static SysexMessage setGeneralMidiMessage(int targetDevice, byte type) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(GENERAL_MIDI_MESSAGES); baos.write(type); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage scaleOctaveTuning1ByteForm(int targetDevice, boolean realtime, boolean channels[], int[] tuning) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (realtime) baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); else baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(SCALE_OCTAVE_TUNING_1BYTE_FORM); int channelmask = 0; for (int i = 0; i < 2; i++) { if (channels[i + 14]) channelmask += 1 << i; } baos.write((byte) channelmask); channelmask = 0; for (int i = 0; i < 7; i++) { if (channels[i + 7]) channelmask += 1 << i; } baos.write((byte) channelmask); channelmask = 0; for (int i = 0; i < 7; i++) { if (channels[i]) channelmask += 1 << i; } baos.write((byte) channelmask); for (int i = 0; i < 12; i++) { baos.write((byte) (tuning[i] + 64)); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage scaleOctaveTuning2ByteForm(int targetDevice, boolean realtime, boolean channels[], int[] tuning) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (realtime) baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); else baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(SCALE_OCTAVE_TUNING_2BYTE_FORM); int channelmask = 0; for (int i = 0; i < 2; i++) { if (channels[i + 14]) channelmask += 1 << i; } baos.write((byte) channelmask); channelmask = 0; for (int i = 0; i < 7; i++) { if (channels[i + 7]) channelmask += 1 << i; } baos.write((byte) channelmask); channelmask = 0; for (int i = 0; i < 7; i++) { if (channels[i]) channelmask += 1 << i; } baos.write((byte) channelmask); for (int i = 0; i < 12; i++) { int t = tuning[i] + 8192; baos.write((byte) (t / 128)); baos.write((byte) (t % 128)); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage scaleOctaveTuningDump1ByteForm( int targetDevice, int bank, int preset, String name, int[] tuning) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(SCALE_OCTAVE_TUNING_DUMP_1BYTE_FORM); baos.write((byte) bank); baos.write((byte) preset); if (name.length() > 16) name = name.substring(0, 16); byte[] namebytes = name.getBytes("ASCII"); baos.write(namebytes); byte space_char = " ".getBytes()[0]; for (int i = namebytes.length; i < 16; i++) baos.write(space_char); for (int i = 0; i < 12; i++) { baos.write((byte) (tuning[i] + 64)); } baos.write(0); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); setTuningChecksum(data); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage scaleOctaveTuningDump2ByteForm(int targetDevice, int bank, int preset, String name, int[] tuning) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(SCALE_OCTAVE_TUNING_DUMP_2BYTE_FORM); baos.write((byte) bank); baos.write((byte) preset); if (name.length() > 16) name = name.substring(0, 16); byte[] namebytes = name.getBytes("ASCII"); baos.write(namebytes); byte space_char = " ".getBytes()[0]; for (int i = namebytes.length; i < 16; i++) baos.write(space_char); for (int i = 0; i < 12; i++) { int t = tuning[i] + 8192; baos.write((byte) (t / 128)); baos.write((byte) (t % 128)); } baos.write(0); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); setTuningChecksum(data); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage singleNoteTuningChange(int targetDevice, boolean realtime, int bank, int preset, int[] key_numbers, int[] key_tunings) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (realtime) baos.write(UNIVERSAL_REALTIME_SYSEX_HEADER); else baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(SINGLE_NOTE_TUNING_CHANGE_BANK); baos.write((byte) bank); baos.write((byte) preset); baos.write((byte) key_numbers.length); for (int i = 0; i < key_numbers.length; i++) { baos.write((byte) key_numbers[i]); int t = key_tunings[i]; baos.write((byte) ((t / 16384) % 128)); baos.write((byte) ((t / 128) % 128)); baos.write((byte) (t % 128)); } baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage keyBasedTuningDump(int targetDevice, int preset, String name, int[] tunings) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(BULK_TUNING_DUMP); baos.write((byte) preset); if (name.length() > 16) name = name.substring(0, 16); byte[] namebytes = name.getBytes("ASCII"); baos.write(namebytes); byte space_char = " ".getBytes()[0]; for (int i = namebytes.length; i < 16; i++) baos.write(space_char); for (int i = 0; i < 128; i++) { int t = tunings[i]; baos.write((byte) ((t / 16384) % 128)); baos.write((byte) ((t / 128) % 128)); baos.write((byte) (t % 128)); } baos.write(0); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); setTuningChecksum(data); sysex.setMessage(data, data.length); return sysex; }
public static SysexMessage keyBasedTuningDump(int targetDevice, int bank, int preset, String name, int[] tunings) throws IOException, InvalidMidiDataException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(UNIVERSAL_NON_REALTIME_SYSEX_HEADER); baos.write((byte) targetDevice); baos.write(MIDI_TUNING_STANDARD); baos.write(KEY_BASED_TUNING_DUMP); baos.write((byte) bank); baos.write((byte) preset); if (name.length() > 16) name = name.substring(0, 16); byte[] namebytes = name.getBytes("ASCII"); baos.write(namebytes); byte space_char = " ".getBytes()[0]; for (int i = namebytes.length; i < 16; i++) baos.write(space_char); for (int i = 0; i < 128; i++) { int t = tunings[i]; baos.write((byte) ((t / 16384) % 128)); baos.write((byte) ((t / 128) % 128)); baos.write((byte) (t % 128)); } baos.write(0); baos.write(EOX); SysexMessage sysex = new SysexMessage(); byte[] data = baos.toByteArray(); setTuningChecksum(data); sysex.setMessage(data, data.length); return sysex; }
public static void sendTunings(Receiver recv, int bank, int preset, String name, double[] tunings) throws IOException, InvalidMidiDataException { int[] itunings = new int[128]; for (int i = 0; i < itunings.length; i++) { itunings[i] = (int) (tunings[i] * 16384.0 / 100.0); } SysexMessage msg = UniversalSysExBuilder.MidiTuningStandard .keyBasedTuningDump(UniversalSysExBuilder.ALL_DEVICES, bank, preset, name, itunings); recv.send(msg, -1); }
public void retune(int bank, int preset, int note, double tuning) throws IOException, InvalidMidiDataException { int[] key_numbers = new int[1]; int[] key_tunings = new int[1]; key_numbers[0] = note; key_tunings[0] = (int) (tuning * 16384.0 / 100.0); SysexMessage msg = UniversalSysExBuilder.MidiTuningStandard .singleNoteTuningChange(UniversalSysExBuilder.ALL_DEVICES, true, bank, preset, key_numbers, key_tunings); recv.send(msg, -1); }
@Test public void testSendMidi() throws MidiUnavailableException, InvalidMidiDataException { Info[] midiDeviceInfos = MidiSystem.getMidiDeviceInfo(); int portCount = 0; for (Info info : midiDeviceInfos) { if (info instanceof CoreMidiDeviceInfo) { MidiDevice midiDevice = MidiSystem.getMidiDevice(info); if (midiDevice.getMaxReceivers() == -1) { portCount++; assertEquals(CoreMidiDestination.class, midiDevice.getClass()); midiDevice.open(); Receiver receiver = midiDevice.getReceiver(); ShortMessage shortMessage = new ShortMessage(); shortMessage .setMessage(ShortMessage.CONTROL_CHANGE, 21, 35); receiver.send(shortMessage, 0); SysexMessage sysexMessage = new SysexMessage(); byte[] buf = new byte[] { (byte) 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x33, 0x02, 0x0D, (byte) 0xF7 }; sysexMessage.setMessage(buf, buf.length); receiver.send(sysexMessage, 0); midiDevice.close(); } } } assertEquals(NUM_PORTS, portCount); }
private static boolean testMessage(MidiMessage message) { receivedMessage = null; baos = new ByteArrayOutputStream(); expectedBytes = message.getLength(); receivedBytes = 0; System.out.print("Sending message " + getMessageString(message.getMessage())+"..."); receiver.send(message, -1); /* sending 3 bytes can roughly be done in 1 millisecond, * so this estimate waits at max 3 times longer than the message takes, * plus a little offset to allow the MIDI subsystem some processing time */ int offset = 300; // standard offset 100 millis if (message instanceof SysexMessage) { // add a little processing time to sysex messages offset += 1000; } if (receivedBytes < expectedBytes) { sleep(expectedBytes + offset); } boolean equal; byte[] data = baos.toByteArray(); if (data.length > 0) { equal = messagesEqual(message.getMessage(), data); } else { equal = messagesEqual(message, receivedMessage); if (receivedMessage != null) { data = receivedMessage.getMessage(); } else { data = null; } } if (!equal) { if ((message.getStatus() & 0xF0) == ShortMessage.PITCH_BEND) { out("NOT failed (may expose a bug in ALSA)"); equal = true; sleep(100); } if ((message.getStatus() == 0xF6) && (message.getLength() == 1)) { out("NOT failed (may expose an issue on Solaris)"); equal = true; sleep(100); } else if ((message.getStatus()) == 0xF0 && message.getLength() < 4) { out("NOT failed (not a correct sys ex message)"); equal = true; sleep(200); } else { out("FAILED:"); out(" received as " + getMessageString(data)); } } else { System.out.println("OK"); } return equal; }
/** * Change the volume of all sounds. * * @param volumeValue A double to set the volume of all sounds between 0.0 * and 1.0. If the parameter is higher or lower than this range, * then the volume is clamped to the end of the ranges. */ public static void setVolume(double volumeValue) { if (volumeValue < 0.0) { volume = 0.0; } else if (volumeValue > 1.0) { volume = 1.0; } else { volume = volumeValue; } if (midiAvailable) { /* * Construct a system exclusive MIDI message to send a real time * message to request a volume change. */ boolean midiNeedsToBeClosed = false; if (!midiSequencer.isOpen()) { openMidi(); midiNeedsToBeClosed = true; } Double volumeDouble = volumeValue * 127.0; byte volumeByte = (byte) volumeDouble.intValue(); try { MidiMessage volumeMessage = new SysexMessage(SysexMessage.SYSTEM_EXCLUSIVE, new byte[] { 0x7F, 0x7F, 0x04, 0x01, 0x00, volumeByte }, 6); /* * REFERENCE: This MIDI message: "7F 7F 04 01 LL MM" is used * from this Stack Overflow question: * http://stackoverflow.com/questions/23170223/how-to-change-the * -master-volume-of-a-synthesizer-sequencer The answer here * describes the appropriate message needed to be sent to MIDI * receiver and not an implementation as how to send such * message. */ midiReceiver.send(volumeMessage, -1); } catch (InvalidMidiDataException exception) { throw new RuntimeException(exception.getMessage()); } finally { if (midiNeedsToBeClosed) { midiSequencer.close(); } } } }
public void setBrightness(float value) { send(sysex(SysexMessage.SYSTEM_EXCLUSIVE,71,127,21,124,0,1,MathUtilities.clamp((int)(value*127), 0, 127),SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE)); }
public void clearLine(int line) { send(sysex(SysexMessage.SYSTEM_EXCLUSIVE,71,127,21,28+line,0,0,SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE)); }
public void setTouchStrip(TouchStrip conf) { send(sysex(SysexMessage.SYSTEM_EXCLUSIVE,71,127,21,99,0,1,conf.ordinal(),SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE)); }