1 import javax.sound.midi.*;
4 * Functional representation of a MIDI note, which contains two MIDI events, note on and note off.
6 * @author Andersson, Andreen, Lanneskog, Pehrson
10 public class MooNote {
12 private MidiEvent noteOnEvent, noteOffEvent;
13 private ShortMessage noteOnMsg, noteOffMsg;
14 private long noteOnTime, noteOffTime;
17 * Creates a MooNote of the given pitch, velocity and length in the current track.
19 public MooNote (int pitch, int velocity, int length) {
20 // MidiEvent(MidiMessage message, long tick)
21 noteOnMsg = new ShortMessage();
22 noteOffMsg = new ShortMessage();
23 noteOnMsg.setMessage(ShortMessage.NOTE_ON, top.getChannel(), pitch, velocity);
24 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, top.getChannel(), pitch, velocity);
26 noteOffTime = noteOnTime + length;
27 noteOnEvent = new MidiEvent(noteOnMsg, noteOnTime)
28 noteOffEvent = new MidiEvent(noteOffMsg, noteOffTime)
32 * Sets the pitch of the current note.
33 + @param pitch the pitch of the note (0-127)
35 public void setPitch(int pitch) {
40 * Sets the velocity of the current note.
41 + @param vel the velocity of the note (0-127)
43 public void setVelocity(int vel) {
48 * Sets the length of the current note (or rather moves the note off event).
49 + @param n the length of the note in ticks (100 per beat)
51 public void setLength(int ticks) {
56 * Returns the note on event of the current note.
57 * @return the note on MidiEvent
59 public MidiEvent getNoteOnEvent() {
64 * Returns the note off event of the current note.
65 * @return the note off MidiEvent
67 public MidiEvent getNoteOffEvent() {
72 * Returns the pitch of the current note.
73 * @return the pitch of the note
75 public int getPitch() {
80 * Returns the velocity of the current note.
81 * @return the velocity of the note
83 public int getVelocity() {
88 * Returns the length of the current note.
89 * @return the length of the note
91 public int getLength() {