SequencerCacheValues.java revision 16009:5445b9413d9d
1275732Sjmg/* 2275732Sjmg * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. 3275732Sjmg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4275732Sjmg * 5275732Sjmg * This code is free software; you can redistribute it and/or modify it 6275732Sjmg * under the terms of the GNU General Public License version 2 only, as 7275732Sjmg * published by the Free Software Foundation. 8275732Sjmg * 9275732Sjmg * This code is distributed in the hope that it will be useful, but WITHOUT 10275732Sjmg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11275732Sjmg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12275732Sjmg * version 2 for more details (a copy is included in the LICENSE file that 13275732Sjmg * accompanied this code). 14275732Sjmg * 15275732Sjmg * You should have received a copy of the GNU General Public License version 16275732Sjmg * 2 along with this work; if not, write to the Free Software Foundation, 17275732Sjmg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18275732Sjmg * 19275732Sjmg * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20275732Sjmg * or visit www.oracle.com if you need additional information or have any 21275732Sjmg * questions. 22275732Sjmg */ 23275732Sjmg 24275732Sjmgimport javax.sound.midi.MidiDevice; 25275732Sjmgimport javax.sound.midi.MidiSystem; 26275732Sjmgimport javax.sound.midi.MidiUnavailableException; 27275732Sjmgimport javax.sound.midi.Sequencer; 28275732Sjmg 29275732Sjmg/** 30275732Sjmg * @test 31275732Sjmg * @bug 4716740 32275732Sjmg * @summary default sequencer does not set the tempo factor 33275732Sjmg */ 34275732Sjmgpublic class SequencerCacheValues { 35275732Sjmg 36275732Sjmg static boolean failed = false; 37275732Sjmg 38275732Sjmg public static void main(String args[]) throws Exception { 39275732Sjmg Sequencer seq = null; 40275732Sjmg int totalNumberOfSequencers = 0; 41275732Sjmg 42275732Sjmg MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); 43275732Sjmg for (int device=0; device<infos.length; device++) { 44275732Sjmg //seq = MidiSystem.getSequencer(); 45275732Sjmg MidiDevice dev = MidiSystem.getMidiDevice(infos[device]); 46275732Sjmg if (dev instanceof Sequencer) { 47275732Sjmg seq = (Sequencer) dev; 48275732Sjmg totalNumberOfSequencers++; 49275732Sjmg System.out.println("Opening sequencer "+infos[device]); 50275732Sjmg try { 51275732Sjmg seq.open(); 52275732Sjmg try { 53275732Sjmg doTest(seq); 54275732Sjmg } finally { 55275732Sjmg if (seq != null) { 56 seq.close(); 57 seq = null; 58 } 59 } 60 } catch (MidiUnavailableException mue) { 61 System.err.println("MidiUnavailableException was thrown: " + mue); 62 System.err.println("could not test this sequencer."); 63 } 64 } 65 } 66 if (totalNumberOfSequencers == 0) { 67 System.out.println("No sequencers installed!"); 68 failed = true; 69 } 70 if (failed) { 71 throw new Exception("FAILED"); 72 } else { 73 System.out.println("test OK"); 74 } 75 } 76 77 public static boolean equalsFloat(float f1, float f2) { 78 return (f1-f2<0.0001) && (f2-f1<0.0001); 79 } 80 81 public static void doTest(Sequencer seq) throws Exception { 82 seq.setTempoInMPQ(3.0f); 83 System.out.println("Setting tempo in MPQ to "+3.0f); 84 if (!equalsFloat(seq.getTempoInMPQ(), 3.0f)) { 85 System.err.println("getTempoInMPQ() returns wrong value : " 86 + seq.getTempoInMPQ()); 87 failed = true; 88 } 89 90 System.out.println("Setting tempo factor to "+2.0f); 91 seq.setTempoFactor(2.0f); 92 if (!equalsFloat(seq.getTempoFactor(), 2.0f)) { 93 System.err.println("getTempoFactor() returns: " + seq.getTempoFactor()); 94 failed = true; 95 } 96 97 float bpmTempo = 120.0f; 98 System.out.println("Setting tempo to "+120.0f+"bpm"); 99 seq.setTempoInBPM(bpmTempo); 100 if (!equalsFloat(seq.getTempoInMPQ(), (60000000.0f/seq.getTempoInBPM()))) { 101 System.err.println("getTempoInMPQ() returns: " + seq.getTempoInMPQ()); 102 System.err.println("getTempoInBPM() returns: " + seq.getTempoInBPM()); 103 failed = true; 104 } 105 } 106} 107