plectrum

Plectrum: instrument tuner for Android
Log | Files | Refs | README | LICENSE

Event.java (4225B)


      1 /*
      2 *      _______                       _____   _____ _____  
      3 *     |__   __|                     |  __ \ / ____|  __ \ 
      4 *        | | __ _ _ __ ___  ___  ___| |  | | (___ | |__) |
      5 *        | |/ _` | '__/ __|/ _ \/ __| |  | |\___ \|  ___/ 
      6 *        | | (_| | |  \__ \ (_) \__ \ |__| |____) | |     
      7 *        |_|\__,_|_|  |___/\___/|___/_____/|_____/|_|     
      8 *                                                         
      9 * -------------------------------------------------------------
     10 *
     11 * TarsosDSP is developed by Joren Six at IPEM, University Ghent
     12 *  
     13 * -------------------------------------------------------------
     14 *
     15 *  Info: http://0110.be/tag/TarsosDSP
     16 *  Github: https://github.com/JorenSix/TarsosDSP
     17 *  Releases: http://0110.be/releases/TarsosDSP/
     18 *  
     19 *  TarsosDSP includes modified source code by various authors,
     20 *  for credits and info, see README.
     21 * 
     22 */
     23 
     24 /*
     25 	Copyright (C) 2001, 2006 by Simon Dixon
     26 
     27 	This program is free software; you can redistribute it and/or modify
     28 	it under the terms of the GNU General Public License as published by
     29 	the Free Software Foundation; either version 2 of the License, or
     30 	(at your option) any later version.
     31 
     32 	This program is distributed in the hope that it will be useful,
     33 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     34 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     35 	GNU General Public License for more details.
     36 
     37 	You should have received a copy of the GNU General Public License along
     38 	with this program (the file gpl.txt); if not, download it from
     39 	http://www.gnu.org/licenses/gpl.txt or write to the
     40 	Free Software Foundation, Inc.,
     41 	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     42 */
     43 
     44 package be.tarsos.dsp.beatroot;
     45 
     46 public class Event implements Comparable<Event>, Cloneable {
     47 
     48 	public double keyDown, keyUp, pedalUp, scoreBeat, scoreDuration, salience;
     49 	public int midiPitch, midiVelocity, flags, midiCommand, midiChannel,
     50 				midiTrack;
     51 	//public String label;
     52 
     53 	public Event(double onset, double offset, double eOffset, int pitch,
     54 				 int velocity, double beat, double duration, int eventFlags,
     55 				 int command, int channel, int track) {
     56 		this(onset, offset, eOffset, pitch, velocity, beat,duration,eventFlags);
     57 		midiCommand = command;
     58 		midiChannel = channel;
     59 		midiTrack = track;
     60 	} // constructor
     61 
     62 	public Event(double onset, double offset, double eOffset, int pitch,
     63 				 int velocity, double beat, double duration, int eventFlags) {
     64 		keyDown = onset;
     65 		keyUp = offset;
     66 		pedalUp = eOffset;
     67 		midiPitch = pitch;
     68 		midiVelocity = velocity;
     69 		scoreBeat = beat;
     70 		scoreDuration = duration;
     71 		flags = eventFlags;
     72 		midiCommand = 144;//javax.sound.midi.ShortMessage.NOTE_ON;
     73 		midiChannel = 1;
     74 		midiTrack = 0;
     75 		salience = 0;
     76 	} // constructor
     77 
     78 	public Event clone() {
     79 		return new Event(keyDown, keyUp, pedalUp, midiPitch, midiVelocity,
     80 					scoreBeat, scoreDuration, flags, midiCommand, midiChannel,
     81 					midiTrack);
     82 	} // clone()
     83 
     84 	// Interface Comparable
     85 	public int compareTo(Event e) {
     86 		return (int)Math.signum(keyDown - e.keyDown);
     87 	} // compareTo()
     88 
     89 	public String toString() {
     90 		return "n=" + midiPitch + " v=" + midiVelocity + " t=" + keyDown +
     91 				" to " + keyUp + " (" + pedalUp + ")";
     92 	} // toString()
     93 
     94 	public void print(Flags f) {
     95 		System.out.printf("Event:\n");
     96 		System.out.printf("\tkeyDown / Up / pedalUp: %5.3f / %5.3f /  %5.3f\n",
     97 			keyDown, keyUp, pedalUp);
     98 		//System.out.printf("\tkeyUp: %5.3f\n", keyUp);
     99 		//System.out.printf("\tpedalUp: %5.3f\n", pedalUp);
    100 		System.out.printf("\tmidiPitch: %d\n", midiPitch);
    101 		System.out.printf("\tmidiVelocity: %d\n", midiVelocity);
    102 		System.out.printf("\tmidiCommand: %02x\t", midiCommand | midiChannel);
    103 		//System.out.printf("\tmidiChannel: %d\n", midiChannel);
    104 		System.out.printf("\tmidiTrack: %d\n", midiTrack);
    105 		System.out.printf("\tsalience: %5.3f\t", salience);
    106 		System.out.printf("\tscoreBeat: %5.3f\t", scoreBeat);
    107 		System.out.printf("\tscoreDuration: %5.3f\n", scoreDuration);
    108 		System.out.printf("\tflags: %X", flags);
    109 		if (f != null) {
    110 			int ff = flags;
    111 			for (int i=0; ff != 0; i++) {
    112 				if (ff % 2 == 1)
    113 					System.out.print(" " + f.getLabel(i));
    114 				ff >>>= 1;
    115 			}
    116 		}
    117 		System.out.print("\n\n");
    118 	} // print()
    119 
    120 } // class Event