本文整理匯總了Java中javax.sound.midi.Synthesizer.getChannels方法的典型用法代碼示例。如果您正苦於以下問題:Java Synthesizer.getChannels方法的具體用法?Java Synthesizer.getChannels怎麽用?Java Synthesizer.getChannels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.Synthesizer
的用法示例。
在下文中一共展示了Synthesizer.getChannels方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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);
}
}
示例3: getChannel
import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
/**
* 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];
}
示例4: MidiChordPlayer
import javax.sound.midi.Synthesizer; //導入方法依賴的package包/類
public MidiChordPlayer() {
//TODO: do we really have to search for a free channel? - i mean: do
//we playback a score the same time when we play a chord?
Synthesizer synth = SynthManager.getSynthesizer();
for (int midichannel = 0; midichannel < 16; midichannel++) {
channel = synth.getChannels()[midichannel];
if (channel != null) {
break;
}
if (midichannel == 15 && channel == null) {
// No free midichannel => Now we have a Problem
// TODO no free midichannel
}
}
}
示例5: 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) {
}
}