1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
25 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
27 |
|
|
|
import java.io.ByteArrayInputStream; |
|
28 |
import java.io.ByteArrayOutputStream; |
import java.io.ByteArrayOutputStream; |
29 |
import java.io.File; |
import java.io.File; |
30 |
import java.io.FileInputStream; |
import java.io.FileInputStream; |
41 |
|
|
42 |
import javax.swing.Timer; |
import javax.swing.Timer; |
43 |
|
|
44 |
|
import javax.swing.event.ChangeEvent; |
45 |
|
import javax.swing.event.ChangeListener; |
46 |
|
|
47 |
import net.sf.juife.Task; |
import net.sf.juife.Task; |
48 |
import net.sf.juife.TaskQueue; |
import net.sf.juife.TaskQueue; |
49 |
|
|
134 |
scheduleTask(Task t) { |
scheduleTask(Task t) { |
135 |
while(getTaskQueue().removeTask(t)) { } |
while(getTaskQueue().removeTask(t)) { } |
136 |
|
|
|
if(getTaskQueue().getPendingTaskCount() == 0) { |
|
|
if(t.equals(getTaskQueue().getRunningTask())) return; |
|
|
} |
|
|
|
|
137 |
getTaskQueue().add(t); |
getTaskQueue().add(t); |
138 |
} |
} |
139 |
|
|
140 |
/** |
/** |
141 |
|
* Adds the specified task to the task queue only if the last |
142 |
|
* task in the is not equal to <code>t</code>. |
143 |
|
*/ |
144 |
|
public static void |
145 |
|
addTask(Task t) { |
146 |
|
Task[] tasks = getTaskQueue().getPendingTasks(); |
147 |
|
if(tasks.length > 0 && tasks[tasks.length - 1].equals(t)) return; |
148 |
|
getTaskQueue().add(t); |
149 |
|
} |
150 |
|
|
151 |
|
/** |
152 |
* Gets the configuration of the current view. |
* Gets the configuration of the current view. |
153 |
*/ |
*/ |
154 |
public static JSViewConfig |
public static JSViewConfig |
155 |
getViewConfig() { return viewConfig; } |
getViewConfig() { return viewConfig; } |
156 |
|
|
157 |
|
public static JSPrefs |
158 |
|
preferences() { return getViewConfig().preferences(); } |
159 |
|
|
160 |
/** |
/** |
161 |
* Sets the configuration of the current view. |
* Sets the configuration of the current view. |
162 |
*/ |
*/ |
241 |
run() { if(handler != null) handler.flush(); } |
run() { if(handler != null) handler.flush(); } |
242 |
}, 1000, 1000); |
}, 1000, 1000); |
243 |
|
|
244 |
CC.getLogger().fine("CC.jsStarted"); |
getLogger().fine("CC.jsStarted"); |
245 |
|
|
246 |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
247 |
|
|
|
getClient().setServerAddress(Prefs.getLSAddress()); |
|
|
getClient().setServerPort(Prefs.getLSPort()); |
|
|
|
|
248 |
timer.setRepeats(false); |
timer.setRepeats(false); |
249 |
|
|
250 |
timer.addActionListener(new ActionListener() { |
timer.addActionListener(new ActionListener() { |
306 |
|
|
307 |
getClient().removeGlobalInfoListener(getHandler()); |
getClient().removeGlobalInfoListener(getHandler()); |
308 |
getClient().addGlobalInfoListener(getHandler()); |
getClient().addGlobalInfoListener(getHandler()); |
309 |
|
|
310 |
|
getClient().removeChannelMidiDataListener(getHandler()); |
311 |
|
getClient().addChannelMidiDataListener(getHandler()); |
312 |
} |
} |
313 |
|
|
314 |
/** |
/** |
327 |
} |
} |
328 |
} |
} |
329 |
|
|
330 |
CC.getMainFrame().installJSamplerHome(); |
getMainFrame().installJSamplerHome(); |
331 |
} |
} |
332 |
|
|
333 |
/** |
/** |
384 |
public static OrchestraListModel |
public static OrchestraListModel |
385 |
getOrchestras() { return orchestras; } |
getOrchestras() { return orchestras; } |
386 |
|
|
387 |
|
private final static ServerList servers = new ServerList(); |
388 |
|
|
389 |
|
/** Returns the server list. */ |
390 |
|
public static ServerList |
391 |
|
getServerList() { return servers; } |
392 |
|
|
393 |
|
private static ServerListListener serverListListener = new ServerListListener(); |
394 |
|
|
395 |
|
private static class ServerListListener implements ChangeListener { |
396 |
|
public void |
397 |
|
stateChanged(ChangeEvent e) { |
398 |
|
saveServerList(); |
399 |
|
} |
400 |
|
} |
401 |
|
|
402 |
|
private static final Vector<ChangeListener> idtmListeners = new Vector<ChangeListener>(); |
403 |
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
404 |
|
|
405 |
/** |
/** |
406 |
* Gets the tree model of the instruments database. |
* Gets the tree model of the instruments database. |
407 |
* If the currently used view doesn't have instruments |
* If the currently used view doesn't have instruments |
412 |
*/ |
*/ |
413 |
public static InstrumentsDbTreeModel |
public static InstrumentsDbTreeModel |
414 |
getInstrumentsDbTreeModel() { |
getInstrumentsDbTreeModel() { |
415 |
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
if(getSamplerModel().getServerInfo() == null) return null; |
416 |
|
if(!getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
417 |
|
|
418 |
if(instrumentsDbTreeModel == null) { |
if(instrumentsDbTreeModel == null) { |
419 |
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
420 |
|
for(ChangeListener l : idtmListeners) l.stateChanged(null); |
421 |
} |
} |
422 |
|
|
423 |
return instrumentsDbTreeModel; |
return instrumentsDbTreeModel; |
424 |
} |
} |
425 |
|
|
426 |
|
public static void |
427 |
|
addInstrumentsDbChangeListener(ChangeListener l) { |
428 |
|
idtmListeners.add(l); |
429 |
|
} |
430 |
|
|
431 |
|
public static void |
432 |
|
removeInstrumentsDbChangeListener(ChangeListener l) { |
433 |
|
idtmListeners.remove(l); |
434 |
|
} |
435 |
|
|
436 |
|
private static final LostFilesModel lostFilesModel = new LostFilesModel(); |
437 |
|
|
438 |
|
public static LostFilesModel |
439 |
|
getLostFilesModel() { return lostFilesModel; } |
440 |
|
|
441 |
/** |
/** |
442 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
443 |
* 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 |
451 |
|
|
452 |
try { |
try { |
453 |
String s = getJSamplerHome(); |
String s = getJSamplerHome(); |
|
if(s == null) return; |
|
|
getOrchestras().addOrchestraListListener(getHandler()); |
|
454 |
|
|
455 |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
456 |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
463 |
} catch(Exception x) { |
} catch(Exception x) { |
464 |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
465 |
} |
} |
466 |
|
|
467 |
|
getOrchestras().addOrchestraListListener(getHandler()); |
468 |
} |
} |
469 |
|
|
470 |
|
|
515 |
} |
} |
516 |
|
|
517 |
/** |
/** |
518 |
|
* Loads the servers' info described in <code><jsampler_home>/servers.xml</code>. |
519 |
|
* If file with name <code>servers.xml.bkp</code> exist in the JSampler's home |
520 |
|
* directory, this means that the last save has failed. In that case a recovery file |
521 |
|
* <code>servers.xml.rec</code> is created and a recovery procedure |
522 |
|
* will be initiated. |
523 |
|
*/ |
524 |
|
public static void |
525 |
|
loadServerList() { |
526 |
|
if(getJSamplerHome() == null) return; |
527 |
|
|
528 |
|
try { |
529 |
|
String s = getJSamplerHome(); |
530 |
|
|
531 |
|
File f = new File(s + File.separator + "servers.xml.bkp"); |
532 |
|
if(f.isFile()) HF.createBackup("servers.xml.bkp", "servers.xml.rec"); |
533 |
|
|
534 |
|
FileInputStream fis; |
535 |
|
fis = new FileInputStream(s + File.separator + "servers.xml"); |
536 |
|
|
537 |
|
loadServerList(fis); |
538 |
|
fis.close(); |
539 |
|
} catch(Exception x) { |
540 |
|
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
541 |
|
} |
542 |
|
|
543 |
|
getServerList().addChangeListener(serverListListener); |
544 |
|
|
545 |
|
/* We should have at least one server to connect. */ |
546 |
|
if(getServerList().getServerCount() == 0) { |
547 |
|
Server server = new Server(); |
548 |
|
server.setName("127.0.0.1:8888"); |
549 |
|
server.setAddress("127.0.0.1"); |
550 |
|
server.setPort(8888); |
551 |
|
getServerList().addServer(server); |
552 |
|
} |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
|
private static void |
557 |
|
loadServerList(InputStream in) { |
558 |
|
Document doc = DOMUtils.readObject(in); |
559 |
|
|
560 |
|
try { getServerList().readObject(doc.getDocumentElement()); } |
561 |
|
catch(Exception x) { |
562 |
|
HF.showErrorMessage(x, "Loading server list: "); |
563 |
|
return; |
564 |
|
} |
565 |
|
} |
566 |
|
|
567 |
|
private static void |
568 |
|
saveServerList() { |
569 |
|
try { |
570 |
|
String s = getJSamplerHome(); |
571 |
|
if(s == null) return; |
572 |
|
|
573 |
|
HF.createBackup("servers.xml", "servers.xml.bkp"); |
574 |
|
|
575 |
|
FileOutputStream fos; |
576 |
|
fos = new FileOutputStream(s + File.separator + "servers.xml", false); |
577 |
|
|
578 |
|
Document doc = DOMUtils.createEmptyDocument(); |
579 |
|
|
580 |
|
Node node = doc.createElement("temp"); |
581 |
|
doc.appendChild(node); |
582 |
|
|
583 |
|
getServerList().writeObject(doc, doc.getDocumentElement()); |
584 |
|
|
585 |
|
doc.replaceChild(node.getFirstChild(), node); |
586 |
|
|
587 |
|
DOMUtils.writeObject(doc, fos); |
588 |
|
|
589 |
|
fos.close(); |
590 |
|
|
591 |
|
HF.deleteFile("servers.xml.bkp"); |
592 |
|
} catch(Exception x) { |
593 |
|
HF.showErrorMessage(x, "Saving server list: "); |
594 |
|
return; |
595 |
|
} |
596 |
|
} |
597 |
|
|
598 |
|
/** |
599 |
* 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. |
600 |
* @see #cleanExit(int i) |
* @see #cleanExit(int i) |
601 |
*/ |
*/ |
608 |
*/ |
*/ |
609 |
public static void |
public static void |
610 |
cleanExit(int i) { |
cleanExit(int i) { |
611 |
CC.getLogger().fine("CC.jsEnded"); |
getLogger().fine("CC.jsEnded"); |
612 |
System.exit(i); |
System.exit(i); |
613 |
} |
} |
614 |
|
|
651 |
getSamplerModel() { return samplerModel; } |
getSamplerModel() { return samplerModel; } |
652 |
|
|
653 |
/** |
/** |
654 |
|
* Connects to LinuxSampler. |
655 |
|
*/ |
656 |
|
public static void |
657 |
|
connect() { initSamplerModel(); } |
658 |
|
|
659 |
|
/** |
660 |
* Reconnects to LinuxSampler. |
* Reconnects to LinuxSampler. |
661 |
*/ |
*/ |
662 |
public static void |
public static void |
663 |
reconnect() { |
reconnect() { initSamplerModel(getCurrentServer()); } |
664 |
initSamplerModel(); |
|
665 |
fireReconnectEvent(); |
private static Server currentServer = null; |
666 |
|
|
667 |
|
/** |
668 |
|
* Gets the server, to which the frontend is going to connect |
669 |
|
* or is already connected. |
670 |
|
*/ |
671 |
|
public static Server |
672 |
|
getCurrentServer() { return currentServer; } |
673 |
|
|
674 |
|
/** |
675 |
|
* Sets the current server. |
676 |
|
*/ |
677 |
|
public static void |
678 |
|
setCurrentServer(Server server) { currentServer = server; } |
679 |
|
|
680 |
|
/** |
681 |
|
* Sets the LSCP client's read timeout. |
682 |
|
* @param timeout The new timeout value (in seconds). |
683 |
|
*/ |
684 |
|
public static void |
685 |
|
setClientReadTimeout(int timeout) { |
686 |
|
getTaskQueue().add(new Global.SetClientReadTimeout(timeout)); |
687 |
} |
} |
688 |
|
|
689 |
/** |
/** |
690 |
* This method updates the information about the backend state. |
* This method updates the information about the backend state. |
691 |
*/ |
*/ |
692 |
public static void |
private static void |
693 |
initSamplerModel() { |
initSamplerModel() { |
694 |
|
Server srv = getMainFrame().getServer(); |
695 |
|
if(srv == null) return; |
696 |
|
initSamplerModel(srv); |
697 |
|
} |
698 |
|
|
699 |
|
/** |
700 |
|
* This method updates the information about the backend state. |
701 |
|
*/ |
702 |
|
private static void |
703 |
|
initSamplerModel(Server srv) { |
704 |
|
setCurrentServer(srv); |
705 |
|
final SetServerAddress ssa = new SetServerAddress(srv.getAddress(), srv.getPort()); |
706 |
|
|
707 |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
708 |
|
|
709 |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
791 |
cnt.addTaskListener(new TaskListener() { |
cnt.addTaskListener(new TaskListener() { |
792 |
public void |
public void |
793 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
794 |
if(cnt.doneWithErrors()) return; |
if(cnt.doneWithErrors()) { |
795 |
|
setCurrentServer(null); |
796 |
|
retryToConnect(); |
797 |
|
return; |
798 |
|
} |
799 |
|
|
800 |
getTaskQueue().add(gsi); |
getTaskQueue().add(gsi); |
801 |
getTaskQueue().add(gaod); |
getTaskQueue().add(gaod); |
805 |
getTaskQueue().add(mgim); |
getTaskQueue().add(mgim); |
806 |
getTaskQueue().add(new Midi.UpdateDevices()); |
getTaskQueue().add(new Midi.UpdateDevices()); |
807 |
getTaskQueue().add(new Audio.UpdateDevices()); |
getTaskQueue().add(new Audio.UpdateDevices()); |
808 |
getTaskQueue().add(uc); |
addTask(uc); |
809 |
} |
} |
810 |
}); |
}); |
811 |
getTaskQueue().add(cnt); |
|
812 |
|
ssa.addTaskListener(new TaskListener() { |
813 |
|
public void |
814 |
|
taskPerformed(TaskEvent e) { |
815 |
|
int t = preferences().getIntProperty(JSPrefs.SOCKET_READ_TIMEOUT); |
816 |
|
CC.setClientReadTimeout(t * 1000); |
817 |
|
CC.getTaskQueue().add(cnt); |
818 |
|
} |
819 |
|
}); |
820 |
|
|
821 |
|
getSamplerModel().reset(); |
822 |
|
if(instrumentsDbTreeModel != null) { |
823 |
|
instrumentsDbTreeModel.reset(); |
824 |
|
instrumentsDbTreeModel = null; |
825 |
|
} |
826 |
|
|
827 |
|
getTaskQueue().removePendingTasks(); |
828 |
|
getTaskQueue().add(ssa); |
829 |
|
|
830 |
|
fireReconnectEvent(); |
831 |
|
} |
832 |
|
|
833 |
|
private static void |
834 |
|
retryToConnect() { |
835 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
836 |
|
public void |
837 |
|
run() { changeBackend(); } |
838 |
|
}); |
839 |
|
} |
840 |
|
|
841 |
|
public static void |
842 |
|
changeBackend() { |
843 |
|
Server s = getMainFrame().getServer(true); |
844 |
|
if(s != null) initSamplerModel(s); |
845 |
} |
} |
846 |
|
|
847 |
private static class GetFxSendsListener implements TaskListener { |
private static class GetFxSendsListener implements TaskListener { |
878 |
exportInstrMapsToLscpScript(Client lscpClient) { |
exportInstrMapsToLscpScript(Client lscpClient) { |
879 |
try { |
try { |
880 |
lscpClient.removeAllMidiInstrumentMaps(); |
lscpClient.removeAllMidiInstrumentMaps(); |
881 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
MidiInstrumentMap[] maps = getSamplerModel().getMidiInstrumentMaps(); |
882 |
for(int i = 0; i < maps.length; i++) { |
for(int i = 0; i < maps.length; i++) { |
883 |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
884 |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
885 |
} |
} |
886 |
} catch(Exception e) { |
} catch(Exception e) { |
887 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
888 |
HF.showErrorMessage(e); |
HF.showErrorMessage(e); |
889 |
} |
} |
890 |
} |
} |
893 |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
894 |
throws Exception { |
throws Exception { |
895 |
|
|
896 |
|
boolean b = preferences().getBoolProperty(JSPrefs.LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND); |
897 |
|
|
898 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
899 |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo()); |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo(), b); |
900 |
} |
} |
901 |
} |
} |
902 |
|
|
903 |
public static String |
public static String |
904 |
exportSessionToLscpScript() { |
exportSessionToLscpScript() { |
905 |
CC.getSamplerModel().setModified(false); |
getSamplerModel().setModified(false); |
906 |
|
|
907 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
StringBuffer sb = new StringBuffer("# Exported by: "); |
908 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
918 |
sb.append(out.toString()); |
sb.append(out.toString()); |
919 |
out.reset(); |
out.reset(); |
920 |
sb.append("\r\n"); |
sb.append("\r\n"); |
921 |
lscpClient.setVolume(CC.getSamplerModel().getVolume()); |
lscpClient.setVolume(getSamplerModel().getVolume()); |
922 |
sb.append(out.toString()); |
sb.append(out.toString()); |
923 |
out.reset(); |
out.reset(); |
924 |
sb.append("\r\n"); |
sb.append("\r\n"); |
925 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
} catch(Exception e) { getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
926 |
|
|
927 |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
928 |
for(int i = 0; i < mDevs.length; i++) { |
for(int i = 0; i < mDevs.length; i++) { |
940 |
sb.append("\r\n"); |
sb.append("\r\n"); |
941 |
} |
} |
942 |
|
|
943 |
|
boolean b = preferences().getBoolProperty(JSPrefs.EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT); |
944 |
|
if(b) { |
945 |
|
exportInstrMapsToLscpScript(lscpClient); |
946 |
|
sb.append(out.toString()); |
947 |
|
out.reset(); |
948 |
|
sb.append("\r\n"); |
949 |
|
} |
950 |
|
|
951 |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
952 |
|
|
953 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
965 |
sb.append("\r\n"); |
sb.append("\r\n"); |
966 |
} |
} |
967 |
|
|
968 |
exportInstrMapsToLscpScript(lscpClient); |
//sb.append(getViewConfig().exportSessionViewConfig()); |
|
sb.append(out.toString()); |
|
|
out.reset(); |
|
969 |
|
|
970 |
return sb.toString(); |
return sb.toString(); |
971 |
} |
} |
988 |
} |
} |
989 |
} |
} |
990 |
} catch(Exception e) { |
} catch(Exception e) { |
991 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
992 |
} |
} |
993 |
} |
} |
994 |
|
|
1008 |
} |
} |
1009 |
} |
} |
1010 |
} catch(Exception e) { |
} catch(Exception e) { |
1011 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1012 |
} |
} |
1013 |
} |
} |
1014 |
|
|
1017 |
try { |
try { |
1018 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
1019 |
|
|
1020 |
SamplerModel sm = CC.getSamplerModel(); |
SamplerModel sm = getSamplerModel(); |
1021 |
int id = chn.getMidiInputDevice(); |
int id = chn.getMidiInputDevice(); |
1022 |
if(id != -1) { |
if(id != -1) { |
1023 |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
1030 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
1031 |
} |
} |
1032 |
|
|
1033 |
|
if(chn.getEngine() != null) { |
1034 |
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
1035 |
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
1036 |
|
int mapId = chn.getMidiInstrumentMapId(); |
1037 |
|
lscpCLient.setChannelMidiInstrumentMap(chnId, mapId); |
1038 |
|
} |
1039 |
|
|
1040 |
id = chn.getAudioOutputDevice(); |
id = chn.getAudioOutputDevice(); |
1041 |
if(id != -1) { |
if(id != -1) { |
1042 |
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
1056 |
} |
} |
1057 |
} |
} |
1058 |
|
|
|
if(chn.getEngine() != null) { |
|
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
|
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
|
|
} |
|
|
|
|
1059 |
String s = chn.getInstrumentFile(); |
String s = chn.getInstrumentFile(); |
1060 |
int i = chn.getInstrumentIndex(); |
int i = chn.getInstrumentIndex(); |
1061 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
1063 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
1064 |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
1065 |
} catch(Exception e) { |
} catch(Exception e) { |
1066 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1067 |
} |
} |
1068 |
} |
} |
1069 |
|
|
1082 |
} |
} |
1083 |
} |
} |
1084 |
} catch(Exception e) { |
} catch(Exception e) { |
1085 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1086 |
} |
} |
1087 |
} |
} |
1088 |
|
|
1089 |
|
public static void |
1090 |
|
scheduleInTaskQueue(final Runnable r) { |
1091 |
|
Task dummy = new Global.DummyTask(); |
1092 |
|
dummy.addTaskListener(new TaskListener() { |
1093 |
|
public void |
1094 |
|
taskPerformed(TaskEvent e) { |
1095 |
|
javax.swing.SwingUtilities.invokeLater(r); |
1096 |
|
} |
1097 |
|
}); |
1098 |
|
|
1099 |
|
getTaskQueue().add(dummy); |
1100 |
|
} |
1101 |
|
|
1102 |
|
public static boolean |
1103 |
|
verifyConnection() { |
1104 |
|
if(getCurrentServer() == null) { |
1105 |
|
HF.showErrorMessage(i18n.getError("CC.notConnected")); |
1106 |
|
return false; |
1107 |
|
} |
1108 |
|
|
1109 |
|
return true; |
1110 |
|
} |
1111 |
|
|
1112 |
|
|
1113 |
private final static EventHandler eventHandler = new EventHandler(); |
private final static EventHandler eventHandler = new EventHandler(); |
1114 |
|
|
1119 |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
1120 |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
1121 |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
1122 |
MidiInstrumentInfoListener, GlobalInfoListener { |
MidiInstrumentInfoListener, GlobalInfoListener, ChannelMidiDataListener { |
1123 |
|
|
1124 |
/** Invoked when the number of channels has changed. */ |
/** Invoked when the number of channels has changed. */ |
1125 |
public void |
public void |
1126 |
channelCountChanged( ChannelCountEvent e) { |
channelCountChanged( ChannelCountEvent e) { |
1127 |
getTaskQueue().add(new UpdateChannels()); |
addTask(new UpdateChannels()); |
1128 |
} |
} |
1129 |
|
|
1130 |
/** Invoked when changes to the sampler channel has occured. */ |
/** Invoked when changes to the sampler channel has occured. */ |
1238 |
/** 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. */ |
1239 |
public void |
public void |
1240 |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
1241 |
getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId())); |
scheduleTask(new Midi.UpdateInstruments(e.getMapId())); |
1242 |
} |
} |
1243 |
|
|
1244 |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
1336 |
e.getEntry().removeOrchestraListener(getHandler()); |
e.getEntry().removeOrchestraListener(getHandler()); |
1337 |
saveOrchestras(); |
saveOrchestras(); |
1338 |
} |
} |
1339 |
|
|
1340 |
|
/** |
1341 |
|
* Invoked when MIDI data arrives. |
1342 |
|
*/ |
1343 |
|
public void |
1344 |
|
midiDataArrived(final ChannelMidiDataEvent e) { |
1345 |
|
try { |
1346 |
|
javax.swing.SwingUtilities.invokeAndWait(new Runnable() { |
1347 |
|
public void |
1348 |
|
run() { fireChannelMidiDataEvent(e); } |
1349 |
|
}); |
1350 |
|
} catch(Exception x) { |
1351 |
|
CC.getLogger().log(Level.INFO, "Failed!", x); |
1352 |
|
} |
1353 |
|
} |
1354 |
|
} |
1355 |
|
|
1356 |
|
private static void |
1357 |
|
fireChannelMidiDataEvent(ChannelMidiDataEvent e) { |
1358 |
|
SamplerChannelModel chn; |
1359 |
|
chn = CC.getSamplerModel().getChannelById(e.getChannelId()); |
1360 |
|
if(chn == null) { |
1361 |
|
CC.getLogger().info("Unknown channel ID: " + e.getChannelId()); |
1362 |
|
} |
1363 |
|
|
1364 |
|
((DefaultSamplerChannelModel)chn).fireMidiDataEvent(e); |
1365 |
} |
} |
1366 |
|
|
1367 |
private static final AudioDeviceCountListener audioDeviceCountListener = |
private static final AudioDeviceCountListener audioDeviceCountListener = |