/[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 1776 - (show annotations) (download)
Thu Sep 11 18:48:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 32310 byte(s)
* Implemented virtual MIDI keyboard

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

  ViewVC Help
Powered by ViewVC