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 ConstantTempoMap implements TempoMap { Chris@2: Chris@2: protected double interBeatInterval; Chris@2: Chris@2: public ConstantTempoMap(double bpm) { Chris@2: interBeatInterval = 60 / bpm; Chris@2: } // constructor Chris@2: Chris@2: public ConstantTempoMap() { Chris@2: this(120); Chris@2: } // default constructor Chris@2: Chris@2: public void add(double time, double tempo) { Chris@2: throw new RuntimeException("ConstantTempoMap: cannot change tempo"); Chris@2: } // add() Chris@2: Chris@2: public double toRealTime(double value) { Chris@2: return value * interBeatInterval; Chris@2: } // toRealTime() Chris@2: Chris@2: public double toScoreTime(double value) { Chris@2: return value / interBeatInterval; Chris@2: } // toScoreTime() Chris@2: Chris@2: public static void main(String[] args) { // unit test Chris@2: TempoMap mtm = new ConstantTempoMap(100); Chris@2: System.out.println(mtm.toRealTime(1)); Chris@2: System.out.println(mtm.toScoreTime(mtm.toRealTime(1))); Chris@2: System.out.println(mtm.toScoreTime(4)); Chris@2: System.out.println(mtm.toRealTime(mtm.toScoreTime(4))); Chris@2: mtm.add(5, 120); Chris@2: } // main() Chris@2: Chris@2: } // ConstantTempoMap