42 |
|
|
43 |
import javax.swing.Timer; |
import javax.swing.Timer; |
44 |
|
|
45 |
|
import javax.swing.event.ChangeEvent; |
46 |
|
import javax.swing.event.ChangeListener; |
47 |
|
|
48 |
import net.sf.juife.Task; |
import net.sf.juife.Task; |
49 |
import net.sf.juife.TaskQueue; |
import net.sf.juife.TaskQueue; |
50 |
|
|
62 |
|
|
63 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
64 |
import org.jsampler.view.JSProgress; |
import org.jsampler.view.JSProgress; |
65 |
|
import org.jsampler.view.JSViewConfig; |
66 |
import org.jsampler.view.InstrumentsDbTreeModel; |
import org.jsampler.view.InstrumentsDbTreeModel; |
67 |
|
|
68 |
import org.linuxsampler.lscp.AudioOutputChannel; |
import org.linuxsampler.lscp.AudioOutputChannel; |
80 |
import org.w3c.dom.Node; |
import org.w3c.dom.Node; |
81 |
|
|
82 |
import static org.jsampler.JSI18n.i18n; |
import static org.jsampler.JSI18n.i18n; |
83 |
|
import static org.jsampler.JSPrefs.MANUAL_SERVER_SELECT_ON_STARTUP; |
84 |
|
|
85 |
|
|
86 |
/** |
/** |
92 |
private static Handler handler; |
private static Handler handler; |
93 |
private static FileOutputStream fos; |
private static FileOutputStream fos; |
94 |
|
|
95 |
|
private static JSViewConfig viewConfig = null; |
96 |
private static JSMainFrame mainFrame = null; |
private static JSMainFrame mainFrame = null; |
97 |
private static JSProgress progress = null; |
private static JSProgress progress = null; |
98 |
|
|
136 |
scheduleTask(Task t) { |
scheduleTask(Task t) { |
137 |
while(getTaskQueue().removeTask(t)) { } |
while(getTaskQueue().removeTask(t)) { } |
138 |
|
|
|
if(getTaskQueue().getPendingTaskCount() == 0) { |
|
|
if(t.equals(getTaskQueue().getRunningTask())) return; |
|
|
} |
|
|
|
|
139 |
getTaskQueue().add(t); |
getTaskQueue().add(t); |
140 |
} |
} |
141 |
|
|
142 |
/** |
/** |
143 |
|
* Adds the specified task to the task queue only if the last |
144 |
|
* task in the is not equal to <code>t</code>. |
145 |
|
*/ |
146 |
|
public static void |
147 |
|
addTask(Task t) { |
148 |
|
Task[] tasks = getTaskQueue().getPendingTasks(); |
149 |
|
if(tasks.length > 0 && tasks[tasks.length - 1].equals(t)) return; |
150 |
|
getTaskQueue().add(t); |
151 |
|
} |
152 |
|
|
153 |
|
/** |
154 |
|
* Gets the configuration of the current view. |
155 |
|
*/ |
156 |
|
public static JSViewConfig |
157 |
|
getViewConfig() { return viewConfig; } |
158 |
|
|
159 |
|
private static JSPrefs |
160 |
|
preferences() { return getViewConfig().preferences(); } |
161 |
|
|
162 |
|
/** |
163 |
|
* Sets the configuration of the current view. |
164 |
|
*/ |
165 |
|
public static void |
166 |
|
setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; } |
167 |
|
|
168 |
|
/** |
169 |
* Returns the main window of this application. |
* Returns the main window of this application. |
170 |
* @return The main window of this application. |
* @return The main window of this application. |
171 |
*/ |
*/ |
247 |
|
|
248 |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
249 |
|
|
|
getClient().setServerAddress(Prefs.getLSAddress()); |
|
|
getClient().setServerPort(Prefs.getLSPort()); |
|
|
|
|
250 |
timer.setRepeats(false); |
timer.setRepeats(false); |
251 |
|
|
252 |
timer.addActionListener(new ActionListener() { |
timer.addActionListener(new ActionListener() { |
276 |
getClient().removeVoiceCountListener(getHandler()); |
getClient().removeVoiceCountListener(getHandler()); |
277 |
getClient().addVoiceCountListener(getHandler()); |
getClient().addVoiceCountListener(getHandler()); |
278 |
|
|
279 |
|
getClient().removeTotalStreamCountListener(getHandler()); |
280 |
|
getClient().addTotalStreamCountListener(getHandler()); |
281 |
|
|
282 |
getClient().removeTotalVoiceCountListener(getHandler()); |
getClient().removeTotalVoiceCountListener(getHandler()); |
283 |
getClient().addTotalVoiceCountListener(getHandler()); |
getClient().addTotalVoiceCountListener(getHandler()); |
284 |
|
|
321 |
checkJSamplerHome() { |
checkJSamplerHome() { |
322 |
if(getJSamplerHome() != null) { |
if(getJSamplerHome() != null) { |
323 |
File f = new File(getJSamplerHome()); |
File f = new File(getJSamplerHome()); |
324 |
if(f.isDirectory()) return; |
if(f.exists() && f.isDirectory()) { |
325 |
|
return; |
326 |
|
} |
327 |
} |
} |
328 |
|
|
329 |
CC.getMainFrame().installJSamplerHome(); |
CC.getMainFrame().installJSamplerHome(); |
339 |
public static void |
public static void |
340 |
changeJSamplerHome(String path) { |
changeJSamplerHome(String path) { |
341 |
File fNew = new File(path); |
File fNew = new File(path); |
342 |
if(fNew.isFile()) { |
if(fNew.exists() && fNew.isFile()) { |
343 |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
344 |
return; |
return; |
345 |
} |
} |
346 |
|
|
347 |
if(!fNew.isDirectory()) { |
if(!fNew.exists()) { |
348 |
if(!fNew.mkdir()) { |
if(!fNew.mkdir()) { |
349 |
String s = fNew.getAbsolutePath(); |
String s = fNew.getAbsolutePath(); |
350 |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
352 |
} |
} |
353 |
} |
} |
354 |
|
|
355 |
if(getJSamplerHome() == null) { |
if(getJSamplerHome() == null || path.equals(getJSamplerHome())) { |
356 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
357 |
return; |
return; |
358 |
} |
} |
359 |
|
|
360 |
File fOld = new File(getJSamplerHome()); |
File fOld = new File(getJSamplerHome()); |
361 |
if(!fOld.isDirectory()) { |
if(!fOld.exists() || !fOld.isDirectory()) { |
362 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
363 |
return; |
return; |
364 |
} |
} |
383 |
public static OrchestraListModel |
public static OrchestraListModel |
384 |
getOrchestras() { return orchestras; } |
getOrchestras() { return orchestras; } |
385 |
|
|
386 |
|
private final static ServerList servers = new ServerList(); |
387 |
|
|
388 |
|
/** Returns the server list. */ |
389 |
|
public static ServerList |
390 |
|
getServerList() { return servers; } |
391 |
|
|
392 |
|
private static ServerListListener serverListListener = new ServerListListener(); |
393 |
|
|
394 |
|
private static class ServerListListener implements ChangeListener { |
395 |
|
public void |
396 |
|
stateChanged(ChangeEvent e) { |
397 |
|
saveServerList(); |
398 |
|
} |
399 |
|
} |
400 |
|
|
401 |
|
private static final Vector<ChangeListener> idtmListeners = new Vector<ChangeListener>(); |
402 |
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
403 |
|
|
404 |
/** |
/** |
405 |
* Gets the tree model of the instruments database. |
* Gets the tree model of the instruments database. |
406 |
* If the currently used view doesn't have instruments |
* If the currently used view doesn't have instruments |
407 |
* database support the tree model is initialized on first use. |
* database support the tree model is initialized on first use. |
408 |
* @return The tree model of the instruments database or |
* @return The tree model of the instruments database or |
409 |
* <code>null</code> if the backend doesn't have instruments database support. |
* <code>null</code> if the backend doesn't have instruments database support. |
410 |
* @see org.jsampler.view.JSMainFrame#getInstrumentsDbSupport |
* @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport |
411 |
*/ |
*/ |
412 |
public static InstrumentsDbTreeModel |
public static InstrumentsDbTreeModel |
413 |
getInstrumentsDbTreeModel() { |
getInstrumentsDbTreeModel() { |
414 |
|
if(CC.getSamplerModel().getServerInfo() == null) return null; |
415 |
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
416 |
|
|
417 |
if(instrumentsDbTreeModel == null) { |
if(instrumentsDbTreeModel == null) { |
418 |
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
419 |
|
for(ChangeListener l : idtmListeners) l.stateChanged(null); |
420 |
} |
} |
421 |
|
|
422 |
return instrumentsDbTreeModel; |
return instrumentsDbTreeModel; |
423 |
} |
} |
424 |
|
|
425 |
|
public static void |
426 |
|
addInstrumentsDbChangeListener(ChangeListener l) { |
427 |
|
idtmListeners.add(l); |
428 |
|
} |
429 |
|
|
430 |
|
public static void |
431 |
|
removeInstrumentsDbChangeListener(ChangeListener l) { |
432 |
|
idtmListeners.remove(l); |
433 |
|
} |
434 |
|
|
435 |
|
private static final LostFilesModel lostFilesModel = new LostFilesModel(); |
436 |
|
|
437 |
|
public static LostFilesModel |
438 |
|
getLostFilesModel() { return lostFilesModel; } |
439 |
|
|
440 |
/** |
/** |
441 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
442 |
* If file with name <code>orchestras.xml.bkp</code> exist in the JSampler's home |
* If file with name <code>orchestras.xml.bkp</code> exist in the JSampler's home |
448 |
loadOrchestras() { |
loadOrchestras() { |
449 |
if(getJSamplerHome() == null) return; |
if(getJSamplerHome() == null) return; |
450 |
|
|
|
//TODO: This should be removed in the next release (including loadOrchestras0()) |
|
|
File f2 = new File(getJSamplerHome() + File.separator + "orchestras.xml"); |
|
|
if(!f2.isFile()) { |
|
|
loadOrchestras0(); |
|
|
saveOrchestras(); |
|
|
return; |
|
|
} |
|
|
/////// |
|
|
|
|
451 |
try { |
try { |
452 |
String s = getJSamplerHome(); |
String s = getJSamplerHome(); |
|
if(s == null) return; |
|
453 |
|
|
454 |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
455 |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
462 |
} catch(Exception x) { |
} catch(Exception x) { |
463 |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
464 |
} |
} |
465 |
|
|
466 |
|
getOrchestras().addOrchestraListListener(getHandler()); |
467 |
} |
} |
468 |
|
|
469 |
|
|
480 |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
481 |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
482 |
} |
} |
|
getOrchestras().addOrchestraListListener(getHandler()); |
|
|
} |
|
|
|
|
|
private static void |
|
|
loadOrchestras0() { |
|
|
String s = Prefs.getOrchestras(); |
|
|
if(s == null) return; |
|
|
|
|
|
ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); |
|
|
Document doc = DOMUtils.readObject(bais); |
|
|
|
|
|
try { getOrchestras().readObject(doc.getDocumentElement()); } |
|
|
catch(Exception x) { HF.showErrorMessage(x, "Loading orchestras: "); } |
|
483 |
} |
} |
484 |
|
|
485 |
private static void |
private static void |
514 |
} |
} |
515 |
|
|
516 |
/** |
/** |
517 |
|
* Loads the servers' info described in <code><jsampler_home>/servers.xml</code>. |
518 |
|
* If file with name <code>servers.xml.bkp</code> exist in the JSampler's home |
519 |
|
* directory, this means that the last save has failed. In that case a recovery file |
520 |
|
* <code>servers.xml.rec</code> is created and a recovery procedure |
521 |
|
* will be initiated. |
522 |
|
*/ |
523 |
|
public static void |
524 |
|
loadServerList() { |
525 |
|
if(getJSamplerHome() == null) return; |
526 |
|
|
527 |
|
try { |
528 |
|
String s = getJSamplerHome(); |
529 |
|
|
530 |
|
File f = new File(s + File.separator + "servers.xml.bkp"); |
531 |
|
if(f.isFile()) HF.createBackup("servers.xml.bkp", "servers.xml.rec"); |
532 |
|
|
533 |
|
FileInputStream fis; |
534 |
|
fis = new FileInputStream(s + File.separator + "servers.xml"); |
535 |
|
|
536 |
|
loadServerList(fis); |
537 |
|
fis.close(); |
538 |
|
} catch(Exception x) { |
539 |
|
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
540 |
|
} |
541 |
|
|
542 |
|
getServerList().addChangeListener(serverListListener); |
543 |
|
|
544 |
|
/* We should have at least one server to connect. */ |
545 |
|
if(getServerList().getServerCount() == 0) { |
546 |
|
Server server = new Server(); |
547 |
|
server.setName("127.0.0.1:8888"); |
548 |
|
server.setAddress("127.0.0.1"); |
549 |
|
server.setPort(8888); |
550 |
|
getServerList().addServer(server); |
551 |
|
} |
552 |
|
} |
553 |
|
|
554 |
|
|
555 |
|
private static void |
556 |
|
loadServerList(InputStream in) { |
557 |
|
Document doc = DOMUtils.readObject(in); |
558 |
|
|
559 |
|
try { getServerList().readObject(doc.getDocumentElement()); } |
560 |
|
catch(Exception x) { |
561 |
|
HF.showErrorMessage(x, "Loading server list: "); |
562 |
|
return; |
563 |
|
} |
564 |
|
} |
565 |
|
|
566 |
|
private static void |
567 |
|
saveServerList() { |
568 |
|
try { |
569 |
|
String s = getJSamplerHome(); |
570 |
|
if(s == null) return; |
571 |
|
|
572 |
|
HF.createBackup("servers.xml", "servers.xml.bkp"); |
573 |
|
|
574 |
|
FileOutputStream fos; |
575 |
|
fos = new FileOutputStream(s + File.separator + "servers.xml", false); |
576 |
|
|
577 |
|
Document doc = DOMUtils.createEmptyDocument(); |
578 |
|
|
579 |
|
Node node = doc.createElement("temp"); |
580 |
|
doc.appendChild(node); |
581 |
|
|
582 |
|
getServerList().writeObject(doc, doc.getDocumentElement()); |
583 |
|
|
584 |
|
doc.replaceChild(node.getFirstChild(), node); |
585 |
|
|
586 |
|
DOMUtils.writeObject(doc, fos); |
587 |
|
|
588 |
|
fos.close(); |
589 |
|
|
590 |
|
HF.deleteFile("servers.xml.bkp"); |
591 |
|
} catch(Exception x) { |
592 |
|
HF.showErrorMessage(x, "Saving server list: "); |
593 |
|
return; |
594 |
|
} |
595 |
|
} |
596 |
|
|
597 |
|
/** |
598 |
* The exit point of the application which ensures clean exit with default exit status 0. |
* The exit point of the application which ensures clean exit with default exit status 0. |
599 |
* @see #cleanExit(int i) |
* @see #cleanExit(int i) |
600 |
*/ |
*/ |
650 |
getSamplerModel() { return samplerModel; } |
getSamplerModel() { return samplerModel; } |
651 |
|
|
652 |
/** |
/** |
653 |
|
* Connects to LinuxSampler. |
654 |
|
*/ |
655 |
|
public static void |
656 |
|
connect() { initSamplerModel(); } |
657 |
|
|
658 |
|
/** |
659 |
* Reconnects to LinuxSampler. |
* Reconnects to LinuxSampler. |
660 |
*/ |
*/ |
661 |
public static void |
public static void |
662 |
reconnect() { |
reconnect() { initSamplerModel(getCurrentServer()); } |
663 |
initSamplerModel(); |
|
664 |
fireReconnectEvent(); |
private static Server currentServer = null; |
|
} |
|
665 |
|
|
666 |
/** |
/** |
667 |
* This method updates the information about the backend state. |
* Gets the server, to which the frontend is going to connect |
668 |
|
* or is already connected. |
669 |
|
*/ |
670 |
|
public static Server |
671 |
|
getCurrentServer() { return currentServer; } |
672 |
|
|
673 |
|
/** |
674 |
|
* Sets the current server. |
675 |
*/ |
*/ |
676 |
public static void |
public static void |
677 |
|
setCurrentServer(Server server) { currentServer = server; } |
678 |
|
|
679 |
|
/** |
680 |
|
* This method updates the information about the backend state. |
681 |
|
*/ |
682 |
|
private static void |
683 |
initSamplerModel() { |
initSamplerModel() { |
684 |
|
Server srv = getMainFrame().getServer(); |
685 |
|
if(srv == null) return; |
686 |
|
initSamplerModel(srv); |
687 |
|
} |
688 |
|
|
689 |
|
/** |
690 |
|
* This method updates the information about the backend state. |
691 |
|
*/ |
692 |
|
private static void |
693 |
|
initSamplerModel(Server srv) { |
694 |
|
setCurrentServer(srv); |
695 |
|
final SetServerAddress ssa = new SetServerAddress(srv.getAddress(), srv.getPort()); |
696 |
|
|
697 |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
698 |
|
|
699 |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
704 |
|
|
705 |
model.setServerInfo(gsi.getResult()); |
model.setServerInfo(gsi.getResult()); |
706 |
|
|
707 |
if(CC.getMainFrame().getInstrumentsDbSupport()) { |
if(CC.getViewConfig().getInstrumentsDbSupport()) { |
708 |
getInstrumentsDbTreeModel(); |
getInstrumentsDbTreeModel(); |
709 |
} |
} |
710 |
} |
} |
770 |
gfs.addTaskListener(new GetFxSendsListener()); |
gfs.addTaskListener(new GetFxSendsListener()); |
771 |
getTaskQueue().add(gfs); |
getTaskQueue().add(gfs); |
772 |
} |
} |
773 |
|
|
774 |
|
// TODO: This should be done after the fx sends are set |
775 |
|
//CC.getSamplerModel().setModified(false); |
776 |
} |
} |
777 |
}); |
}); |
778 |
|
|
781 |
cnt.addTaskListener(new TaskListener() { |
cnt.addTaskListener(new TaskListener() { |
782 |
public void |
public void |
783 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
784 |
if(cnt.doneWithErrors()) return; |
if(cnt.doneWithErrors()) { |
785 |
|
setCurrentServer(null); |
786 |
|
retryToConnect(); |
787 |
|
return; |
788 |
|
} |
789 |
|
|
790 |
getTaskQueue().add(gsi); |
getTaskQueue().add(gsi); |
791 |
getTaskQueue().add(gaod); |
getTaskQueue().add(gaod); |
795 |
getTaskQueue().add(mgim); |
getTaskQueue().add(mgim); |
796 |
getTaskQueue().add(new Midi.UpdateDevices()); |
getTaskQueue().add(new Midi.UpdateDevices()); |
797 |
getTaskQueue().add(new Audio.UpdateDevices()); |
getTaskQueue().add(new Audio.UpdateDevices()); |
798 |
getTaskQueue().add(uc); |
addTask(uc); |
799 |
} |
} |
800 |
}); |
}); |
801 |
getTaskQueue().add(cnt); |
|
802 |
|
ssa.addTaskListener(new TaskListener() { |
803 |
|
public void |
804 |
|
taskPerformed(TaskEvent e) { |
805 |
|
CC.getTaskQueue().add(cnt); |
806 |
|
} |
807 |
|
}); |
808 |
|
|
809 |
|
getSamplerModel().reset(); |
810 |
|
if(instrumentsDbTreeModel != null) { |
811 |
|
instrumentsDbTreeModel.reset(); |
812 |
|
instrumentsDbTreeModel = null; |
813 |
|
} |
814 |
|
|
815 |
|
getTaskQueue().removePendingTasks(); |
816 |
|
getTaskQueue().add(ssa); |
817 |
|
|
818 |
|
fireReconnectEvent(); |
819 |
|
} |
820 |
|
|
821 |
|
private static void |
822 |
|
retryToConnect() { |
823 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
824 |
|
public void |
825 |
|
run() { changeBackend(); } |
826 |
|
}); |
827 |
|
} |
828 |
|
|
829 |
|
public static void |
830 |
|
changeBackend() { |
831 |
|
Server s = getMainFrame().getServer(true); |
832 |
|
if(s != null) initSamplerModel(s); |
833 |
} |
} |
834 |
|
|
835 |
private static class GetFxSendsListener implements TaskListener { |
private static class GetFxSendsListener implements TaskListener { |
888 |
|
|
889 |
public static String |
public static String |
890 |
exportSessionToLscpScript() { |
exportSessionToLscpScript() { |
891 |
|
CC.getSamplerModel().setModified(false); |
892 |
|
|
893 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
StringBuffer sb = new StringBuffer("# Exported by: "); |
894 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
895 |
sb.append(JSampler.VERSION).append("\r\n"); |
sb.append(JSampler.VERSION).append("\r\n"); |
926 |
sb.append("\r\n"); |
sb.append("\r\n"); |
927 |
} |
} |
928 |
|
|
929 |
|
exportInstrMapsToLscpScript(lscpClient); |
930 |
|
sb.append(out.toString()); |
931 |
|
out.reset(); |
932 |
|
sb.append("\r\n"); |
933 |
|
|
934 |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
935 |
|
|
936 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
937 |
SamplerChannelModel scm = getSamplerModel().getChannelById(i); |
SamplerChannelModel scm = channels[i]; |
938 |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
939 |
sb.append(out.toString()); |
sb.append(out.toString()); |
940 |
out.reset(); |
out.reset(); |
948 |
sb.append("\r\n"); |
sb.append("\r\n"); |
949 |
} |
} |
950 |
|
|
|
exportInstrMapsToLscpScript(lscpClient); |
|
|
sb.append(out.toString()); |
|
|
out.reset(); |
|
|
|
|
951 |
return sb.toString(); |
return sb.toString(); |
952 |
} |
} |
953 |
|
|
998 |
try { |
try { |
999 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
1000 |
|
|
1001 |
int i = chn.getMidiInputDevice(); |
SamplerModel sm = CC.getSamplerModel(); |
1002 |
if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i); |
int id = chn.getMidiInputDevice(); |
1003 |
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
if(id != -1) { |
1004 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
1005 |
|
if(sm.getMidiDevice(i).getDeviceId() == id) { |
1006 |
i = chn.getAudioOutputDevice(); |
lscpCLient.setChannelMidiInputDevice(chnId, i); |
1007 |
if(i != -1) { |
break; |
1008 |
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
} |
1009 |
|
} |
1010 |
|
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
1011 |
|
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
1012 |
|
} |
1013 |
|
|
1014 |
|
if(chn.getEngine() != null) { |
1015 |
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
1016 |
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
1017 |
|
int mapId = chn.getMidiInstrumentMapId(); |
1018 |
|
lscpCLient.setChannelMidiInstrumentMap(chnId, mapId); |
1019 |
|
} |
1020 |
|
|
1021 |
|
id = chn.getAudioOutputDevice(); |
1022 |
|
if(id != -1) { |
1023 |
|
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
1024 |
|
if(sm.getAudioDevice(i).getDeviceId() == id) { |
1025 |
|
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
1026 |
|
break; |
1027 |
|
} |
1028 |
|
} |
1029 |
|
|
1030 |
Integer[] routing = chn.getAudioOutputRouting(); |
Integer[] routing = chn.getAudioOutputRouting(); |
1031 |
|
|
1032 |
for(int j = 0; j < routing.length; j++) { |
for(int j = 0; j < routing.length; j++) { |
1037 |
} |
} |
1038 |
} |
} |
1039 |
|
|
|
if(chn.getEngine() != null) { |
|
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
|
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
|
|
} |
|
|
|
|
1040 |
String s = chn.getInstrumentFile(); |
String s = chn.getInstrumentFile(); |
1041 |
i = chn.getInstrumentIndex(); |
int i = chn.getInstrumentIndex(); |
1042 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
1043 |
|
|
1044 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
1067 |
} |
} |
1068 |
} |
} |
1069 |
|
|
1070 |
|
public static void |
1071 |
|
scheduleInTaskQueue(final Runnable r) { |
1072 |
|
Task dummy = new Global.DummyTask(); |
1073 |
|
dummy.addTaskListener(new TaskListener() { |
1074 |
|
public void |
1075 |
|
taskPerformed(TaskEvent e) { |
1076 |
|
javax.swing.SwingUtilities.invokeLater(r); |
1077 |
|
} |
1078 |
|
}); |
1079 |
|
|
1080 |
|
CC.getTaskQueue().add(dummy); |
1081 |
|
} |
1082 |
|
|
1083 |
|
public static boolean |
1084 |
|
verifyConnection() { |
1085 |
|
if(getCurrentServer() == null) { |
1086 |
|
HF.showErrorMessage(i18n.getError("CC.notConnected")); |
1087 |
|
return false; |
1088 |
|
} |
1089 |
|
|
1090 |
|
return true; |
1091 |
|
} |
1092 |
|
|
1093 |
|
|
1094 |
private final static EventHandler eventHandler = new EventHandler(); |
private final static EventHandler eventHandler = new EventHandler(); |
1095 |
|
|
1098 |
|
|
1099 |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
1100 |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
1101 |
TotalVoiceCountListener, TaskQueueListener, OrchestraListener, |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
1102 |
ListListener<OrchestraModel>, MidiInstrumentCountListener, |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
1103 |
MidiInstrumentInfoListener, GlobalInfoListener { |
MidiInstrumentInfoListener, GlobalInfoListener { |
1104 |
|
|
1105 |
/** Invoked when the number of channels has changed. */ |
/** Invoked when the number of channels has changed. */ |
1106 |
public void |
public void |
1107 |
channelCountChanged( ChannelCountEvent e) { |
channelCountChanged( ChannelCountEvent e) { |
1108 |
getTaskQueue().add(new UpdateChannels()); |
addTask(new UpdateChannels()); |
1109 |
} |
} |
1110 |
|
|
1111 |
/** Invoked when changes to the sampler channel has occured. */ |
/** Invoked when changes to the sampler channel has occured. */ |
1204 |
scm.setVoiceCount(e.getVoiceCount()); |
scm.setVoiceCount(e.getVoiceCount()); |
1205 |
} |
} |
1206 |
|
|
1207 |
|
/** Invoked when the total number of active streams has changed. */ |
1208 |
|
public void |
1209 |
|
totalStreamCountChanged(TotalStreamCountEvent e) { |
1210 |
|
getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount()); |
1211 |
|
} |
1212 |
|
|
1213 |
/** Invoked when the total number of active voices has changed. */ |
/** Invoked when the total number of active voices has changed. */ |
1214 |
public void |
public void |
1215 |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
1219 |
/** Invoked when the number of MIDI instruments in a MIDI instrument map is changed. */ |
/** Invoked when the number of MIDI instruments in a MIDI instrument map is changed. */ |
1220 |
public void |
public void |
1221 |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
1222 |
getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId())); |
scheduleTask(new Midi.UpdateInstruments(e.getMapId())); |
1223 |
} |
} |
1224 |
|
|
1225 |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
1253 |
case TASK_DONE: |
case TASK_DONE: |
1254 |
EnhancedTask t = (EnhancedTask)e.getSource(); |
EnhancedTask t = (EnhancedTask)e.getSource(); |
1255 |
if(t.doneWithErrors() && !t.isStopped()) { |
if(t.doneWithErrors() && !t.isStopped()) { |
1256 |
if(t.getErrorDetails() == null) { |
showError(t); |
|
HF.showErrorMessage(t.getErrorMessage()); |
|
|
} else { |
|
|
getMainFrame().showDetailedErrorMessage ( |
|
|
getMainFrame(), |
|
|
t.getErrorMessage(), |
|
|
t.getErrorDetails() |
|
|
); |
|
|
} |
|
1257 |
} |
} |
1258 |
break; |
break; |
1259 |
case NOT_IDLE: |
case NOT_IDLE: |
1266 |
} |
} |
1267 |
} |
} |
1268 |
|
|
1269 |
|
private void |
1270 |
|
showError(final Task t) { |
1271 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
1272 |
|
public void |
1273 |
|
run() { |
1274 |
|
if(t.getErrorDetails() == null) { |
1275 |
|
HF.showErrorMessage(t.getErrorMessage()); |
1276 |
|
} else { |
1277 |
|
getMainFrame().showDetailedErrorMessage ( |
1278 |
|
getMainFrame(), |
1279 |
|
t.getErrorMessage(), |
1280 |
|
t.getErrorDetails() |
1281 |
|
); |
1282 |
|
} |
1283 |
|
} |
1284 |
|
}); |
1285 |
|
} |
1286 |
|
|
1287 |
/** Invoked when the name of orchestra is changed. */ |
/** Invoked when the name of orchestra is changed. */ |
1288 |
public void |
public void |
1289 |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |