Java examples for javax.sound.midi:MidiSystem
MIDI Enables a tuning preset.
/**/*from w w w . j ava2 s . c o m*/ * MidiUtils provides a lot of MIDI messages. Also it can be used to build and * send tuning messages to a receiver. Uses a lot of unmodified code from the * gervill software package, licensed under the GPL with the classpath * exception. <a * href="https://gervill.dev.java.net/source/browse/gervill/src.demos/"> Gervill * source code</a> * * @author Karl Helgason */ //package com.java2s; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.Receiver; import javax.sound.midi.ShortMessage; public class Main { /** * Enables a tuning preset. * * @param recv * the receiver to send the message to * @param channel * the channel to send the message on * @param tuningpreset * the index of the tuning preset * @throws InvalidMidiDataException * if something goes awry. */ public static void sendTuningChange(final Receiver recv, final int channel, final int tuningpreset) throws InvalidMidiDataException { // Data Entry final ShortMessage sm1 = new ShortMessage(); sm1.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x64, 03); final ShortMessage sm2 = new ShortMessage(); sm2.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x65, 00); // Tuning program 19 final ShortMessage sm3 = new ShortMessage(); sm3.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x06, tuningpreset); // Data Increment final ShortMessage sm4 = new ShortMessage(); sm4.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x60, 0x7F); // Data Decrement final ShortMessage sm5 = new ShortMessage(); sm5.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x61, 0x7F); recv.send(sm1, -1); recv.send(sm2, -1); recv.send(sm3, -1); recv.send(sm4, -1); recv.send(sm5, -1); } }