Search in sources :

Example 11 with Receiver

use of javax.sound.midi.Receiver in project jdk8u_jdk by JetBrains.

the class SoftSynthesizer method openStream.

public AudioInputStream openStream(AudioFormat targetFormat, Map<String, Object> info) throws MidiUnavailableException {
    if (isOpen())
        throw new MidiUnavailableException("Synthesizer is already open");
    synchronized (control_mutex) {
        gmmode = 0;
        voice_allocation_mode = 0;
        processPropertyInfo(info);
        open = true;
        implicitOpen = false;
        if (targetFormat != null)
            setFormat(targetFormat);
        if (load_default_soundbank) {
            Soundbank defbank = getDefaultSoundbank();
            if (defbank != null) {
                loadAllInstruments(defbank);
            }
        }
        voices = new SoftVoice[maxpoly];
        for (int i = 0; i < maxpoly; i++) voices[i] = new SoftVoice(this);
        mainmixer = new SoftMainMixer(this);
        channels = new SoftChannel[number_of_midi_channels];
        for (int i = 0; i < channels.length; i++) channels[i] = new SoftChannel(this, i);
        if (external_channels == null) {
            // when the synhtesizer is closed.
            if (channels.length < 16)
                external_channels = new SoftChannelProxy[16];
            else
                external_channels = new SoftChannelProxy[channels.length];
            for (int i = 0; i < external_channels.length; i++) external_channels[i] = new SoftChannelProxy();
        } else {
            // into the new one
            if (channels.length > external_channels.length) {
                SoftChannelProxy[] new_external_channels = new SoftChannelProxy[channels.length];
                for (int i = 0; i < external_channels.length; i++) new_external_channels[i] = external_channels[i];
                for (int i = external_channels.length; i < new_external_channels.length; i++) {
                    new_external_channels[i] = new SoftChannelProxy();
                }
            }
        }
        for (int i = 0; i < channels.length; i++) external_channels[i].setChannel(channels[i]);
        for (SoftVoice voice : getVoices()) voice.resampler = resampler.openStreamer();
        for (Receiver recv : getReceivers()) {
            SoftReceiver srecv = ((SoftReceiver) recv);
            srecv.open = open;
            srecv.mainmixer = mainmixer;
            srecv.midimessages = mainmixer.midimessages;
        }
        return mainmixer.getInputStream();
    }
}
Also used : MidiUnavailableException(javax.sound.midi.MidiUnavailableException) Soundbank(javax.sound.midi.Soundbank) Receiver(javax.sound.midi.Receiver)

Aggregations

Receiver (javax.sound.midi.Receiver)11 MidiUnavailableException (javax.sound.midi.MidiUnavailableException)4 AudioSynthesizer (com.sun.media.sound.AudioSynthesizer)3 SoftSynthesizer (com.sun.media.sound.SoftSynthesizer)3 MidiDevice (javax.sound.midi.MidiDevice)2 MidiDeviceReceiver (javax.sound.midi.MidiDeviceReceiver)2 ShortMessage (javax.sound.midi.ShortMessage)2 Transmitter (javax.sound.midi.Transmitter)2 AudioInputStream (javax.sound.sampled.AudioInputStream)2 SoftReceiver (com.sun.media.sound.SoftReceiver)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Random (java.util.Random)1 MetaMessage (javax.sound.midi.MetaMessage)1 MidiDeviceTransmitter (javax.sound.midi.MidiDeviceTransmitter)1 MidiEvent (javax.sound.midi.MidiEvent)1 MidiMessage (javax.sound.midi.MidiMessage)1 Soundbank (javax.sound.midi.Soundbank)1 Synthesizer (javax.sound.midi.Synthesizer)1 Track (javax.sound.midi.Track)1