42 |
|
|
43 |
import javax.swing.Timer; |
import javax.swing.Timer; |
44 |
|
|
45 |
|
import javax.swing.event.ChangeEvent; |
46 |
|
import javax.swing.event.ChangeListener; |
47 |
|
|
48 |
import net.sf.juife.Task; |
import net.sf.juife.Task; |
49 |
import net.sf.juife.TaskQueue; |
import net.sf.juife.TaskQueue; |
50 |
|
|
62 |
|
|
63 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
64 |
import org.jsampler.view.JSProgress; |
import org.jsampler.view.JSProgress; |
65 |
|
import org.jsampler.view.JSViewConfig; |
66 |
|
import org.jsampler.view.InstrumentsDbTreeModel; |
67 |
|
|
68 |
import org.linuxsampler.lscp.AudioOutputChannel; |
import org.linuxsampler.lscp.AudioOutputChannel; |
69 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
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; |
83 |
|
import static org.jsampler.JSPrefs.MANUAL_SERVER_SELECT_ON_STARTUP; |
84 |
|
|
85 |
|
|
86 |
/** |
/** |
92 |
private static Handler handler; |
private static Handler handler; |
93 |
private static FileOutputStream fos; |
private static FileOutputStream fos; |
94 |
|
|
95 |
|
private static JSViewConfig viewConfig = null; |
96 |
private static JSMainFrame mainFrame = null; |
private static JSMainFrame mainFrame = null; |
97 |
private static JSProgress progress = null; |
private static JSProgress progress = null; |
98 |
|
|
129 |
getTaskQueue() { return taskQueue; } |
getTaskQueue() { return taskQueue; } |
130 |
|
|
131 |
/** |
/** |
132 |
|
* Adds the specified task to the task queue. All task in the |
133 |
|
* queue equal to the specified task are removed from the queue. |
134 |
|
*/ |
135 |
|
public static void |
136 |
|
scheduleTask(Task t) { |
137 |
|
while(getTaskQueue().removeTask(t)) { } |
138 |
|
|
139 |
|
if(getTaskQueue().getPendingTaskCount() == 0) { |
140 |
|
if(t.equals(getTaskQueue().getRunningTask())) return; |
141 |
|
} |
142 |
|
|
143 |
|
getTaskQueue().add(t); |
144 |
|
} |
145 |
|
|
146 |
|
/** |
147 |
|
* Gets the configuration of the current view. |
148 |
|
*/ |
149 |
|
public static JSViewConfig |
150 |
|
getViewConfig() { return viewConfig; } |
151 |
|
|
152 |
|
private static JSPrefs |
153 |
|
preferences() { return getViewConfig().preferences(); } |
154 |
|
|
155 |
|
/** |
156 |
|
* Sets the configuration of the current view. |
157 |
|
*/ |
158 |
|
public static void |
159 |
|
setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; } |
160 |
|
|
161 |
|
/** |
162 |
* Returns the main window of this application. |
* Returns the main window of this application. |
163 |
* @return The main window of this application. |
* @return The main window of this application. |
164 |
*/ |
*/ |
227 |
handler.setLevel(Level.FINE); |
handler.setLevel(Level.FINE); |
228 |
getLogger().addHandler(handler); |
getLogger().addHandler(handler); |
229 |
getLogger().setLevel(Level.FINE); |
getLogger().setLevel(Level.FINE); |
|
Logger.getLogger("org.linuxsampler.lscp").addHandler(handler); |
|
230 |
Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE); |
Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE); |
231 |
|
Logger.getLogger("org.linuxsampler.lscp").addHandler(handler); |
232 |
|
|
233 |
// Flushing logs on every second |
// Flushing logs on every second |
234 |
new java.util.Timer().schedule(new java.util.TimerTask() { |
new java.util.Timer().schedule(new java.util.TimerTask() { |
240 |
|
|
241 |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
242 |
|
|
|
getClient().setServerAddress(Prefs.getLSAddress()); |
|
|
getClient().setServerPort(Prefs.getLSPort()); |
|
|
|
|
243 |
timer.setRepeats(false); |
timer.setRepeats(false); |
244 |
|
|
245 |
timer.addActionListener(new ActionListener() { |
timer.addActionListener(new ActionListener() { |
269 |
getClient().removeVoiceCountListener(getHandler()); |
getClient().removeVoiceCountListener(getHandler()); |
270 |
getClient().addVoiceCountListener(getHandler()); |
getClient().addVoiceCountListener(getHandler()); |
271 |
|
|
272 |
|
getClient().removeTotalStreamCountListener(getHandler()); |
273 |
|
getClient().addTotalStreamCountListener(getHandler()); |
274 |
|
|
275 |
getClient().removeTotalVoiceCountListener(getHandler()); |
getClient().removeTotalVoiceCountListener(getHandler()); |
276 |
getClient().addTotalVoiceCountListener(getHandler()); |
getClient().addTotalVoiceCountListener(getHandler()); |
277 |
|
|
314 |
checkJSamplerHome() { |
checkJSamplerHome() { |
315 |
if(getJSamplerHome() != null) { |
if(getJSamplerHome() != null) { |
316 |
File f = new File(getJSamplerHome()); |
File f = new File(getJSamplerHome()); |
317 |
if(f.isDirectory()) return; |
if(f.exists() && f.isDirectory()) { |
318 |
|
return; |
319 |
|
} |
320 |
} |
} |
321 |
|
|
322 |
CC.getMainFrame().installJSamplerHome(); |
CC.getMainFrame().installJSamplerHome(); |
332 |
public static void |
public static void |
333 |
changeJSamplerHome(String path) { |
changeJSamplerHome(String path) { |
334 |
File fNew = new File(path); |
File fNew = new File(path); |
335 |
if(fNew.isFile()) { |
if(fNew.exists() && fNew.isFile()) { |
336 |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
337 |
return; |
return; |
338 |
} |
} |
339 |
|
|
340 |
if(!fNew.isDirectory()) { |
if(!fNew.exists()) { |
341 |
if(!fNew.mkdir()) { |
if(!fNew.mkdir()) { |
342 |
String s = fNew.getAbsolutePath(); |
String s = fNew.getAbsolutePath(); |
343 |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
345 |
} |
} |
346 |
} |
} |
347 |
|
|
348 |
if(getJSamplerHome() == null) { |
if(getJSamplerHome() == null || path.equals(getJSamplerHome())) { |
349 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
350 |
return; |
return; |
351 |
} |
} |
352 |
|
|
353 |
File fOld = new File(getJSamplerHome()); |
File fOld = new File(getJSamplerHome()); |
354 |
if(!fOld.isDirectory()) { |
if(!fOld.exists() || !fOld.isDirectory()) { |
355 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
356 |
return; |
return; |
357 |
} |
} |
376 |
public static OrchestraListModel |
public static OrchestraListModel |
377 |
getOrchestras() { return orchestras; } |
getOrchestras() { return orchestras; } |
378 |
|
|
379 |
|
private final static ServerList servers = new ServerList(); |
380 |
|
|
381 |
|
/** Returns the server list. */ |
382 |
|
public static ServerList |
383 |
|
getServerList() { return servers; } |
384 |
|
|
385 |
|
private static ServerListListener serverListListener = new ServerListListener(); |
386 |
|
|
387 |
|
private static class ServerListListener implements ChangeListener { |
388 |
|
public void |
389 |
|
stateChanged(ChangeEvent e) { |
390 |
|
saveServerList(); |
391 |
|
} |
392 |
|
} |
393 |
|
|
394 |
|
private static final Vector<ChangeListener> idtmListeners = new Vector<ChangeListener>(); |
395 |
|
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
396 |
|
|
397 |
|
/** |
398 |
|
* Gets the tree model of the instruments database. |
399 |
|
* If the currently used view doesn't have instruments |
400 |
|
* database support the tree model is initialized on first use. |
401 |
|
* @return The tree model of the instruments database or |
402 |
|
* <code>null</code> if the backend doesn't have instruments database support. |
403 |
|
* @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport |
404 |
|
*/ |
405 |
|
public static InstrumentsDbTreeModel |
406 |
|
getInstrumentsDbTreeModel() { |
407 |
|
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
408 |
|
|
409 |
|
if(instrumentsDbTreeModel == null) { |
410 |
|
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
411 |
|
for(ChangeListener l : idtmListeners) l.stateChanged(null); |
412 |
|
} |
413 |
|
|
414 |
|
return instrumentsDbTreeModel; |
415 |
|
} |
416 |
|
|
417 |
|
public static void |
418 |
|
addInstrumentsDbChangeListener(ChangeListener l) { |
419 |
|
idtmListeners.add(l); |
420 |
|
} |
421 |
|
|
422 |
|
public static void |
423 |
|
removeInstrumentsDbChangeListener(ChangeListener l) { |
424 |
|
idtmListeners.remove(l); |
425 |
|
} |
426 |
|
|
427 |
/** |
/** |
428 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
429 |
* 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 |
435 |
loadOrchestras() { |
loadOrchestras() { |
436 |
if(getJSamplerHome() == null) return; |
if(getJSamplerHome() == null) return; |
437 |
|
|
|
//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; |
|
|
} |
|
|
/////// |
|
|
|
|
438 |
try { |
try { |
439 |
String s = getJSamplerHome(); |
String s = getJSamplerHome(); |
|
if(s == null) return; |
|
440 |
|
|
441 |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
442 |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
449 |
} catch(Exception x) { |
} catch(Exception x) { |
450 |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
451 |
} |
} |
452 |
|
|
453 |
|
getOrchestras().addOrchestraListListener(getHandler()); |
454 |
} |
} |
455 |
|
|
456 |
|
|
467 |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
468 |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
469 |
} |
} |
|
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: "); } |
|
470 |
} |
} |
471 |
|
|
472 |
private static void |
private static void |
501 |
} |
} |
502 |
|
|
503 |
/** |
/** |
504 |
|
* Loads the servers' info described in <code><jsampler_home>/servers.xml</code>. |
505 |
|
* If file with name <code>servers.xml.bkp</code> exist in the JSampler's home |
506 |
|
* directory, this means that the last save has failed. In that case a recovery file |
507 |
|
* <code>servers.xml.rec</code> is created and a recovery procedure |
508 |
|
* will be initiated. |
509 |
|
*/ |
510 |
|
public static void |
511 |
|
loadServerList() { |
512 |
|
if(getJSamplerHome() == null) return; |
513 |
|
|
514 |
|
try { |
515 |
|
String s = getJSamplerHome(); |
516 |
|
|
517 |
|
File f = new File(s + File.separator + "servers.xml.bkp"); |
518 |
|
if(f.isFile()) HF.createBackup("servers.xml.bkp", "servers.xml.rec"); |
519 |
|
|
520 |
|
FileInputStream fis; |
521 |
|
fis = new FileInputStream(s + File.separator + "servers.xml"); |
522 |
|
|
523 |
|
loadServerList(fis); |
524 |
|
fis.close(); |
525 |
|
} catch(Exception x) { |
526 |
|
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
527 |
|
} |
528 |
|
|
529 |
|
getServerList().addChangeListener(serverListListener); |
530 |
|
|
531 |
|
/* We should have at least one server to connect. */ |
532 |
|
if(getServerList().getServerCount() == 0) { |
533 |
|
Server server = new Server(); |
534 |
|
server.setName("127.0.0.1:8888"); |
535 |
|
server.setAddress("127.0.0.1"); |
536 |
|
server.setPort(8888); |
537 |
|
getServerList().addServer(server); |
538 |
|
} |
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
private static void |
543 |
|
loadServerList(InputStream in) { |
544 |
|
Document doc = DOMUtils.readObject(in); |
545 |
|
|
546 |
|
try { getServerList().readObject(doc.getDocumentElement()); } |
547 |
|
catch(Exception x) { |
548 |
|
HF.showErrorMessage(x, "Loading server list: "); |
549 |
|
return; |
550 |
|
} |
551 |
|
} |
552 |
|
|
553 |
|
private static void |
554 |
|
saveServerList() { |
555 |
|
try { |
556 |
|
String s = getJSamplerHome(); |
557 |
|
if(s == null) return; |
558 |
|
|
559 |
|
HF.createBackup("servers.xml", "servers.xml.bkp"); |
560 |
|
|
561 |
|
FileOutputStream fos; |
562 |
|
fos = new FileOutputStream(s + File.separator + "servers.xml", false); |
563 |
|
|
564 |
|
Document doc = DOMUtils.createEmptyDocument(); |
565 |
|
|
566 |
|
Node node = doc.createElement("temp"); |
567 |
|
doc.appendChild(node); |
568 |
|
|
569 |
|
getServerList().writeObject(doc, doc.getDocumentElement()); |
570 |
|
|
571 |
|
doc.replaceChild(node.getFirstChild(), node); |
572 |
|
|
573 |
|
DOMUtils.writeObject(doc, fos); |
574 |
|
|
575 |
|
fos.close(); |
576 |
|
|
577 |
|
HF.deleteFile("servers.xml.bkp"); |
578 |
|
} catch(Exception x) { |
579 |
|
HF.showErrorMessage(x, "Saving server list: "); |
580 |
|
return; |
581 |
|
} |
582 |
|
} |
583 |
|
|
584 |
|
/** |
585 |
* 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. |
586 |
* @see #cleanExit(int i) |
* @see #cleanExit(int i) |
587 |
*/ |
*/ |
637 |
getSamplerModel() { return samplerModel; } |
getSamplerModel() { return samplerModel; } |
638 |
|
|
639 |
/** |
/** |
640 |
|
* Connects to LinuxSampler. |
641 |
|
*/ |
642 |
|
public static void |
643 |
|
connect() { initSamplerModel(); } |
644 |
|
|
645 |
|
/** |
646 |
* Reconnects to LinuxSampler. |
* Reconnects to LinuxSampler. |
647 |
*/ |
*/ |
648 |
public static void |
public static void |
649 |
reconnect() { |
reconnect() { initSamplerModel(getCurrentServer()); } |
650 |
initSamplerModel(); |
|
651 |
fireReconnectEvent(); |
private static Server currentServer = null; |
|
} |
|
652 |
|
|
653 |
/** |
/** |
654 |
* This method updates the information about the backend state. |
* Gets the server, to which the frontend is going to connect |
655 |
|
* or is already connected. |
656 |
|
*/ |
657 |
|
public static Server |
658 |
|
getCurrentServer() { return currentServer; } |
659 |
|
|
660 |
|
/** |
661 |
|
* Sets the current server. |
662 |
*/ |
*/ |
663 |
public static void |
public static void |
664 |
|
setCurrentServer(Server server) { currentServer = server; } |
665 |
|
|
666 |
|
/** |
667 |
|
* This method updates the information about the backend state. |
668 |
|
*/ |
669 |
|
private static void |
670 |
initSamplerModel() { |
initSamplerModel() { |
671 |
|
Server srv = getMainFrame().getServer(); |
672 |
|
if(srv == null) return; |
673 |
|
initSamplerModel(srv); |
674 |
|
} |
675 |
|
|
676 |
|
/** |
677 |
|
* This method updates the information about the backend state. |
678 |
|
*/ |
679 |
|
private static void |
680 |
|
initSamplerModel(Server srv) { |
681 |
|
setCurrentServer(srv); |
682 |
|
final SetServerAddress ssa = new SetServerAddress(srv.getAddress(), srv.getPort()); |
683 |
|
|
684 |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
685 |
|
|
686 |
final GetServerInfo gsi = new GetServerInfo(); |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
687 |
gsi.addTaskListener(new TaskListener() { |
gsi.addTaskListener(new TaskListener() { |
688 |
public void |
public void |
689 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
690 |
if(!gsi.doneWithErrors()) model.setServerInfo(gsi.getResult()); |
if(gsi.doneWithErrors()) return; |
691 |
|
|
692 |
|
model.setServerInfo(gsi.getResult()); |
693 |
|
|
694 |
|
if(CC.getViewConfig().getInstrumentsDbSupport()) { |
695 |
|
getInstrumentsDbTreeModel(); |
696 |
|
} |
697 |
} |
} |
698 |
}); |
}); |
699 |
|
|
749 |
uc.addTaskListener(new TaskListener() { |
uc.addTaskListener(new TaskListener() { |
750 |
public void |
public void |
751 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
752 |
for(SamplerChannelModel c : model.getChannelModels()) { |
for(SamplerChannelModel c : model.getChannels()) { |
753 |
if(c.getChannelInfo().getEngine() == null) continue; |
if(c.getChannelInfo().getEngine() == null) continue; |
754 |
|
|
755 |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
757 |
gfs.addTaskListener(new GetFxSendsListener()); |
gfs.addTaskListener(new GetFxSendsListener()); |
758 |
getTaskQueue().add(gfs); |
getTaskQueue().add(gfs); |
759 |
} |
} |
760 |
|
|
761 |
|
// TODO: This should be done after the fx sends are set |
762 |
|
//CC.getSamplerModel().setModified(false); |
763 |
} |
} |
764 |
}); |
}); |
765 |
|
|
768 |
cnt.addTaskListener(new TaskListener() { |
cnt.addTaskListener(new TaskListener() { |
769 |
public void |
public void |
770 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
771 |
if(cnt.doneWithErrors()) return; |
if(cnt.doneWithErrors()) { |
772 |
|
setCurrentServer(null); |
773 |
|
retryToConnect(); |
774 |
|
return; |
775 |
|
} |
776 |
|
|
777 |
getTaskQueue().add(gsi); |
getTaskQueue().add(gsi); |
778 |
getTaskQueue().add(gaod); |
getTaskQueue().add(gaod); |
785 |
getTaskQueue().add(uc); |
getTaskQueue().add(uc); |
786 |
} |
} |
787 |
}); |
}); |
788 |
getTaskQueue().add(cnt); |
|
789 |
|
ssa.addTaskListener(new TaskListener() { |
790 |
|
public void |
791 |
|
taskPerformed(TaskEvent e) { |
792 |
|
CC.getTaskQueue().add(cnt); |
793 |
|
} |
794 |
|
}); |
795 |
|
|
796 |
|
getSamplerModel().reset(); |
797 |
|
if(instrumentsDbTreeModel != null) { |
798 |
|
instrumentsDbTreeModel.reset(); |
799 |
|
instrumentsDbTreeModel = null; |
800 |
|
} |
801 |
|
|
802 |
|
getTaskQueue().removePendingTasks(); |
803 |
|
getTaskQueue().add(ssa); |
804 |
|
|
805 |
|
fireReconnectEvent(); |
806 |
|
} |
807 |
|
|
808 |
|
private static void |
809 |
|
retryToConnect() { |
810 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
811 |
|
public void |
812 |
|
run() { changeBackend(); } |
813 |
|
}); |
814 |
|
} |
815 |
|
|
816 |
|
public static void |
817 |
|
changeBackend() { |
818 |
|
Server s = getMainFrame().getServer(true); |
819 |
|
if(s != null) initSamplerModel(s); |
820 |
} |
} |
821 |
|
|
822 |
private static class GetFxSendsListener implements TaskListener { |
private static class GetFxSendsListener implements TaskListener { |
824 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
825 |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
826 |
if(gfs.doneWithErrors()) return; |
if(gfs.doneWithErrors()) return; |
827 |
SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel()); |
SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel()); |
828 |
m.removeAllFxSends(); |
m.removeAllFxSends(); |
829 |
|
|
830 |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
875 |
|
|
876 |
public static String |
public static String |
877 |
exportSessionToLscpScript() { |
exportSessionToLscpScript() { |
878 |
|
CC.getSamplerModel().setModified(false); |
879 |
|
|
880 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
StringBuffer sb = new StringBuffer("# Exported by: "); |
881 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
882 |
sb.append(JSampler.VERSION).append("\r\n"); |
sb.append(JSampler.VERSION).append("\r\n"); |
897 |
sb.append("\r\n"); |
sb.append("\r\n"); |
898 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
899 |
|
|
900 |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels(); |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
901 |
for(int i = 0; i < mDevs.length; i++) { |
for(int i = 0; i < mDevs.length; i++) { |
902 |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
903 |
sb.append(out.toString()); |
sb.append(out.toString()); |
905 |
sb.append("\r\n"); |
sb.append("\r\n"); |
906 |
} |
} |
907 |
|
|
908 |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels(); |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices(); |
909 |
for(int i = 0; i < aDevs.length; i++) { |
for(int i = 0; i < aDevs.length; i++) { |
910 |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
911 |
sb.append(out.toString()); |
sb.append(out.toString()); |
913 |
sb.append("\r\n"); |
sb.append("\r\n"); |
914 |
} |
} |
915 |
|
|
916 |
SamplerChannelModel[] channels = getSamplerModel().getChannelModels(); |
exportInstrMapsToLscpScript(lscpClient); |
917 |
|
sb.append(out.toString()); |
918 |
|
out.reset(); |
919 |
|
|
920 |
|
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
921 |
|
|
922 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
923 |
SamplerChannelModel scm = getSamplerModel().getChannelModel(i); |
SamplerChannelModel scm = channels[i]; |
924 |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
925 |
sb.append(out.toString()); |
sb.append(out.toString()); |
926 |
out.reset(); |
out.reset(); |
934 |
sb.append("\r\n"); |
sb.append("\r\n"); |
935 |
} |
} |
936 |
|
|
|
exportInstrMapsToLscpScript(lscpClient); |
|
|
sb.append(out.toString()); |
|
|
out.reset(); |
|
|
|
|
937 |
return sb.toString(); |
return sb.toString(); |
938 |
} |
} |
939 |
|
|
984 |
try { |
try { |
985 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
986 |
|
|
987 |
int i = chn.getMidiInputDevice(); |
SamplerModel sm = CC.getSamplerModel(); |
988 |
if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i); |
int id = chn.getMidiInputDevice(); |
989 |
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
if(id != -1) { |
990 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
991 |
|
if(sm.getMidiDevice(i).getDeviceId() == id) { |
992 |
i = chn.getAudioOutputDevice(); |
lscpCLient.setChannelMidiInputDevice(chnId, i); |
993 |
if(i != -1) { |
break; |
994 |
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
} |
995 |
|
} |
996 |
|
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
997 |
|
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
998 |
|
} |
999 |
|
|
1000 |
|
if(chn.getEngine() != null) { |
1001 |
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
1002 |
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
1003 |
|
int mapId = chn.getMidiInstrumentMapId(); |
1004 |
|
lscpCLient.setChannelMidiInstrumentMap(chnId, mapId); |
1005 |
|
} |
1006 |
|
|
1007 |
|
id = chn.getAudioOutputDevice(); |
1008 |
|
if(id != -1) { |
1009 |
|
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
1010 |
|
if(sm.getAudioDevice(i).getDeviceId() == id) { |
1011 |
|
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
1012 |
|
break; |
1013 |
|
} |
1014 |
|
} |
1015 |
|
|
1016 |
Integer[] routing = chn.getAudioOutputRouting(); |
Integer[] routing = chn.getAudioOutputRouting(); |
1017 |
|
|
1018 |
for(int j = 0; j < routing.length; j++) { |
for(int j = 0; j < routing.length; j++) { |
1023 |
} |
} |
1024 |
} |
} |
1025 |
|
|
|
if(chn.getEngine() != null) { |
|
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
|
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
|
|
} |
|
|
|
|
1026 |
String s = chn.getInstrumentFile(); |
String s = chn.getInstrumentFile(); |
1027 |
i = chn.getInstrumentIndex(); |
int i = chn.getInstrumentIndex(); |
1028 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
1029 |
|
|
1030 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
1053 |
} |
} |
1054 |
} |
} |
1055 |
|
|
1056 |
|
public static void |
1057 |
|
scheduleInTaskQueue(final Runnable r) { |
1058 |
|
Task dummy = new Global.DummyTask(); |
1059 |
|
dummy.addTaskListener(new TaskListener() { |
1060 |
|
public void |
1061 |
|
taskPerformed(TaskEvent e) { |
1062 |
|
javax.swing.SwingUtilities.invokeLater(r); |
1063 |
|
} |
1064 |
|
}); |
1065 |
|
|
1066 |
|
CC.getTaskQueue().add(dummy); |
1067 |
|
} |
1068 |
|
|
1069 |
|
public static boolean |
1070 |
|
verifyConnection() { |
1071 |
|
if(getCurrentServer() == null) { |
1072 |
|
HF.showErrorMessage(i18n.getError("CC.notConnected")); |
1073 |
|
return false; |
1074 |
|
} |
1075 |
|
|
1076 |
|
return true; |
1077 |
|
} |
1078 |
|
|
1079 |
|
|
1080 |
private final static EventHandler eventHandler = new EventHandler(); |
private final static EventHandler eventHandler = new EventHandler(); |
1081 |
|
|
1084 |
|
|
1085 |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
1086 |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
1087 |
TotalVoiceCountListener, TaskQueueListener, OrchestraListener, |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
1088 |
ListListener<OrchestraModel>, MidiInstrumentCountListener, |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
1089 |
MidiInstrumentInfoListener, GlobalInfoListener { |
MidiInstrumentInfoListener, GlobalInfoListener { |
1090 |
|
|
1091 |
/** Invoked when the number of channels has changed. */ |
/** Invoked when the number of channels has changed. */ |
1153 |
public void |
public void |
1154 |
streamCountChanged(StreamCountEvent e) { |
streamCountChanged(StreamCountEvent e) { |
1155 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
1156 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
1157 |
|
|
1158 |
if(scm == null) { |
if(scm == null) { |
1159 |
CC.getLogger().log ( |
CC.getLogger().log ( |
1175 |
public void |
public void |
1176 |
voiceCountChanged(VoiceCountEvent e) { |
voiceCountChanged(VoiceCountEvent e) { |
1177 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
1178 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
1179 |
|
|
1180 |
if(scm == null) { |
if(scm == null) { |
1181 |
CC.getLogger().log ( |
CC.getLogger().log ( |
1190 |
scm.setVoiceCount(e.getVoiceCount()); |
scm.setVoiceCount(e.getVoiceCount()); |
1191 |
} |
} |
1192 |
|
|
1193 |
|
/** Invoked when the total number of active streams has changed. */ |
1194 |
|
public void |
1195 |
|
totalStreamCountChanged(TotalStreamCountEvent e) { |
1196 |
|
getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount()); |
1197 |
|
} |
1198 |
|
|
1199 |
/** Invoked when the total number of active voices has changed. */ |
/** Invoked when the total number of active voices has changed. */ |
1200 |
public void |
public void |
1201 |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
1238 |
break; |
break; |
1239 |
case TASK_DONE: |
case TASK_DONE: |
1240 |
EnhancedTask t = (EnhancedTask)e.getSource(); |
EnhancedTask t = (EnhancedTask)e.getSource(); |
1241 |
if(t.doneWithErrors() && !t.isStopped()) |
if(t.doneWithErrors() && !t.isStopped()) { |
1242 |
HF.showErrorMessage(t.getErrorMessage()); |
showError(t); |
1243 |
|
} |
1244 |
break; |
break; |
1245 |
case NOT_IDLE: |
case NOT_IDLE: |
1246 |
timer.start(); |
timer.start(); |
1252 |
} |
} |
1253 |
} |
} |
1254 |
|
|
1255 |
|
private void |
1256 |
|
showError(final Task t) { |
1257 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
1258 |
|
public void |
1259 |
|
run() { |
1260 |
|
if(t.getErrorDetails() == null) { |
1261 |
|
HF.showErrorMessage(t.getErrorMessage()); |
1262 |
|
} else { |
1263 |
|
getMainFrame().showDetailedErrorMessage ( |
1264 |
|
getMainFrame(), |
1265 |
|
t.getErrorMessage(), |
1266 |
|
t.getErrorDetails() |
1267 |
|
); |
1268 |
|
} |
1269 |
|
} |
1270 |
|
}); |
1271 |
|
} |
1272 |
|
|
1273 |
/** Invoked when the name of orchestra is changed. */ |
/** Invoked when the name of orchestra is changed. */ |
1274 |
public void |
public void |
1275 |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |