1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1143 |
* Copyright (C) 2005-2007 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 java.util.logging.Level; |
28 |
|
|
|
29 |
|
|
import javax.swing.SwingUtilities; |
30 |
|
|
|
31 |
|
|
import javax.swing.event.EventListenerList; |
32 |
|
|
|
33 |
iliev |
1143 |
import net.sf.juife.Task; |
34 |
|
|
import net.sf.juife.event.TaskEvent; |
35 |
|
|
import net.sf.juife.event.TaskListener; |
36 |
|
|
|
37 |
|
|
import org.jsampler.event.ListEvent; |
38 |
|
|
import org.jsampler.event.ListListener; |
39 |
iliev |
787 |
import org.jsampler.event.MidiDeviceListEvent; |
40 |
|
|
import org.jsampler.event.MidiDeviceListListener; |
41 |
|
|
import org.jsampler.event.SamplerChannelListEvent; |
42 |
|
|
import org.jsampler.event.SamplerChannelListListener; |
43 |
|
|
import org.jsampler.event.SamplerEvent; |
44 |
|
|
import org.jsampler.event.SamplerListener; |
45 |
|
|
|
46 |
iliev |
1143 |
import org.jsampler.task.Audio; |
47 |
|
|
import org.jsampler.task.Channel; |
48 |
|
|
import org.jsampler.task.Global; |
49 |
|
|
import org.jsampler.task.Midi; |
50 |
iliev |
787 |
|
51 |
|
|
import org.linuxsampler.lscp.*; |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/** |
55 |
iliev |
911 |
* This class provides default implementation of the <code>SamplerModel</code> interface. |
56 |
iliev |
1143 |
* Note that the setter methods of this class does <b>not</b> alter any settings |
57 |
|
|
* on the backend side unless otherwise specified. |
58 |
iliev |
787 |
* @author Grigor Iliev |
59 |
|
|
*/ |
60 |
|
|
public class DefaultSamplerModel implements SamplerModel { |
61 |
|
|
private ServerInfo serverInfo = null; |
62 |
|
|
private AudioOutputDriver[] aoDrvS = null; |
63 |
|
|
private MidiInputDriver[] miDrvS = null; |
64 |
|
|
private SamplerEngine[] engines = null; |
65 |
|
|
|
66 |
iliev |
1545 |
private int totalStreamCount = 0; |
67 |
iliev |
787 |
private int totalVoiceCount = 0; |
68 |
|
|
private int totalVoiceCountMax = 0; |
69 |
|
|
|
70 |
iliev |
1143 |
private float volume = 1; |
71 |
|
|
private MidiInstrumentMap defaultMidiInstrumentMap; |
72 |
|
|
|
73 |
iliev |
787 |
private final Vector<SamplerChannelModel> channelModels = new Vector<SamplerChannelModel>(); |
74 |
|
|
private final Vector<AudioDeviceModel> audioDeviceModels = new Vector<AudioDeviceModel>(); |
75 |
|
|
private final Vector<MidiDeviceModel> midiDeviceModels = new Vector<MidiDeviceModel>(); |
76 |
iliev |
1143 |
private final Vector<MidiInstrumentMap> midiInstrMaps = new Vector<MidiInstrumentMap>(); |
77 |
iliev |
787 |
|
78 |
|
|
private final Vector<SamplerListener> listeners = new Vector<SamplerListener>(); |
79 |
iliev |
1143 |
private final Vector<ListListener<MidiInstrumentMap>> mapsListeners = |
80 |
|
|
new Vector<ListListener<MidiInstrumentMap>>(); |
81 |
|
|
|
82 |
iliev |
787 |
private final EventListenerList listenerList = new EventListenerList(); |
83 |
|
|
|
84 |
iliev |
1567 |
private boolean modified = false; |
85 |
iliev |
787 |
|
86 |
iliev |
1567 |
|
87 |
iliev |
787 |
/** Creates a new instance of DefaultSamplerModel */ |
88 |
|
|
public |
89 |
|
|
DefaultSamplerModel() { |
90 |
iliev |
1143 |
addMidiInstrumentMapListListener(getHandler()); |
91 |
iliev |
787 |
} |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* Registers the specified listener for receiving event messages. |
95 |
|
|
* @param l The <code>SamplerListener</code> to register. |
96 |
|
|
*/ |
97 |
|
|
public void |
98 |
|
|
addSamplerListener(SamplerListener l) { listeners.add(l); } |
99 |
|
|
|
100 |
|
|
/** |
101 |
|
|
* Removes the specified listener. |
102 |
|
|
* @param l The <code>SamplerListener</code> to remove. |
103 |
|
|
*/ |
104 |
|
|
public void |
105 |
|
|
removeSamplerListener(SamplerListener l) { listeners.remove(l); } |
106 |
|
|
|
107 |
|
|
/** |
108 |
|
|
* Registers the specified listener for receiving event messages. |
109 |
|
|
* @param listener The <code>AudioDeviceListListener</code> to register. |
110 |
|
|
*/ |
111 |
|
|
public void |
112 |
iliev |
1143 |
addAudioDeviceListListener(ListListener<AudioDeviceModel> listener) { |
113 |
|
|
listenerList.add(ListListener.class, listener); |
114 |
iliev |
787 |
} |
115 |
|
|
|
116 |
|
|
/** |
117 |
|
|
* Removes the specified listener. |
118 |
|
|
* @param listener The <code>AudioDeviceListListener</code> to remove. |
119 |
|
|
*/ |
120 |
|
|
public void |
121 |
iliev |
1143 |
removeAudioDeviceListListener(ListListener<AudioDeviceModel> listener) { |
122 |
|
|
listenerList.remove(ListListener.class, listener); |
123 |
iliev |
787 |
} |
124 |
|
|
|
125 |
|
|
/** |
126 |
|
|
* Registers the specified listener for receiving event messages. |
127 |
|
|
* @param listener The <code>MidiDeviceListListener</code> to register. |
128 |
|
|
*/ |
129 |
|
|
public void |
130 |
|
|
addMidiDeviceListListener(MidiDeviceListListener listener) { |
131 |
|
|
listenerList.add(MidiDeviceListListener.class, listener); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
/** |
135 |
|
|
* Removes the specified listener. |
136 |
|
|
* @param listener The <code>MidiDeviceListListener</code> to remove. |
137 |
|
|
*/ |
138 |
|
|
public void |
139 |
|
|
removeMidiDeviceListListener(MidiDeviceListListener listener) { |
140 |
|
|
listenerList.remove(MidiDeviceListListener.class, listener); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
/** |
144 |
|
|
* Registers the specified listener for receiving event messages. |
145 |
iliev |
1143 |
* @param listener The <code>ListListener</code> to register. |
146 |
|
|
*/ |
147 |
|
|
public void |
148 |
|
|
addMidiInstrumentMapListListener(ListListener<MidiInstrumentMap> listener) { |
149 |
|
|
mapsListeners.add(listener); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
/** |
153 |
|
|
* Removes the specified listener. |
154 |
|
|
* @param listener The <code>ListListener</code> to remove. |
155 |
|
|
*/ |
156 |
|
|
public void |
157 |
|
|
removeMidiInstrumentMapListListener(ListListener<MidiInstrumentMap> listener) { |
158 |
|
|
mapsListeners.remove(listener); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
/** |
162 |
|
|
* Registers the specified listener for receiving event messages. |
163 |
iliev |
787 |
* @param listener The <code>SamplerChannelListListener</code> to register. |
164 |
|
|
*/ |
165 |
|
|
public void |
166 |
|
|
addSamplerChannelListListener(SamplerChannelListListener listener) { |
167 |
|
|
listenerList.add(SamplerChannelListListener.class, listener); |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
/** |
171 |
|
|
* Removes the specified listener. |
172 |
|
|
* @param listener The <code>SamplerChannelListListener</code> to remove. |
173 |
|
|
*/ |
174 |
|
|
public void |
175 |
|
|
removeSamplerChannelListListener(SamplerChannelListListener listener) { |
176 |
|
|
listenerList.remove(SamplerChannelListListener.class, listener); |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
/** |
180 |
|
|
* Gets information about the LinuxSampler instance the front-end is connected to. |
181 |
|
|
* |
182 |
|
|
* @return <code>ServerInfo</code> instance containing |
183 |
|
|
* information about the LinuxSampler instance the front-end is connected to. |
184 |
|
|
*/ |
185 |
|
|
public ServerInfo |
186 |
|
|
getServerInfo() { return serverInfo; } |
187 |
|
|
|
188 |
|
|
/** |
189 |
|
|
* Sets information about the LinuxSampler instance the front-end is connected to. |
190 |
|
|
* |
191 |
|
|
* @param serverInfo <code>ServerInfo</code> instance containing |
192 |
|
|
* information about the LinuxSampler instance the front-end is connected to. |
193 |
|
|
*/ |
194 |
|
|
public void |
195 |
|
|
setServerInfo(ServerInfo serverInfo) { this.serverInfo = serverInfo; } |
196 |
|
|
|
197 |
|
|
/** |
198 |
|
|
* Gets all audio output drivers currently available for the LinuxSampler instance. |
199 |
|
|
* |
200 |
|
|
* @return <code>AudioOutputDriver</code> array containing all audio output drivers |
201 |
|
|
* currently available for the LinuxSampler instance. |
202 |
|
|
*/ |
203 |
|
|
public AudioOutputDriver[] |
204 |
|
|
getAudioOutputDrivers() { return aoDrvS; } |
205 |
|
|
|
206 |
|
|
/** |
207 |
|
|
* Sets the currently available audio output drivers for the LinuxSampler instance. |
208 |
|
|
* |
209 |
|
|
* @param drivers <code>AudioOutputDriver</code> array containing all audio output drivers |
210 |
|
|
* currently available for the LinuxSampler instance. |
211 |
|
|
*/ |
212 |
|
|
public void |
213 |
|
|
setAudioOutputDrivers(AudioOutputDriver[] drivers) { aoDrvS = drivers; } |
214 |
|
|
|
215 |
|
|
/** |
216 |
iliev |
1467 |
* Gets the model of the audio device at the specified position. |
217 |
|
|
* @param index The position of the audio device to return. |
218 |
|
|
* @return The model of the audio device at the specified position. |
219 |
|
|
* @see #getAudioDeviceCount |
220 |
|
|
*/ |
221 |
|
|
public AudioDeviceModel |
222 |
|
|
getAudioDevice(int index) { |
223 |
|
|
return audioDeviceModels.get(index); |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
/** |
227 |
iliev |
1143 |
* Gets the model of the audio device with ID <code>deviceId</code>. |
228 |
|
|
* @param deviceId The ID of the audio device whose model should be obtained. |
229 |
iliev |
787 |
* @return The model of the specified audio device or <code>null</code> |
230 |
iliev |
1143 |
* if there is no audio device with ID <code>deviceId</code>. |
231 |
iliev |
787 |
*/ |
232 |
|
|
public AudioDeviceModel |
233 |
iliev |
1204 |
getAudioDeviceById(int deviceId) { |
234 |
iliev |
787 |
for(AudioDeviceModel m : audioDeviceModels) |
235 |
iliev |
1143 |
if(m.getDeviceId() == deviceId) return m; |
236 |
iliev |
787 |
|
237 |
|
|
return null; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
/** |
241 |
|
|
* Gets the current number of audio devices. |
242 |
|
|
* @return The current number of audio devices. |
243 |
|
|
*/ |
244 |
|
|
public int |
245 |
|
|
getAudioDeviceCount() { return audioDeviceModels.size(); } |
246 |
|
|
|
247 |
|
|
/** |
248 |
|
|
* Gets the current list of audio device models. |
249 |
|
|
* @return The current list of audio device models. |
250 |
|
|
*/ |
251 |
|
|
public AudioDeviceModel[] |
252 |
iliev |
1204 |
getAudioDevices() { |
253 |
iliev |
787 |
return audioDeviceModels.toArray(new AudioDeviceModel[audioDeviceModels.size()]); |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
/** |
257 |
|
|
* Adds the specified audio device. |
258 |
|
|
* @param device The audio device to be added. |
259 |
|
|
*/ |
260 |
|
|
public void |
261 |
|
|
addAudioDevice(AudioOutputDevice device) { |
262 |
|
|
DefaultAudioDeviceModel model = new DefaultAudioDeviceModel(device); |
263 |
|
|
audioDeviceModels.add(model); |
264 |
|
|
fireAudioDeviceAdded(model); |
265 |
|
|
} |
266 |
|
|
|
267 |
|
|
/** |
268 |
|
|
* Removes the specified audio device. |
269 |
iliev |
1143 |
* @param deviceId The ID of the audio device to be removed. |
270 |
iliev |
787 |
* @return <code>true</code> if the audio device is removed successfully, <code>false</code> |
271 |
iliev |
1143 |
* if the device list does not contain audio device with ID <code>deviceId</code>. |
272 |
iliev |
787 |
*/ |
273 |
|
|
public boolean |
274 |
iliev |
1204 |
removeAudioDeviceById(int deviceId) { |
275 |
iliev |
787 |
for(int i = 0; i < audioDeviceModels.size(); i++) { |
276 |
|
|
AudioDeviceModel m = audioDeviceModels.get(i); |
277 |
iliev |
1143 |
if(m.getDeviceId() == deviceId) { |
278 |
iliev |
787 |
audioDeviceModels.remove(i); |
279 |
|
|
fireAudioDeviceRemoved(m); |
280 |
|
|
return true; |
281 |
|
|
} |
282 |
|
|
} |
283 |
|
|
|
284 |
|
|
return false; |
285 |
|
|
} |
286 |
|
|
|
287 |
|
|
/** |
288 |
iliev |
1143 |
* Schedules a new task for removing the specified audio device on the backend side. |
289 |
|
|
* @param deviceId The ID of the audio device to be removed. |
290 |
|
|
*/ |
291 |
|
|
public void |
292 |
|
|
removeBackendAudioDevice(int deviceId) { |
293 |
|
|
CC.getTaskQueue().add(new Audio.DestroyDevice(deviceId)); |
294 |
|
|
} |
295 |
|
|
|
296 |
|
|
/** |
297 |
iliev |
787 |
* Gets all MIDI input drivers currently available for the LinuxSampler instance. |
298 |
|
|
* |
299 |
|
|
* @return <code>MidiInputDriver</code> array containing all MIDI input drivers currently |
300 |
|
|
* available for the LinuxSampler instance. |
301 |
|
|
*/ |
302 |
|
|
public MidiInputDriver[] |
303 |
|
|
getMidiInputDrivers() { return miDrvS; } |
304 |
|
|
|
305 |
|
|
/** |
306 |
|
|
* Sets the currently available MIDI input drivers for the LinuxSampler instance. |
307 |
|
|
* |
308 |
|
|
* @param drivers <code>MidiInputDriver</code> array containing all MIDI input drivers |
309 |
|
|
* currently available for the LinuxSampler instance. |
310 |
|
|
*/ |
311 |
|
|
public void |
312 |
|
|
setMidiInputDrivers(MidiInputDriver[] drivers) { miDrvS = drivers; } |
313 |
|
|
|
314 |
|
|
/** |
315 |
iliev |
1467 |
* Gets the model of the MIDI device at the specified position. |
316 |
|
|
* @param index The position of the MIDI device to return. |
317 |
|
|
* @return The model of the MIDI device at the specified position. |
318 |
|
|
*/ |
319 |
|
|
public MidiDeviceModel |
320 |
|
|
getMidiDevice(int index) { |
321 |
|
|
return midiDeviceModels.get(index); |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
/** |
325 |
iliev |
1143 |
* Gets the model of the MIDI device with ID <code>deviceId</code>. |
326 |
|
|
* @param deviceId The ID of the MIDI device whose model should be obtained. |
327 |
iliev |
787 |
* @return The model of the specified MIDI device or <code>null</code> |
328 |
iliev |
1143 |
* if there is no MIDI device with ID <code>deviceId</code>. |
329 |
iliev |
787 |
*/ |
330 |
|
|
public MidiDeviceModel |
331 |
iliev |
1204 |
getMidiDeviceById(int deviceId) { |
332 |
iliev |
787 |
for(MidiDeviceModel m : midiDeviceModels) |
333 |
iliev |
1143 |
if(m.getDeviceId() == deviceId) return m; |
334 |
iliev |
787 |
|
335 |
|
|
return null; |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
/** |
339 |
|
|
* Gets the current number of MIDI input devices. |
340 |
|
|
* @return The current number of MIDI input devices. |
341 |
|
|
*/ |
342 |
|
|
public int |
343 |
|
|
getMidiDeviceCount() { return midiDeviceModels.size(); } |
344 |
|
|
|
345 |
|
|
/** |
346 |
|
|
* Gets the current list of MIDI device models. |
347 |
|
|
* @return The current list of MIDI device models. |
348 |
|
|
*/ |
349 |
|
|
public MidiDeviceModel[] |
350 |
iliev |
1204 |
getMidiDevices() { |
351 |
iliev |
787 |
return midiDeviceModels.toArray(new MidiDeviceModel[midiDeviceModels.size()]); |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
/** |
355 |
|
|
* Adds the specified MIDI device. |
356 |
|
|
* @param device The MIDI device to be added. |
357 |
|
|
*/ |
358 |
|
|
public void |
359 |
|
|
addMidiDevice(MidiInputDevice device) { |
360 |
|
|
DefaultMidiDeviceModel model = new DefaultMidiDeviceModel(device); |
361 |
|
|
midiDeviceModels.add(model); |
362 |
|
|
fireMidiDeviceAdded(model); |
363 |
|
|
} |
364 |
|
|
|
365 |
|
|
/** |
366 |
iliev |
1143 |
* Schedules a new task for adding new MIDI device. |
367 |
|
|
* @param driver The desired MIDI input system. |
368 |
|
|
* @param parameters An optional list of driver specific parameters. |
369 |
|
|
*/ |
370 |
|
|
public void |
371 |
|
|
addBackendMidiDevice(String driver, Parameter... parameters) { |
372 |
|
|
CC.getTaskQueue().add(new Midi.CreateDevice(driver, parameters)); |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
/** |
376 |
iliev |
787 |
* Removes the specified MIDI device. |
377 |
iliev |
1143 |
* @param deviceId The ID of the MIDI device to be removed. |
378 |
iliev |
787 |
* @return <code>true</code> if the MIDI device is removed successfully, <code>false</code> |
379 |
iliev |
1143 |
* if the device list does not contain MIDI device with ID <code>deviceId</code>. |
380 |
iliev |
787 |
*/ |
381 |
|
|
public boolean |
382 |
iliev |
1204 |
removeMidiDeviceById(int deviceId) { |
383 |
iliev |
787 |
for(int i = 0; i < midiDeviceModels.size(); i++) { |
384 |
|
|
MidiDeviceModel m = midiDeviceModels.get(i); |
385 |
iliev |
1143 |
if(m.getDeviceId() == deviceId) { |
386 |
iliev |
787 |
midiDeviceModels.remove(i); |
387 |
|
|
fireMidiDeviceRemoved(m); |
388 |
|
|
return true; |
389 |
|
|
} |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
return false; |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
/** |
396 |
iliev |
1143 |
* Schedules a new task for removing the specified MIDI device. |
397 |
|
|
* @param deviceId The ID of the MIDI input device to be destroyed. |
398 |
|
|
*/ |
399 |
|
|
public void |
400 |
|
|
removeBackendMidiDevice(int deviceId) { |
401 |
|
|
CC.getTaskQueue().add(new Midi.DestroyDevice(deviceId)); |
402 |
|
|
} |
403 |
|
|
|
404 |
|
|
/** |
405 |
|
|
* Gets the MIDI instrument map with ID <code>mapId</code>. |
406 |
|
|
* @param mapId The ID of the MIDI instrument map to obtain. |
407 |
|
|
* @return The MIDI instrument map with the specified ID or <code>null</code> |
408 |
|
|
* if there is no MIDI instrument map with ID <code>mapId</code>. |
409 |
|
|
*/ |
410 |
|
|
public MidiInstrumentMap |
411 |
|
|
getMidiInstrumentMapById(int mapId) { |
412 |
|
|
for(MidiInstrumentMap m : midiInstrMaps) |
413 |
|
|
if(m.getMapId() == mapId) return m; |
414 |
|
|
|
415 |
|
|
return null; |
416 |
|
|
} |
417 |
|
|
|
418 |
|
|
/** |
419 |
|
|
* Gets the MIDI instrument map at the specified position. |
420 |
|
|
* @param index The position of the MIDI instrument map to return. |
421 |
|
|
* @return The MIDI instrument map at the specified position. |
422 |
|
|
*/ |
423 |
|
|
public MidiInstrumentMap |
424 |
|
|
getMidiInstrumentMap(int index) { |
425 |
|
|
return midiInstrMaps.get(index); |
426 |
|
|
} |
427 |
|
|
|
428 |
|
|
/** |
429 |
|
|
* Gets the current number of MIDI instrument maps. |
430 |
|
|
* @return The current number of MIDI instrument maps. |
431 |
|
|
*/ |
432 |
|
|
public int |
433 |
|
|
getMidiInstrumentMapCount() { return midiInstrMaps.size(); } |
434 |
|
|
|
435 |
|
|
/** |
436 |
|
|
* Gets the current list of MIDI instrument maps. |
437 |
|
|
* @return The current list of MIDI instrument maps. |
438 |
|
|
*/ |
439 |
|
|
public MidiInstrumentMap[] |
440 |
|
|
getMidiInstrumentMaps() { |
441 |
|
|
return midiInstrMaps.toArray(new MidiInstrumentMap[midiInstrMaps.size()]); |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
/** |
445 |
iliev |
1285 |
* Gets the position of the specified MIDI instrument map in the list. |
446 |
|
|
* @param map The map whose index should be returned. |
447 |
|
|
* @return The position of the specified map in the list, |
448 |
|
|
* or -1 if <code>map</code> is <code>null</code> or |
449 |
|
|
* the map list does not contain the specified map. |
450 |
|
|
*/ |
451 |
|
|
public int |
452 |
|
|
getMidiInstrumentMapIndex(MidiInstrumentMap map) { |
453 |
|
|
if(map == null) return -1; |
454 |
|
|
|
455 |
|
|
for(int i = 0; i < getMidiInstrumentMapCount(); i++) { |
456 |
|
|
if(getMidiInstrumentMap(i) == map) return i; |
457 |
|
|
} |
458 |
|
|
|
459 |
|
|
return -1; |
460 |
|
|
} |
461 |
|
|
|
462 |
|
|
/** |
463 |
iliev |
1143 |
* Adds the specified MIDI instrument map. |
464 |
|
|
* @param map The MIDI instrument map to be added. |
465 |
|
|
* @throws IllegalArgumentException If <code>map</code> is <code>null</code>. |
466 |
|
|
*/ |
467 |
|
|
public void |
468 |
|
|
addMidiInstrumentMap(MidiInstrumentMap map) { |
469 |
|
|
if(map == null) throw new IllegalArgumentException("map should be non-null!"); |
470 |
|
|
|
471 |
|
|
midiInstrMaps.add(map); |
472 |
|
|
fireMidiInstrumentMapAdded(map); |
473 |
|
|
} |
474 |
|
|
|
475 |
|
|
/** |
476 |
|
|
* Schedules a new task for creating a new MIDI instrument map on the backend side. |
477 |
|
|
* @param name The name of the MIDI instrument map. |
478 |
|
|
* @throws IllegalArgumentException If <code>name</code> is <code>null</code>. |
479 |
|
|
*/ |
480 |
|
|
public void |
481 |
|
|
addBackendMidiInstrumentMap(String name) { |
482 |
|
|
if(name == null) throw new IllegalArgumentException("name should be non-null!"); |
483 |
|
|
|
484 |
|
|
CC.getTaskQueue().add(new Midi.AddInstrumentMap(name)); |
485 |
|
|
} |
486 |
|
|
|
487 |
|
|
/** |
488 |
|
|
* Removes the specified MIDI instrument map. |
489 |
|
|
* @param mapId The ID of the MIDI instrument map to be removed. |
490 |
|
|
* @return <code>true</code> if the MIDI instrument map is removed successfully, |
491 |
|
|
* <code>false</code> if the MIDI instrument map's list does not contain |
492 |
|
|
* MIDI instrument map with ID <code>mapId</code>. |
493 |
|
|
*/ |
494 |
|
|
public boolean |
495 |
iliev |
1204 |
removeMidiInstrumentMapById(int mapId) { |
496 |
iliev |
1143 |
for(int i = 0; i < midiInstrMaps.size(); i++) { |
497 |
|
|
MidiInstrumentMap m = getMidiInstrumentMap(i); |
498 |
|
|
if(m.getMapId() == mapId) { |
499 |
|
|
midiInstrMaps.remove(i); |
500 |
|
|
fireMidiInstrumentMapRemoved(m); |
501 |
|
|
return true; |
502 |
|
|
} |
503 |
|
|
} |
504 |
|
|
|
505 |
|
|
return false; |
506 |
|
|
} |
507 |
|
|
|
508 |
|
|
/** |
509 |
|
|
* Removes the specified MIDI instrument map. |
510 |
|
|
* @param map The MIDI instrument map to remove. |
511 |
|
|
* @return <code>true</code> if the specified MIDI instrument map was in the list, |
512 |
|
|
* <code>false</code> otherwise. |
513 |
|
|
*/ |
514 |
|
|
public boolean |
515 |
|
|
removeMidiInstrumentMap(MidiInstrumentMap map) { |
516 |
|
|
boolean b = midiInstrMaps.removeElement(map); |
517 |
|
|
if(b) fireMidiInstrumentMapRemoved(map); |
518 |
|
|
return b; |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
/** Removes all MIDI instrument maps. */ |
522 |
|
|
public void |
523 |
|
|
removeAllMidiInstrumentMaps() { |
524 |
|
|
for(int i = midiInstrMaps.size() - 1; i >= 0; i--) { |
525 |
|
|
MidiInstrumentMap map = midiInstrMaps.get(i); |
526 |
|
|
midiInstrMaps.removeElementAt(i); |
527 |
|
|
fireMidiInstrumentMapRemoved(map); |
528 |
|
|
} |
529 |
|
|
} |
530 |
|
|
|
531 |
|
|
/** |
532 |
|
|
* Schedules a new task for removing the |
533 |
|
|
* specified MIDI instrument map on the backend side. |
534 |
|
|
* @param mapId The numerical ID of the MIDI instrument map to remove. |
535 |
|
|
*/ |
536 |
|
|
public void |
537 |
|
|
removeBackendMidiInstrumentMap(int mapId) { |
538 |
|
|
CC.getTaskQueue().add(new Midi.RemoveInstrumentMap(mapId)); |
539 |
|
|
} |
540 |
|
|
|
541 |
|
|
/** |
542 |
|
|
* Schedules a new task for changing the name of |
543 |
|
|
* the specified MIDI instrument map on the backend side. |
544 |
|
|
* @param mapId The numerical ID of the MIDI instrument map. |
545 |
|
|
* @param name The new name for the specified MIDI instrument map. |
546 |
|
|
*/ |
547 |
|
|
public void |
548 |
|
|
setBackendMidiInstrumentMapName(final int mapId, String name) { |
549 |
|
|
final Task t = new Midi.SetInstrumentMapInfo(mapId, name); |
550 |
|
|
|
551 |
|
|
t.addTaskListener(new TaskListener() { |
552 |
|
|
public void |
553 |
|
|
taskPerformed(TaskEvent e) { |
554 |
|
|
/* |
555 |
|
|
* Because with the invokation of the method the task is considered |
556 |
|
|
* to be done, if the task fails, we must update the settings. |
557 |
|
|
*/ |
558 |
|
|
if(t.doneWithErrors()) { |
559 |
|
|
Task t2 = new Midi.UpdateInstrumentMapInfo(mapId); |
560 |
|
|
CC.getTaskQueue().add(t2); |
561 |
|
|
} |
562 |
|
|
} |
563 |
|
|
}); |
564 |
|
|
CC.getTaskQueue().add(t); |
565 |
|
|
} |
566 |
|
|
|
567 |
|
|
/** |
568 |
|
|
* Gets the default MIDI instrument map. |
569 |
|
|
* @return The default MIDI instrument map or <code>null</code> |
570 |
|
|
* if there are no maps created. |
571 |
|
|
*/ |
572 |
|
|
public MidiInstrumentMap |
573 |
|
|
getDefaultMidiInstrumentMap() { |
574 |
|
|
return defaultMidiInstrumentMap; |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
/** |
578 |
|
|
* Gets the default MIDI instrument map. |
579 |
|
|
* @return The default MIDI instrument map or <code>null</code> |
580 |
|
|
* if there are no maps created. |
581 |
|
|
*/ |
582 |
|
|
private MidiInstrumentMap |
583 |
|
|
findDefaultMidiInstrumentMap() { |
584 |
|
|
for(int i = 0; i < getMidiInstrumentMapCount(); i++) { |
585 |
|
|
MidiInstrumentMap m = getMidiInstrumentMap(i); |
586 |
|
|
if(m.getInfo().isDefault()) return m; |
587 |
|
|
} |
588 |
|
|
|
589 |
|
|
return null; |
590 |
|
|
} |
591 |
|
|
|
592 |
|
|
/** |
593 |
|
|
* Schedules a new task for mapping a MIDI instrument on the backend side. |
594 |
|
|
* @param mapId The id of the MIDI instrument map. |
595 |
|
|
* @param bank The index of the MIDI bank, which shall contain the instrument. |
596 |
|
|
* @param program The MIDI program number of the new instrument. |
597 |
|
|
* @param instrInfo Provides the MIDI instrument settings. |
598 |
|
|
*/ |
599 |
|
|
public void |
600 |
|
|
mapBackendMidiInstrument(int mapId, int bank, int program, MidiInstrumentInfo instrInfo) { |
601 |
|
|
CC.getTaskQueue().add(new Midi.MapInstrument(mapId, bank, program, instrInfo)); |
602 |
|
|
} |
603 |
|
|
|
604 |
|
|
/** |
605 |
|
|
* Schedules a new task for removing a MIDI instrument on the backend side. |
606 |
|
|
* @param mapId The id of the MIDI instrument map containing the instrument to be removed. |
607 |
|
|
* @param bank The index of the MIDI bank containing the instrument to be removed. |
608 |
|
|
* @param program The MIDI program number of the instrument to be removed. |
609 |
|
|
*/ |
610 |
|
|
public void |
611 |
|
|
unmapBackendMidiInstrument(int mapId, int bank, int program) { |
612 |
|
|
CC.getTaskQueue().add(new Midi.UnmapInstrument(mapId, bank, program)); |
613 |
|
|
} |
614 |
|
|
|
615 |
|
|
/** |
616 |
iliev |
787 |
* Gets a list of all available engines. |
617 |
|
|
* @return A list of all available engines. |
618 |
|
|
*/ |
619 |
|
|
public SamplerEngine[] |
620 |
|
|
getEngines() { return engines; } |
621 |
|
|
|
622 |
|
|
/** |
623 |
|
|
* Sets the list of all available engines. |
624 |
|
|
* @param engines The new list of all available engines. |
625 |
|
|
*/ |
626 |
|
|
public void |
627 |
|
|
setEngines(SamplerEngine[] engines) { this.engines = engines; } |
628 |
|
|
|
629 |
|
|
/** |
630 |
iliev |
1467 |
* Gets the model of the sampler channel in the specified position. |
631 |
|
|
* @param index The position of the channel to return. |
632 |
|
|
* @return The model of the specified sampler channel. |
633 |
|
|
* @see #getchannelCount |
634 |
|
|
*/ |
635 |
|
|
public SamplerChannelModel |
636 |
|
|
getChannel(int index) { |
637 |
|
|
return channelModels.get(index); |
638 |
|
|
} |
639 |
|
|
|
640 |
|
|
/** |
641 |
iliev |
1143 |
* Gets the model of the sampler channel with ID <code>channelId</code>. |
642 |
|
|
* @param channelId The ID of the sampler channel whose model should be obtained. |
643 |
iliev |
787 |
* @return The model of the specified sampler channel or <code>null</code> |
644 |
iliev |
1143 |
* if there is no channel with ID <code>channelId</code>. |
645 |
iliev |
787 |
*/ |
646 |
|
|
public SamplerChannelModel |
647 |
iliev |
1204 |
getChannelById(int channelId) { |
648 |
iliev |
787 |
for(SamplerChannelModel m : channelModels) |
649 |
iliev |
1143 |
if(m.getChannelId() == channelId) return m; |
650 |
iliev |
787 |
|
651 |
|
|
return null; |
652 |
|
|
} |
653 |
|
|
|
654 |
|
|
/** |
655 |
|
|
* Gets the current number of sampler channels. |
656 |
|
|
* @return The current number of sampler channels. |
657 |
|
|
*/ |
658 |
|
|
public int |
659 |
|
|
getChannelCount() { return channelModels.size(); } |
660 |
|
|
|
661 |
|
|
/** |
662 |
|
|
* Gets the current list of sampler channel models. |
663 |
|
|
* @return The current list of sampler channel models. |
664 |
|
|
*/ |
665 |
|
|
public SamplerChannelModel[] |
666 |
iliev |
1204 |
getChannels() { |
667 |
iliev |
787 |
return channelModels.toArray(new SamplerChannelModel[channelModels.size()]); |
668 |
|
|
} |
669 |
|
|
|
670 |
|
|
/** |
671 |
iliev |
1143 |
* Schedules a new task for adding a new sampler channel on the |
672 |
|
|
* backend side. The channel will be actually added to this model |
673 |
|
|
* when the backend notifies for its creation. |
674 |
iliev |
787 |
* @see #addChannel |
675 |
|
|
*/ |
676 |
|
|
public void |
677 |
iliev |
1143 |
addBackendChannel() { |
678 |
|
|
CC.getTaskQueue().add(new Channel.Add()); |
679 |
iliev |
787 |
// We leave this event to be notified by the LinuxSampler notification system. |
680 |
|
|
} |
681 |
|
|
|
682 |
|
|
/** |
683 |
|
|
* Adds the specified sampler channel. |
684 |
|
|
* @param channel The channel to be added. |
685 |
|
|
*/ |
686 |
|
|
public void |
687 |
|
|
addChannel(SamplerChannel channel) { |
688 |
|
|
DefaultSamplerChannelModel model = new DefaultSamplerChannelModel(channel); |
689 |
|
|
channelModels.add(model); |
690 |
|
|
fireSamplerChannelAdded(model); |
691 |
|
|
} |
692 |
|
|
|
693 |
|
|
/** |
694 |
|
|
* Updates the settings of the specified channel. |
695 |
|
|
* @param channel A <code>SamplerChannel</code> instance containing the new settings |
696 |
|
|
* for the channel. |
697 |
|
|
*/ |
698 |
|
|
public void |
699 |
iliev |
1143 |
updateChannel(SamplerChannel channel) { |
700 |
iliev |
787 |
for(SamplerChannelModel m : channelModels) { |
701 |
iliev |
1143 |
if(m.getChannelId() == channel.getChannelId()) { |
702 |
iliev |
787 |
m.setChannelInfo(channel); |
703 |
|
|
return; |
704 |
|
|
} |
705 |
|
|
} |
706 |
|
|
|
707 |
|
|
CC.getLogger().log ( |
708 |
iliev |
1143 |
Level.WARNING, "DefaultSamplerModel.unknownChannel!", channel.getChannelId() |
709 |
iliev |
787 |
); |
710 |
|
|
} |
711 |
|
|
|
712 |
|
|
/** |
713 |
|
|
* Removes the specified sampler channel. |
714 |
iliev |
1143 |
* @param channelId The ID of the channel to be removed. |
715 |
iliev |
787 |
* @return <code>true</code> if the channel is removed successfully, <code>false</code> |
716 |
iliev |
1143 |
* if the channel's list does not contain channel with ID <code>channelId</code>. |
717 |
iliev |
787 |
*/ |
718 |
|
|
public boolean |
719 |
iliev |
1204 |
removeChannelById(int channelId) { |
720 |
iliev |
787 |
for(int i = 0; i < channelModels.size(); i++) { |
721 |
|
|
SamplerChannelModel m = channelModels.get(i); |
722 |
iliev |
1143 |
if(m.getChannelId() == channelId) { |
723 |
iliev |
787 |
channelModels.remove(i); |
724 |
|
|
fireSamplerChannelRemoved(m); |
725 |
|
|
return true; |
726 |
|
|
} |
727 |
|
|
} |
728 |
|
|
|
729 |
|
|
return false; |
730 |
|
|
} |
731 |
|
|
|
732 |
|
|
/** |
733 |
iliev |
1143 |
* Schedules a new task for removing the specified sampler channel on the backend side. |
734 |
|
|
* @param channelId The ID of the channel to be removed. |
735 |
|
|
*/ |
736 |
|
|
public void |
737 |
|
|
removeBackendChannel(int channelId) { |
738 |
iliev |
1341 |
CC.getTaskQueue().add(new Channel.Remove(channelId)); |
739 |
iliev |
1143 |
} |
740 |
|
|
|
741 |
|
|
/** |
742 |
iliev |
1341 |
* Schedules a new task for starting an instrument editor for editing |
743 |
|
|
* the loaded instrument on the specified sampler channel. |
744 |
|
|
* @param channelId The sampler channel number. |
745 |
|
|
*/ |
746 |
|
|
public void |
747 |
|
|
editBackendInstrument(int channelId) { |
748 |
|
|
CC.getTaskQueue().add(new Channel.EditInstrument(channelId)); |
749 |
|
|
} |
750 |
|
|
|
751 |
|
|
/** |
752 |
iliev |
787 |
* Determines whether there is at least one solo channel in the current list |
753 |
|
|
* of sampler channels. |
754 |
|
|
* @return <code>true</code> if there is at least one solo channel in the current list of |
755 |
|
|
* sampler channels, <code>false</code> otherwise. |
756 |
|
|
*/ |
757 |
|
|
public boolean |
758 |
|
|
hasSoloChannel() { |
759 |
|
|
for(SamplerChannelModel m : channelModels) |
760 |
|
|
if(m.getChannelInfo().isSoloChannel()) return true; |
761 |
|
|
|
762 |
|
|
return false; |
763 |
|
|
} |
764 |
|
|
|
765 |
|
|
/** |
766 |
|
|
* Gets the number of solo channels in the current list of sampler channels. |
767 |
|
|
* @return The number of solo channels in the current list of sampler channels. |
768 |
|
|
*/ |
769 |
|
|
public int |
770 |
|
|
getSoloChannelCount() { |
771 |
|
|
int count = 0; |
772 |
|
|
for(SamplerChannelModel m : channelModels) |
773 |
|
|
if(m.getChannelInfo().isSoloChannel()) count++; |
774 |
|
|
|
775 |
|
|
return count; |
776 |
|
|
} |
777 |
|
|
|
778 |
|
|
/** |
779 |
|
|
* Gets the number of muted channels in the current list of sampler channels. |
780 |
|
|
* This number includes the channels muted because of the presence of a solo channel. |
781 |
|
|
* @return The number of muted channels in the current list of sampler channels. |
782 |
|
|
*/ |
783 |
|
|
public int |
784 |
|
|
getMutedChannelCount() { |
785 |
|
|
int count = 0; |
786 |
|
|
for(SamplerChannelModel m : channelModels) |
787 |
|
|
if(m.getChannelInfo().isMuted()) count++; |
788 |
|
|
|
789 |
|
|
return count; |
790 |
|
|
} |
791 |
|
|
|
792 |
|
|
/** |
793 |
|
|
* Gets the number of channels muted because of the presence of a solo channel. |
794 |
|
|
* @return The number of channels muted because of the presence of a solo channel. |
795 |
|
|
*/ |
796 |
|
|
public int |
797 |
|
|
getMutedBySoloChannelCount() { |
798 |
|
|
int count = 0; |
799 |
|
|
for(SamplerChannelModel m : channelModels) |
800 |
|
|
if(m.getChannelInfo().isMutedBySolo()) count++; |
801 |
|
|
|
802 |
|
|
return count; |
803 |
|
|
} |
804 |
|
|
|
805 |
|
|
/** |
806 |
iliev |
1545 |
* Gets the total number of active streams. |
807 |
|
|
* @return The total number of active streams. |
808 |
|
|
*/ |
809 |
|
|
public int |
810 |
|
|
getTotalStreamCount() { return totalStreamCount; } |
811 |
|
|
|
812 |
|
|
/** |
813 |
iliev |
787 |
* Gets the total number of active voices. |
814 |
|
|
* @return The total number of active voices. |
815 |
|
|
*/ |
816 |
|
|
public int |
817 |
|
|
getTotalVoiceCount() { return totalVoiceCount; } |
818 |
|
|
|
819 |
|
|
/** |
820 |
|
|
* Gets the maximum number of active voices. |
821 |
|
|
* @return The maximum number of active voices. |
822 |
|
|
*/ |
823 |
|
|
public int |
824 |
|
|
getTotalVoiceCountMax() { return totalVoiceCountMax; } |
825 |
|
|
|
826 |
|
|
/** |
827 |
iliev |
1143 |
* Gets the golobal volume of the sampler. |
828 |
|
|
* @return The golobal volume of the sampler. |
829 |
|
|
*/ |
830 |
|
|
public float |
831 |
|
|
getVolume() { return volume; } |
832 |
|
|
|
833 |
|
|
/** |
834 |
|
|
* Sets the global volume. |
835 |
|
|
* @param volume The new volume value. |
836 |
|
|
*/ |
837 |
|
|
public void |
838 |
|
|
setVolume(float volume) { |
839 |
|
|
if(this.volume == volume) return; |
840 |
|
|
|
841 |
|
|
this.volume = volume; |
842 |
|
|
fireVolumeChanged(); |
843 |
|
|
} |
844 |
|
|
|
845 |
|
|
/** |
846 |
|
|
* Schedules a new task for setting the global volume on the backend side. |
847 |
|
|
* @param volume The new volume value. |
848 |
|
|
*/ |
849 |
|
|
public void |
850 |
|
|
setBackendVolume(float volume) { |
851 |
|
|
CC.getTaskQueue().add(new Global.SetVolume(volume)); |
852 |
|
|
} |
853 |
|
|
|
854 |
|
|
/** |
855 |
|
|
* Schedules a new task for resetting the sampler. |
856 |
|
|
*/ |
857 |
|
|
public void |
858 |
iliev |
1204 |
resetBackend() { CC.getTaskQueue().add(new org.jsampler.task.Global.ResetSampler()); } |
859 |
iliev |
1143 |
|
860 |
|
|
/** |
861 |
iliev |
1545 |
* Updates the current number of active disk streams in the sampler. |
862 |
|
|
* @param count The new number of active streams. |
863 |
|
|
*/ |
864 |
|
|
public void |
865 |
|
|
updateActiveStreamsInfo(int count) { |
866 |
|
|
if(totalStreamCount == count) return; |
867 |
|
|
|
868 |
|
|
totalStreamCount = count; |
869 |
|
|
fireTotalStreamCountChanged(); |
870 |
|
|
} |
871 |
|
|
|
872 |
|
|
/** |
873 |
iliev |
787 |
* Updates the current and the maximum number of active voices in the sampler. |
874 |
|
|
* @param count The new number of active voices. |
875 |
|
|
* @param countMax The maximum number of active voices. |
876 |
|
|
*/ |
877 |
|
|
public void |
878 |
|
|
updateActiveVoiceInfo(int count, int countMax) { |
879 |
|
|
if(totalVoiceCount == count && totalVoiceCountMax == countMax) return; |
880 |
|
|
|
881 |
|
|
totalVoiceCount = count; |
882 |
|
|
totalVoiceCountMax = countMax; |
883 |
|
|
fireTotalVoiceCountChanged(); |
884 |
|
|
} |
885 |
|
|
|
886 |
|
|
/** |
887 |
iliev |
1567 |
* Determines whether the sampler configuration is modified. |
888 |
|
|
*/ |
889 |
|
|
public boolean |
890 |
|
|
isModified() { return modified; } |
891 |
|
|
|
892 |
|
|
/** |
893 |
|
|
* Sets whether the sampler configuration is modified. |
894 |
|
|
*/ |
895 |
|
|
public void |
896 |
|
|
setModified(boolean b) { modified = b; } |
897 |
|
|
|
898 |
|
|
/** |
899 |
iliev |
787 |
* Notifies listeners that a sampler channel has been added. |
900 |
iliev |
1143 |
* This method can be invoked outside the event-dispatching thread. |
901 |
iliev |
787 |
* @param channelModel A <code>SamplerChannelModel</code> instance. |
902 |
|
|
*/ |
903 |
|
|
private void |
904 |
|
|
fireSamplerChannelAdded(SamplerChannelModel channelModel) { |
905 |
|
|
final SamplerChannelListEvent e = new SamplerChannelListEvent(this, channelModel); |
906 |
|
|
|
907 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
908 |
|
|
public void |
909 |
|
|
run() { fireSamplerChannelAdded(e); } |
910 |
|
|
}); |
911 |
|
|
} |
912 |
|
|
/** |
913 |
|
|
* Notifies listeners that a sampler channel has been added. |
914 |
|
|
*/ |
915 |
|
|
private void |
916 |
|
|
fireSamplerChannelAdded(SamplerChannelListEvent e) { |
917 |
iliev |
1567 |
setModified(true); |
918 |
iliev |
787 |
Object[] listeners = listenerList.getListenerList(); |
919 |
|
|
|
920 |
|
|
for(int i = listeners.length - 2; i >= 0; i -= 2) { |
921 |
|
|
if(listeners[i] == SamplerChannelListListener.class) { |
922 |
|
|
((SamplerChannelListListener)listeners[i + 1]).channelAdded(e); |
923 |
|
|
} |
924 |
|
|
} |
925 |
|
|
} |
926 |
|
|
|
927 |
|
|
/** |
928 |
|
|
* Notifies listeners that a sampler channel has been removed. |
929 |
iliev |
1143 |
* This method can be invoked outside the event-dispatching thread. |
930 |
iliev |
787 |
* @param channelModel A <code>SamplerChannelModel</code> instance. |
931 |
|
|
*/ |
932 |
|
|
private void |
933 |
|
|
fireSamplerChannelRemoved(SamplerChannelModel channelModel) { |
934 |
|
|
final SamplerChannelListEvent e = new SamplerChannelListEvent(this, channelModel); |
935 |
|
|
|
936 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
937 |
|
|
public void |
938 |
|
|
run() { fireSamplerChannelRemoved(e); } |
939 |
|
|
}); |
940 |
|
|
} |
941 |
|
|
|
942 |
|
|
/** |
943 |
|
|
* Notifies listeners that a sampler channel has been removed. |
944 |
|
|
*/ |
945 |
|
|
private void |
946 |
|
|
fireSamplerChannelRemoved(SamplerChannelListEvent e) { |
947 |
iliev |
1567 |
setModified(true); |
948 |
iliev |
787 |
Object[] listeners = listenerList.getListenerList(); |
949 |
|
|
|
950 |
|
|
for(int i = listeners.length - 2; i >= 0; i -= 2) { |
951 |
|
|
if(listeners[i] == SamplerChannelListListener.class) { |
952 |
|
|
((SamplerChannelListListener)listeners[i + 1]).channelRemoved(e); |
953 |
|
|
} |
954 |
|
|
} |
955 |
|
|
} |
956 |
|
|
|
957 |
|
|
/** |
958 |
|
|
* Notifies listeners that a MIDI device has been added. |
959 |
iliev |
1143 |
* This method can be invoked outside the event-dispatching thread. |
960 |
iliev |
787 |
* @param model A <code>MidiDeviceModel</code> instance. |
961 |
|
|
*/ |
962 |
|
|
private void |
963 |
|
|
fireMidiDeviceAdded(MidiDeviceModel model) { |
964 |
|
|
final MidiDeviceListEvent e = new MidiDeviceListEvent(this, model); |
965 |
|
|
|
966 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
967 |
|
|
public void |
968 |
|
|
run() { fireMidiDeviceAdded(e); } |
969 |
|
|
}); |
970 |
|
|
} |
971 |
|
|
/** |
972 |
|
|
* Notifies listeners that a MIDI device has been added. |
973 |
|
|
*/ |
974 |
|
|
private void |
975 |
|
|
fireMidiDeviceAdded(MidiDeviceListEvent e) { |
976 |
iliev |
1567 |
setModified(true); |
977 |
iliev |
787 |
Object[] listeners = listenerList.getListenerList(); |
978 |
|
|
|
979 |
|
|
for(int i = listeners.length - 2; i >= 0; i -= 2) { |
980 |
|
|
if(listeners[i] == MidiDeviceListListener.class) { |
981 |
|
|
((MidiDeviceListListener)listeners[i + 1]).deviceAdded(e); |
982 |
|
|
} |
983 |
|
|
} |
984 |
|
|
} |
985 |
|
|
|
986 |
|
|
/** |
987 |
|
|
* Notifies listeners that a MIDI device has been removed. |
988 |
iliev |
1143 |
* This method can be invoked outside the event-dispatching thread. |
989 |
iliev |
787 |
* @param model A <code>MidiDeviceModel</code> instance. |
990 |
|
|
*/ |
991 |
|
|
private void |
992 |
|
|
fireMidiDeviceRemoved(MidiDeviceModel model) { |
993 |
|
|
final MidiDeviceListEvent e = new MidiDeviceListEvent(this, model); |
994 |
|
|
|
995 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
996 |
|
|
public void |
997 |
|
|
run() { fireMidiDeviceRemoved(e); } |
998 |
|
|
}); |
999 |
|
|
} |
1000 |
|
|
|
1001 |
|
|
/** |
1002 |
|
|
* Notifies listeners that a MIDI device has been removed. |
1003 |
|
|
*/ |
1004 |
|
|
private void |
1005 |
|
|
fireMidiDeviceRemoved(MidiDeviceListEvent e) { |
1006 |
iliev |
1567 |
setModified(true); |
1007 |
iliev |
787 |
Object[] listeners = listenerList.getListenerList(); |
1008 |
|
|
|
1009 |
|
|
for(int i = listeners.length - 2; i >= 0; i -= 2) { |
1010 |
|
|
if(listeners[i] == MidiDeviceListListener.class) { |
1011 |
|
|
((MidiDeviceListListener)listeners[i + 1]).deviceRemoved(e); |
1012 |
|
|
} |
1013 |
|
|
} |
1014 |
|
|
} |
1015 |
|
|
|
1016 |
|
|
/** |
1017 |
|
|
* Notifies listeners that an audio device has been added. |
1018 |
iliev |
1143 |
* This method can be invoked outside the event-dispatching thread. |
1019 |
iliev |
787 |
* @param model A <code>AudioDeviceModel</code> instance. |
1020 |
|
|
*/ |
1021 |
|
|
private void |
1022 |
|
|
fireAudioDeviceAdded(AudioDeviceModel model) { |
1023 |
iliev |
1143 |
final ListEvent<AudioDeviceModel> e = new ListEvent<AudioDeviceModel>(this, model); |
1024 |
iliev |
787 |
|
1025 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1026 |
|
|
public void |
1027 |
|
|
run() { fireAudioDeviceAdded(e); } |
1028 |
|
|
}); |
1029 |
|
|
} |
1030 |
|
|
|
1031 |
|
|
/** |
1032 |
|
|
* Notifies listeners that an audio device has been added. |
1033 |
|
|
*/ |
1034 |
|
|
private void |
1035 |
iliev |
1143 |
fireAudioDeviceAdded(ListEvent<AudioDeviceModel> e) { |
1036 |
iliev |
1567 |
setModified(true); |
1037 |
iliev |
787 |
Object[] listeners = listenerList.getListenerList(); |
1038 |
|
|
|
1039 |
|
|
for(int i = listeners.length - 2; i >= 0; i -= 2) { |
1040 |
iliev |
1143 |
if(listeners[i] == ListListener.class) { |
1041 |
|
|
((ListListener<AudioDeviceModel>)listeners[i + 1]).entryAdded(e); |
1042 |
iliev |
787 |
} |
1043 |
|
|
} |
1044 |
|
|
} |
1045 |
|
|
|
1046 |
|
|
/** |
1047 |
|
|
* Notifies listeners that an audio device has been removed. |
1048 |
iliev |
1143 |
* This method can be invoked outside the event-dispatching thread. |
1049 |
iliev |
787 |
* @param model A <code>AudioDeviceModel</code> instance. |
1050 |
|
|
*/ |
1051 |
|
|
private void |
1052 |
|
|
fireAudioDeviceRemoved(AudioDeviceModel model) { |
1053 |
iliev |
1143 |
final ListEvent<AudioDeviceModel> e = new ListEvent<AudioDeviceModel>(this, model); |
1054 |
iliev |
787 |
|
1055 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1056 |
|
|
public void |
1057 |
|
|
run() { fireAudioDeviceRemoved(e); } |
1058 |
|
|
}); |
1059 |
|
|
} |
1060 |
|
|
|
1061 |
|
|
/** |
1062 |
iliev |
1567 |
* Notifies listeners that an audio device has been removed. |
1063 |
|
|
* This method should be invoked from the event-dispatching thread. |
1064 |
|
|
*/ |
1065 |
|
|
private void |
1066 |
|
|
fireAudioDeviceRemoved(ListEvent<AudioDeviceModel> e) { |
1067 |
|
|
setModified(true); |
1068 |
|
|
Object[] listeners = listenerList.getListenerList(); |
1069 |
|
|
|
1070 |
|
|
for(int i = listeners.length - 2; i >= 0; i -= 2) { |
1071 |
|
|
if(listeners[i] == ListListener.class) { |
1072 |
|
|
((ListListener<AudioDeviceModel>)listeners[i + 1]).entryRemoved(e); |
1073 |
|
|
} |
1074 |
|
|
} |
1075 |
|
|
} |
1076 |
|
|
|
1077 |
|
|
/** |
1078 |
iliev |
1143 |
* Notifies listeners that a MIDI instrument map has been added to the list. |
1079 |
|
|
* This method can be invoked outside the event-dispatching thread. |
1080 |
|
|
*/ |
1081 |
|
|
private void |
1082 |
|
|
fireMidiInstrumentMapAdded(MidiInstrumentMap map) { |
1083 |
|
|
final ListEvent<MidiInstrumentMap> e = new ListEvent<MidiInstrumentMap>(this, map); |
1084 |
|
|
|
1085 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1086 |
|
|
public void |
1087 |
|
|
run() { fireMidiInstrumentMapAdded(e); } |
1088 |
|
|
}); |
1089 |
|
|
} |
1090 |
|
|
|
1091 |
|
|
/** Notifies listeners that a MIDI instrument map has been added to the list. */ |
1092 |
|
|
private void |
1093 |
|
|
fireMidiInstrumentMapAdded(ListEvent<MidiInstrumentMap> e) { |
1094 |
iliev |
1567 |
setModified(true); |
1095 |
iliev |
1143 |
for(ListListener<MidiInstrumentMap> l : mapsListeners) l.entryAdded(e); |
1096 |
|
|
} |
1097 |
|
|
|
1098 |
|
|
/** |
1099 |
|
|
* Notifies listeners that a MIDI instrument map has been removed from the list. |
1100 |
|
|
* This method can be invoked outside the event-dispatching thread. |
1101 |
|
|
*/ |
1102 |
|
|
private void |
1103 |
|
|
fireMidiInstrumentMapRemoved(MidiInstrumentMap map) { |
1104 |
|
|
final ListEvent<MidiInstrumentMap> e = new ListEvent<MidiInstrumentMap>(this, map); |
1105 |
|
|
|
1106 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1107 |
|
|
public void |
1108 |
|
|
run() { fireMidiInstrumentMapRemoved(e); } |
1109 |
|
|
}); |
1110 |
|
|
} |
1111 |
|
|
/** Notifies listeners that a MIDI instrument map has been removed from the list. */ |
1112 |
|
|
private void |
1113 |
|
|
fireMidiInstrumentMapRemoved(ListEvent<MidiInstrumentMap> e) { |
1114 |
iliev |
1567 |
setModified(true); |
1115 |
iliev |
1143 |
for(ListListener<MidiInstrumentMap> l : mapsListeners) l.entryRemoved(e); |
1116 |
|
|
} |
1117 |
|
|
|
1118 |
|
|
/** |
1119 |
|
|
* Notifies listeners that the global volume has changed. |
1120 |
|
|
* This method can be invoked outside the event-dispatching thread. |
1121 |
|
|
*/ |
1122 |
iliev |
787 |
private void |
1123 |
iliev |
1143 |
fireVolumeChanged() { |
1124 |
|
|
final SamplerEvent e = new SamplerEvent(this); |
1125 |
|
|
|
1126 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1127 |
|
|
public void |
1128 |
|
|
run() { fireVolumeChanged(e); } |
1129 |
|
|
}); |
1130 |
|
|
} |
1131 |
|
|
|
1132 |
|
|
/** |
1133 |
|
|
* Notifies listeners that the global volume has changed. |
1134 |
|
|
*/ |
1135 |
|
|
private void |
1136 |
|
|
fireVolumeChanged(SamplerEvent e) { |
1137 |
iliev |
1567 |
setModified(true); |
1138 |
iliev |
1143 |
for(SamplerListener l : listeners) l.volumeChanged(e); |
1139 |
|
|
} |
1140 |
|
|
|
1141 |
|
|
/* |
1142 |
iliev |
1545 |
* Notifies listeners that the total number of active streams has changed. |
1143 |
|
|
* This method can be invoked outside the event-dispatching thread. |
1144 |
|
|
*/ |
1145 |
|
|
private void |
1146 |
|
|
fireTotalStreamCountChanged() { |
1147 |
|
|
final SamplerEvent e = new SamplerEvent(this); |
1148 |
|
|
|
1149 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1150 |
|
|
public void |
1151 |
|
|
run() { fireTotalStreamCountChanged(e); } |
1152 |
|
|
}); |
1153 |
|
|
} |
1154 |
|
|
|
1155 |
|
|
/** |
1156 |
|
|
* Notifies listeners that the total number of active streams has changed. |
1157 |
|
|
*/ |
1158 |
|
|
private void |
1159 |
|
|
fireTotalStreamCountChanged(SamplerEvent e) { |
1160 |
|
|
for(SamplerListener l : listeners) l.totalStreamCountChanged(e); |
1161 |
|
|
} |
1162 |
|
|
|
1163 |
|
|
/* |
1164 |
iliev |
1143 |
* Notifies listeners that the total number of active voices has changed. |
1165 |
|
|
* This method can be invoked outside the event-dispatching thread. |
1166 |
|
|
*/ |
1167 |
|
|
private void |
1168 |
iliev |
787 |
fireTotalVoiceCountChanged() { |
1169 |
|
|
final SamplerEvent e = new SamplerEvent(this); |
1170 |
|
|
|
1171 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
1172 |
|
|
public void |
1173 |
|
|
run() { fireTotalVoiceCountChanged(e); } |
1174 |
|
|
}); |
1175 |
|
|
} |
1176 |
|
|
|
1177 |
|
|
/** |
1178 |
|
|
* Notifies listeners that the total number of active voices has changed. |
1179 |
|
|
*/ |
1180 |
|
|
private void |
1181 |
|
|
fireTotalVoiceCountChanged(SamplerEvent e) { |
1182 |
|
|
for(SamplerListener l : listeners) l.totalVoiceCountChanged(e); |
1183 |
|
|
} |
1184 |
iliev |
1143 |
|
1185 |
|
|
/** |
1186 |
iliev |
1567 |
* Notifies listeners that the default MIDI instrument map is changed. |
1187 |
iliev |
1143 |
*/ |
1188 |
|
|
private void |
1189 |
|
|
fireDefaultMapChanged() { |
1190 |
|
|
SamplerEvent e = new SamplerEvent(this); |
1191 |
|
|
for(SamplerListener l : listeners) l.defaultMapChanged(e); |
1192 |
|
|
} |
1193 |
|
|
|
1194 |
|
|
private final Handler handler = new Handler(); |
1195 |
|
|
|
1196 |
|
|
private Handler |
1197 |
|
|
getHandler() { return handler; } |
1198 |
|
|
|
1199 |
|
|
private class Handler implements ListListener<MidiInstrumentMap> { |
1200 |
|
|
/** Invoked when a new map is added to a list. */ |
1201 |
|
|
public void |
1202 |
|
|
entryAdded(ListEvent<MidiInstrumentMap> e) { updateDefaultMap(); } |
1203 |
|
|
|
1204 |
|
|
/** Invoked when a map is removed from a list. */ |
1205 |
|
|
public void |
1206 |
|
|
entryRemoved(ListEvent<MidiInstrumentMap> e) { updateDefaultMap(); } |
1207 |
|
|
|
1208 |
|
|
private void |
1209 |
|
|
updateDefaultMap() { |
1210 |
|
|
if(getDefaultMidiInstrumentMap() != findDefaultMidiInstrumentMap()) { |
1211 |
|
|
defaultMidiInstrumentMap = findDefaultMidiInstrumentMap(); |
1212 |
|
|
fireDefaultMapChanged(); |
1213 |
|
|
} |
1214 |
|
|
} |
1215 |
|
|
} |
1216 |
iliev |
787 |
} |