當前位置: 首頁>>代碼示例>>Java>>正文


Java Synthesizer.isOpen方法代碼示例

本文整理匯總了Java中javax.sound.midi.Synthesizer.isOpen方法的典型用法代碼示例。如果您正苦於以下問題:Java Synthesizer.isOpen方法的具體用法?Java Synthesizer.isOpen怎麽用?Java Synthesizer.isOpen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.midi.Synthesizer的用法示例。


在下文中一共展示了Synthesizer.isOpen方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: allNotesOff

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:d2fn,項目名稱:passage,代碼行數:20,代碼來源:Player.java

示例2: main

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Field f = SoftSynthesizer.class.getDeclaredField("testline");
    f.setAccessible(true);
    f.set(null, new DummySourceDataLine());

    Synthesizer synth = new SoftSynthesizer();

    ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth;

    // Test single open/close cycle

    Receiver recv = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv.close();
    if(synth.isOpen())
        throw new Exception("Synthesizer not closed!");

    // Test using 2 receiver cycle

    Receiver recv1 = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    Receiver recv2 = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
        throw new Exception("Synthesizer not open!");

    recv2.close();
    if(!synth.isOpen())
        throw new Exception("Synthesizer was closed!");
    recv1.close();
    if(synth.isOpen())
        throw new Exception("Synthesizer not closed!");

    // Test for explicit,implicit conflict

    synth.open();
    Receiver recv3 = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv3.close();
    if(!synth.isOpen())
        throw new Exception("Synthesizer was closed!");
    synth.close();
    if(synth.isOpen())
        throw new Exception("Synthesizer not closed!");

    // Test for implicit,explicit conflict

    recv3 = rcd.getReceiverReferenceCounting();
    synth.open();
    if(!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv3.close();
    if(!synth.isOpen())
        throw new Exception("Synthesizer was closed!");
    synth.close();
    if(synth.isOpen())
        throw new Exception("Synthesizer not closed!");

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:62,代碼來源:ImplicitOpenClose.java

示例3: getSequencerConnectedToSynthesizer

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
/**
 * Returns an instance of a Sequencer that uses the provided Synthesizer as its receiver.
 * This is useful when you have made changes to a specific Synthesizer--for example, you've
 * loaded in new patches--that you want the Sequencer to use.  You can then pass the Sequencer
 * to the Player constructor.
 *
 * @param synth The Synthesizer to use as the receiver for the returned Sequencer
 * @return a Sequencer with the provided Synthesizer as its receiver
 * @throws MidiUnavailableException
 * @version 4.0
 */
public static Sequencer getSequencerConnectedToSynthesizer(Synthesizer synth) throws MidiUnavailableException
{
    Sequencer sequencer = MidiSystem.getSequencer(false); // Get Sequencer which is not connected to new Synthesizer.
    sequencer.open();
    if (!synth.isOpen()) {
        synth.open();
    }
    sequencer.getTransmitter().setReceiver(synth.getReceiver()); // Connect the Synthesizer to our synthesizer instance.
    return sequencer;
}
 
開發者ID:d2fn,項目名稱:passage,代碼行數:22,代碼來源:Player.java


注:本文中的javax.sound.midi.Synthesizer.isOpen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。