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