Create a note off event for MIDI. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiEvent

Description

Create a note off event for MIDI.

Demo Code


import javax.sound.midi.ShortMessage;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.Sequencer;
import javax.sound.midi.Track;
import javax.sound.midi.Sequence;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MetaMessage;
import java.util.Vector;

public class Main{
    /** //www.  j a v a2  s .  com
     * Create a note off event.
     */
    public static MidiEvent createNoteOffEvent(long tick, int note,
            int velocity) {
        return MidiHelper.createNoteOffEvent(tick, 0, note, velocity);
    }
    /** 
     * Create a note off event.
     */
    public static MidiEvent createNoteOffEvent(long tick, int channel,
            int note, int velocity) {
        ShortMessage shortMessage = new ShortMessage();
        try {
            shortMessage.setMessage(ShortMessage.NOTE_OFF, channel, note,
                    velocity);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
        return new MidiEvent(shortMessage, tick);
    }
}

Related Tutorials