ResetAllControllers.java revision 829:b06c29386f63
112099Sjoerg/* 212099Sjoerg * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 312099Sjoerg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 412099Sjoerg * 512099Sjoerg * This code is free software; you can redistribute it and/or modify it 612099Sjoerg * under the terms of the GNU General Public License version 2 only, as 712099Sjoerg * published by the Free Software Foundation. Sun designates this 812099Sjoerg * particular file as subject to the "Classpath" exception as provided 912099Sjoerg * by Sun in the LICENSE file that accompanied this code. 1012099Sjoerg * 1112099Sjoerg * This code is distributed in the hope that it will be useful, but WITHOUT 1212099Sjoerg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1312099Sjoerg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1412099Sjoerg * version 2 for more details (a copy is included in the LICENSE file that 1512099Sjoerg * accompanied this code). 1612099Sjoerg * 1712099Sjoerg * You should have received a copy of the GNU General Public License version 1812099Sjoerg * 2 along with this work; if not, write to the Free Software Foundation, 1912099Sjoerg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2012099Sjoerg * 2112099Sjoerg * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2212099Sjoerg * CA 95054 USA or visit www.sun.com if you need additional information or 2312099Sjoerg * have any questions. 2412099Sjoerg */ 2512099Sjoerg 2612099Sjoerg/* @test 2712099Sjoerg @summary Test SoftChannel resetAllControllers method */ 2812099Sjoerg 2912099Sjoergimport javax.sound.midi.*; 3012099Sjoergimport javax.sound.sampled.*; 3112099Sjoerg 3212099Sjoergimport com.sun.media.sound.*; 3312099Sjoerg 3412099Sjoergpublic class ResetAllControllers { 3512099Sjoerg 3612099Sjoerg public static boolean[] dontResetControls = new boolean[128]; 3712099Sjoerg static { 3812099Sjoerg for (int i = 0; i < dontResetControls.length; i++) 3912099Sjoerg dontResetControls[i] = false; 4012099Sjoerg 4112099Sjoerg dontResetControls[0] = true; // Bank Select (MSB) 4212099Sjoerg dontResetControls[32] = true; // Bank Select (LSB) 4312099Sjoerg dontResetControls[7] = true; // Channel Volume (MSB) 4412099Sjoerg dontResetControls[8] = true; // Balance (MSB) 4512099Sjoerg dontResetControls[10] = true; // Pan (MSB) 4612099Sjoerg dontResetControls[11] = true; // Expression (MSB) 4712099Sjoerg dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send) 4812099Sjoerg dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth) 4912099Sjoerg dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send) 5012099Sjoerg dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth) 5112099Sjoerg dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth) 5212099Sjoerg dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation) 5312099Sjoerg dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality) 5412099Sjoerg dontResetControls[72] = true; // Sound Controller 3 (default: Release Time) 5512099Sjoerg dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time) 5612099Sjoerg dontResetControls[74] = true; // Sound Controller 5 (default: Brightness) 5712099Sjoerg dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time) 5812099Sjoerg dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate) 5912099Sjoerg dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth) 6012099Sjoerg dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay) 6112099Sjoerg dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined) 6212099Sjoerg dontResetControls[120] = true; // All Sound Off 6312099Sjoerg dontResetControls[121] = true; // Reset All Controllers 6412099Sjoerg dontResetControls[122] = true; // Local Control On/Off 6512099Sjoerg dontResetControls[123] = true; // All Notes Off 6612099Sjoerg dontResetControls[124] = true; // Omni Mode Off 6712099Sjoerg dontResetControls[125] = true; // Omni Mode On 6812099Sjoerg dontResetControls[126] = true; // Poly Mode Off 6912099Sjoerg dontResetControls[127] = true; // Poly Mode On 7012099Sjoerg 7112099Sjoerg dontResetControls[6] = true; // Data Entry (MSB) 7212099Sjoerg dontResetControls[38] = true; // Data Entry (LSB) 7312099Sjoerg dontResetControls[96] = true; // Data Increment 7412099Sjoerg dontResetControls[97] = true; // Data Decrement 7512099Sjoerg dontResetControls[98] = true; // Non-Registered Parameter Number (LSB) 7612099Sjoerg dontResetControls[99] = true; // Non-Registered Parameter Number(MSB) 7712099Sjoerg dontResetControls[100] = true; // RPN = Null 7812099Sjoerg dontResetControls[101] = true; // RPN = Null 7912099Sjoerg } 8012099Sjoerg 8112099Sjoerg private static void assertEquals(Object a, Object b) throws Exception 8212099Sjoerg { 8312099Sjoerg if(!a.equals(b)) 8412099Sjoerg throw new RuntimeException("assertEquals fails!"); 8512099Sjoerg } 8612099Sjoerg 8712099Sjoerg private static void assertTrue(boolean value) throws Exception 8812099Sjoerg { 8912099Sjoerg if(!value) 9012099Sjoerg throw new RuntimeException("assertTrue fails!"); 9112099Sjoerg } 9212099Sjoerg 9312099Sjoerg public static void main(String[] args) throws Exception { 9412099Sjoerg SoftTestUtils soft = new SoftTestUtils(); 9512099Sjoerg MidiChannel channel = soft.synth.getChannels()[0]; 9612099Sjoerg 9712099Sjoerg // First let all controls contain non-default values 9812099Sjoerg for (int i = 0; i < 128; i++) 9912099Sjoerg channel.setPolyPressure(i, 10); 10012099Sjoerg channel.setChannelPressure(10); 10112099Sjoerg channel.setPitchBend(2192); 10212099Sjoerg for (int i = 0; i < 120; i++) 10312099Sjoerg channel.controlChange(i, 1); 10412099Sjoerg channel.resetAllControllers(); 10512099Sjoerg 10612099Sjoerg // Now check if resetAllControllers did what it was suppose to do 10712099Sjoerg 10812099Sjoerg for (int i = 0; i < 128; i++) 10912099Sjoerg assertEquals(channel.getPolyPressure(i), 0); 11012099Sjoerg assertEquals(channel.getChannelPressure(), 0); 11112099Sjoerg assertEquals(channel.getPitchBend(),8192); 11212099Sjoerg for (int i = 0; i < 120; i++) 11312099Sjoerg if(!dontResetControls[i]) 11412099Sjoerg assertEquals(channel.getController(i), 0); 11512099Sjoerg assertEquals(channel.getController(71), 64); // Filter Resonance 11612099Sjoerg assertEquals(channel.getController(72), 64); // Release Time 11712099Sjoerg assertEquals(channel.getController(73), 64); // Attack Time 11812099Sjoerg assertEquals(channel.getController(74), 64); // Brightness 11912099Sjoerg assertEquals(channel.getController(75), 64); // Decay Time 12012099Sjoerg assertEquals(channel.getController(76), 64); // Vibrato Rate 12112099Sjoerg assertEquals(channel.getController(77), 64); // Vibrato Depth 12212099Sjoerg assertEquals(channel.getController(78), 64); // Vibrato Delay 12312099Sjoerg assertEquals(channel.getController(8), 64); // Balance 124 assertEquals(channel.getController(11), 127); // Expression 125 assertEquals(channel.getController(98), 127); // NRPN Null 126 assertEquals(channel.getController(99), 127); // NRPN Null 127 assertEquals(channel.getController(100), 127); // RPN = Null 128 assertEquals(channel.getController(101), 127); // RPN = Null 129 130 soft.close(); 131 } 132} 133