【发布时间】:2011-02-03 00:28:09
【问题描述】:
我似乎无法改变乐器。我切换了仪器的值,但输出没有任何不同。无论我尝试什么价值,我都只能得到一个钢琴乐器来演奏。这是下面的简单代码。有没有人有什么建议?还是我错过了仪器对象的基本原理?
import javax.sound.midi.*;
//import javax.sound.*;
public class Drum {
static int instrument = 45;
static int note = 100;
static int timbre = 0;
static int force = 100;
public static void main(String[] args) {
Synthesizer synth = null;
try {
synth = MidiSystem.getSynthesizer();
synth.open();
}
catch (Exception e) {
System.out.println(e);
}
Soundbank soundbank = synth.getDefaultSoundbank();
Instrument[] instr = soundbank.getInstruments();
synth.loadInstrument(instr[instrument]); //Changing this int (instrument) does nothing
MidiChannel[] mc = synth.getChannels();
mc[4].noteOn(note, force);
try { Thread.sleep(1000); }
catch(InterruptedException e) {}
System.out.println(instr[instrument].getName());
synth.close();
}
}
【问题讨论】:
-
您不能只加载仪器,还必须发送程序更改消息。我不是 Java 程序员,所以我不知道该怎么做,但这是你必须做的。见download.oracle.com/javase/1.4.2/docs/api/javax/sound/midi/…
标签: java midi-instrument