當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。