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; |
39 |
import java.util.logging.SimpleFormatter; |
import java.util.logging.SimpleFormatter; |
40 |
import java.util.logging.StreamHandler; |
import java.util.logging.StreamHandler; |
41 |
|
|
42 |
|
import javax.swing.SwingUtilities; |
43 |
import javax.swing.Timer; |
import javax.swing.Timer; |
44 |
|
|
45 |
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeEvent; |
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; |
|
import static org.jsampler.JSPrefs.MANUAL_SERVER_SELECT_ON_STARTUP; |
|
83 |
|
|
84 |
|
|
85 |
/** |
/** |
102 |
private final static TaskQueue taskQueue = new TaskQueue(); |
private final static TaskQueue taskQueue = new TaskQueue(); |
103 |
private final static Timer timer = new Timer(2000, null); |
private final static Timer timer = new Timer(2000, null); |
104 |
|
|
105 |
|
private static int connectionFailureCount = 0; |
106 |
|
|
107 |
/** Forbits the instantiation of this class. */ |
/** Forbits the instantiation of this class. */ |
108 |
private |
private |
109 |
CC() { } |
CC() { } |
126 |
* @return The task queue to be used for scheduling tasks |
* @return The task queue to be used for scheduling tasks |
127 |
* for execution out of the event-dispatching thread. |
* for execution out of the event-dispatching thread. |
128 |
*/ |
*/ |
129 |
public static TaskQueue |
public static synchronized TaskQueue |
130 |
getTaskQueue() { return taskQueue; } |
getTaskQueue() { return taskQueue; } |
131 |
|
|
132 |
/** |
/** |
133 |
* Adds the specified task to the task queue. All task in the |
* Adds the specified task to the task queue. All task in the |
134 |
* queue equal to the specified task are removed from the queue. |
* queue equal to the specified task are removed from the queue. |
135 |
*/ |
*/ |
136 |
public static void |
public static synchronized void |
137 |
scheduleTask(Task t) { |
scheduleTask(Task t) { |
138 |
while(getTaskQueue().removeTask(t)) { } |
while(getTaskQueue().removeTask(t)) { } |
139 |
|
|
|
if(getTaskQueue().getPendingTaskCount() == 0) { |
|
|
if(t.equals(getTaskQueue().getRunningTask())) return; |
|
|
} |
|
|
|
|
140 |
getTaskQueue().add(t); |
getTaskQueue().add(t); |
141 |
} |
} |
142 |
|
|
143 |
/** |
/** |
144 |
|
* Adds the specified task to the task queue only if the last |
145 |
|
* task in the queue is not equal to <code>t</code>. |
146 |
|
*/ |
147 |
|
public static synchronized void |
148 |
|
addTask(Task t) { |
149 |
|
Task[] tasks = getTaskQueue().getPendingTasks(); |
150 |
|
if(tasks.length > 0 && tasks[tasks.length - 1].equals(t)) return; |
151 |
|
getTaskQueue().add(t); |
152 |
|
} |
153 |
|
|
154 |
|
/** |
155 |
* Gets the configuration of the current view. |
* Gets the configuration of the current view. |
156 |
*/ |
*/ |
157 |
public static JSViewConfig |
public static JSViewConfig |
158 |
getViewConfig() { return viewConfig; } |
getViewConfig() { return viewConfig; } |
159 |
|
|
160 |
private static JSPrefs |
public static JSPrefs |
161 |
preferences() { return getViewConfig().preferences(); } |
preferences() { return getViewConfig().preferences(); } |
162 |
|
|
163 |
/** |
/** |
244 |
run() { if(handler != null) handler.flush(); } |
run() { if(handler != null) handler.flush(); } |
245 |
}, 1000, 1000); |
}, 1000, 1000); |
246 |
|
|
247 |
CC.getLogger().fine("CC.jsStarted"); |
getLogger().fine("CC.jsStarted"); |
248 |
|
|
249 |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
250 |
|
|
255 |
actionPerformed(ActionEvent e) { CC.getProgressIndicator().start(); } |
actionPerformed(ActionEvent e) { CC.getProgressIndicator().start(); } |
256 |
}); |
}); |
257 |
|
|
258 |
taskQueue.addTaskQueueListener(getHandler()); |
getTaskQueue().addTaskQueueListener(getHandler()); |
259 |
|
|
260 |
taskQueue.start(); |
getTaskQueue().start(); |
261 |
|
|
262 |
getClient().removeChannelCountListener(getHandler()); |
getClient().removeChannelCountListener(getHandler()); |
263 |
getClient().addChannelCountListener(getHandler()); |
getClient().addChannelCountListener(getHandler()); |
309 |
|
|
310 |
getClient().removeGlobalInfoListener(getHandler()); |
getClient().removeGlobalInfoListener(getHandler()); |
311 |
getClient().addGlobalInfoListener(getHandler()); |
getClient().addGlobalInfoListener(getHandler()); |
312 |
|
|
313 |
|
getClient().removeChannelMidiDataListener(getHandler()); |
314 |
|
getClient().addChannelMidiDataListener(getHandler()); |
315 |
|
|
316 |
|
CC.addConnectionEstablishedListener(new ActionListener() { |
317 |
|
public void |
318 |
|
actionPerformed(ActionEvent e) { |
319 |
|
connectionFailureCount = 0; |
320 |
|
} |
321 |
|
}); |
322 |
} |
} |
323 |
|
|
324 |
/** |
/** |
337 |
} |
} |
338 |
} |
} |
339 |
|
|
340 |
CC.getMainFrame().installJSamplerHome(); |
getMainFrame().installJSamplerHome(); |
341 |
} |
} |
342 |
|
|
343 |
/** |
/** |
403 |
private static ServerListListener serverListListener = new ServerListListener(); |
private static ServerListListener serverListListener = new ServerListListener(); |
404 |
|
|
405 |
private static class ServerListListener implements ChangeListener { |
private static class ServerListListener implements ChangeListener { |
406 |
|
@Override |
407 |
public void |
public void |
408 |
stateChanged(ChangeEvent e) { |
stateChanged(ChangeEvent e) { |
409 |
saveServerList(); |
saveServerList(); |
423 |
*/ |
*/ |
424 |
public static InstrumentsDbTreeModel |
public static InstrumentsDbTreeModel |
425 |
getInstrumentsDbTreeModel() { |
getInstrumentsDbTreeModel() { |
426 |
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
if(getSamplerModel().getServerInfo() == null) return null; |
427 |
|
if(!getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
428 |
|
|
429 |
if(instrumentsDbTreeModel == null) { |
if(instrumentsDbTreeModel == null) { |
430 |
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
444 |
idtmListeners.remove(l); |
idtmListeners.remove(l); |
445 |
} |
} |
446 |
|
|
447 |
|
private static final LostFilesModel lostFilesModel = new LostFilesModel(); |
448 |
|
|
449 |
|
public static LostFilesModel |
450 |
|
getLostFilesModel() { return lostFilesModel; } |
451 |
|
|
452 |
/** |
/** |
453 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
454 |
* 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 |
502 |
|
|
503 |
HF.createBackup("orchestras.xml", "orchestras.xml.bkp"); |
HF.createBackup("orchestras.xml", "orchestras.xml.bkp"); |
504 |
|
|
505 |
FileOutputStream fos; |
FileOutputStream fos2; |
506 |
fos = new FileOutputStream(s + File.separator + "orchestras.xml", false); |
fos2 = new FileOutputStream(s + File.separator + "orchestras.xml", false); |
507 |
|
|
508 |
Document doc = DOMUtils.createEmptyDocument(); |
Document doc = DOMUtils.createEmptyDocument(); |
509 |
|
|
514 |
|
|
515 |
doc.replaceChild(node.getFirstChild(), node); |
doc.replaceChild(node.getFirstChild(), node); |
516 |
|
|
517 |
DOMUtils.writeObject(doc, fos); |
DOMUtils.writeObject(doc, fos2); |
518 |
|
|
519 |
fos.close(); |
fos2.close(); |
520 |
|
|
521 |
HF.deleteFile("orchestras.xml.bkp"); |
HF.deleteFile("orchestras.xml.bkp"); |
522 |
} catch(Exception x) { |
} catch(Exception x) { |
583 |
|
|
584 |
HF.createBackup("servers.xml", "servers.xml.bkp"); |
HF.createBackup("servers.xml", "servers.xml.bkp"); |
585 |
|
|
586 |
FileOutputStream fos; |
FileOutputStream fos2; |
587 |
fos = new FileOutputStream(s + File.separator + "servers.xml", false); |
fos2 = new FileOutputStream(s + File.separator + "servers.xml", false); |
588 |
|
|
589 |
Document doc = DOMUtils.createEmptyDocument(); |
Document doc = DOMUtils.createEmptyDocument(); |
590 |
|
|
595 |
|
|
596 |
doc.replaceChild(node.getFirstChild(), node); |
doc.replaceChild(node.getFirstChild(), node); |
597 |
|
|
598 |
DOMUtils.writeObject(doc, fos); |
DOMUtils.writeObject(doc, fos2); |
599 |
|
|
600 |
fos.close(); |
fos2.close(); |
601 |
|
|
602 |
HF.deleteFile("servers.xml.bkp"); |
HF.deleteFile("servers.xml.bkp"); |
603 |
} catch(Exception x) { |
} catch(Exception x) { |
619 |
*/ |
*/ |
620 |
public static void |
public static void |
621 |
cleanExit(int i) { |
cleanExit(int i) { |
622 |
CC.getLogger().fine("CC.jsEnded"); |
getLogger().fine("CC.jsEnded"); |
623 |
|
try { getClient().disconnect(); } // FIXME: this might block the EDT |
624 |
|
catch(Exception x) { x.printStackTrace(); } |
625 |
|
if(backendProcess != null) backendProcess.destroy(); |
626 |
|
backendProcess = null; |
627 |
|
fireBackendProcessEvent(); |
628 |
System.exit(i); |
System.exit(i); |
629 |
} |
} |
630 |
|
|
657 |
for(ActionListener l : listeners) l.actionPerformed(e); |
for(ActionListener l : listeners) l.actionPerformed(e); |
658 |
} |
} |
659 |
|
|
660 |
|
private static final Vector<ActionListener> ceListeners = new Vector<ActionListener>(); |
661 |
|
|
662 |
|
/** |
663 |
|
* Registers the specified listener to be notified when |
664 |
|
* jsampler is connected successfully to LinuxSampler. |
665 |
|
* @param l The <code>ActionListener</code> to register. |
666 |
|
*/ |
667 |
|
public static void |
668 |
|
addConnectionEstablishedListener(ActionListener l) { ceListeners.add(l); } |
669 |
|
|
670 |
|
/** |
671 |
|
* Removes the specified listener. |
672 |
|
* @param l The <code>ActionListener</code> to remove. |
673 |
|
*/ |
674 |
|
public static void |
675 |
|
removeConnectionEstablishedListener(ActionListener l) { ceListeners.remove(l); } |
676 |
|
|
677 |
|
private static void |
678 |
|
fireConnectionEstablishedEvent() { |
679 |
|
ActionEvent e = new ActionEvent(CC.class, ActionEvent.ACTION_PERFORMED, null); |
680 |
|
for(ActionListener l : ceListeners) l.actionPerformed(e); |
681 |
|
} |
682 |
|
|
683 |
private static final SamplerModel samplerModel = new DefaultSamplerModel(); |
private static final SamplerModel samplerModel = new DefaultSamplerModel(); |
684 |
|
|
685 |
/** |
/** |
714 |
* Sets the current server. |
* Sets the current server. |
715 |
*/ |
*/ |
716 |
public static void |
public static void |
717 |
setCurrentServer(Server server) { currentServer = server; } |
setCurrentServer(Server server) { |
718 |
|
if(server == currentServer) return; |
719 |
|
connectionFailureCount = 0; |
720 |
|
currentServer = server; |
721 |
|
} |
722 |
|
|
723 |
|
/** |
724 |
|
* Sets the LSCP client's read timeout. |
725 |
|
* @param timeout The new timeout value (in seconds). |
726 |
|
*/ |
727 |
|
public static void |
728 |
|
setClientReadTimeout(int timeout) { |
729 |
|
getTaskQueue().add(new Global.SetClientReadTimeout(timeout)); |
730 |
|
} |
731 |
|
|
732 |
/** |
/** |
733 |
* This method updates the information about the backend state. |
* This method updates the information about the backend state. |
831 |
|
|
832 |
|
|
833 |
final Connect cnt = new Connect(); |
final Connect cnt = new Connect(); |
834 |
|
boolean b = preferences().getBoolProperty(JSPrefs.LAUNCH_BACKEND_LOCALLY); |
835 |
|
if(b && srv.isLocal() && backendProcess == null) cnt.setSilent(true); |
836 |
cnt.addTaskListener(new TaskListener() { |
cnt.addTaskListener(new TaskListener() { |
837 |
public void |
public void |
838 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
839 |
if(cnt.doneWithErrors()) { |
if(cnt.doneWithErrors()) { |
840 |
setCurrentServer(null); |
onConnectFailure(); |
|
retryToConnect(); |
|
841 |
return; |
return; |
842 |
} |
} |
843 |
|
|
849 |
getTaskQueue().add(mgim); |
getTaskQueue().add(mgim); |
850 |
getTaskQueue().add(new Midi.UpdateDevices()); |
getTaskQueue().add(new Midi.UpdateDevices()); |
851 |
getTaskQueue().add(new Audio.UpdateDevices()); |
getTaskQueue().add(new Audio.UpdateDevices()); |
852 |
getTaskQueue().add(uc); |
addTask(uc); |
853 |
|
|
854 |
|
int vl = preferences().getIntProperty(JSPrefs.GLOBAL_VOICE_LIMIT); |
855 |
|
int sl = preferences().getIntProperty(JSPrefs.GLOBAL_STREAM_LIMIT); |
856 |
|
|
857 |
|
getTaskQueue().add(new Global.SetPolyphony(vl, sl)); |
858 |
|
|
859 |
|
fireConnectionEstablishedEvent(); |
860 |
} |
} |
861 |
}); |
}); |
862 |
|
|
863 |
ssa.addTaskListener(new TaskListener() { |
ssa.addTaskListener(new TaskListener() { |
864 |
public void |
public void |
865 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
866 |
|
int t = preferences().getIntProperty(JSPrefs.SOCKET_READ_TIMEOUT); |
867 |
|
CC.setClientReadTimeout(t * 1000); |
868 |
CC.getTaskQueue().add(cnt); |
CC.getTaskQueue().add(cnt); |
869 |
} |
} |
870 |
}); |
}); |
882 |
} |
} |
883 |
|
|
884 |
private static void |
private static void |
885 |
|
onConnectFailure() { |
886 |
|
connectionFailureCount++; |
887 |
|
if(connectionFailureCount > 50) { // to prevent eventual infinite loop |
888 |
|
getLogger().warning("Reached maximum number of connection failures"); |
889 |
|
return; |
890 |
|
} |
891 |
|
|
892 |
|
try { |
893 |
|
if(launchBackend()) { |
894 |
|
int i = preferences().getIntProperty(JSPrefs.BACKEND_LAUNCH_DELAY); |
895 |
|
if(i < 1) { |
896 |
|
initSamplerModel(getCurrentServer()); |
897 |
|
return; |
898 |
|
} |
899 |
|
|
900 |
|
LaunchBackend lb = new LaunchBackend(i, getBackendMonitor()); |
901 |
|
//CC.getTaskQueue().add(lb); |
902 |
|
new Thread(lb).start(); |
903 |
|
return; |
904 |
|
} |
905 |
|
} catch(Exception x) { |
906 |
|
final String s = JSI18n.i18n.getError("CC.failedToLaunchBackend"); |
907 |
|
CC.getLogger().log(Level.INFO, s, x); |
908 |
|
|
909 |
|
SwingUtilities.invokeLater(new Runnable() { |
910 |
|
public void |
911 |
|
run() { HF.showErrorMessage(s); } |
912 |
|
}); |
913 |
|
return; |
914 |
|
} |
915 |
|
|
916 |
|
retryToConnect(); |
917 |
|
} |
918 |
|
|
919 |
|
private static void |
920 |
retryToConnect() { |
retryToConnect() { |
921 |
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
922 |
public void |
public void |
927 |
public static void |
public static void |
928 |
changeBackend() { |
changeBackend() { |
929 |
Server s = getMainFrame().getServer(true); |
Server s = getMainFrame().getServer(true); |
930 |
if(s != null) initSamplerModel(s); |
if(s != null) { |
931 |
|
connectionFailureCount = 0; // cleared because this change due to user interaction |
932 |
|
initSamplerModel(s); |
933 |
|
} |
934 |
|
} |
935 |
|
|
936 |
|
private static final Vector<ActionListener> pListeners = new Vector<ActionListener>(); |
937 |
|
|
938 |
|
/** |
939 |
|
* Registers the specified listener to be notified when |
940 |
|
* backend process is created/terminated. |
941 |
|
* @param l The <code>ActionListener</code> to register. |
942 |
|
*/ |
943 |
|
public static void |
944 |
|
addBackendProcessListener(ActionListener l) { pListeners.add(l); } |
945 |
|
|
946 |
|
/** |
947 |
|
* Removes the specified listener. |
948 |
|
* @param l The <code>ActionListener</code> to remove. |
949 |
|
*/ |
950 |
|
public static void |
951 |
|
removeBackendProcessListener(ActionListener l) { pListeners.remove(l); } |
952 |
|
|
953 |
|
private static void |
954 |
|
fireBackendProcessEvent() { |
955 |
|
ActionEvent e = new ActionEvent(CC.class, ActionEvent.ACTION_PERFORMED, null); |
956 |
|
for(ActionListener l : pListeners) l.actionPerformed(e); |
957 |
|
} |
958 |
|
|
959 |
|
private static Process backendProcess = null; |
960 |
|
|
961 |
|
public static Process |
962 |
|
getBackendProcess() { return backendProcess; } |
963 |
|
|
964 |
|
private static final Object backendMonitor = new Object(); |
965 |
|
|
966 |
|
public static Object |
967 |
|
getBackendMonitor() { return backendMonitor; } |
968 |
|
|
969 |
|
private static boolean |
970 |
|
launchBackend() throws Exception { |
971 |
|
if(backendProcess != null) { |
972 |
|
try { |
973 |
|
int i = backendProcess.exitValue(); |
974 |
|
getLogger().info("Backend exited with exit value " + i); |
975 |
|
backendProcess = null; |
976 |
|
fireBackendProcessEvent(); |
977 |
|
} catch(IllegalThreadStateException x) { return false; } |
978 |
|
} |
979 |
|
|
980 |
|
if(!preferences().getBoolProperty(JSPrefs.LAUNCH_BACKEND_LOCALLY)) return false; |
981 |
|
if(connectionFailureCount > 1) return false; |
982 |
|
|
983 |
|
Server s = getCurrentServer(); |
984 |
|
if(s != null && s.isLocal()) { |
985 |
|
String cmd = preferences().getStringProperty(JSPrefs.BACKEND_LAUNCH_COMMAND); |
986 |
|
backendProcess = Runtime.getRuntime().exec(cmd); |
987 |
|
fireBackendProcessEvent(); |
988 |
|
return true; |
989 |
|
} |
990 |
|
|
991 |
|
return false; |
992 |
} |
} |
993 |
|
|
994 |
private static class GetFxSendsListener implements TaskListener { |
private static class GetFxSendsListener implements TaskListener { |
995 |
|
@Override |
996 |
public void |
public void |
997 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
998 |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
1026 |
exportInstrMapsToLscpScript(Client lscpClient) { |
exportInstrMapsToLscpScript(Client lscpClient) { |
1027 |
try { |
try { |
1028 |
lscpClient.removeAllMidiInstrumentMaps(); |
lscpClient.removeAllMidiInstrumentMaps(); |
1029 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
MidiInstrumentMap[] maps = getSamplerModel().getMidiInstrumentMaps(); |
1030 |
for(int i = 0; i < maps.length; i++) { |
for(int i = 0; i < maps.length; i++) { |
1031 |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
1032 |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
1033 |
} |
} |
1034 |
} catch(Exception e) { |
} catch(Exception e) { |
1035 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1036 |
HF.showErrorMessage(e); |
HF.showErrorMessage(e); |
1037 |
} |
} |
1038 |
} |
} |
1041 |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
1042 |
throws Exception { |
throws Exception { |
1043 |
|
|
1044 |
|
boolean b = preferences().getBoolProperty(JSPrefs.LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND); |
1045 |
|
|
1046 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
1047 |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo()); |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo(), b); |
1048 |
} |
} |
1049 |
} |
} |
1050 |
|
|
1051 |
public static String |
public static String |
1052 |
exportSessionToLscpScript() { |
exportSessionToLscpScript() { |
1053 |
CC.getSamplerModel().setModified(false); |
getSamplerModel().setModified(false); |
1054 |
|
|
1055 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
StringBuffer sb = new StringBuffer("# Exported by: "); |
1056 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
1066 |
sb.append(out.toString()); |
sb.append(out.toString()); |
1067 |
out.reset(); |
out.reset(); |
1068 |
sb.append("\r\n"); |
sb.append("\r\n"); |
1069 |
lscpClient.setVolume(CC.getSamplerModel().getVolume()); |
lscpClient.setVolume(getSamplerModel().getVolume()); |
1070 |
sb.append(out.toString()); |
sb.append(out.toString()); |
1071 |
out.reset(); |
out.reset(); |
1072 |
sb.append("\r\n"); |
sb.append("\r\n"); |
1073 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
} catch(Exception e) { getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
1074 |
|
|
1075 |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
1076 |
for(int i = 0; i < mDevs.length; i++) { |
for(int i = 0; i < mDevs.length; i++) { |
1088 |
sb.append("\r\n"); |
sb.append("\r\n"); |
1089 |
} |
} |
1090 |
|
|
1091 |
|
boolean b = preferences().getBoolProperty(JSPrefs.EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT); |
1092 |
|
if(b) { |
1093 |
|
exportInstrMapsToLscpScript(lscpClient); |
1094 |
|
sb.append(out.toString()); |
1095 |
|
out.reset(); |
1096 |
|
sb.append("\r\n"); |
1097 |
|
} |
1098 |
|
|
1099 |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
1100 |
|
|
1101 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
1113 |
sb.append("\r\n"); |
sb.append("\r\n"); |
1114 |
} |
} |
1115 |
|
|
1116 |
exportInstrMapsToLscpScript(lscpClient); |
sb.append(getViewConfig().exportSessionViewConfig()); |
|
sb.append(out.toString()); |
|
|
out.reset(); |
|
1117 |
|
|
1118 |
return sb.toString(); |
return sb.toString(); |
1119 |
} |
} |
1136 |
} |
} |
1137 |
} |
} |
1138 |
} catch(Exception e) { |
} catch(Exception e) { |
1139 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1140 |
} |
} |
1141 |
} |
} |
1142 |
|
|
1156 |
} |
} |
1157 |
} |
} |
1158 |
} catch(Exception e) { |
} catch(Exception e) { |
1159 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1160 |
} |
} |
1161 |
} |
} |
1162 |
|
|
1165 |
try { |
try { |
1166 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
1167 |
|
|
1168 |
SamplerModel sm = CC.getSamplerModel(); |
SamplerModel sm = getSamplerModel(); |
1169 |
int id = chn.getMidiInputDevice(); |
int id = chn.getMidiInputDevice(); |
1170 |
if(id != -1) { |
if(id != -1) { |
1171 |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
1181 |
if(chn.getEngine() != null) { |
if(chn.getEngine() != null) { |
1182 |
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
1183 |
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
1184 |
|
int mapId = chn.getMidiInstrumentMapId(); |
1185 |
|
lscpCLient.setChannelMidiInstrumentMap(chnId, mapId); |
1186 |
} |
} |
1187 |
|
|
1188 |
id = chn.getAudioOutputDevice(); |
id = chn.getAudioOutputDevice(); |
1211 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
1212 |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
1213 |
} catch(Exception e) { |
} catch(Exception e) { |
1214 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1215 |
} |
} |
1216 |
} |
} |
1217 |
|
|
1230 |
} |
} |
1231 |
} |
} |
1232 |
} catch(Exception e) { |
} catch(Exception e) { |
1233 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1234 |
} |
} |
1235 |
} |
} |
1236 |
|
|
1244 |
} |
} |
1245 |
}); |
}); |
1246 |
|
|
1247 |
CC.getTaskQueue().add(dummy); |
getTaskQueue().add(dummy); |
1248 |
} |
} |
1249 |
|
|
1250 |
public static boolean |
public static boolean |
1267 |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
1268 |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
1269 |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
1270 |
MidiInstrumentInfoListener, GlobalInfoListener { |
MidiInstrumentInfoListener, GlobalInfoListener, ChannelMidiDataListener { |
1271 |
|
|
1272 |
/** Invoked when the number of channels has changed. */ |
/** Invoked when the number of channels has changed. */ |
1273 |
|
@Override |
1274 |
public void |
public void |
1275 |
channelCountChanged( ChannelCountEvent e) { |
channelCountChanged( ChannelCountEvent e) { |
1276 |
getTaskQueue().add(new UpdateChannels()); |
if(e.getChannelCount() == 0) { |
1277 |
|
/* |
1278 |
|
* This special case is handled because this might be due to |
1279 |
|
* loading a lscp script containing sampler view configuration. |
1280 |
|
*/ |
1281 |
|
CC.getSamplerModel().removeAllChannels(); |
1282 |
|
return; |
1283 |
|
} |
1284 |
|
addTask(new UpdateChannels()); |
1285 |
} |
} |
1286 |
|
|
1287 |
/** Invoked when changes to the sampler channel has occured. */ |
/** Invoked when changes to the sampler channel has occured. */ |
1288 |
|
@Override |
1289 |
public void |
public void |
1290 |
channelInfoChanged(ChannelInfoEvent e) { |
channelInfoChanged(ChannelInfoEvent e) { |
1291 |
/* |
/* |
1323 |
* Invoked when the number of effect sends |
* Invoked when the number of effect sends |
1324 |
* on a particular sampler channel has changed. |
* on a particular sampler channel has changed. |
1325 |
*/ |
*/ |
1326 |
|
@Override |
1327 |
public void |
public void |
1328 |
fxSendCountChanged(FxSendCountEvent e) { |
fxSendCountChanged(FxSendCountEvent e) { |
1329 |
getTaskQueue().add(new Channel.UpdateFxSends(e.getChannel())); |
getTaskQueue().add(new Channel.UpdateFxSends(e.getChannel())); |
1332 |
/** |
/** |
1333 |
* Invoked when the settings of an effect sends are changed. |
* Invoked when the settings of an effect sends are changed. |
1334 |
*/ |
*/ |
1335 |
|
@Override |
1336 |
public void |
public void |
1337 |
fxSendInfoChanged(FxSendInfoEvent e) { |
fxSendInfoChanged(FxSendInfoEvent e) { |
1338 |
Task t = new Channel.UpdateFxSendInfo(e.getChannel(), e.getFxSend()); |
Task t = new Channel.UpdateFxSendInfo(e.getChannel(), e.getFxSend()); |
1343 |
* Invoked when the number of active disk |
* Invoked when the number of active disk |
1344 |
* streams in a specific sampler channel has changed. |
* streams in a specific sampler channel has changed. |
1345 |
*/ |
*/ |
1346 |
|
@Override |
1347 |
public void |
public void |
1348 |
streamCountChanged(StreamCountEvent e) { |
streamCountChanged(StreamCountEvent e) { |
1349 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
1366 |
* Invoked when the number of active voices |
* Invoked when the number of active voices |
1367 |
* in a specific sampler channel has changed. |
* in a specific sampler channel has changed. |
1368 |
*/ |
*/ |
1369 |
|
@Override |
1370 |
public void |
public void |
1371 |
voiceCountChanged(VoiceCountEvent e) { |
voiceCountChanged(VoiceCountEvent e) { |
1372 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
1386 |
} |
} |
1387 |
|
|
1388 |
/** Invoked when the total number of active streams has changed. */ |
/** Invoked when the total number of active streams has changed. */ |
1389 |
|
@Override |
1390 |
public void |
public void |
1391 |
totalStreamCountChanged(TotalStreamCountEvent e) { |
totalStreamCountChanged(TotalStreamCountEvent e) { |
1392 |
getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount()); |
getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount()); |
1393 |
} |
} |
1394 |
|
|
1395 |
/** Invoked when the total number of active voices has changed. */ |
/** Invoked when the total number of active voices has changed. */ |
1396 |
|
@Override |
1397 |
public void |
public void |
1398 |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
1399 |
getTaskQueue().add(new UpdateTotalVoiceCount()); |
scheduleTask(new UpdateTotalVoiceCount()); |
1400 |
} |
} |
1401 |
|
|
1402 |
/** 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. */ |
1403 |
|
@Override |
1404 |
public void |
public void |
1405 |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
1406 |
getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId())); |
scheduleTask(new Midi.UpdateInstruments(e.getMapId())); |
1407 |
} |
} |
1408 |
|
|
1409 |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
1410 |
|
@Override |
1411 |
public void |
public void |
1412 |
instrumentInfoChanged(MidiInstrumentInfoEvent e) { |
instrumentInfoChanged(MidiInstrumentInfoEvent e) { |
1413 |
Task t = new Midi.UpdateInstrumentInfo ( |
Task t = new Midi.UpdateInstrumentInfo ( |
1418 |
} |
} |
1419 |
|
|
1420 |
/** Invoked when the global volume of the sampler is changed. */ |
/** Invoked when the global volume of the sampler is changed. */ |
1421 |
|
@Override |
1422 |
public void |
public void |
1423 |
volumeChanged(GlobalInfoEvent e) { |
volumeChanged(GlobalInfoEvent e) { |
1424 |
getSamplerModel().setVolume(e.getVolume()); |
getSamplerModel().setVolume(e.getVolume()); |
1425 |
} |
} |
1426 |
|
|
1427 |
|
@Override |
1428 |
|
public void |
1429 |
|
voiceLimitChanged(GlobalInfoEvent e) { } |
1430 |
|
|
1431 |
|
@Override |
1432 |
|
public void |
1433 |
|
streamLimitChanged(GlobalInfoEvent e) { } |
1434 |
|
|
1435 |
/** |
/** |
1436 |
* Invoked to indicate that the state of a task queue is changed. |
* Invoked to indicate that the state of a task queue is changed. |
1437 |
* This method is invoked only from the event-dispatching thread. |
* This method is invoked only from the event-dispatching thread. |
1438 |
*/ |
*/ |
1439 |
|
@Override |
1440 |
public void |
public void |
1441 |
stateChanged(TaskQueueEvent e) { |
stateChanged(TaskQueueEvent e) { |
1442 |
switch(e.getEventID()) { |
switch(e.getEventID()) { |
1447 |
break; |
break; |
1448 |
case TASK_DONE: |
case TASK_DONE: |
1449 |
EnhancedTask t = (EnhancedTask)e.getSource(); |
EnhancedTask t = (EnhancedTask)e.getSource(); |
1450 |
if(t.doneWithErrors() && !t.isStopped()) { |
if(t.doneWithErrors() && !t.isStopped() && !t.isSilent()) { |
1451 |
showError(t); |
showError(t); |
1452 |
} |
} |
1453 |
break; |
break; |
1480 |
} |
} |
1481 |
|
|
1482 |
/** Invoked when the name of orchestra is changed. */ |
/** Invoked when the name of orchestra is changed. */ |
1483 |
|
@Override |
1484 |
public void |
public void |
1485 |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
1486 |
|
|
1487 |
/** Invoked when the description of orchestra is changed. */ |
/** Invoked when the description of orchestra is changed. */ |
1488 |
|
@Override |
1489 |
public void |
public void |
1490 |
descriptionChanged(OrchestraEvent e) { saveOrchestras(); } |
descriptionChanged(OrchestraEvent e) { saveOrchestras(); } |
1491 |
|
|
1492 |
/** Invoked when an instrument is added to the orchestra. */ |
/** Invoked when an instrument is added to the orchestra. */ |
1493 |
|
@Override |
1494 |
public void |
public void |
1495 |
instrumentAdded(OrchestraEvent e) { saveOrchestras(); } |
instrumentAdded(OrchestraEvent e) { saveOrchestras(); } |
1496 |
|
|
1497 |
/** Invoked when an instrument is removed from the orchestra. */ |
/** Invoked when an instrument is removed from the orchestra. */ |
1498 |
|
@Override |
1499 |
public void |
public void |
1500 |
instrumentRemoved(OrchestraEvent e) { saveOrchestras(); } |
instrumentRemoved(OrchestraEvent e) { saveOrchestras(); } |
1501 |
|
|
1502 |
/** Invoked when the settings of an instrument are changed. */ |
/** Invoked when the settings of an instrument are changed. */ |
1503 |
|
@Override |
1504 |
public void |
public void |
1505 |
instrumentChanged(OrchestraEvent e) { saveOrchestras(); } |
instrumentChanged(OrchestraEvent e) { saveOrchestras(); } |
1506 |
|
|
1507 |
/** Invoked when an orchestra is added to the orchestra list. */ |
/** Invoked when an orchestra is added to the orchestra list. */ |
1508 |
|
@Override |
1509 |
public void |
public void |
1510 |
entryAdded(ListEvent<OrchestraModel> e) { |
entryAdded(ListEvent<OrchestraModel> e) { |
1511 |
e.getEntry().addOrchestraListener(getHandler()); |
e.getEntry().addOrchestraListener(getHandler()); |
1513 |
} |
} |
1514 |
|
|
1515 |
/** Invoked when an orchestra is removed from the orchestra list. */ |
/** Invoked when an orchestra is removed from the orchestra list. */ |
1516 |
|
@Override |
1517 |
public void |
public void |
1518 |
entryRemoved(ListEvent<OrchestraModel> e) { |
entryRemoved(ListEvent<OrchestraModel> e) { |
1519 |
e.getEntry().removeOrchestraListener(getHandler()); |
e.getEntry().removeOrchestraListener(getHandler()); |
1520 |
saveOrchestras(); |
saveOrchestras(); |
1521 |
} |
} |
1522 |
|
|
1523 |
|
/** |
1524 |
|
* Invoked when MIDI data arrives. |
1525 |
|
*/ |
1526 |
|
@Override |
1527 |
|
public void |
1528 |
|
midiDataArrived(final ChannelMidiDataEvent e) { |
1529 |
|
try { |
1530 |
|
javax.swing.SwingUtilities.invokeAndWait(new Runnable() { |
1531 |
|
public void |
1532 |
|
run() { fireChannelMidiDataEvent(e); } |
1533 |
|
}); |
1534 |
|
} catch(Exception x) { |
1535 |
|
CC.getLogger().log(Level.INFO, "Failed!", x); |
1536 |
|
} |
1537 |
|
} |
1538 |
|
} |
1539 |
|
|
1540 |
|
private static void |
1541 |
|
fireChannelMidiDataEvent(ChannelMidiDataEvent e) { |
1542 |
|
SamplerChannelModel chn; |
1543 |
|
chn = CC.getSamplerModel().getChannelById(e.getChannelId()); |
1544 |
|
if(chn == null) { |
1545 |
|
CC.getLogger().info("Unknown channel ID: " + e.getChannelId()); |
1546 |
|
} |
1547 |
|
|
1548 |
|
((DefaultSamplerChannelModel)chn).fireMidiDataEvent(e); |
1549 |
} |
} |
1550 |
|
|
1551 |
private static final AudioDeviceCountListener audioDeviceCountListener = |
private static final AudioDeviceCountListener audioDeviceCountListener = |
1553 |
|
|
1554 |
private static class AudioDeviceCountListener implements ItemCountListener { |
private static class AudioDeviceCountListener implements ItemCountListener { |
1555 |
/** Invoked when the number of audio output devices has changed. */ |
/** Invoked when the number of audio output devices has changed. */ |
1556 |
|
@Override |
1557 |
public void |
public void |
1558 |
itemCountChanged(ItemCountEvent e) { |
itemCountChanged(ItemCountEvent e) { |
1559 |
getTaskQueue().add(new Audio.UpdateDevices()); |
getTaskQueue().add(new Audio.UpdateDevices()); |
1565 |
|
|
1566 |
private static class AudioDeviceInfoListener implements ItemInfoListener { |
private static class AudioDeviceInfoListener implements ItemInfoListener { |
1567 |
/** Invoked when the audio output device's settings are changed. */ |
/** Invoked when the audio output device's settings are changed. */ |
1568 |
|
@Override |
1569 |
public void |
public void |
1570 |
itemInfoChanged(ItemInfoEvent e) { |
itemInfoChanged(ItemInfoEvent e) { |
1571 |
getTaskQueue().add(new Audio.UpdateDeviceInfo(e.getItemID())); |
getTaskQueue().add(new Audio.UpdateDeviceInfo(e.getItemID())); |
1577 |
|
|
1578 |
private static class MidiDeviceCountListener implements ItemCountListener { |
private static class MidiDeviceCountListener implements ItemCountListener { |
1579 |
/** Invoked when the number of MIDI input devices has changed. */ |
/** Invoked when the number of MIDI input devices has changed. */ |
1580 |
|
@Override |
1581 |
public void |
public void |
1582 |
itemCountChanged(ItemCountEvent e) { |
itemCountChanged(ItemCountEvent e) { |
1583 |
getTaskQueue().add(new Midi.UpdateDevices()); |
getTaskQueue().add(new Midi.UpdateDevices()); |
1589 |
|
|
1590 |
private static class MidiDeviceInfoListener implements ItemInfoListener { |
private static class MidiDeviceInfoListener implements ItemInfoListener { |
1591 |
/** Invoked when the MIDI input device's settings are changed. */ |
/** Invoked when the MIDI input device's settings are changed. */ |
1592 |
|
@Override |
1593 |
public void |
public void |
1594 |
itemInfoChanged(ItemInfoEvent e) { |
itemInfoChanged(ItemInfoEvent e) { |
1595 |
getTaskQueue().add(new Midi.UpdateDeviceInfo(e.getItemID())); |
getTaskQueue().add(new Midi.UpdateDeviceInfo(e.getItemID())); |
1601 |
|
|
1602 |
private static class MidiInstrMapCountListener implements ItemCountListener { |
private static class MidiInstrMapCountListener implements ItemCountListener { |
1603 |
/** Invoked when the number of MIDI instrument maps is changed. */ |
/** Invoked when the number of MIDI instrument maps is changed. */ |
1604 |
|
@Override |
1605 |
public void |
public void |
1606 |
itemCountChanged(ItemCountEvent e) { |
itemCountChanged(ItemCountEvent e) { |
1607 |
getTaskQueue().add(new Midi.UpdateInstrumentMaps()); |
getTaskQueue().add(new Midi.UpdateInstrumentMaps()); |
1613 |
|
|
1614 |
private static class MidiInstrMapInfoListener implements ItemInfoListener { |
private static class MidiInstrMapInfoListener implements ItemInfoListener { |
1615 |
/** Invoked when the MIDI instrument map's settings are changed. */ |
/** Invoked when the MIDI instrument map's settings are changed. */ |
1616 |
|
@Override |
1617 |
public void |
public void |
1618 |
itemInfoChanged(ItemInfoEvent e) { |
itemInfoChanged(ItemInfoEvent e) { |
1619 |
getTaskQueue().add(new Midi.UpdateInstrumentMapInfo(e.getItemID())); |
getTaskQueue().add(new Midi.UpdateInstrumentMapInfo(e.getItemID())); |