Chris@2: /* Chris@2: Copyright (C) 2001, 2006 by Simon Dixon Chris@2: Chris@2: This program is free software; you can redistribute it and/or modify Chris@2: it under the terms of the GNU General Public License as published by Chris@2: the Free Software Foundation; either version 2 of the License, or Chris@2: (at your option) any later version. Chris@2: Chris@2: This program is distributed in the hope that it will be useful, Chris@2: but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@2: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@2: GNU General Public License for more details. Chris@2: Chris@2: You should have received a copy of the GNU General Public License along Chris@2: with this program (the file gpl.txt); if not, download it from Chris@2: http://www.gnu.org/licenses/gpl.txt or write to the Chris@2: Free Software Foundation, Inc., Chris@2: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Chris@2: */ Chris@2: Chris@2: package at.ofai.music.util; Chris@2: Chris@2: public class Event implements Comparable, Cloneable, java.io.Serializable { Chris@2: Chris@2: public double keyDown, keyUp, pedalUp, scoreBeat, scoreDuration, salience; Chris@2: public int midiPitch, midiVelocity, flags, midiCommand, midiChannel, Chris@2: midiTrack; Chris@2: //public String label; Chris@2: Chris@2: public Event(double onset, double offset, double eOffset, int pitch, Chris@2: int velocity, double beat, double duration, int eventFlags, Chris@2: int command, int channel, int track) { Chris@2: this(onset, offset, eOffset, pitch, velocity, beat,duration,eventFlags); Chris@2: midiCommand = command; Chris@2: midiChannel = channel; Chris@2: midiTrack = track; Chris@2: } // constructor Chris@2: Chris@2: public Event(double onset, double offset, double eOffset, int pitch, Chris@2: int velocity, double beat, double duration, int eventFlags) { Chris@2: keyDown = onset; Chris@2: keyUp = offset; Chris@2: pedalUp = eOffset; Chris@2: midiPitch = pitch; Chris@2: midiVelocity = velocity; Chris@2: scoreBeat = beat; Chris@2: scoreDuration = duration; Chris@2: flags = eventFlags; Chris@2: midiCommand = javax.sound.midi.ShortMessage.NOTE_ON; Chris@2: midiChannel = 1; Chris@2: midiTrack = 0; Chris@2: salience = 0; Chris@2: } // constructor Chris@2: Chris@2: public Event clone() { Chris@2: return new Event(keyDown, keyUp, pedalUp, midiPitch, midiVelocity, Chris@2: scoreBeat, scoreDuration, flags, midiCommand, midiChannel, Chris@2: midiTrack); Chris@2: } // clone() Chris@2: Chris@2: // Interface Comparable Chris@2: public int compareTo(Object o) { Chris@2: Event e = (Event) o; Chris@2: return (int)Math.signum(keyDown - e.keyDown); Chris@2: } // compareTo() Chris@2: Chris@2: public String toString() { Chris@2: return "n=" + midiPitch + " v=" + midiVelocity + " t=" + keyDown + Chris@2: " to " + keyUp + " (" + pedalUp + ")"; Chris@2: } // toString() Chris@2: Chris@2: public void print(Flags f) { Chris@2: System.out.printf("Event:\n"); Chris@2: System.out.printf("\tkeyDown / Up / pedalUp: %5.3f / %5.3f / %5.3f\n", Chris@2: keyDown, keyUp, pedalUp); Chris@2: //System.out.printf("\tkeyUp: %5.3f\n", keyUp); Chris@2: //System.out.printf("\tpedalUp: %5.3f\n", pedalUp); Chris@2: System.out.printf("\tmidiPitch: %d\n", midiPitch); Chris@2: System.out.printf("\tmidiVelocity: %d\n", midiVelocity); Chris@2: System.out.printf("\tmidiCommand: %02x\t", midiCommand | midiChannel); Chris@2: //System.out.printf("\tmidiChannel: %d\n", midiChannel); Chris@2: System.out.printf("\tmidiTrack: %d\n", midiTrack); Chris@2: System.out.printf("\tsalience: %5.3f\t", salience); Chris@2: System.out.printf("\tscoreBeat: %5.3f\t", scoreBeat); Chris@2: System.out.printf("\tscoreDuration: %5.3f\n", scoreDuration); Chris@2: System.out.printf("\tflags: %X", flags); Chris@2: if (f != null) { Chris@2: int ff = flags; Chris@2: for (int i=0; ff != 0; i++) { Chris@2: if (ff % 2 == 1) Chris@2: System.out.print(" " + f.getLabel(i)); Chris@2: ff >>>= 1; Chris@2: } Chris@2: } Chris@2: System.out.print("\n\n"); Chris@2: } // print() Chris@2: Chris@2: } // class Event