< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/SoftChannel.java

Print this page

        

@@ -20,10 +20,11 @@
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package com.sun.media.sound;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;

@@ -39,11 +40,11 @@
  *
  * @author Karl Helgason
  */
 public final class SoftChannel implements MidiChannel, ModelDirectedPlayer {
 
-    private static boolean[] dontResetControls = new boolean[128];
+    private static final boolean[] dontResetControls = new boolean[128];
     static {
         for (int i = 0; i < dontResetControls.length; i++)
             dontResetControls[i] = false;
 
         dontResetControls[0] = true;   // Bank Select (MSB)

@@ -97,22 +98,22 @@
     private boolean mono = false;
     private boolean mute = false;
     private boolean solo = false;
     private boolean solomute = false;
     private final Object control_mutex;
-    private int channel;
-    private SoftVoice[] voices;
+    private final int channel;
+    private final SoftVoice[] voices;
     private int bank;
     private int program;
-    private SoftSynthesizer synthesizer;
-    private SoftMainMixer mainmixer;
-    private int[] polypressure = new int[128];
+    private final SoftSynthesizer synthesizer;
+    private final SoftMainMixer mainmixer;
+    private final int[] polypressure = new int[128];
     private int channelpressure = 0;
-    private int[] controller = new int[128];
+    private final int[] controller = new int[128];
     private int pitchbend;
-    private double[] co_midi_pitch = new double[1];
-    private double[] co_midi_channel_pressure = new double[1];
+    private final double[] co_midi_pitch = new double[1];
+    private final double[] co_midi_channel_pressure = new double[1];
     SoftTuning tuning = new SoftTuning();
     int tuning_bank = 0;
     int tuning_program = 0;
     SoftInstrument current_instrument = null;
     ModelChannelMixer current_mixer = null;

@@ -130,10 +131,11 @@
     private class MidiControlObject implements SoftControl {
         double[] pitch = co_midi_pitch;
         double[] channel_pressure = co_midi_channel_pressure;
         double[] poly_pressure = new double[1];
 
+        @Override
         public double[] get(int instance, String name) {
             if (name == null)
                 return null;
             if (name.equals("pitch"))
                 return pitch;

@@ -143,30 +145,32 @@
                 return poly_pressure;
             return null;
         }
     }
 
-    private SoftControl[] co_midi = new SoftControl[128];
+    private final SoftControl[] co_midi = new SoftControl[128];
     {
         for (int i = 0; i < co_midi.length; i++) {
             co_midi[i] = new MidiControlObject();
         }
     }
 
-    private double[][] co_midi_cc_cc = new double[128][1];
-    private SoftControl co_midi_cc = new SoftControl() {
+    private final double[][] co_midi_cc_cc = new double[128][1];
+    private final SoftControl co_midi_cc = new SoftControl() {
         double[][] cc = co_midi_cc_cc;
+        @Override
         public double[] get(int instance, String name) {
             if (name == null)
                 return null;
             return cc[Integer.parseInt(name)];
         }
     };
-    Map<Integer, int[]> co_midi_rpn_rpn_i = new HashMap<Integer, int[]>();
-    Map<Integer, double[]> co_midi_rpn_rpn = new HashMap<Integer, double[]>();
-    private SoftControl co_midi_rpn = new SoftControl() {
+    Map<Integer, int[]> co_midi_rpn_rpn_i = new HashMap<>();
+    Map<Integer, double[]> co_midi_rpn_rpn = new HashMap<>();
+    private final SoftControl co_midi_rpn = new SoftControl() {
         Map<Integer, double[]> rpn = co_midi_rpn_rpn;
+        @Override
         public double[] get(int instance, String name) {
             if (name == null)
                 return null;
             int iname = Integer.parseInt(name);
             double[] v = rpn.get(iname);

@@ -175,14 +179,15 @@
                 rpn.put(iname, v);
             }
             return v;
         }
     };
-    Map<Integer, int[]> co_midi_nrpn_nrpn_i = new HashMap<Integer, int[]>();
-    Map<Integer, double[]> co_midi_nrpn_nrpn = new HashMap<Integer, double[]>();
-    private SoftControl co_midi_nrpn = new SoftControl() {
+    Map<Integer, int[]> co_midi_nrpn_nrpn_i = new HashMap<>();
+    Map<Integer, double[]> co_midi_nrpn_nrpn = new HashMap<>();
+    private final SoftControl co_midi_nrpn = new SoftControl() {
         Map<Integer, double[]> nrpn = co_midi_nrpn_nrpn;
+        @Override
         public double[] get(int instance, String name) {
             if (name == null)
                 return null;
             int iname = Integer.parseInt(name);
             double[] v = nrpn.get(iname);

@@ -405,10 +410,11 @@
                 }
             }
         }
     }
 
+    @Override
     public void noteOn(int noteNumber, int velocity) {
         noteOn(noteNumber, velocity, 0);
     }
 
     /* A special noteOn with delay parameter, which is used to

@@ -542,10 +548,11 @@
             }
             */
         }
     }
 
