< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/SoftChannel.java
Print this page
*** 20,29 ****
--- 20,30 ----
*
* 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,49 ****
*
* @author Karl Helgason
*/
public final class SoftChannel implements MidiChannel, ModelDirectedPlayer {
! private static boolean[] dontResetControls = new boolean[128];
static {
for (int i = 0; i < dontResetControls.length; i++)
dontResetControls[i] = false;
dontResetControls[0] = true; // Bank Select (MSB)
--- 40,50 ----
*
* @author Karl Helgason
*/
public final class SoftChannel implements MidiChannel, ModelDirectedPlayer {
! 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,118 ****
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 int bank;
private int program;
! private SoftSynthesizer synthesizer;
! private SoftMainMixer mainmixer;
! private int[] polypressure = new int[128];
private int channelpressure = 0;
! private 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];
SoftTuning tuning = new SoftTuning();
int tuning_bank = 0;
int tuning_program = 0;
SoftInstrument current_instrument = null;
ModelChannelMixer current_mixer = null;
--- 98,119 ----
private boolean mono = false;
private boolean mute = false;
private boolean solo = false;
private boolean solomute = false;
private final Object control_mutex;
! private final int channel;
! private final SoftVoice[] voices;
private int bank;
private int program;
! private final SoftSynthesizer synthesizer;
! private final SoftMainMixer mainmixer;
! private final int[] polypressure = new int[128];
private int channelpressure = 0;
! private final int[] controller = new int[128];
private int pitchbend;
! 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,139 ****
--- 131,141 ----
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,172 ****
return poly_pressure;
return null;
}
}
! private 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() {
double[][] cc = co_midi_cc_cc;
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, double[]> rpn = co_midi_rpn_rpn;
public double[] get(int instance, String name) {
if (name == null)
return null;
int iname = Integer.parseInt(name);
double[] v = rpn.get(iname);
--- 145,176 ----
return poly_pressure;
return null;
}
}
! private final SoftControl[] co_midi = new SoftControl[128];
{
for (int i = 0; i < co_midi.length; i++) {
co_midi[i] = new MidiControlObject();
}
}
! 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<>();
! 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,188 ****
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, double[]> nrpn = co_midi_nrpn_nrpn;
public double[] get(int instance, String name) {
if (name == null)
return null;
int iname = Integer.parseInt(name);
double[] v = nrpn.get(iname);
--- 179,193 ----
rpn.put(iname, v);
}
return v;
}
};
! 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,414 ****
--- 410,420 ----
}
}
}
}
+ @Override
public void noteOn(int noteNumber, int velocity) {
noteOn(noteNumber, velocity, 0);
}
/* A special noteOn with delay parameter, which is used to
*** 542,551 ****
--- 548,558 ----
}
*/
}
}
+ @Override
public void noteOff(int noteNumber, int velocity) {
noteNumber = restrict7Bit(noteNumber);
velocity = restrict7Bit(velocity);
noteOff_internal(noteNumber, velocity);
*** 614,632 ****
play_delay = 0;
current_director.noteOff(tunedKey, velocity);
}
}
! private 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;
public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) {
int noteNumber = play_noteNumber;
int velocity = play_velocity;
int delay = play_delay;
--- 621,640 ----
play_delay = 0;
current_director.noteOff(tunedKey, velocity);
}
}
! 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,669 ****
--- 663,679 ----
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,693 ****
--- 688,705 ----
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,708 ****
--- 711,721 ----
voices[i].setChannelPressure(pressure);
}
}
}
+ @Override
public int getChannelPressure() {
synchronized (control_mutex) {
return channelpressure;
}
}
*** 821,831 ****
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>();
for (int i = 0; i < destination.length; i++) {
int d = destination[i];
int r = range[i];
if (d == 0) {
--- 834,844 ----
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<>();
for (int i = 0; i < destination.length; i++) {
int d = destination[i];
int r = range[i];
if (d == 0) {
*** 867,876 ****
--- 880,890 ----
}
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,930 ****
--- 935,945 ----
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,1062 ****
--- 1068,1078 ----
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,1248 ****
--- 1255,1265 ----
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,1270 ****
--- 1274,1289 ----
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,1290 ****
--- 1294,1311 ----
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,1304 ****
--- 1316,1326 ----
if (voices[i].active)
voices[i].setPitchBend(bend);
}
}
+ @Override
public int getPitchBend() {
synchronized (control_mutex) {
return pitchbend;
}
}
*** 1396,1405 ****
--- 1418,1428 ----
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,1470 ****
--- 1484,1494 ----
}
}
}
+ @Override
public void allNotesOff() {
if (current_mixer != null)
current_mixer.allNotesOff();
synchronized (control_mutex) {
for (int i = 0; i < voices.length; i++)
*** 1473,1522 ****
--- 1497,1553 ----
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,1539 ****
--- 1555,1572 ----
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,1578 ****
--- 1602,1612 ----
if (voices[i].active && voices[i].channel == channel)
voices[i].setSoloMute(solomute);
}
}
+ @Override
public boolean getSolo() {
synchronized (control_mutex) {
return solo;
}
}
< prev index next >