当前位置: 首页>>代码示例>>Java>>正文


Java Synthesizer.getChannels方法代码示例

本文整理汇总了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();
        }
    }
 
开发者ID:teddyted,项目名称:iSeleda,代码行数:23,代码来源:Dialogs.java

示例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);
    }
}
 
开发者ID:d2fn,项目名称:passage,代码行数:20,代码来源:Player.java

示例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];
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:21,代码来源:MidiUtils.java

示例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
		}
	}
}
 
开发者ID:Xenoage,项目名称:Zong,代码行数:16,代码来源:MidiChordPlayer.java

示例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) {
    }
}
 
开发者ID:IvyBits,项目名称:Amber-IDE,代码行数:15,代码来源:MidiAudio.java


注:本文中的javax.sound.midi.Synthesizer.getChannels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。