1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
369 setTempoInMPQ((float) MidiUtils.convertTempo((double) bpm));
370 }
371
372
373 public float getTempoInMPQ() {
374 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTempoInMPQ() ");
375
376 if (needCaching()) {
377 // if the sequencer is closed, return cached value
378 if (cacheTempoMPQ != -1) {
379 return (float) cacheTempoMPQ;
380 }
381 // if sequence is set, return current tempo
382 if (sequence != null) {
383 return tempoCache.getTempoMPQAt(getTickPosition());
384 }
385
386 // last resort: return a standard tempo: 120bpm
387 return (float) MidiUtils.DEFAULT_TEMPO_MPQ;
388 }
389 return (float)getDataPump().getTempoMPQ();
390 }
391
392
393 public void setTempoInMPQ(float mpq) {
394 if (mpq <= 0) {
395 // should throw IllegalArgumentException
396 mpq = 1.0f;
397 }
398
399 if (Printer.trace) Printer.trace(">> RealTimeSequencer: setTempoInMPQ() ");
400
401 if (needCaching()) {
402 // cache the value
403 cacheTempoMPQ = mpq;
404 } else {
405 // set the native tempo in MPQ
406 getDataPump().setTempoMPQ(mpq);
407
408 // reset the tempoInBPM and tempoInMPQ values so we won't use them again
409 cacheTempoMPQ = -1;
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
369 setTempoInMPQ((float) MidiUtils.convertTempo((double) bpm));
370 }
371
372
373 public float getTempoInMPQ() {
374 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTempoInMPQ() ");
375
376 if (needCaching()) {
377 // if the sequencer is closed, return cached value
378 if (cacheTempoMPQ != -1) {
379 return (float) cacheTempoMPQ;
380 }
381 // if sequence is set, return current tempo
382 if (sequence != null) {
383 return tempoCache.getTempoMPQAt(getTickPosition());
384 }
385
386 // last resort: return a standard tempo: 120bpm
387 return (float) MidiUtils.DEFAULT_TEMPO_MPQ;
388 }
389 return getDataPump().getTempoMPQ();
390 }
391
392
393 public void setTempoInMPQ(float mpq) {
394 if (mpq <= 0) {
395 // should throw IllegalArgumentException
396 mpq = 1.0f;
397 }
398
399 if (Printer.trace) Printer.trace(">> RealTimeSequencer: setTempoInMPQ() ");
400
401 if (needCaching()) {
402 // cache the value
403 cacheTempoMPQ = mpq;
404 } else {
405 // set the native tempo in MPQ
406 getDataPump().setTempoMPQ(mpq);
407
408 // reset the tempoInBPM and tempoInMPQ values so we won't use them again
409 cacheTempoMPQ = -1;
|