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 extends AbstractInstrument implements Parseable { |
30 |
private int mapId = -1; |
31 |
private MidiInstrumentEntry entry; |
32 |
|
33 |
private String engine; |
34 |
private String instrName = "Untitled"; |
35 |
private double volume = 1.0; |
36 |
private LoadMode loadMode = LoadMode.DEFAULT; |
37 |
|
38 |
public static enum LoadMode { |
39 |
/** It will be up to the InstrumentManager to decide which mode to use. */ |
40 |
DEFAULT ("Default"), |
41 |
|
42 |
/** |
43 |
* The instrument will be loaded when when demanded by |
44 |
* at least one sampler channel. It will immediately be freed |
45 |
* from memory when not needed by any sampler channel anymore. |
46 |
*/ |
47 |
ON_DEMAND ("On Demand"), |
48 |
|
49 |
/** |
50 |
* Same as <code>ON_DEMAND</code> with the difference that the instrument |
51 |
* will be kept in memory even when not needed by any sampler channel. |
52 |
*/ |
53 |
ON_DEMAND_HOLD ("On Demand and Hold"), |
54 |
|
55 |
/** |
56 |
* The instrument will be immediately loaded into memory |
57 |
* and the instrument will be kept all the time. |
58 |
*/ |
59 |
PERSISTENT ("Persistent"); |
60 |
|
61 |
private final String name; |
62 |
|
63 |
LoadMode(String name) { this.name = name; } |
64 |
|
65 |
public String |
66 |
toString() { return name; } |
67 |
} |
68 |
|
69 |
|
70 |
/** Creates a new instance of <code>MidiInstrumentInfo</code> */ |
71 |
public MidiInstrumentInfo() { |
72 |
|
73 |
} |
74 |
|
75 |
/** |
76 |
* Creates a new instance of <code>MidiInstrumentInfo</code>. |
77 |
* @param mapId The ID of the map containing this instrument. |
78 |
* @param entry The instrument position in the map. |
79 |
*/ |
80 |
public MidiInstrumentInfo(int mapId, MidiInstrumentEntry entry) { |
81 |
this.mapId = mapId; |
82 |
this.entry = entry; |
83 |
} |
84 |
|
85 |
/** |
86 |
* Creates a new instance of <code>MidiInstrumentInfo</code> and parses the |
87 |
* provided information about this instrument. |
88 |
* @param mapId The ID of the map containing this instrument. |
89 |
* @param entry Provides the position of the MIDI instrument in the MIDI instrument map. |
90 |
* @param resultSet An array with information categories about a MIDI instrument. |
91 |
* @throws LscpException If the parse fails. |
92 |
*/ |
93 |
public |
94 |
MidiInstrumentInfo(int mapId, MidiInstrumentEntry entry, String[] resultSet) |
95 |
throws LscpException { |
96 |
this.mapId = mapId; |
97 |
this.entry = entry; |
98 |
|
99 |
for(String s : resultSet) |
100 |
if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s)); |
101 |
} |
102 |
|
103 |
/** |
104 |
* Gets the position of the MIDI instrument in a MIDI instrument map. |
105 |
* @return The position of the MIDI instrument in a MIDI instrument map. |
106 |
*/ |
107 |
public MidiInstrumentEntry |
108 |
getEntry() { return entry; } |
109 |
|
110 |
/** |
111 |
* Gets the ID of the map containing this instrument. |
112 |
* @return The ID of the map containing this instrument. |
113 |
*/ |
114 |
public int |
115 |
getMapId() { return mapId; } |
116 |
|
117 |
/** |
118 |
* Gets the index of the MIDI bank, containing this instrument. |
119 |
* @return The index of the MIDI bank, containing this instrument. |
120 |
*/ |
121 |
public int |
122 |
getMidiBank() { return entry.getMidiBank(); } |
123 |
|
124 |
/** |
125 |
* Gets the MIDI program number of this instrument. |
126 |
* @return The MIDI program number of this instrument. |
127 |
*/ |
128 |
public int |
129 |
getMidiProgram() { return entry.getMidiProgram(); } |
130 |
|
131 |
/** |
132 |
* Gets the name of the sampler engine to be used to load the instrument. |
133 |
* @return The name of the sampler engine to be used to load the instrument. |
134 |
*/ |
135 |
public String |
136 |
getEngine() { return engine; } |
137 |
|
138 |
/** |
139 |
* Sets the name of the sampler engine to be used to load the instrument. |
140 |
* @param engine The name of the sampler engine to be used to load the instrument. |
141 |
*/ |
142 |
public void |
143 |
setEngine(String engine) { this.engine = engine; } |
144 |
|
145 |
/** |
146 |
* Gets the name of the loaded instrument as reflected by its file. |
147 |
* @return The name of the loaded instrument as reflected by its file. |
148 |
*/ |
149 |
public String |
150 |
getInstrumentName() { return instrName; } |
151 |
|
152 |
/** |
153 |
* Sets the name of this instrument as reflected by its file. |
154 |
* @param name The name of the instrument as reflected by its file. |
155 |
* |
156 |
public void |
157 |
setInstrumentName(String name) { this.instrName = name; }*/ |
158 |
|
159 |
/** |
160 |
* Returns the volume, specified for this instrument, where a |
161 |
* value < 1.0 means attenuation and a value > 1.0 means amplification. |
162 |
*/ |
163 |
public double |
164 |
getVolume() { return volume; } |
165 |
|
166 |
/** |
167 |
* Sets the volume level for this instrument, where a |
168 |
* value < 1.0 means attenuation and a value > 1.0 means amplification. |
169 |
*/ |
170 |
public void |
171 |
setVolume(double volume) { this.volume = volume; } |
172 |
|
173 |
/** |
174 |
* Gets the load mode of this MIDI instrument. |
175 |
* @return The load mode of this MIDI instrument. |
176 |
*/ |
177 |
public LoadMode |
178 |
getLoadMode() { return loadMode; } |
179 |
|
180 |
/** |
181 |
* Sets the load mode of this MIDI instrument. |
182 |
* @param loadMode Specifies the load mode for this MIDI instrument. |
183 |
*/ |
184 |
public void |
185 |
setLoadMode(LoadMode loadMode) { this.loadMode = loadMode; } |
186 |
|
187 |
/** |
188 |
* Parses a line of text. |
189 |
* @param s The string to be parsed. |
190 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
191 |
* @throws LscpException If some error occurs. |
192 |
*/ |
193 |
public boolean |
194 |
parse(String s) throws LscpException { |
195 |
if (super.parse(s)) return true; |
196 |
|
197 |
if(s.startsWith("NAME: ")) { |
198 |
setName(s.substring("NAME: ".length())); |
199 |
} else if(s.startsWith("ENGINE_NAME: ")) { |
200 |
setEngine(s.substring("ENGINE_NAME: ".length())); |
201 |
} else if(s.startsWith("INSTRUMENT_NAME: ")) { |
202 |
instrName = s.substring("INSTRUMENT_NAME: ".length()); |
203 |
} else if(s.startsWith("LOAD_MODE: ")) { |
204 |
s = s.substring("LOAD_MODE: ".length()); |
205 |
if(s.length() == 0) setLoadMode(LoadMode.DEFAULT); |
206 |
else setLoadMode(LoadMode.valueOf(s)); |
207 |
} else if(s.startsWith("VOLUME: ")) { |
208 |
s = s.substring("VOLUME: ".length()); |
209 |
setVolume(Parser.parseFloat(s)); |
210 |
} else return false; |
211 |
|
212 |
return true; |
213 |
} |
214 |
|
215 |
/** |
216 |
* Determines whether the specified object is of type |
217 |
* <code>MidiInstrumentInfo</code> and has equal map ID, MIDI bank and MIDI program. |
218 |
* @param obj The reference object with which to compare. |
219 |
* @return <code>true</code> if the specified object is of type |
220 |
* <code>MidiInstrumentInfo</code> and has equal map ID, MIDI bank and MIDI program. |
221 |
*/ |
222 |
public boolean |
223 |
equals(Object obj) { |
224 |
if(obj == null) return false; |
225 |
if(!(obj instanceof MidiInstrumentInfo)) return false; |
226 |
MidiInstrumentInfo i = (MidiInstrumentInfo)obj; |
227 |
if(getMapId() != i.getMapId()) return false; |
228 |
if(getMidiBank() != i.getMidiBank()) return false; |
229 |
if(getMidiProgram() != i.getMidiProgram()) return false; |
230 |
|
231 |
return true; |
232 |
} |
233 |
} |