Return the velocity for a note on or note off event for MIDI. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiEvent

Description

Return the velocity for a note on or note off event for MIDI.

Demo Code


//package com.java2s;

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

public class Main {
    /**//  w w  w  . j  av  a 2s .c o m
     * 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