/*
* 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.
*/
/**
* The software synthesizer class.
*
* @author Karl Helgason
*/
{
private int samplesize;
{
}
if(local_stream != null)
return local_stream.available();
return 0;
}
byte[] b = new byte[1];
if (read(b) == -1)
return -1;
return b[0] & 0xFF;
}
if(local_stream != null)
else
{
silentbuffer = new float[flen];
{
{
public void run()
{
if(_jitter_stream != null)
try {
} catch (IOException e) {
e.printStackTrace();
}
if(_sourceDataLine != null)
}
};
}
return len;
}
}
}
{
}
{
}
}
Info() {
}
}
// 0: default
// 1: DLS Voice Allocation
boolean load_default_soundbank = false;
boolean reverb_light = true;
boolean reverb_on = true;
boolean chorus_on = true;
boolean agc_on = true;
private boolean largemode = false;
// 0: GM Mode off (default)
// 1: GM Level 1
// 2: GM Level 2
private boolean open = false;
private boolean implicitOpen = false;
private boolean jitter_correction = false;
if (osc instanceof ModelByteBufferWavetable) {
buff = w.get8BitExtensionBuffer();
}
}
}
}
}
if (largemode)
return true;
try {
} catch (IOException e) {
return false;
}
return true;
}
if (!isOpen())
return false;
if (!loadSamples(instruments))
return false;
synchronized (control_mutex) {
for (SoftChannel c : channels)
{
c.current_instrument = null;
c.current_director = null;
}
}
}
return true;
}
{
this.resampler = new SoftPointResampler();
this.resamplerType = "point";
}
{
this.resampler = new SoftLinearResampler2();
this.resamplerType = "linear";
}
{
this.resampler = new SoftLinearResampler();
this.resamplerType = "linear1";
}
{
this.resampler = new SoftLinearResampler2();
this.resamplerType = "linear2";
}
{
this.resampler = new SoftCubicResampler();
this.resamplerType = "cubic";
}
{
this.resampler = new SoftLanczosResampler();
this.resamplerType = "lanczos";
}
{
this.resampler = new SoftSincResampler();
this.resamplerType = "sinc";
}
}
else
}
throw new IllegalArgumentException(
"Only mono and stereo audio supported.");
}
throw new IllegalArgumentException("Audio format not supported.");
}
boolean perform_close = false;
synchronized (control_mutex) {
perform_close = true;
}
}
if (perform_close)
close();
}
if (!isOpen())
return null;
return mainmixer;
}
// Add support for GM2 banks 0x78 and 0x79
// as specified in DLS 2.2 in Section 1.4.6
// which allows using percussion and melodic instruments
// on all channels
if (current_instrument != null)
return current_instrument;
p_plaf = "p.";
else
p_plaf = "";
// Instrument not found fallback to MSB:bank, LSB:0
if (current_instrument != null)
return current_instrument;
// Instrument not found fallback to MSB:0, LSB:bank
+ (bank & 128));
if (current_instrument != null)
return current_instrument;
// Instrument not found fallback to MSB:0, LSB:0
if (current_instrument != null)
return current_instrument;
// Instrument not found fallback to MSB:0, LSB:0, program=0
if (current_instrument != null)
return current_instrument;
return null;
}
// Channel 10 uses percussion instruments
if (channel == 9)
p_plaf = "p.";
else
p_plaf = "";
if (current_instrument != null)
return current_instrument;
// Instrument not found fallback to MSB:0, LSB:0
if (current_instrument != null)
return current_instrument;
// Instrument not found fallback to MSB:0, LSB:0, program=0
if (current_instrument != null)
return current_instrument;
return null;
}
int getVoiceAllocationMode() {
return voice_allocation_mode;
}
int getGeneralMidiMode() {
return gmmode;
}
}
int getDeviceID() {
return deviceid;
}
float getControlRate() {
return controlrate;
}
return voices;
}
}
return tuning;
}
public long getLatency() {
synchronized (control_mutex) {
return latency;
}
}
synchronized (control_mutex) {
return format;
}
}
public int getMaxPolyphony() {
synchronized (control_mutex) {
return maxpoly;
}
}
synchronized (control_mutex) {
// if (external_channels == null) => the synthesizer is not open,
// create 16 proxy channels
// otherwise external_channels has the same length as channels array
if (external_channels == null) {
external_channels[i] = new SoftChannelProxy();
}
MidiChannel[] ret;
if (isOpen())
else
ret[i] = external_channels[i];
return ret;
}
}
if (!isOpen()) {
= new VoiceStatus[getMaxPolyphony()];
VoiceStatus b = new VoiceStatus();
b.active = false;
b.bank = 0;
b.channel = 0;
b.note = 0;
b.program = 0;
b.volume = 0;
tempVoiceStatusArray[i] = b;
}
return tempVoiceStatusArray;
}
synchronized (control_mutex) {
VoiceStatus a = voices[i];
VoiceStatus b = new VoiceStatus();
tempVoiceStatusArray[i] = b;
}
return tempVoiceStatusArray;
}
}
if (!(ins instanceof ModelInstrument))
return false;
return true;
}
throw new IllegalArgumentException("Unsupported instrument: " +
}
return loadInstruments(instruments);
}
throw new IllegalArgumentException("Unsupported instrument: " +
}
if (!isOpen())
return;
synchronized (control_mutex) {
for (SoftChannel c: channels)
c.current_instrument = null;
channels[i].allSoundOff();
}
}
}
throw new NullPointerException();
throw new NullPointerException();
if (!(from instanceof ModelInstrument)) {
throw new IllegalArgumentException("Unsupported instrument: " +
}
if (!(to instanceof ModelInstrument)) {
throw new IllegalArgumentException("Unsupported instrument: " +
}
if (!isOpen())
return false;
synchronized (control_mutex) {
throw new IllegalArgumentException("Instrument to is not loaded.");
return loadInstrument(mfrom);
}
}
synchronized (SoftSynthesizer.class) {
if (defaultSoundBank != null)
return defaultSoundBank;
public InputStream run() {
.getProperty("java.home"));
.length())) {
}
}
}
}
}
try {
return new FileInputStream(foundfile);
} catch (IOException e) {
}
}
}
return null;
}
});
public InputStream run() {
.startsWith("Windows")) {
+ "\\system32\\drivers\\gm.dls");
try {
return new FileInputStream(gm_dls);
} catch (IOException e) {
}
}
}
return null;
}
});
public InputStream run() {
/*
* Try to load saved generated soundbank
*/
".gervill");
"soundbank-emg.sf2");
if (emg_soundbank_file.exists()) {
try {
return new FileInputStream(emg_soundbank_file);
} catch (IOException e) {
}
}
return null;
}
});
try {
try {
} finally {
}
return defaultSoundBank;
}
} catch (Exception e) {
}
}
try {
/*
* Generate emergency soundbank
*/
} catch (Exception e) {
}
if (defaultSoundBank != null) {
/*
* Save generated soundbank to disk for faster future use.
*/
public OutputStream run() {
try {
.getProperty("user.home"),
".gervill");
userhome, "soundbank-emg.sf2");
if (emg_soundbank_file.exists())
return null;
return new FileOutputStream(
} catch (IOException e) {
} catch (SecurityException e) {
}
return null;
}
});
try {
} catch (IOException e) {
}
}
}
}
return defaultSoundBank;
}
return new Instrument[0];
return inslist_array;
}
if (!isOpen())
return new Instrument[0];
synchronized (control_mutex) {
return inslist_array;
}
}
throw new IllegalArgumentException(
"Unsupported instrument: " + ins);
}
}
return loadInstruments(instruments);
}
if (!isOpen())
return;
if (ins instanceof ModelInstrument) {
}
}
}
throw new IllegalArgumentException(
"Unsupported instrument: " + ins);
}
}
return loadInstruments(instruments);
}
if (!isOpen())
return;
if (ins instanceof ModelInstrument) {
}
}
}
return info;
}
return AccessController
public Properties run() {
Properties p = new Properties();
try {
}
}
} catch (BackingStoreException e) {
} catch (SecurityException e) {
}
return p;
}
});
}
// If info != null or synthesizer is closed
// we return how the synthesizer will be set on next open
// If info == null and synthesizer is open
// we return current synthesizer properties.
"lanczos", "sinc", "point"};
if (v != null) {
if (c.isInstance(v))
else if (v instanceof String) {
if (c == Boolean.class) {
if (s.equalsIgnoreCase("true"))
if (s.equalsIgnoreCase("false"))
} else if (c == AudioFormat.class) {
int channels = 2;
boolean signed = true;
boolean bigendian = false;
int bits = 16;
float sampleRate = 44100f;
try {
while (st.hasMoreTokens()) {
channels = 1;
signed = false;
bigendian = true;
}
} catch (NumberFormatException e) {
}
} else
try {
if (c == Byte.class)
else if (c == Short.class)
else if (c == Integer.class)
else if (c == Long.class)
else if (c == Float.class)
else if (c == Double.class)
} catch (NumberFormatException e) {
}
} else if (v instanceof Number) {
if (c == Byte.class)
if (c == Short.class)
if (c == Integer.class)
if (c == Long.class)
if (c == Float.class)
if (c == Double.class)
}
}
}
return items;
}
if (isOpen()) {
synchronized (control_mutex) {
implicitOpen = false;
}
return;
}
}
if (isOpen()) {
synchronized (control_mutex) {
implicitOpen = false;
}
return;
}
synchronized (control_mutex) {
try {
// can throw IllegalArgumentException
}
{
} else {
// can throw LineUnavailableException,
// IllegalArgumentException, SecurityException
}
}
// can throw LineUnavailableException,
// IllegalArgumentException, SecurityException
// Remember that we opened that line
// so we can close again in SoftSynthesizer.close()
}
int controlbuffersize = 512;
try {
} catch (IOException e) {
}
// Tell mixer not fill read buffers fully.
// This lowers latency, and tells DataPusher
// to read in smaller amounts.
//mainmixer.readfully = false;
//pusher = new DataPusher(line, ais);
if (jitter_correction) {
if(weakstream != null)
}
pusher_stream = ais;
if(weakstream != null)
{
}
} catch (LineUnavailableException e) {
causeException = e;
} catch (IllegalArgumentException e) {
causeException = e;
} catch (SecurityException e) {
causeException = e;
}
if (causeException != null) {
if (isOpen())
close();
// am: need MidiUnavailableException(Throwable) ctor!
"Can not open line");
throw ex;
}
}
}
if (isOpen())
throw new MidiUnavailableException("Synthesizer is already open");
synchronized (control_mutex) {
gmmode = 0;
open = true;
implicitOpen = false;
if (targetFormat != null)
{
}
}
for (int i = 0; i < maxpoly; i++)
mainmixer = new SoftMainMixer(this);
channels[i] = new SoftChannel(this, i);
if (external_channels == null) {
// Always create external_channels array
// with 16 or more channels
// so getChannels works correctly
// when the synhtesizer is closed.
else
external_channels[i] = new SoftChannelProxy();
} else {
// We must resize external_channels array
// but we must also copy the old SoftChannelProxy
// into the new one
new_external_channels[i] = external_channels[i];
for (int i = external_channels.length;
i < new_external_channels.length; i++) {
new_external_channels[i] = new SoftChannelProxy();
}
}
}
}
return mainmixer.getInputStream();
}
}
public void close() {
if (!isOpen())
return;
synchronized (control_mutex) {
}
}
if (pusher_to_be_closed != null) {
// Pusher must not be closed synchronized against control_mutex,
// this may result in synchronized conflict between pusher
// and current thread.
try {
} catch (IOException e) {
//e.printStackTrace();
}
}
synchronized (control_mutex) {
open = false;
implicitOpen = false;
if (external_channels != null)
if (sourceDataLine != null) {
}
loadedlist.clear();
}
}
public boolean isOpen() {
synchronized (control_mutex) {
return open;
}
}
public long getMicrosecondPosition() {
if (!isOpen())
return 0;
synchronized (control_mutex) {
return mainmixer.getMicrosecondPosition();
}
}
public int getMaxReceivers() {
return -1;
}
public int getMaxTransmitters() {
return 0;
}
synchronized (control_mutex) {
return receiver;
}
}
synchronized (control_mutex) {
return recvs;
}
}
throw new MidiUnavailableException("No transmitter available");
}
return new ArrayList<Transmitter>();
}
throws MidiUnavailableException {
if (!isOpen()) {
open();
synchronized (control_mutex) {
implicitOpen = true;
}
}
return getReceiver();
}
throws MidiUnavailableException {
throw new MidiUnavailableException("No transmitter available");
}
}