本文整理匯總了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();
}
}
示例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.");
}
示例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.");
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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) {
}
}
示例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!");
}
示例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.");
}
}
示例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();
}
示例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();
}
}
示例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;
}