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


Java Synthesizer.open方法代碼示例

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


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

示例1: playWarningSound

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

示例2: main

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

示例3: openInput

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
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.");

}
 
開發者ID:helionmusic,項目名稱:launchpad_s_plus,代碼行數:23,代碼來源:MidiInDump.java

示例4: 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

示例5: main

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

示例6: main

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public static void main(String[  ] args) throws MidiUnavailableException
{
    // We don't need a Sequencer in this example, since we send MIDI
    // events directly to the Synthesizer instead.
    Synthesizer synthesizer = MidiSystem.getSynthesizer( );
    synthesizer.open( );
    JFrame frame = new KeyboardDrumsDemo(synthesizer);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(50, 128);  // We use window width as volume control
    frame.setVisible(true);
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:13,代碼來源:KeyboardDrumsDemo.java

示例7: initLotroSynthesizer

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public static void initLotroSynthesizer(Synthesizer synth) throws MidiUnavailableException,
		InvalidMidiDataException, IOException
{
	synth.open();
	synth.unloadAllInstruments(getLotroSoundbank());
	synth.loadAllInstruments(getLotroSoundbank());
}
 
開發者ID:digero,項目名稱:maestro,代碼行數:8,代碼來源:SynthesizerFactory.java

示例8: getSequencer

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
/**
	 * Returns a {@link Sequencer} to play a {@link Sequence}.
	 *
	 * @param sequence for {@link Sequencer}
	 * @return MIDI {@link Sequencer}
	 * @throws MidiUnavailableException
	 * @throws InvalidMidiDataException
	 * @see Sequence
	 * @see Sequencer
	 * @since 0.0.1
	 */
	public static Sequencer getSequencer(final Sequence sequence) throws MidiUnavailableException, InvalidMidiDataException { //$JUnit$
		if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(sequence));
		if (null == sequence) {
			throw new RuntimeExceptionIsNull("sequence"); //$NON-NLS-1$
		}

		final Sequencer result = MidiSystem.getSequencer();  // Used to play sequences
		result.open(); // Turn it on.

		// Get a Synthesizer for the Sequencer to send notes to
//		try (Synthesizer synth = MidiSystem.getSynthesizer()) {
			final Synthesizer synth = MidiSystem.getSynthesizer();
			synth.open();  // acquire whatever resources it needs
	
			// The Sequencer obtained above may be connected to a Synthesizer
			// by default, or it may not.  Therefore, we explicitly connect it.
//			try (Transmitter transmitter = result.getTransmitter()) {
				final Transmitter transmitter = result.getTransmitter();
				transmitter.setReceiver(synth.getReceiver());
//			}
//		}
		// Read the sequence from the file and tell the sequencer about it
		result.setSequence(sequence);

		if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
		return result;
	}
 
開發者ID:slaubenberger,項目名稱:wichtel,代碼行數:39,代碼來源:HelperSound.java

示例9: setVolume

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public void setVolume(float volume) {
    try {
        this.volume = volume;
        Synthesizer synthesizer = MidiSystem.getSynthesizer();
        synthesizer.open();
        MidiChannel[] channels = synthesizer.getChannels();
        for (MidiChannel channel : channels) {
            if (channel != null) {
                channel.controlChange(7, (int) volume);
            }
        }
    } catch (Exception ex) {
    }
}
 
開發者ID:IvyBits,項目名稱:Amber-IDE,代碼行數:15,代碼來源:MidiAudio.java

示例10: 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

示例11: main

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public static void main(String args[]) throws Exception {
    Synthesizer synth = null;
    boolean failed = false;
    boolean notexec = false;
    try {
        synth = MidiSystem.getSynthesizer();
        System.out.println("Got synth: "+synth);
        synth.open();

        int latency = (int) synth.getLatency();
        System.out.println("  -> latency: "
                           +latency
                           +" microseconds");
        if (latency < 5000 && latency > 0) {
            System.out.println("## This latency is VERY small, probably due to this bug.");
            System.out.println("## This causes failure of this test.");
            failed = true;
        }
    } catch (MidiUnavailableException mue) {
        System.err.println("MidiUnavailableException was "
                           +"thrown: " + mue);
        System.out.println("could not test.");
        notexec = true;
    } catch(SecurityException se) {
        se.printStackTrace();
        System.err.println("Sound access is not denied but "
        + "SecurityException was thrown!");
        notexec = true;
    } finally {
        if (synth != null) synth.close();
    }


    if (failed) {
        throw new Exception("Test FAILED!");
    }
    if (notexec) {
        System.out.println("Test not failed.");
    } else {
        System.out.println("Test Passed.");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:43,代碼來源:SynthesizerGetLatency.java

示例12: JavaMidiSynthesizerTarget

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
protected JavaMidiSynthesizerTarget(Synthesizer synth, int threadPriority, boolean realTime) throws MidiUnavailableException {
	super(threadPriority, realTime);
	this.synth = synth;
	synth.open();
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:6,代碼來源:JavaMidiSynthesizerTarget.java

示例13: main

import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public static void main(String args[]) {
    try {
        for (MidiDevice.Info inf : MidiSystem.getMidiDeviceInfo()) {

            if (inf.getName().equals("Gervill")) {

                Synthesizer dev = (Synthesizer) MidiSystem.getMidiDevice(inf);
                dev.open();


                //   String sf = "/home/pjl/frinika/soundfonts/Club.SF2";
              //  String sf = "/home/pjl/frinika/soundfonts/8MBGMSFX.SF2";
                String sf="/home/pjl/frinika/soundfonts/ChoriumRevA.SF2";
                Soundbank sbk;
                sbk = MidiSystem.getSoundbank(new File(sf));
                dev.loadAllInstruments(sbk);

                Instrument insts[] = dev.getLoadedInstruments();
                //  Instrument insts[] = dev.getAvailableInstruments();
                for (Instrument ins : insts) {
                    System.out.print("\n ***************** INST :" + ins);
                    System.out.println(ins.getName() + " " + ins.getPatch().getBank() + " " + ins.getPatch().getProgram() + " ");

                    Method getChannels = ins.getClass().getMethod(
                            "getChannels");
                    boolean[] channels = null;

                    if (getChannels != null) {
                        channels = (boolean[]) getChannels.invoke(ins, (Object[]) null);


                        if (channels[9]) {
                            Method getKeys = ins.getClass().getMethod(
                                    "getKeys");
                            if (getKeys != null) {
                                String[] keyNames = (String[]) getKeys.invoke(ins, (Object[]) null);
                                int i = 0;
                                for (String keyname : keyNames) {
                                   if (keyname != null) System.out.println((i++) + ":" + keyname);

                                }

                            }
                        }

                    }
                }
            }

        }
        System.out.println(" HIT cntrl-C ");
        Thread.sleep(100000);
    } catch (Exception ex) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex1) {
            Logger.getLogger(ListKeyNames.class.getName()).log(Level.SEVERE, null, ex1);
        }
        ex.printStackTrace();

    }
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:63,代碼來源:ListKeyNames.java

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