1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2011 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 java.util.ArrayList; |
26 |
|
27 |
import org.jsampler.AudioDeviceModel; |
28 |
import org.jsampler.CC; |
29 |
import org.jsampler.EffectChain; |
30 |
import org.jsampler.SamplerChannelModel; |
31 |
import org.jsampler.SamplerModel; |
32 |
|
33 |
import org.linuxsampler.lscp.AudioOutputDevice; |
34 |
import org.linuxsampler.lscp.AudioOutputDriver; |
35 |
import org.linuxsampler.lscp.EffectChainInfo; |
36 |
import org.linuxsampler.lscp.EffectInstanceInfo; |
37 |
import org.linuxsampler.lscp.Effect; |
38 |
import org.linuxsampler.lscp.Parameter; |
39 |
|
40 |
import static org.jsampler.JSI18n.i18n; |
41 |
|
42 |
|
43 |
/** |
44 |
* Provides the audio specific tasks. |
45 |
* @author Grigor Iliev |
46 |
*/ |
47 |
public class Audio { |
48 |
/** Forbids the instantiation of this class. */ |
49 |
private Audio() { } |
50 |
|
51 |
/** |
52 |
* This task retrieves all audio output drivers currently |
53 |
* available for the LinuxSampler instance. |
54 |
*/ |
55 |
public static class GetDrivers extends EnhancedTask<AudioOutputDriver[]> { |
56 |
/** Creates a new instance of <code>GetDrivers</code>. */ |
57 |
public |
58 |
GetDrivers() { |
59 |
setTitle("Audio.GetDrivers_task"); |
60 |
setDescription(i18n.getMessage("Audio.GetDrivers.desc")); |
61 |
} |
62 |
|
63 |
/** The entry point of the task. */ |
64 |
@Override |
65 |
public void |
66 |
exec() throws Exception { setResult(CC.getClient().getAudioOutputDrivers()); } |
67 |
} |
68 |
|
69 |
/** |
70 |
* This task retrieves detailed information about all parameters |
71 |
* of the specified audio output driver. |
72 |
*/ |
73 |
public static class GetDriverParametersInfo extends EnhancedTask<Parameter[]> { |
74 |
private String driver; |
75 |
Parameter[] depList; |
76 |
|
77 |
/** |
78 |
* Creates a new instance of <code>GetDriverParametersInfo</code>. |
79 |
* @param depList - A dependences list. |
80 |
*/ |
81 |
public |
82 |
GetDriverParametersInfo(String driver, Parameter... depList) { |
83 |
setTitle("Audio.GetDriverParametersInfo_task"); |
84 |
setDescription(i18n.getMessage("Audio.GetDriverParametersInfo.desc")); |
85 |
|
86 |
this.driver = driver; |
87 |
this.depList = depList; |
88 |
} |
89 |
|
90 |
/** The entry point of the task. */ |
91 |
@Override |
92 |
public void |
93 |
exec() throws Exception { |
94 |
AudioOutputDriver d; |
95 |
d = CC.getClient().getAudioOutputDriverInfo(driver, depList); |
96 |
setResult(d.getParameters()); |
97 |
} |
98 |
} |
99 |
|
100 |
/** |
101 |
* This task creates a new audio output device. |
102 |
*/ |
103 |
public static class CreateDevice extends EnhancedTask<Integer> { |
104 |
private String driver; |
105 |
private Parameter[] parameters; |
106 |
|
107 |
|
108 |
/** |
109 |
* Creates a new instance of <code>CreateDevice</code>. |
110 |
* @param driver The desired audio output system. |
111 |
* @param parameters An optional list of driver specific parameters. |
112 |
*/ |
113 |
public |
114 |
CreateDevice(String driver, Parameter... parameters) { |
115 |
setTitle("Audio.CreateDevice_task"); |
116 |
setDescription(i18n.getMessage("Audio.CreateDevice.desc")); |
117 |
|
118 |
this.driver = driver; |
119 |
this.parameters = parameters; |
120 |
} |
121 |
|
122 |
/** The entry point of the task. */ |
123 |
@Override |
124 |
public void |
125 |
exec() throws Exception { |
126 |
Integer deviceId = CC.getClient().createAudioOutputDevice(driver, parameters); |
127 |
setResult(deviceId); |
128 |
} |
129 |
} |
130 |
|
131 |
/** |
132 |
* This task destroys the specified audio output device. |
133 |
*/ |
134 |
public static class DestroyDevice extends EnhancedTask { |
135 |
private int deviceId; |
136 |
|
137 |
|
138 |
/** |
139 |
* Creates a new instance of <code>DestroyDevice</code>. |
140 |
* @param deviceId The ID of the audio output device to be destroyed. |
141 |
*/ |
142 |
public |
143 |
DestroyDevice(int deviceId) { |
144 |
setTitle("Audio.DestroyDevice_task"); |
145 |
setDescription(i18n.getMessage("Audio.DestroyDevice.desc", deviceId)); |
146 |
|
147 |
this.deviceId = deviceId; |
148 |
} |
149 |
|
150 |
/** The entry point of the task. */ |
151 |
@Override |
152 |
public void |
153 |
exec() throws Exception { CC.getClient().destroyAudioOutputDevice(deviceId); } |
154 |
} |
155 |
|
156 |
/** |
157 |
* This task enables/disables a specific audio output device. |
158 |
*/ |
159 |
public static class EnableDevice extends EnhancedTask { |
160 |
private int dev; |
161 |
private boolean enable; |
162 |
|
163 |
/** |
164 |
* Creates new instance of <code>EnableDevice</code>. |
165 |
* @param dev The id of the device to be enabled/disabled. |
166 |
* @param enable Specify <code>true</code> to enable the audio device; |
167 |
* code>false</code> to disable it. |
168 |
*/ |
169 |
public |
170 |
EnableDevice(int dev, boolean enable) { |
171 |
setTitle("Audio.EnableDevice_task"); |
172 |
setDescription(i18n.getMessage("Audio.EnableDevice.desc", dev)); |
173 |
|
174 |
this.dev = dev; |
175 |
this.enable = enable; |
176 |
} |
177 |
|
178 |
/** The entry point of the task. */ |
179 |
@Override |
180 |
public void |
181 |
exec() throws Exception { |
182 |
CC.getClient().enableAudioOutputDevice(dev, enable); |
183 |
|
184 |
// Not needed, but eventually speeds up the change. |
185 |
CC.getSamplerModel().getAudioDeviceById(dev).setActive(enable); |
186 |
} |
187 |
} |
188 |
|
189 |
/** |
190 |
* This task alters a specific setting of an audio output device. |
191 |
*/ |
192 |
public static class SetDeviceParameter extends EnhancedTask { |
193 |
private int dev; |
194 |
private Parameter prm; |
195 |
|
196 |
/** |
197 |
* Creates new instance of <code>SetDeviceParameter</code>. |
198 |
* @param dev The id of the device whose parameter should be set. |
199 |
* @param prm The parameter to be set. |
200 |
*/ |
201 |
public |
202 |
SetDeviceParameter(int dev, Parameter prm) { |
203 |
setTitle("Audio.SetDeviceParameter_task"); |
204 |
setDescription(i18n.getMessage("Audio.SetDeviceParameter.desc", dev)); |
205 |
|
206 |
this.dev = dev; |
207 |
this.prm = prm; |
208 |
} |
209 |
|
210 |
/** The entry point of the task. */ |
211 |
@Override |
212 |
public void |
213 |
exec() throws Exception { |
214 |
CC.getClient().setAudioOutputDeviceParameter(dev, prm); |
215 |
} |
216 |
} |
217 |
|
218 |
/** |
219 |
* This task alters a specific setting of an audio output channel. |
220 |
*/ |
221 |
public static class SetChannelParameter extends EnhancedTask { |
222 |
private int dev; |
223 |
private int channel; |
224 |
private Parameter prm; |
225 |
|
226 |
/** |
227 |
* Creates new instance of <code>SetChannelParameter</code>. |
228 |
* @param dev The id of the device whose channel parameter should be set. |
229 |
* @param channel The channel number. |
230 |
* @param prm The parameter to be set. |
231 |
*/ |
232 |
public |
233 |
SetChannelParameter(int dev, int channel, Parameter prm) { |
234 |
setTitle("Audio.SetChannelParameter_task"); |
235 |
setDescription(i18n.getMessage("Audio.SetChannelParameter.desc")); |
236 |
|
237 |
this.dev = dev; |
238 |
this.channel = channel; |
239 |
this.prm = prm; |
240 |
} |
241 |
|
242 |
/** The entry point of the task. */ |
243 |
@Override |
244 |
public void |
245 |
exec() throws Exception { |
246 |
CC.getClient().setAudioOutputChannelParameter(dev, channel, prm); |
247 |
} |
248 |
} |
249 |
|
250 |
/** |
251 |
* This task changes the channel number of the speicifed audio output device. |
252 |
*/ |
253 |
public static class SetChannelCount extends EnhancedTask { |
254 |
private int deviceId; |
255 |
private int channels; |
256 |
|
257 |
/** |
258 |
* Creates new instance of <code>SetChannelCount</code>. |
259 |
* @param deviceId The id of the device whose channels number will be changed. |
260 |
* @param channels The new number of audio channels. |
261 |
*/ |
262 |
public |
263 |
SetChannelCount(int deviceId, int channels) { |
264 |
setTitle("SetAudioOutputChannelCount_task"); |
265 |
setDescription(i18n.getMessage("Audio.SetChannelCount.desc", deviceId)); |
266 |
|
267 |
this.deviceId = deviceId; |
268 |
this.channels = channels; |
269 |
} |
270 |
|
271 |
/** The entry point of the task. */ |
272 |
@Override |
273 |
public void |
274 |
exec() throws Exception { |
275 |
CC.getClient().setAudioOutputChannelCount(deviceId, channels); |
276 |
} |
277 |
} |
278 |
|
279 |
/** |
280 |
* This task adds a send effect chain to the specified audio output device. |
281 |
*/ |
282 |
public static class AddSendEffectChain extends EnhancedTask<Integer> { |
283 |
private int audioDeviceId; |
284 |
|
285 |
/** |
286 |
* Creates a new instance of <code>AddSendEffectChain</code>. |
287 |
* @param audioDeviceId The numerical ID of the audio output device. |
288 |
*/ |
289 |
public |
290 |
AddSendEffectChain(int audioDeviceId) { |
291 |
setTitle("Audio.AddSendEffectChain_task"); |
292 |
setDescription(i18n.getMessage("Audio.AddSendEffectChain.desc")); |
293 |
|
294 |
this.audioDeviceId = audioDeviceId; |
295 |
} |
296 |
|
297 |
/** The entry point of the task. */ |
298 |
@Override |
299 |
public void |
300 |
exec() throws Exception { |
301 |
Integer chainId = CC.getClient().addSendEffectChain(audioDeviceId); |
302 |
setResult(chainId); |
303 |
} |
304 |
} |
305 |
|
306 |
/** |
307 |
* This task removes the specified send effect chain of the specified audio output device. |
308 |
*/ |
309 |
public static class RemoveSendEffectChain extends EnhancedTask { |
310 |
private int audioDeviceId; |
311 |
private int chainId; |
312 |
|
313 |
/** |
314 |
* Creates a new instance of <code>RemoveSendEffectChain</code>. |
315 |
* @param audioDeviceId The numerical ID of the audio output device. |
316 |
* @param chainId The numerical ID of the send effect chain to remove. |
317 |
*/ |
318 |
public |
319 |
RemoveSendEffectChain(int audioDeviceId, int chainId) { |
320 |
setTitle("Audio.RemoveSendEffectChain_task"); |
321 |
setDescription(i18n.getMessage("Audio.RemoveSendEffectChain.desc")); |
322 |
|
323 |
this.audioDeviceId = audioDeviceId; |
324 |
this.chainId = chainId; |
325 |
} |
326 |
|
327 |
/** The entry point of the task. */ |
328 |
@Override |
329 |
public void |
330 |
exec() throws Exception { |
331 |
AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(audioDeviceId); |
332 |
EffectChain chain = adm.getSendEffectChainById(chainId); |
333 |
|
334 |
for(int i = 0; i < CC.getSamplerModel().getChannelCount(); i++) { |
335 |
SamplerChannelModel c = CC.getSamplerModel().getChannel(i); |
336 |
for(int j = 0; j < c.getFxSendCount(); j++) { |
337 |
if(c.getFxSend(j).getDestChainId() == chainId) { |
338 |
CC.getClient().removeFxSendEffect ( |
339 |
c.getChannelId(), c.getFxSend(j).getFxSendId() |
340 |
); |
341 |
} |
342 |
} |
343 |
} |
344 |
|
345 |
for(int i = chain.getEffectInstanceCount() - 1; i >= 0; i--) { |
346 |
CC.getClient().removeEffectInstanceFromChain ( |
347 |
audioDeviceId, chainId, i |
348 |
); |
349 |
|
350 |
int iid = chain.getEffectInstance(i).getInstanceId(); |
351 |
CC.getClient().destroyEffectInstance(iid); |
352 |
} |
353 |
CC.getClient().removeSendEffectChain(audioDeviceId, chainId); |
354 |
} |
355 |
} |
356 |
|
357 |
/** |
358 |
* This task creates new effect instances and inserts them |
359 |
* in the specified send effect chain at the specified position. |
360 |
*/ |
361 |
public static class AddNewEffectInstances extends EnhancedTask { |
362 |
private Effect[] effects; |
363 |
private int audioDeviceId; |
364 |
private int chainId; |
365 |
private int index; |
366 |
|
367 |
/** |
368 |
* Creates a new instance of <code>AddNewEffectInstances</code>. |
369 |
* @param audioDeviceId The numerical ID of the audio output device. |
370 |
* @param chainId The numerical ID of the send effect chain. |
371 |
* @param index The position in the chain where the newly created |
372 |
* effect instances should be inserted to. Use -1 to append. |
373 |
*/ |
374 |
public |
375 |
AddNewEffectInstances(Effect[] effects, int audioDeviceId, int chainId, int index) { |
376 |
setTitle("Audio.AddNewEffectInstances_task"); |
377 |
setDescription(i18n.getMessage("Audio.AddNewEffectInstances.desc")); |
378 |
|
379 |
this.effects = effects; |
380 |
this.audioDeviceId = audioDeviceId; |
381 |
this.chainId = chainId; |
382 |
this.index = index; |
383 |
} |
384 |
|
385 |
/** The entry point of the task. */ |
386 |
@Override |
387 |
public void |
388 |
exec() throws Exception { |
389 |
for(Effect e : effects) { |
390 |
int ei = CC.getClient().createEffectInstance(e); |
391 |
if(index != -1) { |
392 |
CC.getClient().insertEffectInstance(audioDeviceId, chainId, index, ei); |
393 |
} else { |
394 |
CC.getClient().appendEffectInstance(audioDeviceId, chainId, ei); |
395 |
} |
396 |
} |
397 |
} |
398 |
} |
399 |
|
400 |
/** |
401 |
* This task removes the specified effect instance from the specified send effect chain. |
402 |
*/ |
403 |
public static class RemoveEffectInstance extends EnhancedTask { |
404 |
private int audioDeviceId; |
405 |
private int chainId; |
406 |
private int instanceId; |
407 |
|
408 |
/** |
409 |
* Creates a new instance of <code>RemoveEffectInstance</code>. |
410 |
* @param audioDeviceId The numerical ID of the audio output device. |
411 |
* @param chainId The numerical ID of the send effect chain. |
412 |
* @param instanceId The numerical ID of the effect instance to remove. |
413 |
*/ |
414 |
public |
415 |
RemoveEffectInstance(int audioDeviceId, int chainId, int instanceId) { |
416 |
setTitle("Audio.RemoveEffectInstance_task"); |
417 |
setDescription(i18n.getMessage("Audio.RemoveEffectInstance.desc")); |
418 |
|
419 |
this.audioDeviceId = audioDeviceId; |
420 |
this.chainId = chainId; |
421 |
this.instanceId = instanceId; |
422 |
} |
423 |
|
424 |
/** The entry point of the task. */ |
425 |
@Override |
426 |
public void |
427 |
exec() throws Exception { |
428 |
AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(audioDeviceId); |
429 |
EffectChain chain = adm.getSendEffectChainById(chainId); |
430 |
|
431 |
CC.getClient().removeEffectInstanceFromChain ( |
432 |
audioDeviceId, chainId, chain.getIndex(instanceId) |
433 |
); |
434 |
|
435 |
CC.getClient().destroyEffectInstance(instanceId); |
436 |
|
437 |
} |
438 |
} |
439 |
|
440 |
|
441 |
/** |
442 |
* This task updates the send effect chain list of an audio output device. |
443 |
*/ |
444 |
public static class UpdateSendEffectChains extends EnhancedTask { |
445 |
private int devId; |
446 |
|
447 |
/** |
448 |
* Creates new instance of <code>UpdateSendEffectChains</code>. |
449 |
* @param devId The id of the device. |
450 |
*/ |
451 |
public |
452 |
UpdateSendEffectChains(int devId) { |
453 |
setTitle("Audio.UpdateSendEffectChains_task"); |
454 |
setDescription(i18n.getMessage("Audio.UpdateSendEffectChains.desc", devId)); |
455 |
|
456 |
this.devId = devId; |
457 |
} |
458 |
|
459 |
/** The entry point of the task. */ |
460 |
@Override |
461 |
public void |
462 |
exec() throws Exception { |
463 |
AudioDeviceModel m = CC.getSamplerModel().getAudioDeviceById(devId); |
464 |
|
465 |
Integer[] idS = CC.getClient().getSendEffectChainIDs(devId); |
466 |
|
467 |
ArrayList<Integer> removedChains = new ArrayList<Integer>(); |
468 |
|
469 |
for(int i = 0; i < m.getSendEffectChainCount(); i++) { |
470 |
boolean found = false; |
471 |
for(int j = 0; j < idS.length; j++) { |
472 |
if(idS[j] != null && m.getSendEffectChain(i).getChainId() == idS[j]) { |
473 |
found = true; |
474 |
idS[j] = null; |
475 |
} |
476 |
} |
477 |
if(!found) removedChains.add(m.getSendEffectChain(i).getChainId()); |
478 |
} |
479 |
|
480 |
for(int i : removedChains) m.removeSendEffectChain(i); |
481 |
|
482 |
for(int i = 0; i < idS.length; i++) { |
483 |
if(idS[i] != null) { |
484 |
m.addSendEffectChain ( |
485 |
new EffectChain(CC.getClient().getSendEffectChainInfo(devId, idS[i])) |
486 |
); |
487 |
} |
488 |
} |
489 |
} |
490 |
} |
491 |
|
492 |
/** |
493 |
* This task updates the list of effect instances. |
494 |
*/ |
495 |
public static class UpdateEffectInstances extends EnhancedTask { |
496 |
private int audioDeviceId; |
497 |
private int chainId; |
498 |
|
499 |
/** |
500 |
* Creates a new instance of <code>UpdateEffectInstances</code>. |
501 |
* @param audioDeviceId The numerical ID of the audio output device. |
502 |
* @param chainId The numerical ID of the send effect chain. |
503 |
*/ |
504 |
public |
505 |
UpdateEffectInstances(int audioDeviceId, int chainId) { |
506 |
setTitle("Audio.UpdateEffectInstances_task"); |
507 |
setDescription(i18n.getMessage("Audio.UpdateEffectInstances.desc")); |
508 |
|
509 |
this.audioDeviceId = audioDeviceId; |
510 |
this.chainId = chainId; |
511 |
} |
512 |
|
513 |
/** The entry point of the task. */ |
514 |
@Override |
515 |
public void |
516 |
exec() throws Exception { |
517 |
setSilent(true); |
518 |
|
519 |
EffectChainInfo c = |
520 |
CC.getClient().getSendEffectChainInfo(audioDeviceId, chainId); |
521 |
|
522 |
AudioDeviceModel m = CC.getSamplerModel().getAudioDeviceById(audioDeviceId); |
523 |
m.getSendEffectChainById(chainId).setEffectInstances(c); |
524 |
} |
525 |
} |
526 |
|
527 |
|
528 |
/** |
529 |
* This task updates the setting of an effect instance. |
530 |
*/ |
531 |
public static class UpdateEffectInstanceInfo extends EnhancedTask { |
532 |
private int instanceId; |
533 |
|
534 |
/** |
535 |
* Creates new instance of <code>UpdateEffectInstanceInfo</code>. |
536 |
* @param instanceId The id of the effect instance, which settings should be updated. |
537 |
*/ |
538 |
public |
539 |
UpdateEffectInstanceInfo(int instanceId) { |
540 |
setTitle("Audio.UpdateEffectInstanceInfo_task"); |
541 |
setDescription(i18n.getMessage("Audio.UpdateEffectInstanceInfo.desc", instanceId)); |
542 |
|
543 |
this.instanceId = instanceId; |
544 |
} |
545 |
|
546 |
/** The entry point of the task. */ |
547 |
@Override |
548 |
public void |
549 |
exec() throws Exception { |
550 |
EffectInstanceInfo ei = CC.getClient().getEffectInstanceInfo(instanceId); |
551 |
CC.getSamplerModel().updateEffectInstance(ei); |
552 |
} |
553 |
} |
554 |
|
555 |
|
556 |
/** |
557 |
* This task changes the value of an effect instance parameter. |
558 |
*/ |
559 |
public static class SetEffectInstanceParameter extends EnhancedTask { |
560 |
private int instanceId; |
561 |
private int prmIndex; |
562 |
private float newValue; |
563 |
|
564 |
/** |
565 |
* Creates new instance of <code>SetEffectInstanceParameter</code>. |
566 |
*/ |
567 |
public |
568 |
SetEffectInstanceParameter(int instanceId, int prmIndex, float newValue) { |
569 |
setTitle("Audio.SetEffectInstanceParameter_task"); |
570 |
setDescription(i18n.getMessage("Audio.SetEffectInstanceParameter.desc")); |
571 |
|
572 |
this.instanceId = instanceId; |
573 |
this.prmIndex = prmIndex; |
574 |
this.newValue = newValue; |
575 |
} |
576 |
|
577 |
/** The entry point of the task. */ |
578 |
@Override |
579 |
public void |
580 |
exec() throws Exception { |
581 |
CC.getClient().setEffectInstanceParameter(instanceId, prmIndex, newValue); |
582 |
} |
583 |
} |
584 |
|
585 |
|
586 |
/** |
587 |
* This task updates the setting of an audio output device. |
588 |
*/ |
589 |
public static class UpdateDeviceInfo extends EnhancedTask { |
590 |
private int dev; |
591 |
|
592 |
/** |
593 |
* Creates new instance of <code>UpdateDeviceInfo</code>. |
594 |
* @param dev The id of the device, which settings should be updated. |
595 |
*/ |
596 |
public |
597 |
UpdateDeviceInfo(int dev) { |
598 |
setTitle("Audio.UpdateDeviceInfo_task"); |
599 |
setDescription(i18n.getMessage("Audio.UpdateDeviceInfo.desc", dev)); |
600 |
|
601 |
this.dev = dev; |
602 |
} |
603 |
|
604 |
/** The entry point of the task. */ |
605 |
@Override |
606 |
public void |
607 |
exec() throws Exception { |
608 |
AudioOutputDevice d = CC.getClient().getAudioOutputDeviceInfo(dev); |
609 |
CC.getSamplerModel().getAudioDeviceById(dev).setDeviceInfo(d); |
610 |
} |
611 |
} |
612 |
|
613 |
/** |
614 |
* This task updates the audio output device list. |
615 |
*/ |
616 |
public static class UpdateDevices extends EnhancedTask { |
617 |
/** Creates a new instance of <code>UpdateDevices</code>. */ |
618 |
public |
619 |
UpdateDevices() { |
620 |
setTitle("Audio.UpdateDevices_task"); |
621 |
setDescription(i18n.getMessage("Audio.UpdateDevices.desc")); |
622 |
} |
623 |
|
624 |
/** The entry point of the task. */ |
625 |
@Override |
626 |
public void |
627 |
exec() throws Exception { |
628 |
SamplerModel sm = CC.getSamplerModel(); |
629 |
Integer[] devIDs = CC.getClient().getAudioOutputDeviceIDs(); |
630 |
|
631 |
boolean found = false; |
632 |
|
633 |
for(AudioDeviceModel m : sm.getAudioDevices()) { |
634 |
for(int i = 0; i < devIDs.length; i++) { |
635 |
if(m.getDeviceId() == devIDs[i]) { |
636 |
devIDs[i] = -1; |
637 |
found = true; |
638 |
} |
639 |
} |
640 |
|
641 |
if(!found) sm.removeAudioDeviceById(m.getDeviceId()); |
642 |
found = false; |
643 |
} |
644 |
|
645 |
AudioOutputDevice d; |
646 |
|
647 |
for(int id : devIDs) { |
648 |
if(id >= 0) { |
649 |
d = CC.getClient().getAudioOutputDeviceInfo(id); |
650 |
sm.addAudioDevice(d); |
651 |
} |
652 |
} |
653 |
} |
654 |
} |
655 |
|
656 |
} |