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, pitch, velocity);
24 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, 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) {
36 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, noteOnMsg.getData2());
37 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, noteOffMsg.getData2());
41 * Sets the velocity of the current note.
42 + @param vel the velocity of the note (0-127)
44 public void setVelocity(int vel) {
45 noteOnMsg.setMessage(ShortMessage.NOTE_ON, noteOnMsg.getData1(), vel);
46 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, noteOffMsg.getData1(), vel);
50 * Sets the length of the current note (or rather moves the note off event).
51 + @param n the length of the note in ticks (100 per beat)
53 public void setLength(int ticks) {
58 * Returns the note on event of the current note.
59 * @return the note on MidiEvent
61 public MidiEvent getNoteOnEvent() {
66 * Returns the note off event of the current note.
67 * @return the note off MidiEvent
69 public MidiEvent getNoteOffEvent() {
74 * Returns the pitch of the current note.
75 * @return the pitch of the note
77 public int getPitch() {
78 return noteOnMsg.getData1();
82 * Returns the velocity of the current note.
83 * @return the velocity of the note
85 public int getVelocity() {
86 return noteOnMsg.getData2();
90 * Returns the length of the current note.
91 * @return the length of the note
93 public int getLength() {