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; |
41 |
|
|
42 |
import javax.swing.Timer; |
import javax.swing.Timer; |
43 |
|
|
44 |
|
import javax.swing.event.ChangeEvent; |
45 |
|
import javax.swing.event.ChangeListener; |
46 |
|
|
47 |
import net.sf.juife.Task; |
import net.sf.juife.Task; |
48 |
import net.sf.juife.TaskQueue; |
import net.sf.juife.TaskQueue; |
49 |
|
|
61 |
|
|
62 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
63 |
import org.jsampler.view.JSProgress; |
import org.jsampler.view.JSProgress; |
64 |
|
import org.jsampler.view.JSViewConfig; |
65 |
|
import org.jsampler.view.InstrumentsDbTreeModel; |
66 |
|
|
67 |
import org.linuxsampler.lscp.AudioOutputChannel; |
import org.linuxsampler.lscp.AudioOutputChannel; |
68 |
import org.linuxsampler.lscp.AudioOutputDevice; |
import org.linuxsampler.lscp.AudioOutputDevice; |
90 |
private static Handler handler; |
private static Handler handler; |
91 |
private static FileOutputStream fos; |
private static FileOutputStream fos; |
92 |
|
|
93 |
|
private static JSViewConfig viewConfig = null; |
94 |
private static JSMainFrame mainFrame = null; |
private static JSMainFrame mainFrame = null; |
95 |
private static JSProgress progress = null; |
private static JSProgress progress = null; |
96 |
|
|
127 |
getTaskQueue() { return taskQueue; } |
getTaskQueue() { return taskQueue; } |
128 |
|
|
129 |
/** |
/** |
130 |
|
* Adds the specified task to the task queue. All task in the |
131 |
|
* queue equal to the specified task are removed from the queue. |
132 |
|
*/ |
133 |
|
public static void |
134 |
|
scheduleTask(Task t) { |
135 |
|
while(getTaskQueue().removeTask(t)) { } |
136 |
|
|
137 |
|
getTaskQueue().add(t); |
138 |
|
} |
139 |
|
|
140 |
|
/** |
141 |
|
* Adds the specified task to the task queue only if the last |
142 |
|
* task in the is not equal to <code>t</code>. |
143 |
|
*/ |
144 |
|
public static void |
145 |
|
addTask(Task t) { |
146 |
|
Task[] tasks = getTaskQueue().getPendingTasks(); |
147 |
|
if(tasks.length > 0 && tasks[tasks.length - 1].equals(t)) return; |
148 |
|
getTaskQueue().add(t); |
149 |
|
} |
150 |
|
|
151 |
|
/** |
152 |
|
* Gets the configuration of the current view. |
153 |
|
*/ |
154 |
|
public static JSViewConfig |
155 |
|
getViewConfig() { return viewConfig; } |
156 |
|
|
157 |
|
public static JSPrefs |
158 |
|
preferences() { return getViewConfig().preferences(); } |
159 |
|
|
160 |
|
/** |
161 |
|
* Sets the configuration of the current view. |
162 |
|
*/ |
163 |
|
public static void |
164 |
|
setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; } |
165 |
|
|
166 |
|
/** |
167 |
* Returns the main window of this application. |
* Returns the main window of this application. |
168 |
* @return The main window of this application. |
* @return The main window of this application. |
169 |
*/ |
*/ |
232 |
handler.setLevel(Level.FINE); |
handler.setLevel(Level.FINE); |
233 |
getLogger().addHandler(handler); |
getLogger().addHandler(handler); |
234 |
getLogger().setLevel(Level.FINE); |
getLogger().setLevel(Level.FINE); |
|
Logger.getLogger("org.linuxsampler.lscp").addHandler(handler); |
|
235 |
Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE); |
Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE); |
236 |
|
Logger.getLogger("org.linuxsampler.lscp").addHandler(handler); |
237 |
|
|
238 |
// Flushing logs on every second |
// Flushing logs on every second |
239 |
new java.util.Timer().schedule(new java.util.TimerTask() { |
new java.util.Timer().schedule(new java.util.TimerTask() { |
241 |
run() { if(handler != null) handler.flush(); } |
run() { if(handler != null) handler.flush(); } |
242 |
}, 1000, 1000); |
}, 1000, 1000); |
243 |
|
|
244 |
CC.getLogger().fine("CC.jsStarted"); |
getLogger().fine("CC.jsStarted"); |
245 |
|
|
246 |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
HF.setUIDefaultFont(Prefs.getInterfaceFont()); |
247 |
|
|
|
getClient().setServerAddress(Prefs.getLSAddress()); |
|
|
getClient().setServerPort(Prefs.getLSPort()); |
|
|
|
|
248 |
timer.setRepeats(false); |
timer.setRepeats(false); |
249 |
|
|
250 |
timer.addActionListener(new ActionListener() { |
timer.addActionListener(new ActionListener() { |
274 |
getClient().removeVoiceCountListener(getHandler()); |
getClient().removeVoiceCountListener(getHandler()); |
275 |
getClient().addVoiceCountListener(getHandler()); |
getClient().addVoiceCountListener(getHandler()); |
276 |
|
|
277 |
|
getClient().removeTotalStreamCountListener(getHandler()); |
278 |
|
getClient().addTotalStreamCountListener(getHandler()); |
279 |
|
|
280 |
getClient().removeTotalVoiceCountListener(getHandler()); |
getClient().removeTotalVoiceCountListener(getHandler()); |
281 |
getClient().addTotalVoiceCountListener(getHandler()); |
getClient().addTotalVoiceCountListener(getHandler()); |
282 |
|
|
319 |
checkJSamplerHome() { |
checkJSamplerHome() { |
320 |
if(getJSamplerHome() != null) { |
if(getJSamplerHome() != null) { |
321 |
File f = new File(getJSamplerHome()); |
File f = new File(getJSamplerHome()); |
322 |
if(f.isDirectory()) return; |
if(f.exists() && f.isDirectory()) { |
323 |
|
return; |
324 |
|
} |
325 |
} |
} |
326 |
|
|
327 |
CC.getMainFrame().installJSamplerHome(); |
getMainFrame().installJSamplerHome(); |
328 |
} |
} |
329 |
|
|
330 |
/** |
/** |
337 |
public static void |
public static void |
338 |
changeJSamplerHome(String path) { |
changeJSamplerHome(String path) { |
339 |
File fNew = new File(path); |
File fNew = new File(path); |
340 |
if(fNew.isFile()) { |
if(fNew.exists() && fNew.isFile()) { |
341 |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!")); |
342 |
return; |
return; |
343 |
} |
} |
344 |
|
|
345 |
if(!fNew.isDirectory()) { |
if(!fNew.exists()) { |
346 |
if(!fNew.mkdir()) { |
if(!fNew.mkdir()) { |
347 |
String s = fNew.getAbsolutePath(); |
String s = fNew.getAbsolutePath(); |
348 |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s)); |
350 |
} |
} |
351 |
} |
} |
352 |
|
|
353 |
if(getJSamplerHome() == null) { |
if(getJSamplerHome() == null || path.equals(getJSamplerHome())) { |
354 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
355 |
return; |
return; |
356 |
} |
} |
357 |
|
|
358 |
File fOld = new File(getJSamplerHome()); |
File fOld = new File(getJSamplerHome()); |
359 |
if(!fOld.isDirectory()) { |
if(!fOld.exists() || !fOld.isDirectory()) { |
360 |
setJSamplerHome(fNew.getAbsolutePath()); |
setJSamplerHome(fNew.getAbsolutePath()); |
361 |
return; |
return; |
362 |
} |
} |
381 |
public static OrchestraListModel |
public static OrchestraListModel |
382 |
getOrchestras() { return orchestras; } |
getOrchestras() { return orchestras; } |
383 |
|
|
384 |
|
private final static ServerList servers = new ServerList(); |
385 |
|
|
386 |
|
/** Returns the server list. */ |
387 |
|
public static ServerList |
388 |
|
getServerList() { return servers; } |
389 |
|
|
390 |
|
private static ServerListListener serverListListener = new ServerListListener(); |
391 |
|
|
392 |
|
private static class ServerListListener implements ChangeListener { |
393 |
|
public void |
394 |
|
stateChanged(ChangeEvent e) { |
395 |
|
saveServerList(); |
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
|
private static final Vector<ChangeListener> idtmListeners = new Vector<ChangeListener>(); |
400 |
|
private static InstrumentsDbTreeModel instrumentsDbTreeModel = null; |
401 |
|
|
402 |
|
/** |
403 |
|
* Gets the tree model of the instruments database. |
404 |
|
* If the currently used view doesn't have instruments |
405 |
|
* database support the tree model is initialized on first use. |
406 |
|
* @return The tree model of the instruments database or |
407 |
|
* <code>null</code> if the backend doesn't have instruments database support. |
408 |
|
* @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport |
409 |
|
*/ |
410 |
|
public static InstrumentsDbTreeModel |
411 |
|
getInstrumentsDbTreeModel() { |
412 |
|
if(getSamplerModel().getServerInfo() == null) return null; |
413 |
|
if(!getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null; |
414 |
|
|
415 |
|
if(instrumentsDbTreeModel == null) { |
416 |
|
instrumentsDbTreeModel = new InstrumentsDbTreeModel(); |
417 |
|
for(ChangeListener l : idtmListeners) l.stateChanged(null); |
418 |
|
} |
419 |
|
|
420 |
|
return instrumentsDbTreeModel; |
421 |
|
} |
422 |
|
|
423 |
|
public static void |
424 |
|
addInstrumentsDbChangeListener(ChangeListener l) { |
425 |
|
idtmListeners.add(l); |
426 |
|
} |
427 |
|
|
428 |
|
public static void |
429 |
|
removeInstrumentsDbChangeListener(ChangeListener l) { |
430 |
|
idtmListeners.remove(l); |
431 |
|
} |
432 |
|
|
433 |
|
private static final LostFilesModel lostFilesModel = new LostFilesModel(); |
434 |
|
|
435 |
|
public static LostFilesModel |
436 |
|
getLostFilesModel() { return lostFilesModel; } |
437 |
|
|
438 |
/** |
/** |
439 |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
* Loads the orchestras described in <code><jsampler_home>/orchestras.xml</code>. |
440 |
* 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 |
446 |
loadOrchestras() { |
loadOrchestras() { |
447 |
if(getJSamplerHome() == null) return; |
if(getJSamplerHome() == null) return; |
448 |
|
|
|
//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; |
|
|
} |
|
|
/////// |
|
|
|
|
449 |
try { |
try { |
450 |
String s = getJSamplerHome(); |
String s = getJSamplerHome(); |
|
if(s == null) return; |
|
451 |
|
|
452 |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
File f = new File(s + File.separator + "orchestras.xml.bkp"); |
453 |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec"); |
460 |
} catch(Exception x) { |
} catch(Exception x) { |
461 |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
462 |
} |
} |
463 |
|
|
464 |
|
getOrchestras().addOrchestraListListener(getHandler()); |
465 |
} |
} |
466 |
|
|
467 |
|
|
478 |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) { |
479 |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
getOrchestras().getOrchestra(i).addOrchestraListener(getHandler()); |
480 |
} |
} |
|
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: "); } |
|
481 |
} |
} |
482 |
|
|
483 |
private static void |
private static void |
512 |
} |
} |
513 |
|
|
514 |
/** |
/** |
515 |
|
* Loads the servers' info described in <code><jsampler_home>/servers.xml</code>. |
516 |
|
* If file with name <code>servers.xml.bkp</code> exist in the JSampler's home |
517 |
|
* directory, this means that the last save has failed. In that case a recovery file |
518 |
|
* <code>servers.xml.rec</code> is created and a recovery procedure |
519 |
|
* will be initiated. |
520 |
|
*/ |
521 |
|
public static void |
522 |
|
loadServerList() { |
523 |
|
if(getJSamplerHome() == null) return; |
524 |
|
|
525 |
|
try { |
526 |
|
String s = getJSamplerHome(); |
527 |
|
|
528 |
|
File f = new File(s + File.separator + "servers.xml.bkp"); |
529 |
|
if(f.isFile()) HF.createBackup("servers.xml.bkp", "servers.xml.rec"); |
530 |
|
|
531 |
|
FileInputStream fis; |
532 |
|
fis = new FileInputStream(s + File.separator + "servers.xml"); |
533 |
|
|
534 |
|
loadServerList(fis); |
535 |
|
fis.close(); |
536 |
|
} catch(Exception x) { |
537 |
|
getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
538 |
|
} |
539 |
|
|
540 |
|
getServerList().addChangeListener(serverListListener); |
541 |
|
|
542 |
|
/* We should have at least one server to connect. */ |
543 |
|
if(getServerList().getServerCount() == 0) { |
544 |
|
Server server = new Server(); |
545 |
|
server.setName("127.0.0.1:8888"); |
546 |
|
server.setAddress("127.0.0.1"); |
547 |
|
server.setPort(8888); |
548 |
|
getServerList().addServer(server); |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
|
private static void |
554 |
|
loadServerList(InputStream in) { |
555 |
|
Document doc = DOMUtils.readObject(in); |
556 |
|
|
557 |
|
try { getServerList().readObject(doc.getDocumentElement()); } |
558 |
|
catch(Exception x) { |
559 |
|
HF.showErrorMessage(x, "Loading server list: "); |
560 |
|
return; |
561 |
|
} |
562 |
|
} |
563 |
|
|
564 |
|
private static void |
565 |
|
saveServerList() { |
566 |
|
try { |
567 |
|
String s = getJSamplerHome(); |
568 |
|
if(s == null) return; |
569 |
|
|
570 |
|
HF.createBackup("servers.xml", "servers.xml.bkp"); |
571 |
|
|
572 |
|
FileOutputStream fos; |
573 |
|
fos = new FileOutputStream(s + File.separator + "servers.xml", false); |
574 |
|
|
575 |
|
Document doc = DOMUtils.createEmptyDocument(); |
576 |
|
|
577 |
|
Node node = doc.createElement("temp"); |
578 |
|
doc.appendChild(node); |
579 |
|
|
580 |
|
getServerList().writeObject(doc, doc.getDocumentElement()); |
581 |
|
|
582 |
|
doc.replaceChild(node.getFirstChild(), node); |
583 |
|
|
584 |
|
DOMUtils.writeObject(doc, fos); |
585 |
|
|
586 |
|
fos.close(); |
587 |
|
|
588 |
|
HF.deleteFile("servers.xml.bkp"); |
589 |
|
} catch(Exception x) { |
590 |
|
HF.showErrorMessage(x, "Saving server list: "); |
591 |
|
return; |
592 |
|
} |
593 |
|
} |
594 |
|
|
595 |
|
/** |
596 |
* 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. |
597 |
* @see #cleanExit(int i) |
* @see #cleanExit(int i) |
598 |
*/ |
*/ |
605 |
*/ |
*/ |
606 |
public static void |
public static void |
607 |
cleanExit(int i) { |
cleanExit(int i) { |
608 |
CC.getLogger().fine("CC.jsEnded"); |
getLogger().fine("CC.jsEnded"); |
609 |
System.exit(i); |
System.exit(i); |
610 |
} |
} |
611 |
|
|
648 |
getSamplerModel() { return samplerModel; } |
getSamplerModel() { return samplerModel; } |
649 |
|
|
650 |
/** |
/** |
651 |
|
* Connects to LinuxSampler. |
652 |
|
*/ |
653 |
|
public static void |
654 |
|
connect() { initSamplerModel(); } |
655 |
|
|
656 |
|
/** |
657 |
* Reconnects to LinuxSampler. |
* Reconnects to LinuxSampler. |
658 |
*/ |
*/ |
659 |
public static void |
public static void |
660 |
reconnect() { |
reconnect() { initSamplerModel(getCurrentServer()); } |
661 |
initSamplerModel(); |
|
662 |
fireReconnectEvent(); |
private static Server currentServer = null; |
663 |
|
|
664 |
|
/** |
665 |
|
* Gets the server, to which the frontend is going to connect |
666 |
|
* or is already connected. |
667 |
|
*/ |
668 |
|
public static Server |
669 |
|
getCurrentServer() { return currentServer; } |
670 |
|
|
671 |
|
/** |
672 |
|
* Sets the current server. |
673 |
|
*/ |
674 |
|
public static void |
675 |
|
setCurrentServer(Server server) { currentServer = server; } |
676 |
|
|
677 |
|
/** |
678 |
|
* Sets the LSCP client's read timeout. |
679 |
|
* @param timeout The new timeout value (in seconds). |
680 |
|
*/ |
681 |
|
public static void |
682 |
|
setClientReadTimeout(int timeout) { |
683 |
|
getTaskQueue().add(new Global.SetClientReadTimeout(timeout)); |
684 |
} |
} |
685 |
|
|
686 |
/** |
/** |
687 |
* This method updates the information about the backend state. |
* This method updates the information about the backend state. |
688 |
*/ |
*/ |
689 |
public static void |
private static void |
690 |
initSamplerModel() { |
initSamplerModel() { |
691 |
|
Server srv = getMainFrame().getServer(); |
692 |
|
if(srv == null) return; |
693 |
|
initSamplerModel(srv); |
694 |
|
} |
695 |
|
|
696 |
|
/** |
697 |
|
* This method updates the information about the backend state. |
698 |
|
*/ |
699 |
|
private static void |
700 |
|
initSamplerModel(Server srv) { |
701 |
|
setCurrentServer(srv); |
702 |
|
final SetServerAddress ssa = new SetServerAddress(srv.getAddress(), srv.getPort()); |
703 |
|
|
704 |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel(); |
705 |
|
|
706 |
final GetServerInfo gsi = new GetServerInfo(); |
final Global.GetServerInfo gsi = new Global.GetServerInfo(); |
707 |
gsi.addTaskListener(new TaskListener() { |
gsi.addTaskListener(new TaskListener() { |
708 |
public void |
public void |
709 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
710 |
if(!gsi.doneWithErrors()) model.setServerInfo(gsi.getResult()); |
if(gsi.doneWithErrors()) return; |
711 |
|
|
712 |
|
model.setServerInfo(gsi.getResult()); |
713 |
|
|
714 |
|
if(CC.getViewConfig().getInstrumentsDbSupport()) { |
715 |
|
getInstrumentsDbTreeModel(); |
716 |
|
} |
717 |
} |
} |
718 |
}); |
}); |
719 |
|
|
769 |
uc.addTaskListener(new TaskListener() { |
uc.addTaskListener(new TaskListener() { |
770 |
public void |
public void |
771 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
772 |
for(SamplerChannelModel c : model.getChannelModels()) { |
for(SamplerChannelModel c : model.getChannels()) { |
773 |
if(c.getChannelInfo().getEngine() == null) continue; |
if(c.getChannelInfo().getEngine() == null) continue; |
774 |
|
|
775 |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
Channel.GetFxSends gfs = new Channel.GetFxSends(); |
777 |
gfs.addTaskListener(new GetFxSendsListener()); |
gfs.addTaskListener(new GetFxSendsListener()); |
778 |
getTaskQueue().add(gfs); |
getTaskQueue().add(gfs); |
779 |
} |
} |
780 |
|
|
781 |
|
// TODO: This should be done after the fx sends are set |
782 |
|
//CC.getSamplerModel().setModified(false); |
783 |
} |
} |
784 |
}); |
}); |
785 |
|
|
788 |
cnt.addTaskListener(new TaskListener() { |
cnt.addTaskListener(new TaskListener() { |
789 |
public void |
public void |
790 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
791 |
if(cnt.doneWithErrors()) return; |
if(cnt.doneWithErrors()) { |
792 |
|
setCurrentServer(null); |
793 |
|
retryToConnect(); |
794 |
|
return; |
795 |
|
} |
796 |
|
|
797 |
getTaskQueue().add(gsi); |
getTaskQueue().add(gsi); |
798 |
getTaskQueue().add(gaod); |
getTaskQueue().add(gaod); |
802 |
getTaskQueue().add(mgim); |
getTaskQueue().add(mgim); |
803 |
getTaskQueue().add(new Midi.UpdateDevices()); |
getTaskQueue().add(new Midi.UpdateDevices()); |
804 |
getTaskQueue().add(new Audio.UpdateDevices()); |
getTaskQueue().add(new Audio.UpdateDevices()); |
805 |
getTaskQueue().add(uc); |
addTask(uc); |
806 |
} |
} |
807 |
}); |
}); |
808 |
getTaskQueue().add(cnt); |
|
809 |
|
ssa.addTaskListener(new TaskListener() { |
810 |
|
public void |
811 |
|
taskPerformed(TaskEvent e) { |
812 |
|
int t = preferences().getIntProperty(JSPrefs.SOCKET_READ_TIMEOUT); |
813 |
|
CC.setClientReadTimeout(t * 1000); |
814 |
|
CC.getTaskQueue().add(cnt); |
815 |
|
} |
816 |
|
}); |
817 |
|
|
818 |
|
getSamplerModel().reset(); |
819 |
|
if(instrumentsDbTreeModel != null) { |
820 |
|
instrumentsDbTreeModel.reset(); |
821 |
|
instrumentsDbTreeModel = null; |
822 |
|
} |
823 |
|
|
824 |
|
getTaskQueue().removePendingTasks(); |
825 |
|
getTaskQueue().add(ssa); |
826 |
|
|
827 |
|
fireReconnectEvent(); |
828 |
|
} |
829 |
|
|
830 |
|
private static void |
831 |
|
retryToConnect() { |
832 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
833 |
|
public void |
834 |
|
run() { changeBackend(); } |
835 |
|
}); |
836 |
|
} |
837 |
|
|
838 |
|
public static void |
839 |
|
changeBackend() { |
840 |
|
Server s = getMainFrame().getServer(true); |
841 |
|
if(s != null) initSamplerModel(s); |
842 |
} |
} |
843 |
|
|
844 |
private static class GetFxSendsListener implements TaskListener { |
private static class GetFxSendsListener implements TaskListener { |
846 |
taskPerformed(TaskEvent e) { |
taskPerformed(TaskEvent e) { |
847 |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource(); |
848 |
if(gfs.doneWithErrors()) return; |
if(gfs.doneWithErrors()) return; |
849 |
SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel()); |
SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel()); |
850 |
m.removeAllFxSends(); |
m.removeAllFxSends(); |
851 |
|
|
852 |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs); |
875 |
exportInstrMapsToLscpScript(Client lscpClient) { |
exportInstrMapsToLscpScript(Client lscpClient) { |
876 |
try { |
try { |
877 |
lscpClient.removeAllMidiInstrumentMaps(); |
lscpClient.removeAllMidiInstrumentMaps(); |
878 |
MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps(); |
MidiInstrumentMap[] maps = getSamplerModel().getMidiInstrumentMaps(); |
879 |
for(int i = 0; i < maps.length; i++) { |
for(int i = 0; i < maps.length; i++) { |
880 |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
lscpClient.addMidiInstrumentMap(maps[i].getName()); |
881 |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
exportInstrumentsToLscpScript(i, maps[i], lscpClient); |
882 |
} |
} |
883 |
} catch(Exception e) { |
} catch(Exception e) { |
884 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
885 |
HF.showErrorMessage(e); |
HF.showErrorMessage(e); |
886 |
} |
} |
887 |
} |
} |
890 |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient) |
891 |
throws Exception { |
throws Exception { |
892 |
|
|
893 |
|
boolean b = preferences().getBoolProperty(JSPrefs.LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND); |
894 |
|
|
895 |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
for(MidiInstrument i : map.getAllMidiInstruments()) { |
896 |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo()); |
lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo(), b); |
897 |
} |
} |
898 |
} |
} |
899 |
|
|
900 |
public static String |
public static String |
901 |
exportSessionToLscpScript() { |
exportSessionToLscpScript() { |
902 |
|
getSamplerModel().setModified(false); |
903 |
|
|
904 |
StringBuffer sb = new StringBuffer("# Exported by: "); |
StringBuffer sb = new StringBuffer("# Exported by: "); |
905 |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: "); |
906 |
sb.append(JSampler.VERSION).append("\r\n"); |
sb.append(JSampler.VERSION).append("\r\n"); |
915 |
sb.append(out.toString()); |
sb.append(out.toString()); |
916 |
out.reset(); |
out.reset(); |
917 |
sb.append("\r\n"); |
sb.append("\r\n"); |
918 |
lscpClient.setVolume(CC.getSamplerModel().getVolume()); |
lscpClient.setVolume(getSamplerModel().getVolume()); |
919 |
sb.append(out.toString()); |
sb.append(out.toString()); |
920 |
out.reset(); |
out.reset(); |
921 |
sb.append("\r\n"); |
sb.append("\r\n"); |
922 |
} catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
} catch(Exception e) { getLogger().log(Level.FINE, HF.getErrorMessage(e), e); } |
923 |
|
|
924 |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels(); |
MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices(); |
925 |
for(int i = 0; i < mDevs.length; i++) { |
for(int i = 0; i < mDevs.length; i++) { |
926 |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient); |
927 |
sb.append(out.toString()); |
sb.append(out.toString()); |
929 |
sb.append("\r\n"); |
sb.append("\r\n"); |
930 |
} |
} |
931 |
|
|
932 |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels(); |
AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices(); |
933 |
for(int i = 0; i < aDevs.length; i++) { |
for(int i = 0; i < aDevs.length; i++) { |
934 |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient); |
935 |
sb.append(out.toString()); |
sb.append(out.toString()); |
937 |
sb.append("\r\n"); |
sb.append("\r\n"); |
938 |
} |
} |
939 |
|
|
940 |
SamplerChannelModel[] channels = getSamplerModel().getChannelModels(); |
boolean b = preferences().getBoolProperty(JSPrefs.EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT); |
941 |
|
if(b) { |
942 |
|
exportInstrMapsToLscpScript(lscpClient); |
943 |
|
sb.append(out.toString()); |
944 |
|
out.reset(); |
945 |
|
sb.append("\r\n"); |
946 |
|
} |
947 |
|
|
948 |
|
SamplerChannelModel[] channels = getSamplerModel().getChannels(); |
949 |
|
|
950 |
for(int i = 0; i < channels.length; i++) { |
for(int i = 0; i < channels.length; i++) { |
951 |
SamplerChannelModel scm = getSamplerModel().getChannelModel(i); |
SamplerChannelModel scm = channels[i]; |
952 |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient); |
953 |
sb.append(out.toString()); |
sb.append(out.toString()); |
954 |
out.reset(); |
out.reset(); |
962 |
sb.append("\r\n"); |
sb.append("\r\n"); |
963 |
} |
} |
964 |
|
|
965 |
exportInstrMapsToLscpScript(lscpClient); |
//sb.append(getViewConfig().exportSessionViewConfig()); |
|
sb.append(out.toString()); |
|
|
out.reset(); |
|
966 |
|
|
967 |
return sb.toString(); |
return sb.toString(); |
968 |
} |
} |
985 |
} |
} |
986 |
} |
} |
987 |
} catch(Exception e) { |
} catch(Exception e) { |
988 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
989 |
} |
} |
990 |
} |
} |
991 |
|
|
1005 |
} |
} |
1006 |
} |
} |
1007 |
} catch(Exception e) { |
} catch(Exception e) { |
1008 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1009 |
} |
} |
1010 |
} |
} |
1011 |
|
|
1014 |
try { |
try { |
1015 |
lscpCLient.addSamplerChannel(); |
lscpCLient.addSamplerChannel(); |
1016 |
|
|
1017 |
int i = chn.getMidiInputDevice(); |
SamplerModel sm = getSamplerModel(); |
1018 |
if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i); |
int id = chn.getMidiInputDevice(); |
1019 |
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
if(id != -1) { |
1020 |
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
for(int i = 0; i < sm.getMidiDeviceCount(); i++) { |
1021 |
|
if(sm.getMidiDevice(i).getDeviceId() == id) { |
1022 |
i = chn.getAudioOutputDevice(); |
lscpCLient.setChannelMidiInputDevice(chnId, i); |
1023 |
if(i != -1) { |
break; |
1024 |
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
} |
1025 |
|
} |
1026 |
|
lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort()); |
1027 |
|
lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel()); |
1028 |
|
} |
1029 |
|
|
1030 |
|
if(chn.getEngine() != null) { |
1031 |
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
1032 |
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
1033 |
|
int mapId = chn.getMidiInstrumentMapId(); |
1034 |
|
lscpCLient.setChannelMidiInstrumentMap(chnId, mapId); |
1035 |
|
} |
1036 |
|
|
1037 |
|
id = chn.getAudioOutputDevice(); |
1038 |
|
if(id != -1) { |
1039 |
|
for(int i = 0; i < sm.getAudioDeviceCount(); i++) { |
1040 |
|
if(sm.getAudioDevice(i).getDeviceId() == id) { |
1041 |
|
lscpCLient.setChannelAudioOutputDevice(chnId, i); |
1042 |
|
break; |
1043 |
|
} |
1044 |
|
} |
1045 |
|
|
1046 |
Integer[] routing = chn.getAudioOutputRouting(); |
Integer[] routing = chn.getAudioOutputRouting(); |
1047 |
|
|
1048 |
for(int j = 0; j < routing.length; j++) { |
for(int j = 0; j < routing.length; j++) { |
1053 |
} |
} |
1054 |
} |
} |
1055 |
|
|
|
if(chn.getEngine() != null) { |
|
|
lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId); |
|
|
lscpCLient.setChannelVolume(chnId, chn.getVolume()); |
|
|
} |
|
|
|
|
1056 |
String s = chn.getInstrumentFile(); |
String s = chn.getInstrumentFile(); |
1057 |
i = chn.getInstrumentIndex(); |
int i = chn.getInstrumentIndex(); |
1058 |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
if(s != null) lscpCLient.loadInstrument(s, i, chnId, true); |
1059 |
|
|
1060 |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true); |
1061 |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true); |
1062 |
} catch(Exception e) { |
} catch(Exception e) { |
1063 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1064 |
} |
} |
1065 |
} |
} |
1066 |
|
|
1079 |
} |
} |
1080 |
} |
} |
1081 |
} catch(Exception e) { |
} catch(Exception e) { |
1082 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
1083 |
|
} |
1084 |
|
} |
1085 |
|
|
1086 |
|
public static void |
1087 |
|
scheduleInTaskQueue(final Runnable r) { |
1088 |
|
Task dummy = new Global.DummyTask(); |
1089 |
|
dummy.addTaskListener(new TaskListener() { |
1090 |
|
public void |
1091 |
|
taskPerformed(TaskEvent e) { |
1092 |
|
javax.swing.SwingUtilities.invokeLater(r); |
1093 |
|
} |
1094 |
|
}); |
1095 |
|
|
1096 |
|
getTaskQueue().add(dummy); |
1097 |
|
} |
1098 |
|
|
1099 |
|
public static boolean |
1100 |
|
verifyConnection() { |
1101 |
|
if(getCurrentServer() == null) { |
1102 |
|
HF.showErrorMessage(i18n.getError("CC.notConnected")); |
1103 |
|
return false; |
1104 |
} |
} |
1105 |
|
|
1106 |
|
return true; |
1107 |
} |
} |
1108 |
|
|
1109 |
|
|
1114 |
|
|
1115 |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
private static class EventHandler implements ChannelCountListener, ChannelInfoListener, |
1116 |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener, |
1117 |
TotalVoiceCountListener, TaskQueueListener, OrchestraListener, |
TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener, |
1118 |
ListListener<OrchestraModel>, MidiInstrumentCountListener, |
OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener, |
1119 |
MidiInstrumentInfoListener, GlobalInfoListener { |
MidiInstrumentInfoListener, GlobalInfoListener { |
1120 |
|
|
1121 |
/** Invoked when the number of channels has changed. */ |
/** Invoked when the number of channels has changed. */ |
1122 |
public void |
public void |
1123 |
channelCountChanged( ChannelCountEvent e) { |
channelCountChanged( ChannelCountEvent e) { |
1124 |
getTaskQueue().add(new UpdateChannels()); |
addTask(new UpdateChannels()); |
1125 |
} |
} |
1126 |
|
|
1127 |
/** Invoked when changes to the sampler channel has occured. */ |
/** Invoked when changes to the sampler channel has occured. */ |
1183 |
public void |
public void |
1184 |
streamCountChanged(StreamCountEvent e) { |
streamCountChanged(StreamCountEvent e) { |
1185 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
1186 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
1187 |
|
|
1188 |
if(scm == null) { |
if(scm == null) { |
1189 |
CC.getLogger().log ( |
CC.getLogger().log ( |
1205 |
public void |
public void |
1206 |
voiceCountChanged(VoiceCountEvent e) { |
voiceCountChanged(VoiceCountEvent e) { |
1207 |
SamplerChannelModel scm = |
SamplerChannelModel scm = |
1208 |
getSamplerModel().getChannelModel(e.getSamplerChannel()); |
getSamplerModel().getChannelById(e.getSamplerChannel()); |
1209 |
|
|
1210 |
if(scm == null) { |
if(scm == null) { |
1211 |
CC.getLogger().log ( |
CC.getLogger().log ( |
1220 |
scm.setVoiceCount(e.getVoiceCount()); |
scm.setVoiceCount(e.getVoiceCount()); |
1221 |
} |
} |
1222 |
|
|
1223 |
|
/** Invoked when the total number of active streams has changed. */ |
1224 |
|
public void |
1225 |
|
totalStreamCountChanged(TotalStreamCountEvent e) { |
1226 |
|
getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount()); |
1227 |
|
} |
1228 |
|
|
1229 |
/** Invoked when the total number of active voices has changed. */ |
/** Invoked when the total number of active voices has changed. */ |
1230 |
public void |
public void |
1231 |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
totalVoiceCountChanged(TotalVoiceCountEvent e) { |
1235 |
/** 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. */ |
1236 |
public void |
public void |
1237 |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
instrumentCountChanged(MidiInstrumentCountEvent e) { |
1238 |
getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId())); |
scheduleTask(new Midi.UpdateInstruments(e.getMapId())); |
1239 |
} |
} |
1240 |
|
|
1241 |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
/** Invoked when a MIDI instrument in a MIDI instrument map is changed. */ |
1268 |
break; |
break; |
1269 |
case TASK_DONE: |
case TASK_DONE: |
1270 |
EnhancedTask t = (EnhancedTask)e.getSource(); |
EnhancedTask t = (EnhancedTask)e.getSource(); |
1271 |
if(t.doneWithErrors() && !t.isStopped()) |
if(t.doneWithErrors() && !t.isStopped()) { |
1272 |
HF.showErrorMessage(t.getErrorMessage()); |
showError(t); |
1273 |
|
} |
1274 |
break; |
break; |
1275 |
case NOT_IDLE: |
case NOT_IDLE: |
1276 |
timer.start(); |
timer.start(); |
1282 |
} |
} |
1283 |
} |
} |
1284 |
|
|
1285 |
|
private void |
1286 |
|
showError(final Task t) { |
1287 |
|
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
1288 |
|
public void |
1289 |
|
run() { |
1290 |
|
if(t.getErrorDetails() == null) { |
1291 |
|
HF.showErrorMessage(t.getErrorMessage()); |
1292 |
|
} else { |
1293 |
|
getMainFrame().showDetailedErrorMessage ( |
1294 |
|
getMainFrame(), |
1295 |
|
t.getErrorMessage(), |
1296 |
|
t.getErrorDetails() |
1297 |
|
); |
1298 |
|
} |
1299 |
|
} |
1300 |
|
}); |
1301 |
|
} |
1302 |
|
|
1303 |
/** Invoked when the name of orchestra is changed. */ |
/** Invoked when the name of orchestra is changed. */ |
1304 |
public void |
public void |
1305 |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |
nameChanged(OrchestraEvent e) { saveOrchestras(); } |