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

Contents of /jsampler/trunk/src/org/jsampler/DefaultSamplerChannelModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 28354 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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;
24
25 import java.util.Vector;
26
27 import net.sf.juife.PDUtils;
28 import net.sf.juife.Task;
29 import net.sf.juife.event.TaskEvent;
30 import net.sf.juife.event.TaskListener;
31
32 import org.jsampler.event.EffectSendsEvent;
33 import org.jsampler.event.EffectSendsListener;
34 import org.jsampler.event.SamplerChannelEvent;
35 import org.jsampler.event.SamplerChannelListener;
36
37 import org.jsampler.task.Channel;
38 import org.jsampler.task.Channel.LoadEngine;
39 import org.jsampler.task.Channel.LoadInstrument;
40 import org.jsampler.task.Channel.SetMidiInputChannel;
41 import org.jsampler.task.Channel.SetMidiInputDevice;
42 import org.jsampler.task.Channel.SetMidiInputPort;
43 import org.jsampler.task.Channel.SetMute;
44 import org.jsampler.task.Channel.SetSolo;
45 import org.jsampler.task.Channel.SetVolume;
46 import org.jsampler.task.Channel.UpdateFxSendInfo;
47 import org.jsampler.task.DuplicateChannels;
48
49 import org.linuxsampler.lscp.FxSend;
50 import org.linuxsampler.lscp.SamplerChannel;
51
52 import org.linuxsampler.lscp.event.MidiDataEvent;
53 import org.linuxsampler.lscp.event.MidiDataListener;
54
55
56 /**
57 * This class provides default implementation of the <code>SamplerChannelModel</code> interface.
58 * Note that all methods that begin with <code>setBackend</code> alter the settings
59 * on the backend side.
60 * @author Grigor Iliev
61 */
62 public class DefaultSamplerChannelModel implements SamplerChannelModel {
63 private SamplerChannel channel;
64 private int streamCount = 0;
65 private int voiceCount = 0;
66
67 private final Vector<SamplerChannelListener> listeners =
68 new Vector<SamplerChannelListener>();
69
70 private final Vector<EffectSendsListener> fxListeners = new Vector<EffectSendsListener>();
71
72 private final Vector<FxSend> fxSends = new Vector<FxSend>();
73
74 private final Vector<MidiDataListener> midiListeners = new Vector<MidiDataListener>();
75
76 /**
77 * Creates a new instance of <code>DefaultSamplerChannelModel</code> using the
78 * specified channel settings.
79 * @param channel A non-null <code>SamplerChannel</code> instance containing the current
80 * settings of the channel which will be represented by this sampler channel model.
81 * @throws IllegalArgumentException If <code>channel</code> is <code>null</code>.
82 */
83 public DefaultSamplerChannelModel(SamplerChannel channel) {
84 if(channel == null) throw new IllegalArgumentException("channel must be non null");
85 this.channel = channel;
86 }
87
88 /**
89 * Registers the specified listener for receiving event messages.
90 * @param l The <code>SamplerChannelListener</code> to register.
91 */
92 @Override
93 public void
94 addSamplerChannelListener(SamplerChannelListener l) { listeners.add(l); }
95
96 /**
97 * Removes the specified listener.
98 * @param l The <code>SamplerChannelListener</code> to remove.
99 */
100 @Override
101 public void
102 removeSamplerChannelListener(SamplerChannelListener l) { listeners.remove(l); }
103
104 /**
105 * Registers the specified listener for receiving event messages.
106 * @param l The <code>EffectSendsListener</code> to register.
107 */
108 @Override
109 public void
110 addEffectSendsListener(EffectSendsListener l) { fxListeners.add(l); }
111
112 /**
113 * Removes the specified listener.
114 * @param l The <code>EffectSendsListener</code> to remove.
115 */
116 @Override
117 public void
118 removeEffectSendsListener(EffectSendsListener l) { fxListeners.remove(l); }
119
120 /**
121 * Registers the specified listener to be notified when
122 * MIDI events are sent to the channel.
123 * @param l The <code>MidiDataListener</code> to register.
124 */
125 @Override
126 public void
127 addMidiDataListener(MidiDataListener l) { midiListeners.add(l); }
128
129 /**
130 * Removes the specified listener.
131 * @param l The <code>MidiDataListener</code> to remove.
132 */
133 @Override
134 public void
135 removeMidiDataListener(MidiDataListener l) { midiListeners.remove(l); }
136
137 /**
138 * Gets the sampler channel number.
139 * @return The sampler channel number or -1 if the sampler channel number is not set.
140 */
141 @Override
142 public int
143 getChannelId() { return channel == null ? -1 : channel.getChannelId(); }
144
145 /**
146 * Gets the current settings of the sampler channel.
147 * @return <code>SamplerChannel</code> instance containing
148 * the current settings of the sampler channel.
149 */
150 @Override
151 public SamplerChannel
152 getChannelInfo() { return channel; }
153
154 /**
155 * Sets the current settings of the sampler channel.
156 * Note that this method does not changes the channel settings on
157 * the backend. It is invoked just notify for channel settings' changes.
158 * @param channel A <code>SamplerChannel</code> instance containing
159 * the new settings for this sampler channel.
160 * @throws IllegalArgumentException If <code>channel</code> is <code>null</code>.
161 */
162 @Override
163 public void
164 setChannelInfo(SamplerChannel channel) {
165 if(channel == null) throw new IllegalArgumentException("channel must be non null");
166 if(this.channel == channel) return;
167
168 this.channel = channel;
169 fireSamplerChannelChanged();
170 }
171
172 /**
173 * Gets the number of active disk streams.
174 * @return The number of active disk streams.
175 */
176 @Override
177 public int
178 getStreamCount() { return streamCount; }
179
180 /**
181 * Sets the number of active disk streams.
182 * Note that this method does <b>not</b> alter the number
183 * of active disk streams on the backend side.
184 * @param count The new number of active disk streams.
185 */
186 @Override
187 public void
188 setStreamCount(int count) {
189 if(streamCount == count) return;
190
191 streamCount = count;
192 fireStreamCountChanged();
193 }
194
195 /**
196 * Gets the number of active voices.
197 * @return The number of active voices.
198 */
199 @Override
200 public int
201 getVoiceCount() { return voiceCount; }
202
203 /**
204 * Sets the number of active voices.
205 * Note that this method does <b>not</b> alter the number
206 * of active voices on the backend side.
207 * @param count The new number of active voices.
208 */
209 @Override
210 public void
211 setVoiceCount(int count) {
212 if(voiceCount == count) return;
213
214 voiceCount = count;
215 fireVoiceCountChanged();
216 }
217
218 /**
219 * Schedules a new task for setting the sampler engine type to be used.
220 * @param engine The name of the engine type to be used.
221 */
222 @Override
223 public void
224 setBackendEngineType(String engine) {
225 final LoadEngine loadEngine = new LoadEngine(engine, getChannelId());
226 final SamplerChannelEvent event = new SamplerChannelEvent(this);
227
228 loadEngine.addTaskListener(new TaskListener() {
229 public void
230 taskPerformed(TaskEvent e) {
231 /*
232 * Because with the invokation of the method the task is considered
233 * to be done, if the task fails, we must notify for a channel
234 * changes. This should be done to revert the old channel settings.
235 */
236 if(loadEngine.doneWithErrors()) fireSamplerChannelChanged(event);
237 }
238 });
239 CC.getTaskQueue().add(loadEngine);
240
241 // We leave this event to be notified by the LinuxSampler notification system.
242 }
243
244 /**
245 * Schedules a new task for setting the mute mode of the channel.
246 * @param mute Specifies the mute mode. If <code>true</code> the channel is muted, else
247 * the channel is unmuted.
248 */
249 @Override
250 public void
251 setBackendMute(boolean mute) {
252 final SetMute smc = new SetMute(getChannelId(), mute);
253 final SamplerChannelEvent event = new SamplerChannelEvent(this);
254
255 smc.addTaskListener(new TaskListener() {
256 public void
257 taskPerformed(TaskEvent e) {
258 /*
259 * Because with the invokation of the method the task is considered
260 * to be done, if the task fails, we must notify for a channel
261 * changes. This should be done to revert the old channel settings.
262 */
263 if(smc.doneWithErrors()) fireSamplerChannelChanged(event);
264 }
265 });
266 CC.getTaskQueue().add(smc);
267
268 // We leave this event to be notified by the LinuxSampler notification system.
269 }
270
271 /**
272 * Schedules a new task for setting on the backend side the solo mode of the channel.
273 * @param solo Specifies the solo mode. If <code>true</code> the channel is soloed, else
274 * the channel is unsoloed.
275 */
276 @Override
277 public void
278 setBackendSolo(boolean solo) {
279 final SetSolo ssc = new SetSolo(getChannelId(), solo);
280 final SamplerChannelEvent event = new SamplerChannelEvent(this);
281
282 ssc.addTaskListener(new TaskListener() {
283 public void
284 taskPerformed(TaskEvent e) {
285 /*
286 * Because with the invokation of the method the task is considered
287 * to be done, if the task fails, we must notify for a channel
288 * changes. This should be done to revert the old channel settings.
289 */
290 if(ssc.doneWithErrors()) fireSamplerChannelChanged(event);
291 }
292 });
293 CC.getTaskQueue().add(ssc);
294
295 // We leave this event to be notified by the LinuxSampler notification system.
296 }
297
298 /**
299 * Schedules a new task for setting the channel volume on the backend side.
300 * @param volume Specifies the new volume value.
301 */
302 @Override
303 public void
304 setBackendVolume(float volume) {
305 final SetVolume scv = new SetVolume(getChannelId(), volume);
306 final SamplerChannelEvent event = new SamplerChannelEvent(this);
307
308 scv.addTaskListener(new TaskListener() {
309 public void
310 taskPerformed(TaskEvent e) {
311 /*
312 * Because with the invokation of the method the task is considered
313 * to be done, if the task fails, we must notify for a channel
314 * changes. This should be done to revert the old channel settings.
315 */
316 if(scv.doneWithErrors()) fireSamplerChannelChanged(event);
317 }
318 });
319 CC.getTaskQueue().add(scv);
320
321 // We leave this event to be notified by the LinuxSampler notification system.
322 }
323
324 /**
325 * Schedules a new task for setting on the backend side the MIDI input
326 * device of the channel represented by this model.
327 * @param deviceId Specifies the numerical ID of the MIDI input device to be set.
328 */
329 @Override
330 public void
331 setBackendMidiInputDevice(int deviceId) {
332 final Task scmid = new SetMidiInputDevice(getChannelId(), deviceId);
333 final SamplerChannelEvent event = new SamplerChannelEvent(this);
334
335 scmid.addTaskListener(new TaskListener() {
336 public void
337 taskPerformed(TaskEvent e) {
338 /*
339 * Because with the invokation of the method the task is considered
340 * to be done, if the task fails, we must notify for a channel
341 * changes. This should be done to revert the old channel settings.
342 */
343 if(scmid.doneWithErrors()) fireSamplerChannelChanged(event);
344 }
345 });
346 CC.getTaskQueue().add(scmid);
347
348 // We leave this event to be notified by the LinuxSampler notification system.
349 }
350
351 /**
352 * Schedules a new task for setting (on the backend side) the
353 * MIDI input port of the channel represented by this model.
354 * @param port Specifies the number of the MIDI input port.
355 */
356 @Override
357 public void
358 setBackendMidiInputPort(int port) {
359 final Task scmip = new SetMidiInputPort(getChannelId(), port);
360 final SamplerChannelEvent event = new SamplerChannelEvent(this);
361
362 scmip.addTaskListener(new TaskListener() {
363 public void
364 taskPerformed(TaskEvent e) {
365 /*
366 * Because with the invokation of the method the task is considered
367 * to be done, if the task fails, we must notify for a channel
368 * changes. This should be done to revert the old channel settings.
369 */
370 if(scmip.doneWithErrors()) fireSamplerChannelChanged(event);
371 }
372 });
373 CC.getTaskQueue().add(scmip);
374
375 // We leave this event to be notified by the LinuxSampler notification system.
376 }
377
378 /**
379 * Schedules a new task for setting (on the backend side) the MIDI channel
380 * that the channel represented by this model should listen to.
381 * @param channel Specifies the MIDI channel that the channel
382 * represented by this model should listen to.
383 */
384 @Override
385 public void
386 setBackendMidiInputChannel(int channel) {
387 final Task scmic = new SetMidiInputChannel(getChannelId(), channel);
388 final SamplerChannelEvent event = new SamplerChannelEvent(this);
389
390 scmic.addTaskListener(new TaskListener() {
391 public void
392 taskPerformed(TaskEvent e) {
393 /*
394 * Because with the invokation of the method the task is considered
395 * to be done, if the task fails, we must notify for a channel
396 * changes. This should be done to revert the old channel settings.
397 */
398 if(scmic.doneWithErrors()) fireSamplerChannelChanged(event);
399 }
400 });
401 CC.getTaskQueue().add(scmic);
402
403 // We leave this event to be notified by the LinuxSampler notification system.
404 }
405
406 /**
407 * Schedules a new task for setting (on the backend side) the audio output
408 * device of the channel represented by this model.
409 * @param deviceId Specifies the numerical ID of the audio output device to be set.
410 */
411 @Override
412 public void
413 setBackendAudioOutputDevice(int deviceId) {
414 final Task scaod = new Channel.SetAudioOutputDevice(getChannelId(), deviceId);
415 final SamplerChannelEvent event = new SamplerChannelEvent(this);
416
417 scaod.addTaskListener(new TaskListener() {
418 public void
419 taskPerformed(TaskEvent e) {
420 /*
421 * Because with the invokation of the method the task is considered
422 * to be done, if the task fails, we must notify for a channel
423 * changes. This should be done to revert the old channel settings.
424 */
425 if(scaod.doneWithErrors()) fireSamplerChannelChanged(event);
426 }
427 });
428 CC.getTaskQueue().add(scaod);
429
430 // We leave this event to be notified by the LinuxSampler notification system.
431 }
432
433 /**
434 * Sets the destination of the destination of the specified audio channel.
435 * @param audioSrc The numerical ID of the sampler channel's audio
436 * output channel, which should be rerouted.
437 * @param audioDst The audio channel of the selected audio output device
438 * where <code>audioSrc</code> should be routed to.
439 */
440 @Override
441 public void
442 setBackendAudioOutputChannel(int audioSrc, int audioDst) {
443 final Task t;
444 t = new Channel.SetAudioOutputChannel(getChannelId(), audioSrc, audioDst);
445 final SamplerChannelEvent event = new SamplerChannelEvent(this);
446
447 t.addTaskListener(new TaskListener() {
448 public void
449 taskPerformed(TaskEvent e) {
450 /*
451 * Because with the invokation of the method the task is considered
452 * to be done, if the task fails, we must notify for a channel
453 * changes. This should be done to revert the old channel settings.
454 */
455 if(t.doneWithErrors()) fireSamplerChannelChanged(event);
456 }
457 });
458 CC.getTaskQueue().add(t);
459 }
460
461 /**
462 * Schedules a new task for assigning (on the backend side) the
463 * specified MIDI instrument map to this sampler channel.
464 * @param mapId Specify the numerical ID of the MIDI instrument
465 * map that should be assigned to this sampler
466 * channel or <code>-1</code> to remove the current map binding.
467 */
468 @Override
469 public void
470 setBackendMidiInstrumentMap(int mapId) {
471 final Task t = new Channel.SetMidiInstrumentMap(getChannelId(), mapId);
472 final SamplerChannelEvent event = new SamplerChannelEvent(this);
473
474 t.addTaskListener(new TaskListener() {
475 public void
476 taskPerformed(TaskEvent e) {
477 /*
478 * Because with the invokation of the method the task is considered
479 * to be done, if the task fails, we must notify for a channel
480 * changes. This should be done to revert the old channel settings.
481 */
482 if(t.doneWithErrors()) fireSamplerChannelChanged(event);
483 }
484 });
485 CC.getTaskQueue().add(t);
486 }
487
488 /**
489 * Schedules a new task for loading and assigning the specified instrument
490 * to the sampler channel represented by this model.
491 * @param filename The file name of the instrument to be loaded.
492 * @param InstrIndex The index of the instrument in the instrument file to be loaded.
493 */
494 @Override
495 public void
496 loadBackendInstrument(String filename, int InstrIndex) {
497 final Task li = new LoadInstrument(filename, InstrIndex, getChannelId());
498 CC.getTaskQueue().add(li);
499
500 // We leave this event to be notified by the LinuxSampler notification system.
501 }
502
503 /** Schedules a new task for reseting the channel. */
504 @Override
505 public void
506 resetBackendChannel() {
507 CC.getTaskQueue().add(new org.jsampler.task.Channel.Reset(getChannelId()));
508
509 // We leave this event to be notified by the LinuxSampler notification system.
510 }
511
512 /** Schedules a new task for duplicating the channel. */
513 @Override
514 public void
515 duplicateBackendChannel() {
516 CC.getTaskQueue().add(new DuplicateChannels(getChannelInfo()));
517 }
518
519 /**
520 * Schedules a new task for adding a new effect send on the
521 * backend side. The effect send will be actually added to this model
522 * when the backend notifies for its creation.
523 * @param midiCtrl Defines the MIDI controller, which
524 * will be able alter the effect send level.
525 */
526 @Override
527 public void
528 addBackendFxSend(int midiCtrl) {
529 CC.getTaskQueue().add(new Channel.AddFxSend(getChannelId(), midiCtrl));
530 // We leave this event to be notified by the LinuxSampler notification system.
531 }
532
533 /**
534 * Schedules a new task for adding a new effect send on the
535 * backend side. The effect send will be actually added to this model
536 * when the backend notifies for its creation.
537 * @param midiCtrl Defines the MIDI controller, which
538 * will be able alter the effect send level.
539 * @param name The name of the effect send entity.
540 * The name does not have to be unique.
541 */
542 @Override
543 public void
544 addBackendFxSend(int midiCtrl, String name) {
545 CC.getTaskQueue().add(new Channel.AddFxSend(getChannelId(), midiCtrl, name));
546 // We leave this event to be notified by the LinuxSampler notification system.
547 }
548
549 /**
550 * Adds the specified effect send.
551 * @param fxSend The effect send to be added.
552 */
553 @Override
554 public void
555 addFxSend(FxSend fxSend) {
556 fxSends.add(fxSend);
557 fireFxSendAdded(fxSend);
558 }
559
560 /**
561 * Schedules a new task for removing the specified effect send on the backend side.
562 * @param fxSendId The ID of the effect send to remove.
563 */
564 @Override
565 public void
566 removeBackendFxSend(int fxSendId) {
567 CC.getTaskQueue().add(new Channel.RemoveFxSend(getChannelId(), fxSendId));
568 }
569
570 /**
571 * Gets the effect send at the specified position.
572 * @param index The index of the effect send to be returned.
573 * @return The effect send at the specified position.
574 */
575 @Override
576 public FxSend
577 getFxSend(int index) { return fxSends.get(index); }
578
579 /**
580 * Gets the effect send with the specified ID.
581 * @param fxSendId The ID of the effect send to return.
582 * @return The effect send with the specified ID or <code>null</code>
583 * if there is no effect send with ID <code>fxSendId</code>.
584 */
585 @Override
586 public FxSend
587 getFxSendById(int fxSendId) {
588 for(FxSend fxs : fxSends) {
589 if(fxs.getFxSendId() == fxSendId) return fxs;
590 }
591
592 return null;
593 }
594
595 /**
596 * Removes the effect send at the specified position.
597 * @param index The position of the effect send to remove.
598 * @return The removed effect send.
599 */
600 @Override
601 public FxSend
602 removeFxSend(int index) {
603 FxSend fxs = fxSends.remove(index);
604 fireFxSendRemoved(fxs);
605 return fxs;
606 }
607
608 /**
609 * Removes the specified effect send.
610 * @param fxSendId The ID of the effect send to remove.
611 * @return <code>true</code> if the effect send is removed successfully, <code>false</code>
612 * if the channel does not contain effect send with ID <code>fxSendId</code>.
613 */
614 @Override
615 public boolean
616 removeFxSendById(int fxSendId) {
617 for(int i = 0; i < fxSends.size(); i++) {
618 FxSend fxs = fxSends.get(i);
619 if(fxs.getFxSendId() == fxSendId) {
620 fxSends.remove(i);
621 fireFxSendRemoved(fxs);
622 return true;
623 }
624 }
625
626 return false;
627 }
628
629 /** Removes all effect sends from this channel. */
630 @Override
631 public void
632 removeAllFxSends() {
633 for(int i = fxSends.size() - 1; i >= 0; i--) {
634 FxSend fxs = fxSends.get(i);
635 fxSends.removeElementAt(i);
636 fireFxSendRemoved(fxs);
637 }
638 }
639
640 /**
641 * Updates the specified effect send.
642 * @param fxSend The effect send to update.
643 */
644 @Override
645 public void
646 updateFxSend(FxSend fxSend) {
647 for(int i = 0; i < fxSends.size(); i++) {
648 FxSend fxs = fxSends.get(i);
649 if(fxs.getFxSendId() == fxSend.getFxSendId()) {
650 fxSends.setElementAt(fxSend, i);
651 fireFxSendUpdated(fxSend);
652 return;
653 }
654 }
655 }
656
657 /**
658 * Gets the current number of effect sends.
659 * @return The current number of effect sends.
660 */
661 @Override
662 public int
663 getFxSendCount() { return fxSends.size(); }
664
665 /**
666 * Gets the current list of effect sends.
667 * @return The current list of effect sends.
668 */
669 @Override
670 public FxSend[]
671 getFxSends() { return fxSends.toArray(new FxSend[fxSends.size()]); }
672
673 /**
674 * Sets the name of the specified effect send.
675 * @param fxSend The numerical ID of the effect send.
676 * @param name The new name of the effect send entity.
677 */
678 @Override
679 public void
680 setBackendFxSendName(final int fxSend, String name) {
681 final Task t = new Channel.SetFxSendName(getChannelId(), fxSend, name);
682 t.addTaskListener(new TaskListener() {
683 public void
684 taskPerformed(TaskEvent e) {
685 /*
686 * Because with the invokation of the method the task is considered
687 * to be done, if the task fails, we must update the settings.
688 */
689 if(t.doneWithErrors()) {
690 int id = getChannelId();
691 CC.getTaskQueue().add(new UpdateFxSendInfo(id, fxSend));
692 }
693 }
694 });
695 CC.getTaskQueue().add(t);
696 }
697
698 /**
699 * Sets the destination of an effect send's audio channel.
700 * @param fxSend The numerical ID of the effect send entity to be rerouted.
701 * @param audioSrc The numerical ID of the effect send's audio output channel,
702 * which should be rerouted.
703 * @param audioDst The audio channel of the selected audio output device
704 * where <code>audioSrc</code> should be routed to.
705 */
706 @Override
707 public void
708 setBackendFxSendAudioOutputChannel(int fxSend, int audioSrc, int audioDst) {
709 Task t = new Channel.SetFxSendAudioOutputChannel (
710 getChannelId(), fxSend, audioSrc, audioDst
711 );
712
713 CC.getTaskQueue().add(t);
714 }
715
716 /**
717 * Sets the MIDI controller of the specified effect send.
718 * @param fxSend The numerical ID of the effect send.
719 * @param midiCtrl The MIDI controller which shall be
720 * able to modify the effect send's send level.
721 */
722 @Override
723 public void
724 setBackendFxSendMidiController(int fxSend, int midiCtrl) {
725 Task t = new Channel.SetFxSendMidiController(getChannelId(), fxSend, midiCtrl);
726 CC.getTaskQueue().add(t);
727 }
728
729 /**
730 * Sets the volume of the specified effect send.
731 * @param fxSend The numerical ID of the effect
732 * send, which volume should be changed.
733 * @param level The new volume value.
734 */
735 @Override
736 public void
737 setBackendFxSendLevel(int fxSend, float level) {
738 CC.getTaskQueue().add(new Channel.SetFxSendLevel(getChannelId(), fxSend, level));
739 }
740
741 /**
742 * Sends a MIDI data message to this sampler channel.
743 */
744 @Override
745 public void
746 sendBackendMidiData(MidiDataEvent e) {
747 sendBackendMidiData(e.getType(), e.getNote(), e.getVelocity());
748 }
749
750 /**
751 * Sends a MIDI data message to this sampler channel.
752 * @param type The type of MIDI message to send.
753 * @param arg1 Depends on the message type.
754 * @param arg2 Depends on the message type.
755 */
756 @Override
757 public void
758 sendBackendMidiData(MidiDataEvent.Type type, int arg1, int arg2) {
759 CC.getTaskQueue().add(new Channel.SendMidiMsg(getChannelId(), type, arg1, arg2));
760 }
761
762 /**
763 * Sets destination effect on the specified effect send.
764 * @param fxSend The numerical ID of the effect send.
765 */
766 @Override
767 public void
768 setBackendFxSendEffect(int fxSend, int chainId, int chainPos) {
769 CC.getTaskQueue().add (
770 new Channel.SetFxSendEffect(getChannelId(), fxSend, chainId, chainPos)
771 );
772 }
773
774 /**
775 * Removes the destination effect of the specified effect send.
776 * @param fxSend The numerical ID of the effect send.
777 */
778 @Override
779 public void
780 removeBackendFxSendEffect(int fxSend) {
781 CC.getTaskQueue().add (
782 new Channel.SetFxSendEffect(getChannelId(), fxSend, -1, -1)
783 );
784 }
785
786 /** Notifies listeners that the sampler channel settings has changed. */
787 protected void
788 fireSamplerChannelChanged() {
789 final SamplerChannelEvent e = new SamplerChannelEvent(this);
790
791 PDUtils.runOnUiThread(new Runnable() {
792 public void
793 run() { fireSamplerChannelChanged(e); }
794 });
795 }
796
797 /**
798 * Notifies listeners that the sampler channel settings has changed.
799 * This method should be invoked from the UI thread.
800 */
801 protected void
802 fireSamplerChannelChanged(SamplerChannelEvent e) {
803 CC.getSamplerModel().setModified(true);
804 for(SamplerChannelListener l : listeners) l.channelChanged(e);
805 }
806
807 /** Notifies listeners that the number of active disk streams has changed. */
808 protected void
809 fireStreamCountChanged() {
810 final SamplerChannelEvent e = new SamplerChannelEvent(this);
811
812 PDUtils.runOnUiThread(new Runnable() {
813 public void
814 run() { fireStreamCountChanged(e); }
815 });
816 }
817
818 /**
819 * Notifies listeners that the number of active disk streams has changed.
820 * This method should be invoked from the UI thread.
821 */
822 protected void
823 fireStreamCountChanged(SamplerChannelEvent e) {
824 for(SamplerChannelListener l : listeners) l.streamCountChanged(e);
825 }
826
827 /** Notifies listeners that the number of active voices has changed. */
828 protected void
829 fireVoiceCountChanged() {
830 final SamplerChannelEvent e = new SamplerChannelEvent(this);
831
832 PDUtils.runOnUiThread(new Runnable() {
833 public void
834 run() { fireVoiceCountChanged(e); }
835 });
836 }
837
838 /**
839 * Notifies listeners that the number of active voices has changed.
840 * This method should be invoked from the UI thread.
841 */
842 protected void
843 fireVoiceCountChanged(SamplerChannelEvent e) {
844 for(SamplerChannelListener l : listeners) l.voiceCountChanged(e);
845 }
846
847 /**
848 * Notifies listeners that the specified effect send has been added to the channel.
849 */
850 protected void
851 fireFxSendAdded(FxSend fxSend) {
852 final EffectSendsEvent e = new EffectSendsEvent(this, fxSend);
853
854 PDUtils.runOnUiThread(new Runnable() {
855 public void
856 run() { fireFxSendAdded(e); }
857 });
858 }
859
860 /**
861 * Notifies listeners that the specified effect send has been added to the channel.
862 * This method should be invoked from the UI thread.
863 */
864 protected void
865 fireFxSendAdded(EffectSendsEvent e) {
866 CC.getSamplerModel().setModified(true);
867 for(EffectSendsListener l : fxListeners) l.effectSendAdded(e);
868 }
869
870 /** Notifies listeners that the specified effect send has been removed. */
871 protected void
872 fireFxSendRemoved(FxSend fxSend) {
873 final EffectSendsEvent e = new EffectSendsEvent(this, fxSend);
874
875 PDUtils.runOnUiThread(new Runnable() {
876 public void
877 run() { fireFxSendRemoved(e); }
878 });
879 }
880
881 /**
882 * Notifies listeners that the specified effect send has been removed.
883 * This method should be invoked from the UI thread.
884 */
885 protected void
886 fireFxSendRemoved(EffectSendsEvent e) {
887 CC.getSamplerModel().setModified(true);
888 for(EffectSendsListener l : fxListeners) l.effectSendRemoved(e);
889 }
890
891 /** Notifies listeners that the specified effect send has been updated. */
892 protected void
893 fireFxSendUpdated(FxSend fxSend) {
894 final EffectSendsEvent e = new EffectSendsEvent(this, fxSend);
895
896 PDUtils.runOnUiThread(new Runnable() {
897 public void
898 run() { fireFxSendUpdated(e); }
899 });
900 }
901
902 /**
903 * Notifies listeners that the specified effect send has been updated.
904 * This method should be invoked from the UI thread.
905 */
906 protected void
907 fireFxSendUpdated(EffectSendsEvent e) {
908 CC.getSamplerModel().setModified(true);
909 for(EffectSendsListener l : fxListeners) l.effectSendChanged(e);
910 }
911
912 /**
913 * Notifies listeners that the specified effect send has been updated.
914 * This method should be invoked from the event-dispatching thread.
915 */
916 protected void
917 fireMidiDataEvent(MidiDataEvent e) {
918 for(MidiDataListener l : midiListeners) l.midiDataArrived(e);
919 }
920 }

  ViewVC Help
Powered by ViewVC