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