Sends a MidiUtils.MidiTuningStandard.keyBasedTuningDump MIDI message to a receiver using the specified tuning in cents. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiMessage

Description

Sends a MidiUtils.MidiTuningStandard.keyBasedTuningDump MIDI message to a receiver using the specified tuning in cents.

Demo Code

/**//from   w  w w.j  a  va 2  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
 */
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.SysexMessage;

public class Main{
    public static final int ALL_DEVICES = 0x7F;
    /**
     * Sends a {@link MidiUtils.MidiTuningStandard.keyBasedTuningDump} MIDI
     * message to a receiver using the specified tuning in cents.
     * 
     * @param recv
     * @param bank
     * @param preset
     * @param name
     * @param tunings
     * @throws IOException
     * @throws InvalidMidiDataException
     */
    public static void sendTunings(final Receiver recv, final int bank,
            final int preset, final String name, final double[] tunings)
            throws IOException, InvalidMidiDataException {
        assert tunings.length == 128;
        final int[] itunings = new int[128];
        for (int i = 0; i < itunings.length; i++) {
            itunings[i] = (int) (tunings[i] * 16384.0 / 100.0);
        }

        final SysexMessage msg = MidiUtils.MidiTuningStandard
                .keyBasedTuningDump(MidiUtils.ALL_DEVICES, bank, preset,
                        name, itunings);
        recv.send(msg, -1);
    }
}

Related Tutorials