Java Midi Synthesizer

B

bryan.crompton

Hello,

I've been having a little trouble working with the Java midi
synthesizer included with the API.

I found a peice of code on a forum something like what follows:

import java.util.*;
import javax.sound.midi.*;

class SoundTest
{
public static void main(String[] args) {
try {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();

final MidiChannel[] mc = synth.getChannels();
Instrument[] instr =
synth.getAvailableInstruments();
synth.loadInstrument(instr[55]);
for (int i = 20; i < 80; ++i) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {}
mc[4].noteOn(i,100);
}
} catch (MidiUnavailableException e) {}
}
}

Though I'm not very familier with the sound API (I've just come
accross it today), I'm not confused with the code. The problem is, I
would expect, when modifying the line
"synth.loadInstrument(instr[55]);" to get a different instrument, but
I haven't.

Can anyone help me out?

-Bryan
 
A

Andrew Thompson

Can anyone help me out?

Try this..
<sscce>
import java.util.*;
import javax.sound.midi.*;

class SoundTest
{
public static void main(String[] args) {
try {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();

final MidiChannel[] mc= synth.getChannels();
Instrument[]instr =
synth.getAvailableInstruments();
for (int ii= 0; ii<20; ii++) {
System.out.println( instr[ii].getName() );
for (int i = 50; i < 60; ++i) {
// instrument loading is irrelevant, it is
// the prgram change that matters..
mc[4].programChange(ii);
mc[4].noteOn(i,300);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
}
}
</sscce>

HTH

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200706/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top