本文整理汇总了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) {
}
}