jdk/src/share/classes/com/sun/media/sound/SoftSynthesizer.java
author serb
Thu, 07 Aug 2014 17:02:48 +0400
changeset 26030 576ffa819e23
parent 24548 9c007a986347
permissions -rw-r--r--
8054372: Cleanup of com.sun.media.sound packages Reviewed-by: azvegint, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
     1
/*
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
     2
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
     4
 *
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4385
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4385
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    10
 *
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    15
 * accompanied this code).
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    16
 *
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4385
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4385
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4385
diff changeset
    23
 * questions.
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    24
 */
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    25
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    26
package com.sun.media.sound;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    27
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    28
import java.io.BufferedInputStream;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    29
import java.io.File;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    30
import java.io.FileInputStream;
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
    31
import java.io.FileNotFoundException;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    32
import java.io.FileOutputStream;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    33
import java.io.IOException;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    34
import java.io.InputStream;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    35
import java.io.OutputStream;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    36
import java.lang.ref.WeakReference;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    37
import java.security.AccessController;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    38
import java.security.PrivilegedAction;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    39
import java.util.ArrayList;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    40
import java.util.Arrays;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    41
import java.util.HashMap;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    42
import java.util.List;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    43
import java.util.Map;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    44
import java.util.Properties;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    45
import java.util.StringTokenizer;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    46
import java.util.prefs.BackingStoreException;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
    47
import java.util.prefs.Preferences;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    48
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    49
import javax.sound.midi.Instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    50
import javax.sound.midi.MidiChannel;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    51
import javax.sound.midi.MidiDevice;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    52
import javax.sound.midi.MidiSystem;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    53
import javax.sound.midi.MidiUnavailableException;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    54
import javax.sound.midi.Patch;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    55
import javax.sound.midi.Receiver;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    56
import javax.sound.midi.Soundbank;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    57
import javax.sound.midi.Transmitter;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    58
import javax.sound.midi.VoiceStatus;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    59
import javax.sound.sampled.AudioFormat;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    60
import javax.sound.sampled.AudioInputStream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    61
import javax.sound.sampled.AudioSystem;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    62
import javax.sound.sampled.LineUnavailableException;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    63
import javax.sound.sampled.SourceDataLine;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    64
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    65
/**
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    66
 * The software synthesizer class.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    67
 *
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    68
 * @author Karl Helgason
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    69
 */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
    70
