6321N/A * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A// - define and use a global symbolic constant for 60000000 (see convertTempo) 0N/A * Some utilities for MIDI (some stuff is used from javax.sound.midi) 0N/A * @author Florian Bomers 6321N/A * Suppresses default constructor, ensuring non-instantiability. 0N/A /** return true if the passed message is Meta End Of Track */ 0N/A // first check if it is a META message at all 0N/A // now get message and check for end of track 0N/A /** return if the given message is a meta tempo message */ 0N/A // first check if it is a META message at all 0N/A // now get message and check for tempo 0N/A // meta type must be 0x51, and data length must be 3 0N/A /** parses this message for a META tempo message and returns 0N/A * the tempo in MPQ, or -1 if this isn't a tempo message 0N/A // first check if it is a META message at all 0N/A * 1 - MPQ-Tempo to BPM tempo<br> 0N/A * 2 - BPM tempo to MPQ tempo<br> 0N/A * convert tick to microsecond with given tempo. 0N/A * Does not take tempo changes into account. 0N/A * Does not work for SMPTE timing! 0N/A * convert tempo to microsecond with given tempo 0N/A * Does not take tempo changes into account. 0N/A * Does not work for SMPTE timing! 0N/A // do not round to nearest tick 0N/A //return (long) Math.round((((double)us) * resolution) / tempoMPQ); 0N/A * Given a tick, convert to microsecond 0N/A * @param cache tempo info and current tempo 0N/A // optimization to not always go through entire list of tempo events 0N/A // walk through all tempo changes and add time for the respective blocks 0N/A long us =
0;
// microsecond 0N/A // this implementation needs a tempo event at tick 0! 0N/A * Given a microsecond time, convert to tick. 0N/A * returns tempo at the given time in cache.getCurrTempoMPQ 0N/A / ((
double)
1000000);
0N/A // walk through all tempo changes and add time for the respective blocks 0N/A // to find the right tick 0N/A // this loop requires that the first tempo Event is at time 0 0N/A //if (Printer.debug) Printer.debug(" -> convert back = " + (tick2microsecond(seq, tick, null) / 1000)+" microseconds"); 0N/A * Binary search for the event indexes of the track 0N/A * @param tick - tick number of index to be found in array 0N/A * @return index in track which is on or after "tick". 0N/A * if no entries are found that follow after tick, track.size() is returned 0N/A // take the middle event as estimate 0N/A }
else {
// if (t>tick) 0N/A // estimate too high 0N/A // microsecond at the snapshot 0N/A int currTempo;
// MPQ, used as return value for microsecond2tick 0N/A // just some defaults, to prevents weird stuff 0N/A // tempo events only occur in track 0 0N/A for (
int i =
0; i < c; i++) {
0N/A // found a tempo event. Add it to the list 0N/A // do not need to add an initial tempo event at the beginning 0N/A // add tempo 120 at beginning