1 |
iliev |
596 |
/* |
2 |
|
|
* jlscp - a java LinuxSampler control protocol API |
3 |
|
|
* |
4 |
iliev |
1139 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
596 |
* |
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 |
iliev |
1421 |
import static org.linuxsampler.lscp.Parser.*; |
26 |
|
|
|
27 |
iliev |
596 |
/** |
28 |
iliev |
1139 |
* Provides information about the current settings of a specific sampler channel. |
29 |
iliev |
596 |
* @author Grigor Iliev |
30 |
|
|
*/ |
31 |
|
|
public class SamplerChannel implements Parseable { |
32 |
iliev |
784 |
/** Indicates that the channel is muted because of the presence of a solo channel. */ |
33 |
|
|
private final static int MUTED_BY_SOLO = -1; |
34 |
|
|
|
35 |
iliev |
1139 |
private int chnId = -1; |
36 |
iliev |
596 |
|
37 |
iliev |
784 |
private SamplerEngine engine = null; |
38 |
iliev |
596 |
private int aoDevice = -1; |
39 |
|
|
private int aoChannels = 0; |
40 |
|
|
private Integer[] aor = null; |
41 |
|
|
private String instrFile = null; |
42 |
|
|
private int instrIdx = 0; |
43 |
|
|
private String instrName = null; |
44 |
|
|
private int instrStat = 0; |
45 |
|
|
private int miDev = -1; |
46 |
|
|
private int miPort = 0; |
47 |
|
|
private int miChn = -1; |
48 |
|
|
private float vol = 0; |
49 |
iliev |
784 |
private int mute = 0; |
50 |
|
|
private boolean solo = false; |
51 |
iliev |
1139 |
private int midiInstrumentMapId = -1; |
52 |
iliev |
596 |
|
53 |
|
|
/** Creates a new instance of SamplerChannel */ |
54 |
|
|
public |
55 |
|
|
SamplerChannel() { |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Creates a new instance of <code>SamplerChannel</code> and parses the information |
60 |
|
|
* about a specific sampler channel described by <code>resultSet</code>. |
61 |
|
|
* @param resultSet An array with information categories about a sampler channel. |
62 |
|
|
* @throws LscpException If the parse fail. |
63 |
|
|
*/ |
64 |
|
|
public |
65 |
|
|
SamplerChannel(String[] resultSet) throws LscpException { |
66 |
|
|
for(String s : resultSet) |
67 |
|
|
if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s)); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
/** |
71 |
|
|
* Gets the sampler channel number. |
72 |
|
|
* @return The sampler channel number or -1 if the sampler channel number is not set. |
73 |
|
|
*/ |
74 |
|
|
public int |
75 |
iliev |
1139 |
getChannelId() { return chnId; } |
76 |
iliev |
596 |
|
77 |
|
|
/** |
78 |
|
|
* Sets the sampler channel number. |
79 |
|
|
* @param id The new sampler channel number. |
80 |
|
|
*/ |
81 |
|
|
public void |
82 |
iliev |
1139 |
setChannelId(int id) { chnId = id; } |
83 |
iliev |
596 |
|
84 |
|
|
/** |
85 |
iliev |
784 |
* Gets the engine that is deployed on the sampler channel. |
86 |
|
|
* @return The engine that is deployed on the sampler channel |
87 |
iliev |
596 |
* or <code>null</code> if there is no engine deployed yet for this sampler channel. |
88 |
|
|
*/ |
89 |
iliev |
784 |
public SamplerEngine |
90 |
|
|
getEngine() { return engine; } |
91 |
iliev |
596 |
|
92 |
|
|
/** |
93 |
iliev |
784 |
* Associates the specified sampler engine to this sampler channel. |
94 |
|
|
* @param engine A <code>SamplerEngine</code> instance containing the information |
95 |
|
|
* about the engine to be assigned to this channel. |
96 |
|
|
*/ |
97 |
|
|
public void |
98 |
|
|
setEngine(SamplerEngine engine) { this.engine = engine; } |
99 |
|
|
|
100 |
|
|
/** |
101 |
iliev |
596 |
* Gets the numerical ID of the audio output device which is currently connected |
102 |
|
|
* to this sampler channel to output the audio signal. |
103 |
|
|
* |
104 |
|
|
* @return The numerical ID of the audio output device or -1 if there is no |
105 |
|
|
* device connected to this sampler channel. |
106 |
|
|
*/ |
107 |
|
|
public int |
108 |
|
|
getAudioOutputDevice() { return aoDevice; } |
109 |
|
|
|
110 |
|
|
/** |
111 |
|
|
* Gets the number of output channels the sampler channel offers. |
112 |
|
|
* @return The number of output channels the sampler channel offers. |
113 |
|
|
*/ |
114 |
|
|
public int |
115 |
|
|
getAudioOutputChannels() { return aoChannels; } |
116 |
|
|
|
117 |
|
|
/** |
118 |
|
|
* Gets a list which reflects to which audio channel of the selected audio output device |
119 |
iliev |
1139 |
* each sampler output channel is routed to. The number of the array's position represents |
120 |
|
|
* the sampler output channel and the value at the specified position represents |
121 |
|
|
* to which channel of the selected audio output device the |
122 |
|
|
* sampler output channel is routed to. |
123 |
iliev |
596 |
* @return A list which reflects to which audio channel of the selected audio output device |
124 |
|
|
* each sampler output channel is routed to. |
125 |
|
|
*/ |
126 |
|
|
public Integer[] |
127 |
|
|
getAudioOutputRouting() { return aor; } |
128 |
|
|
|
129 |
|
|
/** |
130 |
|
|
* Gets the file name of the loaded instrument. |
131 |
|
|
* @return The file name of the loaded instrument. |
132 |
|
|
* or <code>null</code> if there is no instrument yet loaded for this sampler channel. |
133 |
|
|
*/ |
134 |
|
|
public String |
135 |
|
|
getInstrumentFile() { return instrFile; } |
136 |
|
|
|
137 |
|
|
/** |
138 |
|
|
* Gets the instrument index number of the loaded instrument. |
139 |
|
|
* @return The instrument index number of the loaded instrument. |
140 |
|
|
*/ |
141 |
|
|
public int |
142 |
|
|
getInstrumentIndex() { return instrIdx; } |
143 |
|
|
|
144 |
|
|
/** |
145 |
iliev |
784 |
* Gets the name of the loaded instrument. |
146 |
|
|
* @return The name of the loaded instrument or |
147 |
|
|
* <code>null</code> if there is no instrument loaded. |
148 |
iliev |
596 |
*/ |
149 |
|
|
public String |
150 |
|
|
getInstrumentName() { return instrName; } |
151 |
|
|
|
152 |
|
|
/** |
153 |
|
|
* Gets the instrument status - an integer values from 0 to 100 indicating loading |
154 |
|
|
* progress percentage for the instrument. Negative value indicates a loading exception. |
155 |
|
|
* Value of 100 indicates that the instrument is fully loaded. |
156 |
|
|
* @return The instrument status. |
157 |
|
|
*/ |
158 |
|
|
public int |
159 |
|
|
getInstrumentStatus() { return instrStat; } |
160 |
|
|
|
161 |
|
|
/** |
162 |
|
|
* Gets the numerical ID of the MIDI input device which is currently connected |
163 |
|
|
* to this sampler channel to deliver MIDI input commands. |
164 |
|
|
* @return The numerical ID of the MIDI input device which is currently connected |
165 |
|
|
* to this sampler channel to deliver MIDI input commands or -1 if there is no device |
166 |
|
|
* connected to this sampler channel. |
167 |
|
|
*/ |
168 |
|
|
public int |
169 |
|
|
getMidiInputDevice() { return miDev; } |
170 |
|
|
|
171 |
|
|
/** |
172 |
|
|
* Gets the port number of the MIDI input device. |
173 |
|
|
* @return The port number of the MIDI input device. |
174 |
|
|
*/ |
175 |
|
|
public int |
176 |
|
|
getMidiInputPort() { return miPort; } |
177 |
|
|
|
178 |
|
|
/** |
179 |
|
|
* Gets the MIDI input channel number this sampler channel should listen to |
180 |
|
|
* or -1 to listen on all MIDI channels. |
181 |
|
|
* @return The MIDI input channel number this sampler channel should listen to |
182 |
|
|
* or -1 to listen on all MIDI channels. |
183 |
|
|
*/ |
184 |
|
|
public int |
185 |
|
|
getMidiInputChannel() { return miChn; } |
186 |
|
|
|
187 |
|
|
/** |
188 |
|
|
* Gets the channel volume factor. Value less then 1.0 means attenuation, |
189 |
|
|
* value greater then 1.0 means amplification. |
190 |
|
|
* @return The channel volume factor. |
191 |
|
|
*/ |
192 |
|
|
public float |
193 |
|
|
getVolume() { return vol; } |
194 |
|
|
|
195 |
|
|
/** |
196 |
iliev |
784 |
* Determines whether this channel is muted. |
197 |
|
|
* @return <code>true</code> if the channel is muted, <code>false</code> otherwise. |
198 |
|
|
*/ |
199 |
|
|
public boolean |
200 |
|
|
isMuted() { return mute != 0; } |
201 |
|
|
|
202 |
|
|
/** |
203 |
|
|
* Determines whether this channel is muted because of the presence of a solo channel. |
204 |
|
|
* All channels, muted because of the presence of a solo channel, will be |
205 |
|
|
* automatically unmuted when there are no solo channels left. |
206 |
|
|
* @return <code>true</code> if the channel is muted because of the presence of a solo |
207 |
|
|
* channel, <code>false</code> otherwise. |
208 |
|
|
*/ |
209 |
|
|
public boolean |
210 |
|
|
isMutedBySolo() { return mute == MUTED_BY_SOLO; } |
211 |
|
|
|
212 |
|
|
/** |
213 |
|
|
* Determines whether this channel is a solo channel. |
214 |
|
|
* @return <code>true</code> if the channel is a solo channel, <code>false</code> otherwise. |
215 |
|
|
*/ |
216 |
|
|
public boolean |
217 |
|
|
isSoloChannel() { return solo; } |
218 |
|
|
|
219 |
|
|
/** |
220 |
iliev |
1139 |
* Gets the numerical id of the MIDI instrument |
221 |
|
|
* map, to which this sampler channel is assigned to. |
222 |
|
|
* @return The numerical id of the MIDI instrument map, to |
223 |
|
|
* which this sampler channel is assigned to, or <code>-1</code> |
224 |
|
|
* if no MIDI instrument map is assigned to this sampler |
225 |
|
|
* channel and <code>-2</code> if the channel is assigned |
226 |
|
|
* to the default MIDI instrument map. |
227 |
|
|
* @see #isUsingDefaultMidiInstrumentMap |
228 |
|
|
*/ |
229 |
|
|
public int |
230 |
|
|
getMidiInstrumentMapId() { return midiInstrumentMapId; } |
231 |
|
|
|
232 |
|
|
/** |
233 |
|
|
* Determines whether the sampler channel is |
234 |
|
|
* assigned to the default MIDI instrument map. |
235 |
|
|
* @return <code>true</code> if the sampler channel is assigned |
236 |
|
|
* to the default MIDI instrument map, <code>false</code> otherwise. |
237 |
|
|
*/ |
238 |
|
|
public boolean |
239 |
|
|
isUsingDefaultMidiInstrumentMap() { return getMidiInstrumentMapId() == -2; } |
240 |
|
|
|
241 |
|
|
/** |
242 |
iliev |
596 |
* Parses a line of text. |
243 |
|
|
* @param s The string to be parsed. |
244 |
|
|
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
245 |
|
|
* @throws LscpException If some error occurs. |
246 |
|
|
*/ |
247 |
|
|
public boolean |
248 |
|
|
parse(String s) throws LscpException { |
249 |
|
|
if(s.startsWith("ENGINE_NAME: ")) { |
250 |
|
|
s = s.substring("ENGINE_NAME: ".length()); |
251 |
|
|
if(s.equals("NONE")) engine = null; |
252 |
iliev |
784 |
else { |
253 |
|
|
engine = new SamplerEngine(); |
254 |
|
|
engine.setName(s); |
255 |
|
|
} |
256 |
iliev |
596 |
} else if(s.startsWith("AUDIO_OUTPUT_DEVICE: ")) { |
257 |
|
|
s = s.substring("AUDIO_OUTPUT_DEVICE: ".length()); |
258 |
|
|
if(s.equals("NONE")) aoDevice = -1; |
259 |
|
|
else aoDevice = Parser.parseInt(s); |
260 |
|
|
} else if(s.startsWith("AUDIO_OUTPUT_CHANNELS: ")) { |
261 |
|
|
s = s.substring("AUDIO_OUTPUT_CHANNELS: ".length()); |
262 |
|
|
if(s.equals("NONE")) aoChannels = -1; |
263 |
|
|
else aoChannels = Parser.parseInt(s); |
264 |
|
|
} else if(s.startsWith("AUDIO_OUTPUT_ROUTING: ")) { |
265 |
|
|
s = s.substring("AUDIO_OUTPUT_ROUTING: ".length()); |
266 |
|
|
aor = Parser.parseIntList(s); |
267 |
|
|
} else if(s.startsWith("INSTRUMENT_FILE: ")) { |
268 |
|
|
s = s.substring("INSTRUMENT_FILE: ".length()); |
269 |
|
|
if(s.equals("NONE")) instrFile = null; |
270 |
|
|
else instrFile = s; |
271 |
|
|
} else if(s.startsWith("INSTRUMENT_NR: ")) { |
272 |
|
|
s = s.substring("INSTRUMENT_NR: ".length()); |
273 |
|
|
if(s.equals("NONE")) instrIdx = -1; |
274 |
|
|
else instrIdx = Parser.parseInt(s); |
275 |
|
|
} else if(s.startsWith("INSTRUMENT_NAME: ")) { |
276 |
iliev |
784 |
s = s.substring("INSTRUMENT_NAME: ".length()); |
277 |
|
|
if(s.equals("NONE")) instrName = null; |
278 |
iliev |
1421 |
else instrName = toNonEscapedString(s); |
279 |
iliev |
596 |
} else if(s.startsWith("INSTRUMENT_STATUS: ")) { |
280 |
|
|
s = s.substring("INSTRUMENT_STATUS: ".length()); |
281 |
|
|
instrStat = Parser.parseInt(s); |
282 |
|
|
} else if(s.startsWith("MIDI_INPUT_DEVICE: ")) { |
283 |
|
|
s = s.substring("MIDI_INPUT_DEVICE: ".length()); |
284 |
|
|
if(s.equals("NONE")) miDev = -1; |
285 |
|
|
else miDev = Parser.parseInt(s); |
286 |
|
|
} else if(s.startsWith("MIDI_INPUT_PORT: ")) { |
287 |
|
|
s = s.substring("MIDI_INPUT_PORT: ".length()); |
288 |
|
|
if(s.equals("NONE")) miPort = -1; |
289 |
|
|
else miPort = Parser.parseInt(s); |
290 |
|
|
} else if(s.startsWith("MIDI_INPUT_CHANNEL: ")) { |
291 |
|
|
s = s.substring("MIDI_INPUT_CHANNEL: ".length()); |
292 |
|
|
if(s.equals("ALL")) miChn = -1; |
293 |
|
|
else miChn = Parser.parseInt(s); |
294 |
|
|
} else if(s.startsWith("VOLUME: ")) { |
295 |
|
|
s = s.substring("VOLUME: ".length()); |
296 |
|
|
try { vol = Float.parseFloat(s); } |
297 |
|
|
catch(NumberFormatException x) { throw new LscpException ( |
298 |
|
|
LscpI18n.getLogMsg("CommandFailed!"), x |
299 |
|
|
);} |
300 |
iliev |
784 |
} else if(s.startsWith("MUTE: ")) { |
301 |
|
|
s = s.substring("MUTE: ".length()); |
302 |
|
|
if(s.equals("MUTED_BY_SOLO")) mute = MUTED_BY_SOLO; |
303 |
|
|
else mute = Boolean.parseBoolean(s) ? 1 : 0; |
304 |
|
|
} else if(s.startsWith("SOLO: ")) { |
305 |
|
|
s = s.substring("SOLO: ".length()); |
306 |
|
|
solo = Boolean.parseBoolean(s); |
307 |
iliev |
1139 |
} else if(s.startsWith("MIDI_INSTRUMENT_MAP: ")) { |
308 |
|
|
s = s.substring("MIDI_INSTRUMENT_MAP: ".length()); |
309 |
|
|
if(s.equals("NONE")) midiInstrumentMapId = -1; |
310 |
|
|
else if(s.equals("DEFAULT")) midiInstrumentMapId = -2; |
311 |
|
|
else midiInstrumentMapId = Parser.parseInt(s); |
312 |
iliev |
596 |
} else return false; |
313 |
|
|
|
314 |
|
|
return true; |
315 |
|
|
} |
316 |
iliev |
784 |
|
317 |
|
|
/** |
318 |
|
|
* Returns the numerical ID of this sampler channel. |
319 |
|
|
* @return The numerical ID of this sampler channel. |
320 |
|
|
*/ |
321 |
|
|
public String |
322 |
iliev |
1139 |
toString() { return String.valueOf(getChannelId()); } |
323 |
iliev |
596 |
} |