1 /* 2 * Copyright (c) 2007, 2015, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 @summary Test SoftChannel resetAllControllers method 26 @modules java.desktop/com.sun.media.sound 27 */ 28 29 import javax.sound.midi.*; 30 import javax.sound.sampled.*; 31 32 import com.sun.media.sound.*; 33 34 public class ResetAllControllers { 35 36 public static boolean[] dontResetControls = new boolean[128]; 37 static { 38 for (int i = 0; i < dontResetControls.length; i++) 39 dontResetControls[i] = false; 40 41 dontResetControls[0] = true; // Bank Select (MSB) 42 dontResetControls[32] = true; // Bank Select (LSB) 43 dontResetControls[7] = true; // Channel Volume (MSB) 44 dontResetControls[8] = true; // Balance (MSB) 45 dontResetControls[10] = true; // Pan (MSB) 46 dontResetControls[11] = true; // Expression (MSB) 47 dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send) 48 dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth) 49 dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send) 50 dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth) 51 dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth) 52 dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation) 53 dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality) 54 dontResetControls[72] = true; // Sound Controller 3 (default: Release Time) 55 dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time) 56 dontResetControls[74] = true; // Sound Controller 5 (default: Brightness) 57 dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time) 58 dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate) 59 dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth) 60 dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay) 61 dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined) 62 dontResetControls[120] = true; // All Sound Off 63 dontResetControls[121] = true; // Reset All Controllers 64 dontResetControls[122] = true; // Local Control On/Off 65 dontResetControls[123] = true; // All Notes Off 66 dontResetControls[124] = true; // Omni Mode Off 67 dontResetControls[125] = true; // Omni Mode On 68 dontResetControls[126] = true; // Poly Mode Off 69 dontResetControls[127] = true; // Poly Mode On 70 71 dontResetControls[6] = true; // Data Entry (MSB) 72 dontResetControls[38] = true; // Data Entry (LSB) 73 dontResetControls[96] = true; // Data Increment 74 dontResetControls[97] = true; // Data Decrement 75 dontResetControls[98] = true; // Non-Registered Parameter Number (LSB) 76 dontResetControls[99] = true; // Non-Registered Parameter Number(MSB) 77 dontResetControls[100] = true; // RPN = Null 78 dontResetControls[101] = true; // RPN = Null 79 } 80 81 private static void assertEquals(Object a, Object b) throws Exception 82 { 83 if(!a.equals(b)) 84 throw new RuntimeException("assertEquals fails!"); 85 } 86 87 private static void assertTrue(boolean value) throws Exception 88 { 89 if(!value) 90 throw new RuntimeException("assertTrue fails!"); 91 } 92 93 public static void main(String[] args) throws Exception { 94 SoftTestUtils soft = new SoftTestUtils(); 95 MidiChannel channel = soft.synth.getChannels()[0]; 96 97 // First let all controls contain non-default values 98 for (int i = 0; i < 128; i++) 99 channel.setPolyPressure(i, 10); 100 channel.setChannelPressure(10); 101 channel.setPitchBend(2192); 102 for (int i = 0; i < 120; i++) 103 channel.controlChange(i, 1); 104 channel.resetAllControllers(); 105 106 // Now check if resetAllControllers did what it was suppose to do 107 108 for (int i = 0; i < 128; i++) 109 assertEquals(channel.getPolyPressure(i), 0); 110 assertEquals(channel.getChannelPressure(), 0); 111 assertEquals(channel.getPitchBend(),8192); 112 for (int i = 0; i < 120; i++) 113 if(!dontResetControls[i]) 114 assertEquals(channel.getController(i), 0); 115 assertEquals(channel.getController(71), 64); // Filter Resonance 116 assertEquals(channel.getController(72), 64); // Release Time 117 assertEquals(channel.getController(73), 64); // Attack Time 118 assertEquals(channel.getController(74), 64); // Brightness 119 assertEquals(channel.getController(75), 64); // Decay Time 120 assertEquals(channel.getController(76), 64); // Vibrato Rate 121 assertEquals(channel.getController(77), 64); // Vibrato Depth 122 assertEquals(channel.getController(78), 64); // Vibrato Delay 123 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 }