public final class SoftSynthesizer implements AudioSynthesizer,
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    71
        ReferenceCountingDevice {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    72
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
    73
    protected static final class WeakAudioStream extends InputStream
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    74
    {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    75
        private volatile AudioInputStream stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    76
        public SoftAudioPusher pusher = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    77
        public AudioInputStream jitter_stream = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    78
        public SourceDataLine sourceDataLine = null;
4385
cf4674d08b51 6833357: Improve time-stamp support in Gervill to reduce jitter
kalli
parents: 2654
diff changeset
    79
        public volatile long silent_samples = 0;
cf4674d08b51 6833357: Improve time-stamp support in Gervill to reduce jitter
kalli
parents: 2654
diff changeset
    80
        private int framesize = 0;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    81
        private WeakReference<AudioInputStream> weak_stream_link;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    82
        private AudioFloatConverter converter;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    83
        private float[] silentbuffer = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    84
        private int samplesize;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    85
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    86
        public void setInputStream(AudioInputStream stream)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    87
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    88
            this.stream = stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    89
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    90
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    91
        public int available() throws IOException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    92
            AudioInputStream local_stream = stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    93
            if(local_stream != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    94
                return local_stream.available();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    95
            return 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    96
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    97
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    98
        public int read() throws IOException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
    99
             byte[] b = new byte[1];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   100
             if (read(b) == -1)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   101
                  return -1;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   102
             return b[0] & 0xFF;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   103
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   104
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   105
        public int read(byte[] b, int off, int len) throws IOException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   106
             AudioInputStream local_stream = stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   107
             if(local_stream != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   108
                 return local_stream.read(b, off, len);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   109
             else
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   110
             {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   111
                 int flen = len / samplesize;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   112
                 if(silentbuffer == null || silentbuffer.length < flen)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   113
                     silentbuffer = new float[flen];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   114
                 converter.toByteArray(silentbuffer, flen, b, off);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   115
4385
cf4674d08b51 6833357: Improve time-stamp support in Gervill to reduce jitter
kalli
parents: 2654
diff changeset
   116
                 silent_samples += (long)((len / framesize));
cf4674d08b51 6833357: Improve time-stamp support in Gervill to reduce jitter
kalli
parents: 2654
diff changeset
   117
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   118
                 if(pusher != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   119
                 if(weak_stream_link.get() == null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   120
                 {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   121
                     Runnable runnable = new Runnable()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   122
                     {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   123
                         SoftAudioPusher _pusher = pusher;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   124
                         AudioInputStream _jitter_stream = jitter_stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   125
                         SourceDataLine _sourceDataLine = sourceDataLine;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   126
                         public void run()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   127
                         {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   128
                             _pusher.stop();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   129
                             if(_jitter_stream != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   130
                                try {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   131
                                    _jitter_stream.close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   132
                                } catch (IOException e) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   133
                                    e.printStackTrace();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   134
                                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   135
                             if(_sourceDataLine != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   136
                                 _sourceDataLine.close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   137
                         }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   138
                     };
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   139
                     pusher = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   140
                     jitter_stream = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   141
                     sourceDataLine = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   142
                     new Thread(runnable).start();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   143
                 }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   144
                 return len;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   145
             }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   146
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   147
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   148
        public WeakAudioStream(AudioInputStream stream) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   149
            this.stream = stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   150
            weak_stream_link = new WeakReference<AudioInputStream>(stream);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   151
            converter = AudioFloatConverter.getConverter(stream.getFormat());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   152
            samplesize = stream.getFormat().getFrameSize() / stream.getFormat().getChannels();
4385
cf4674d08b51 6833357: Improve time-stamp support in Gervill to reduce jitter
kalli
parents: 2654
diff changeset
   153
            framesize = stream.getFormat().getFrameSize();
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   154
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   155
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   156
        public AudioInputStream getAudioInputStream()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   157
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   158
            return new AudioInputStream(this, stream.getFormat(), AudioSystem.NOT_SPECIFIED);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   159
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   160
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   161
        public void close() throws IOException
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   162
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   163
            AudioInputStream astream  = weak_stream_link.get();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   164
            if(astream != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   165
                astream.close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   166
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   167
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   168
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   169
    private static class Info extends MidiDevice.Info {
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   170
        Info() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   171
            super(INFO_NAME, INFO_VENDOR, INFO_DESCRIPTION, INFO_VERSION);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   172
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   173
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   174
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   175
    static final String INFO_NAME = "Gervill";
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   176
    static final String INFO_VENDOR = "OpenJDK";
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   177
    static final String INFO_DESCRIPTION = "Software MIDI Synthesizer";
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   178
    static final String INFO_VERSION = "1.0";
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   179
    final static MidiDevice.Info info = new Info();
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   180
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   181
    private static SourceDataLine testline = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   182
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   183
    private static Soundbank defaultSoundBank = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   184
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   185
    WeakAudioStream weakstream = null;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   186
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   187
    final Object control_mutex = this;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   188
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   189
    int voiceIDCounter = 0;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   190
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   191
    // 0: default
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   192
    // 1: DLS Voice Allocation
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   193
    int voice_allocation_mode = 0;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   194
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   195
    boolean load_default_soundbank = false;
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   196
    boolean reverb_light = true;
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   197
    boolean reverb_on = true;
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   198
    boolean chorus_on = true;
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   199
    boolean agc_on = true;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   200
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   201
    SoftChannel[] channels;
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   202
    SoftChannelProxy[] external_channels = null;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   203
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   204
    private boolean largemode = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   205
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   206
    // 0: GM Mode off (default)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   207
    // 1: GM Level 1
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   208
    // 2: GM Level 2
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   209
    private int gmmode = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   210
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   211
    private int deviceid = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   212
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   213
    private AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   214
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   215
    private SourceDataLine sourceDataLine = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   216
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   217
    private SoftAudioPusher pusher = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   218
    private AudioInputStream pusher_stream = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   219
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   220
    private float controlrate = 147f;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   221
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   222
    private boolean open = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   223
    private boolean implicitOpen = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   224
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   225
    private String resamplerType = "linear";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   226
    private SoftResampler resampler = new SoftLinearResampler();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   227
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   228
    private int number_of_midi_channels = 16;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   229
    private int maxpoly = 64;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   230
    private long latency = 200000; // 200 msec
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   231
    private boolean jitter_correction = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   232
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   233
    private SoftMainMixer mainmixer;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   234
    private SoftVoice[] voices;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   235
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   236
    private Map<String, SoftTuning> tunings
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   237
            = new HashMap<String, SoftTuning>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   238
    private Map<String, SoftInstrument> inslist
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   239
            = new HashMap<String, SoftInstrument>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   240
    private Map<String, ModelInstrument> loadedlist
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   241
            = new HashMap<String, ModelInstrument>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   242
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   243
    private ArrayList<Receiver> recvslist = new ArrayList<Receiver>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   244
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   245
    private void getBuffers(ModelInstrument instrument,
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   246
            List<ModelByteBuffer> buffers) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   247
        for (ModelPerformer performer : instrument.getPerformers()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   248
            if (performer.getOscillators() != null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   249
                for (ModelOscillator osc : performer.getOscillators()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   250
                    if (osc instanceof ModelByteBufferWavetable) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   251
                        ModelByteBufferWavetable w = (ModelByteBufferWavetable)osc;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   252
                        ModelByteBuffer buff = w.getBuffer();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   253
                        if (buff != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   254
                            buffers.add(buff);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   255
                        buff = w.get8BitExtensionBuffer();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   256
                        if (buff != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   257
                            buffers.add(buff);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   258
                    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   259
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   260
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   261
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   262
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   263
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   264
    private boolean loadSamples(List<ModelInstrument> instruments) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   265
        if (largemode)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   266
            return true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   267
        List<ModelByteBuffer> buffers = new ArrayList<ModelByteBuffer>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   268
        for (ModelInstrument instrument : instruments)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   269
            getBuffers(instrument, buffers);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   270
        try {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   271
            ModelByteBuffer.loadAll(buffers);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   272
        } catch (IOException e) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   273
            return false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   274
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   275
        return true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   276
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   277
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   278
    private boolean loadInstruments(List<ModelInstrument> instruments) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   279
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   280
            return false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   281
        if (!loadSamples(instruments))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   282
            return false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   283
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   284
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   285
            if (channels != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   286
                for (SoftChannel c : channels)
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   287
                {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   288
                    c.current_instrument = null;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   289
                    c.current_director = null;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   290
                }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   291
            for (Instrument instrument : instruments) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   292
                String pat = patchToString(instrument.getPatch());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   293
                SoftInstrument softins
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   294
                        = new SoftInstrument((ModelInstrument) instrument);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   295
                inslist.put(pat, softins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   296
                loadedlist.put(pat, (ModelInstrument) instrument);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   297
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   298
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   299
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   300
        return true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   301
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   302
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   303
    private void processPropertyInfo(Map<String, Object> info) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   304
        AudioSynthesizerPropertyInfo[] items = getPropertyInfo(info);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   305
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   306
        String resamplerType = (String)items[0].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   307
        if (resamplerType.equalsIgnoreCase("point"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   308
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   309
            this.resampler = new SoftPointResampler();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   310
            this.resamplerType = "point";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   311
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   312
        else if (resamplerType.equalsIgnoreCase("linear"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   313
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   314
            this.resampler = new SoftLinearResampler2();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   315
            this.resamplerType = "linear";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   316
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   317
        else if (resamplerType.equalsIgnoreCase("linear1"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   318
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   319
            this.resampler = new SoftLinearResampler();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   320
            this.resamplerType = "linear1";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   321
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   322
        else if (resamplerType.equalsIgnoreCase("linear2"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   323
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   324
            this.resampler = new SoftLinearResampler2();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   325
            this.resamplerType = "linear2";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   326
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   327
        else if (resamplerType.equalsIgnoreCase("cubic"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   328
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   329
            this.resampler = new SoftCubicResampler();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   330
            this.resamplerType = "cubic";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   331
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   332
        else if (resamplerType.equalsIgnoreCase("lanczos"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   333
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   334
            this.resampler = new SoftLanczosResampler();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   335
            this.resamplerType = "lanczos";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   336
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   337
        else if (resamplerType.equalsIgnoreCase("sinc"))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   338
        {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   339
            this.resampler = new SoftSincResampler();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   340
            this.resamplerType = "sinc";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   341
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   342
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   343
        setFormat((AudioFormat)items[2].value);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   344
        controlrate = (Float)items[1].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   345
        latency = (Long)items[3].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   346
        deviceid = (Integer)items[4].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   347
        maxpoly = (Integer)items[5].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   348
        reverb_on = (Boolean)items[6].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   349
        chorus_on = (Boolean)items[7].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   350
        agc_on = (Boolean)items[8].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   351
        largemode = (Boolean)items[9].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   352
        number_of_midi_channels = (Integer)items[10].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   353
        jitter_correction = (Boolean)items[11].value;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   354
        reverb_light = (Boolean)items[12].value;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   355
        load_default_soundbank = (Boolean)items[13].value;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   356
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   357
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   358
    private String patchToString(Patch patch) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   359
        if (patch instanceof ModelPatch && ((ModelPatch) patch).isPercussion())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   360
            return "p." + patch.getProgram() + "." + patch.getBank();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   361
        else
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   362
            return patch.getProgram() + "." + patch.getBank();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   363
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   364
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   365
    private void setFormat(AudioFormat format) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   366
        if (format.getChannels() > 2) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   367
            throw new IllegalArgumentException(
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   368
                    "Only mono and stereo audio supported.");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   369
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   370
        if (AudioFloatConverter.getConverter(format) == null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   371
            throw new IllegalArgumentException("Audio format not supported.");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   372
        this.format = format;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   373
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   374
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   375
    void removeReceiver(Receiver recv) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   376
        boolean perform_close = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   377
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   378
            if (recvslist.remove(recv)) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   379
                if (implicitOpen && recvslist.isEmpty())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   380
                    perform_close = true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   381
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   382
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   383
        if (perform_close)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   384
            close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   385
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   386
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   387
    SoftMainMixer getMainMixer() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   388
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   389
            return null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   390
        return mainmixer;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   391
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   392
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   393
    SoftInstrument findInstrument(int program, int bank, int channel) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   394
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   395
        // Add support for GM2 banks 0x78 and 0x79
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   396
        // as specified in DLS 2.2 in Section 1.4.6
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   397
        // which allows using percussion and melodic instruments
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   398
        // on all channels
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   399
        if (bank >> 7 == 0x78 || bank >> 7 == 0x79) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   400
            SoftInstrument current_instrument
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   401
                    = inslist.get(program + "." + bank);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   402
            if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   403
                return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   404
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   405
            String p_plaf;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   406
            if (bank >> 7 == 0x78)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   407
                p_plaf = "p.";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   408
            else
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   409
                p_plaf = "";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   410
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   411
            // Instrument not found fallback to MSB:bank, LSB:0
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   412
            current_instrument = inslist.get(p_plaf + program + "."
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   413
                    + ((bank & 128) << 7));
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   414
            if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   415
                return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   416
            // Instrument not found fallback to MSB:0, LSB:bank
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   417
            current_instrument = inslist.get(p_plaf + program + "."
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   418
                    + (bank & 128));
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   419
            if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   420
                return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   421
            // Instrument not found fallback to MSB:0, LSB:0
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   422
            current_instrument = inslist.get(p_plaf + program + ".0");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   423
            if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   424
                return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   425
            // Instrument not found fallback to MSB:0, LSB:0, program=0
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   426
            current_instrument = inslist.get(p_plaf + program + "0.0");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   427
            if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   428
                return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   429
            return null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   430
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   431
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   432
        // Channel 10 uses percussion instruments
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   433
        String p_plaf;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   434
        if (channel == 9)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   435
            p_plaf = "p.";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   436
        else
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   437
            p_plaf = "";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   438
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   439
        SoftInstrument current_instrument
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   440
                = inslist.get(p_plaf + program + "." + bank);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   441
        if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   442
            return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   443
        // Instrument not found fallback to MSB:0, LSB:0
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   444
        current_instrument = inslist.get(p_plaf + program + ".0");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   445
        if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   446
            return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   447
        // Instrument not found fallback to MSB:0, LSB:0, program=0
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   448
        current_instrument = inslist.get(p_plaf + "0.0");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   449
        if (current_instrument != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   450
            return current_instrument;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   451
        return null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   452
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   453
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   454
    int getVoiceAllocationMode() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   455
        return voice_allocation_mode;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   456
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   457
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   458
    int getGeneralMidiMode() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   459
        return gmmode;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   460
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   461
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   462
    void setGeneralMidiMode(int gmmode) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   463
        this.gmmode = gmmode;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   464
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   465
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   466
    int getDeviceID() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   467
        return deviceid;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   468
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   469
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   470
    float getControlRate() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   471
        return controlrate;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   472
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   473
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   474
    SoftVoice[] getVoices() {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   475
        return voices;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   476
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   477
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6502
diff changeset
   478
    SoftTuning getTuning(Patch patch) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   479
        String t_id = patchToString(patch);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   480
        SoftTuning tuning = tunings.get(t_id);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   481
        if (tuning == null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   482
            tuning = new SoftTuning(patch);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   483
            tunings.put(t_id, tuning);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   484
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   485
        return tuning;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   486
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   487
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   488
    public long getLatency() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   489
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   490
            return latency;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   491
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   492
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   493
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   494
    public AudioFormat getFormat() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   495
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   496
            return format;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   497
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   498
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   499
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   500
    public int getMaxPolyphony() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   501
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   502
            return maxpoly;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   503
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   504
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   505
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   506
    public MidiChannel[] getChannels() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   507
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   508
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   509
            // if (external_channels == null) => the synthesizer is not open,
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   510
            // create 16 proxy channels
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   511
            // otherwise external_channels has the same length as channels array
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   512
            if (external_channels == null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   513
                external_channels = new SoftChannelProxy[16];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   514
                for (int i = 0; i < external_channels.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   515
                    external_channels[i] = new SoftChannelProxy();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   516
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   517
            MidiChannel[] ret;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   518
            if (isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   519
                ret = new MidiChannel[channels.length];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   520
            else
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   521
                ret = new MidiChannel[16];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   522
            for (int i = 0; i < ret.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   523
                ret[i] = external_channels[i];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   524
            return ret;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   525
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   526
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   527
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   528
    public VoiceStatus[] getVoiceStatus() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   529
        if (!isOpen()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   530
            VoiceStatus[] tempVoiceStatusArray
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   531
                    = new VoiceStatus[getMaxPolyphony()];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   532
            for (int i = 0; i < tempVoiceStatusArray.length; i++) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   533
                VoiceStatus b = new VoiceStatus();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   534
                b.active = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   535
                b.bank = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   536
                b.channel = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   537
                b.note = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   538
                b.program = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   539
                b.volume = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   540
                tempVoiceStatusArray[i] = b;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   541
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   542
            return tempVoiceStatusArray;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   543
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   544
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   545
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   546
            VoiceStatus[] tempVoiceStatusArray = new VoiceStatus[voices.length];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   547
            for (int i = 0; i < voices.length; i++) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   548
                VoiceStatus a = voices[i];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   549
                VoiceStatus b = new VoiceStatus();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   550
                b.active = a.active;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   551
                b.bank = a.bank;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   552
                b.channel = a.channel;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   553
                b.note = a.note;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   554
                b.program = a.program;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   555
                b.volume = a.volume;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   556
                tempVoiceStatusArray[i] = b;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   557
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   558
            return tempVoiceStatusArray;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   559
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   560
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   561
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   562
    public boolean isSoundbankSupported(Soundbank soundbank) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   563
        for (Instrument ins: soundbank.getInstruments())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   564
            if (!(ins instanceof ModelInstrument))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   565
                return false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   566
        return true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   567
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   568
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   569
    public boolean loadInstrument(Instrument instrument) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   570
        if (instrument == null || (!(instrument instanceof ModelInstrument))) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   571
            throw new IllegalArgumentException("Unsupported instrument: " +
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   572
                    instrument);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   573
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   574
        List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   575
        instruments.add((ModelInstrument)instrument);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   576
        return loadInstruments(instruments);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   577
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   578
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   579
    public void unloadInstrument(Instrument instrument) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   580
        if (instrument == null || (!(instrument instanceof ModelInstrument))) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   581
            throw new IllegalArgumentException("Unsupported instrument: " +
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   582
                    instrument);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   583
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   584
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   585
            return;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   586
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   587
        String pat = patchToString(instrument.getPatch());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   588
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   589
            for (SoftChannel c: channels)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   590
                c.current_instrument = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   591
            inslist.remove(pat);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   592
            loadedlist.remove(pat);
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   593
            for (int i = 0; i < channels.length; i++) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   594
                channels[i].allSoundOff();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   595
            }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   596
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   597
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   598
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   599
    public boolean remapInstrument(Instrument from, Instrument to) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   600
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   601
        if (from == null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   602
            throw new NullPointerException();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   603
        if (to == null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   604
            throw new NullPointerException();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   605
        if (!(from instanceof ModelInstrument)) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   606
            throw new IllegalArgumentException("Unsupported instrument: " +
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   607
                    from.toString());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   608
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   609
        if (!(to instanceof ModelInstrument)) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   610
            throw new IllegalArgumentException("Unsupported instrument: " +
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   611
                    to.toString());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   612
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   613
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   614
            return false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   615
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   616
        synchronized (control_mutex) {
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   617
            if (!loadedlist.containsValue(to))
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   618
                throw new IllegalArgumentException("Instrument to is not loaded.");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   619
            unloadInstrument(from);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   620
            ModelMappedInstrument mfrom = new ModelMappedInstrument(
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   621
                    (ModelInstrument)to, from.getPatch());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   622
            return loadInstrument(mfrom);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   623
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   624
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   625
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   626
    public Soundbank getDefaultSoundbank() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   627
        synchronized (SoftSynthesizer.class) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   628
            if (defaultSoundBank != null)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   629
                return defaultSoundBank;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   630
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   631
            List<PrivilegedAction<InputStream>> actions =
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   632
                new ArrayList<PrivilegedAction<InputStream>>();
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   633
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   634
            actions.add(new PrivilegedAction<InputStream>() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   635
                public InputStream run() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   636
                    File javahome = new File(System.getProperties()
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   637
                            .getProperty("java.home"));
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   638
                    File libaudio = new File(new File(javahome, "lib"), "audio");
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   639
                    if (libaudio.exists()) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   640
                        File foundfile = null;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   641
                        File[] files = libaudio.listFiles();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   642
                        if (files != null) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   643
                            for (int i = 0; i < files.length; i++) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   644
                                File file = files[i];
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   645
                                if (file.isFile()) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   646
                                    String lname = file.getName().toLowerCase();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   647
                                    if (lname.endsWith(".sf2")
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   648
                                            || lname.endsWith(".dls")) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   649
                                        if (foundfile == null
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   650
                                                || (file.length() > foundfile
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   651
                                                        .length())) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   652
                                            foundfile = file;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   653
                                        }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   654
                                    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   655
                                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   656
                            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   657
                        }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   658
                        if (foundfile != null) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   659
                            try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   660
                                return new FileInputStream(foundfile);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   661
                            } catch (IOException e) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   662
                            }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   663
                        }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   664
                    }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   665
                    return null;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   666
                }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   667
            });
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   668
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   669
            actions.add(new PrivilegedAction<InputStream>() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   670
                public InputStream run() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   671
                    if (System.getProperties().getProperty("os.name")
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   672
                            .startsWith("Windows")) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   673
                        File gm_dls = new File(System.getenv("SystemRoot")
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   674
                                + "\\system32\\drivers\\gm.dls");
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   675
                        if (gm_dls.exists()) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   676
                            try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   677
                                return new FileInputStream(gm_dls);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   678
                            } catch (IOException e) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   679
                            }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   680
                        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   681
                    }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   682
                    return null;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   683
                }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   684
            });
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   685
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   686
            actions.add(new PrivilegedAction<InputStream>() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   687
                public InputStream run() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   688
                    /*
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   689
                     * Try to load saved generated soundbank
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   690
                     */
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   691
                    File userhome = new File(System.getProperty("user.home"),
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   692
                            ".gervill");
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   693
                    File emg_soundbank_file = new File(userhome,
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   694
                            "soundbank-emg.sf2");
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   695
                    if (emg_soundbank_file.exists()) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   696
                        try {
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   697
                            return new FileInputStream(emg_soundbank_file);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   698
                        } catch (IOException e) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   699
                        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   700
                    }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   701
                    return null;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   702
                }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   703
            });
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   704
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   705
            for (PrivilegedAction<InputStream> action : actions) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   706
                try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   707
                    InputStream is = AccessController.doPrivileged(action);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   708
                    if(is == null) continue;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   709
                    Soundbank sbk;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   710
                    try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   711
                        sbk = MidiSystem.getSoundbank(new BufferedInputStream(is));
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   712
                    } finally {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   713
                        is.close();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   714
                    }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   715
                    if (sbk != null) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   716
                        defaultSoundBank = sbk;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   717
                        return defaultSoundBank;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   718
                    }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   719
                } catch (Exception e) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   720
                }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   721
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   722
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   723
            try {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   724
                /*
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   725
                 * Generate emergency soundbank
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   726
                 */
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   727
                defaultSoundBank = EmergencySoundbank.createSoundbank();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   728
            } catch (Exception e) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   729
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   730
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   731
            if (defaultSoundBank != null) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   732
                /*
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   733
                 * Save generated soundbank to disk for faster future use.
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   734
                 */
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   735
                OutputStream out = AccessController
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   736
                        .doPrivileged((PrivilegedAction<OutputStream>) () -> {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   737
                            try {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   738
                                File userhome = new File(System
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   739
                                        .getProperty("user.home"), ".gervill");
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   740
                                if (!userhome.exists()) {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   741
                                    userhome.mkdirs();
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   742
                                }
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   743
                                File emg_soundbank_file = new File(
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   744
                                        userhome, "soundbank-emg.sf2");
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   745
                                if (emg_soundbank_file.exists()) {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   746
                                    return null;
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   747
                                }
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   748
                                return new FileOutputStream(emg_soundbank_file);
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   749
                            } catch (final FileNotFoundException ignored) {
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   750
                            }
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   751
                            return null;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   752
                        });
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   753
                if (out != null) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   754
                    try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   755
                        ((SF2Soundbank) defaultSoundBank).save(out);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   756
                        out.close();
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   757
                    } catch (final IOException ignored) {
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   758
                    }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   759
                }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   760
            }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   761
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   762
        return defaultSoundBank;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   763
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   764
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   765
    public Instrument[] getAvailableInstruments() {
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   766
        Soundbank defsbk = getDefaultSoundbank();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   767
        if (defsbk == null)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   768
            return new Instrument[0];
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   769
        Instrument[] inslist_array = defsbk.getInstruments();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   770
        Arrays.sort(inslist_array, new ModelInstrumentComparator());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   771
        return inslist_array;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   772
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   773
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   774
    public Instrument[] getLoadedInstruments() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   775
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   776
            return new Instrument[0];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   777
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   778
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   779
            ModelInstrument[] inslist_array =
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   780
                    new ModelInstrument[loadedlist.values().size()];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   781
            loadedlist.values().toArray(inslist_array);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   782
            Arrays.sort(inslist_array, new ModelInstrumentComparator());
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   783
            return inslist_array;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   784
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   785
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   786
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   787
    public boolean loadAllInstruments(Soundbank soundbank) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   788
        List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   789
        for (Instrument ins: soundbank.getInstruments()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   790
            if (ins == null || !(ins instanceof ModelInstrument)) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   791
                throw new IllegalArgumentException(
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   792
                        "Unsupported instrument: " + ins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   793
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   794
            instruments.add((ModelInstrument)ins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   795
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   796
        return loadInstruments(instruments);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   797
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   798
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   799
    public void unloadAllInstruments(Soundbank soundbank) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   800
        if (soundbank == null || !isSoundbankSupported(soundbank))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   801
            throw new IllegalArgumentException("Unsupported soundbank: " + soundbank);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   802
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   803
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   804
            return;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   805
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   806
        for (Instrument ins: soundbank.getInstruments()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   807
            if (ins instanceof ModelInstrument) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   808
                unloadInstrument(ins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   809
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   810
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   811
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   812
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   813
    public boolean loadInstruments(Soundbank soundbank, Patch[] patchList) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   814
        List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   815
        for (Patch patch: patchList) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   816
            Instrument ins = soundbank.getInstrument(patch);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   817
            if (ins == null || !(ins instanceof ModelInstrument)) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   818
                throw new IllegalArgumentException(
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   819
                        "Unsupported instrument: " + ins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   820
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   821
            instruments.add((ModelInstrument)ins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   822
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   823
        return loadInstruments(instruments);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   824
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   825
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   826
    public void unloadInstruments(Soundbank soundbank, Patch[] patchList) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   827
        if (soundbank == null || !isSoundbankSupported(soundbank))
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   828
            throw new IllegalArgumentException("Unsupported soundbank: " + soundbank);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   829
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   830
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   831
            return;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   832
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   833
        for (Patch pat: patchList) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   834
            Instrument ins = soundbank.getInstrument(pat);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   835
            if (ins instanceof ModelInstrument) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   836
                unloadInstrument(ins);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   837
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   838
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   839
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   840
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   841
    public MidiDevice.Info getDeviceInfo() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   842
        return info;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   843
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   844
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   845
    private Properties getStoredProperties() {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   846
        return AccessController
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   847
                .doPrivileged((PrivilegedAction<Properties>) () -> {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   848
                    Properties p = new Properties();
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   849
                    String notePath = "/com/sun/media/sound/softsynthesizer";
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   850
                    try {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   851
                        Preferences prefroot = Preferences.userRoot();
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   852
                        if (prefroot.nodeExists(notePath)) {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   853
                            Preferences prefs = prefroot.node(notePath);
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   854
                            String[] prefs_keys = prefs.keys();
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   855
                            for (String prefs_key : prefs_keys) {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   856
                                String val = prefs.get(prefs_key, null);
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   857
                                if (val != null) {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   858
                                    p.setProperty(prefs_key, val);
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   859
                                }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   860
                            }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   861
                        }
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   862
                    } catch (final BackingStoreException ignored) {
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   863
                    }
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
   864
                    return p;
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   865
                });
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   866
    }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   867
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   868
    public AudioSynthesizerPropertyInfo[] getPropertyInfo(Map<String, Object> info) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   869
        List<AudioSynthesizerPropertyInfo> list =
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   870
                new ArrayList<AudioSynthesizerPropertyInfo>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   871
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   872
        AudioSynthesizerPropertyInfo item;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   873
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   874
        // If info != null or synthesizer is closed
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   875
        //   we return how the synthesizer will be set on next open
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   876
        // If info == null and synthesizer is open
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   877
        //   we return current synthesizer properties.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   878
        boolean o = info == null && open;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   879
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   880
        item = new AudioSynthesizerPropertyInfo("interpolation", o?resamplerType:"linear");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   881
        item.choices = new String[]{"linear", "linear1", "linear2", "cubic",
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   882
                                    "lanczos", "sinc", "point"};
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   883
        item.description = "Interpolation method";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   884
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   885
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   886
        item = new AudioSynthesizerPropertyInfo("control rate", o?controlrate:147f);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   887
        item.description = "Control rate";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   888
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   889
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   890
        item = new AudioSynthesizerPropertyInfo("format",
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   891
                o?format:new AudioFormat(44100, 16, 2, true, false));
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   892
        item.description = "Default audio format";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   893
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   894
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   895
        item = new AudioSynthesizerPropertyInfo("latency", o?latency:120000L);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   896
        item.description = "Default latency";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   897
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   898
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   899
        item = new AudioSynthesizerPropertyInfo("device id", o?deviceid:0);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   900
        item.description = "Device ID for SysEx Messages";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   901
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   902
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   903
        item = new AudioSynthesizerPropertyInfo("max polyphony", o?maxpoly:64);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   904
        item.description = "Maximum polyphony";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   905
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   906
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   907
        item = new AudioSynthesizerPropertyInfo("reverb", o?reverb_on:true);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   908
        item.description = "Turn reverb effect on or off";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   909
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   910
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   911
        item = new AudioSynthesizerPropertyInfo("chorus", o?chorus_on:true);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   912
        item.description = "Turn chorus effect on or off";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   913
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   914
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   915
        item = new AudioSynthesizerPropertyInfo("auto gain control", o?agc_on:true);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   916
        item.description = "Turn auto gain control on or off";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   917
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   918
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   919
        item = new AudioSynthesizerPropertyInfo("large mode", o?largemode:false);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   920
        item.description = "Turn large mode on or off.";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   921
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   922
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   923
        item = new AudioSynthesizerPropertyInfo("midi channels", o?channels.length:16);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   924
        item.description = "Number of midi channels.";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   925
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   926
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   927
        item = new AudioSynthesizerPropertyInfo("jitter correction", o?jitter_correction:true);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   928
        item.description = "Turn jitter correction on or off.";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   929
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   930
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   931
        item = new AudioSynthesizerPropertyInfo("light reverb", o?reverb_light:true);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   932
        item.description = "Turn light reverb mode on or off";
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   933
        list.add(item);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   934
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   935
        item = new AudioSynthesizerPropertyInfo("load default soundbank", o?load_default_soundbank:true);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   936
        item.description = "Enabled/disable loading default soundbank";
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   937
        list.add(item);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   938
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   939
        AudioSynthesizerPropertyInfo[] items;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   940
        items = list.toArray(new AudioSynthesizerPropertyInfo[list.size()]);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
   941
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   942
        Properties storedProperties = getStoredProperties();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   943
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   944
        for (AudioSynthesizerPropertyInfo item2 : items) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   945
            Object v = (info == null) ? null : info.get(item2.name);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   946
            v = (v != null) ? v : storedProperties.getProperty(item2.name);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   947
            if (v != null) {
24548
9c007a986347 8042256: Fix raw and unchecked lint warnings in com.sun.media.sound
darcy
parents: 18215
diff changeset
   948
                Class<?> c = (item2.valueClass);
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   949
                if (c.isInstance(v))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   950
                    item2.value = v;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   951
                else if (v instanceof String) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   952
                    String s = (String) v;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   953
                    if (c == Boolean.class) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   954
                        if (s.equalsIgnoreCase("true"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   955
                            item2.value = Boolean.TRUE;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   956
                        if (s.equalsIgnoreCase("false"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   957
                            item2.value = Boolean.FALSE;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   958
                    } else if (c == AudioFormat.class) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   959
                        int channels = 2;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   960
                        boolean signed = true;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   961
                        boolean bigendian = false;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   962
                        int bits = 16;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   963
                        float sampleRate = 44100f;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   964
                        try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   965
                            StringTokenizer st = new StringTokenizer(s, ", ");
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   966
                            String prevToken = "";
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   967
                            while (st.hasMoreTokens()) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   968
                                String token = st.nextToken().toLowerCase();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   969
                                if (token.equals("mono"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   970
                                    channels = 1;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   971
                                if (token.startsWith("channel"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   972
                                    channels = Integer.parseInt(prevToken);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   973
                                if (token.contains("unsigned"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   974
                                    signed = false;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   975
                                if (token.equals("big-endian"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   976
                                    bigendian = true;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   977
                                if (token.equals("bit"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   978
                                    bits = Integer.parseInt(prevToken);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   979
                                if (token.equals("hz"))
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   980
                                    sampleRate = Float.parseFloat(prevToken);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   981
                                prevToken = token;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   982
                            }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   983
                            item2.value = new AudioFormat(sampleRate, bits,
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   984
                                    channels, signed, bigendian);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   985
                        } catch (NumberFormatException e) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   986
                        }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   987
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   988
                    } else
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   989
                        try {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   990
                            if (c == Byte.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   991
                                item2.value = Byte.valueOf(s);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   992
                            else if (c == Short.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   993
                                item2.value = Short.valueOf(s);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   994
                            else if (c == Integer.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   995
                                item2.value = Integer.valueOf(s);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   996
                            else if (c == Long.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   997
                                item2.value = Long.valueOf(s);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   998
                            else if (c == Float.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
   999
                                item2.value = Float.valueOf(s);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1000
                            else if (c == Double.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1001
                                item2.value = Double.valueOf(s);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1002
                        } catch (NumberFormatException e) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1003
                        }
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1004
                } else if (v instanceof Number) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1005
                    Number n = (Number) v;
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1006
                    if (c == Byte.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1007
                        item2.value = Byte.valueOf(n.byteValue());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1008
                    if (c == Short.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1009
                        item2.value = Short.valueOf(n.shortValue());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1010
                    if (c == Integer.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1011
                        item2.value = Integer.valueOf(n.intValue());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1012
                    if (c == Long.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1013
                        item2.value = Long.valueOf(n.longValue());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1014
                    if (c == Float.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1015
                        item2.value = Float.valueOf(n.floatValue());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1016
                    if (c == Double.class)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1017
                        item2.value = Double.valueOf(n.doubleValue());
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1018
                }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1019
            }
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1020
        }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1021
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1022
        return items;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1023
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1024
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1025
    public void open() throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1026
        if (isOpen()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1027
            synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1028
                implicitOpen = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1029
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1030
            return;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1031
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1032
        open(null, null);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1033
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1034
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1035
    public void open(SourceDataLine line, Map<String, Object> info) throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1036
        if (isOpen()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1037
            synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1038
                implicitOpen = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1039
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1040
            return;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1041
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1042
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1043
            try {
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1044
                if (line != null) {
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1045
                    // can throw IllegalArgumentException
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1046
                    setFormat(line.getFormat());
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1047
                }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1048
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1049
                AudioInputStream ais = openStream(getFormat(), info);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1050
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1051
                weakstream = new WeakAudioStream(ais);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1052
                ais = weakstream.getAudioInputStream();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1053
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1054
                if (line == null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1055
                {
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1056
                    if (testline != null) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1057
                        line = testline;
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1058
                    } else {
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1059
                        // can throw LineUnavailableException,
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1060
                        // IllegalArgumentException, SecurityException
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1061
                        line = AudioSystem.getSourceDataLine(getFormat());
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1062
                    }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1063
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1064
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1065
                double latency = this.latency;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1066
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1067
                if (!line.isOpen()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1068
                    int bufferSize = getFormat().getFrameSize()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1069
                        * (int)(getFormat().getFrameRate() * (latency/1000000f));
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1070
                    // can throw LineUnavailableException,
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1071
                    // IllegalArgumentException, SecurityException
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1072
                    line.open(getFormat(), bufferSize);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1073
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1074
                    // Remember that we opened that line
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1075
                    // so we can close again in SoftSynthesizer.close()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1076
                    sourceDataLine = line;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1077
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1078
                if (!line.isActive())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1079
                    line.start();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1080
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1081
                int controlbuffersize = 512;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1082
                try {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1083
                    controlbuffersize = ais.available();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1084
                } catch (IOException e) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1085
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1086
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1087
                // Tell mixer not fill read buffers fully.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1088
                // This lowers latency, and tells DataPusher
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1089
                // to read in smaller amounts.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1090
                //mainmixer.readfully = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1091
                //pusher = new DataPusher(line, ais);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1092
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1093
                int buffersize = line.getBufferSize();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1094
                buffersize -= buffersize % controlbuffersize;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1095
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1096
                if (buffersize < 3 * controlbuffersize)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1097
                    buffersize = 3 * controlbuffersize;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1098
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1099
                if (jitter_correction) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1100
                    ais = new SoftJitterCorrector(ais, buffersize,
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1101
                            controlbuffersize);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1102
                    if(weakstream != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1103
                        weakstream.jitter_stream = ais;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1104
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1105
                pusher = new SoftAudioPusher(line, ais, controlbuffersize);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1106
                pusher_stream = ais;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1107
                pusher.start();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1108
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1109
                if(weakstream != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1110
                {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1111
                    weakstream.pusher = pusher;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1112
                    weakstream.sourceDataLine = sourceDataLine;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1113
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1114
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
  1115
            } catch (final LineUnavailableException | SecurityException
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
  1116
                    | IllegalArgumentException e) {
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
  1117
                if (isOpen()) {
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1118
                    close();
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
  1119
                }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1120
                // am: need MidiUnavailableException(Throwable) ctor!
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1121
                MidiUnavailableException ex = new MidiUnavailableException(
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1122
                        "Can not open line");
26030
576ffa819e23 8054372: Cleanup of com.sun.media.sound packages
serb
parents: 24548
diff changeset
  1123
                ex.initCause(e);
2654
64f93f554db6 6806019: 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46
amenkov
parents: 1846
diff changeset
  1124
                throw ex;
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1125
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1126
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1127
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1128
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1129
    public AudioInputStream openStream(AudioFormat targetFormat,
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1130
            Map<String, Object> info) throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1131
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1132
        if (isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1133
            throw new MidiUnavailableException("Synthesizer is already open");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1134
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1135
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1136
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1137
            gmmode = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1138
            voice_allocation_mode = 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1139
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1140
            processPropertyInfo(info);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1141
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1142
            open = true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1143
            implicitOpen = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1144
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1145
            if (targetFormat != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1146
                setFormat(targetFormat);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1147
6502
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1148
            if (load_default_soundbank)
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1149
            {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1150
                Soundbank defbank = getDefaultSoundbank();
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1151
                if (defbank != null) {
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1152
                    loadAllInstruments(defbank);
13b20559a04a 6941027: Gervill update, April 2010
kalli
parents: 5506
diff changeset
  1153
                }
1846
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1154
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1155
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1156
            voices = new SoftVoice[maxpoly];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1157
            for (int i = 0; i < maxpoly; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1158
                voices[i] = new SoftVoice(this);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1159
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1160
            mainmixer = new SoftMainMixer(this);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1161
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1162
            channels = new SoftChannel[number_of_midi_channels];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1163
            for (int i = 0; i < channels.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1164
                channels[i] = new SoftChannel(this, i);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1165
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1166
            if (external_channels == null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1167
                // Always create external_channels array
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1168
                // with 16 or more channels
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1169
                // so getChannels works correctly
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1170
                // when the synhtesizer is closed.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1171
                if (channels.length < 16)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1172
                    external_channels = new SoftChannelProxy[16];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1173
                else
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1174
                    external_channels = new SoftChannelProxy[channels.length];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1175
                for (int i = 0; i < external_channels.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1176
                    external_channels[i] = new SoftChannelProxy();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1177
            } else {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1178
                // We must resize external_channels array
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1179
                // but we must also copy the old SoftChannelProxy
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1180
                // into the new one
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1181
                if (channels.length > external_channels.length) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1182
                    SoftChannelProxy[] new_external_channels
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1183
                            = new SoftChannelProxy[channels.length];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1184
                    for (int i = 0; i < external_channels.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1185
                        new_external_channels[i] = external_channels[i];
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1186
                    for (int i = external_channels.length;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1187
                            i < new_external_channels.length; i++) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1188
                        new_external_channels[i] = new SoftChannelProxy();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1189
                    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1190
                }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1191
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1192
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1193
            for (int i = 0; i < channels.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1194
                external_channels[i].setChannel(channels[i]);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1195
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1196
            for (SoftVoice voice: getVoices())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1197
                voice.resampler = resampler.openStreamer();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1198
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1199
            for (Receiver recv: getReceivers()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1200
                SoftReceiver srecv = ((SoftReceiver)recv);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1201
                srecv.open = open;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1202
                srecv.mainmixer = mainmixer;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1203
                srecv.midimessages = mainmixer.midimessages;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1204
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1205
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1206
            return mainmixer.getInputStream();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1207
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1208
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1209
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1210
    public void close() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1211
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1212
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1213
            return;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1214
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1215
        SoftAudioPusher pusher_to_be_closed = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1216
        AudioInputStream pusher_stream_to_be_closed = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1217
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1218
            if (pusher != null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1219
                pusher_to_be_closed = pusher;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1220
                pusher_stream_to_be_closed = pusher_stream;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1221
                pusher = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1222
                pusher_stream = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1223
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1224
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1225
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1226
        if (pusher_to_be_closed != null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1227
            // Pusher must not be closed synchronized against control_mutex,
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1228
            // this may result in synchronized conflict between pusher
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1229
            // and current thread.
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1230
            pusher_to_be_closed.stop();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1231
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1232
            try {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1233
                pusher_stream_to_be_closed.close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1234
            } catch (IOException e) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1235
                //e.printStackTrace();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1236
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1237
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1238
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1239
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1240
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1241
            if (mainmixer != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1242
                mainmixer.close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1243
            open = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1244
            implicitOpen = false;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1245
            mainmixer = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1246
            voices = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1247
            channels = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1248
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1249
            if (external_channels != null)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1250
                for (int i = 0; i < external_channels.length; i++)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1251
                    external_channels[i].setChannel(null);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1252
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1253
            if (sourceDataLine != null) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1254
                sourceDataLine.close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1255
                sourceDataLine = null;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1256
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1257
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1258
            inslist.clear();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1259
            loadedlist.clear();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1260
            tunings.clear();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1261
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1262
            while (recvslist.size() != 0)
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1263
                recvslist.get(recvslist.size() - 1).close();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1264
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1265
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1266
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1267
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1268
    public boolean isOpen() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1269
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1270
            return open;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1271
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1272
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1273
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1274
    public long getMicrosecondPosition() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1275
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1276
        if (!isOpen())
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1277
            return 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1278
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1279
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1280
            return mainmixer.getMicrosecondPosition();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1281
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1282
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1283
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1284
    public int getMaxReceivers() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1285
        return -1;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1286
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1287
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1288
    public int getMaxTransmitters() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1289
        return 0;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1290
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1291
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1292
    public Receiver getReceiver() throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1293
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1294
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1295
            SoftReceiver receiver = new SoftReceiver(this);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1296
            receiver.open = open;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1297
            recvslist.add(receiver);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1298
            return receiver;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1299
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1300
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1301
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1302
    public List<Receiver> getReceivers() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1303
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1304
        synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1305
            ArrayList<Receiver> recvs = new ArrayList<Receiver>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1306
            recvs.addAll(recvslist);
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1307
            return recvs;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1308
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1309
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1310
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1311
    public Transmitter getTransmitter() throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1312
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1313
        throw new MidiUnavailableException("No transmitter available");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1314
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1315
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1316
    public List<Transmitter> getTransmitters() {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1317
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1318
        return new ArrayList<Transmitter>();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1319
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1320
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1321
    public Receiver getReceiverReferenceCounting()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1322
            throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1323
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1324
        if (!isOpen()) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1325
            open();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1326
            synchronized (control_mutex) {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1327
                implicitOpen = true;
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1328
            }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1329
        }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1330
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1331
        return getReceiver();
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1332
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1333
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1334
    public Transmitter getTransmitterReferenceCounting()
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1335
            throws MidiUnavailableException {
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1336
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1337
        throw new MidiUnavailableException("No transmitter available");
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1338
    }
4a53d636e2f4 6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
diff changeset
  1339
}