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; |
64 |
|
|
65 |
import org.linuxsampler.lscp.AudioOutputChannel; |
import org.linuxsampler.lscp.AudioOutputChannel; |
66 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
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 |
|
|
125 |
getTaskQueue() { return taskQueue; } |
getTaskQueue() { return taskQueue; } |
126 |
|
|
127 |
/** |
/** |
128 |
|
* Adds the specified task to the task queue. All task in the |
129 |
|
* queue equal to the specified task are removed from the queue. |
130 |
|
*/ |
131 |
|
public static void |
132 |
|
scheduleTask(Task t) { |
133 |
|
while(getTaskQueue().removeTask(t)) { } |
134 |
|
|
135 |
|
if(getTaskQueue().getPendingTaskCount() == 0) { |
136 |
|
if(t.equals(getTaskQueue().getRunningTask())) return; |
137 |
|
} |
138 |
|
|
139 |
|
getTaskQueue().add(t); |
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 |
*/ |
*/ |
220 |
handler.setLevel(Level.FINE); |
handler.setLevel(Level.FINE); |
221 |
getLogger().addHandler(handler); |
getLogger().addHandler(handler); |
222 |
getLogger().setLevel(Level.FINE); |
getLogger().setLevel(Level.FINE); |
|
Logger.getLogger("org.linuxsampler.lscp").addHandler(handler); |
|
223 |
Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE); |
Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE); |
224 |
|
Logger.getLogger("org.linuxsampler.lscp").addHandler(handler); |
225 |
|
|
226 |
// Flushing logs on every second |
// Flushing logs on every second |
227 |
new java.util.Timer().schedule(new java.util.TimerTask() { |
new java.util.Timer().schedule(new java.util.TimerTask() { |
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 |
} |
} |
372 |
public static OrchestraListModel |
public static OrchestraListModel |
373 |
getOrchestras() { return orchestras; } |
getOrchestras() { return orchestras; } |
374 |
|
|
375 |
|
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
376 |
|
/** |
377 |
|
* Gets the tree model of the instruments database. |
378 |
|
* If the currently used view doesn't have instruments |
379 |
|
* database support the tree model is initialized on first use. |
380 |
|
* @return The tree model of the instruments database or |
381 |
|
* <code>null</code> if the backend doesn't have instruments database support. |
382 |
|
* @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport |
383 |
|
*/ |
384 |
|
public static InstrumentsDbTreeModel |
385 |
|
getInstrumentsDbTreeModel() { |
386 |
|
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
387 |
|
|
388 |
|
if(instrumentsDbTreeModel == null) { |
389 |
|
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
390 |
|
} |
391 |
|
|
392 |
|
return instrumentsDbTreeModel; |
393 |
|
} |
394 |
|
|
395 |
/** |
/** |
396 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
397 |
* 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 |
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 |
539 |
initSamplerModel() { |
initSamplerModel() { |
540 |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
541 |
|
|
542 |
final GetServerInfo gsi = new GetServerInfo(); |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
543 |
gsi.addTaskListener(new TaskListener() { |
gsi.addTaskListener(new TaskListener() { |
544 |
public void |
public void |
545 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
546 |
if(!gsi.doneWithErrors()) model.setServerInfo(gsi.getResult()); |
if(gsi.doneWithErrors()) return; |
547 |
|
|
548 |
|
model.setServerInfo(gsi.getResult()); |
549 |
|
|
550 |
|
if(CC.getViewConfig().getInstrumentsDbSupport()) { |
551 |
|
getInstrumentsDbTreeModel(); |
552 |
|
} |
553 |
} |
} |
554 |
}); |
}); |
555 |
|
|
605 |
uc.addTaskListener(new TaskListener() { |
uc.addTaskListener(new TaskListener() { |
606 |
public void |
public void |
607 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
608 |
for(SamplerChannelModel c : model.getChannelModels()) { |
for(SamplerChannelModel c : model.getChannels()) { |
609 |
if(c.getChannelInfo().getEngine() == null) continue; |
if(c.getChannelInfo().getEngine() == null) continue; |
610 |
|
|
611 |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
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 |
|
|
645 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
646 |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
647 |
if(gfs.doneWithErrors()) return; |
if(gfs.doneWithErrors()) return; |
648 |
SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel()); |
SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel()); |
649 |
m.removeAllFxSends(); |
m.removeAllFxSends(); |
650 |
|
|
651 |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
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"); |
718 |
sb.append("\r\n"); |
sb.append("\r\n"); |
719 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
720 |
|
|
721 |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels(); |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
722 |
for(int i = 0; i < mDevs.length; i++) { |
for(int i = 0; i < mDevs.length; i++) { |
723 |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
724 |
sb.append(out.toString()); |
sb.append(out.toString()); |
726 |
sb.append("\r\n"); |
sb.append("\r\n"); |
727 |
} |
} |
728 |
|
|
729 |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels(); |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices(); |
730 |
for(int i = 0; i < aDevs.length; i++) { |
for(int i = 0; i < aDevs.length; i++) { |
731 |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
732 |
sb.append(out.toString()); |
sb.append(out.toString()); |
734 |
sb.append("\r\n"); |
sb.append("\r\n"); |
735 |
} |
} |
736 |
|
|
737 |
SamplerChannelModel[] channels = getSamplerModel().getChannelModels(); |
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().getChannelModel(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. */ |
949 |
public void |
public void |
950 |
streamCountChanged(StreamCountEvent e) { |
streamCountChanged(StreamCountEvent e) { |
951 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
952 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
953 |
|
|
954 |
if(scm == null) { |
if(scm == null) { |
955 |
CC.getLogger().log ( |
CC.getLogger().log ( |
971 |
public void |
public void |
972 |
voiceCountChanged(VoiceCountEvent e) { |
voiceCountChanged(VoiceCountEvent e) { |
973 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
974 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
975 |
|
|
976 |
if(scm == null) { |
if(scm == null) { |
977 |
CC.getLogger().log ( |
CC.getLogger().log ( |
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) { |
1034 |
break; |
break; |
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 |
HF.showErrorMessage(t.getErrorMessage()); |
showError(t); |
1039 |
|
} |
1040 |
break; |
break; |
1041 |
case NOT_IDLE: |
case NOT_IDLE: |
1042 |
timer.start(); |
timer.start(); |
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(); } |