Java 类javax.sound.midi.Synthesizer 实例源码

项目:OpenJSharp    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:jdk8u-jdk    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:openjdk-jdk10    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:openjdk-jdk10    文件:OpenClose.java   
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
public static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    return result;
}
项目:openjdk-jdk10    文件:ClosedReceiver.java   
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
private static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = !(device instanceof Sequencer)
                    && !(device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    return result;
}
项目:openjdk-jdk10    文件:MidiOutGetMicrosecondPositionBug.java   
private static void doAll() throws Exception {
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i=0; i < infos.length; i++) {
        MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
        if ((! (device instanceof Sequencer)) &&
            (! (device instanceof Synthesizer)) &&
            (device.getMaxReceivers() > 0 || device.getMaxReceivers() == -1)) {

            System.out.println("--------------");
            System.out.println("Testing MIDI device: " + infos[i]);
            testDevice(device);
        }
        if (infos.length==0) {
            System.out.println("No MIDI devices available!");
        }
    }
}
项目:openjdk-jdk10    文件:MidiOutGetMicrosecondPositionBug.java   
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
public static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
项目:openjdk-jdk10    文件:ExtraCharInSoundbank.java   
public static boolean checkInstrumentNames(Synthesizer theSynthesizer)
{
    boolean containsControlCharacters = false;

    Instrument[] theLoadedInstruments = theSynthesizer.getLoadedInstruments();

    System.out.println("Checking soundbank...");
    for(int theInstrumentIndex = 0; theInstrumentIndex < theLoadedInstruments.length; theInstrumentIndex++) {
        String name = theLoadedInstruments[theInstrumentIndex].getName();
        if (containsControlChar(name)) {
            containsControlCharacters = true;
            System.out.print("Instrument[" + theInstrumentIndex + "] contains unexpected control characters: ");
            printName(name);
        }
    }
    return !containsControlCharacters;
}
项目:openjdk-jdk10    文件:ExtraCharInSoundbank.java   
public static void main(String[] args) throws Exception {
    // the internal synthesizer needs a soundcard to work properly
    if (!isSoundcardInstalled()) {
        return;
    }
    Synthesizer theSynth = MidiSystem.getSynthesizer();
    System.out.println("Got synth: "+theSynth);
    theSynth.open();
    try {
        Soundbank theSoundbank = theSynth.getDefaultSoundbank();
        System.out.println("Got soundbank: "+theSoundbank);
        theSynth.loadAllInstruments(theSoundbank);
        try {
                if (!checkInstrumentNames(theSynth)) {
                        throw new Exception("Test failed");
                }
        } finally {
                theSynth.unloadAllInstruments(theSoundbank);
        }
    } finally {
        theSynth.close();
    }
    System.out.println("Test passed.");
}
项目:openjdk9    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:launchpad_s_plus    文件:MidiInDump.java   
public static void openInput() throws Exception {
    setup();

    if (bUseDefaultSynthesizer) {
        Synthesizer synth = MidiSystem.getSynthesizer();
        synth.open();
        r = synth.getReceiver();
        try {
            Transmitter t = launchpad_s_plus.Launchpad.getInputDevice()
                    .getTransmitter();
            t.setReceiver(r);
        } catch (MidiUnavailableException e) {
            out("wasn't able to connect the device's Transmitter to the default Synthesizer:");
            out(e);
            launchpad_s_plus.Launchpad.getInputDevice().close();
            System.exit(1);
        }
    }

    out("\nNow taking input.");

}
项目:jdk8u_jdk    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:lookaside_java-1.8.0-openjdk    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:iSeleda    文件:Dialogs.java   
private static void playWarningSound() {
//        if (2 > 1) {
//            return;
//        }

        try {
//            int velocity = 127;    // max volume
            int velocity = 90;    // max volume
            int sound = 65;
            Synthesizer synthesizer = MidiSystem.getSynthesizer();
            synthesizer.open();
            MidiChannel channel = synthesizer.getChannels()[9];  // drums channel.
            for (int i = 0; i < 10; i++) {
                Thread.sleep(100);
                channel.noteOn(sound + i, velocity);
                Thread.sleep(100);
                channel.noteOff(sound + i);
            }
        } catch (MidiUnavailableException | InterruptedException e1) {
            e1.printStackTrace();
        }
    }
