1 |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
4 |
* Copyright (C) 2005 Grigor Kirilov Iliev |
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 current settings of a specific sampler channel. |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class SamplerChannel implements Parseable { |
30 |
private int chnID = -1; |
31 |
|
32 |
private String engine = null; |
33 |
private int aoDevice = -1; |
34 |
private int aoChannels = 0; |
35 |
private Integer[] aor = null; |
36 |
private String instrFile = null; |
37 |
private int instrIdx = 0; |
38 |
private String instrName = null; |
39 |
private int instrStat = 0; |
40 |
private int miDev = -1; |
41 |
private int miPort = 0; |
42 |
private int miChn = -1; |
43 |
private float vol = 0; |
44 |
|
45 |
/** Creates a new instance of SamplerChannel */ |
46 |
public |
47 |
SamplerChannel() { |
48 |
} |
49 |
|
50 |
/** |
51 |
* Creates a new instance of <code>SamplerChannel</code> and parses the information |
52 |
* about a specific sampler channel described by <code>resultSet</code>. |
53 |
* @param resultSet An array with information categories about a sampler channel. |
54 |
* @throws LscpException If the parse fail. |
55 |
*/ |
56 |
public |
57 |
SamplerChannel(String[] resultSet) throws LscpException { |
58 |
for(String s : resultSet) |
59 |
if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s)); |
60 |
} |
61 |
|
62 |
/** |
63 |
* Gets the sampler channel number. |
64 |
* @return The sampler channel number or -1 if the sampler channel number is not set. |
65 |
*/ |
66 |
public int |
67 |
getChannelID() { return chnID; } |
68 |
|
69 |
/** |
70 |
* Sets the sampler channel number. |
71 |
* @param id The new sampler channel number. |
72 |
*/ |
73 |
public void |
74 |
setChannelID(int id) { chnID = id; } |
75 |
|
76 |
/** |
77 |
* Gets the name of the engine that is deployed on the sampler channel. |
78 |
* @return The name of the engine that is deployed on the sampler channel |
79 |
* or <code>null</code> if there is no engine deployed yet for this sampler channel. |
80 |
*/ |
81 |
public String |
82 |
getEngineName() { return engine; } |
83 |
|
84 |
/** |
85 |
* Gets the numerical ID of the audio output device which is currently connected |
86 |
* to this sampler channel to output the audio signal. |
87 |
* |
88 |
* @return The numerical ID of the audio output device or -1 if there is no |
89 |
* device connected to this sampler channel. |
90 |
*/ |
91 |
public int |
92 |
getAudioOutputDevice() { return aoDevice; } |
93 |
|
94 |
/** |
95 |
* Gets the number of output channels the sampler channel offers. |
96 |
* @return The number of output channels the sampler channel offers. |
97 |
*/ |
98 |
public int |
99 |
getAudioOutputChannels() { return aoChannels; } |
100 |
|
101 |
/** |
102 |
* Gets a list which reflects to which audio channel of the selected audio output device |
103 |
* each sampler output channel is routed to. |
104 |
* @return A list which reflects to which audio channel of the selected audio output device |
105 |
* each sampler output channel is routed to. |
106 |
*/ |
107 |
public Integer[] |
108 |
getAudioOutputRouting() { return aor; } |
109 |
|
110 |
/** |
111 |
* Gets the file name of the loaded instrument. |
112 |
* @return The file name of the loaded instrument. |
113 |
* or <code>null</code> if there is no instrument yet loaded for this sampler channel. |
114 |
*/ |
115 |
public String |
116 |
getInstrumentFile() { return instrFile; } |
117 |
|
118 |
/** |
119 |
* Gets the instrument index number of the loaded instrument. |
120 |
* @return The instrument index number of the loaded instrument. |
121 |
*/ |
122 |
public int |
123 |
getInstrumentIndex() { return instrIdx; } |
124 |
|
125 |
/** |
126 |
* Gets the instrument name of the loaded instrument. |
127 |
* @return The instrument name of the loaded instrument. |
128 |
*/ |
129 |
public String |
130 |
getInstrumentName() { return instrName; } |
131 |
|
132 |
/** |
133 |
* Gets the instrument status - an integer values from 0 to 100 indicating loading |
134 |
* progress percentage for the instrument. Negative value indicates a loading exception. |
135 |
* Value of 100 indicates that the instrument is fully loaded. |
136 |
* @return The instrument status. |
137 |
*/ |
138 |
public int |
139 |
getInstrumentStatus() { return instrStat; } |
140 |
|
141 |
/** |
142 |
* Gets the numerical ID of the MIDI input device which is currently connected |
143 |
* to this sampler channel to deliver MIDI input commands. |
144 |
* @return The numerical ID of the MIDI input device which is currently connected |
145 |
* to this sampler channel to deliver MIDI input commands or -1 if there is no device |
146 |
* connected to this sampler channel. |
147 |
*/ |
148 |
public int |
149 |
getMidiInputDevice() { return miDev; } |
150 |
|
151 |
/** |
152 |
* Gets the port number of the MIDI input device. |
153 |
* @return The port number of the MIDI input device. |
154 |
*/ |
155 |
public int |
156 |
getMidiInputPort() { return miPort; } |
157 |
|
158 |
/** |
159 |
* Gets the MIDI input channel number this sampler channel should listen to |
160 |
* or -1 to listen on all MIDI channels. |
161 |
* @return The MIDI input channel number this sampler channel should listen to |
162 |
* or -1 to listen on all MIDI channels. |
163 |
*/ |
164 |
public int |
165 |
getMidiInputChannel() { return miChn; } |
166 |
|
167 |
/** |
168 |
* Gets the channel volume factor. Value less then 1.0 means attenuation, |
169 |
* value greater then 1.0 means amplification. |
170 |
* @return The channel volume factor. |
171 |
*/ |
172 |
public float |
173 |
getVolume() { return vol; } |
174 |
|
175 |
/** |
176 |
* Parses a line of text. |
177 |
* @param s The string to be parsed. |
178 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
179 |
* @throws LscpException If some error occurs. |
180 |
*/ |
181 |
public boolean |
182 |
parse(String s) throws LscpException { |
183 |
if(s.startsWith("ENGINE_NAME: ")) { |
184 |
s = s.substring("ENGINE_NAME: ".length()); |
185 |
if(s.equals("NONE")) engine = null; |
186 |
else engine = s; |
187 |
} else if(s.startsWith("AUDIO_OUTPUT_DEVICE: ")) { |
188 |
s = s.substring("AUDIO_OUTPUT_DEVICE: ".length()); |
189 |
if(s.equals("NONE")) aoDevice = -1; |
190 |
else aoDevice = Parser.parseInt(s); |
191 |
} else if(s.startsWith("AUDIO_OUTPUT_CHANNELS: ")) { |
192 |
s = s.substring("AUDIO_OUTPUT_CHANNELS: ".length()); |
193 |
if(s.equals("NONE")) aoChannels = -1; |
194 |
else aoChannels = Parser.parseInt(s); |
195 |
} else if(s.startsWith("AUDIO_OUTPUT_ROUTING: ")) { |
196 |
s = s.substring("AUDIO_OUTPUT_ROUTING: ".length()); |
197 |
aor = Parser.parseIntList(s); |
198 |
} else if(s.startsWith("INSTRUMENT_FILE: ")) { |
199 |
s = s.substring("INSTRUMENT_FILE: ".length()); |
200 |
if(s.equals("NONE")) instrFile = null; |
201 |
else instrFile = s; |
202 |
} else if(s.startsWith("INSTRUMENT_NR: ")) { |
203 |
s = s.substring("INSTRUMENT_NR: ".length()); |
204 |
if(s.equals("NONE")) instrIdx = -1; |
205 |
else instrIdx = Parser.parseInt(s); |
206 |
} else if(s.startsWith("INSTRUMENT_NAME: ")) { |
207 |
instrName = s.substring("INSTRUMENT_NAME: ".length()); |
208 |
} else if(s.startsWith("INSTRUMENT_STATUS: ")) { |
209 |
s = s.substring("INSTRUMENT_STATUS: ".length()); |
210 |
instrStat = Parser.parseInt(s); |
211 |
} else if(s.startsWith("MIDI_INPUT_DEVICE: ")) { |
212 |
s = s.substring("MIDI_INPUT_DEVICE: ".length()); |
213 |
if(s.equals("NONE")) miDev = -1; |
214 |
else miDev = Parser.parseInt(s); |
215 |
} else if(s.startsWith("MIDI_INPUT_PORT: ")) { |
216 |
s = s.substring("MIDI_INPUT_PORT: ".length()); |
217 |
if(s.equals("NONE")) miPort = -1; |
218 |
else miPort = Parser.parseInt(s); |
219 |
} else if(s.startsWith("MIDI_INPUT_CHANNEL: ")) { |
220 |
s = s.substring("MIDI_INPUT_CHANNEL: ".length()); |
221 |
if(s.equals("ALL")) miChn = -1; |
222 |
else miChn = Parser.parseInt(s); |
223 |
} else if(s.startsWith("VOLUME: ")) { |
224 |
s = s.substring("VOLUME: ".length()); |
225 |
try { vol = Float.parseFloat(s); } |
226 |
catch(NumberFormatException x) { throw new LscpException ( |
227 |
LscpI18n.getLogMsg("CommandFailed!"), x |
228 |
);} |
229 |
} else return false; |
230 |
|
231 |
return true; |
232 |
} |
233 |
} |