1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 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.logging.Level; |
26 |
|
27 |
import net.sf.juife.Task; |
28 |
|
29 |
import org.jsampler.CC; |
30 |
import org.jsampler.HF; |
31 |
import org.jsampler.SamplerChannelModel; |
32 |
import org.jsampler.SamplerModel; |
33 |
|
34 |
import org.linuxsampler.lscp.FxSend; |
35 |
|
36 |
import static org.jsampler.JSI18n.i18n; |
37 |
|
38 |
|
39 |
/** |
40 |
* Provides the sampler channel's specific tasks. |
41 |
* @author Grigor Iliev |
42 |
*/ |
43 |
public class Channel { |
44 |
|
45 |
/** Forbits the instantiation of this class. */ |
46 |
private Channel() { } |
47 |
|
48 |
|
49 |
/** |
50 |
* This task creates a new sampler channel.\ |
51 |
*/ |
52 |
public static class Add extends EnhancedTask<Integer> { |
53 |
/** Creates a new instance of <code>Add</code>. */ |
54 |
public |
55 |
Add() { |
56 |
setTitle("Channel.Add_task"); |
57 |
setDescription(i18n.getMessage("Channel.Add.desc")); |
58 |
} |
59 |
|
60 |
/** The entry point of the task. */ |
61 |
public void |
62 |
run() { |
63 |
try { setResult(CC.getClient().addSamplerChannel()); } |
64 |
catch(Exception x) { |
65 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
66 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
67 |
} |
68 |
} |
69 |
} |
70 |
|
71 |
/** |
72 |
* This task removes the specified sampler channel. |
73 |
*/ |
74 |
public static class Remove extends EnhancedTask { |
75 |
private int channel; |
76 |
|
77 |
/** |
78 |
* Creates new instance of <code>Remove</code>. |
79 |
* @param channel The numerical ID of the channel to remove. |
80 |
*/ |
81 |
public |
82 |
Remove(int channel) { |
83 |
setTitle("Channel.Remove_task"); |
84 |
setDescription(i18n.getMessage("Channel.Remove.desc", channel)); |
85 |
|
86 |
this.channel = channel; |
87 |
} |
88 |
|
89 |
/** The entry point of the task. */ |
90 |
public void |
91 |
run() { |
92 |
try { CC.getClient().removeSamplerChannel(channel); } |
93 |
catch(Exception x) { |
94 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
95 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
96 |
} |
97 |
} |
98 |
} |
99 |
|
100 |
/** |
101 |
* This task resets the specified sampler channel. |
102 |
*/ |
103 |
public static class Reset extends EnhancedTask { |
104 |
private int channel; |
105 |
|
106 |
/** |
107 |
* Creates new instance of <code>Reset</code>. |
108 |
* @param channel The numerical ID of the channel to reset. |
109 |
*/ |
110 |
public |
111 |
Reset(int channel) { |
112 |
setTitle("Channel.Reset_task"); |
113 |
setDescription(i18n.getMessage("Channel.Reset.desc", channel)); |
114 |
|
115 |
this.channel = channel; |
116 |
} |
117 |
|
118 |
/** The entry point of the task. */ |
119 |
public void |
120 |
run() { |
121 |
try { CC.getClient().resetChannel(channel); } |
122 |
catch(Exception x) { |
123 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
124 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
/** |
130 |
* This task sets an audio output channel of a specific sampler channel. |
131 |
*/ |
132 |
public static class SetAudioOutputChannel extends EnhancedTask { |
133 |
private int chn; |
134 |
private int audioOut; |
135 |
private int audioIn; |
136 |
|
137 |
/** |
138 |
* Creates new instance of <code>SetAudioOutputChannel</code>. |
139 |
* @param channel The sampler channel number. |
140 |
* @param audioOut The sampler channel's audio output |
141 |
* channel which should be rerouted. |
142 |
* @param audioIn The audio channel of the selected audio output device where |
143 |
* <code>audioOut</code> should be routed to. |
144 |
*/ |
145 |
public |
146 |
SetAudioOutputChannel(int channel, int audioOut, int audioIn) { |
147 |
setTitle("Channel.SetAudioOutputChannel_task"); |
148 |
String s = i18n.getMessage("Channel.SetAudioOutputChannel.desc", channel); |
149 |
setDescription(s); |
150 |
|
151 |
this.chn = channel; |
152 |
this.audioOut = audioOut; |
153 |
this.audioIn = audioIn; |
154 |
} |
155 |
|
156 |
/** The entry point of the task. */ |
157 |
public void |
158 |
run() { |
159 |
try { CC.getClient().setChannelAudioOutputChannel(chn, audioOut, audioIn); } |
160 |
catch(Exception x) { |
161 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
162 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
163 |
} |
164 |
} |
165 |
} |
166 |
|
167 |
/** |
168 |
* This task sets the audio output device of a specific sampler channel. |
169 |
*/ |
170 |
public static class SetAudioOutputDevice extends EnhancedTask { |
171 |
private int channel; |
172 |
private int deviceID; |
173 |
|
174 |
/** |
175 |
* Creates new instance of <code>SetAudioOutputDevice</code>. |
176 |
* @param channel The sampler channel number. |
177 |
* @param deviceID The numerical ID of the audio output device. |
178 |
*/ |
179 |
public |
180 |
SetAudioOutputDevice(int channel, int deviceID) { |
181 |
setTitle("Channel.SetAudioOutputDevice_task"); |
182 |
String s = i18n.getMessage("Channel.SetAudioOutputDevice.desc", channel); |
183 |
setDescription(s); |
184 |
|
185 |
this.channel = channel; |
186 |
this.deviceID = deviceID; |
187 |
} |
188 |
|
189 |
/** The entry point of the task. */ |
190 |
public void |
191 |
run() { |
192 |
try { CC.getClient().setChannelAudioOutputDevice(channel, deviceID); } |
193 |
catch(Exception x) { |
194 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
195 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
196 |
} |
197 |
} |
198 |
} |
199 |
|
200 |
/** |
201 |
* This task sets the MIDI input channel the specified sampler channel should listen to. |
202 |
*/ |
203 |
public static class SetMidiInputChannel extends EnhancedTask { |
204 |
private int channel; |
205 |
private int midiChannel; |
206 |
|
207 |
/** |
208 |
* Creates new instance of <code>SetMidiInputChannel</code>. |
209 |
* @param channel The sampler channel number. |
210 |
* @param midiChannel The number of the new MIDI input channel where |
211 |
* <code>channel</code> should listen to or -1 to listen on all 16 MIDI channels. |
212 |
*/ |
213 |
public |
214 |
SetMidiInputChannel(int channel, int midiChannel) { |
215 |
setTitle("Channel.SetMidiInputChannel_task"); |
216 |
String s = i18n.getMessage("Channel.SetMidiInputChannel.desc", channel); |
217 |
setDescription(s); |
218 |
|
219 |
this.channel = channel; |
220 |
this.midiChannel = midiChannel; |
221 |
} |
222 |
|
223 |
/** The entry point of the task. */ |
224 |
public void |
225 |
run() { |
226 |
try { CC.getClient().setChannelMidiInputChannel(channel, midiChannel); } |
227 |
catch(Exception x) { |
228 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
229 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
230 |
} |
231 |
} |
232 |
} |
233 |
|
234 |
/** |
235 |
* This task sets the MIDI input device on a specific sampler channel. |
236 |
*/ |
237 |
public static class SetMidiInputDevice extends EnhancedTask { |
238 |
private int channel; |
239 |
private int deviceID; |
240 |
|
241 |
/** |
242 |
* Creates new instance of <code>SetMidiInputDevice</code>. |
243 |
* @param channel The sampler channel number. |
244 |
* @param deviceID The numerical ID of the MIDI input device. |
245 |
*/ |
246 |
public |
247 |
SetMidiInputDevice(int channel, int deviceID) { |
248 |
setTitle("Channel.SetMidiInputDevice_task"); |
249 |
String s = i18n.getMessage("Channel.SetMidiInputDevice.desc", channel); |
250 |
setDescription(s); |
251 |
|
252 |
this.channel = channel; |
253 |
this.deviceID = deviceID; |
254 |
} |
255 |
|
256 |
/** The entry point of the task. */ |
257 |
public void |
258 |
run() { |
259 |
try { CC.getClient().setChannelMidiInputDevice(channel, deviceID); } |
260 |
catch(Exception x) { |
261 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
262 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
263 |
} |
264 |
} |
265 |
} |
266 |
|
267 |
/** |
268 |
* This task sets the MIDI input port of a specific sampler channel. |
269 |
*/ |
270 |
public static class SetMidiInputPort extends EnhancedTask { |
271 |
private int channel; |
272 |
private int port; |
273 |
|
274 |
/** |
275 |
* Creates new instance of <code>SetMidiInputPort</code>. |
276 |
* @param channel The sampler channel number. |
277 |
* @param port The MIDI input port number |
278 |
* of the MIDI input device connected to the specified sampler channel. |
279 |
*/ |
280 |
public |
281 |
SetMidiInputPort(int channel, int port) { |
282 |
setTitle("Channel.SetMidiInputPort_task"); |
283 |
setDescription(i18n.getMessage("Channel.SetMidiInputPort.desc", channel)); |
284 |
|
285 |
this.channel = channel; |
286 |
this.port = port; |
287 |
} |
288 |
|
289 |
/** The entry point of the task. */ |
290 |
public void |
291 |
run() { |
292 |
try { CC.getClient().setChannelMidiInputPort(channel, port); } |
293 |
catch(Exception x) { |
294 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
295 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
296 |
} |
297 |
} |
298 |
} |
299 |
|
300 |
/** |
301 |
* This task assigns the specifed MIDI instrument map to the specified sampler channel. |
302 |
*/ |
303 |
public static class SetMidiInstrumentMap extends EnhancedTask { |
304 |
private int channel; |
305 |
private int mapId; |
306 |
|
307 |
/** |
308 |
* Creates new instance of <code>SetMidiInstrumentMap</code>. |
309 |
* @param channel The sampler channel number. |
310 |
* @param mapId The numerical ID of the MIDI instrument |
311 |
* map that should be assigned to the specified sampler |
312 |
* channel or <code>-1</code> to remove the current map binding. |
313 |
*/ |
314 |
public |
315 |
SetMidiInstrumentMap(int channel, int mapId) { |
316 |
setTitle("Channel.SetMidiInstrumentMap_task"); |
317 |
String s = i18n.getMessage("Channel.SetMidiInstrumentMap.desc", channel); |
318 |
setDescription(s); |
319 |
|
320 |
this.channel = channel; |
321 |
this.mapId = mapId; |
322 |
} |
323 |
|
324 |
/** The entry point of the task. */ |
325 |
public void |
326 |
run() { |
327 |
try { CC.getClient().setChannelMidiInstrumentMap(channel, mapId); } |
328 |
catch(Exception x) { |
329 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
330 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
331 |
} |
332 |
} |
333 |
} |
334 |
|
335 |
/** |
336 |
* This task mutes/unmutes a specific sampler channel. |
337 |
*/ |
338 |
public static class SetMute extends EnhancedTask { |
339 |
private int channel; |
340 |
private boolean mute; |
341 |
|
342 |
/** |
343 |
* Creates new instance of <code>SetMute</code>. |
344 |
* @param channel The sampler channel to be muted/unmuted. |
345 |
* @param mute If <code>true</code> the specified channel is muted, |
346 |
* else the channel is unmuted. |
347 |
*/ |
348 |
public |
349 |
SetMute(int channel, boolean mute) { |
350 |
setTitle("Channel.SetMute_task"); |
351 |
setDescription(i18n.getMessage("Channel.SetMute.desc", channel)); |
352 |
|
353 |
this.channel = channel; |
354 |
this.mute = mute; |
355 |
} |
356 |
|
357 |
/** The entry point of the task. */ |
358 |
public void |
359 |
run() { |
360 |
try { CC.getClient().setChannelMute(channel, mute); } |
361 |
catch(Exception x) { |
362 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
363 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
364 |
} |
365 |
} |
366 |
} |
367 |
|
368 |
/** |
369 |
* This task solos/unsolos a specific sampler channel. |
370 |
*/ |
371 |
public static class SetSolo extends EnhancedTask { |
372 |
private int channel; |
373 |
private boolean solo; |
374 |
|
375 |
/** |
376 |
* Creates new instance of <code>SetSolo</code>. |
377 |
* @param channel The sampler channel number. |
378 |
* @param solo Specify <code>true</code> to solo the specified channel, |
379 |
* <code>false</code> otherwise. |
380 |
*/ |
381 |
public |
382 |
SetSolo(int channel, boolean solo) { |
383 |
setTitle("Channel.SetSolo_task"); |
384 |
setDescription(i18n.getMessage("Channel.SetSolo.desc", channel)); |
385 |
|
386 |
this.channel = channel; |
387 |
this.solo = solo; |
388 |
} |
389 |
|
390 |
/** The entry point of the task. */ |
391 |
public void |
392 |
run() { |
393 |
try { CC.getClient().setChannelSolo(channel, solo); } |
394 |
catch(Exception x) { |
395 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
396 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
397 |
} |
398 |
} |
399 |
} |
400 |
|
401 |
/** |
402 |
* This taks sets the volume of a specific sampler channel. |
403 |
*/ |
404 |
public static class SetVolume extends EnhancedTask { |
405 |
private int channel; |
406 |
private float volume; |
407 |
|
408 |
/** |
409 |
* Creates new instance of <code>SetVolume</code>. |
410 |
* @param channel The sampler channel number. |
411 |
* @param volume The new volume value. |
412 |
*/ |
413 |
public |
414 |
SetVolume(int channel, float volume) { |
415 |
setTitle("Channel.SetVolume_task"); |
416 |
setDescription(i18n.getMessage("Channel.SetVolume.desc", channel)); |
417 |
|
418 |
this.channel = channel; |
419 |
this.volume = volume; |
420 |
} |
421 |
|
422 |
/** The entry point of the task. */ |
423 |
public void |
424 |
run() { |
425 |
/* |
426 |
* Because of the rapid flow of volume change tasks in some cases |
427 |
* we need to do some optimization to decrease the traffic. |
428 |
*/ |
429 |
boolean b = true; |
430 |
Task[] tS = CC.getTaskQueue().getPendingTasks(); |
431 |
|
432 |
for(int i = tS.length - 1; i >= 0; i--) { |
433 |
Task t = tS[i]; |
434 |
|
435 |
if(t instanceof SetVolume) { |
436 |
SetVolume scv = (SetVolume)t; |
437 |
if(scv.getChannelId() == channel) { |
438 |
CC.getTaskQueue().removeTask(scv); |
439 |
} |
440 |
} |
441 |
} |
442 |
|
443 |
try { CC.getClient().setChannelVolume(channel, volume); } |
444 |
catch(Exception x) { |
445 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
446 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
447 |
} |
448 |
} |
449 |
|
450 |
/** |
451 |
* Gets the ID of the channel whose volume should be changed. |
452 |
* @return The ID of the channel whose volume should be changed. |
453 |
*/ |
454 |
public int |
455 |
getChannelId() { return channel; } |
456 |
} |
457 |
|
458 |
/** |
459 |
* This task updates the settings of a specific sampler channel. |
460 |
*/ |
461 |
public static class UpdateInfo extends EnhancedTask { |
462 |
private int channel; |
463 |
|
464 |
/** |
465 |
* Creates new instance of <code>UpdateInfo</code>. |
466 |
* @param channel The sampler channel to be updated. |
467 |
*/ |
468 |
public |
469 |
UpdateInfo(int channel) { |
470 |
setTitle("Channel.UpdateInfo_task"); |
471 |
setDescription(i18n.getMessage("Channel.UpdateInfo.desc")); |
472 |
|
473 |
this.channel = channel; |
474 |
} |
475 |
|
476 |
/** The entry point of the task. */ |
477 |
public void |
478 |
run() { |
479 |
try { |
480 |
SamplerModel sm = CC.getSamplerModel(); |
481 |
sm.updateChannel(CC.getClient().getSamplerChannelInfo(channel)); |
482 |
} catch(Exception x) { |
483 |
/* |
484 |
* We don't want to bother the user if error occurs when updating |
485 |
* a channel because in most cases this happens due to a race |
486 |
* condition between delete/update events. So we just log this |
487 |
* error instead to indicate the failure of this task. |
488 |
*/ |
489 |
String msg = getDescription() + ": " + HF.getErrorMessage(x); |
490 |
CC.getLogger().log(Level.INFO, msg, x); |
491 |
} |
492 |
} |
493 |
|
494 |
/** |
495 |
* Gets the ID of the channel for which information should be obtained. |
496 |
* @return The ID of the channel for which information should be obtained. |
497 |
*/ |
498 |
public int |
499 |
getChannelId() { return channel; } |
500 |
} |
501 |
|
502 |
/** |
503 |
* This task creates an additional effect send on the specified sampler channel. |
504 |
*/ |
505 |
public static class AddFxSend extends EnhancedTask<Integer> { |
506 |
private int channel; |
507 |
private int midiCtrl; |
508 |
private String name; |
509 |
|
510 |
/** |
511 |
* Creates a new instance of <code>AddFxSend</code>. |
512 |
* @param channel The sampler channel, on which a new effect send should be added. |
513 |
* @param midiCtrl Defines the MIDI controller, which |
514 |
* will be able alter the effect send level. |
515 |
*/ |
516 |
public |
517 |
AddFxSend(int channel, int midiCtrl) { |
518 |
this(channel, midiCtrl, null); |
519 |
} |
520 |
|
521 |
/** |
522 |
* Creates a new instance of <code>AddFxSend</code>. |
523 |
* @param channel The sampler channel, on which a new effect send should be added. |
524 |
* @param midiCtrl Defines the MIDI controller, which |
525 |
* will be able alter the effect send level. |
526 |
* @param name The name of the effect send entity. |
527 |
* The name does not have to be unique. |
528 |
*/ |
529 |
public |
530 |
AddFxSend(int channel, int midiCtrl, String name) { |
531 |
setTitle("Channel.AddFxSend_task"); |
532 |
setDescription(i18n.getMessage("Channel.AddFxSend.desc")); |
533 |
this.channel = channel; |
534 |
this.midiCtrl = midiCtrl; |
535 |
this.name = name; |
536 |
} |
537 |
|
538 |
/** The entry point of the task. */ |
539 |
public void |
540 |
run() { |
541 |
try { setResult(CC.getClient().createFxSend(channel, midiCtrl, name)); } |
542 |
catch(Exception x) { |
543 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
544 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
545 |
x.printStackTrace(); |
546 |
} |
547 |
} |
548 |
} |
549 |
|
550 |
/** |
551 |
* This task removes the specified effect send on the specified sampler channel. |
552 |
*/ |
553 |
public static class RemoveFxSend extends EnhancedTask { |
554 |
private int channel; |
555 |
private int fxSend; |
556 |
|
557 |
/** |
558 |
* Creates a new instance of <code>RemoveFxSend</code>. |
559 |
* @param channel The sampler channel, from which an effect send should be removed. |
560 |
* @param fxSend The ID of the effect send that should be removed. |
561 |
*/ |
562 |
public |
563 |
RemoveFxSend(int channel, int fxSend) { |
564 |
setTitle("Channel.RemoveFxSend_task"); |
565 |
String s = i18n.getMessage("Channel.RemoveFxSend.desc", channel, fxSend); |
566 |
setDescription(s); |
567 |
this.channel = channel; |
568 |
this.fxSend = fxSend; |
569 |
} |
570 |
|
571 |
/** The entry point of the task. */ |
572 |
public void |
573 |
run() { |
574 |
try { CC.getClient().destroyFxSend(channel, fxSend); } |
575 |
catch(Exception x) { |
576 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
577 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
578 |
} |
579 |
} |
580 |
} |
581 |
|
582 |
/** |
583 |
* This task gets the list of effect sends on the specified sampler channel. |
584 |
*/ |
585 |
public static class GetFxSends extends EnhancedTask<FxSend[]> { |
586 |
private int channel; |
587 |
|
588 |
/** |
589 |
* Creates a new instance of <code>GetFxSends</code>. |
590 |
*/ |
591 |
public |
592 |
GetFxSends() { this(-1); } |
593 |
|
594 |
/** |
595 |
* Creates a new instance of <code>GetFxSends</code>. |
596 |
*/ |
597 |
public |
598 |
GetFxSends(int channel) { |
599 |
setTitle("Channel.GetFxSends_task"); |
600 |
setDescription(i18n.getMessage("Channel.GetFxSends.desc", channel)); |
601 |
|
602 |
this.channel = channel; |
603 |
} |
604 |
|
605 |
/** The entry point of the task. */ |
606 |
public void |
607 |
run() { |
608 |
try { |
609 |
setResult(CC.getClient().getFxSends(channel)); |
610 |
} catch(Exception x) { |
611 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
612 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
613 |
} |
614 |
} |
615 |
|
616 |
/** |
617 |
* Gets the channel ID. |
618 |
*/ |
619 |
public int |
620 |
getChannel() { return channel; } |
621 |
|
622 |
/** |
623 |
* Sets the channel, for which effect sends should be obtained. |
624 |
*/ |
625 |
public void |
626 |
setChannel(int channel) { |
627 |
this.channel = channel; |
628 |
setDescription(i18n.getMessage("Channel.GetFxSends.desc", channel)); |
629 |
} |
630 |
} |
631 |
|
632 |
/** |
633 |
* This task updates the list of effect sends on the specified sampler channel. |
634 |
*/ |
635 |
public static class UpdateFxSends extends EnhancedTask { |
636 |
private int channel; |
637 |
|
638 |
/** |
639 |
* Creates a new instance of <code>UpdateFxSends</code>. |
640 |
* @param channel The numerical ID of the sampler channel |
641 |
* whose effect send list should be updated. |
642 |
*/ |
643 |
public |
644 |
UpdateFxSends(int channel) { |
645 |
setTitle("Channel.UpdateFxSends_task"); |
646 |
setDescription(i18n.getMessage("Channel.UpdateFxSends.desc", channel)); |
647 |
|
648 |
this.channel = channel; |
649 |
} |
650 |
|
651 |
/** The entry point of the task. */ |
652 |
public void |
653 |
run() { |
654 |
try { |
655 |
SamplerChannelModel scm; |
656 |
scm = CC.getSamplerModel().getChannelModel(channel); |
657 |
Integer[] fxSendIDs = CC.getClient().getFxSendIDs(channel); |
658 |
|
659 |
boolean found = false; |
660 |
|
661 |
for(FxSend fxs : scm.getFxSends()) { |
662 |
for(int i = 0; i < fxSendIDs.length; i++) { |
663 |
if(fxSendIDs[i] == fxs.getFxSendId()) { |
664 |
fxSendIDs[i] = -1; |
665 |
found = true; |
666 |
} |
667 |
} |
668 |
|
669 |
if(!found) scm.removeFxSendById(fxs.getFxSendId()); |
670 |
found = false; |
671 |
} |
672 |
|
673 |
FxSend fxs; |
674 |
|
675 |
for(int id : fxSendIDs) { |
676 |
if(id >= 0) { |
677 |
fxs = CC.getClient().getFxSendInfo(channel, id); |
678 |
scm.addFxSend(fxs); |
679 |
} |
680 |
} |
681 |
} catch(Exception x) { |
682 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
683 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
684 |
} |
685 |
} |
686 |
} |
687 |
|
688 |
/** |
689 |
* This task updates the settings of a specific effect send. |
690 |
*/ |
691 |
public static class UpdateFxSendInfo extends EnhancedTask { |
692 |
private int channel; |
693 |
private int fxSend; |
694 |
|
695 |
/** |
696 |
* Creates new instance of <code>UpdateFxSendInfo</code>. |
697 |
* @param channel The numerical ID of the sampler channel |
698 |
* containing the effect send entity that should be updated. |
699 |
* @param fxSend The numerical ID of the effect send |
700 |
* that should be updated. |
701 |
*/ |
702 |
public |
703 |
UpdateFxSendInfo(int channel, int fxSend) { |
704 |
setTitle("Channel.UpdateFxSendInfo_task"); |
705 |
String s = "Channel.UpdateFxSendInfo.desc"; |
706 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
707 |
|
708 |
this.channel = channel; |
709 |
this.fxSend = fxSend; |
710 |
} |
711 |
|
712 |
/** The entry point of the task. */ |
713 |
public void |
714 |
run() { |
715 |
try { |
716 |
SamplerChannelModel scm; |
717 |
scm = CC.getSamplerModel().getChannelModel(channel); |
718 |
scm.updateFxSend(CC.getClient().getFxSendInfo(channel, fxSend)); |
719 |
} catch(Exception x) { |
720 |
/* |
721 |
* We don't want to bother the user if error occurs when updating |
722 |
* an effect send because in most cases this happens due to a race |
723 |
* condition between delete/update events. So we just log this |
724 |
* error instead to indicate the failure of this task. |
725 |
*/ |
726 |
String msg = getDescription() + ": " + HF.getErrorMessage(x); |
727 |
CC.getLogger().log(Level.INFO, msg, x); |
728 |
} |
729 |
} |
730 |
} |
731 |
|
732 |
/** |
733 |
* This taks changes the name of a specific effect send. |
734 |
*/ |
735 |
public static class SetFxSendName extends EnhancedTask { |
736 |
private int channel; |
737 |
private int fxSend; |
738 |
private String name; |
739 |
|
740 |
/** |
741 |
* Creates new instance of <code>SetFxSendName</code>. |
742 |
* @param channel The sampler channel number. |
743 |
* @param fxSend The numerical ID of the effect |
744 |
* send, which name should be changed. |
745 |
* @param name The new name of the effect send entity. |
746 |
*/ |
747 |
public |
748 |
SetFxSendName(int channel, int fxSend, String name) { |
749 |
setTitle("Channel.SetFxSendName_task"); |
750 |
String s = "Channel.SetFxSendName.desc"; |
751 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
752 |
|
753 |
this.channel = channel; |
754 |
this.fxSend = fxSend; |
755 |
this.name = name; |
756 |
} |
757 |
|
758 |
/** The entry point of the task. */ |
759 |
public void |
760 |
run() { |
761 |
try { CC.getClient().setFxSendName(channel, fxSend, name); } |
762 |
catch(Exception x) { |
763 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
764 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
765 |
} |
766 |
} |
767 |
} |
768 |
|
769 |
/** |
770 |
* This taks sets the MIDI controller of a specific effect send. |
771 |
*/ |
772 |
public static class SetFxSendAudioOutputChannel extends EnhancedTask { |
773 |
private int channel; |
774 |
private int fxSend; |
775 |
private int audioSrc; |
776 |
private int audioDst; |
777 |
|
778 |
/** |
779 |
* Creates new instance of <code>SetFxSendAudioOutputChannel</code>. |
780 |
* @param channel The sampler channel number. |
781 |
* @param fxSend The numerical ID of the effect send entity to be rerouted. |
782 |
* @param audioSrc The numerical ID of the effect send's audio output channel, |
783 |
* which should be rerouted. |
784 |
* @param audioDst The audio channel of the selected audio output device |
785 |
* where <code>audioSrc</code> should be routed to. |
786 |
*/ |
787 |
public |
788 |
SetFxSendAudioOutputChannel(int channel, int fxSend, int audioSrc, int audioDst) { |
789 |
setTitle("Channel.SetFxSendAudioOutputChannel_task"); |
790 |
String s = "Channel.SetFxSendAudioOutputChannel.desc"; |
791 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
792 |
|
793 |
this.channel = channel; |
794 |
this.fxSend = fxSend; |
795 |
this.audioSrc = audioSrc; |
796 |
this.audioDst = audioDst; |
797 |
} |
798 |
|
799 |
/** The entry point of the task. */ |
800 |
public void |
801 |
run() { |
802 |
try { |
803 |
CC.getClient().setFxSendAudioOutputChannel ( |
804 |
channel, fxSend, audioSrc, audioDst |
805 |
); |
806 |
} |
807 |
catch(Exception x) { |
808 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
809 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
810 |
} |
811 |
} |
812 |
} |
813 |
|
814 |
/** |
815 |
* This taks sets the volume of a specific effect send. |
816 |
*/ |
817 |
public static class SetFxSendLevel extends EnhancedTask { |
818 |
private int channel; |
819 |
private int fxSend; |
820 |
private float volume; |
821 |
|
822 |
/** |
823 |
* Creates new instance of <code>SetFxSendLevel</code>. |
824 |
* @param channel The sampler channel number. |
825 |
* @param fxSend The numerical ID of the effect send, which |
826 |
* volume should be changed. |
827 |
* @param volume The new volume value. |
828 |
*/ |
829 |
public |
830 |
SetFxSendLevel(int channel, int fxSend, float volume) { |
831 |
setTitle("Channel.SetFxSendLevel_task"); |
832 |
String s = i18n.getMessage("Channel.SetFxSendLevel.desc", channel, fxSend); |
833 |
setDescription(s); |
834 |
|
835 |
this.channel = channel; |
836 |
this.fxSend = fxSend; |
837 |
this.volume = volume; |
838 |
} |
839 |
|
840 |
/** The entry point of the task. */ |
841 |
public void |
842 |
run() { |
843 |
try { CC.getClient().setFxSendLevel(channel, fxSend, volume); } |
844 |
catch(Exception x) { |
845 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
846 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
847 |
} |
848 |
} |
849 |
} |
850 |
|
851 |
/** |
852 |
* This taks sets the MIDI controller of a specific effect send. |
853 |
*/ |
854 |
public static class SetFxSendMidiController extends EnhancedTask { |
855 |
private int channel; |
856 |
private int fxSend; |
857 |
private int midiCtrl; |
858 |
|
859 |
/** |
860 |
* Creates new instance of <code>SetFxSendMidiController</code>. |
861 |
* @param channel The sampler channel number. |
862 |
* @param fxSend The numerical ID of the effect |
863 |
* send, which MIDI controller should be changed. |
864 |
* @param midiCtrl The MIDI controller which shall be |
865 |
* able to modify the effect send's send level. |
866 |
*/ |
867 |
public |
868 |
SetFxSendMidiController(int channel, int fxSend, int midiCtrl) { |
869 |
setTitle("Channel.SetFxSendMidiController_task"); |
870 |
String s = "Channel.SetFxSendMidiController.desc"; |
871 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
872 |
|
873 |
this.channel = channel; |
874 |
this.fxSend = fxSend; |
875 |
this.midiCtrl = midiCtrl; |
876 |
} |
877 |
|
878 |
/** The entry point of the task. */ |
879 |
public void |
880 |
run() { |
881 |
try { CC.getClient().setFxSendMidiController(channel, fxSend, midiCtrl); } |
882 |
catch(Exception x) { |
883 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
884 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
885 |
} |
886 |
} |
887 |
} |
888 |
|
889 |
} |