+    @Override
     public void noteOff(int noteNumber, int velocity) {
         noteNumber = restrict7Bit(noteNumber);
         velocity = restrict7Bit(velocity);
         noteOff_internal(noteNumber, velocity);
 

@@ -614,19 +621,20 @@
             play_delay = 0;
             current_director.noteOff(tunedKey, velocity);
 
         }
     }
-    private int[] lastVelocity = new int[128];
+    private final int[] lastVelocity = new int[128];
     private int prevVoiceID;
     private boolean firstVoice = true;
     private int voiceNo = 0;
     private int play_noteNumber = 0;
     private int play_velocity = 0;
     private int play_delay = 0;
     private boolean play_releasetriggered = false;
 
+    @Override
     public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) {
 
         int noteNumber = play_noteNumber;
         int velocity = play_velocity;
         int delay = play_delay;

@@ -655,15 +663,17 @@
 
         initVoice(voices[voiceNo], p, prevVoiceID, noteNumber, velocity, delay,
                 connectionBlocks, current_mixer, releasetriggered);
     }
 
+    @Override
     public void noteOff(int noteNumber) {
         if(noteNumber < 0 || noteNumber > 127) return;
         noteOff_internal(noteNumber, 64);
     }
 
+    @Override
     public void setPolyPressure(int noteNumber, int pressure) {
         noteNumber = restrict7Bit(noteNumber);
         pressure = restrict7Bit(pressure);
 
         if (current_mixer != null)

@@ -678,16 +688,18 @@
                     voices[i].setPolyPressure(pressure);
             }
         }
     }
 
+    @Override
     public int getPolyPressure(int noteNumber) {
         synchronized (control_mutex) {
             return polypressure[noteNumber];
         }
     }
 
+    @Override
     public void setChannelPressure(int pressure) {
         pressure = restrict7Bit(pressure);
         if (current_mixer != null)
             current_mixer.setChannelPressure(pressure);
         synchronized (control_mutex) {

@@ -699,10 +711,11 @@
                     voices[i].setChannelPressure(pressure);
             }
         }
     }
 
+    @Override
     public int getChannelPressure() {
         synchronized (control_mutex) {
             return channelpressure;
         }
     }

@@ -821,11 +834,11 @@
         03 LFO Pitch Depth       | 00H..7FH | 0..600 cents            |  0
         04 LFO Filter Depth      | 00H..7FH | 0..2400 cents           |  0
         05 LFO Amplitude Depth   | 00H..7FH | 0..100 percent          |  0
         */
 
