+ /**
+ * Creates a MooNote of the given pitch, velocity and duration in the current track.
+ * @param channel the channel of the note (1-16)
+ * @param pitch the pitch of the note (0-127)
+ * @param velocity the velocity of the note (0-127)
+ * @param timestamp the timestamp of the note in ticks (96 per beat)
+ * @param duration the duration of the note in ticks (96 per beat)
+ */
+ public MooNote (int channel, int pitch, int velocity, long timestamp, int duration) {
+ super(new ShortMessage(), timestamp);
+ noteOffEvent = new MidiEvent(new ShortMessage(), timestamp + duration);
+ noteOnMsg = (ShortMessage)getMessage();
+ noteOffMsg = (ShortMessage)noteOffEvent.getMessage();
+ try {
+ noteOnMsg.setMessage(ShortMessage.NOTE_ON, channel, pitch, velocity);
+ noteOffMsg.setMessage(ShortMessage.NOTE_OFF, channel, pitch, 64);
+ } catch (InvalidMidiDataException e) {System.out.println("Invalid data!");}
+ }
+
+ /**
+ * Returns the note off event of this note.
+ * @return the note off event
+ */
+ public MidiEvent getNoteOffEvent() {
+ return noteOffEvent;
+ }
+
+ /**
+ * Returns the channel of the current note.
+ * @return the channel of the note (1-16)
+ */
+ public int getChannel() {
+ return noteOnMsg.getChannel();
+ }
+
+ /**
+ * Returns the pitch of the current note.
+ * @return the pitch of the note (0-127)
+ */
+ public int getPitch() {
+ return noteOnMsg.getData1();
+ }
+
+ /**
+ * Returns the velocity of the current note.
+ * @return the velocity of the note (0-127)
+ */
+ public int getVelocity() {
+ return noteOnMsg.getData2();
+ }
+
+ /**
+ * Returns the duration of the current note.
+ * @return the duration of the note (in ticks)
+ */
+ public int getDuration() {
+ return (int)(noteOffEvent.getTick() - getTick());
+ }
+
+ /**
+ * Sets the channel of the current note.
+ * @param channel the channel of the note (1-16)
+ */
+ public void setChannel(int channel) {
+ try {
+ noteOnMsg.setMessage(noteOnMsg.getCommand(), (byte)channel, noteOnMsg.getData1(), noteOnMsg.getData2());
+ noteOffMsg.setMessage(noteOffMsg.getCommand(), (byte)channel, noteOffMsg.getData1(), noteOffMsg.getData2());
+ } catch (InvalidMidiDataException e) {}
+ }
+
+ /**