use of javax.sound.midi.VoiceStatus in project jdk8u_jdk by JetBrains.
the class NoteOverFlowTest method main.
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
AudioInputStream stream = synth.openStream(format, null);
// Make all voices busy, e.g.
// send midi on and midi off on all available voices
MidiChannel ch1 = synth.getChannels()[0];
// Use contionus instrument like string ensemble
ch1.programChange(48);
for (int i = 0; i < synth.getMaxPolyphony(); i++) {
ch1.noteOn(64, 64);
ch1.noteOff(64);
}
// Now send single midi on, and midi off message
ch1.noteOn(64, 64);
ch1.noteOff(64);
// Read 10 sec from stream, by this time all voices should be inactvie
stream.skip(format.getFrameSize() * ((int) (format.getFrameRate() * 20)));
// If no voice are active, then this test will pass
VoiceStatus[] v = synth.getVoiceStatus();
for (int i = 0; i < v.length; i++) {
if (v[i].active) {
throw new RuntimeException("Not all voices are inactive!");
}
}
// Close the synthesizer after use
synth.close();
}
use of javax.sound.midi.VoiceStatus in project jdk8u_jdk by JetBrains.
the class SoftSynthesizer method getVoiceStatus.
public VoiceStatus[] getVoiceStatus() {
if (!isOpen()) {
VoiceStatus[] tempVoiceStatusArray = new VoiceStatus[getMaxPolyphony()];
for (int i = 0; i < tempVoiceStatusArray.length; i++) {
VoiceStatus b = new VoiceStatus();
b.active = false;
b.bank = 0;
b.channel = 0;
b.note = 0;
b.program = 0;
b.volume = 0;
tempVoiceStatusArray[i] = b;
}
return tempVoiceStatusArray;
}
synchronized (control_mutex) {
VoiceStatus[] tempVoiceStatusArray = new VoiceStatus[voices.length];
for (int i = 0; i < voices.length; i++) {
VoiceStatus a = voices[i];
VoiceStatus b = new VoiceStatus();
b.active = a.active;
b.bank = a.bank;
b.channel = a.channel;
b.note = a.note;
b.program = a.program;
b.volume = a.volume;
tempVoiceStatusArray[i] = b;
}
return tempVoiceStatusArray;
}
}
Aggregations