/** * Returns the synthesizer channels. * * @return the synthesizer channels. */ public List<MidiChannel> getChannels() { return Arrays.asList(synthesizer.getChannels()); }
/** * 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]; }
private static void playWarningSound() { try { int maxVolume = 90; 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, maxVolume); Thread.sleep(100); channel.noteOff(sound + i); } } catch (MidiUnavailableException | InterruptedException e1) { e1.printStackTrace(); } }
import javax.sound.midi.*; public class MidiSynthesizerSample { public static void main(String[] args) { int[] notes = new int[]{60, 62, 64, 65, 67, 69, 71, 72, 72, 71, 69, 67, 65, 64, 62, 60}; try { Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel channel = synthesizer.getChannels()[0]; for (int note : notes) { channel.noteOn(note, 50); try { Thread.sleep(200); } catch (InterruptedException e) { break; } finally { channel.noteOff(note); } } } catch (MidiUnavailableException e) { e.printStackTrace(); } } }
getLogger().info("VoiceStatus array size={}, firstEntry={}", synthVoiceStatusArr.length, synthVoiceStatusArr[0]); MidiChannel[] midChans = dsynth.getChannels(); for (int cidx = 0; cidx < midChans.length; cidx++) { MidiChannel chan = midChans[cidx];
syn = MidiSystem.getSynthesizer(); syn.open(); midChannel = syn.getChannels();
MidiChannel[] mChannels = midiSynth.getChannels();
Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); return synthesizer.getChannels()[instrument];
synth.loadAllInstruments (synth.getDefaultSoundbank ()); Instrument [] insts = synth.getLoadedInstruments (); MidiChannel channels[] = synth.getChannels (); for (int i = 0; i < channels.length; i++) { if (channels [i] != null) {
if( synthesizer != null ) javax.sound.midi.MidiChannel[] channels = synthesizer.getChannels(); for( int c = 0; channels != null && c < channels.length; c++ ) javax.sound.midi.MidiChannel[] channels = synthesizer.getChannels(); for( int c = 0; channels != null && c < channels.length; c++ )
MidiChannel[] channels = synth.getChannels();