]> ruin.nu Git - moosique.git/blob - MooInstrumentList.java
no message
[moosique.git] / MooInstrumentList.java
1 import javax.sound.midi.*;
2 import javax.swing.*;
3 import java.awt.*;
4 import java.awt.event.*;
5
6 /**
7  * A Combo Box where the instrument of the currently active channel can be selected.
8  * 
9  * @author  Einar Pehrson, Michael Andreen
10  */
11  
12 public class MooInstrumentList extends JComboBox implements ActionListener {
13
14         private int channel;
15         private ShortMessage programChangeMessage;
16         public static final int INSTRUMENTS = 0, DRUMS = 1;
17         
18         /**
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
23          */
24         public MooInstrumentList(int chan, int listType, ShortMessage programMsg) {
25                 super(instruments[listType]);
26                 programChangeMessage = programMsg;
27                 if (programChangeMessage != null) setSelectedIndex(programChangeMessage.getData1());
28                 setChannel(chan);       
29                 setFont(Moosique.getGUI().FONT);
30                 addActionListener(this);
31         }
32
33         /**
34          * Sets the channel that it will operate on.
35          */
36         public void setChannel(int chan) {
37                 channel = chan;
38                 try {programChangeMessage.setMessage(programChangeMessage.getCommand(), chan, programChangeMessage.getData1(), 0);}
39                 catch (Exception e) {}
40         }
41
42         /**
43          * Sets the instrument on a channel when it's changed in the combobox.
44          */
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) {}
50         }
51     
52         /**
53          * The list with standard MIDI instruments.
54          */
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",
60                 " 4 Rhodes Piano",
61                 " 5 Chorused Piano",
62                 " 6 Harpischord",
63                 " 7 Clavinet",
64                 " 8 Celesta",
65                 " 9 Glockenspiel",
66                 " 10 Music Box",
67                 " 11 Vibraphone",
68                 " 12 Marimba",
69                 " 13 Xylophone",
70                 " 14 Tubular Bells",
71                 " 15 Dulcimer",
72                 " 16 Hammond Organ",
73                 " 17 Percussive Organ",
74                 " 18 Rock Organ",
75                 " 19 Church Organ",
76                 " 20 Reed Organ",
77                 " 21 Accordion",
78                 " 22 Harmonica",
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",
88                 " 32 Acoustic Bass",
89                 " 33 Electric Bass Fingered",
90                 " 34 Electric Bass Picked",
91                 " 35 Fretless Bass",
92                 " 36 Slap Bass 1",
93                 " 37 Slap Bass 2",
94                 " 38 Synth Bass 1",
95                 " 39 Synth Bass 2",
96                 " 40 Violin",
97                 " 41 Viola",
98                 " 42 Cello",
99                 " 43 Contrabass",
100                 " 44 Tremolo Strings",
101                 " 45 Pizzicato Strings",
102                 " 46 Orchestral Harp",
103                 " 47 Timpani",
104                 " 48 String Ensemble 1",
105                 " 49 String Ensemble 2",
106                 " 50 Synth Strings 1",
107                 " 51 Synth Strings 2",
108                 " 52 Choir Aahs",
109                 " 53 Voice Oohs",
110                 " 54 Synth Voice",
111                 " 55 Orchestral Hit",
112                 " 56 Trumpet",
113                 " 57 Trombone",
114                 " 58 Tuba",
115                 " 59 Muted Trumpet",
116                 " 60 French Horn",
117                 " 61 Brass Section",
118                 " 62 Synth Brass 1",
119                 " 63 Synth Brass 2",
120                 " 64 Soprano Sax",
121                 " 65 Alto Sax",
122                 " 66 Tenor Sax",
123                 " 67 Baritone Sax",
124                 " 68 Oboe",
125                 " 69 English Horn",
126                 " 70 Bassoon",
127                 " 71 Clarinet",
128                 " 72 Piccolo",
129                 " 73 Flute",
130                 " 74 Recorder",
131                 " 75 Pan Flute",
132                 " 76 Bottle Blow",
133                 " 77 Shakuhachi",
134                 " 78 Whistle",
135                 " 79 Ocarina",
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",
160                 " 104 Sitar",
161                 " 105 Banjo",
162                 " 106 Shamisen",
163                 " 107 Koto",
164                 " 108 Kalimba",
165                 " 109 Bagpipe",
166                 " 110 Fiddle",
167                 " 111 Shanai",
168                 " 112 Tinkle Bells",
169                 " 113 Agogo",
170                 " 114 Steel Drums",
171                 " 115 Woodblock",
172                 " 116 Taiko Drum",
173                 " 117 Melodic Tom",
174                 " 118 Synth Drum",
175                 " 119 Reverse Cymbal",
176                 " 120 Guitar Fret Noise",
177                 " 121 Breath Noise",
178                 " 122 Seashore",
179                 " 123 Bird Tweet",
180                 " 124 Telephone Ring",
181                 " 125 Helicopter",
182                 " 126 Applause",
183                 " 127 Gunshot"
184         }, new String[128]};
185         
186         static {
187                 for (int i = 0; i < 128; i++) {
188                         instruments[1][i] = " Program Change " + i;
189                 }       
190         }
191 }