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() { |
307 |
checkJSamplerHome() { |
checkJSamplerHome() { |
308 |
if(getJSamplerHome() != null) { |
if(getJSamplerHome() != null) { |
309 |
File f = new File(getJSamplerHome()); |
File f = new File(getJSamplerHome()); |
310 |
if(f.isDirectory()) return; |
if(f.exists() && f.isDirectory()) { |
311 |
|
return; |
312 |
|
} |
313 |
} |
} |
314 |
|
|
315 |
CC.getMainFrame().installJSamplerHome(); |
CC.getMainFrame().installJSamplerHome(); |
325 |
public static void |
public static void |
326 |
changeJSamplerHome(String path) { |
changeJSamplerHome(String path) { |
327 |
File fNew = new File(path); |
File fNew = new File(path); |
328 |
if(fNew.isFile()) { |
if(fNew.exists() && fNew.isFile()) { |
329 |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
330 |
return; |
return; |
331 |
} |
} |
332 |
|
|
333 |
if(!fNew.isDirectory()) { |
if(!fNew.exists()) { |
334 |
if(!fNew.mkdir()) { |
if(!fNew.mkdir()) { |
335 |
String s = fNew.getAbsolutePath(); |
String s = fNew.getAbsolutePath(); |
336 |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
338 |
} |
} |
339 |
} |
} |
340 |
|
|
341 |
if(getJSamplerHome() == null) { |
if(getJSamplerHome() == null || path.equals(getJSamplerHome())) { |
342 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
343 |
return; |
return; |
344 |
} |
} |
345 |
|
|
346 |
File fOld = new File(getJSamplerHome()); |
File fOld = new File(getJSamplerHome()); |
347 |
if(!fOld.isDirectory()) { |
if(!fOld.exists() || !fOld.isDirectory()) { |
348 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
349 |
return; |
return; |
350 |
} |
} |
369 |
public static OrchestraListModel |
public static OrchestraListModel |
370 |
getOrchestras() { return orchestras; } |
getOrchestras() { return orchestras; } |
371 |
|
|
372 |
|
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
373 |
|
/** |
374 |
|
* Gets the tree model of the instruments database. |
375 |
|
* If the currently used view doesn't have instruments |
376 |
|
* database support the tree model is initialized on first use. |
377 |
|
* @return The tree model of the instruments database or |
378 |
|
* <code>null</code> if the backend doesn't have instruments database support. |
379 |
|
* @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport |
380 |
|
*/ |
381 |
|
public static InstrumentsDbTreeModel |
382 |
|
getInstrumentsDbTreeModel() { |
383 |
|
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
384 |
|
|
385 |
|
if(instrumentsDbTreeModel == null) { |
386 |
|
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
387 |
|
} |
388 |
|
|
389 |
|
return instrumentsDbTreeModel; |
390 |
|
} |
391 |
|
|
392 |
/** |
/** |
393 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
394 |
* 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 |
400 |
loadOrchestras() { |
loadOrchestras() { |
401 |
if(getJSamplerHome() == null) return; |
if(getJSamplerHome() == null) return; |
402 |
|
|
|
//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; |
|
|
} |
|
|
/////// |
|
|
|
|
403 |
try { |
try { |
404 |
String s = getJSamplerHome(); |
String s = getJSamplerHome(); |
405 |
if(s == null) return; |
if(s == null) return; |
406 |
|
getOrchestras().addOrchestraListListener(getHandler()); |
407 |
|
|
408 |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
409 |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
432 |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
433 |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
434 |
} |
} |
|
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: "); } |
|
435 |
} |
} |
436 |
|
|
437 |
private static void |
private static void |
536 |
initSamplerModel() { |
initSamplerModel() { |
537 |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
538 |
|
|
539 |
final GetServerInfo gsi = new GetServerInfo(); |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
540 |
gsi.addTaskListener(new TaskListener() { |
gsi.addTaskListener(new TaskListener() { |
541 |
public void |
public void |
542 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
543 |
if(!gsi.doneWithErrors()) model.setServerInfo(gsi.getResult()); |
if(gsi.doneWithErrors()) return; |
544 |
|
|
545 |
|
model.setServerInfo(gsi.getResult()); |
546 |
|
|
547 |
|
if(CC.getViewConfig().getInstrumentsDbSupport()) { |
548 |
|
getInstrumentsDbTreeModel(); |
549 |
|
} |
550 |
} |
} |
551 |
}); |
}); |
552 |
|
|
602 |
uc.addTaskListener(new TaskListener() { |
uc.addTaskListener(new TaskListener() { |
603 |
public void |
public void |
604 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
605 |
for(SamplerChannelModel c : model.getChannelModels()) { |
for(SamplerChannelModel c : model.getChannels()) { |
606 |
if(c.getChannelInfo().getEngine() == null) continue; |
if(c.getChannelInfo().getEngine() == null) continue; |
607 |
|
|
608 |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
639 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
640 |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
641 |
if(gfs.doneWithErrors()) return; |
if(gfs.doneWithErrors()) return; |
642 |
SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel()); |
SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel()); |
643 |
m.removeAllFxSends(); |
m.removeAllFxSends(); |
644 |
|
|
645 |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
710 |
sb.append("\r\n"); |
sb.append("\r\n"); |
711 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
712 |
|
|
713 |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels(); |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
714 |
for(int i = 0; i < mDevs.length; i++) { |
for(int i = 0; i < mDevs.length; i++) { |
715 |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
716 |
sb.append(out.toString()); |
sb.append(out.toString()); |
718 |
sb.append("\r\n"); |
sb.append("\r\n"); |
719 |
} |
} |
720 |
|
|
721 |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels(); |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices(); |
722 |
for(int i = 0; i < aDevs.length; i++) { |
for(int i = 0; i < aDevs.length; i++) { |
723 |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
exportAudioDeviceToLscpScript(aDevs[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 |
SamplerChannelModel[] channels = getSamplerModel().getChannelModels(); |
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
730 |
|
|
731 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
732 |
SamplerChannelModel scm = getSamplerModel().getChannelModel(i); |
SamplerChannelModel scm = channels[i]; |
733 |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
734 |
sb.append(out.toString()); |
sb.append(out.toString()); |
735 |
out.reset(); |
out.reset(); |
797 |
try { |
try { |
798 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
799 |
|
|
800 |
int i = chn.getMidiInputDevice(); |
SamplerModel sm = CC.getSamplerModel(); |
801 |
if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i); |
int id = chn.getMidiInputDevice(); |
802 |
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
if(id != -1) { |
803 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
804 |
|
if(sm.getMidiDevice(i).getDeviceId() == id) { |
805 |
i = chn.getAudioOutputDevice(); |
lscpCLient.setChannelMidiInputDevice(chnId, i); |
806 |
if(i != -1) { |
break; |
807 |
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
} |
808 |
|
} |
809 |
|
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
810 |
|
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
811 |
|
} |
812 |
|
|
813 |
|
id = chn.getAudioOutputDevice(); |
814 |
|
if(id != -1) { |
815 |
|
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
816 |
|
if(sm.getAudioDevice(i).getDeviceId() == id) { |
817 |
|
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
818 |
|
break; |
819 |
|
} |
820 |
|
} |
821 |
|
|
822 |
Integer[] routing = chn.getAudioOutputRouting(); |
Integer[] routing = chn.getAudioOutputRouting(); |
823 |
|
|
824 |
for(int j = 0; j < routing.length; j++) { |
for(int j = 0; j < routing.length; j++) { |
835 |
} |
} |
836 |
|
|
837 |
String s = chn.getInstrumentFile(); |
String s = chn.getInstrumentFile(); |
838 |
i = chn.getInstrumentIndex(); |
int i = chn.getInstrumentIndex(); |
839 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
840 |
|
|
841 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
941 |
public void |
public void |
942 |
streamCountChanged(StreamCountEvent e) { |
streamCountChanged(StreamCountEvent e) { |
943 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
944 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
945 |
|
|
946 |
if(scm == null) { |
if(scm == null) { |
947 |
CC.getLogger().log ( |
CC.getLogger().log ( |
963 |
public void |
public void |
964 |
voiceCountChanged(VoiceCountEvent e) { |
voiceCountChanged(VoiceCountEvent e) { |
965 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
966 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
967 |
|
|
968 |
if(scm == null) { |
if(scm == null) { |
969 |
CC.getLogger().log ( |
CC.getLogger().log ( |
1020 |
break; |
break; |
1021 |
case TASK_DONE: |
case TASK_DONE: |
1022 |
EnhancedTask t = (EnhancedTask)e.getSource(); |
EnhancedTask t = (EnhancedTask)e.getSource(); |
1023 |
if(t.doneWithErrors() && !t.isStopped()) |
if(t.doneWithErrors() && !t.isStopped()) { |
1024 |
HF.showErrorMessage(t.getErrorMessage()); |
showError(t); |
1025 |
|
} |
1026 |
break; |
break; |
1027 |
case NOT_IDLE: |
case NOT_IDLE: |
1028 |
timer.start(); |
timer.start(); |
1034 |
} |
} |
1035 |
} |
} |
1036 |
|
|
1037 |
|
private void |
1038 |
|
showError(final Task t) { |
1039 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
1040 |
|
public void |
1041 |
|
run() { |
1042 |
|
if(t.getErrorDetails() == null) { |
1043 |
|
HF.showErrorMessage(t.getErrorMessage()); |
1044 |
|
} else { |
1045 |
|
getMainFrame().showDetailedErrorMessage ( |
1046 |
|
getMainFrame(), |
1047 |
|
t.getErrorMessage(), |
1048 |
|
t.getErrorDetails() |
1049 |
|
); |
1050 |
|
} |
1051 |
|
} |
1052 |
|
}); |
1053 |
|
} |
1054 |
|
|
1055 |
/** Invoked when the name of orchestra is changed. */ |
/** Invoked when the name of orchestra is changed. */ |
1056 |
public void |
public void |
1057 |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |