/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/SamplerChannel.java
ViewVC logotype

Contents of /jlscp/trunk/src/org/linuxsampler/lscp/SamplerChannel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1139 - (show annotations) (download)
Mon Apr 2 20:43:58 2007 UTC (17 years ago) by iliev
File size: 11181 byte(s)
* upgraded to version 0.4a

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

  ViewVC Help
Powered by ViewVC