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 noteOnMsg = new ShortMessage();
21 noteOffMsg = new ShortMessage();
22 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, velocity);
23 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, velocity);
25 noteOffTime = noteOnTime + length;
26 noteOnEvent = new MidiEvent(noteOnMsg, noteOnTime);
27 noteOffEvent = new MidiEvent(noteOffMsg, noteOffTime);
31 * Sets the pitch of the current note.
32 * @param pitch the pitch of the note (0-127)
34 public void setPitch(int pitch) {
35 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, noteOnMsg.getData2());
36 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, noteOffMsg.getData2());
40 * Sets the velocity of the current note.
41 + @param vel the velocity of the note (0-127)
43 public void setVelocity(int vel) {
44 noteOnMsg.setMessage(ShortMessage.NOTE_ON, noteOnMsg.getData1(), vel);
45 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, noteOffMsg.getData1(), vel);
49 * Sets the length of the current note (or rather moves the note off event).
50 + @param n the length of the note in ticks (100 per beat)
52 public void setLength(int ticks) {
57 * Returns the note on event of the current note.
58 * @return the note on MidiEvent
60 public MidiEvent getNoteOnEvent() {
65 * Returns the note off event of the current note.
66 * @return the note off MidiEvent
68 public MidiEvent getNoteOffEvent() {
73 * Returns the pitch of the current note.
74 * @return the pitch of the note
76 public int getPitch() {
77 return noteOnMsg.getData1();
81 * Returns the velocity of the current note.
82 * @return the velocity of the note
84 public int getVelocity() {
85 return noteOnMsg.getData2();
89 * Returns the length of the current note.
90 * @return the length of the note
92 public int getLength() {