1 import javax.sound.midi.*;
4 import java.awt.event.*;
7 * A Combo Box where the instrument of the currently active channel can be selected.
9 * @author Einar Pehrson, Michael Andreen
12 public class MooInstrumentList extends JComboBox implements ActionListener {
15 private ShortMessage programChangeMessage;
16 public static final int INSTRUMENTS = 0, DRUMS = 1;
19 * Creates the instrument list.
20 * @param chan the channel it will operate on.
21 * @param type one of the constants: INSTRUMENTS and DRUMS
22 * @param chan the MIDI message assigning the initial program change
24 public MooInstrumentList(int chan, int listType, ShortMessage programMsg) {
25 super(instruments[listType]);
26 programChangeMessage = programMsg;
27 if (programChangeMessage != null) setSelectedIndex(programChangeMessage.getData1());
29 setFont(Moosique.getGUI().FONT);
30 addActionListener(this);
34 * Sets the channel that it will operate on.
36 public void setChannel(int chan) {
38 try {programChangeMessage.setMessage(programChangeMessage.getCommand(), chan, programChangeMessage.getData1(), 0);}
39 catch (Exception e) {}
43 * Sets the instrument on a channel when it's changed in the combobox.
45 public void actionPerformed(ActionEvent e) {
46 int instrument = ((JComboBox)e.getSource()).getSelectedIndex();
47 Moosique.getChannel(channel).programChange(instrument);
48 try {programChangeMessage.setMessage(programChangeMessage.getCommand(), programChangeMessage.getChannel(), instrument, 0);}
49 catch (InvalidMidiDataException ex) {}
53 * The list with standard MIDI instruments.
55 public static final String[][] instruments = {{
56 " 0 Acoustic Grand Piano",
57 " 1 Bright Acoustic Piano",
58 " 2 Electric Grand Piano",
59 " 3 Honky-Tonk Piano",
73 " 17 Percussive Organ",
79 " 23 Tango Accordion",
80 " 24 Acoustic Nylon Guitar",
81 " 25 Acoustic Steel Guitar",
82 " 26 Electric Jazz Guitar",
83 " 27 Electric Clean Guitar",
84 " 28 Electric Muted Guitar",
85 " 29 Overdriven Guitar",
86 " 30 Distortion Guitar",
87 " 31 Guitar Harmonics",
89 " 33 Electric Bass Fingered",
90 " 34 Electric Bass Picked",
100 " 44 Tremolo Strings",
101 " 45 Pizzicato Strings",
102 " 46 Orchestral Harp",
104 " 48 String Ensemble 1",
105 " 49 String Ensemble 2",
106 " 50 Synth Strings 1",
107 " 51 Synth Strings 2",
111 " 55 Orchestral Hit",
136 " 80 Synth Lead 1 Square Wave Lead",
137 " 81 Synth Lead 2 Sawtooth Wave Lead",
138 " 82 Synth Lead 3 Caliope Lead",
139 " 83 Synth Lead 4 Chiff Lead",
140 " 84 Synth Lead 5 Charang",
141 " 85 Synth Lead 6 Solo Synth Voice",
142 " 86 Synth Lead 7 Bright Saw Wave",
143 " 87 Synth Lead 8 Brass and Lead",
144 " 88 Synth Pad 1 Fantasia Pad",
145 " 89 Synth Pad 2 Warm Pad",
146 " 90 Synth Pad 3 Poly Synth Pad",
147 " 91 Synth Pad 4 Space Voice Pad",
148 " 92 Synth Pad 5 Bowed Glass Pad",
149 " 93 Synth Pad 6 Metal Pad",
150 " 94 Synth Pad 7 Halo Pad",
151 " 95 Synth Pad 8 Sweep Pad",
152 " 96 Synth SFX 1 Ice Rain",
153 " 97 Synth SFX 2 Sound Track",
154 " 98 Synth SFX 3 Crystal",
155 " 99 Synth SFX 4 Atmosphere",
156 " 100 Synth SFX 5 Brightness",
157 " 101 Synth SFX 6 Goblin",
158 " 102 Synth SFX 7 Echo Drops",
159 " 103 Synth SFX 8 Star Theme",
175 " 119 Reverse Cymbal",
176 " 120 Guitar Fret Noise",
180 " 124 Telephone Ring",
187 for (int i = 0; i < 128; i++) {
188 instruments[1][i] = " Program Change " + i;