1 /*
   2  * Copyright (c) 2007, 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 SoftReceiver send method */
  26 
  27 import javax.sound.midi.*;
  28 import javax.sound.sampled.*;
  29 
  30 import com.sun.media.sound.*;
  31 
  32 public class Send_ResetAllControllers {
  33 
  34     public static boolean[] dontResetControls = new boolean[128];
  35     static {
  36         for (int i = 0; i < dontResetControls.length; i++)
  37             dontResetControls[i] = false;
  38 
  39         dontResetControls[0] = true;   // Bank Select (MSB)
  40         dontResetControls[32] = true;  // Bank Select (LSB)
  41         dontResetControls[7] = true;   // Channel Volume (MSB)
  42         dontResetControls[8] = true;   // Balance (MSB)
  43         dontResetControls[10] = true;  // Pan (MSB)
  44         dontResetControls[11] = true;  // Expression (MSB)
  45         dontResetControls[91] = true;  // Effects 1 Depth (default: Reverb Send)
  46         dontResetControls[92] = true;  // Effects 2 Depth (default: Tremolo Depth)
  47         dontResetControls[93] = true;  // Effects 3 Depth (default: Chorus Send)
  48         dontResetControls[94] = true;  // Effects 4 Depth (default: Celeste [Detune] Depth)
  49         dontResetControls[95] = true;  // Effects 5 Depth (default: Phaser Depth)
  50         dontResetControls[70] = true;  // Sound Controller 1 (default: Sound Variation)
  51         dontResetControls[71] = true;  // Sound Controller 2 (default: Timbre / Harmonic Quality)
  52         dontResetControls[72] = true;  // Sound Controller 3 (default: Release Time)
  53         dontResetControls[73] = true;  // Sound Controller 4 (default: Attack Time)
  54         dontResetControls[74] = true;  // Sound Controller 5 (default: Brightness)
  55         dontResetControls[75] = true;  // Sound Controller 6 (GM2 default: Decay Time)
  56         dontResetControls[76] = true;  // Sound Controller 7 (GM2 default: Vibrato Rate)
  57         dontResetControls[77] = true;  // Sound Controller 8 (GM2 default: Vibrato Depth)
  58         dontResetControls[78] = true;  // Sound Controller 9 (GM2 default: Vibrato Delay)
  59         dontResetControls[79] = true;  // Sound Controller 10 (GM2 default: Undefined)
  60         dontResetControls[120] = true; // All Sound Off
  61         dontResetControls[121] = true; // Reset All Controllers
  62         dontResetControls[122] = true; // Local Control On/Off
  63         dontResetControls[123] = true; // All Notes Off
  64         dontResetControls[124] = true; // Omni Mode Off
  65         dontResetControls[125] = true; // Omni Mode On
  66         dontResetControls[126] = true; // Poly Mode Off
  67         dontResetControls[127] = true; // Poly Mode On
  68 
  69         dontResetControls[6] = true;   // Data Entry (MSB)
  70         dontResetControls[38] = true;  // Data Entry (LSB)
  71         dontResetControls[96] = true;  // Data Increment
  72         dontResetControls[97] = true;  // Data Decrement
  73         dontResetControls[98] = true;  // Non-Registered Parameter Number (LSB)
  74         dontResetControls[99] = true;  // Non-Registered Parameter Number(MSB)
  75         dontResetControls[100] = true; // RPN = Null
  76         dontResetControls[101] = true; // RPN = Null
  77     }
  78 
  79     private static void assertEquals(Object a, Object b) throws Exception
  80     {
  81         if(!a.equals(b))
  82             throw new RuntimeException("assertEquals fails!");
  83     }
  84 
  85     private static void assertTrue(boolean value) throws Exception
  86     {
  87         if(!value)
  88             throw new RuntimeException("assertTrue fails!");
  89     }
  90 
  91     public static void main(String[] args) throws Exception {
  92         SoftTestUtils soft = new SoftTestUtils();
  93         MidiChannel channel = soft.synth.getChannels()[0];
  94         Receiver receiver = soft.synth.getReceiver();
  95 
  96         // First let all controls contain non-default values
  97         for (int i = 0; i < 128; i++)
  98             channel.setPolyPressure(i, 10);
  99         channel.setChannelPressure(10);
 100         channel.setPitchBend(2192);
 101         for (int i = 0; i < 120; i++)
 102             channel.controlChange(i, 1);
 103 
 104         ShortMessage smsg = new ShortMessage();
 105         smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 121,0);
 106         receiver.send(smsg, -1);
 107 
 108         // Now check if resetAllControllers did what it was suppose to do
 109 
 110         for (int i = 0; i < 128; i++)
 111             assertEquals(channel.getPolyPressure(i), 0);
 112         assertEquals(channel.getChannelPressure(), 0);
 113         assertEquals(channel.getPitchBend(),8192);
 114         for (int i = 0; i < 120; i++)
 115             if(!dontResetControls[i])
 116                 assertEquals(channel.getController(i), 0);
 117         assertEquals(channel.getController(71), 64); // Filter Resonance
 118         assertEquals(channel.getController(72), 64); // Release Time
 119         assertEquals(channel.getController(73), 64); // Attack Time
 120         assertEquals(channel.getController(74), 64); // Brightness
 121         assertEquals(channel.getController(75), 64); // Decay Time
 122         assertEquals(channel.getController(76), 64); // Vibrato Rate
 123         assertEquals(channel.getController(77), 64); // Vibrato Depth
 124         assertEquals(channel.getController(78), 64); // Vibrato Delay
 125         assertEquals(channel.getController(8), 64); // Balance
 126         assertEquals(channel.getController(11), 127); // Expression
 127         assertEquals(channel.getController(98), 127); // NRPN Null
 128         assertEquals(channel.getController(99), 127); // NRPN Null
 129         assertEquals(channel.getController(100), 127); // RPN = Null
 130         assertEquals(channel.getController(101), 127); // RPN = Null
 131 
 132         soft.close();
 133     }
 134 }