annotate at/ofai/music/util/Event.java @ 5:bcb4c9697967 tip

Add README and CITATION files
author Chris Cannam
date Tue, 03 Dec 2013 12:58:05 +0000
parents 4c3f5bc01c97
children
rev   line source
Chris@2 1 /*
Chris@2 2 Copyright (C) 2001, 2006 by Simon Dixon
Chris@2 3
Chris@2 4 This program is free software; you can redistribute it and/or modify
Chris@2 5 it under the terms of the GNU General Public License as published by
Chris@2 6 the Free Software Foundation; either version 2 of the License, or
Chris@2 7 (at your option) any later version.
Chris@2 8
Chris@2 9 This program is distributed in the hope that it will be useful,
Chris@2 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@2 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@2 12 GNU General Public License for more details.
Chris@2 13
Chris@2 14 You should have received a copy of the GNU General Public License along
Chris@2 15 with this program (the file gpl.txt); if not, download it from
Chris@2 16 http://www.gnu.org/licenses/gpl.txt or write to the
Chris@2 17 Free Software Foundation, Inc.,
Chris@2 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Chris@2 19 */
Chris@2 20
Chris@2 21 package at.ofai.music.util;
Chris@2 22
Chris@2 23 public class Event implements Comparable, Cloneable, java.io.Serializable {
Chris@2 24
Chris@2 25 public double keyDown, keyUp, pedalUp, scoreBeat, scoreDuration, salience;
Chris@2 26 public int midiPitch, midiVelocity, flags, midiCommand, midiChannel,
Chris@2 27 midiTrack;
Chris@2 28 //public String label;
Chris@2 29
Chris@2 30 public Event(double onset, double offset, double eOffset, int pitch,
Chris@2 31 int velocity, double beat, double duration, int eventFlags,
Chris@2 32 int command, int channel, int track) {
Chris@2 33 this(onset, offset, eOffset, pitch, velocity, beat,duration,eventFlags);
Chris@2 34 midiCommand = command;
Chris@2 35 midiChannel = channel;
Chris@2 36 midiTrack = track;
Chris@2 37 } // constructor
Chris@2 38
Chris@2 39 public Event(double onset, double offset, double eOffset, int pitch,
Chris@2 40 int velocity, double beat, double duration, int eventFlags) {
Chris@2 41 keyDown = onset;
Chris@2 42 keyUp = offset;
Chris@2 43 pedalUp = eOffset;
Chris@2 44 midiPitch = pitch;
Chris@2 45 midiVelocity = velocity;
Chris@2 46 scoreBeat = beat;
Chris@2 47 scoreDuration = duration;
Chris@2 48 flags = eventFlags;
Chris@2 49 midiCommand = javax.sound.midi.ShortMessage.NOTE_ON;
Chris@2 50 midiChannel = 1;
Chris@2 51 midiTrack = 0;
Chris@2 52 salience = 0;
Chris@2 53 } // constructor
Chris@2 54
Chris@2 55 public Event clone() {
Chris@2 56 return new Event(keyDown, keyUp, pedalUp, midiPitch, midiVelocity,
Chris@2 57 scoreBeat, scoreDuration, flags, midiCommand, midiChannel,
Chris@2 58 midiTrack);
Chris@2 59 } // clone()
Chris@2 60
Chris@2 61 // Interface Comparable
Chris@2 62 public int compareTo(Object o) {
Chris@2 63 Event e = (Event) o;
Chris@2 64 return (int)Math.signum(keyDown - e.keyDown);
Chris@2 65 } // compareTo()
Chris@2 66
Chris@2 67 public String toString() {
Chris@2 68 return "n=" + midiPitch + " v=" + midiVelocity + " t=" + keyDown +
Chris@2 69 " to " + keyUp + " (" + pedalUp + ")";
Chris@2 70 } // toString()
Chris@2 71
Chris@2 72 public void print(Flags f) {
Chris@2 73 System.out.printf("Event:\n");
Chris@2 74 System.out.printf("\tkeyDown / Up / pedalUp: %5.3f / %5.3f / %5.3f\n",
Chris@2 75 keyDown, keyUp, pedalUp);
Chris@2 76 //System.out.printf("\tkeyUp: %5.3f\n", keyUp);
Chris@2 77 //System.out.printf("\tpedalUp: %5.3f\n", pedalUp);
Chris@2 78 System.out.printf("\tmidiPitch: %d\n", midiPitch);
Chris@2 79 System.out.printf("\tmidiVelocity: %d\n", midiVelocity);
Chris@2 80 System.out.printf("\tmidiCommand: %02x\t", midiCommand | midiChannel);
Chris@2 81 //System.out.printf("\tmidiChannel: %d\n", midiChannel);
Chris@2 82 System.out.printf("\tmidiTrack: %d\n", midiTrack);
Chris@2 83 System.out.printf("\tsalience: %5.3f\t", salience);
Chris@2 84 System.out.printf("\tscoreBeat: %5.3f\t", scoreBeat);
Chris@2 85 System.out.printf("\tscoreDuration: %5.3f\n", scoreDuration);
Chris@2 86 System.out.printf("\tflags: %X", flags);
Chris@2 87 if (f != null) {
Chris@2 88 int ff = flags;
Chris@2 89 for (int i=0; ff != 0; i++) {
Chris@2 90 if (ff % 2 == 1)
Chris@2 91 System.out.print(" " + f.getLabel(i));
Chris@2 92 ff >>>= 1;
Chris@2 93 }
Chris@2 94 }
Chris@2 95 System.out.print("\n\n");
Chris@2 96 } // print()
Chris@2 97
Chris@2 98 } // class Event