Parece que no consigo que el instrumento cambie. Cambio el valor del instrumento pero no obtengo nada diferente en la salida. Solo puedo tocar un instrumento de piano sin importar el valor que pruebe. Aquí está el código simple a continuación. ¿Alguien tiene alguna sugerencia? ¿O me falta un elemento fundamental del instrumento?Sintetizador MIDI en Java - No se pueden cambiar los instrumentos
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();
}
}
No puede simplemente cargar un instrumento, también debe enviar un mensaje de cambio de programa. No soy un programador de Java, así que no sé cómo hacer esto, pero eso es lo que debes hacer. Ver http://download.oracle.com/javase/1.4.2/docs/api/javax/sound/midi/Synthesizer.html#loadInstrument(javax.sound.midi.Instrument) – Brad