1 |
iliev |
1144 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
5 |
|
|
* |
6 |
|
|
* This file is part of JSampler. |
7 |
|
|
* |
8 |
|
|
* JSampler is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License version 2 |
10 |
|
|
* as published by the Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* JSampler is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with JSampler; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
|
* MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
package org.jsampler.task; |
23 |
|
|
|
24 |
|
|
import java.util.Vector; |
25 |
|
|
import java.util.logging.Level; |
26 |
|
|
|
27 |
|
|
import net.sf.juife.Task; |
28 |
|
|
|
29 |
|
|
import org.linuxsampler.lscp.BoolParameter; |
30 |
|
|
import org.linuxsampler.lscp.MidiInputDevice; |
31 |
|
|
import org.linuxsampler.lscp.MidiInputDriver; |
32 |
|
|
import org.linuxsampler.lscp.MidiInstrumentEntry; |
33 |
|
|
import org.linuxsampler.lscp.MidiInstrumentInfo; |
34 |
|
|
import org.linuxsampler.lscp.MidiInstrumentMapInfo; |
35 |
|
|
import org.linuxsampler.lscp.Parameter; |
36 |
|
|
|
37 |
|
|
import org.jsampler.CC; |
38 |
|
|
import org.jsampler.HF; |
39 |
|
|
import org.jsampler.MidiDeviceModel; |
40 |
|
|
import org.jsampler.MidiInstrument; |
41 |
|
|
import org.jsampler.MidiInstrumentMap; |
42 |
|
|
import org.jsampler.SamplerModel; |
43 |
|
|
|
44 |
|
|
import static org.jsampler.JSI18n.i18n; |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* Provides the MIDI specific tasks. |
49 |
|
|
* @author Grigor Iliev |
50 |
|
|
*/ |
51 |
|
|
public class Midi { |
52 |
|
|
/** Forbits the instantiation of this class. */ |
53 |
|
|
private Midi() { } |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
/** |
57 |
|
|
* This task retrieves all MIDI input drivers currently |
58 |
|
|
* available for the LinuxSampler instance. |
59 |
|
|
*/ |
60 |
|
|
public static class GetDrivers extends EnhancedTask<MidiInputDriver[]> { |
61 |
|
|
/** Creates a new instance of <code>GetDrivers</code>. */ |
62 |
|
|
public |
63 |
|
|
GetDrivers() { |
64 |
|
|
setTitle("Midi.GetDrivers_task"); |
65 |
|
|
setDescription(i18n.getMessage("Midi.GetDrivers.desc")); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
/** The entry point of the task. */ |
69 |
|
|
public void |
70 |
|
|
run() { |
71 |
|
|
try { setResult(CC.getClient().getMidiInputDrivers()); } |
72 |
|
|
catch(Exception x) { |
73 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
74 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
/** |
80 |
|
|
* This task creates a new MIDI input device. |
81 |
|
|
*/ |
82 |
|
|
public static class CreateDevice extends EnhancedTask<Integer> { |
83 |
|
|
private String driver; |
84 |
|
|
private Parameter[] parameters; |
85 |
|
|
|
86 |
|
|
/** |
87 |
|
|
* Creates a new instance of <code>CreateDevice</code>. |
88 |
|
|
* @param driver The desired MIDI input system. |
89 |
|
|
* @param parameters An optional list of driver specific parameters. |
90 |
|
|
*/ |
91 |
|
|
public |
92 |
|
|
CreateDevice(String driver, Parameter... parameters) { |
93 |
|
|
setTitle("Midi.CreateDevice_task"); |
94 |
|
|
setDescription(i18n.getMessage("Midi.CreateDevice.desc")); |
95 |
|
|
|
96 |
|
|
this.driver = driver; |
97 |
|
|
this.parameters = parameters; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
/** The entry point of the task. */ |
101 |
|
|
public void |
102 |
|
|
run() { |
103 |
|
|
try { |
104 |
|
|
run0(); |
105 |
|
|
} catch(Exception x) { |
106 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
107 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
private void |
112 |
|
|
run0() throws Exception { |
113 |
|
|
Integer deviceId = CC.getClient().createMidiInputDevice(driver, parameters); |
114 |
|
|
setResult(deviceId); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/** |
119 |
|
|
* This task destroys the specified MIDI input device. |
120 |
|
|
*/ |
121 |
|
|
public static class DestroyDevice extends EnhancedTask { |
122 |
|
|
private int deviceId; |
123 |
|
|
|
124 |
|
|
/** |
125 |
|
|
* Creates a new instance of <code>DestroyDevice</code>. |
126 |
|
|
* @param deviceId The ID of the MIDI input device to be destroyed. |
127 |
|
|
*/ |
128 |
|
|
public |
129 |
|
|
DestroyDevice(int deviceId) { |
130 |
|
|
setTitle("Midi.DestroyDevice_task"); |
131 |
|
|
setDescription(i18n.getMessage("Midi.DestroyDevice.desc", deviceId)); |
132 |
|
|
|
133 |
|
|
this.deviceId = deviceId; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
/** The entry point of the task. */ |
137 |
|
|
public void |
138 |
|
|
run() { |
139 |
|
|
try { CC.getClient().destroyMidiInputDevice(deviceId); } |
140 |
|
|
catch(Exception x) { |
141 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
142 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/** |
148 |
|
|
* This task enables/disables a specific MIDI input device. |
149 |
|
|
*/ |
150 |
|
|
public static class EnableDevice extends EnhancedTask { |
151 |
|
|
private int dev; |
152 |
|
|
private boolean enable; |
153 |
|
|
|
154 |
|
|
/** |
155 |
|
|
* Creates new instance of <code>EnableDevice</code>. |
156 |
|
|
* @param dev The id of the device to be enabled/disabled. |
157 |
|
|
* @param enable Specify <code>true</code> to enable the MIDI device; |
158 |
|
|
* code>false</code> to disable it. |
159 |
|
|
*/ |
160 |
|
|
public |
161 |
|
|
EnableDevice(int dev, boolean enable) { |
162 |
|
|
setTitle("Midi.EnableDevice_task"); |
163 |
|
|
setDescription(i18n.getMessage("Midi.EnableDevice.desc", dev)); |
164 |
|
|
|
165 |
|
|
this.dev = dev; |
166 |
|
|
this.enable = enable; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
/** The entry point of the task. */ |
170 |
|
|
public void |
171 |
|
|
run() { |
172 |
|
|
try { |
173 |
|
|
CC.getClient().enableMidiInputDevice(dev, enable); |
174 |
|
|
|
175 |
|
|
// Not needed, but eventually speeds up the change. |
176 |
iliev |
1204 |
CC.getSamplerModel().getMidiDeviceById(dev).setActive(enable); |
177 |
iliev |
1144 |
} catch(Exception x) { |
178 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
179 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
180 |
|
|
} |
181 |
|
|
} |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
/** |
185 |
|
|
* This task alters a specific setting of a created MIDI input device. |
186 |
|
|
*/ |
187 |
|
|
public static class SetDeviceParameter extends EnhancedTask { |
188 |
|
|
private int dev; |
189 |
|
|
private Parameter prm; |
190 |
|
|
|
191 |
|
|
/** |
192 |
|
|
* Creates new instance of <code>SetDeviceParameter</code>. |
193 |
|
|
* @param dev The id of the device whose parameter should be set. |
194 |
|
|
* @param prmName The parameter name. |
195 |
|
|
* @param value The new value for the specified parameter. |
196 |
|
|
*/ |
197 |
|
|
public |
198 |
|
|
SetDeviceParameter(int dev, String prmName, boolean value) { |
199 |
|
|
this(dev, new BoolParameter(prmName, value)); |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
/** |
203 |
|
|
* Creates new instance of <code>SetDeviceParameter</code>. |
204 |
|
|
* @param dev The id of the device whose parameter should be set. |
205 |
|
|
* @param prm The parameter to be set. |
206 |
|
|
*/ |
207 |
|
|
public |
208 |
|
|
SetDeviceParameter(int dev, Parameter prm) { |
209 |
|
|
setTitle("Midi.SetDeviceParameter_task"); |
210 |
|
|
setDescription(i18n.getMessage("Midi.SetDeviceParameter.desc")); |
211 |
|
|
|
212 |
|
|
this.dev = dev; |
213 |
|
|
this.prm = prm; |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
/** The entry point of the task. */ |
217 |
|
|
public void |
218 |
|
|
run() { |
219 |
|
|
try { |
220 |
|
|
CC.getClient().setMidiInputDeviceParameter(dev, prm); |
221 |
|
|
|
222 |
iliev |
1204 |
CC.getSamplerModel().getMidiDeviceById(dev); |
223 |
iliev |
1144 |
} catch(Exception x) { |
224 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
225 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
226 |
|
|
} |
227 |
|
|
} |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
/** |
231 |
|
|
* This task changes the port number of a speicific MIDI input device. |
232 |
|
|
*/ |
233 |
|
|
public static class SetPortCount extends EnhancedTask { |
234 |
|
|
private int deviceId; |
235 |
|
|
private int ports; |
236 |
|
|
|
237 |
|
|
/** |
238 |
|
|
* Creates new instance of <code>SetPortCount</code>. |
239 |
|
|
* @param deviceId The id of the device whose ports number will be changed. |
240 |
|
|
* @param ports The new number of ports. |
241 |
|
|
*/ |
242 |
|
|
public |
243 |
|
|
SetPortCount(int deviceId, int ports) { |
244 |
|
|
setTitle("SetMidiInputPortCount_task"); |
245 |
|
|
setDescription(i18n.getMessage("Midi.SetPortCount.desc", deviceId)); |
246 |
|
|
|
247 |
|
|
this.deviceId = deviceId; |
248 |
|
|
this.ports = ports; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
/** The entry point of the task. */ |
252 |
|
|
public void |
253 |
|
|
run() { |
254 |
|
|
try { CC.getClient().setMidiInputPortCount(deviceId, ports); } |
255 |
|
|
catch(Exception x) { |
256 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
257 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
258 |
|
|
} |
259 |
|
|
} |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
/** |
263 |
|
|
* This task alters a specific setting of a MIDI input port. |
264 |
|
|
*/ |
265 |
|
|
public static class SetPortParameter extends EnhancedTask { |
266 |
|
|
private int dev; |
267 |
|
|
private int port; |
268 |
|
|
private Parameter prm; |
269 |
|
|
|
270 |
|
|
/** |
271 |
|
|
* Creates new instance of <code>SetPortParameter</code>. |
272 |
|
|
* @param dev The id of the device whose port parameter should be set. |
273 |
|
|
* @param port The number of the port. |
274 |
|
|
* @param prm The parameter to be set. |
275 |
|
|
*/ |
276 |
|
|
public |
277 |
|
|
SetPortParameter(int dev, int port, Parameter prm) { |
278 |
|
|
setTitle("Midi.SetPortParameter_task"); |
279 |
|
|
setDescription(i18n.getMessage("Midi.SetPortParameter.desc")); |
280 |
|
|
|
281 |
|
|
this.dev = dev; |
282 |
|
|
this.port = port; |
283 |
|
|
this.prm = prm; |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
/** The entry point of the task. */ |
287 |
|
|
public void |
288 |
|
|
run() { |
289 |
|
|
try { CC.getClient().setMidiInputPortParameter(dev, port, prm); } |
290 |
|
|
catch(Exception x) { |
291 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
292 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
293 |
|
|
} |
294 |
|
|
} |
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
/** |
298 |
|
|
* This task updates the settings of a MIDI input device. |
299 |
|
|
*/ |
300 |
|
|
public static class UpdateDeviceInfo extends EnhancedTask { |
301 |
|
|
private int dev; |
302 |
|
|
|
303 |
|
|
/** |
304 |
|
|
* Creates new instance of <code>UpdateDeviceInfo</code>. |
305 |
|
|
* @param dev The id of the device, whose settings should be updated. |
306 |
|
|
*/ |
307 |
|
|
public |
308 |
|
|
UpdateDeviceInfo(int dev) { |
309 |
|
|
setTitle("Midi.UpdateDeviceInfo_task"); |
310 |
|
|
setDescription(i18n.getMessage("Midi.UpdateDeviceInfo.desc", dev)); |
311 |
|
|
|
312 |
|
|
this.dev = dev; |
313 |
|
|
} |
314 |
|
|
|
315 |
|
|
/** The entry point of the task. */ |
316 |
|
|
public void |
317 |
|
|
run() { |
318 |
|
|
try { |
319 |
|
|
MidiInputDevice mid = CC.getClient().getMidiInputDeviceInfo(dev); |
320 |
iliev |
1204 |
CC.getSamplerModel().getMidiDeviceById(dev).setDeviceInfo(mid); |
321 |
iliev |
1144 |
} catch(Exception x) { |
322 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
323 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
324 |
|
|
} |
325 |
|
|
} |
326 |
|
|
} |
327 |
|
|
|
328 |
|
|
/** |
329 |
|
|
* This task updates the MIDI device list and all MIDI devices' settings. |
330 |
|
|
*/ |
331 |
|
|
public static class UpdateDevices extends EnhancedTask { |
332 |
|
|
/** Creates a new instance of <code>UpdateDevices</code>. */ |
333 |
|
|
public |
334 |
|
|
UpdateDevices() { |
335 |
|
|
setTitle("Midi.UpdateDevices_task"); |
336 |
|
|
setDescription(i18n.getMessage("Midi.UpdateDevices.desc")); |
337 |
|
|
} |
338 |
|
|
|
339 |
|
|
/** The entry point of the task. */ |
340 |
|
|
public void |
341 |
|
|
run() { |
342 |
|
|
try { |
343 |
|
|
SamplerModel sm = CC.getSamplerModel(); |
344 |
|
|
Integer[] deviceIDs = CC.getClient().getMidiInputDeviceIDs(); |
345 |
|
|
|
346 |
|
|
boolean found = false; |
347 |
|
|
|
348 |
iliev |
1204 |
for(MidiDeviceModel m : sm.getMidiDevices()) { |
349 |
iliev |
1144 |
for(int i = 0; i < deviceIDs.length; i++) { |
350 |
|
|
if(m.getDeviceId() == deviceIDs[i]) { |
351 |
|
|
deviceIDs[i] = -1; |
352 |
|
|
found = true; |
353 |
|
|
} |
354 |
|
|
} |
355 |
|
|
|
356 |
iliev |
1204 |
if(!found) sm.removeMidiDeviceById(m.getDeviceId()); |
357 |
iliev |
1144 |
found = false; |
358 |
|
|
} |
359 |
|
|
|
360 |
|
|
MidiInputDevice dev; |
361 |
|
|
|
362 |
|
|
for(int id : deviceIDs) { |
363 |
|
|
if(id >= 0) { |
364 |
|
|
dev = CC.getClient().getMidiInputDeviceInfo(id); |
365 |
|
|
sm.addMidiDevice(dev); |
366 |
|
|
} |
367 |
|
|
} |
368 |
|
|
} catch(Exception x) { |
369 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
370 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
371 |
|
|
} |
372 |
|
|
} |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
/** |
376 |
|
|
* This task creates a new MIDI instrument map. |
377 |
|
|
*/ |
378 |
|
|
public static class AddInstrumentMap extends EnhancedTask<Integer> { |
379 |
|
|
private String name; |
380 |
|
|
|
381 |
|
|
/** |
382 |
|
|
* Creates a new instance of <code>AddInstrumentMap</code>. |
383 |
|
|
* |
384 |
|
|
* @param name The chosen name for the new MIDI instrument map. |
385 |
|
|
*/ |
386 |
|
|
public |
387 |
|
|
AddInstrumentMap(String name) { |
388 |
|
|
setTitle("Midi.AddMidiInstrumentMap_task"); |
389 |
|
|
setDescription(i18n.getMessage("Midi.AddMidiInstrumentMap.desc")); |
390 |
|
|
|
391 |
|
|
this.name = name; |
392 |
|
|
} |
393 |
|
|
|
394 |
|
|
/** The entry point of the task. */ |
395 |
|
|
public void |
396 |
|
|
run() { |
397 |
|
|
try { |
398 |
|
|
Integer mapId = CC.getClient().addMidiInstrumentMap(name); |
399 |
|
|
setResult(mapId); |
400 |
|
|
} catch(Exception x) { |
401 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
402 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
403 |
|
|
} |
404 |
|
|
} |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
/** |
408 |
|
|
* This task removes the specified MIDI instrument map. |
409 |
|
|
*/ |
410 |
|
|
public static class RemoveInstrumentMap extends EnhancedTask { |
411 |
|
|
private int mapId; |
412 |
|
|
|
413 |
|
|
/** |
414 |
|
|
* Creates a new instance of <code>RemoveInstrumentMap</code>. |
415 |
|
|
* |
416 |
|
|
* @param mapId The numerical ID of the MIDI instrument map to remove. |
417 |
|
|
*/ |
418 |
|
|
public |
419 |
|
|
RemoveInstrumentMap(int mapId) { |
420 |
|
|
setTitle("Midi.RemoveMidiInstrumentMap_task"); |
421 |
|
|
setDescription(i18n.getMessage("Midi.RemoveMidiInstrumentMap.desc", mapId)); |
422 |
|
|
|
423 |
|
|
this.mapId = mapId; |
424 |
|
|
} |
425 |
|
|
|
426 |
|
|
/** The entry point of the task. */ |
427 |
|
|
public void |
428 |
|
|
run() { |
429 |
|
|
try { |
430 |
|
|
CC.getClient().removeMidiInstrumentMap(mapId); |
431 |
|
|
} catch(Exception x) { |
432 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
433 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
434 |
|
|
} |
435 |
|
|
} |
436 |
|
|
} |
437 |
|
|
|
438 |
|
|
/** |
439 |
|
|
* This task changes the MIDI instrument map settings. |
440 |
|
|
*/ |
441 |
|
|
public static class SetInstrumentMapInfo extends EnhancedTask { |
442 |
|
|
private int mapId; |
443 |
|
|
private String name; |
444 |
|
|
|
445 |
|
|
/** |
446 |
|
|
* Creates a new instance of <code>SetInstrumentMapInfo</code>. |
447 |
|
|
* @param mapId The numerical ID of the MIDI instrument map. |
448 |
|
|
* @param name The new name for the specified MIDI instrument map. |
449 |
|
|
*/ |
450 |
|
|
public |
451 |
|
|
SetInstrumentMapInfo(int mapId, String name) { |
452 |
|
|
setTitle("Midi.SetInstrumentMapInfo_task"); |
453 |
|
|
setDescription(i18n.getMessage("Midi.SetInstrumentMapInfo.desc")); |
454 |
|
|
|
455 |
|
|
this.mapId = mapId; |
456 |
|
|
this.name = name; |
457 |
|
|
} |
458 |
|
|
|
459 |
|
|
/** The entry point of the task. */ |
460 |
|
|
public void |
461 |
|
|
run() { |
462 |
|
|
try { |
463 |
|
|
CC.getClient().setMidiInstrumentMapName(mapId, name); |
464 |
|
|
} catch(Exception x) { |
465 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
466 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
467 |
|
|
} |
468 |
|
|
} |
469 |
|
|
} |
470 |
|
|
|
471 |
|
|
/** |
472 |
|
|
* This task updates the settings of a MIDI instrument map. |
473 |
|
|
*/ |
474 |
|
|
public static class UpdateInstrumentMapInfo extends EnhancedTask { |
475 |
|
|
private int mapId; |
476 |
|
|
|
477 |
|
|
/** |
478 |
|
|
* Creates new instance of <code>UpdateInstrumentMapInfo</code>. |
479 |
|
|
* @param mapId The id of the MIDI instrument map, whose settings should be updated. |
480 |
|
|
*/ |
481 |
|
|
public |
482 |
|
|
UpdateInstrumentMapInfo(int mapId) { |
483 |
|
|
setTitle("Midi.UpdateInstrumentMapInfo_task"); |
484 |
|
|
setDescription(i18n.getMessage("Midi.UpdateInstrumentMapInfo.desc", mapId)); |
485 |
|
|
|
486 |
|
|
this.mapId = mapId; |
487 |
|
|
} |
488 |
|
|
|
489 |
|
|
/** The entry point of the task. */ |
490 |
|
|
public void |
491 |
|
|
run() { |
492 |
|
|
try { |
493 |
|
|
MidiInstrumentMapInfo info = |
494 |
|
|
CC.getClient().getMidiInstrumentMapInfo(mapId); |
495 |
|
|
|
496 |
|
|
CC.getSamplerModel().getMidiInstrumentMapById(mapId).setInfo(info); |
497 |
|
|
} catch(Exception x) { |
498 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
499 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
500 |
|
|
} |
501 |
|
|
} |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
/** |
505 |
|
|
* This task gets the MIDI instrument map list and all MIDI instruments' settings. |
506 |
|
|
*/ |
507 |
|
|
public static class GetInstrumentMaps extends EnhancedTask<MidiInstrumentMap[]> { |
508 |
|
|
/** Creates a new instance of <code>GetInstrumentMaps</code>. */ |
509 |
|
|
public |
510 |
|
|
GetInstrumentMaps() { |
511 |
|
|
setTitle("Midi.GetInstrumentMaps_task"); |
512 |
|
|
setDescription(i18n.getMessage("Midi.GetInstrumentMaps.desc")); |
513 |
|
|
} |
514 |
|
|
|
515 |
|
|
/** The entry point of the task. */ |
516 |
|
|
public void |
517 |
|
|
run() { |
518 |
|
|
try { |
519 |
|
|
MidiInstrumentMapInfo[] mims; |
520 |
|
|
mims = CC.getClient().getMidiInstrumentMaps(); |
521 |
|
|
MidiInstrumentMap[] maps = new MidiInstrumentMap[mims.length]; |
522 |
|
|
|
523 |
|
|
for(int i = 0; i < mims.length; i++) { |
524 |
|
|
maps[i] = createMap(mims[i]); |
525 |
|
|
} |
526 |
|
|
|
527 |
|
|
setResult(maps); |
528 |
|
|
} catch(Exception x) { |
529 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
530 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
531 |
|
|
} |
532 |
|
|
} |
533 |
|
|
|
534 |
|
|
private MidiInstrumentMap |
535 |
|
|
createMap(MidiInstrumentMapInfo m) throws Exception { |
536 |
|
|
MidiInstrumentMap map = new MidiInstrumentMap(m); |
537 |
|
|
MidiInstrumentInfo[] miis = CC.getClient().getMidiInstruments(m.getMapId()); |
538 |
|
|
|
539 |
|
|
for(MidiInstrumentInfo instrInfo : miis) { |
540 |
|
|
MidiInstrument instr = new MidiInstrument(instrInfo); |
541 |
|
|
map.mapMidiInstrument(instrInfo.getEntry(), instr); |
542 |
|
|
} |
543 |
|
|
|
544 |
|
|
return map; |
545 |
|
|
} |
546 |
|
|
} |
547 |
|
|
|
548 |
|
|
/** |
549 |
|
|
* This task updates the MIDI instrument map list. |
550 |
|
|
*/ |
551 |
|
|
public static class UpdateInstrumentMaps extends EnhancedTask { |
552 |
|
|
/** Creates a new instance of <code>UpdateInstrumentMaps</code>. */ |
553 |
|
|
public |
554 |
|
|
UpdateInstrumentMaps() { |
555 |
|
|
setTitle("Midi.UpdateInstrumentMaps_task"); |
556 |
|
|
setDescription(i18n.getMessage("Midi.UpdateInstrumentMaps.desc")); |
557 |
|
|
} |
558 |
|
|
|
559 |
|
|
/** The entry point of the task. */ |
560 |
|
|
public void |
561 |
|
|
run() { |
562 |
|
|
try { |
563 |
|
|
SamplerModel sm = CC.getSamplerModel(); |
564 |
|
|
Integer[] mapIDs = CC.getClient().getMidiInstrumentMapIDs(); |
565 |
|
|
|
566 |
|
|
boolean found = false; |
567 |
|
|
|
568 |
|
|
for(MidiInstrumentMap m : sm.getMidiInstrumentMaps()) { |
569 |
|
|
for(int i = 0; i < mapIDs.length; i++) { |
570 |
|
|
if(mapIDs[i] == m.getMapId()) { |
571 |
|
|
mapIDs[i] = -1; |
572 |
|
|
found = true; |
573 |
|
|
} |
574 |
|
|
} |
575 |
|
|
|
576 |
iliev |
1204 |
if(!found) sm.removeMidiInstrumentMapById(m.getMapId()); |
577 |
iliev |
1144 |
found = false; |
578 |
|
|
} |
579 |
|
|
|
580 |
|
|
MidiInstrumentMapInfo map; |
581 |
|
|
|
582 |
|
|
for(int id : mapIDs) { |
583 |
|
|
if(id >= 0) { |
584 |
|
|
map = CC.getClient().getMidiInstrumentMapInfo(id); |
585 |
|
|
sm.addMidiInstrumentMap(new MidiInstrumentMap(map)); |
586 |
|
|
} |
587 |
|
|
} |
588 |
|
|
} catch(Exception x) { |
589 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
590 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
591 |
|
|
x.printStackTrace(); |
592 |
|
|
} |
593 |
|
|
} |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
/** |
597 |
|
|
* This task maps a new MIDI instrument or replaces an existing one. |
598 |
|
|
*/ |
599 |
|
|
public static class MapInstrument extends EnhancedTask { |
600 |
|
|
private int mapId; |
601 |
|
|
private int bank; |
602 |
|
|
private int program; |
603 |
|
|
private MidiInstrumentInfo instrInfo; |
604 |
|
|
|
605 |
|
|
/** |
606 |
|
|
* Creates new instance of <code>MapInstrument</code>. |
607 |
|
|
* @param mapId The id of the MIDI instrument map. |
608 |
|
|
* @param bank The index of the MIDI bank, which will contain the instrument. |
609 |
|
|
* @param program The MIDI program number of the new instrument. |
610 |
|
|
* @param instrInfo Provides the MIDI instrument settings. |
611 |
|
|
*/ |
612 |
|
|
public |
613 |
|
|
MapInstrument(int mapId, int bank, int program, MidiInstrumentInfo instrInfo) { |
614 |
|
|
setTitle("Midi.MapInstrument_task"); |
615 |
|
|
setDescription(i18n.getMessage("Midi.MapInstrument.desc")); |
616 |
|
|
|
617 |
|
|
this.mapId = mapId; |
618 |
|
|
this.bank = bank; |
619 |
|
|
this.program = program; |
620 |
|
|
this.instrInfo = instrInfo; |
621 |
|
|
} |
622 |
|
|
|
623 |
|
|
/** The entry point of the task. */ |
624 |
|
|
public void |
625 |
|
|
run() { |
626 |
|
|
try { |
627 |
|
|
MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program); |
628 |
iliev |
1204 |
CC.getClient().mapMidiInstrument(mapId, entry, instrInfo, true); |
629 |
iliev |
1144 |
} catch(Exception x) { |
630 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
631 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
632 |
|
|
} |
633 |
|
|
} |
634 |
|
|
} |
635 |
|
|
|
636 |
|
|
/** |
637 |
|
|
* This task removes a MIDI instrument. |
638 |
|
|
*/ |
639 |
|
|
public static class UnmapInstrument extends EnhancedTask { |
640 |
|
|
private int mapId; |
641 |
|
|
private int bank; |
642 |
|
|
private int program; |
643 |
|
|
|
644 |
|
|
/** |
645 |
|
|
* Creates new instance of <code>UnmapInstrument</code>. |
646 |
|
|
* @param mapId The id of the MIDI instrument |
647 |
|
|
* map containing the instrument to be removed. |
648 |
|
|
* @param bank The index of the MIDI bank containing the instrument to be removed. |
649 |
|
|
* @param program The MIDI program number of the instrument to be removed. |
650 |
|
|
*/ |
651 |
|
|
public |
652 |
|
|
UnmapInstrument(int mapId, int bank, int program) { |
653 |
|
|
setTitle("Midi.UnmapInstrument_task"); |
654 |
|
|
setDescription(i18n.getMessage("Midi.UnmapInstrument.desc")); |
655 |
|
|
|
656 |
|
|
this.mapId = mapId; |
657 |
|
|
this.bank = bank; |
658 |
|
|
this.program = program; |
659 |
|
|
} |
660 |
|
|
|
661 |
|
|
/** The entry point of the task. */ |
662 |
|
|
public void |
663 |
|
|
run() { |
664 |
|
|
try { |
665 |
|
|
MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program); |
666 |
|
|
CC.getClient().unmapMidiInstrument(mapId, entry); |
667 |
|
|
} catch(Exception x) { |
668 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
669 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
670 |
|
|
} |
671 |
|
|
} |
672 |
|
|
} |
673 |
|
|
|
674 |
|
|
/** |
675 |
|
|
* This task updates the settings of a MIDI instrument. |
676 |
|
|
*/ |
677 |
|
|
public static class UpdateInstrumentInfo extends EnhancedTask { |
678 |
|
|
private int mapId; |
679 |
|
|
private int bank; |
680 |
|
|
private int program; |
681 |
|
|
|
682 |
|
|
/** |
683 |
|
|
* Creates new instance of <code>UpdateInstrumentInfo</code>. |
684 |
|
|
* @param mapId The id of the MIDI instrument map containg the instrument. |
685 |
|
|
* @param bank The index of the MIDI bank, containing the instrument. |
686 |
|
|
* @param program The MIDI program number of the instrument. |
687 |
|
|
*/ |
688 |
|
|
public |
689 |
|
|
UpdateInstrumentInfo(int mapId, int bank, int program) { |
690 |
|
|
setTitle("Midi.UpdateInstrumentInfo_task"); |
691 |
|
|
setDescription(i18n.getMessage("Midi.UpdateInstrumentInfo.desc")); |
692 |
|
|
|
693 |
|
|
this.mapId = mapId; |
694 |
|
|
this.bank = bank; |
695 |
|
|
this.program = program; |
696 |
|
|
} |
697 |
|
|
|
698 |
|
|
/** The entry point of the task. */ |
699 |
|
|
public void |
700 |
|
|
run() { |
701 |
|
|
try { |
702 |
|
|
MidiInstrumentInfo info = |
703 |
|
|
CC.getClient().getMidiInstrumentInfo(mapId, bank, program); |
704 |
|
|
|
705 |
|
|
MidiInstrumentMap map; |
706 |
|
|
map = CC.getSamplerModel().getMidiInstrumentMapById(mapId); |
707 |
|
|
map.getMidiInstrument(bank, program).setInfo(info); |
708 |
|
|
} catch(Exception x) { |
709 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
710 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
711 |
|
|
} |
712 |
|
|
} |
713 |
|
|
} |
714 |
|
|
|
715 |
|
|
/** |
716 |
|
|
* This task updates the MIDI instrument list on a specific MIDI instrument map. |
717 |
|
|
*/ |
718 |
|
|
public static class UpdateInstruments extends EnhancedTask { |
719 |
|
|
private int mapId; |
720 |
|
|
|
721 |
|
|
/** Creates a new instance of <code>UpdateInstruments</code>. */ |
722 |
|
|
public |
723 |
|
|
UpdateInstruments(int mapId) { |
724 |
|
|
setTitle("Midi.UpdateInstruments_task"); |
725 |
|
|
setDescription(i18n.getMessage("Midi.UpdateInstruments.desc")); |
726 |
|
|
|
727 |
|
|
this.mapId = mapId; |
728 |
|
|
} |
729 |
|
|
|
730 |
|
|
/** The entry point of the task. */ |
731 |
|
|
public void |
732 |
|
|
run() { |
733 |
|
|
try { |
734 |
|
|
SamplerModel sm = CC.getSamplerModel(); |
735 |
|
|
MidiInstrumentInfo[] iS = CC.getClient().getMidiInstruments(mapId); |
736 |
|
|
MidiInstrumentMap map = sm.getMidiInstrumentMapById(mapId); |
737 |
|
|
|
738 |
|
|
boolean found = false; |
739 |
|
|
|
740 |
|
|
for(MidiInstrument instr : map.getAllMidiInstruments()) { |
741 |
|
|
for(int i = 0; i < iS.length; i++) { |
742 |
|
|
if(instr.getInfo().equals(iS[i])) { |
743 |
|
|
iS[i] = null; |
744 |
|
|
found = true; |
745 |
|
|
} |
746 |
|
|
} |
747 |
|
|
|
748 |
|
|
if(!found) { |
749 |
|
|
map.unmapMidiInstrument(instr.getInfo().getEntry()); |
750 |
|
|
} |
751 |
|
|
found = false; |
752 |
|
|
} |
753 |
|
|
|
754 |
|
|
for(MidiInstrumentInfo mii : iS) { |
755 |
|
|
if(mii != null) { |
756 |
|
|
MidiInstrument instr = new MidiInstrument(mii); |
757 |
|
|
map.mapMidiInstrument(mii.getEntry(), instr); |
758 |
|
|
} |
759 |
|
|
} |
760 |
|
|
} catch(Exception x) { |
761 |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
762 |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
763 |
|
|
} |
764 |
|
|
} |
765 |
|
|
} |
766 |
|
|
|
767 |
|
|
} |