本文整理汇总了Java中javax.sound.midi.MidiSystem.getSynthesizer方法的典型用法代码示例。如果您正苦于以下问题:Java MidiSystem.getSynthesizer方法的具体用法?Java MidiSystem.getSynthesizer怎么用?Java MidiSystem.getSynthesizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.getSynthesizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playWarningSound
import javax.sound.midi.MidiSystem; //导入方法依赖的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: open
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private void open () throws MidiUnavailableException{
synth = MidiSystem.getSynthesizer();
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
MidiDevice.Info msInfo = null;
StringBuilder sb = new StringBuilder();
sb.append("Available MidiDevice are\n");
for ( MidiDevice.Info i:infos ){
if ( i.toString().contains("Microsoft GS Wavetable Synth") ){
msInfo = i;
sb.append(" *****");
}
sb.append("\t" + i.toString() + ": " + i.getDescription() + '\n');
}
// MidiDevice msDevice = MidiSystem.getMidiDevice(msInfo);
synth.open();
sb.append("synth=" + synth.getDeviceInfo().toString() + " with default soundbank " + synth.getDefaultSoundbank().getDescription() + '\n');
sb.append("max synthesizer latency =" + synth.getLatency() + " us\n");
log.info(sb.toString());
channels = synth.getChannels();
channel = channels[PERCUSSION_CHANNEL];
}
示例3: main
import javax.sound.midi.MidiSystem; //导入方法依赖的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.");
}
示例4: openInput
import javax.sound.midi.MidiSystem; //导入方法依赖的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.");
}
示例5: init
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* This method initializes the MusicPlayer
*/
public static boolean init()
{
try
{
if (synth == null)
synth = MidiSystem.getSynthesizer();
if (!synth.isOpen())
synth.open();
return true;
} catch (MidiUnavailableException e)
{
e.printStackTrace();
return false;
}
}
示例6: findAudioSynthesizer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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;
}
示例7: setupMidi
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void setupMidi() throws Exception {
synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
midiChannels = synthesizer.getChannels();
sequencer = MidiSystem.getSequencer();
sequence = new Sequence(Sequence.PPQ, 10);
Soundbank sb = synthesizer.getDefaultSoundbank();
if (sb != null) {
instruments = synthesizer.getDefaultSoundbank().getInstruments();
for (int i = 0; i < instruments.length; i++) {
System.out.printf("%4d: %s%n", i, instruments[i]);
}
if (instruments.length > 0) {
synthesizer.loadInstrument(instruments[0]);
midiChannels[currentChannel].programChange(0);
}
if (instruments.length > 14) {
synthesizer.loadInstrument(instruments[14]);
midiChannels[currentChannel].programChange(14);
}
}
}
示例8: initSynthesizer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private boolean initSynthesizer() {
if (null == m_synth) {
try {
if (MidiSystem.getSequencer() == null) {
System.err.println("MidiSystem Sequencer Unavailable");
return false;
}
m_synth = MidiSystem.getSynthesizer();
m_synth.open();
m_sequencer = MidiSystem.getSequencer();
//m_sequencer.open();
}
catch (MidiUnavailableException e) {
System.err.println("Midi System Unavailable:" + e);
return false;
}
}
return true;
}
示例9: findAudioSynthesizer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* 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;
}
示例10: findAudioSynthesizer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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;
}
示例11: MIDIPlayer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
MIDIPlayer(int playerChannel, int playerProgram) {
this.zapis=new LinkedBlockingQueue(); // Ustvari izravnalnik
try {
this.sintetizator = MidiSystem.getSynthesizer(); // Ustvari napravo MIDI (glej Vajo 3)
this.sintetizator.open(); // Odpri napravo MIDI
} catch (MidiUnavailableException ex) {
ex.printStackTrace();
System.exit(1);
}
this.kanal = this.sintetizator.getChannels()[playerChannel]; // Doloci kanal MIID
kanal.programChange(playerProgram); // Doloci glasbilo http://en.wikipedia.org/wiki/General_MIDI
}
示例12: findAudioSynthesizer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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;
}
示例13: main
import javax.sound.midi.MidiSystem; //导入方法依赖的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);
}
示例14: SoundPlayer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public SoundPlayer() {
try {
synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
midiChannel = synthesizer.getChannels()[0];
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
}
示例15: onStartup
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Starts up this plugin. Obtains and opens the required MIDI devices and sets up receivers and transmitters. Any setters for MIDI
* devices must be invoked before the Sponge startup.
*/
@Override
public void onStartup() {
try {
logMidiSystemInfo();
// Use the default sequencer if not set.
if (sequencer == null) {
sequencer = MidiSystem.getSequencer(sequencerConnectedToSynthesizer);
if (sequencer == null) {
throw new SpongeException("The sequencer device is not supported");
}
}
// Use the default synthesizer if not set.
if (synthesizer == null) {
synthesizer = MidiSystem.getSynthesizer();
if (synthesizer == null) {
throw new SpongeException("The synthesizer device is not supported");
}
}
update();
if (loadAllInstruments) {
loadAllInstruments();
}
} catch (MidiUnavailableException e) {
throw SpongeUtils.wrapException(e);
}
}