Non riesco a far cambiare lo strumento. Cambio il valore dello strumento ma non ottengo nulla di diverso sull'uscita. Posso suonare uno strumento per pianoforte solo a prescindere dal valore che cerco. Ecco il semplice codice qui sotto. Qualcuno ha qualche suggerimento? O mi manca una fondamentale dell'oggetto dello strumento?Sintetizzatore MIDI Java - Impossibile cambiare gli strumenti
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();
}
}
Non è possibile caricare solo uno strumento, è necessario inviare anche un messaggio di cambio programma. Non sono un programmatore Java, quindi non so come farlo, ma è quello che devi fare. Vedi http://download.oracle.com/javase/1.4.2/docs/api/javax/sound/midi/Synthesizer.html#loadInstrument(javax.sound.midi.Instrument) – Brad