1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2009 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 |
443 |
* channel or <code>-1</code> to remove the current map binding. |
444 |
*/ |
445 |
public |
446 |
SetMidiInstrumentMap(int channel, int mapId) { |
447 |
setTitle("Channel.SetMidiInstrumentMap_task"); |
448 |
String s = i18n.getMessage("Channel.SetMidiInstrumentMap.desc", channel); |
449 |
setDescription(s); |
450 |
|
451 |
this.channel = channel; |
452 |
this.mapId = mapId; |
453 |
} |
454 |
|
455 |
/** The entry point of the task. */ |
456 |
@Override |
457 |
public void |
458 |
exec() throws Exception { |
459 |
CC.getClient().setChannelMidiInstrumentMap(channel, mapId); |
460 |
} |
461 |
} |
462 |
|
463 |
/** |
464 |
* This task mutes/unmutes a specific sampler channel. |
465 |
*/ |
466 |
public static class SetMute extends EnhancedTask { |
467 |
private int channel; |
468 |
private boolean mute; |
469 |
|
470 |
/** |
471 |
* Creates new instance of <code>SetMute</code>. |
472 |
* @param channel The sampler channel to be muted/unmuted. |
473 |
* @param mute If <code>true</code> the specified channel is muted, |
474 |
* else the channel is unmuted. |
475 |
*/ |
476 |
public |
477 |
SetMute(int channel, boolean mute) { |
478 |
setTitle("Channel.SetMute_task"); |
479 |
setDescription(i18n.getMessage("Channel.SetMute.desc", channel)); |
480 |
|
481 |
this.channel = channel; |
482 |
this.mute = mute; |
483 |
} |
484 |
|
485 |
/** The entry point of the task. */ |
486 |
@Override |
487 |
public void |
488 |
exec() throws Exception { CC.getClient().setChannelMute(channel, mute); } |
489 |
} |
490 |
|
491 |
/** |
492 |
* This task solos/unsolos a specific sampler channel. |
493 |
*/ |
494 |
public static class SetSolo extends EnhancedTask { |
495 |
private int channel; |
496 |
private boolean solo; |
497 |
|
498 |
/** |
499 |
* Creates new instance of <code>SetSolo</code>. |
500 |
* @param channel The sampler channel number. |
501 |
* @param solo Specify <code>true</code> to solo the specified channel, |
502 |
* <code>false</code> otherwise. |
503 |
*/ |
504 |
public |
505 |
SetSolo(int channel, boolean solo) { |
506 |
setTitle("Channel.SetSolo_task"); |
507 |
setDescription(i18n.getMessage("Channel.SetSolo.desc", channel)); |
508 |
|
509 |
this.channel = channel; |
510 |
this.solo = solo; |
511 |
} |
512 |
|
513 |
/** The entry point of the task. */ |
514 |
@Override |
515 |
public void |
516 |
exec() throws Exception { CC.getClient().setChannelSolo(channel, solo); } |
517 |
} |
518 |
|
519 |
/** |
520 |
* This taks sets the volume of a specific sampler channel. |
521 |
*/ |
522 |
public static class SetVolume extends EnhancedTask { |
523 |
private int channel; |
524 |
private float volume; |
525 |
|
526 |
/** |
527 |
* Creates new instance of <code>SetVolume</code>. |
528 |
* @param channel The sampler channel number. |
529 |
* @param volume The new volume value. |
530 |
*/ |
531 |
public |
532 |
SetVolume(int channel, float volume) { |
533 |
setTitle("Channel.SetVolume_task"); |
534 |
setDescription(i18n.getMessage("Channel.SetVolume.desc", channel)); |
535 |
|
536 |
this.channel = channel; |
537 |
this.volume = volume; |
538 |
} |
539 |
|
540 |
/** The entry point of the task. */ |
541 |
@Override |
542 |
public void |
543 |
exec() throws Exception { |
544 |
/* |
545 |
* Because of the rapid flow of volume change tasks in some cases |
546 |
* we need to do some optimization to decrease the traffic. |
547 |
*/ |
548 |
boolean b = true; |
549 |
Task[] tS = CC.getTaskQueue().getPendingTasks(); |
550 |
|
551 |
for(int i = tS.length - 1; i >= 0; i--) { |
552 |
Task t = tS[i]; |
553 |
|
554 |
if(t instanceof SetVolume) { |
555 |
SetVolume scv = (SetVolume)t; |
556 |
if(scv.getChannelId() == channel) { |
557 |
CC.getTaskQueue().removeTask(scv); |
558 |
} |
559 |
} |
560 |
} |
561 |
|
562 |
CC.getClient().setChannelVolume(channel, volume); |
563 |
} |
564 |
|
565 |
/** |
566 |
* Gets the ID of the channel whose volume should be changed. |
567 |
* @return The ID of the channel whose volume should be changed. |
568 |
*/ |
569 |
public int |
570 |
getChannelId() { return channel; } |
571 |
} |
572 |
|
573 |
/** |
574 |
* This task updates the settings of a specific sampler channel. |
575 |
*/ |
576 |
public static class UpdateInfo extends EnhancedTask { |
577 |
private int channel; |
578 |
|
579 |
/** |
580 |
* Creates new instance of <code>UpdateInfo</code>. |
581 |
* @param channel The sampler channel to be updated. |
582 |
*/ |
583 |
public |
584 |
UpdateInfo(int channel) { |
585 |
setTitle("Channel.UpdateInfo_task"); |
586 |
setDescription(i18n.getMessage("Channel.UpdateInfo.desc")); |
587 |
|
588 |
this.channel = channel; |
589 |
} |
590 |
|
591 |
/** The entry point of the task. */ |
592 |
@Override |
593 |
public void |
594 |
exec() throws Exception { |
595 |
/* |
596 |
* We don't want to bother the user if error occurs when updating |
597 |
* a channel because in most cases this happens due to a race |
598 |
* condition between delete/update events. So we just log this |
599 |
* error instead to indicate the failure of this task. |
600 |
*/ |
601 |
setSilent(true); |
602 |
SamplerModel sm = CC.getSamplerModel(); |
603 |
sm.updateChannel(CC.getClient().getSamplerChannelInfo(channel)); |
604 |
} |
605 |
|
606 |
/** |
607 |
* Gets the ID of the channel for which information should be obtained. |
608 |
* @return The ID of the channel for which information should be obtained. |
609 |
*/ |
610 |
public int |
611 |
getChannelId() { return channel; } |
612 |
} |
613 |
|
614 |
/** |
615 |
* This task creates an additional effect send on the specified sampler channel. |
616 |
*/ |
617 |
public static class AddFxSend extends EnhancedTask<Integer> { |
618 |
private int channel; |
619 |
private int midiCtrl; |
620 |
private String name; |
621 |
|
622 |
/** |
623 |
* Creates a new instance of <code>AddFxSend</code>. |
624 |
* @param channel The sampler channel, on which a new effect send should be added. |
625 |
* @param midiCtrl Defines the MIDI controller, which |
626 |
* will be able alter the effect send level. |
627 |
*/ |
628 |
public |
629 |
AddFxSend(int channel, int midiCtrl) { |
630 |
this(channel, midiCtrl, null); |
631 |
} |
632 |
|
633 |
/** |
634 |
* Creates a new instance of <code>AddFxSend</code>. |
635 |
* @param channel The sampler channel, on which a new effect send should be added. |
636 |
* @param midiCtrl Defines the MIDI controller, which |
637 |
* will be able alter the effect send level. |
638 |
* @param name The name of the effect send entity. |
639 |
* The name does not have to be unique. |
640 |
*/ |
641 |
public |
642 |
AddFxSend(int channel, int midiCtrl, String name) { |
643 |
setTitle("Channel.AddFxSend_task"); |
644 |
setDescription(i18n.getMessage("Channel.AddFxSend.desc")); |
645 |
this.channel = channel; |
646 |
this.midiCtrl = midiCtrl; |
647 |
this.name = name; |
648 |
} |
649 |
|
650 |
/** The entry point of the task. */ |
651 |
@Override |
652 |
public void |
653 |
exec() throws Exception { |
654 |
setResult(CC.getClient().createFxSend(channel, midiCtrl, name)); |
655 |
} |
656 |
} |
657 |
|
658 |
/** |
659 |
* This task removes the specified effect send on the specified sampler channel. |
660 |
*/ |
661 |
public static class RemoveFxSend extends EnhancedTask { |
662 |
private int channel; |
663 |
private int fxSend; |
664 |
|
665 |
/** |
666 |
* Creates a new instance of <code>RemoveFxSend</code>. |
667 |
* @param channel The sampler channel, from which an effect send should be removed. |
668 |
* @param fxSend The ID of the effect send that should be removed. |
669 |
*/ |
670 |
public |
671 |
RemoveFxSend(int channel, int fxSend) { |
672 |
setTitle("Channel.RemoveFxSend_task"); |
673 |
String s = i18n.getMessage("Channel.RemoveFxSend.desc", channel, fxSend); |
674 |
setDescription(s); |
675 |
this.channel = channel; |
676 |
this.fxSend = fxSend; |
677 |
} |
678 |
|
679 |
/** The entry point of the task. */ |
680 |
@Override |
681 |
public void |
682 |
exec() throws Exception { CC.getClient().destroyFxSend(channel, fxSend); } |
683 |
} |
684 |
|
685 |
/** |
686 |
* This task gets the list of effect sends on the specified sampler channel. |
687 |
*/ |
688 |
public static class GetFxSends extends EnhancedTask<FxSend[]> { |
689 |
private int channel; |
690 |
|
691 |
/** |
692 |
* Creates a new instance of <code>GetFxSends</code>. |
693 |
*/ |
694 |
public |
695 |
GetFxSends() { this(-1); } |
696 |
|
697 |
/** |
698 |
* Creates a new instance of <code>GetFxSends</code>. |
699 |
*/ |
700 |
public |
701 |
GetFxSends(int channel) { |
702 |
setTitle("Channel.GetFxSends_task"); |
703 |
setDescription(i18n.getMessage("Channel.GetFxSends.desc", channel)); |
704 |
|
705 |
this.channel = channel; |
706 |
} |
707 |
|
708 |
/** The entry point of the task. */ |
709 |
@Override |
710 |
public void |
711 |
exec() throws Exception { setResult(CC.getClient().getFxSends(channel)); } |
712 |
|
713 |
/** |
714 |
* Gets the channel ID. |
715 |
*/ |
716 |
public int |
717 |
getChannel() { return channel; } |
718 |
|
719 |
/** |
720 |
* Sets the channel, for which effect sends should be obtained. |
721 |
*/ |
722 |
public void |
723 |
setChannel(int channel) { |
724 |
this.channel = channel; |
725 |
setDescription(i18n.getMessage("Channel.GetFxSends.desc", channel)); |
726 |
} |
727 |
} |
728 |
|
729 |
/** |
730 |
* This task updates the list of effect sends on the specified sampler channel. |
731 |
*/ |
732 |
public static class UpdateFxSends extends EnhancedTask { |
733 |
private int channel; |
734 |
|
735 |
/** |
736 |
* Creates a new instance of <code>UpdateFxSends</code>. |
737 |
* @param channel The numerical ID of the sampler channel |
738 |
* whose effect send list should be updated. |
739 |
*/ |
740 |
public |
741 |
UpdateFxSends(int channel) { |
742 |
setTitle("Channel.UpdateFxSends_task"); |
743 |
setDescription(i18n.getMessage("Channel.UpdateFxSends.desc", channel)); |
744 |
|
745 |
this.channel = channel; |
746 |
} |
747 |
|
748 |
/** The entry point of the task. */ |
749 |
@Override |
750 |
public void |
751 |
exec() throws Exception { |
752 |
SamplerChannelModel scm; |
753 |
scm = CC.getSamplerModel().getChannelById(channel); |
754 |
Integer[] fxSendIDs = CC.getClient().getFxSendIDs(channel); |
755 |
|
756 |
boolean found = false; |
757 |
|
758 |
for(FxSend fxs : scm.getFxSends()) { |
759 |
for(int i = 0; i < fxSendIDs.length; i++) { |
760 |
if(fxSendIDs[i] == fxs.getFxSendId()) { |
761 |
fxSendIDs[i] = -1; |
762 |
found = true; |
763 |
} |
764 |
} |
765 |
|
766 |
if(!found) scm.removeFxSendById(fxs.getFxSendId()); |
767 |
found = false; |
768 |
} |
769 |
|
770 |
FxSend fxs; |
771 |
|
772 |
for(int id : fxSendIDs) { |
773 |
if(id >= 0) { |
774 |
fxs = CC.getClient().getFxSendInfo(channel, id); |
775 |
scm.addFxSend(fxs); |
776 |
} |
777 |
} |
778 |
} |
779 |
} |
780 |
|
781 |
/** |
782 |
* This task updates the settings of a specific effect send. |
783 |
*/ |
784 |
public static class UpdateFxSendInfo extends EnhancedTask { |
785 |
private int channel; |
786 |
private int fxSend; |
787 |
|
788 |
/** |
789 |
* Creates new instance of <code>UpdateFxSendInfo</code>. |
790 |
* @param channel The numerical ID of the sampler channel |
791 |
* containing the effect send entity that should be updated. |
792 |
* @param fxSend The numerical ID of the effect send |
793 |
* that should be updated. |
794 |
*/ |
795 |
public |
796 |
UpdateFxSendInfo(int channel, int fxSend) { |
797 |
setTitle("Channel.UpdateFxSendInfo_task"); |
798 |
String s = "Channel.UpdateFxSendInfo.desc"; |
799 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
800 |
|
801 |
this.channel = channel; |
802 |
this.fxSend = fxSend; |
803 |
} |
804 |
|
805 |
/** The entry point of the task. */ |
806 |
@Override |
807 |
public void |
808 |
exec() throws Exception { |
809 |
/* |
810 |
* We don't want to bother the user if error occurs when updating |
811 |
* an effect send because in most cases this happens due to a race |
812 |
* condition between delete/update events. So we just log this |
813 |
* error instead to indicate the failure of this task. |
814 |
*/ |
815 |
setSilent(true); |
816 |
SamplerChannelModel scm; |
817 |
scm = CC.getSamplerModel().getChannelById(channel); |
818 |
scm.updateFxSend(CC.getClient().getFxSendInfo(channel, fxSend)); |
819 |
} |
820 |
} |
821 |
|
822 |
/** |
823 |
* This taks changes the name of a specific effect send. |
824 |
*/ |
825 |
public static class SetFxSendName extends EnhancedTask { |
826 |
private int channel; |
827 |
private int fxSend; |
828 |
private String name; |
829 |
|
830 |
/** |
831 |
* Creates new instance of <code>SetFxSendName</code>. |
832 |
* @param channel The sampler channel number. |
833 |
* @param fxSend The numerical ID of the effect |
834 |
* send, which name should be changed. |
835 |
* @param name The new name of the effect send entity. |
836 |
*/ |
837 |
public |
838 |
SetFxSendName(int channel, int fxSend, String name) { |
839 |
setTitle("Channel.SetFxSendName_task"); |
840 |
String s = "Channel.SetFxSendName.desc"; |
841 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
842 |
|
843 |
this.channel = channel; |
844 |
this.fxSend = fxSend; |
845 |
this.name = name; |
846 |
} |
847 |
|
848 |
/** The entry point of the task. */ |
849 |
@Override |
850 |
public void |
851 |
exec() throws Exception { CC.getClient().setFxSendName(channel, fxSend, name); } |
852 |
} |
853 |
|
854 |
/** |
855 |
* This taks sets the MIDI controller of a specific effect send. |
856 |
*/ |
857 |
public static class SetFxSendAudioOutputChannel extends EnhancedTask { |
858 |
private int channel; |
859 |
private int fxSend; |
860 |
private int audioSrc; |
861 |
private int audioDst; |
862 |
|
863 |
/** |
864 |
* Creates new instance of <code>SetFxSendAudioOutputChannel</code>. |
865 |
* @param channel The sampler channel number. |
866 |
* @param fxSend The numerical ID of the effect send entity to be rerouted. |
867 |
* @param audioSrc The numerical ID of the effect send's audio output channel, |
868 |
* which should be rerouted. |
869 |
* @param audioDst The audio channel of the selected audio output device |
870 |
* where <code>audioSrc</code> should be routed to. |
871 |
*/ |
872 |
public |
873 |
SetFxSendAudioOutputChannel(int channel, int fxSend, int audioSrc, int audioDst) { |
874 |
setTitle("Channel.SetFxSendAudioOutputChannel_task"); |
875 |
String s = "Channel.SetFxSendAudioOutputChannel.desc"; |
876 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
877 |
|
878 |
this.channel = channel; |
879 |
this.fxSend = fxSend; |
880 |
this.audioSrc = audioSrc; |
881 |
this.audioDst = audioDst; |
882 |
} |
883 |
|
884 |
/** The entry point of the task. */ |
885 |
@Override |
886 |
public void |
887 |
exec() throws Exception { |
888 |
CC.getClient().setFxSendAudioOutputChannel ( |
889 |
channel, fxSend, audioSrc, audioDst |
890 |
); |
891 |
} |
892 |
} |
893 |
|
894 |
/** |
895 |
* This taks sets the volume of a specific effect send. |
896 |
*/ |
897 |
public static class SetFxSendLevel extends EnhancedTask { |
898 |
private int channel; |
899 |
private int fxSend; |
900 |
private float volume; |
901 |
|
902 |
/** |
903 |
* Creates new instance of <code>SetFxSendLevel</code>. |
904 |
* @param channel The sampler channel number. |
905 |
* @param fxSend The numerical ID of the effect send, which |
906 |
* volume should be changed. |
907 |
* @param volume The new volume value. |
908 |
*/ |
909 |
public |
910 |
SetFxSendLevel(int channel, int fxSend, float volume) { |
911 |
setTitle("Channel.SetFxSendLevel_task"); |
912 |
String s = i18n.getMessage("Channel.SetFxSendLevel.desc", channel, fxSend); |
913 |
setDescription(s); |
914 |
|
915 |
this.channel = channel; |
916 |
this.fxSend = fxSend; |
917 |
this.volume = volume; |
918 |
} |
919 |
|
920 |
/** The entry point of the task. */ |
921 |
@Override |
922 |
public void |
923 |
exec() throws Exception { |
924 |
CC.getClient().setFxSendLevel(channel, fxSend, volume); |
925 |
} |
926 |
} |
927 |
|
928 |
/** |
929 |
* This taks sets the MIDI controller of a specific effect send. |
930 |
*/ |
931 |
public static class SetFxSendMidiController extends EnhancedTask { |
932 |
private int channel; |
933 |
private int fxSend; |
934 |
private int midiCtrl; |
935 |
|
936 |
/** |
937 |
* Creates new instance of <code>SetFxSendMidiController</code>. |
938 |
* @param channel The sampler channel number. |
939 |
* @param fxSend The numerical ID of the effect |
940 |
* send, which MIDI controller should be changed. |
941 |
* @param midiCtrl The MIDI controller which shall be |
942 |
* able to modify the effect send's send level. |
943 |
*/ |
944 |
public |
945 |
SetFxSendMidiController(int channel, int fxSend, int midiCtrl) { |
946 |
setTitle("Channel.SetFxSendMidiController_task"); |
947 |
String s = "Channel.SetFxSendMidiController.desc"; |
948 |
setDescription(i18n.getMessage(s, channel, fxSend)); |
949 |
|
950 |
this.channel = channel; |
951 |
this.fxSend = fxSend; |
952 |
this.midiCtrl = midiCtrl; |
953 |
} |
954 |
|
955 |
/** The entry point of the task. */ |
956 |
@Override |
957 |
public void |
958 |
exec() throws Exception { |
959 |
CC.getClient().setFxSendMidiController(channel, fxSend, midiCtrl); |
960 |
} |
961 |
} |
962 |
|
963 |
/** |
964 |
* This task starts an instrument editor for editing the loaded instrument |
965 |
* on the specified sampler channel. |
966 |
*/ |
967 |
public static class EditInstrument extends EnhancedTask { |
968 |
private int chn; |
969 |
|
970 |
/** |
971 |
* Creates new instance of <code>EditInstrument</code>. |
972 |
* @param channel The sampler channel number. |
973 |
*/ |
974 |
public |
975 |
EditInstrument(int channel) { |
976 |
setTitle("Channel.EditInstrument_task"); |
977 |
String s = i18n.getMessage("Channel.EditInstrument.desc"); |
978 |
setDescription(s); |
979 |
|
980 |
this.chn = channel; |
981 |
} |
982 |
|
983 |
/** The entry point of the task. */ |
984 |
@Override |
985 |
public void |
986 |
exec() throws Exception { CC.getClient().editChannelInstrument(chn); } |
987 |
} |
988 |
|
989 |
/** |
990 |
* This task starts an instrument editor for editing the loaded instrument |
991 |
* on the specified sampler channel. |
992 |
*/ |
993 |
public static class SendMidiMsg extends EnhancedTask { |
994 |
private int chn; |
995 |
private MidiDataEvent.Type type; |
996 |
private int arg1; |
997 |
private int arg2; |
998 |
|
999 |
/** |
1000 |
* Creates new instance of <code>SendMidiMsg</code>. |
1001 |
* @param channel The sampler channel number. |
1002 |
*/ |
1003 |
public |
1004 |
SendMidiMsg(int channel, MidiDataEvent.Type type, int arg1, int arg2) { |
1005 |
this.chn = channel; |
1006 |
this.type = type; |
1007 |
this.arg1 = arg1; |
1008 |
this.arg2 = arg2; |
1009 |
|
1010 |
setTitle("Channel.SendMidiMsg_task"); |
1011 |
String s = i18n.getMessage("Channel.SendMidiMsg.desc", channel); |
1012 |
setDescription(s); |
1013 |
} |
1014 |
|
1015 |
/** The entry point of the task. */ |
1016 |
@Override |
1017 |
public void |
1018 |
exec() throws Exception { |
1019 |
setSilent(true); |
1020 |
CC.getClient().sendChannelMidiData(chn, type, arg1, arg2); |
1021 |
} |
1022 |
} |
1023 |
} |