项目:TuxGuitar-1.3.1-fork    文件:MidiPortSynthesizer.java   
public Synthesizer getSynth() {
    try {
        if(!this.synth.isOpen()){
            this.synth.open();
            if(!isSoundbankLoaded( false )){
                String path = MidiConfigUtils.getSoundbankPath(this.context);
                if( path != null ){
                    this.loadSoundbank(new File(TGExpressionResolver.getInstance(this.context).resolve(path)));
                }

                if(!isSoundbankLoaded( true )){
                    this.loadSoundbank(this.synth.getDefaultSoundbank());
                }

                if(!isSoundbankLoaded( true )){
                    new SBAssistant(this.context, this).process();
                }
            }
        }
        this.synthesizerLoaded = this.synth.isOpen();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return this.synth;
}
项目:TuxGuitar-1.3.1-fork    文件:MidiPortSynthesizer.java   
public Synthesizer getSynth() {
    try {
        if(!this.synth.isOpen()){
            this.synth.open();
            if(!isSoundbankLoaded( false )){
                if(!isSoundbankLoaded( true )){
                    this.loadSoundbank(this.synth.getDefaultSoundbank());
                }
            }
        }
        this.synthesizerLoaded = this.synth.isOpen();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return this.synth;
}
项目:ether    文件:URLAudioSource.java   
private Synthesizer findAudioSynthesizer() throws MidiUnavailableException, ClassNotFoundException {
    Class<?> audioSynth = Class.forName("com.sun.media.sound.AudioSynthesizer");

    // First check if default synthesizer is AudioSynthesizer.
    Synthesizer synth = MidiSystem.getSynthesizer();
    if (audioSynth.isAssignableFrom(synth.getClass())) {
        return synth;
    }

    // If default synthesizer is not AudioSynthesizer, check others.
    MidiDevice.Info[] midiDeviceInfo = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < midiDeviceInfo.length; i++) {
        MidiDevice dev = MidiSystem.getMidiDevice(midiDeviceInfo[i]);
        if (audioSynth.isAssignableFrom(dev.getClass())) {
            return (Synthesizer)dev;
        }
    }
    return null;
}
项目:launchpad_s_plus    文件:MidiInDump.java   
public static void openInput() throws Exception {
    setup();

    if (bUseDefaultSynthesizer) {
        Synthesizer synth = MidiSystem.getSynthesizer();
        synth.open();
        r = synth.getReceiver();
        try {
            Transmitter t = launchpad_s_plus.Launchpad.getInputDevice()
                    .getTransmitter();
            t.setReceiver(r);
        } catch (MidiUnavailableException e) {
            out("wasn't able to connect the device's Transmitter to the default Synthesizer:");
            out(e);
            launchpad_s_plus.Launchpad.getInputDevice().close();
            System.exit(1);
        }
    }

    out("\nNow taking input.");

}
项目:infobip-open-jdk-8    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:jdk8u-dev-jdk    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:frinika    文件:SynthesizerDescriptor.java   
@Override
protected void installImp(ProjectContainer project) {
    super.installImp(project);
    if(soundBankFileName != null)
    try
    {           
        Soundbank soundbank;
        if(midiDevice instanceof SynthWrapper)
            soundbank = ((SynthWrapper)midiDevice).getSoundbank(new File(soundBankFileName));
        else
            soundbank = MidiSystem.getSoundbank(new File(soundBankFileName));           
        ((Synthesizer)midiDevice).loadAllInstruments(soundbank);
        System.out.println("Soundbank loaded");
    } catch(Exception e){
        e.printStackTrace();
    }
}
项目:frinika    文件:MidiResource.java   
/**
 * Return a list of voices for a device. if device does not provide a list
 * return null.
 * 
 * @param dev
 * @param channel
 * @return
 */
public PatchNameMap getVoiceList(MidiDevice dev, int channel) {
    if (! (dev instanceof SynthWrapper) ) return null;
    assert (dev instanceof SynthWrapper);
    if (channel < 0 ) return null;  // Make channel -1 someone elses problem since we will get an array exception
    // use first part of the device string.
    // TODO think ??? Still thinking PJL ?? :) /PJS
    // Still think this is all a bit ugly PJL

    if(((SynthWrapper)dev).getRealDevice() instanceof Synthesizer)  {
        return new PatchNameMap((Synthesizer)dev, channel);
    } else if (((SynthWrapper)dev).getRealDevice() instanceof DrumMapper ){
        return null;
    } else  {
        String lookup = dev.getDeviceInfo().toString().split("\\s")[0];

        PatchNameMap vl = voiceTreeMap.get(lookup);
        if (vl == null) {
            System.out.println(" Could not find voice map for \"" + lookup
                    + "\"");
            return voiceTreeMap.get("default");
        }
        return vl;
    }
}
项目:maestro    文件:SynthesizerFactory.java   
/**
 * Find available AudioSynthesizer
 */
public static AudioSynthesizer findAudioSynthesizer() throws MidiUnavailableException
{
    // First check if default synthesizer is AudioSynthesizer.
    Synthesizer synth = MidiSystem.getSynthesizer();
    if (synth instanceof AudioSynthesizer)
        return (AudioSynthesizer) synth;

    // If default synhtesizer is not AudioSynthesizer, check others.
    for (Info info : MidiSystem.getMidiDeviceInfo())
    {
        MidiDevice dev = MidiSystem.getMidiDevice(info);
        if (dev instanceof AudioSynthesizer)
            return (AudioSynthesizer) dev;
    }

    // No AudioSynthesizer was found, return null.
    return null;
}
项目:jdk7-jdk    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:computoser    文件:Midi2WavRenderer.java   
public static AudioSynthesizer findAudioSynthesizer() throws MidiUnavailableException, IOException, InvalidMidiDataException {
    // First check if default synthesizer is AudioSynthesizer.
    Synthesizer synth = MidiSystem.getSynthesizer();
    if (synth instanceof AudioSynthesizer) {
        return (AudioSynthesizer) synth;
    }

    // If default synhtesizer is not AudioSynthesizer, check others.
    Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        MidiDevice dev = MidiSystem.getMidiDevice(infos[i]);
        if (dev instanceof AudioSynthesizer) {
            return (AudioSynthesizer) dev;
        }
    }

    // No AudioSynthesizer was found, return null.
    return null;
}
项目:openjdk-source-code-learn    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:passage    文件:Player.java   
/**
 * Stops all notes from playing on all MIDI channels.
 */
