1 |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of jlscp. |
7 |
* |
8 |
* jlscp is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* jlscp is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with jlscp; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.linuxsampler.lscp; |
24 |
|
25 |
/** |
26 |
* Provides information about a MIDI instrument. |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class MidiInstrumentInfo implements Parseable { |
30 |
private int mapId = -1; |
31 |
private MidiInstrumentEntry entry; |
32 |
|
33 |
private String name = "Untitled"; |
34 |
private String engine; |
35 |
private String instrName = "Untitled"; |
36 |
private String path = null; |
37 |
private int instrumentIndex = 0; |
38 |
private double volume = 1.0; |
39 |
private LoadMode loadMode = LoadMode.DEFAULT; |
40 |
|
41 |
public static enum LoadMode { |
42 |
/** It will be up to the InstrumentManager to decide which mode to use. */ |
43 |
DEFAULT ("Default"), |
44 |
|
45 |
/** |
46 |
* The instrument will be loaded when when demanded by |
47 |
* at least one sampler channel. It will immediately be freed |
48 |
* from memory when not needed by any sampler channel anymore. |
49 |
*/ |
50 |
ON_DEMAND ("On Demand"), |
51 |
|
52 |
/** |
53 |
* Same as <code>ON_DEMAND</code> with the difference that the instrument |
54 |
* will be kept in memory even when not needed by any sampler channel. |
55 |
*/ |
56 |
ON_DEMAND_HOLD ("On Demand and Hold"), |
57 |
|
58 |
/** |
59 |
* The instrument will be immediately loaded into memory |
60 |
* and the instrument will be kept all the time. |
61 |
*/ |
62 |
PERSISTENT ("Persistent"); |
63 |
|
64 |
private final String name; |
65 |
|
66 |
LoadMode(String name) { this.name = name; } |
67 |
|
68 |
public String |
69 |
toString() { return name; } |
70 |
} |
71 |
|
72 |
|
73 |
/** Creates a new instance of <code>MidiInstrumentInfo</code> */ |
74 |
public MidiInstrumentInfo() { |
75 |
|
76 |
} |
77 |
|
78 |
/** |
79 |
* Creates a new instance of <code>MidiInstrumentInfo</code>. |
80 |
* @param mapId The ID of the map containing this instrument. |
81 |
* @param entry The instrument position in the map. |
82 |
*/ |
83 |
public MidiInstrumentInfo(int mapId, MidiInstrumentEntry entry) { |
84 |
this.mapId = mapId; |
85 |
this.entry = entry; |
86 |
} |
87 |
|
88 |
/** |
89 |
* Creates a new instance of <code>MidiInstrumentInfo</code> and parses the |
90 |
* provided information about this instrument. |
91 |
* @param mapId The ID of the map containing this instrument. |
92 |
* @param entry Provides the position of the MIDI instrument in the MIDI instrument map. |
93 |
* @param resultSet An array with information categories about a MIDI instrument. |
94 |
* @throws LscpException If the parse fails. |
95 |
*/ |
96 |
public |
97 |
MidiInstrumentInfo(int mapId, MidiInstrumentEntry entry, String[] resultSet) |
98 |
throws LscpException { |
99 |
this.mapId = mapId; |
100 |
this.entry = entry; |
101 |
|
102 |
for(String s : resultSet) |
103 |
if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s)); |
104 |
} |
105 |
|
106 |
/** |
107 |
* Gets the position of the MIDI instrument in a MIDI instrument map. |
108 |
* @return The position of the MIDI instrument in a MIDI instrument map. |
109 |
*/ |
110 |
public MidiInstrumentEntry |
111 |
getEntry() { return entry; } |
112 |
|
113 |
/** |
114 |
* Gets the ID of the map containing this instrument. |
115 |
* @return The ID of the map containing this instrument. |
116 |
*/ |
117 |
public int |
118 |
getMapId() { return mapId; } |
119 |
|
120 |
/** |
121 |
* Gets the index of the MIDI bank, containing this instrument. |
122 |
* @return The index of the MIDI bank, containing this instrument. |
123 |
*/ |
124 |
public int |
125 |
getMidiBank() { return entry.getMidiBank(); } |
126 |
|
127 |
/** |
128 |
* Gets the MIDI program number of this instrument. |
129 |
* @return The MIDI program number of this instrument. |
130 |
*/ |
131 |
public int |
132 |
getMidiProgram() { return entry.getMidiProgram(); } |
133 |
|
134 |
/** |
135 |
* Gets the name of this MIDI instrument. |
136 |
* @return The name of this MIDI instrument. |
137 |
*/ |
138 |
public String |
139 |
getName() { return name; } |
140 |
|
141 |
/** |
142 |
* Sets the name of this MIDI instrument. |
143 |
* @param name The new name of this MIDI instrument. |
144 |
*/ |
145 |
public void |
146 |
setName(String name) { this.name = name; } |
147 |
|
148 |
/** |
149 |
* Gets the name of the sampler engine to be used to load the instrument. |
150 |
* @return The name of the sampler engine to be used to load the instrument. |
151 |
*/ |
152 |
public String |
153 |
getEngine() { return engine; } |
154 |
|
155 |
/** |
156 |
* Sets the name of the sampler engine to be used to load the instrument. |
157 |
* @param engine The name of the sampler engine to be used to load the instrument. |
158 |
*/ |
159 |
public void |
160 |
setEngine(String engine) { this.engine = engine; } |
161 |
|
162 |
/** |
163 |
* Gets the name of the loaded instrument as reflected by its file. |
164 |
* @return The name of the loaded instrument as reflected by its file. |
165 |
*/ |
166 |
public String |
167 |
getInstrumentName() { return instrName; } |
168 |
|
169 |
/** |
170 |
* Sets the name of this instrument as reflected by its file. |
171 |
* @param name The name of the instrument as reflected by its file. |
172 |
* |
173 |
public void |
174 |
setInstrumentName(String name) { this.instrName = name; }*/ |
175 |
|
176 |
/** |
177 |
* Returns the absolute pathname of the instrument location. |
178 |
* @return The absolute pathname of the instrument location. |
179 |
*/ |
180 |
public String |
181 |
getFileName() { return path; } |
182 |
|
183 |
/** |
184 |
* Sets the absolute pathname of the instrument location. |
185 |
* @param path Specifies the absolute pathname of the instrument location. |
186 |
*/ |
187 |
public void |
188 |
setFileName(String path) { this.path = path; } |
189 |
|
190 |
/** |
191 |
* Returns the index of the instrument in the instrument file. |
192 |
* @return The index of the instrument in the instrument file. |
193 |
*/ |
194 |
public int |
195 |
getInstrumentIndex() { return instrumentIndex; } |
196 |
|
197 |
/** |
198 |
* Sets the index of the instrument in the instrument file. |
199 |
* @param idx The index of the instrument in the instrument file. |
200 |
*/ |
201 |
public void |
202 |
setInstrumentIndex(int idx) { instrumentIndex = idx; } |
203 |
|
204 |
/** |
205 |
* Returns the volume, specified for this instrument, where a |
206 |
* value < 1.0 means attenuation and a value > 1.0 means amplification. |
207 |
*/ |
208 |
public double |
209 |
getVolume() { return volume; } |
210 |
|
211 |
/** |
212 |
* Sets the volume level for this instrument, where a |
213 |
* value < 1.0 means attenuation and a value > 1.0 means amplification. |
214 |
*/ |
215 |
public void |
216 |
setVolume(double volume) { this.volume = volume; } |
217 |
|
218 |
/** |
219 |
* Gets the load mode of this MIDI instrument. |
220 |
* @return The load mode of this MIDI instrument. |
221 |
*/ |
222 |
public LoadMode |
223 |
getLoadMode() { return loadMode; } |
224 |
|
225 |
/** |
226 |
* Sets the load mode of this MIDI instrument. |
227 |
* @param loadMode Specifies the load mode for this MIDI instrument. |
228 |
*/ |
229 |
public void |
230 |
setLoadMode(LoadMode loadMode) { this.loadMode = loadMode; } |
231 |
|
232 |
/** |
233 |
* Parses a line of text. |
234 |
* @param s The string to be parsed. |
235 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
236 |
* @throws LscpException If some error occurs. |
237 |
*/ |
238 |
public boolean |
239 |
parse(String s) throws LscpException { |
240 |
if(s.startsWith("NAME: ")) { |
241 |
setName(s.substring("NAME: ".length())); |
242 |
} else if(s.startsWith("ENGINE_NAME: ")) { |
243 |
setEngine(s.substring("ENGINE_NAME: ".length())); |
244 |
} else if(s.startsWith("INSTRUMENT_FILE: ")) { |
245 |
setFileName(s.substring("INSTRUMENT_FILE: ".length())); |
246 |
} else if(s.startsWith("INSTRUMENT_NR: ")) { |
247 |
s = s.substring("INSTRUMENT_NR: ".length()); |
248 |
setInstrumentIndex(Parser.parseInt(s)); |
249 |
} else if(s.startsWith("INSTRUMENT_NAME: ")) { |
250 |
instrName = s.substring("INSTRUMENT_NAME: ".length()); |
251 |
} else if(s.startsWith("LOAD_MODE: ")) { |
252 |
s = s.substring("LOAD_MODE: ".length()); |
253 |
if(s.length() == 0) setLoadMode(LoadMode.DEFAULT); |
254 |
else setLoadMode(LoadMode.valueOf(s)); |
255 |
} else if(s.startsWith("VOLUME: ")) { |
256 |
s = s.substring("VOLUME: ".length()); |
257 |
setVolume(Parser.parseFloat(s)); |
258 |
} else return false; |
259 |
|
260 |
return true; |
261 |
} |
262 |
|
263 |
/** |
264 |
* Determines whether the specified object is of type |
265 |
* <code>MidiInstrumentInfo</code> and has equal map ID, MIDI bank and MIDI program. |
266 |
* @param obj The reference object with which to compare. |
267 |
* @return <code>true</code> if the specified object is of type |
268 |
* <code>MidiInstrumentInfo</code> and has equal map ID, MIDI bank and MIDI program. |
269 |
*/ |
270 |
public boolean |
271 |
equals(Object obj) { |
272 |
if(obj == null) return false; |
273 |
if(!(obj instanceof MidiInstrumentInfo)) return false; |
274 |
MidiInstrumentInfo i = (MidiInstrumentInfo)obj; |
275 |
if(getMapId() != i.getMapId()) return false; |
276 |
if(getMidiBank() != i.getMidiBank()) return false; |
277 |
if(getMidiProgram() != i.getMidiProgram()) return false; |
278 |
|
279 |
return true; |
280 |
} |
281 |
} |