1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2012 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler; |
24 |
|
25 |
import java.io.ByteArrayOutputStream; |
26 |
|
27 |
import java.io.File; |
28 |
import java.text.DateFormat; |
29 |
import java.util.logging.Level; |
30 |
import java.util.zip.GZIPOutputStream; |
31 |
|
32 |
import org.jsampler.view.JSChannel; |
33 |
import org.jsampler.view.JSChannelsPane; |
34 |
|
35 |
import org.linuxsampler.lscp.AudioOutputChannel; |
36 |
import org.linuxsampler.lscp.AudioOutputDevice; |
37 |
import org.linuxsampler.lscp.Client; |
38 |
import org.linuxsampler.lscp.EffectParameter; |
39 |
import org.linuxsampler.lscp.FxSend; |
40 |
import org.linuxsampler.lscp.MidiInputDevice; |
41 |
import org.linuxsampler.lscp.MidiPort; |
42 |
import org.linuxsampler.lscp.Parameter; |
43 |
import org.linuxsampler.lscp.SamplerChannel; |
44 |
|
45 |
import org.w3c.dom.Document; |
46 |
import org.w3c.dom.Element; |
47 |
|
48 |
import static org.jsampler.CC.preferences; |
49 |
import static org.jsampler.JSI18n.i18n; |
50 |
|
51 |
/** |
52 |
* |
53 |
* @author Grigor Iliev |
54 |
*/ |
55 |
public class JSUtils { |
56 |
|
57 |
/** Forbids the instantiation of this class */ |
58 |
private |
59 |
JSUtils() { } |
60 |
|
61 |
/** |
62 |
* Checks whether the JSampler home directory is specified and exist. |
63 |
* If the JSampler home directory is not specifed, or is specified |
64 |
* but doesn't exist, a procedure of specifying a JSampler home |
65 |
* directory is initiated. |
66 |
* @see org.jsampler.view.JSMainFrame#installJSamplerHome |
67 |
*/ |
68 |
public static void |
69 |
checkJSamplerHome() { |
70 |
if(CC.getJSamplerHome() != null) { |
71 |
File f = new File(CC.getJSamplerHome()); |
72 |
if(f.exists() && f.isDirectory()) { |
73 |
return; |
74 |
} |
75 |
} |
76 |
|
77 |
CC.getMainFrame().installJSamplerHome(); |
78 |
} |
79 |
|
80 |
/** |
81 |
* Changes the JSampler's home directory and moves all files from |
82 |
* the old JSampler's home directory to the new one. If all files are |
83 |
* moved successfully, the old directory is deleted. |
84 |
* @param path The location of the new JSampler's home directory. If |
85 |
* the last directory in the path doesn't exist, it is created. |
86 |
*/ |
87 |
public static void |
88 |
changeJSamplerHome(String path) { |
89 |
File fNew = new File(path); |
90 |
if(fNew.exists() && fNew.isFile()) { |
91 |
CC.getViewConfig().showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
92 |
return; |
93 |
} |
94 |
|
95 |
if(!fNew.exists()) { |
96 |
if(!fNew.mkdir()) { |
97 |
String s = fNew.getAbsolutePath(); |
98 |
CC.getViewConfig().showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
99 |
return; |
100 |
} |
101 |
} |
102 |
|
103 |
if(CC.getJSamplerHome() == null || path.equals(CC.getJSamplerHome())) { |
104 |
CC.setJSamplerHome(fNew.getAbsolutePath()); |
105 |
return; |
106 |
} |
107 |
|
108 |
File fOld = new File(CC.getJSamplerHome()); |
109 |
if(!fOld.exists() || !fOld.isDirectory()) { |
110 |
CC.setJSamplerHome(fNew.getAbsolutePath()); |
111 |
return; |
112 |
} |
113 |
|
114 |
File[] files = fOld.listFiles(); |
115 |
boolean b = true; |
116 |
if(files != null) { |
117 |
String s = fNew.getAbsolutePath() + File.separator; |
118 |
for(File f : files) if(!f.renameTo(new File(s + f.getName()))) b = false; |
119 |
} |
120 |
|
121 |
if(b) fOld.delete(); |
122 |
CC.setJSamplerHome(fNew.getAbsolutePath()); |
123 |
} |
124 |
|
125 |
public static String |
126 |
exportInstrMapsToLscpScript() { |
127 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
128 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
129 |
sb.append(JSampler.VERSION).append("\r\n"); |
130 |
sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n"); |
131 |
|
132 |
Client lscpClient = new Client(true); |
133 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
134 |
lscpClient.setPrintOnlyModeOutputStream(out); |
135 |
|
136 |
exportInstrMapsToLscpScript(lscpClient); |
137 |
sb.append(out.toString()); |
138 |
out.reset(); |
139 |
|
140 |
return sb.toString(); |
141 |
} |
142 |
|
143 |
private static void |
144 |
exportInstrMapsToLscpScript(Client lscpClient) { |
145 |
try { |
146 |
lscpClient.removeAllMidiInstrumentMaps(); |
147 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
148 |
for(int i = 0; i < maps.length; i++) { |
149 |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
150 |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
151 |
} |
152 |
} catch(Exception e) { |
153 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
154 |
CC.getViewConfig().showErrorMessage(e); |
155 |
} |
156 |
} |
157 |
|
158 |
private static void |
159 |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
160 |
throws Exception { |
161 |
|
162 |
boolean b = preferences().getBoolProperty(JSPrefs.LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND); |
163 |
|
164 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
165 |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo(), b); |
166 |
} |
167 |
} |
168 |
|
169 |
public static String |
170 |
exportInstrMapsToText() { |
171 |
String nl = System.getProperty("line.separator"); |
172 |
StringBuffer sb = new StringBuffer(); |
173 |
|
174 |
|
175 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
176 |
for(int i = 0; i < maps.length; i++) { |
177 |
sb.append("MIDI Instrument Map: "); |
178 |
sb.append(maps[i].getName()).append(nl); |
179 |
exportInstrumentsToText(maps[i], sb); |
180 |
} |
181 |
|
182 |
String date = DateFormat.getDateInstance().format(new java.util.Date()); |
183 |
sb.append("Date: ").append(date).append(nl); |
184 |
sb.append("Exported by: JSampler - a java front-end for LinuxSampler, Version "); |
185 |
sb.append(JSampler.VERSION).append(nl); |
186 |
|
187 |
return sb.toString(); |
188 |
} |
189 |
|
190 |
private static void |
191 |
exportInstrumentsToText(MidiInstrumentMap map, StringBuffer sb) { |
192 |
int bank = -1; |
193 |
String nl = System.getProperty("line.separator"); |
194 |
int bnkOffset = preferences().getIntProperty(JSPrefs.FIRST_MIDI_BANK_NUMBER); |
195 |
int prgOffset = preferences().getIntProperty(JSPrefs.FIRST_MIDI_PROGRAM_NUMBER); |
196 |
|
197 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
198 |
int newBank = i.getInfo().getMidiBank(); |
199 |
if(newBank != bank) { |
200 |
bank = newBank; |
201 |
sb.append(nl).append("\tMIDI Bank "); |
202 |
sb.append(bank + bnkOffset).append(nl); |
203 |
} |
204 |
sb.append("\t[").append(bank + bnkOffset).append("] "); |
205 |
sb.append(i.getInfo().getMidiProgram() + prgOffset); |
206 |
sb.append(" - ").append(i.getName()).append(nl); |
207 |
} |
208 |
|
209 |
sb.append(nl); |
210 |
} |
211 |
|
212 |
public static String |
213 |
exportInstrMapsToHtml() { |
214 |
String nl = System.getProperty("line.separator"); |
215 |
StringBuffer sb = new StringBuffer("<html>").append(nl); |
216 |
|
217 |
sb.append("<head><title>MIDI Instrument Maps</title></head>"); |
218 |
|
219 |
sb.append("<body>").append(nl); |
220 |
sb.append("<h1>MIDI Instrument Maps</h1>").append(nl); |
221 |
|
222 |
String date = DateFormat.getDateInstance().format(new java.util.Date()); |
223 |
sb.append("Date: ").append(date).append("<br>").append(nl); |
224 |
sb.append("Exported by <a href=http://linuxsampler.org/jsampler/manual/html/jsampler.html>"); |
225 |
sb.append("JSampler</a> version "); |
226 |
sb.append(JSampler.VERSION).append("<br>").append(nl); |
227 |
|
228 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
229 |
|
230 |
sb.append("<ol>").append(nl); |
231 |
for(int i = 0; i < maps.length; i++) { |
232 |
String name = toHtmlEscapedText(maps[i].getName()); |
233 |
sb.append("<li><a href=#map-").append(i + 1).append(">"); |
234 |
sb.append(name).append("</a></li>").append(nl); |
235 |
} |
236 |
sb.append("</ol>").append(nl); |
237 |
|
238 |
for(int i = 0; i < maps.length; i++) { |
239 |
String s = toHtmlEscapedText(maps[i].getName()); |
240 |
sb.append("<h2><a name=map-").append(i + 1).append(">"); |
241 |
sb.append(s).append("</a></h2>").append(nl); |
242 |
exportInstrumentsToHtml(i, maps[i], sb); |
243 |
} |
244 |
|
245 |
sb.append(nl).append("</body>").append(nl).append("</html>"); |
246 |
return sb.toString(); |
247 |
} |
248 |
|
249 |
private static void |
250 |
exportInstrumentsToHtml(int mapId, MidiInstrumentMap map, StringBuffer sb) { |
251 |
int bank = -1; |
252 |
String nl = System.getProperty("line.separator"); |
253 |
int bnkOffset = preferences().getIntProperty(JSPrefs.FIRST_MIDI_BANK_NUMBER); |
254 |
int prgOffset = preferences().getIntProperty(JSPrefs.FIRST_MIDI_PROGRAM_NUMBER); |
255 |
|
256 |
sb.append("<ol>").append(nl); |
257 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
258 |
int newBank = i.getInfo().getMidiBank(); |
259 |
if(newBank != bank) { |
260 |
bank = newBank; |
261 |
String s = "map-" + (mapId + 1) + "-bank-" + (bank + bnkOffset); |
262 |
sb.append(nl).append("<li><a href=#").append(s); |
263 |
sb.append(">MIDI Bank "); |
264 |
sb.append(bank + bnkOffset).append("</a></li>").append(nl); |
265 |
} |
266 |
} |
267 |
sb.append("</ol>").append(nl); |
268 |
|
269 |
bank = -1; |
270 |
String bankName = ""; |
271 |
|
272 |
sb.append("<table border=0>").append(nl); |
273 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
274 |
int newBank = i.getInfo().getMidiBank(); |
275 |
if(newBank != bank) { |
276 |
bank = newBank; |
277 |
sb.append("</table>").append(nl); |
278 |
|
279 |
bankName = "map-" + (mapId + 1) + "-bank-" + (bank + bnkOffset); |
280 |
sb.append(nl).append("<h4><a name=").append(bankName); |
281 |
sb.append(">MIDI Bank "); |
282 |
sb.append(bank + bnkOffset).append("</a></h4>").append(nl); |
283 |
|
284 |
sb.append("<table border=0>").append(nl); |
285 |
} |
286 |
|
287 |
sb.append("<tr><td align='right'>"); |
288 |
sb.append(i.getInfo().getMidiProgram() + prgOffset).append(" - </td>"); |
289 |
String file = i.getInfo().getFilePath(); |
290 |
String tooltip = "File: " + file + ", Index: " + i.getInfo().getInstrumentIndex(); |
291 |
sb.append("<td><a title='").append(tooltip).append("'>"); |
292 |
String s = toHtmlEscapedText(i.getName()); |
293 |
sb.append(s).append("</a></td>"); |
294 |
|
295 |
sb.append("<td> <a href=#").append(bankName).append(">"); |
296 |
sb.append("[").append(bank + bnkOffset).append("]</a></td>").append(nl); |
297 |
sb.append("</tr>"); |
298 |
} |
299 |
sb.append("</table>").append(nl); |
300 |
|
301 |
sb.append(nl); |
302 |
} |
303 |
|
304 |
private static String |
305 |
toHtmlEscapedText(String s) { |
306 |
s = s.replaceAll("&", "&"); |
307 |
s = s.replaceAll("<", "<"); |
308 |
s = s.replaceAll(">", ">"); |
309 |
|
310 |
return s; |
311 |
} |
312 |
|
313 |
public static byte[] |
314 |
exportInstrMapsToRGD() { |
315 |
Document doc = DOMUtils.createEmptyDocument(); |
316 |
|
317 |
Element rgd = doc.createElement("rosegarden-data"); |
318 |
rgd.setAttribute("version", "1.7.2"); |
319 |
doc.appendChild(rgd); |
320 |
|
321 |
Element studio = doc.createElement("studio"); |
322 |
studio.setAttribute("thrufilter", "0"); |
323 |
studio.setAttribute("recordfilter", "0"); |
324 |
rgd.appendChild(studio); |
325 |
|
326 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
327 |
for(int i = 0; i < maps.length; i++) { |
328 |
Element dev = doc.createElement("device"); |
329 |
dev.setAttribute("id", String.valueOf(i)); |
330 |
dev.setAttribute("name", "LinuxSampler: " + maps[i].getName()); |
331 |
dev.setAttribute("type", "midi"); |
332 |
studio.appendChild(dev); |
333 |
|
334 |
Element el = doc.createElement("librarian"); |
335 |
el.setAttribute("name", "Grigor Iliev"); |
336 |
el.setAttribute("email", "grigor@grigoriliev.com"); |
337 |
dev.appendChild(el); |
338 |
|
339 |
exportInstrumentsToRGD(maps[i], dev); |
340 |
} |
341 |
|
342 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
343 |
DOMUtils.writeObject(doc, baos); |
344 |
|
345 |
// Hack to insert the file name in the archive |
346 |
byte[] data2 = null; |
347 |
try { |
348 |
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); |
349 |
GZIPOutputStream gzos = new GZIPOutputStream(baos2); |
350 |
gzos.write(baos.toByteArray()); |
351 |
gzos.finish(); |
352 |
byte[] data = baos2.toByteArray(); |
353 |
data[3] = 8; // File name |
354 |
byte[] fn = "x-rosegarden-device".getBytes("US-ASCII"); |
355 |
int fnsize = fn.length; |
356 |
data2 = new byte[data.length + fnsize + 1]; |
357 |
|
358 |
for(int i = 0; i < 10; i++) data2[i] = data[i]; |
359 |
for(int i = 0; i < fnsize; i++) data2[i + 10] = fn[i]; |
360 |
data2[10 + fnsize] = 0; |
361 |
for(int i = 10; i < data.length; i++) data2[i + fnsize + 1] = data[i]; |
362 |
|
363 |
} catch(Exception e) { |
364 |
e.printStackTrace(); |
365 |
} |
366 |
////////////// |
367 |
|
368 |
return data2; |
369 |
} |
370 |
|
371 |
private static void |
372 |
exportInstrumentsToRGD(MidiInstrumentMap map, Element el) { |
373 |
int bank = -1; |
374 |
int bnkOffset = preferences().getIntProperty(JSPrefs.FIRST_MIDI_BANK_NUMBER); |
375 |
Element elBank = null; |
376 |
|
377 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
378 |
int newBank = i.getInfo().getMidiBank(); |
379 |
if(newBank != bank) { |
380 |
bank = newBank; |
381 |
elBank = el.getOwnerDocument().createElement("bank"); |
382 |
elBank.setAttribute("name", "Bank " + (bank + bnkOffset)); |
383 |
elBank.setAttribute("msb", String.valueOf((bank >> 7) & 0x7f)); |
384 |
elBank.setAttribute("lsb", String.valueOf(bank & 0x7f)); |
385 |
el.appendChild(elBank); |
386 |
} |
387 |
|
388 |
Element elProgram = el.getOwnerDocument().createElement("program"); |
389 |
elProgram.setAttribute("id", String.valueOf(i.getInfo().getMidiProgram())); |
390 |
elProgram.setAttribute("name", i.getName()); |
391 |
|
392 |
elBank.appendChild(elProgram); |
393 |
} |
394 |
} |
395 |
|
396 |
public static String |
397 |
exportSessionToLscpScript() { |
398 |
CC.getSamplerModel().setModified(false); |
399 |
|
400 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
401 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
402 |
sb.append(JSampler.VERSION).append("\r\n"); |
403 |
sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n"); |
404 |
|
405 |
Client lscpClient = new Client(true); |
406 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
407 |
lscpClient.setPrintOnlyModeOutputStream(out); |
408 |
|
409 |
try { |
410 |
lscpClient.resetSampler(); |
411 |
sb.append(out.toString()); |
412 |
out.reset(); |
413 |
sb.append("\r\n"); |
414 |
lscpClient.setVolume(CC.getSamplerModel().getVolume()); |
415 |
sb.append(out.toString()); |
416 |
out.reset(); |
417 |
sb.append("\r\n"); |
418 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
419 |
|
420 |
MidiDeviceModel[] mDevs = CC.getSamplerModel().getMidiDevices(); |
421 |
for(int i = 0; i < mDevs.length; i++) { |
422 |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
423 |
sb.append(out.toString()); |
424 |
out.reset(); |
425 |
sb.append("\r\n"); |
426 |
} |
427 |
|
428 |
AudioDeviceModel[] aDevs = CC.getSamplerModel().getAudioDevices(); |
429 |
int fxInsts = 0; |
430 |
|
431 |
for(int i = 0; i < aDevs.length; i++) { |
432 |
fxInsts += exportAudioDeviceToLscpScript(aDevs[i], i, fxInsts, lscpClient); |
433 |
sb.append(out.toString()); |
434 |
out.reset(); |
435 |
sb.append("\r\n"); |
436 |
} |
437 |
|
438 |
boolean b = preferences().getBoolProperty(JSPrefs.EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT); |
439 |
if(b) { |
440 |
exportInstrMapsToLscpScript(lscpClient); |
441 |
sb.append(out.toString()); |
442 |
out.reset(); |
443 |
sb.append("\r\n"); |
444 |
} |
445 |
|
446 |
int chnId = 0; |
447 |
for(Object cp : CC.getMainFrame().getChannelsPaneList()) { |
448 |
for(JSChannel chn : ((JSChannelsPane)cp).getChannels()) { |
449 |
SamplerChannelModel scm; |
450 |
scm = CC.getSamplerModel().getChannelById(chn.getChannelId()); |
451 |
exportChannelToLscpScript(scm.getChannelInfo(), chnId, lscpClient); |
452 |
sb.append(out.toString()); |
453 |
out.reset(); |
454 |
|
455 |
sb.append("\r\n"); |
456 |
|
457 |
exportFxSendsToLscpScript(scm, chnId, lscpClient); |
458 |
sb.append(out.toString()); |
459 |
out.reset(); |
460 |
|
461 |
sb.append("\r\n"); |
462 |
|
463 |
chnId++; |
464 |
} |
465 |
} |
466 |
|
467 |
sb.append(CC.getViewConfig().exportSessionViewConfig()); |
468 |
|
469 |
return sb.toString(); |
470 |
} |
471 |
|
472 |
private static void |
473 |
exportMidiDeviceToLscpScript(MidiInputDevice mid, int devId, Client lscpCLient) { |
474 |
try { |
475 |
String s = mid.getDriverName(); |
476 |
lscpCLient.createMidiInputDevice(s, mid.getAdditionalParameters()); |
477 |
|
478 |
MidiPort[] mPorts = mid.getMidiPorts(); |
479 |
int l = mPorts.length; |
480 |
if(l != 1) lscpCLient.setMidiInputPortCount(devId, l); |
481 |
|
482 |
for(int i = 0; i < l; i++) { |
483 |
Parameter[] prms = mPorts[i].getAllParameters(); |
484 |
for(Parameter p : prms) { |
485 |
if(!p.isFixed() && p.getStringValue().length() > 0) |
486 |
lscpCLient.setMidiInputPortParameter(devId, i, p); |
487 |
} |
488 |
} |
489 |
} catch(Exception e) { |
490 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
491 |
} |
492 |
} |
493 |
|
494 |
/** |
495 |
* @param fxInsts The current number of created effect instances. |
496 |
* @return The number of effect instances in this audio device. |
497 |
*/ |
498 |
private static int |
499 |
exportAudioDeviceToLscpScript(AudioDeviceModel model, int devId, int fxInsts, Client lscpCLient) { |
500 |
int effectInstances = 0; |
501 |
|
502 |
try { |
503 |
AudioOutputDevice aod = model.getDeviceInfo(); |
504 |
String s = aod.getDriverName(); |
505 |
lscpCLient.createAudioOutputDevice(s, aod.getAllParameters()); |
506 |
|
507 |
AudioOutputChannel[] chns = aod.getAudioChannels(); |
508 |
|
509 |
for(int i = 0; i < chns.length; i++) { |
510 |
Parameter[] prms = chns[i].getAllParameters(); |
511 |
for(Parameter p : prms) { |
512 |
if(p.isFixed() || p.getStringValue().length() == 0); |
513 |
else lscpCLient.setAudioOutputChannelParameter(devId, i, p); |
514 |
} |
515 |
} |
516 |
|
517 |
for(int i = 0; i < model.getSendEffectChainCount(); i++) { |
518 |
lscpCLient.addSendEffectChain(devId); |
519 |
EffectChain chain = model.getSendEffectChain(i); |
520 |
for(int j = 0; j < chain.getEffectInstanceCount(); j++) { |
521 |
EffectInstance ei = chain.getEffectInstance(j); |
522 |
String sys = ei.getInfo().getSystem(); |
523 |
String mod = ei.getInfo().getModule(); |
524 |
String name = ei.getInfo().getName(); |
525 |
lscpCLient.createEffectInstance(sys, mod, name); |
526 |
int fxInstanceId = fxInsts + effectInstances++; |
527 |
lscpCLient.appendEffectInstance(devId, i, fxInstanceId); |
528 |
|
529 |
EffectParameter[] fxParams = ei.getInfo().getParameters(); |
530 |
for(EffectParameter p : fxParams) { |
531 |
lscpCLient.setEffectInstanceParameter ( |
532 |
fxInstanceId, p.getIndex(), p.getValue() |
533 |
); |
534 |
} |
535 |
} |
536 |
} |
537 |
} catch(Exception e) { |
538 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
539 |
} |
540 |
|
541 |
return effectInstances; |
542 |
} |
543 |
|
544 |
private static void |
545 |
exportChannelToLscpScript(SamplerChannel chn, int chnId, Client lscpCLient) { |
546 |
try { |
547 |
lscpCLient.addSamplerChannel(); |
548 |
|
549 |
SamplerModel sm = CC.getSamplerModel(); |
550 |
int id = chn.getMidiInputDevice(); |
551 |
if(id != -1) { |
552 |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
553 |
if(sm.getMidiDevice(i).getDeviceId() == id) { |
554 |
lscpCLient.setChannelMidiInputDevice(chnId, i); |
555 |
break; |
556 |
} |
557 |
} |
558 |
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
559 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
560 |
} |
561 |
|
562 |
if(chn.getEngine() != null) { |
563 |
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
564 |
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
565 |
int mapId = chn.getMidiInstrumentMapId(); |
566 |
lscpCLient.setChannelMidiInstrumentMap(chnId, mapId); |
567 |
} |
568 |
|
569 |
id = chn.getAudioOutputDevice(); |
570 |
if(id != -1) { |
571 |
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
572 |
if(sm.getAudioDevice(i).getDeviceId() == id) { |
573 |
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
574 |
break; |
575 |
} |
576 |
} |
577 |
|
578 |
Integer[] routing = chn.getAudioOutputRouting(); |
579 |
|
580 |
for(int j = 0; j < routing.length; j++) { |
581 |
int k = routing[j]; |
582 |
if(k == j) continue; |
583 |
|
584 |
lscpCLient.setChannelAudioOutputChannel(chnId, j, k); |
585 |
} |
586 |
} |
587 |
|
588 |
String s = chn.getInstrumentFile(); |
589 |
int i = chn.getInstrumentIndex(); |
590 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
591 |
|
592 |
if(chn.isMuted() && !chn.isMutedBySolo()) lscpCLient.setChannelMute(chnId, true); |
593 |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
594 |
} catch(Exception e) { |
595 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
596 |
} |
597 |
} |
598 |
|
599 |
private static void |
600 |
exportFxSendsToLscpScript(SamplerChannelModel scm, int chnId, Client lscpClient) { |
601 |
try { |
602 |
FxSend[] fxSends = scm.getFxSends(); |
603 |
|
604 |
for(int i = 0; i < fxSends.length; i++) { |
605 |
FxSend f = fxSends[i]; |
606 |
lscpClient.createFxSend(chnId, f.getMidiController(), f.getName()); |
607 |
lscpClient.setFxSendLevel(chnId, i, f.getLevel()); |
608 |
|
609 |
Integer[] r = f.getAudioOutputRouting(); |
610 |
for(int j = 0; j < r.length; j++) { |
611 |
lscpClient.setFxSendAudioOutputChannel(chnId, i, j, r[j]); |
612 |
} |
613 |
|
614 |
int chainId = f.getDestChainId(); |
615 |
int chainPos = f.getDestChainPos(); |
616 |
|
617 |
if(chainId != -1) { |
618 |
int aid = scm.getChannelInfo().getAudioOutputDevice(); |
619 |
AudioDeviceModel m = CC.getSamplerModel().getAudioDeviceById(aid); |
620 |
int idx = m.getSendEffectChainIndex(chainId); |
621 |
lscpClient.setFxSendEffect(chnId, i, idx, chainPos); |
622 |
} |
623 |
} |
624 |
} catch(Exception e) { |
625 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
626 |
} |
627 |
} |
628 |
} |