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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2302 - (hide annotations) (download)
Thu Dec 15 23:13:30 2011 UTC (12 years, 4 months ago) by iliev
File size: 28426 byte(s)
* Initial support for Android platforms (only sampler channel
  manipulation for now - see the screenshots on the website)

1 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2200 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 787 *
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 iliev 2288 import net.sf.juife.PDUtils;
28 iliev 787 import net.sf.juife.Task;
29     import net.sf.juife.event.TaskEvent;
30     import net.sf.juife.event.TaskListener;
31    
32 iliev 1143 import org.jsampler.event.EffectSendsEvent;
33     import org.jsampler.event.EffectSendsListener;
34 iliev 787 import org.jsampler.event.SamplerChannelEvent;
35     import org.jsampler.event.SamplerChannelListener;
36    
37 iliev 1143 import org.jsampler.task.Channel;
38 iliev 1204 import org.jsampler.task.Channel.LoadEngine;
39     import org.jsampler.task.Channel.LoadInstrument;
40 iliev 1143 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 iliev 911 import org.jsampler.task.DuplicateChannels;
48 iliev 787
49 iliev 1143 import org.linuxsampler.lscp.FxSend;
50 iliev 787 import org.linuxsampler.lscp.SamplerChannel;
51    
52 iliev 1776 import org.linuxsampler.lscp.event.MidiDataEvent;
53     import org.linuxsampler.lscp.event.MidiDataListener;
54 iliev 787
55 iliev 1776
56 iliev 787 /**
57 iliev 911 * This class provides default implementation of the <code>SamplerChannelModel</code> interface.
58 iliev 1143 * Note that all methods that begin with <code>setBackend</code> alter the settings
59     * on the backend side.
60 iliev 787 * @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 iliev 1143 private final Vector<EffectSendsListener> fxListeners = new Vector<EffectSendsListener>();
71    
72     private final Vector<FxSend> fxSends = new Vector<FxSend>();
73    
74 iliev 1776 private final Vector<MidiDataListener> midiListeners = new Vector<MidiDataListener>();
75    
76 iliev 787 /**
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 iliev 2288 @Override
93 iliev 787 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 iliev 2288 @Override
101 iliev 787 public void
102     removeSamplerChannelListener(SamplerChannelListener l) { listeners.remove(l); }
103    
104     /**
105 iliev 1143 * Registers the specified listener for receiving event messages.
106     * @param l The <code>EffectSendsListener</code> to register.
107     */
108 iliev 2288 @Override
109 iliev 1143 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 iliev 2288 @Override
117 iliev 1143 public void
118     removeEffectSendsListener(EffectSendsListener l) { fxListeners.remove(l); }
119    
120     /**
121 iliev 1776 * 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 iliev 2288 @Override
126 iliev 1776 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 iliev 2288 @Override
134 iliev 1776 public void
135     removeMidiDataListener(MidiDataListener l) { midiListeners.remove(l); }
136    
137     /**
138 iliev 787 * Gets the sampler channel number.
139     * @return The sampler channel number or -1 if the sampler channel number is not set.
140     */
141 iliev 2288 @Override
142 iliev 787 public int
143 iliev 1143 getChannelId() { return channel == null ? -1 : channel.getChannelId(); }
144 iliev 787
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 iliev 2288 @Override
151 iliev 787 public SamplerChannel
152     getChannelInfo() { return channel; }
153    
154     /**
155     * Sets the current settings of the sampler channel.
156 iliev 911 * Note that this method does not changes the channel settings on
157 iliev 1143 * the backend. It is invoked just notify for channel settings' changes.
158 iliev 787 * @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 iliev 2288 @Override
163 iliev 787 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 iliev 2288 @Override
177 iliev 787 public int
178     getStreamCount() { return streamCount; }
179    
180     /**
181     * Sets the number of active disk streams.
182 iliev 1143 * Note that this method does <b>not</b> alter the number
183     * of active disk streams on the backend side.
184 iliev 787 * @param count The new number of active disk streams.
185     */
186 iliev 2288 @Override
187 iliev 787 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 iliev 2288 @Override
200 iliev 787 public int
201     getVoiceCount() { return voiceCount; }
202    
203     /**
204     * Sets the number of active voices.
205 iliev 1143 * Note that this method does <b>not</b> alter the number
206     * of active voices on the backend side.
207 iliev 787 * @param count The new number of active voices.
208     */
209 iliev 2288 @Override
210 iliev 787 public void
211     setVoiceCount(int count) {
212     if(voiceCount == count) return;
213    
214     voiceCount = count;
215     fireVoiceCountChanged();
216     }
217    
218     /**
219 iliev 1143 * Schedules a new task for setting the sampler engine type to be used.
220 iliev 787 * @param engine The name of the engine type to be used.
221     */
222 iliev 2288 @Override
223 iliev 787 public void
224 iliev 1143 setBackendEngineType(String engine) {
225     final LoadEngine loadEngine = new LoadEngine(engine, getChannelId());
226 iliev 787 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 iliev 1143 * Schedules a new task for setting the mute mode of the channel.
246 iliev 787 * @param mute Specifies the mute mode. If <code>true</code> the channel is muted, else
247     * the channel is unmuted.
248     */
249 iliev 2288 @Override
250 iliev 787 public void
251 iliev 1143 setBackendMute(boolean mute) {
252     final SetMute smc = new SetMute(getChannelId(), mute);
253 iliev 787 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 iliev 1143 * Schedules a new task for setting on the backend side the solo mode of the channel.
273 iliev 787 * @param solo Specifies the solo mode. If <code>true</code> the channel is soloed, else
274     * the channel is unsoloed.
275     */
276 iliev 2288 @Override
277 iliev 787 public void
278 iliev 1143 setBackendSolo(boolean solo) {
279     final SetSolo ssc = new SetSolo(getChannelId(), solo);
280 iliev 787 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 iliev 1143 * Schedules a new task for setting the channel volume on the backend side.
300 iliev 787 * @param volume Specifies the new volume value.
301     */
302 iliev 2288 @Override
303 iliev 787 public void
304 iliev 1143 setBackendVolume(float volume) {
305     final SetVolume scv = new SetVolume(getChannelId(), volume);
306 iliev 787 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 iliev 1143 * 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 iliev 787 */
329 iliev 2288 @Override
330 iliev 787 public void
331 iliev 1143 setBackendMidiInputDevice(int deviceId) {
332     final Task scmid = new SetMidiInputDevice(getChannelId(), deviceId);
333 iliev 787 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 iliev 1143 * Schedules a new task for setting (on the backend side) the
353     * MIDI input port of the channel represented by this model.
354 iliev 787 * @param port Specifies the number of the MIDI input port.
355     */
356 iliev 2288 @Override
357 iliev 787 public void
358 iliev 1143 setBackendMidiInputPort(int port) {
359     final Task scmip = new SetMidiInputPort(getChannelId(), port);
360 iliev 787 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 iliev 1143 * 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 iliev 787 * @param channel Specifies the MIDI channel that the channel
382     * represented by this model should listen to.
383     */
384 iliev 2288 @Override
385 iliev 787 public void
386 iliev 1143 setBackendMidiInputChannel(int channel) {
387     final Task scmic = new SetMidiInputChannel(getChannelId(), channel);
388 iliev 787 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 iliev 1143 * 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 iliev 787 */
411 iliev 2288 @Override
412 iliev 787 public void
413 iliev 1143 setBackendAudioOutputDevice(int deviceId) {
414     final Task scaod = new Channel.SetAudioOutputDevice(getChannelId(), deviceId);
415 iliev 787 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 iliev 1143 * 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 iliev 2288 @Override
441 iliev 1143 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 iliev 2302 * map that should be assigned to this sampler channel.
466     * To remove the current map binding use <code>-1</code>.
467     * To set the current map to be the default map use <code>-2</code>.
468 iliev 1143 */
469 iliev 2288 @Override
470 iliev 1143 public void
471     setBackendMidiInstrumentMap(int mapId) {
472     final Task t = new Channel.SetMidiInstrumentMap(getChannelId(), mapId);
473     final SamplerChannelEvent event = new SamplerChannelEvent(this);
474    
475     t.addTaskListener(new TaskListener() {
476     public void
477     taskPerformed(TaskEvent e) {
478     /*
479     * Because with the invokation of the method the task is considered
480     * to be done, if the task fails, we must notify for a channel
481     * changes. This should be done to revert the old channel settings.
482     */
483     if(t.doneWithErrors()) fireSamplerChannelChanged(event);
484     }
485     });
486     CC.getTaskQueue().add(t);
487     }
488    
489     /**
490     * Schedules a new task for loading and assigning the specified instrument
491 iliev 787 * to the sampler channel represented by this model.
492     * @param filename The file name of the instrument to be loaded.
493     * @param InstrIndex The index of the instrument in the instrument file to be loaded.
494     */
495 iliev 2288 @Override
496 iliev 787 public void
497 iliev 1143 loadBackendInstrument(String filename, int InstrIndex) {
498     final Task li = new LoadInstrument(filename, InstrIndex, getChannelId());
499 iliev 787 CC.getTaskQueue().add(li);
500    
501     // We leave this event to be notified by the LinuxSampler notification system.
502     }
503    
504 iliev 1143 /** Schedules a new task for reseting the channel. */
505 iliev 2288 @Override
506 iliev 911 public void
507 iliev 1143 resetBackendChannel() {
508     CC.getTaskQueue().add(new org.jsampler.task.Channel.Reset(getChannelId()));
509 iliev 911
510     // We leave this event to be notified by the LinuxSampler notification system.
511     }
512    
513 iliev 1143 /** Schedules a new task for duplicating the channel. */
514 iliev 2288 @Override
515 iliev 911 public void
516 iliev 1143 duplicateBackendChannel() {
517 iliev 911 CC.getTaskQueue().add(new DuplicateChannels(getChannelInfo()));
518     }
519    
520 iliev 1143 /**
521     * Schedules a new task for adding a new effect send on the
522     * backend side. The effect send will be actually added to this model
523     * when the backend notifies for its creation.
524     * @param midiCtrl Defines the MIDI controller, which
525     * will be able alter the effect send level.
526     */
527 iliev 2288 @Override
528 iliev 1143 public void
529     addBackendFxSend(int midiCtrl) {
530     CC.getTaskQueue().add(new Channel.AddFxSend(getChannelId(), midiCtrl));
531     // We leave this event to be notified by the LinuxSampler notification system.
532     }
533    
534     /**
535     * Schedules a new task for adding a new effect send on the
536     * backend side. The effect send will be actually added to this model
537     * when the backend notifies for its creation.
538     * @param midiCtrl Defines the MIDI controller, which
539     * will be able alter the effect send level.
540     * @param name The name of the effect send entity.
541     * The name does not have to be unique.
542     */
543 iliev 2288 @Override
544 iliev 1143 public void
545     addBackendFxSend(int midiCtrl, String name) {
546     CC.getTaskQueue().add(new Channel.AddFxSend(getChannelId(), midiCtrl, name));
547     // We leave this event to be notified by the LinuxSampler notification system.
548     }
549    
550     /**
551     * Adds the specified effect send.
552     * @param fxSend The effect send to be added.
553     */
554 iliev 2288 @Override
555 iliev 1143 public void
556     addFxSend(FxSend fxSend) {
557     fxSends.add(fxSend);
558     fireFxSendAdded(fxSend);
559     }
560    
561     /**
562     * Schedules a new task for removing the specified effect send on the backend side.
563     * @param fxSendId The ID of the effect send to remove.
564     */
565 iliev 2288 @Override
566 iliev 1143 public void
567     removeBackendFxSend(int fxSendId) {
568     CC.getTaskQueue().add(new Channel.RemoveFxSend(getChannelId(), fxSendId));
569     }
570    
571     /**
572     * Gets the effect send at the specified position.
573     * @param index The index of the effect send to be returned.
574     * @return The effect send at the specified position.
575     */
576 iliev 2288 @Override
577 iliev 1143 public FxSend
578     getFxSend(int index) { return fxSends.get(index); }
579    
580     /**
581     * Gets the effect send with the specified ID.
582     * @param fxSendId The ID of the effect send to return.
583     * @return The effect send with the specified ID or <code>null</code>
584     * if there is no effect send with ID <code>fxSendId</code>.
585     */
586 iliev 2288 @Override
587 iliev 1143 public FxSend
588     getFxSendById(int fxSendId) {
589     for(FxSend fxs : fxSends) {
590     if(fxs.getFxSendId() == fxSendId) return fxs;
591     }
592    
593     return null;
594     }
595    
596     /**
597     * Removes the effect send at the specified position.
598     * @param index The position of the effect send to remove.
599     * @return The removed effect send.
600     */
601 iliev 2288 @Override
602 iliev 1143 public FxSend
603     removeFxSend(int index) {
604     FxSend fxs = fxSends.remove(index);
605     fireFxSendRemoved(fxs);
606     return fxs;
607     }
608    
609     /**
610     * Removes the specified effect send.
611     * @param fxSendId The ID of the effect send to remove.
612     * @return <code>true</code> if the effect send is removed successfully, <code>false</code>
613     * if the channel does not contain effect send with ID <code>fxSendId</code>.
614     */
615 iliev 2288 @Override
616 iliev 1143 public boolean
617     removeFxSendById(int fxSendId) {
618     for(int i = 0; i < fxSends.size(); i++) {
619     FxSend fxs = fxSends.get(i);
620     if(fxs.getFxSendId() == fxSendId) {
621     fxSends.remove(i);
622     fireFxSendRemoved(fxs);
623     return true;
624     }
625     }
626    
627     return false;
628     }
629    
630     /** Removes all effect sends from this channel. */
631 iliev 2288 @Override
632 iliev 1143 public void
633     removeAllFxSends() {
634     for(int i = fxSends.size() - 1; i >= 0; i--) {
635     FxSend fxs = fxSends.get(i);
636     fxSends.removeElementAt(i);
637     fireFxSendRemoved(fxs);
638     }
639     }
640    
641     /**
642     * Updates the specified effect send.
643     * @param fxSend The effect send to update.
644     */
645 iliev 2288 @Override
646 iliev 1143 public void
647     updateFxSend(FxSend fxSend) {
648     for(int i = 0; i < fxSends.size(); i++) {
649     FxSend fxs = fxSends.get(i);
650     if(fxs.getFxSendId() == fxSend.getFxSendId()) {
651     fxSends.setElementAt(fxSend, i);
652     fireFxSendUpdated(fxSend);
653     return;
654     }
655     }
656     }
657    
658     /**
659     * Gets the current number of effect sends.
660     * @return The current number of effect sends.
661     */
662 iliev 2288 @Override
663 iliev 1143 public int
664     getFxSendCount() { return fxSends.size(); }
665    
666     /**
667     * Gets the current list of effect sends.
668     * @return The current list of effect sends.
669     */
670 iliev 2288 @Override
671 iliev 1143 public FxSend[]
672     getFxSends() { return fxSends.toArray(new FxSend[fxSends.size()]); }
673    
674     /**
675     * Sets the name of the specified effect send.
676     * @param fxSend The numerical ID of the effect send.
677     * @param name The new name of the effect send entity.
678     */
679 iliev 2288 @Override
680 iliev 1143 public void
681     setBackendFxSendName(final int fxSend, String name) {
682     final Task t = new Channel.SetFxSendName(getChannelId(), fxSend, name);
683     t.addTaskListener(new TaskListener() {
684     public void
685     taskPerformed(TaskEvent e) {
686     /*
687     * Because with the invokation of the method the task is considered
688     * to be done, if the task fails, we must update the settings.
689     */
690     if(t.doneWithErrors()) {
691     int id = getChannelId();
692     CC.getTaskQueue().add(new UpdateFxSendInfo(id, fxSend));
693     }
694     }
695     });
696     CC.getTaskQueue().add(t);
697     }
698    
699     /**
700     * Sets the destination of an effect send's audio channel.
701     * @param fxSend The numerical ID of the effect send entity to be rerouted.
702     * @param audioSrc The numerical ID of the effect send's audio output channel,
703     * which should be rerouted.
704     * @param audioDst The audio channel of the selected audio output device
705     * where <code>audioSrc</code> should be routed to.
706     */
707 iliev 2288 @Override
708 iliev 1143 public void
709     setBackendFxSendAudioOutputChannel(int fxSend, int audioSrc, int audioDst) {
710     Task t = new Channel.SetFxSendAudioOutputChannel (
711     getChannelId(), fxSend, audioSrc, audioDst
712     );
713    
714     CC.getTaskQueue().add(t);
715     }
716    
717     /**
718     * Sets the MIDI controller of the specified effect send.
719     * @param fxSend The numerical ID of the effect send.
720     * @param midiCtrl The MIDI controller which shall be
721     * able to modify the effect send's send level.
722     */
723 iliev 2288 @Override
724 iliev 1143 public void
725     setBackendFxSendMidiController(int fxSend, int midiCtrl) {
726     Task t = new Channel.SetFxSendMidiController(getChannelId(), fxSend, midiCtrl);
727     CC.getTaskQueue().add(t);
728     }
729    
730     /**
731     * Sets the volume of the specified effect send.
732     * @param fxSend The numerical ID of the effect
733     * send, which volume should be changed.
734     * @param level The new volume value.
735     */
736 iliev 2288 @Override
737 iliev 1143 public void
738     setBackendFxSendLevel(int fxSend, float level) {
739     CC.getTaskQueue().add(new Channel.SetFxSendLevel(getChannelId(), fxSend, level));
740     }
741    
742 iliev 1776 /**
743     * Sends a MIDI data message to this sampler channel.
744     */
745 iliev 2288 @Override
746 iliev 1776 public void
747     sendBackendMidiData(MidiDataEvent e) {
748     sendBackendMidiData(e.getType(), e.getNote(), e.getVelocity());
749     }
750    
751     /**
752     * Sends a MIDI data message to this sampler channel.
753     * @param type The type of MIDI message to send.
754     * @param arg1 Depends on the message type.
755     * @param arg2 Depends on the message type.
756     */
757 iliev 2288 @Override
758 iliev 1776 public void
759     sendBackendMidiData(MidiDataEvent.Type type, int arg1, int arg2) {
760     CC.getTaskQueue().add(new Channel.SendMidiMsg(getChannelId(), type, arg1, arg2));
761     }
762    
763 iliev 2200 /**
764     * Sets destination effect on the specified effect send.
765     * @param fxSend The numerical ID of the effect send.
766     */
767 iliev 2288 @Override
768 iliev 2200 public void
769     setBackendFxSendEffect(int fxSend, int chainId, int chainPos) {
770     CC.getTaskQueue().add (
771     new Channel.SetFxSendEffect(getChannelId(), fxSend, chainId, chainPos)
772     );
773     }
774    
775     /**
776     * Removes the destination effect of the specified effect send.
777     * @param fxSend The numerical ID of the effect send.
778     */
779 iliev 2288 @Override
780 iliev 2200 public void
781     removeBackendFxSendEffect(int fxSend) {
782     CC.getTaskQueue().add (
783     new Channel.SetFxSendEffect(getChannelId(), fxSend, -1, -1)
784     );
785     }
786    
787 iliev 787 /** Notifies listeners that the sampler channel settings has changed. */
788     protected void
789     fireSamplerChannelChanged() {
790     final SamplerChannelEvent e = new SamplerChannelEvent(this);
791    
792 iliev 2288 PDUtils.runOnUiThread(new Runnable() {
793 iliev 787 public void
794     run() { fireSamplerChannelChanged(e); }
795     });
796     }
797    
798     /**
799     * Notifies listeners that the sampler channel settings has changed.
800 iliev 2288 * This method should be invoked from the UI thread.
801 iliev 787 */
802     protected void
803     fireSamplerChannelChanged(SamplerChannelEvent e) {
804 iliev 1567 CC.getSamplerModel().setModified(true);
805 iliev 787 for(SamplerChannelListener l : listeners) l.channelChanged(e);
806     }
807    
808     /** Notifies listeners that the number of active disk streams has changed. */
809     protected void
810     fireStreamCountChanged() {
811     final SamplerChannelEvent e = new SamplerChannelEvent(this);
812    
813 iliev 2288 PDUtils.runOnUiThread(new Runnable() {
814 iliev 787 public void
815     run() { fireStreamCountChanged(e); }
816     });
817     }
818    
819     /**
820     * Notifies listeners that the number of active disk streams has changed.
821 iliev 2288 * This method should be invoked from the UI thread.
822 iliev 787 */
823     protected void
824     fireStreamCountChanged(SamplerChannelEvent e) {
825     for(SamplerChannelListener l : listeners) l.streamCountChanged(e);
826     }
827    
828     /** Notifies listeners that the number of active voices has changed. */
829     protected void
830     fireVoiceCountChanged() {
831     final SamplerChannelEvent e = new SamplerChannelEvent(this);
832    
833 iliev 2288 PDUtils.runOnUiThread(new Runnable() {
834 iliev 787 public void
835     run() { fireVoiceCountChanged(e); }
836     });
837     }
838    
839     /**
840     * Notifies listeners that the number of active voices has changed.
841 iliev 2288 * This method should be invoked from the UI thread.
842 iliev 787 */
843     protected void
844     fireVoiceCountChanged(SamplerChannelEvent e) {
845     for(SamplerChannelListener l : listeners) l.voiceCountChanged(e);
846     }
847 iliev 1143
848     /**
849     * Notifies listeners that the specified effect send has been added to the channel.
850     */
851     protected void
852     fireFxSendAdded(FxSend fxSend) {
853     final EffectSendsEvent e = new EffectSendsEvent(this, fxSend);
854    
855 iliev 2288 PDUtils.runOnUiThread(new Runnable() {
856 iliev 1143 public void
857     run() { fireFxSendAdded(e); }
858     });
859     }
860    
861     /**
862     * Notifies listeners that the specified effect send has been added to the channel.
863 iliev 2288 * This method should be invoked from the UI thread.
864 iliev 1143 */
865     protected void
866     fireFxSendAdded(EffectSendsEvent e) {
867 iliev 1567 CC.getSamplerModel().setModified(true);
868 iliev 1143 for(EffectSendsListener l : fxListeners) l.effectSendAdded(e);
869     }
870    
871     /** Notifies listeners that the specified effect send has been removed. */
872     protected void
873     fireFxSendRemoved(FxSend fxSend) {
874     final EffectSendsEvent e = new EffectSendsEvent(this, fxSend);
875    
876 iliev 2288 PDUtils.runOnUiThread(new Runnable() {
877 iliev 1143 public void
878     run() { fireFxSendRemoved(e); }
879     });
880     }
881    
882     /**
883     * Notifies listeners that the specified effect send has been removed.
884 iliev 2288 * This method should be invoked from the UI thread.
885 iliev 1143 */
886     protected void
887     fireFxSendRemoved(EffectSendsEvent e) {
888 iliev 1567 CC.getSamplerModel().setModified(true);
889 iliev 1143 for(EffectSendsListener l : fxListeners) l.effectSendRemoved(e);
890     }
891    
892     /** Notifies listeners that the specified effect send has been updated. */
893     protected void
894     fireFxSendUpdated(FxSend fxSend) {
895     final EffectSendsEvent e = new EffectSendsEvent(this, fxSend);
896    
897 iliev 2288 PDUtils.runOnUiThread(new Runnable() {
898 iliev 1143 public void
899     run() { fireFxSendUpdated(e); }
900     });
901     }
902    
903     /**
904     * Notifies listeners that the specified effect send has been updated.
905 iliev 2288 * This method should be invoked from the UI thread.
906 iliev 1143 */
907     protected void
908     fireFxSendUpdated(EffectSendsEvent e) {
909 iliev 1567 CC.getSamplerModel().setModified(true);
910 iliev 1143 for(EffectSendsListener l : fxListeners) l.effectSendChanged(e);
911     }
912 iliev 1776
913     /**
914     * Notifies listeners that the specified effect send has been updated.
915     * This method should be invoked from the event-dispatching thread.
916     */
917     protected void
918     fireMidiDataEvent(MidiDataEvent e) {
919     for(MidiDataListener l : midiListeners) l.midiDataArrived(e);
920     }
921 iliev 787 }

  ViewVC Help
Powered by ViewVC