public static void allNotesOff(Synthesizer synth)
{
    try {
        if (!synth.isOpen()) {
            synth.open();
        }
        MidiChannel[] channels = synth.getChannels();
        for (int i=0; i < channels.length; i++)
        {
            channels[i].allNotesOff();
        }
    } catch (MidiUnavailableException e)
    {
        throw new JFugueException(JFugueException.GENERAL_ERROR);
    }
}
项目:RipplePower    文件:LMidiSound.java   
public LMidiSound() {
    if (rendererStatus == UNINITIALIZED) {
        rendererStatus = INITIALIZING;
        Thread thread = new Thread() {
            public final void run() {
                try {

                    Sequencer sequencer = MidiSystem.getSequencer();
                    sequencer.open();
                    volumeSupported = (sequencer instanceof Synthesizer);

                    sequencer.close();
                    available = true;
                } catch (Throwable e) {
                    available = false;
                }
                rendererStatus = INITIALIZED;
            }
        };
        thread.setDaemon(true);
        thread.start();
    }
}
项目:RipplePower    文件:LMidiSound.java   
public LMidiSound(String fileName) throws IOException {
    bytes = new ArrayByte(UIRes.getStream(fileName), ArrayByte.BIG_ENDIAN);
    if (rendererStatus == UNINITIALIZED) {
        rendererStatus = INITIALIZING;
        Thread thread = new Thread() {
            public final void run() {
                try {

                    Sequencer sequencer = MidiSystem.getSequencer();
                    sequencer.open();
                    volumeSupported = (sequencer instanceof Synthesizer);

                    sequencer.close();
                    available = true;
                } catch (Throwable e) {
                    available = false;
                }
                rendererStatus = INITIALIZED;
            }
        };
        thread.setDaemon(true);
        thread.start();
    }
}
项目:OLD-OpenJDK8    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:openjdk-jdk7u-jdk    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:totallicks-tuxguitar    文件:MidiPortSynthesizer.java   
public Synthesizer getSynthesizer() {
    try {
        if(!this.synthesizer.isOpen()){
            this.synthesizer.open();
            if(!isSoundbankLoaded( false )){
                String path = MidiConfigUtils.getSoundbankPath();
                if(path != null){
                    this.loadSoundbank(new File(path));
                }

                if(!isSoundbankLoaded( true )){
                    this.loadSoundbank( this.synthesizer.getDefaultSoundbank() );
                }

                if(!isSoundbankLoaded( true )){
                    new SBAssistant(this).process();
                }
            }
        }
        this.synthesizerLoaded = this.synthesizer.isOpen();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return this.synthesizer;
}
项目:openjdk-icedtea7    文件:JDK13Services.java   
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:gervill    文件:SimpleMidiPlayer.java   
public static AudioSynthesizer findAudioSynthesizer()
        throws MidiUnavailableException {
    // First check if default synthesizer is AudioSynthesizer.
    Synthesizer synth = MidiSystem.getSynthesizer();
    if (synth instanceof AudioSynthesizer)
        return (AudioSynthesizer) synth;

    // If default synhtesizer is not AudioSynthesizer, check others.
    Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        MidiDevice dev = MidiSystem.getMidiDevice(infos[i]);
        if (dev instanceof AudioSynthesizer)
            return (AudioSynthesizer) dev;
    }

    // No AudioSynthesizer was found, return null.
    return null;
}
项目:gervill    文件:FMTest1.java   
public static void main(String[] args) throws Exception {

    Synthesizer synth = MidiSystem.getSynthesizer();
    synth.open();
    synth.unloadAllInstruments(synth.getDefaultSoundbank());
    synth.loadAllInstruments(new MyOscillator());
    Sequence seq = MidiSystem.getSequence(FMTest1.class.getResource("/FMTest1.mid"));
    Sequencer seqr = MidiSystem.getSequencer(false);
    seqr.open();
    seqr.getTransmitter().setReceiver(synth.getReceiver());
    seqr.setSequence(seq);
    seqr.start();

    System.out.println();
    System.out.println("Is active, press enter to stop");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    br.readLine();
    System.out.println("Stop...");

    seqr.stop();
    seqr.close();
    synth.close();

    System.exit(0);
}
项目:gervill    文件:Midi2WavRender.java   
public static AudioSynthesizer findAudioSynthesizer()
        throws MidiUnavailableException {
    // First check if default synthesizer is AudioSynthesizer.
    Synthesizer synth = MidiSystem.getSynthesizer();
    if (synth instanceof AudioSynthesizer)
        return (AudioSynthesizer) synth;

    // If default synhtesizer is not AudioSynthesizer, check others.
    Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        MidiDevice dev = MidiSystem.getMidiDevice(infos[i]);
        if (dev instanceof AudioSynthesizer)
            return (AudioSynthesizer) dev;
    }

    // No AudioSynthesizer was found, return null.
    return null;
}
项目:sponge    文件:MidiPlugin.java   
/**
 * Sets the synthesizer. If there has already been an another synthesizer set then it will be closed.
 *
 * @param synthesizer the synthesizer.
 */
