/[svn]/jsampler/trunk/src/org/jsampler/task/Channel.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/task/Channel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1334 - (show annotations) (download)
Sun Sep 9 17:43:30 2007 UTC (16 years, 7 months ago) by iliev
File size: 30517 byte(s)
* Added options for choosing default channel volume and
  MIDI instrument map

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

  ViewVC Help
Powered by ViewVC