829N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
829N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
829N/A *
829N/A * This code is free software; you can redistribute it and/or modify it
829N/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
829N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
829N/A *
829N/A * This code is distributed in the hope that it will be useful, but WITHOUT
829N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
829N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
829N/A * version 2 for more details (a copy is included in the LICENSE file that
829N/A * accompanied this code).
829N/A *
829N/A * You should have received a copy of the GNU General Public License version
829N/A * 2 along with this work; if not, write to the Free Software Foundation,
829N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
829N/A *
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
2362N/A * questions.
829N/A */
829N/A
829N/A/* @test
829N/A @summary Test SoftReceiver send method */
829N/A
829N/Aimport javax.sound.midi.*;
829N/Aimport javax.sound.sampled.*;
829N/A
829N/Aimport com.sun.media.sound.*;
829N/A
829N/Apublic class Send_ResetAllControllers {
829N/A
829N/A public static boolean[] dontResetControls = new boolean[128];
829N/A static {
829N/A for (int i = 0; i < dontResetControls.length; i++)
829N/A dontResetControls[i] = false;
829N/A
829N/A dontResetControls[0] = true; // Bank Select (MSB)
829N/A dontResetControls[32] = true; // Bank Select (LSB)
829N/A dontResetControls[7] = true; // Channel Volume (MSB)
829N/A dontResetControls[8] = true; // Balance (MSB)
829N/A dontResetControls[10] = true; // Pan (MSB)
829N/A dontResetControls[11] = true; // Expression (MSB)
829N/A dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send)
829N/A dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth)
829N/A dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send)
829N/A dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth)
829N/A dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth)
829N/A dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation)
829N/A dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality)
829N/A dontResetControls[72] = true; // Sound Controller 3 (default: Release Time)
829N/A dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time)
829N/A dontResetControls[74] = true; // Sound Controller 5 (default: Brightness)
829N/A dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time)
829N/A dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate)
829N/A dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth)
829N/A dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay)
829N/A dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined)
829N/A dontResetControls[120] = true; // All Sound Off
829N/A dontResetControls[121] = true; // Reset All Controllers
829N/A dontResetControls[122] = true; // Local Control On/Off
829N/A dontResetControls[123] = true; // All Notes Off
829N/A dontResetControls[124] = true; // Omni Mode Off
829N/A dontResetControls[125] = true; // Omni Mode On
829N/A dontResetControls[126] = true; // Poly Mode Off
829N/A dontResetControls[127] = true; // Poly Mode On
829N/A
829N/A dontResetControls[6] = true; // Data Entry (MSB)
829N/A dontResetControls[38] = true; // Data Entry (LSB)
829N/A dontResetControls[96] = true; // Data Increment
829N/A dontResetControls[97] = true; // Data Decrement
829N/A dontResetControls[98] = true; // Non-Registered Parameter Number (LSB)
829N/A dontResetControls[99] = true; // Non-Registered Parameter Number(MSB)
829N/A dontResetControls[100] = true; // RPN = Null
829N/A dontResetControls[101] = true; // RPN = Null
829N/A }
829N/A
829N/A private static void assertEquals(Object a, Object b) throws Exception
829N/A {
829N/A if(!a.equals(b))
829N/A throw new RuntimeException("assertEquals fails!");
829N/A }
829N/A
829N/A private static void assertTrue(boolean value) throws Exception
829N/A {
829N/A if(!value)
829N/A throw new RuntimeException("assertTrue fails!");
829N/A }
829N/A
829N/A public static void main(String[] args) throws Exception {
829N/A SoftTestUtils soft = new SoftTestUtils();
829N/A MidiChannel channel = soft.synth.getChannels()[0];
829N/A Receiver receiver = soft.synth.getReceiver();
829N/A
829N/A // First let all controls contain non-default values
829N/A for (int i = 0; i < 128; i++)
829N/A channel.setPolyPressure(i, 10);
829N/A channel.setChannelPressure(10);
829N/A channel.setPitchBend(2192);
829N/A for (int i = 0; i < 120; i++)
829N/A channel.controlChange(i, 1);
829N/A
829N/A ShortMessage smsg = new ShortMessage();
829N/A smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 121,0);
829N/A receiver.send(smsg, -1);
829N/A
829N/A // Now check if resetAllControllers did what it was suppose to do
829N/A
829N/A for (int i = 0; i < 128; i++)
829N/A assertEquals(channel.getPolyPressure(i), 0);
829N/A assertEquals(channel.getChannelPressure(), 0);
829N/A assertEquals(channel.getPitchBend(),8192);
829N/A for (int i = 0; i < 120; i++)
829N/A if(!dontResetControls[i])
829N/A assertEquals(channel.getController(i), 0);
829N/A assertEquals(channel.getController(71), 64); // Filter Resonance
829N/A assertEquals(channel.getController(72), 64); // Release Time
829N/A assertEquals(channel.getController(73), 64); // Attack Time
829N/A assertEquals(channel.getController(74), 64); // Brightness
829N/A assertEquals(channel.getController(75), 64); // Decay Time
829N/A assertEquals(channel.getController(76), 64); // Vibrato Rate
829N/A assertEquals(channel.getController(77), 64); // Vibrato Depth
829N/A assertEquals(channel.getController(78), 64); // Vibrato Delay
829N/A assertEquals(channel.getController(8), 64); // Balance
829N/A assertEquals(channel.getController(11), 127); // Expression
829N/A assertEquals(channel.getController(98), 127); // NRPN Null
829N/A assertEquals(channel.getController(99), 127); // NRPN Null
829N/A assertEquals(channel.getController(100), 127); // RPN = Null
829N/A assertEquals(channel.getController(101), 127); // RPN = Null
829N/A
829N/A soft.close();
829N/A }
829N/A}