-        List<ModelConnectionBlock> conns = new ArrayList<ModelConnectionBlock>();
+        List<ModelConnectionBlock> conns = new ArrayList<>();
 
         for (int i = 0; i < destination.length; i++) {
             int d = destination[i];
             int r = range[i];
             if (d == 0) {

@@ -867,10 +880,11 @@
             }
             if (d == 2) {
                 final double scale = (r / 64.0);
                 ModelTransform mt = new ModelTransform() {
                     double s = scale;
+                    @Override
                     public double transform(double value) {
                         if (s < 1)
                             value = s + (value * (1.0 - s));
                         else if (s > 1)
                             value = 1 + (value * (s - 1.0));

@@ -921,10 +935,11 @@
             if (d == 5) {
                 final double scale = (r / 127.0);
 
                 ModelTransform mt = new ModelTransform() {
                     double s = scale;
+                    @Override
                     public double transform(double value) {
                         return -((5.0 / 12.0) / Math.log(10))
                                 * Math.log(1 - value * s);
                     }
                 };

@@ -1053,10 +1068,11 @@
         if (!keybasedcontroller_active[noteNumber][controller])
             return -1;
         return (int)(keybasedcontroller_value[noteNumber][controller] * 128);
     }
 
+    @Override
     public void controlChange(int controller, int value) {
         controller = restrict7Bit(controller);
         value = restrict7Bit(value);
         if (current_mixer != null)
             current_mixer.controlChange(controller, value);

@@ -1239,10 +1255,11 @@
                     voices[i].controlChange(controller, value);
 
         }
     }
 
+    @Override
     public int getController(int controller) {
         synchronized (control_mutex) {
             // Should only return lower 7 bits,
             // even when controller is "boosted" higher.
             return this.controller[controller] & 127;

@@ -1257,14 +1274,16 @@
         synchronized (control_mutex) {
             tuning = synthesizer.getTuning(new Patch(bank, program));
         }
     }
 
+    @Override
     public void programChange(int program) {
         programChange(bank, program);
     }
 
+    @Override
     public void programChange(int bank, int program) {
         bank = restrict14Bit(bank);
         program = restrict7Bit(program);
         synchronized (control_mutex) {
             mainmixer.activity();

@@ -1275,16 +1294,18 @@
                 current_instrument = null;
             }
         }
     }
 
+    @Override
     public int getProgram() {
         synchronized (control_mutex) {
             return program;
         }
     }
 
+    @Override
     public void setPitchBend(int bend) {
         bend = restrict14Bit(bend);
         if (current_mixer != null)
             current_mixer.setPitchBend(bend);
         synchronized (control_mutex) {

@@ -1295,10 +1316,11 @@
                 if (voices[i].active)
                     voices[i].setPitchBend(bend);
         }
     }
 
+    @Override
     public int getPitchBend() {
         synchronized (control_mutex) {
             return pitchbend;
         }
     }

@@ -1396,10 +1418,11 @@
         for (int i = 0; i < voices.length; i++)
             if (voices[i].active)
                 voices[i].rpnChange(controller, val_i[0]);
     }
 
+    @Override
     public void resetAllControllers() {
         resetAllControllers(false);
     }
 
     public void resetAllControllers(boolean allControls) {

@@ -1461,10 +1484,11 @@
             }
 
         }
     }
 
+    @Override
     public void allNotesOff() {
         if (current_mixer != null)
             current_mixer.allNotesOff();
         synchronized (control_mutex) {
             for (int i = 0; i < voices.length; i++)

@@ -1473,50 +1497,57 @@
                     voices[i].noteOff(0);
                 }
         }
     }
 
+    @Override
     public void allSoundOff() {
         if (current_mixer != null)
             current_mixer.allSoundOff();
         synchronized (control_mutex) {
             for (int i = 0; i < voices.length; i++)
                 if (voices[i].on && voices[i].channel == channel)
                     voices[i].soundOff();
         }
     }
 
+    @Override
     public boolean localControl(boolean on) {
         return false;
     }
 
+    @Override
     public void setMono(boolean on) {
         if (current_mixer != null)
             current_mixer.setMono(on);
         synchronized (control_mutex) {
             allNotesOff();
             mono = on;
         }
     }
 
+    @Override
     public boolean getMono() {
         synchronized (control_mutex) {
             return mono;
         }
     }
 
+    @Override
     public void setOmni(boolean on) {
         if (current_mixer != null)
             current_mixer.setOmni(on);
         allNotesOff();
     // Omni is not supported by GM2
     }
 
+    @Override
     public boolean getOmni() {
         return false;
     }
 
+    @Override
     public void setMute(boolean mute) {
         if (current_mixer != null)
             current_mixer.setMute(mute);
         synchronized (control_mutex) {
             this.mute = mute;

@@ -1524,16 +1555,18 @@
                 if (voices[i].active && voices[i].channel == channel)
                     voices[i].setMute(mute);
         }
     }
 
+    @Override
     public boolean getMute() {
         synchronized (control_mutex) {
             return mute;
         }
     }
 
+    @Override
     public void setSolo(boolean soloState) {
         if (current_mixer != null)
             current_mixer.setSolo(soloState);
 
         synchronized (control_mutex) {

@@ -1569,10 +1602,11 @@
                 if (voices[i].active && voices[i].channel == channel)
                     voices[i].setSoloMute(solomute);
         }
     }
 
+    @Override
     public boolean getSolo() {
         synchronized (control_mutex) {
             return solo;
         }
     }
< prev index next >