/[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 2302 - (show annotations) (download)
Thu Dec 15 23:13:30 2011 UTC (12 years, 4 months ago) by iliev
File size: 29895 byte(s)
* Initial support for Android platforms (only sampler channel
  manipulation for now - see the screenshots on the website)

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

  ViewVC Help
Powered by ViewVC