1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler 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 |
* JSampler 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 JSampler; 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.jsampler.task; |
24 |
|
25 |
import org.jsampler.AudioDeviceModel; |
26 |
import org.jsampler.CC; |
27 |
import org.jsampler.SamplerModel; |
28 |
|
29 |
import org.linuxsampler.lscp.AudioOutputDevice; |
30 |
import org.linuxsampler.lscp.AudioOutputDriver; |
31 |
import org.linuxsampler.lscp.Parameter; |
32 |
|
33 |
import static org.jsampler.JSI18n.i18n; |
34 |
|
35 |
|
36 |
/** |
37 |
* Provides the audio specific tasks. |
38 |
* @author Grigor Iliev |
39 |
*/ |
40 |
public class Audio { |
41 |
/** Forbits the instantiation of this class. */ |
42 |
private Audio() { } |
43 |
|
44 |
/** |
45 |
* This task retrieves all audio output drivers currently |
46 |
* available for the LinuxSampler instance. |
47 |
*/ |
48 |
public static class GetDrivers extends EnhancedTask<AudioOutputDriver[]> { |
49 |
/** Creates a new instance of <code>GetDrivers</code>. */ |
50 |
public |
51 |
GetDrivers() { |
52 |
setTitle("Audio.GetDrivers_task"); |
53 |
setDescription(i18n.getMessage("Audio.GetDrivers.desc")); |
54 |
} |
55 |
|
56 |
/** The entry point of the task. */ |
57 |
@Override |
58 |
public void |
59 |
exec() throws Exception { setResult(CC.getClient().getAudioOutputDrivers()); } |
60 |
} |
61 |
|
62 |
/** |
63 |
* This task retrieves detailed information about all parameters |
64 |
* of the specified audio output driver. |
65 |
*/ |
66 |
public static class GetDriverParametersInfo extends EnhancedTask<Parameter[]> { |
67 |
private String driver; |
68 |
Parameter[] depList; |
69 |
|
70 |
/** |
71 |
* Creates a new instance of <code>GetDriverParametersInfo</code>. |
72 |
* @param depList - A dependences list. |
73 |
*/ |
74 |
public |
75 |
GetDriverParametersInfo(String driver, Parameter... depList) { |
76 |
setTitle("Audio.GetDriverParametersInfo_task"); |
77 |
setDescription(i18n.getMessage("Audio.GetDriverParametersInfo.desc")); |
78 |
|
79 |
this.driver = driver; |
80 |
this.depList = depList; |
81 |
} |
82 |
|
83 |
/** The entry point of the task. */ |
84 |
@Override |
85 |
public void |
86 |
exec() throws Exception { |
87 |
AudioOutputDriver d; |
88 |
d = CC.getClient().getAudioOutputDriverInfo(driver, depList); |
89 |
setResult(d.getParameters()); |
90 |
} |
91 |
} |
92 |
|
93 |
/** |
94 |
* This task creates a new audio output device. |
95 |
*/ |
96 |
public static class CreateDevice extends EnhancedTask<Integer> { |
97 |
private String driver; |
98 |
private Parameter[] parameters; |
99 |
|
100 |
|
101 |
/** |
102 |
* Creates a new instance of <code>CreateDevice</code>. |
103 |
* @param driver The desired audio output system. |
104 |
* @param parameters An optional list of driver specific parameters. |
105 |
*/ |
106 |
public |
107 |
CreateDevice(String driver, Parameter... parameters) { |
108 |
setTitle("Audio.CreateDevice_task"); |
109 |
setDescription(i18n.getMessage("Audio.CreateDevice.desc")); |
110 |
|
111 |
this.driver = driver; |
112 |
this.parameters = parameters; |
113 |
} |
114 |
|
115 |
/** The entry point of the task. */ |
116 |
@Override |
117 |
public void |
118 |
exec() throws Exception { |
119 |
Integer deviceId = CC.getClient().createAudioOutputDevice(driver, parameters); |
120 |
setResult(deviceId); |
121 |
} |
122 |
} |
123 |
|
124 |
/** |
125 |
* This task destroys the specified audio output device. |
126 |
*/ |
127 |
public static class DestroyDevice extends EnhancedTask { |
128 |
private int deviceId; |
129 |
|
130 |
|
131 |
/** |
132 |
* Creates a new instance of <code>DestroyDevice</code>. |
133 |
* @param deviceId The ID of the audio output device to be destroyed. |
134 |
*/ |
135 |
public |
136 |
DestroyDevice(int deviceId) { |
137 |
setTitle("Audio.DestroyDevice_task"); |
138 |
setDescription(i18n.getMessage("Audio.DestroyDevice.desc", deviceId)); |
139 |
|
140 |
this.deviceId = deviceId; |
141 |
} |
142 |
|
143 |
/** The entry point of the task. */ |
144 |
@Override |
145 |
public void |
146 |
exec() throws Exception { CC.getClient().destroyAudioOutputDevice(deviceId); } |
147 |
} |
148 |
|
149 |
/** |
150 |
* This task enables/disables a specific audio output device. |
151 |
*/ |
152 |
public static class EnableDevice extends EnhancedTask { |
153 |
private int dev; |
154 |
private boolean enable; |
155 |
|
156 |
/** |
157 |
* Creates new instance of <code>EnableDevice</code>. |
158 |
* @param dev The id of the device to be enabled/disabled. |
159 |
* @param enable Specify <code>true</code> to enable the audio device; |
160 |
* code>false</code> to disable it. |
161 |
*/ |
162 |
public |
163 |
EnableDevice(int dev, boolean enable) { |
164 |
setTitle("Audio.EnableDevice_task"); |
165 |
setDescription(i18n.getMessage("Audio.EnableDevice.desc", dev)); |
166 |
|
167 |
this.dev = dev; |
168 |
this.enable = enable; |
169 |
} |
170 |
|
171 |
/** The entry point of the task. */ |
172 |
@Override |
173 |
public void |
174 |
exec() throws Exception { |
175 |
CC.getClient().enableAudioOutputDevice(dev, enable); |
176 |
|
177 |
// Not needed, but eventually speeds up the change. |
178 |
CC.getSamplerModel().getAudioDeviceById(dev).setActive(enable); |
179 |
} |
180 |
} |
181 |
|
182 |
/** |
183 |
* This task alters a specific setting of an audio output device. |
184 |
*/ |
185 |
public static class SetDeviceParameter extends EnhancedTask { |
186 |
private int dev; |
187 |
private Parameter prm; |
188 |
|
189 |
/** |
190 |
* Creates new instance of <code>SetDeviceParameter</code>. |
191 |
* @param dev The id of the device whose parameter should be set. |
192 |
* @param prm The parameter to be set. |
193 |
*/ |
194 |
public |
195 |
SetDeviceParameter(int dev, Parameter prm) { |
196 |
setTitle("Audio.SetDeviceParameter_task"); |
197 |
setDescription(i18n.getMessage("Audio.SetDeviceParameter.desc", dev)); |
198 |
|
199 |
this.dev = dev; |
200 |
this.prm = prm; |
201 |
} |
202 |
|
203 |
/** The entry point of the task. */ |
204 |
@Override |
205 |
public void |
206 |
exec() throws Exception { |
207 |
CC.getClient().setAudioOutputDeviceParameter(dev, prm); |
208 |
} |
209 |
} |
210 |
|
211 |
/** |
212 |
* This task alters a specific setting of an audio output channel. |
213 |
*/ |
214 |
public static class SetChannelParameter extends EnhancedTask { |
215 |
private int dev; |
216 |
private int channel; |
217 |
private Parameter prm; |
218 |
|
219 |
/** |
220 |
* Creates new instance of <code>SetChannelParameter</code>. |
221 |
* @param dev The id of the device whose channel parameter should be set. |
222 |
* @param channel The channel number. |
223 |
* @param prm The parameter to be set. |
224 |
*/ |
225 |
public |
226 |
SetChannelParameter(int dev, int channel, Parameter prm) { |
227 |
setTitle("Audio.SetChannelParameter_task"); |
228 |
setDescription(i18n.getMessage("Audio.SetChannelParameter.desc")); |
229 |
|
230 |
this.dev = dev; |
231 |
this.channel = channel; |
232 |
this.prm = prm; |
233 |
} |
234 |
|
235 |
/** The entry point of the task. */ |
236 |
@Override |
237 |
public void |
238 |
exec() throws Exception { |
239 |
CC.getClient().setAudioOutputChannelParameter(dev, channel, prm); |
240 |
} |
241 |
} |
242 |
|
243 |
/** |
244 |
* This task changes the channel number of the speicifed audio output device. |
245 |
*/ |
246 |
public static class SetChannelCount extends EnhancedTask { |
247 |
private int deviceId; |
248 |
private int channels; |
249 |
|
250 |
/** |
251 |
* Creates new instance of <code>SetChannelCount</code>. |
252 |
* @param deviceId The id of the device whose channels number will be changed. |
253 |
* @param channels The new number of audio channels. |
254 |
*/ |
255 |
public |
256 |
SetChannelCount(int deviceId, int channels) { |
257 |
setTitle("SetAudioOutputChannelCount_task"); |
258 |
setDescription(i18n.getMessage("Audio.SetChannelCount.desc", deviceId)); |
259 |
|
260 |
this.deviceId = deviceId; |
261 |
this.channels = channels; |
262 |
} |
263 |
|
264 |
/** The entry point of the task. */ |
265 |
@Override |
266 |
public void |
267 |
exec() throws Exception { |
268 |
CC.getClient().setAudioOutputChannelCount(deviceId, channels); |
269 |
} |
270 |
} |
271 |
|
272 |
|
273 |
/** |
274 |
* This task updates the setting of an audio output device. |
275 |
*/ |
276 |
public static class UpdateDeviceInfo extends EnhancedTask { |
277 |
private int dev; |
278 |
|
279 |
/** |
280 |
* Creates new instance of <code>UpdateDeviceInfo</code>. |
281 |
* @param dev The id of the device, which settings should be updated. |
282 |
*/ |
283 |
public |
284 |
UpdateDeviceInfo(int dev) { |
285 |
setTitle("Audio.UpdateDeviceInfo_task"); |
286 |
setDescription(i18n.getMessage("Audio.UpdateDeviceInfo.desc", dev)); |
287 |
|
288 |
this.dev = dev; |
289 |
} |
290 |
|
291 |
/** The entry point of the task. */ |
292 |
@Override |
293 |
public void |
294 |
exec() throws Exception { |
295 |
AudioOutputDevice d = CC.getClient().getAudioOutputDeviceInfo(dev); |
296 |
CC.getSamplerModel().getAudioDeviceById(dev).setDeviceInfo(d); |
297 |
} |
298 |
} |
299 |
|
300 |
/** |
301 |
* This task updates the audio output device list. |
302 |
*/ |
303 |
public static class UpdateDevices extends EnhancedTask { |
304 |
/** Creates a new instance of <code>UpdateDevices</code>. */ |
305 |
public |
306 |
UpdateDevices() { |
307 |
setTitle("Audio.UpdateDevices_task"); |
308 |
setDescription(i18n.getMessage("Audio.UpdateDevices.desc")); |
309 |
} |
310 |
|
311 |
/** The entry point of the task. */ |
312 |
@Override |
313 |
public void |
314 |
exec() throws Exception { |
315 |
SamplerModel sm = CC.getSamplerModel(); |
316 |
Integer[] devIDs = CC.getClient().getAudioOutputDeviceIDs(); |
317 |
|
318 |
boolean found = false; |
319 |
|
320 |
for(AudioDeviceModel m : sm.getAudioDevices()) { |
321 |
for(int i = 0; i < devIDs.length; i++) { |
322 |
if(m.getDeviceId() == devIDs[i]) { |
323 |
devIDs[i] = -1; |
324 |
found = true; |
325 |
} |
326 |
} |
327 |
|
328 |
if(!found) sm.removeAudioDeviceById(m.getDeviceId()); |
329 |
found = false; |
330 |
} |
331 |
|
332 |
AudioOutputDevice d; |
333 |
|
334 |
for(int id : devIDs) { |
335 |
if(id >= 0) { |
336 |
d = CC.getClient().getAudioOutputDeviceInfo(id); |
337 |
sm.addAudioDevice(d); |
338 |
} |
339 |
} |
340 |
} |
341 |
} |
342 |
|
343 |
} |