/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*/
/**
* Software Synthesizer MIDI channel class.
*
* @author Karl Helgason
*/
static {
dontResetControls[i] = false;
}
private boolean portamento = false;
private boolean mono = false;
private boolean mute = false;
private boolean solo = false;
private boolean solomute = false;
private int channel;
private int bank;
private int program;
private int pitchbend;
// Controller Destination Settings
boolean sustain = false;
return null;
return pitch;
return channel_pressure;
return poly_pressure;
return null;
}
}
{
co_midi[i] = new MidiControlObject();
}
}
double[][] cc = co_midi_cc_cc;
return null;
}
};
return null;
if (v == null) {
v = new double[1];
}
return v;
}
};
return null;
if (v == null) {
v = new double[1];
}
return v;
}
};
{
return value;
}
{
return value;
}
this.synthesizer = synth;
resetAllControllers(true);
}
private int findFreeVoice(int x) {
if(x == -1)
{
// x = -1 means that there where no available voice
// last time we called findFreeVoice
// and it hasn't changed because no audio has been
// rendered in the meantime.
// Therefore we have to return -1.
return -1;
}
return i;
// No free voice was found, we must steal one
if (vmode == 1) {
// DLS Static Voice Allocation
// * priority ( 10, 1-9, 11-16)
// Search for channel to steal from
int steal_channel = channel;
if (steal_channel == 9) {
} else {
}
}
}
}
int voiceNo = -1;
// Search for oldest voice in off state on steal_channel
if (v == null) {
v = voices[j];
voiceNo = j;
}
v = voices[j];
voiceNo = j;
}
}
}
}
// Search for oldest voice in on state on steal_channel
if (voiceNo == -1) {
if (v == null) {
v = voices[j];
voiceNo = j;
}
v = voices[j];
voiceNo = j;
}
}
}
}
}
return voiceNo;
} else {
// Default Voice Allocation
// * Find voice that is on
// and Find voice which has lowest voiceID ( oldest voice)
// * Or find voice that is off
// and Find voice which has lowest voiceID ( oldest voice)
int voiceNo = -1;
// Search for oldest voice in off state
if (v == null) {
v = voices[j];
voiceNo = j;
}
v = voices[j];
voiceNo = j;
}
}
}
// Search for oldest voice in on state
if (voiceNo == -1) {
if (v == null) {
v = voices[j];
voiceNo = j;
}
v = voices[j];
voiceNo = j;
}
}
}
}
return voiceNo;
}
}
// Voice is active , we must steal the voice
voice.stealer_channel = this;
voice.stealer_performer = p;
return;
}
voice.softchannel = this;
if (releaseTriggered)
return;
* (1f / 128f);
voice.portamento = true;
} else if (portamento) {
if (mono) {
* (1f / 128f);
voice.portamento = true;
}
} else {
if (portamento_lastnote_ix != 0) {
/ 100.0)
* (1f / 128f);
voice.portamento = true;
}
}
}
}
}
/* A special noteOn with delay parameter, which is used to
* start note within control buffers.
*/
if (current_mixer != null)
}
if (velocity == 0) {
return;
}
synchronized (control_mutex) {
if (sustain) {
sustain = false;
}
}
sustain = true;
}
if (mono) {
if (portamento) {
boolean n_found = false;
&& voices[i].releaseTriggered == false) {
voices[i].portamento = true;
n_found = true;
}
}
if (n_found) {
return;
}
}
boolean n_found = false;
&& voices[i].releaseTriggered == false) {
voices[i].portamento = true;
n_found = true;
}
}
if (n_found)
return;
}
}
if (mono)
allNotesOff();
if (current_instrument == null) {
if (current_instrument == null)
return;
if (current_mixer != null)
if (current_mixer != null)
}
firstVoice = true;
voiceNo = 0;
play_delay = delay;
play_releasetriggered = false;
/*
SoftPerformer[] performers = current_instrument.getPerformers();
for (int i = 0; i < performers.length; i++) {
SoftPerformer p = performers[i];
if (p.keyFrom <= tunedKey && p.keyTo >= tunedKey) {
if (p.velFrom <= velocity && p.velTo >= velocity) {
if (firstVoice) {
firstVoice = false;
if (p.exclusiveClass != 0) {
int x = p.exclusiveClass;
for (int j = 0; j < voices.length; j++) {
if (voices[j].active
&& voices[j].channel == channel
&& voices[j].exclusiveClass == x) {
if (!(p.selfNonExclusive
&& voices[j].note == noteNumber))
voices[j].shutdown();
}
}
}
}
voiceNo = findFreeVoice(voiceNo);
if (voiceNo == -1)
return;
initVoice(voices[voiceNo], p, prevVoiceID, noteNumber,
velocity);
}
}
}
*/
}
}
if (current_mixer != null)
}
synchronized (control_mutex) {
if (!mono) {
if (portamento) {
if (portamento_lastnote_ix != 127) {
}
}
}
&& voices[i].releaseTriggered == false) {
}
// We must also check stolen voices
v.stealer_releaseTriggered = false;
v.stealer_channel = null;
v.stealer_performer = null;
v.stealer_voiceID = -1;
v.stealer_noteNumber = 0;
v.stealer_velocity = 0;
v.stealer_channelmixer = null;
}
}
// Try play back note-off triggered voices,
if (current_instrument == null) {
if (current_instrument == null)
return;
if (current_mixer != null)
if (current_mixer != null)
}
firstVoice = true;
voiceNo = 0;
play_releasetriggered = true;
play_delay = 0;
}
}
private int prevVoiceID;
private boolean firstVoice = true;
private boolean play_releasetriggered = false;
int noteNumber = play_noteNumber;
int velocity = play_velocity;
int delay = play_delay;
boolean releasetriggered = play_releasetriggered;
if (firstVoice) {
firstVoice = false;
if (p.exclusiveClass != 0) {
int x = p.exclusiveClass;
&& voices[j].exclusiveClass == x) {
}
}
}
}
if (voiceNo == -1)
return;
}
}
if (current_mixer != null)
synchronized (control_mutex) {
}
}
}
synchronized (control_mutex) {
return polypressure[noteNumber];
}
}
if (current_mixer != null)
synchronized (control_mutex) {
}
}
}
public int getChannelPressure() {
synchronized (control_mutex) {
return channelpressure;
}
}
void applyInstrumentCustomization() {
if (cds_control_connections == null
&& cds_polypressure_connections == null) {
return;
}
new_performers[i] = new_performer;
if (cds_control_connections != null) {
boolean removeok = false;
removeok = true;
}
}
}
if (removeok)
}
}
if (cds_polypressure_connections != null) {
boolean removeok = false;
&& "poly_pressure".equals(
removeok = true;
}
}
}
if (removeok)
}
}
if (cds_channelpressure_connections != null) {
boolean removeok = false;
removeok = true;
}
}
}
if (removeok)
}
}
}
}
int[] destination, int[] range) {
/*
controlled parameter (pp)|range (rr)| Description |Default
-------------------------|----------|-------------------------|-------
00 Pitch Control | 28H..58H | -24..+24 semitones | 40H
01 Filter Cutoff Control | 00H..7FH | -9600..+9450 cents | 40H
02 Amplitude Control | 00H..7FH | 0..(127/64)*100 percent | 40H
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
*/
int d = destination[i];
int r = range[i];
if (d == 0) {
new ModelSource(sid,
new ModelDestination(
}
if (d == 1) {
if (scale > 0) {
conn = new ModelConnectionBlock(
new ModelSource(sid,
-scale,
new ModelDestination(
} else {
conn = new ModelConnectionBlock(
new ModelSource(sid,
new ModelDestination(
}
}
if (d == 2) {
final double scale = (r / 64.0);
double s = scale;
if (s < 1)
else if (s > 1)
else
return 0;
}
};
}
if (d == 3) {
new ModelSource(sid,
new ModelDestination(
}
if (d == 4) {
new ModelSource(sid,
new ModelDestination(
}
if (d == 5) {
final double scale = (r / 127.0);
double s = scale;
}
};
-960,
new ModelDestination(
}
}
}
return;
}
destination, range);
}
return;
}
destination, range);
}
return;
}
return;
}
destination, range);
}
/*
CC# | nn | Name | vv | default | description
-----|------|-------------------------|----------------|------------|-------------------------------
7 |07H |Note Volume |00H-40H-7FH |40H |0-100-(127/64)*100(%)(Relative)
10 |0AH |*Pan |00H-7FH absolute|Preset Value|Left-Center-Right (absolute)
33-63|21-3FH|LSB for |01H-1FH | |
72 |48H |Release Time |00H-40H-7FH |40H (???) |
73 |49H |Attack Time |00H-40H-7FH |40H (???) |
74 |4AH |Brightness |00H-40H-7FH |40H (???) |
75 |4BH |Decay Time |00H-40H-7FH |40H (???) |
76 |4CH |Vibrato Rate |00H-40H-7FH |40H (???) |
77 |4DH |Vibrato Depth |00H-40H-7FH |40H (???) |
78 |4EH |Vibrato Delay |00H-40H-7FH |40H (???) |
91 |5BH |*Reverb Send |00H-7FH absolute|Preset Value|Left-Center-Right (absolute)
93 |5DH |*Chorus Send |00H-7FH absolute|Preset Value|Left-Center-Right (absolute)
120 |78H |**Fine Tuning |00H-40H-7FH |40H (???) |
121 |79H |**Coarse Tuning |00H-40H-7FH |40H (???) |
*/
if (keybasedcontroller_active == null) {
keybasedcontroller_active = new boolean[128][];
keybasedcontroller_value = new double[128][];
}
}
if (value == -1) {
} else {
}
if (controller < 120) {
} else if (controller == 120) {
} else if (controller == 121) {
}
}
if (keybasedcontroller_active == null)
return -1;
return -1;
return -1;
}
if (current_mixer != null)
synchronized (control_mutex) {
switch (controller) {
/*
Map<String, int[]>co_midi_rpn_rpn_i = new HashMap<String, int[]>();
Map<String, double[]>co_midi_rpn_rpn = new HashMap<String, double[]>();
Map<String, int[]>co_midi_nrpn_nrpn_i = new HashMap<String, int[]>();
Map<String, double[]>co_midi_nrpn_nrpn = new HashMap<String, double[]>();
*/
case 5:
// This produce asin-like curve
// as described in General Midi Level 2 Specification, page 6
// Convert x from cent/msec to key/controlbuffertime
portamento_time = x;
break;
case 6:
case 38:
case 96:
case 97:
int val = 0;
if (nrpn_control != RPN_NULL_VALUE) {
}
if (rpn_control != RPN_NULL_VALUE) {
}
if (controller == 6)
else if (controller == 38)
int step = 1;
step = 128;
if (controller == 96)
if (controller == 97)
}
if (nrpn_control != RPN_NULL_VALUE)
if (rpn_control != RPN_NULL_VALUE)
break;
case 64: // Hold1 (Damper) (cc#64)
if (!on) {
}
}
}
} else {
}
}
break;
case 65:
//allNotesOff();
/*
for (int i = 0; i < portamento_lastnote.length; i++)
portamento_lastnote[i] = -1;
*/
break;
case 66: // Sostenuto (cc#66)
if (on) {
}
}
}
if (!on) {
}
}
}
}
break;
case 98:
break;
case 99:
break;
case 100:
break;
case 101:
break;
case 120:
allSoundOff();
break;
case 121:
break;
case 122:
break;
case 123:
allNotesOff();
break;
case 124:
setOmni(false);
break;
case 125:
setOmni(true);
break;
case 126:
if (value == 1)
setMono(true);
break;
case 127:
setMono(false);
break;
default:
break;
}
if (controller == 0x00) {
return;
}
if (controller == 0x20) {
return;
}
if(controller < 0x20)
}
}
synchronized (control_mutex) {
// Should only return lower 7 bits,
// even when controller is "boosted" higher.
}
}
}
synchronized (control_mutex) {
}
}
}
synchronized (control_mutex) {
{
}
}
}
public int getProgram() {
synchronized (control_mutex) {
return program;
}
}
if (current_mixer != null)
synchronized (control_mutex) {
}
}
public int getPitchBend() {
synchronized (control_mutex) {
return pitchbend;
}
}
/*
System.out.println("(" + channel + ").nrpnChange("
+ Integer.toHexString(controller >> 7)
+ " " + Integer.toHexString(controller & 127)
+ ", " + Integer.toHexString(value >> 7)
+ " " + Integer.toHexString(value & 127) + ")");
*/
}
val_i = new int[1];
}
val_d = new double[1];
}
}
/*
System.out.println("(" + channel + ").rpnChange("
+ Integer.toHexString(controller >> 7)
+ " " + Integer.toHexString(controller & 127)
+ ", " + Integer.toHexString(value >> 7)
+ " " + Integer.toHexString(value & 127) + ")");
*/
if (controller == 3) {
}
if (controller == 4) {
}
val_i = new int[1];
}
val_d = new double[1];
}
}
public void resetAllControllers() {
resetAllControllers(false);
}
synchronized (control_mutex) {
for (int i = 0; i < 128; i++) {
setPolyPressure(i, 0);
}
setPitchBend(8192);
for (int i = 0; i < 128; i++) {
if (!dontResetControls[i])
controlChange(i, 0);
}
// see DLS 2.1 (Power-on Default Values)
if (allControls) {
// don't reset tuning settings
}
tuning_bank = 0;
tuning_program = 0;
tuning = new SoftTuning();
}
}
}
public void allNotesOff() {
if (current_mixer != null)
synchronized (control_mutex) {
&& voices[i].releaseTriggered == false) {
}
}
}
public void allSoundOff() {
if (current_mixer != null)
synchronized (control_mutex) {
}
}
return false;
}
if (current_mixer != null)
synchronized (control_mutex) {
allNotesOff();
}
}
public boolean getMono() {
synchronized (control_mutex) {
return mono;
}
}
if (current_mixer != null)
allNotesOff();
// Omni is not supported by GM2
}
public boolean getOmni() {
return false;
}
if (current_mixer != null)
synchronized (control_mutex) {
}
}
public boolean getMute() {
synchronized (control_mutex) {
return mute;
}
}
if (current_mixer != null)
synchronized (control_mutex) {
boolean soloinuse = false;
if (c.solo) {
soloinuse = true;
break;
}
}
if (!soloinuse) {
c.setSoloMute(false);
return;
}
c.setSoloMute(!c.solo);
}
}
synchronized (control_mutex) {
return;
}
}
public boolean getSolo() {
synchronized (control_mutex) {
return solo;
}
}
}