Load7.java revision 829:b06c29386f63
194742Sobrien/*
294742Sobrien * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
394742Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
495253Sru *
594742Sobrien * This code is free software; you can redistribute it and/or modify it
694772Simp * under the terms of the GNU General Public License version 2 only, as
794772Simp * published by the Free Software Foundation.  Sun designates this
896991Srwatson * particular file as subject to the "Classpath" exception as provided
996991Srwatson * by Sun in the LICENSE file that accompanied this code.
1096991Srwatson *
11102773Srwatson * This code is distributed in the hope that it will be useful, but WITHOUT
12102773Srwatson * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1394854Ssos * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1494917Simp * version 2 for more details (a copy is included in the LICENSE file that
1594917Simp * accompanied this code).
1694917Simp *
1794917Simp * You should have received a copy of the GNU General Public License version
1894845Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
1994845Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2094845Smarkm *
2195382Srnordier * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2294847Sjhb * CA 95054 USA or visit www.sun.com if you need additional information or
2394847Sjhb * have any questions.
2494847Sjhb */
2594849Sphk
2694849Sphk/* @test
2794849Sphk   @summary Test SoftTuning load method */
2894849Sphk
2994849Sphkimport javax.sound.midi.MidiUnavailableException;
3094849Sphkimport javax.sound.midi.Patch;
3194849Sphkimport javax.sound.sampled.*;
3294855Sscottl
3394855Sscottlimport com.sun.media.sound.*;
3494902Sbenno
3594915Skenpublic class Load7 {
3699607Smjacob
3794915Sken    private static void assertEquals(Object a, Object b) throws Exception
3894915Sken    {
3994915Sken        if(!a.equals(b))
4094915Sken            throw new RuntimeException("assertEquals fails!");
4194915Sken    }
42105411Snjl
4394915Sken    private static void assertTrue(boolean value) throws Exception
4494915Sken    {
4594915Sken        if(!value)
4699607Smjacob            throw new RuntimeException("assertTrue fails!");
4799607Smjacob    }
4897611Sbillf
4994918Sgshapiro    public static void main(String[] args) throws Exception {
5094918Sgshapiro        // http://www.midi.org/about-midi/tuning_extens.shtml
5194918Sgshapiro        // 0x07 SINGLE NOTE TUNING CHANGE (NON REAL-TIME) (BANK)
5294918Sgshapiro        SoftTuning tuning = new SoftTuning();
5394918Sgshapiro        int[] msg = {0xf0,0x7f,0x7f,0x08,0x07,0x00,0x00,0x02,
5494955Smurray                36,36,64,0,
5594955Smurray                40,70,0,0,
5695054Snectar                0xf7};
5795455Sdes        byte[] bmsg = new byte[msg.length];
5898750Sdes        for (int i = 0; i < bmsg.length; i++)
5999606Sdes            bmsg[i] = (byte)msg[i];
6099606Sdes        tuning.load(bmsg);
6199606Sdes        double[] tunings = tuning.getTuning();
6296268Sgad        for (int i = 0; i < tunings.length; i++) {
6396268Sgad            if(i == 36)
6496268Sgad                assertTrue(Math.abs(tunings[i]-3650)< 0.00001);
6596301Sgrog            else if(i == 40)
6696332Speter                assertTrue(Math.abs(tunings[i]-7000) < 0.00001);
6796332Speter            else
6896332Speter                assertTrue(Math.abs(tunings[i]-i*100) < 0.00001);
6996332Speter        }
7096332Speter
71100314Sru    }
72100314Sru}
7396451Sru