1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
22 |
|
|
23 |
package org.jsampler.task; |
package org.jsampler.task; |
24 |
|
|
25 |
|
import java.util.ArrayList; |
26 |
|
|
27 |
import org.jsampler.AudioDeviceModel; |
import org.jsampler.AudioDeviceModel; |
28 |
import org.jsampler.CC; |
import org.jsampler.CC; |
29 |
|
import org.jsampler.EffectChain; |
30 |
import org.jsampler.SamplerModel; |
import org.jsampler.SamplerModel; |
31 |
|
|
32 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
33 |
import org.linuxsampler.lscp.AudioOutputDriver; |
import org.linuxsampler.lscp.AudioOutputDriver; |
34 |
|
import org.linuxsampler.lscp.EffectInstance; |
35 |
|
import org.linuxsampler.lscp.Effect; |
36 |
import org.linuxsampler.lscp.Parameter; |
import org.linuxsampler.lscp.Parameter; |
37 |
|
|
38 |
import static org.jsampler.JSI18n.i18n; |
import static org.jsampler.JSI18n.i18n; |
43 |
* @author Grigor Iliev |
* @author Grigor Iliev |
44 |
*/ |
*/ |
45 |
public class Audio { |
public class Audio { |
46 |
/** Forbits the instantiation of this class. */ |
/** Forbids the instantiation of this class. */ |
47 |
private Audio() { } |
private Audio() { } |
48 |
|
|
49 |
/** |
/** |
274 |
} |
} |
275 |
} |
} |
276 |
|
|
277 |
|
/** |
278 |
|
* This task adds a send effect chain to the specified audio output device. |
279 |
|
*/ |
280 |
|
public static class AddSendEffectChain extends EnhancedTask<Integer> { |
281 |
|
private int audioDeviceId; |
282 |
|
|
283 |
|
/** |
284 |
|
* Creates a new instance of <code>AddSendEffectChain</code>. |
285 |
|
* @param audioDeviceId The numerical ID of the audio output device. |
286 |
|
*/ |
287 |
|
public |
288 |
|
AddSendEffectChain(int audioDeviceId) { |
289 |
|
setTitle("Audio.AddSendEffectChain_task"); |
290 |
|
setDescription(i18n.getMessage("Audio.AddSendEffectChain.desc")); |
291 |
|
|
292 |
|
this.audioDeviceId = audioDeviceId; |
293 |
|
} |
294 |
|
|
295 |
|
/** The entry point of the task. */ |
296 |
|
@Override |
297 |
|
public void |
298 |
|
exec() throws Exception { |
299 |
|
Integer chainId = CC.getClient().addSendEffectChain(audioDeviceId); |
300 |
|
setResult(chainId); |
301 |
|
} |
302 |
|
} |
303 |
|
|
304 |
|
/** |
305 |
|
* This task removes the specified send effect chain of the specified audio output device. |
306 |
|
*/ |
307 |
|
public static class RemoveSendEffectChain extends EnhancedTask { |
308 |
|
private int audioDeviceId; |
309 |
|
private int chainId; |
310 |
|
|
311 |
|
/** |
312 |
|
* Creates a new instance of <code>RemoveSendEffectChain</code>. |
313 |
|
* @param audioDeviceId The numerical ID of the audio output device. |
314 |
|
* @param chainId The numerical ID of the send effect chain to remove. |
315 |
|
*/ |
316 |
|
public |
317 |
|
RemoveSendEffectChain(int audioDeviceId, int chainId) { |
318 |
|
setTitle("Audio.RemoveSendEffectChain_task"); |
319 |
|
setDescription(i18n.getMessage("Audio.RemoveSendEffectChain.desc")); |
320 |
|
|
321 |
|
this.audioDeviceId = audioDeviceId; |
322 |
|
this.chainId = chainId; |
323 |
|
} |
324 |
|
|
325 |
|
/** The entry point of the task. */ |
326 |
|
@Override |
327 |
|
public void |
328 |
|
exec() throws Exception { |
329 |
|
AudioDeviceModel adm = CC.getSamplerModel().getAudioDevice(audioDeviceId); |
330 |
|
EffectChain chain = adm.getSendEffectChainById(chainId); |
331 |
|
|
332 |
|
for(int i = chain.getEffectInstanceCount() - 1; i >= 0; i--) { |
333 |
|
CC.getClient().removeEffectInstanceFromChain ( |
334 |
|
audioDeviceId, chainId, i |
335 |
|
); |
336 |
|
|
337 |
|
int iid = chain.getEffectInstance(i).getInstanceId(); |
338 |
|
CC.getClient().destroyEffectInstance(iid); |
339 |
|
} |
340 |
|
CC.getClient().removeSendEffectChain(audioDeviceId, chainId); |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
|
/** |
345 |
|
* This task creates new effect instances and inserts them |
346 |
|
* in the specified send effect chain at the specified position. |
347 |
|
*/ |
348 |
|
public static class AddNewEffectInstances extends EnhancedTask { |
349 |
|
private Effect[] effects; |
350 |
|
private int audioDeviceId; |
351 |
|
private int chainId; |
352 |
|
private int index; |
353 |
|
|
354 |
|
/** |
355 |
|
* Creates a new instance of <code>AddNewEffectInstances</code>. |
356 |
|
* @param audioDeviceId The numerical ID of the audio output device. |
357 |
|
* @param chainId The numerical ID of the send effect chain. |
358 |
|
* @param index The position in the chain where the newly created |
359 |
|
* effect instances should be inserted to. Use -1 to append. |
360 |
|
*/ |
361 |
|
public |
362 |
|
AddNewEffectInstances(Effect[] effects, int audioDeviceId, int chainId, int index) { |
363 |
|
setTitle("Audio.AddNewEffectInstances_task"); |
364 |
|
setDescription(i18n.getMessage("Audio.AddNewEffectInstances.desc")); |
365 |
|
|
366 |
|
this.effects = effects; |
367 |
|
this.audioDeviceId = audioDeviceId; |
368 |
|
this.chainId = chainId; |
369 |
|
this.index = index; |
370 |
|
} |
371 |
|
|
372 |
|
/** The entry point of the task. */ |
373 |
|
@Override |
374 |
|
public void |
375 |
|
exec() throws Exception { |
376 |
|
for(Effect e : effects) { |
377 |
|
int ei = CC.getClient().createEffectInstance(e); |
378 |
|
if(index != -1) { |
379 |
|
CC.getClient().insertEffectInstance(audioDeviceId, chainId, index, ei); |
380 |
|
} else { |
381 |
|
CC.getClient().appendEffectInstance(audioDeviceId, chainId, ei); |
382 |
|
} |
383 |
|
} |
384 |
|
} |
385 |
|
} |
386 |
|
|
387 |
|
/** |
388 |
|
* This task removes the specified effect instance from the specified send effect chain. |
389 |
|
*/ |
390 |
|
public static class RemoveEffectInstance extends EnhancedTask { |
391 |
|
private int audioDeviceId; |
392 |
|
private int chainId; |
393 |
|
private int instanceId; |
394 |
|
|
395 |
|
/** |
396 |
|
* Creates a new instance of <code>RemoveEffectInstance</code>. |
397 |
|
* @param audioDeviceId The numerical ID of the audio output device. |
398 |
|
* @param chainId The numerical ID of the send effect chain. |
399 |
|
* @param instanceId The numerical ID of the effect instance to remove. |
400 |
|
*/ |
401 |
|
public |
402 |
|
RemoveEffectInstance(int audioDeviceId, int chainId, int instanceId) { |
403 |
|
setTitle("Audio.RemoveEffectInstance_task"); |
404 |
|
setDescription(i18n.getMessage("Audio.RemoveEffectInstance.desc")); |
405 |
|
|
406 |
|
this.audioDeviceId = audioDeviceId; |
407 |
|
this.chainId = chainId; |
408 |
|
this.instanceId = instanceId; |
409 |
|
} |
410 |
|
|
411 |
|
/** The entry point of the task. */ |
412 |
|
@Override |
413 |
|
public void |
414 |
|
exec() throws Exception { |
415 |
|
AudioDeviceModel adm = CC.getSamplerModel().getAudioDevice(audioDeviceId); |
416 |
|
EffectChain chain = adm.getSendEffectChainById(chainId); |
417 |
|
|
418 |
|
CC.getClient().removeEffectInstanceFromChain ( |
419 |
|
audioDeviceId, chainId, chain.getIndex(instanceId) |
420 |
|
); |
421 |
|
|
422 |
|
CC.getClient().destroyEffectInstance(instanceId); |
423 |
|
|
424 |
|
} |
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
|
/** |
429 |
|
* This task updates the send effect chain list of an audio output device. |
430 |
|
*/ |
431 |
|
public static class UpdateSendEffectChains extends EnhancedTask { |
432 |
|
private int devId; |
433 |
|
|
434 |
|
/** |
435 |
|
* Creates new instance of <code>UpdateSendEffectChains</code>. |
436 |
|
* @param devId The id of the device. |
437 |
|
*/ |
438 |
|
public |
439 |
|
UpdateSendEffectChains(int devId) { |
440 |
|
setTitle("Audio.UpdateSendEffectChains_task"); |
441 |
|
setDescription(i18n.getMessage("Audio.UpdateSendEffectChains.desc", devId)); |
442 |
|
|
443 |
|
this.devId = devId; |
444 |
|
} |
445 |
|
|
446 |
|
/** The entry point of the task. */ |
447 |
|
@Override |
448 |
|
public void |
449 |
|
exec() throws Exception { |
450 |
|
AudioDeviceModel m = CC.getSamplerModel().getAudioDeviceById(devId); |
451 |
|
|
452 |
|
Integer[] idS = CC.getClient().getSendEffectChainIDs(devId); |
453 |
|
|
454 |
|
ArrayList<Integer> removedChains = new ArrayList<Integer>(); |
455 |
|
|
456 |
|
for(int i = 0; i < m.getSendEffectChainCount(); i++) { |
457 |
|
boolean found = false; |
458 |
|
for(int j = 0; j < idS.length; j++) { |
459 |
|
if(idS[j] != null && m.getSendEffectChain(i).getChainId() == idS[j]) { |
460 |
|
found = true; |
461 |
|
idS[j] = null; |
462 |
|
} |
463 |
|
} |
464 |
|
if(!found) removedChains.add(m.getSendEffectChain(i).getChainId()); |
465 |
|
} |
466 |
|
|
467 |
|
for(int i : removedChains) m.removeSendEffectChain(i); |
468 |
|
|
469 |
|
for(int i = 0; i < idS.length; i++) { |
470 |
|
if(idS[i] != null) { |
471 |
|
m.addSendEffectChain ( |
472 |
|
new EffectChain(CC.getClient().getSendEffectChainInfo(devId, idS[i])) |
473 |
|
); |
474 |
|
} |
475 |
|
} |
476 |
|
} |
477 |
|
} |
478 |
|
|
479 |
|
/** |
480 |
|
* This task updates the list of effect instances. |
481 |
|
*/ |
482 |
|
public static class UpdateEffectInstances extends EnhancedTask { |
483 |
|
private int audioDeviceId; |
484 |
|
private int chainId; |
485 |
|
|
486 |
|
/** |
487 |
|
* Creates a new instance of <code>UpdateEffectInstances</code>. |
488 |
|
* @param audioDeviceId The numerical ID of the audio output device. |
489 |
|
* @param chainId The numerical ID of the send effect chain. |
490 |
|
*/ |
491 |
|
public |
492 |
|
UpdateEffectInstances(int audioDeviceId, int chainId) { |
493 |
|
setTitle("Audio.UpdateEffectInstances_task"); |
494 |
|
setDescription(i18n.getMessage("Audio.UpdateEffectInstances.desc")); |
495 |
|
|
496 |
|
this.audioDeviceId = audioDeviceId; |
497 |
|
this.chainId = chainId; |
498 |
|
} |
499 |
|
|
500 |
|
/** The entry point of the task. */ |
501 |
|
@Override |
502 |
|
public void |
503 |
|
exec() throws Exception { |
504 |
|
setSilent(true); |
505 |
|
|
506 |
|
EffectChain c = new EffectChain ( |
507 |
|
CC.getClient().getSendEffectChainInfo(audioDeviceId, chainId) |
508 |
|
); |
509 |
|
AudioDeviceModel m = CC.getSamplerModel().getAudioDeviceById(audioDeviceId); |
510 |
|
m.getSendEffectChainById(chainId).setEffectInstances(c.getEffectInstances()); |
511 |
|
} |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
/** |
/** |
516 |
* This task updates the setting of an audio output device. |
* This task updates the setting of an audio output device. |