public void setSynthesizer(Synthesizer synthesizer) {
    if (synthesizer != this.synthesizer) {
        MidiUtils.close(this.synthesizer);
    }

    this.synthesizer = synthesizer;
}
项目:sponge    文件:MidiUtils.java   
/**
 * Loads a MIDI instrument by name. Throws exception if not found.
 *
 * @param synthesizer the synthesizer.
 * @param instrumentName the instrument name.
 * @return the instrument or {@code null} if the instrument couldn't be loaded.
 */
public static Instrument loadInstrument(Synthesizer synthesizer, String instrumentName) {
    Optional<Instrument> result = Arrays.stream(synthesizer.getAvailableInstruments())
            .filter(instrument -> instrument.getName().equals(instrumentName)).findFirst();

    if (!result.isPresent()) {
        throw new IllegalArgumentException("Instrument named " + instrumentName + " is not available");
    }

    return synthesizer.loadInstrument(result.get()) ? result.get() : null;
}
项目:sponge    文件:MidiUtils.java   
/**
 * Returns the MIDI channel.
 *
 * @param synthesizer the synthesizer.
 * @param channel the channel number.
 * @param required if {@code true} then throws exception when not found or not available. Otherwise returns {@code null}.
 * @return the MIDI channel.
 */
public static MidiChannel getChannel(Synthesizer synthesizer, int channel, boolean required) {
    MidiChannel[] channels = synthesizer.getChannels();
    if (channel >= channels.length || channels[channel] == null) {
        if (required) {
            throw new IllegalArgumentException("Channel " + channel + " is not available");
        } else {
            return null;
        }
    }

    return channels[channel];
}
项目:sponge    文件:MidiUtils.java   
/**
 * Sets the synthesizer instrument from the currently selected bank of instruments.
 *
 * @param synthesizer the synthesizer.
 * @param channel the channel.
 * @param instrumentName the instrument name.
 * @return the new instrument.
 */
public static Instrument setInstrument(Synthesizer synthesizer, int channel, String instrumentName) {
    Optional<Instrument> result = Arrays.stream(synthesizer.getAvailableInstruments())
            .filter(instrument -> instrument.getName().equals(instrumentName)).findFirst();

    if (!result.isPresent()) {
        throw new IllegalArgumentException("Instrument named " + instrumentName + " is not available");
    }

    return setInstrument(synthesizer, channel, result.get().getPatch().getProgram());
}