Return true if message is a Note Off message for MIDI. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiMessage

Description

Return true if message is a Note Off message for MIDI.

Demo Code


//package com.java2s;

import javax.sound.midi.MidiMessage;
import javax.sound.midi.MidiEvent;

public class Main {
    /** /*w w  w  .java  2 s .  c o m*/
     * Return true if message is a Note Off message.
     */
    public static boolean isNoteOffMessage(MidiMessage message) {
        // It is a note off event if the status indicates it is a 
        // note off message.  Or, if it is a note on message and
        // the velocity is zero.
        return (message.getStatus() >= 128 && message.getStatus() < 144)
                || (message.getStatus() >= 144 && message.getStatus() < 160 && getVelocity(message) == 0);
    }

    /**
     * Return the velocity for a note on or note off event.
     */
    public static int getVelocity(MidiEvent noteOnOff) {
        // I can't check for this because isNoteOnMessage calls getVelocity
        //assert isNoteOnEvent(noteOnOff) || isNoteOffEvent(noteOnOff);

        return getVelocity(noteOnOff.getMessage());
    }

    /**
     * Return the velocity for a note on or off message.
     */
    public static int getVelocity(MidiMessage noteOnOff) {
        // I can't check for this because isNoteOnMessage calls getVelocity
        //assert isNoteOnMessage(noteOnOff) || isNoteOffMessage(noteOnOff);

        return noteOnOff.getMessage()[2];
    }
}

Related Tutorials