59 |
|
|
60 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
61 |
import org.jsampler.view.JSProgress; |
import org.jsampler.view.JSProgress; |
62 |
|
import org.jsampler.view.JSViewConfig; |
63 |
import org.jsampler.view.InstrumentsDbTreeModel; |
import org.jsampler.view.InstrumentsDbTreeModel; |
64 |
|
|
65 |
import org.linuxsampler.lscp.AudioOutputChannel; |
import org.linuxsampler.lscp.AudioOutputChannel; |
88 |
private static Handler handler; |
private static Handler handler; |
89 |
private static FileOutputStream fos; |
private static FileOutputStream fos; |
90 |
|
|
91 |
|
private static JSViewConfig viewConfig = null; |
92 |
private static JSMainFrame mainFrame = null; |
private static JSMainFrame mainFrame = null; |
93 |
private static JSProgress progress = null; |
private static JSProgress progress = null; |
94 |
|
|
140 |
} |
} |
141 |
|
|
142 |
/** |
/** |
143 |
|
* Gets the configuration of the current view. |
144 |
|
*/ |
145 |
|
public static JSViewConfig |
146 |
|
getViewConfig() { return viewConfig; } |
147 |
|
|
148 |
|
/** |
149 |
|
* Sets the configuration of the current view. |
150 |
|
*/ |
151 |
|
public static void |
152 |
|
setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; } |
153 |
|
|
154 |
|
/** |
155 |
* Returns the main window of this application. |
* Returns the main window of this application. |
156 |
* @return The main window of this application. |
* @return The main window of this application. |
157 |
*/ |
*/ |
265 |
getClient().removeVoiceCountListener(getHandler()); |
getClient().removeVoiceCountListener(getHandler()); |
266 |
getClient().addVoiceCountListener(getHandler()); |
getClient().addVoiceCountListener(getHandler()); |
267 |
|
|
268 |
|
getClient().removeTotalStreamCountListener(getHandler()); |
269 |
|
getClient().addTotalStreamCountListener(getHandler()); |
270 |
|
|
271 |
getClient().removeTotalVoiceCountListener(getHandler()); |
getClient().removeTotalVoiceCountListener(getHandler()); |
272 |
getClient().addTotalVoiceCountListener(getHandler()); |
getClient().addTotalVoiceCountListener(getHandler()); |
273 |
|
|
310 |
checkJSamplerHome() { |
checkJSamplerHome() { |
311 |
if(getJSamplerHome() != null) { |
if(getJSamplerHome() != null) { |
312 |
File f = new File(getJSamplerHome()); |
File f = new File(getJSamplerHome()); |
313 |
if(f.isDirectory()) return; |
if(f.exists() && f.isDirectory()) { |
314 |
|
return; |
315 |
|
} |
316 |
} |
} |
317 |
|
|
318 |
CC.getMainFrame().installJSamplerHome(); |
CC.getMainFrame().installJSamplerHome(); |
328 |
public static void |
public static void |
329 |
changeJSamplerHome(String path) { |
changeJSamplerHome(String path) { |
330 |
File fNew = new File(path); |
File fNew = new File(path); |
331 |
if(fNew.isFile()) { |
if(fNew.exists() && fNew.isFile()) { |
332 |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
333 |
return; |
return; |
334 |
} |
} |
335 |
|
|
336 |
if(!fNew.isDirectory()) { |
if(!fNew.exists()) { |
337 |
if(!fNew.mkdir()) { |
if(!fNew.mkdir()) { |
338 |
String s = fNew.getAbsolutePath(); |
String s = fNew.getAbsolutePath(); |
339 |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
341 |
} |
} |
342 |
} |
} |
343 |
|
|
344 |
if(getJSamplerHome() == null) { |
if(getJSamplerHome() == null || path.equals(getJSamplerHome())) { |
345 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
346 |
return; |
return; |
347 |
} |
} |
348 |
|
|
349 |
File fOld = new File(getJSamplerHome()); |
File fOld = new File(getJSamplerHome()); |
350 |
if(!fOld.isDirectory()) { |
if(!fOld.exists() || !fOld.isDirectory()) { |
351 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
352 |
return; |
return; |
353 |
} |
} |
379 |
* database support the tree model is initialized on first use. |
* database support the tree model is initialized on first use. |
380 |
* @return The tree model of the instruments database or |
* @return The tree model of the instruments database or |
381 |
* <code>null</code> if the backend doesn't have instruments database support. |
* <code>null</code> if the backend doesn't have instruments database support. |
382 |
* @see org.jsampler.view.JSMainFrame#getInstrumentsDbSupport |
* @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport |
383 |
*/ |
*/ |
384 |
public static InstrumentsDbTreeModel |
public static InstrumentsDbTreeModel |
385 |
getInstrumentsDbTreeModel() { |
getInstrumentsDbTreeModel() { |
403 |
loadOrchestras() { |
loadOrchestras() { |
404 |
if(getJSamplerHome() == null) return; |
if(getJSamplerHome() == null) return; |
405 |
|
|
|
//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; |
|
|
} |
|
|
/////// |
|
|
|
|
406 |
try { |
try { |
407 |
String s = getJSamplerHome(); |
String s = getJSamplerHome(); |
408 |
if(s == null) return; |
if(s == null) return; |
409 |
|
getOrchestras().addOrchestraListListener(getHandler()); |
410 |
|
|
411 |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
412 |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
435 |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
436 |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
437 |
} |
} |
|
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: "); } |
|
438 |
} |
} |
439 |
|
|
440 |
private static void |
private static void |
547 |
|
|
548 |
model.setServerInfo(gsi.getResult()); |
model.setServerInfo(gsi.getResult()); |
549 |
|
|
550 |
if(CC.getMainFrame().getInstrumentsDbSupport()) { |
if(CC.getViewConfig().getInstrumentsDbSupport()) { |
551 |
getInstrumentsDbTreeModel(); |
getInstrumentsDbTreeModel(); |
552 |
} |
} |
553 |
} |
} |
613 |
gfs.addTaskListener(new GetFxSendsListener()); |
gfs.addTaskListener(new GetFxSendsListener()); |
614 |
getTaskQueue().add(gfs); |
getTaskQueue().add(gfs); |
615 |
} |
} |
616 |
|
|
617 |
|
// TODO: This should be done after the fx sends are set |
618 |
|
//CC.getSamplerModel().setModified(false); |
619 |
} |
} |
620 |
}); |
}); |
621 |
|
|
696 |
|
|
697 |
public static String |
public static String |
698 |
exportSessionToLscpScript() { |
exportSessionToLscpScript() { |
699 |
|
CC.getSamplerModel().setModified(false); |
700 |
|
|
701 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
StringBuffer sb = new StringBuffer("# Exported by: "); |
702 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
703 |
sb.append(JSampler.VERSION).append("\r\n"); |
sb.append(JSampler.VERSION).append("\r\n"); |
737 |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
738 |
|
|
739 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
740 |
SamplerChannelModel scm = getSamplerModel().getChannelById(i); |
SamplerChannelModel scm = channels[i]; |
741 |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
742 |
sb.append(out.toString()); |
sb.append(out.toString()); |
743 |
out.reset(); |
out.reset(); |
805 |
try { |
try { |
806 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
807 |
|
|
808 |
int i = chn.getMidiInputDevice(); |
SamplerModel sm = CC.getSamplerModel(); |
809 |
if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i); |
int id = chn.getMidiInputDevice(); |
810 |
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
if(id != -1) { |
811 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
812 |
|
if(sm.getMidiDevice(i).getDeviceId() == id) { |
813 |
i = chn.getAudioOutputDevice(); |
lscpCLient.setChannelMidiInputDevice(chnId, i); |
814 |
if(i != -1) { |
break; |
815 |
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
} |
816 |
|
} |
817 |
|
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
818 |
|
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
819 |
|
} |
820 |
|
|
821 |
|
id = chn.getAudioOutputDevice(); |
822 |
|
if(id != -1) { |
823 |
|
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
824 |
|
if(sm.getAudioDevice(i).getDeviceId() == id) { |
825 |
|
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
826 |
|
break; |
827 |
|
} |
828 |
|
} |
829 |
|
|
830 |
Integer[] routing = chn.getAudioOutputRouting(); |
Integer[] routing = chn.getAudioOutputRouting(); |
831 |
|
|
832 |
for(int j = 0; j < routing.length; j++) { |
for(int j = 0; j < routing.length; j++) { |
843 |
} |
} |
844 |
|
|
845 |
String s = chn.getInstrumentFile(); |
String s = chn.getInstrumentFile(); |
846 |
i = chn.getInstrumentIndex(); |
int i = chn.getInstrumentIndex(); |
847 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
848 |
|
|
849 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
880 |
|
|
881 |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
882 |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
883 |
TotalVoiceCountListener, TaskQueueListener, OrchestraListener, |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
884 |
ListListener<OrchestraModel>, MidiInstrumentCountListener, |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
885 |
MidiInstrumentInfoListener, GlobalInfoListener { |
MidiInstrumentInfoListener, GlobalInfoListener { |
886 |
|
|
887 |
/** Invoked when the number of channels has changed. */ |
/** Invoked when the number of channels has changed. */ |
986 |
scm.setVoiceCount(e.getVoiceCount()); |
scm.setVoiceCount(e.getVoiceCount()); |
987 |
} |
} |
988 |
|
|
989 |
|
/** Invoked when the total number of active streams has changed. */ |
990 |
|
public void |
991 |
|
totalStreamCountChanged(TotalStreamCountEvent e) { |
992 |
|
getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount()); |
993 |
|
} |
994 |
|
|
995 |
/** Invoked when the total number of active voices has changed. */ |
/** Invoked when the total number of active voices has changed. */ |
996 |
public void |
public void |
997 |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
1035 |
case TASK_DONE: |
case TASK_DONE: |
1036 |
EnhancedTask t = (EnhancedTask)e.getSource(); |
EnhancedTask t = (EnhancedTask)e.getSource(); |
1037 |
if(t.doneWithErrors() && !t.isStopped()) { |
if(t.doneWithErrors() && !t.isStopped()) { |
1038 |
if(t.getErrorDetails() == null) { |
showError(t); |
|
HF.showErrorMessage(t.getErrorMessage()); |
|
|
} else { |
|
|
getMainFrame().showDetailedErrorMessage ( |
|
|
getMainFrame(), |
|
|
t.getErrorMessage(), |
|
|
t.getErrorDetails() |
|
|
); |
|
|
} |
|
1039 |
} |
} |
1040 |
break; |
break; |
1041 |
case NOT_IDLE: |
case NOT_IDLE: |
1048 |
} |
} |
1049 |
} |
} |
1050 |
|
|
1051 |
|
private void |
1052 |
|
showError(final Task t) { |
1053 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
1054 |
|
public void |
1055 |
|
run() { |
1056 |
|
if(t.getErrorDetails() == null) { |
1057 |
|
HF.showErrorMessage(t.getErrorMessage()); |
1058 |
|
} else { |
1059 |
|
getMainFrame().showDetailedErrorMessage ( |
1060 |
|
getMainFrame(), |
1061 |
|
t.getErrorMessage(), |
1062 |
|
t.getErrorDetails() |
1063 |
|
); |
1064 |
|
} |
1065 |
|
} |
1066 |
|
}); |
1067 |
|
} |
1068 |
|
|
1069 |
/** Invoked when the name of orchestra is changed. */ |
/** Invoked when the name of orchestra is changed. */ |
1070 |
public void |
public void |
1071 |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |