/[svn]/jsampler/trunk/src/org/jsampler/CC.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/CC.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1708 - (hide annotations) (download)
Wed Feb 20 15:20:34 2008 UTC (16 years, 2 months ago) by iliev
File size: 39474 byte(s)
* fixed bug #84

1 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1143 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 787 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler;
24    
25     import java.awt.event.ActionEvent;
26     import java.awt.event.ActionListener;
27    
28 iliev 911 import java.io.ByteArrayInputStream;
29     import java.io.ByteArrayOutputStream;
30 iliev 1143 import java.io.File;
31     import java.io.FileInputStream;
32 iliev 787 import java.io.FileOutputStream;
33 iliev 1143 import java.io.InputStream;
34 iliev 787
35 iliev 911 import java.util.Vector;
36    
37 iliev 787 import java.util.logging.Handler;
38     import java.util.logging.Level;
39     import java.util.logging.Logger;
40     import java.util.logging.SimpleFormatter;
41     import java.util.logging.StreamHandler;
42    
43     import javax.swing.Timer;
44    
45 iliev 1688 import javax.swing.event.ChangeEvent;
46     import javax.swing.event.ChangeListener;
47    
48 iliev 911 import net.sf.juife.Task;
49     import net.sf.juife.TaskQueue;
50    
51     import net.sf.juife.event.TaskEvent;
52     import net.sf.juife.event.TaskListener;
53     import net.sf.juife.event.TaskQueueEvent;
54     import net.sf.juife.event.TaskQueueListener;
55    
56 iliev 1143 import org.jsampler.event.ListEvent;
57     import org.jsampler.event.ListListener;
58 iliev 911 import org.jsampler.event.OrchestraEvent;
59     import org.jsampler.event.OrchestraListener;
60    
61 iliev 787 import org.jsampler.task.*;
62    
63     import org.jsampler.view.JSMainFrame;
64     import org.jsampler.view.JSProgress;
65 iliev 1285 import org.jsampler.view.JSViewConfig;
66 iliev 1204 import org.jsampler.view.InstrumentsDbTreeModel;
67 iliev 787
68 iliev 1143 import org.linuxsampler.lscp.AudioOutputChannel;
69     import org.linuxsampler.lscp.AudioOutputDevice;
70 iliev 787 import org.linuxsampler.lscp.Client;
71 iliev 1143 import org.linuxsampler.lscp.FxSend;
72     import org.linuxsampler.lscp.MidiInputDevice;
73     import org.linuxsampler.lscp.MidiPort;
74     import org.linuxsampler.lscp.Parameter;
75     import org.linuxsampler.lscp.SamplerChannel;
76    
77 iliev 787 import org.linuxsampler.lscp.event.*;
78    
79 iliev 911 import org.w3c.dom.Document;
80     import org.w3c.dom.Node;
81 iliev 787
82 iliev 1143 import static org.jsampler.JSI18n.i18n;
83 iliev 1688 import static org.jsampler.JSPrefs.MANUAL_SERVER_SELECT_ON_STARTUP;
84 iliev 787
85 iliev 1143
86 iliev 787 /**
87 iliev 911 * This class serves as a 'Control Center' of the application.
88     * It also provides some fundamental routines and access to most used objects.
89 iliev 787 * @author Grigor Iliev
90     */
91     public class CC {
92     private static Handler handler;
93 iliev 911 private static FileOutputStream fos;
94 iliev 787
95 iliev 1285 private static JSViewConfig viewConfig = null;
96 iliev 787 private static JSMainFrame mainFrame = null;
97     private static JSProgress progress = null;
98    
99     private final static Client lsClient = new Client();
100    
101 iliev 1143 private static String jSamplerHome = null;
102    
103 iliev 787 private final static TaskQueue taskQueue = new TaskQueue();
104 iliev 911 private final static Timer timer = new Timer(2000, null);
105 iliev 787
106 iliev 1143 /** Forbits the instantiation of this class. */
107     private
108     CC() { }
109 iliev 787
110 iliev 911 /**
111     * Returns the logger to be used for logging events.
112     * @return The logger to be used for logging events.
113     */
114 iliev 787 public static Logger
115     getLogger() {
116     return Logger.getLogger (
117     "org.jsampler",
118     "org.jsampler.langprops.LogsBundle"
119     );
120     }
121    
122 iliev 911 /**
123     * Returns the task queue to be used for scheduling tasks
124     * for execution out of the event-dispatching thread.
125     * @return The task queue to be used for scheduling tasks
126     * for execution out of the event-dispatching thread.
127     */
128 iliev 787 public static TaskQueue
129     getTaskQueue() { return taskQueue; }
130    
131 iliev 911 /**
132 iliev 1204 * 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 iliev 1285 * Gets the configuration of the current view.
148     */
149     public static JSViewConfig
150     getViewConfig() { return viewConfig; }
151    
152 iliev 1688 private static JSPrefs
153     preferences() { return getViewConfig().preferences(); }
154    
155 iliev 1285 /**
156     * Sets the configuration of the current view.
157     */
158     public static void
159     setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; }
160    
161     /**
162 iliev 911 * Returns the main window of this application.
163     * @return The main window of this application.
164     */
165 iliev 787 public static JSMainFrame
166     getMainFrame() { return mainFrame; }
167    
168 iliev 911 /**
169     * Sets the main window of this application.
170     * @param mainFrame The main window of this application.
171     */
172 iliev 787 public static void
173     setMainFrame(JSMainFrame mainFrame) { CC.mainFrame = mainFrame; }
174    
175 iliev 911 /**
176     * Gets the progress indicator of this application.
177     * @return The progress indicator of this application.
178     */
179 iliev 787 public static JSProgress
180     getProgressIndicator() { return progress; }
181    
182 iliev 911 /**
183     * Sets the progress indicator to be used by this application.
184     * @param progress The progress indicator to be used by this application.
185     */
186 iliev 787 public static void
187     setProgressIndicator(JSProgress progress) { CC.progress = progress; }
188    
189 iliev 911 /**
190 iliev 1143 * Gets the absolute path to the JSampler's home location.
191     * @return The absolute path to the JSampler's home location
192     * or <code>null</code> if the JSampler's home location is not specified yet.
193     */
194     public static String
195     getJSamplerHome() { return jSamplerHome; }
196    
197     /**
198     * Sets the location of the JSampler's home.
199     * @param path The new absolute path to the JSampler's home location.
200     */
201     public static void
202     setJSamplerHome(String path) {
203     jSamplerHome = path;
204     Prefs.setJSamplerHome(jSamplerHome);
205     }
206    
207     /**
208 iliev 911 * This method does the initial preparation of the application.
209     */
210 iliev 787 protected static void
211     initJSampler() {
212     fos = null;
213 iliev 1143 setJSamplerHome(Prefs.getJSamplerHome());
214     String s = getJSamplerHome();
215     try {
216     if(s != null) {
217     s += File.separator + "jsampler.log";
218     File f = new File(s);
219     if(f.isFile()) HF.createBackup("jsampler.log", "jsampler.log.0");
220     fos = new FileOutputStream(s);
221     }
222     } catch(Exception x) { x.printStackTrace(); }
223 iliev 787
224     if(fos == null) handler = new StreamHandler(System.out, new SimpleFormatter());
225     else handler = new StreamHandler(fos, new SimpleFormatter());
226    
227     handler.setLevel(Level.FINE);
228     getLogger().addHandler(handler);
229     getLogger().setLevel(Level.FINE);
230 iliev 1204 Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE);
231 iliev 787 Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
232    
233     // Flushing logs on every second
234     new java.util.Timer().schedule(new java.util.TimerTask() {
235     public void
236     run() { if(handler != null) handler.flush(); }
237     }, 1000, 1000);
238    
239     CC.getLogger().fine("CC.jsStarted");
240    
241     HF.setUIDefaultFont(Prefs.getInterfaceFont());
242    
243     timer.setRepeats(false);
244    
245     timer.addActionListener(new ActionListener() {
246     public void
247     actionPerformed(ActionEvent e) { CC.getProgressIndicator().start(); }
248     });
249    
250 iliev 911 taskQueue.addTaskQueueListener(getHandler());
251 iliev 787
252     taskQueue.start();
253    
254 iliev 1143 getClient().removeChannelCountListener(getHandler());
255 iliev 911 getClient().addChannelCountListener(getHandler());
256 iliev 1143
257     getClient().removeChannelInfoListener(getHandler());
258 iliev 911 getClient().addChannelInfoListener(getHandler());
259 iliev 1143
260     getClient().removeFxSendCountListener(getHandler());
261     getClient().addFxSendCountListener(getHandler());
262    
263     getClient().removeFxSendInfoListener(getHandler());
264     getClient().addFxSendInfoListener(getHandler());
265    
266     getClient().removeStreamCountListener(getHandler());
267 iliev 911 getClient().addStreamCountListener(getHandler());
268 iliev 1143
269     getClient().removeVoiceCountListener(getHandler());
270 iliev 911 getClient().addVoiceCountListener(getHandler());
271 iliev 1143
272 iliev 1545 getClient().removeTotalStreamCountListener(getHandler());
273     getClient().addTotalStreamCountListener(getHandler());
274    
275 iliev 1143 getClient().removeTotalVoiceCountListener(getHandler());
276 iliev 911 getClient().addTotalVoiceCountListener(getHandler());
277    
278 iliev 1143 getClient().removeAudioDeviceCountListener(audioDeviceCountListener);
279     getClient().addAudioDeviceCountListener(audioDeviceCountListener);
280 iliev 911
281 iliev 1143 getClient().removeAudioDeviceInfoListener(audioDeviceInfoListener);
282     getClient().addAudioDeviceInfoListener(audioDeviceInfoListener);
283    
284     getClient().removeMidiDeviceCountListener(midiDeviceCountListener);
285     getClient().addMidiDeviceCountListener(midiDeviceCountListener);
286    
287     getClient().removeMidiDeviceInfoListener(midiDeviceInfoListener);
288     getClient().addMidiDeviceInfoListener(midiDeviceInfoListener);
289    
290     getClient().removeMidiInstrumentMapCountListener(midiInstrMapCountListener);
291     getClient().addMidiInstrumentMapCountListener(midiInstrMapCountListener);
292    
293     getClient().removeMidiInstrumentMapInfoListener(midiInstrMapInfoListener);
294     getClient().addMidiInstrumentMapInfoListener(midiInstrMapInfoListener);
295    
296     getClient().removeMidiInstrumentCountListener(getHandler());
297     getClient().addMidiInstrumentCountListener(getHandler());
298    
299     getClient().removeMidiInstrumentInfoListener(getHandler());
300     getClient().addMidiInstrumentInfoListener(getHandler());
301    
302     getClient().removeGlobalInfoListener(getHandler());
303     getClient().addGlobalInfoListener(getHandler());
304     }
305    
306     /**
307     * Checks whether the JSampler home directory is specified and exist.
308     * If the JSampler home directory is not specifed, or is specified
309     * but doesn't exist, a procedure of specifying a JSampler home
310     * directory is initiated.
311     * @see org.jsampler.view.JSMainFrame#installJSamplerHome
312     */
313     public static void
314     checkJSamplerHome() {
315     if(getJSamplerHome() != null) {
316     File f = new File(getJSamplerHome());
317 iliev 1285 if(f.exists() && f.isDirectory()) {
318     return;
319     }
320 iliev 911 }
321 iliev 1143
322     CC.getMainFrame().installJSamplerHome();
323 iliev 787 }
324    
325 iliev 1143 /**
326     * Changes the JSampler's home directory and moves all files from
327     * the old JSampler's home directory to the new one. If all files are
328     * moved succesfully, the old directory is deleted.
329     * @param path The location of the new JSampler's home directory. If
330     * the last directory in the path doesn't exist, it is created.
331     */
332     public static void
333     changeJSamplerHome(String path) {
334     File fNew = new File(path);
335 iliev 1285 if(fNew.exists() && fNew.isFile()) {
336 iliev 1143 HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!"));
337     return;
338     }
339    
340 iliev 1285 if(!fNew.exists()) {
341 iliev 1143 if(!fNew.mkdir()) {
342     String s = fNew.getAbsolutePath();
343     HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s));
344     return;
345     }
346     }
347    
348 iliev 1285 if(getJSamplerHome() == null || path.equals(getJSamplerHome())) {
349 iliev 1143 setJSamplerHome(fNew.getAbsolutePath());
350     return;
351     }
352    
353     File fOld = new File(getJSamplerHome());
354 iliev 1285 if(!fOld.exists() || !fOld.isDirectory()) {
355 iliev 1143 setJSamplerHome(fNew.getAbsolutePath());
356     return;
357     }
358    
359     File[] files = fOld.listFiles();
360     boolean b = true;
361     if(files != null) {
362     String s = fNew.getAbsolutePath() + File.separator;
363     for(File f : files) if(!f.renameTo(new File(s + f.getName()))) b = false;
364     }
365    
366     if(b) fOld.delete();
367     setJSamplerHome(fNew.getAbsolutePath());
368     }
369    
370 iliev 911 private final static OrchestraListModel orchestras = new DefaultOrchestraListModel();
371    
372     /**
373     * Returns a list containing all available orchestras.
374     * @return A list containing all available orchestras.
375     */
376     public static OrchestraListModel
377     getOrchestras() { return orchestras; }
378    
379 iliev 1688 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 iliev 1204 private static InstrumentsDbTreeModel instrumentsDbTreeModel = null;
396 iliev 1688
397 iliev 1143 /**
398 iliev 1204 * 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 iliev 1327 * @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport
404 iliev 1204 */
405     public static InstrumentsDbTreeModel
406     getInstrumentsDbTreeModel() {
407     if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null;
408    
409     if(instrumentsDbTreeModel == null) {
410     instrumentsDbTreeModel = new InstrumentsDbTreeModel();
411 iliev 1688 for(ChangeListener l : idtmListeners) l.stateChanged(null);
412 iliev 1204 }
413    
414     return instrumentsDbTreeModel;
415     }
416    
417 iliev 1688 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 iliev 1204 /**
428 iliev 1143 * Loads the orchestras described in <code>&lt;jsampler_home&gt;/orchestras.xml</code>.
429     * If file with name <code>orchestras.xml.bkp</code> exist in the JSampler's home
430     * directory, this means that the last save has failed. In that case a recovery file
431     * <code>orchestras.xml.rec</code> is created and a recovery procedure
432     * will be initiated.
433     */
434     public static void
435     loadOrchestras() {
436     if(getJSamplerHome() == null) return;
437    
438     try {
439     String s = getJSamplerHome();
440    
441     File f = new File(s + File.separator + "orchestras.xml.bkp");
442     if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec");
443    
444     FileInputStream fis;
445     fis = new FileInputStream(s + File.separator + "orchestras.xml");
446    
447     loadOrchestras(fis);
448     fis.close();
449     } catch(Exception x) {
450     getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
451     }
452 iliev 1688
453     getOrchestras().addOrchestraListListener(getHandler());
454 iliev 1143 }
455    
456    
457 iliev 911 private static void
458 iliev 1143 loadOrchestras(InputStream in) {
459     Document doc = DOMUtils.readObject(in);
460    
461     try { getOrchestras().readObject(doc.getDocumentElement()); }
462     catch(Exception x) {
463     HF.showErrorMessage(x, "Loading orchestras: ");
464     return;
465     }
466    
467     for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {
468     getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());
469     }
470     }
471    
472     private static void
473 iliev 911 saveOrchestras() {
474 iliev 1143 try {
475     String s = getJSamplerHome();
476     if(s == null) return;
477    
478     HF.createBackup("orchestras.xml", "orchestras.xml.bkp");
479    
480     FileOutputStream fos;
481     fos = new FileOutputStream(s + File.separator + "orchestras.xml", false);
482    
483     Document doc = DOMUtils.createEmptyDocument();
484 iliev 911
485 iliev 1143 Node node = doc.createElement("temp");
486     doc.appendChild(node);
487    
488     getOrchestras().writeObject(doc, doc.getDocumentElement());
489    
490     doc.replaceChild(node.getFirstChild(), node);
491 iliev 911
492 iliev 1143 DOMUtils.writeObject(doc, fos);
493    
494     fos.close();
495    
496     HF.deleteFile("orchestras.xml.bkp");
497     } catch(Exception x) {
498     HF.showErrorMessage(x, "Saving orchestras: ");
499     return;
500     }
501 iliev 911 }
502    
503     /**
504 iliev 1688 * Loads the servers' info described in <code>&lt;jsampler_home&gt;/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 iliev 911 * The exit point of the application which ensures clean exit with default exit status 0.
586     * @see #cleanExit(int i)
587     */
588 iliev 787 public static void
589     cleanExit() { cleanExit(0); }
590    
591 iliev 911 /**
592     * The exit point of the application which ensures clean exit.
593     * @param i The exit status.
594     */
595 iliev 787 public static void
596     cleanExit(int i) {
597     CC.getLogger().fine("CC.jsEnded");
598     System.exit(i);
599     }
600    
601 iliev 911 /**
602     * Gets the <code>Client</code> object that is used to communicate with the backend.
603     * @return The <code>Client</code> object that is used to communicate with the backend.
604     */
605 iliev 787 public static Client
606     getClient() { return lsClient; }
607    
608 iliev 911 private static final Vector<ActionListener> listeners = new Vector<ActionListener>();
609 iliev 787
610 iliev 911 /**
611     * Registers the specified listener to be notified when reconnecting to LinuxSampler.
612     * @param l The <code>ActionListener</code> to register.
613     */
614     public static void
615     addReconnectListener(ActionListener l) { listeners.add(l); }
616    
617     /**
618     * Removes the specified listener.
619     * @param l The <code>ActionListener</code> to remove.
620     */
621     public static void
622     removeReconnectListener(ActionListener l) { listeners.remove(l); }
623    
624     private static void
625     fireReconnectEvent() {
626     ActionEvent e = new ActionEvent(CC.class, ActionEvent.ACTION_PERFORMED, null);
627     for(ActionListener l : listeners) l.actionPerformed(e);
628     }
629    
630 iliev 787 private static final SamplerModel samplerModel = new DefaultSamplerModel();
631    
632     /**
633     * Gets the sampler model.
634     * @return The sampler model.
635     */
636     public static SamplerModel
637     getSamplerModel() { return samplerModel; }
638    
639 iliev 911 /**
640 iliev 1688 * Connects to LinuxSampler.
641     */
642     public static void
643     connect() { initSamplerModel(); }
644    
645     /**
646 iliev 911 * Reconnects to LinuxSampler.
647     */
648 iliev 787 public static void
649 iliev 1688 reconnect() { initSamplerModel(getCurrentServer()); }
650    
651     private static Server currentServer = null;
652    
653     /**
654     * 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
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() {
671     Server srv = getMainFrame().getServer();
672     if(srv == null) return;
673     initSamplerModel(srv);
674 iliev 911 }
675    
676     /**
677     * This method updates the information about the backend state.
678     */
679 iliev 1688 private static void
680     initSamplerModel(Server srv) {
681     setCurrentServer(srv);
682     final SetServerAddress ssa = new SetServerAddress(srv.getAddress(), srv.getPort());
683    
684 iliev 787 final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel();
685    
686 iliev 1204 final Global.GetServerInfo gsi = new Global.GetServerInfo();
687 iliev 787 gsi.addTaskListener(new TaskListener() {
688     public void
689     taskPerformed(TaskEvent e) {
690 iliev 1204 if(gsi.doneWithErrors()) return;
691    
692     model.setServerInfo(gsi.getResult());
693    
694 iliev 1285 if(CC.getViewConfig().getInstrumentsDbSupport()) {
695 iliev 1204 getInstrumentsDbTreeModel();
696     }
697 iliev 787 }
698     });
699    
700 iliev 1143 final Audio.GetDrivers gaod = new Audio.GetDrivers();
701 iliev 787 gaod.addTaskListener(new TaskListener() {
702     public void
703     taskPerformed(TaskEvent e) {
704     if(!gaod.doneWithErrors())
705     model.setAudioOutputDrivers(gaod.getResult());
706     }
707     });
708    
709     final GetEngines ge = new GetEngines();
710     ge.addTaskListener(new TaskListener() {
711     public void
712     taskPerformed(TaskEvent e) {
713     if(!ge.doneWithErrors()) model.setEngines(ge.getResult());
714     }
715     });
716    
717 iliev 1143 final Midi.GetDrivers gmid = new Midi.GetDrivers();
718 iliev 787 gmid.addTaskListener(new TaskListener() {
719     public void
720     taskPerformed(TaskEvent e) {
721     if(!gmid.doneWithErrors())
722     model.setMidiInputDrivers(gmid.getResult());
723     }
724     });
725    
726 iliev 1143 final Global.GetVolume gv = new Global.GetVolume();
727     gv.addTaskListener(new TaskListener() {
728     public void
729     taskPerformed(TaskEvent e) {
730     if(!gv.doneWithErrors())
731     model.setVolume(gv.getResult());
732     }
733     });
734    
735     final Midi.GetInstrumentMaps mgim = new Midi.GetInstrumentMaps();
736     mgim.addTaskListener(new TaskListener() {
737     public void
738     taskPerformed(TaskEvent e) {
739     if(mgim.doneWithErrors()) return;
740     model.removeAllMidiInstrumentMaps();
741    
742     for(MidiInstrumentMap map : mgim.getResult()) {
743     model.addMidiInstrumentMap(map);
744     }
745     }
746     });
747    
748     final UpdateChannels uc = new UpdateChannels();
749     uc.addTaskListener(new TaskListener() {
750     public void
751     taskPerformed(TaskEvent e) {
752 iliev 1204 for(SamplerChannelModel c : model.getChannels()) {
753 iliev 1143 if(c.getChannelInfo().getEngine() == null) continue;
754    
755     Channel.GetFxSends gfs = new Channel.GetFxSends();
756     gfs.setChannel(c.getChannelId());
757     gfs.addTaskListener(new GetFxSendsListener());
758     getTaskQueue().add(gfs);
759     }
760 iliev 1567
761     // TODO: This should be done after the fx sends are set
762     //CC.getSamplerModel().setModified(false);
763 iliev 1143 }
764     });
765    
766    
767 iliev 787 final Connect cnt = new Connect();
768     cnt.addTaskListener(new TaskListener() {
769     public void
770     taskPerformed(TaskEvent e) {
771 iliev 1688 if(cnt.doneWithErrors()) {
772     setCurrentServer(null);
773     retryToConnect();
774     return;
775     }
776 iliev 787
777     getTaskQueue().add(gsi);
778     getTaskQueue().add(gaod);
779     getTaskQueue().add(gmid);
780     getTaskQueue().add(ge);
781 iliev 1143 getTaskQueue().add(gv);
782     getTaskQueue().add(mgim);
783     getTaskQueue().add(new Midi.UpdateDevices());
784     getTaskQueue().add(new Audio.UpdateDevices());
785     getTaskQueue().add(uc);
786 iliev 787 }
787     });
788 iliev 1688
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 iliev 787 }
807    
808 iliev 1688 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 iliev 1143 private static class GetFxSendsListener implements TaskListener {
823     public void
824     taskPerformed(TaskEvent e) {
825     Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();
826     if(gfs.doneWithErrors()) return;
827 iliev 1204 SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel());
828 iliev 1143 m.removeAllFxSends();
829    
830     for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);
831     }
832     }
833    
834     public static String
835     exportInstrMapsToLscpScript() {
836     StringBuffer sb = new StringBuffer("# Exported by: ");
837     sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
838     sb.append(JSampler.VERSION).append("\r\n");
839     sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n");
840    
841     Client lscpClient = new Client(true);
842     ByteArrayOutputStream out = new ByteArrayOutputStream();
843     lscpClient.setPrintOnlyModeOutputStream(out);
844    
845     exportInstrMapsToLscpScript(lscpClient);
846     sb.append(out.toString());
847     out.reset();
848    
849     return sb.toString();
850     }
851    
852     private static void
853     exportInstrMapsToLscpScript(Client lscpClient) {
854     try {
855     lscpClient.removeAllMidiInstrumentMaps();
856     MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps();
857     for(int i = 0; i < maps.length; i++) {
858     lscpClient.addMidiInstrumentMap(maps[i].getName());
859     exportInstrumentsToLscpScript(i, maps[i], lscpClient);
860     }
861     } catch(Exception e) {
862     CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
863     HF.showErrorMessage(e);
864     }
865     }
866    
867     private static void
868     exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient)
869     throws Exception {
870    
871     for(MidiInstrument i : map.getAllMidiInstruments()) {
872     lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo());
873     }
874     }
875    
876     public static String
877     exportSessionToLscpScript() {
878 iliev 1567 CC.getSamplerModel().setModified(false);
879    
880 iliev 1143 StringBuffer sb = new StringBuffer("# Exported by: ");
881     sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
882     sb.append(JSampler.VERSION).append("\r\n");
883     sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n");
884    
885     Client lscpClient = new Client(true);
886     ByteArrayOutputStream out = new ByteArrayOutputStream();
887     lscpClient.setPrintOnlyModeOutputStream(out);
888    
889     try {
890     lscpClient.resetSampler();
891     sb.append(out.toString());
892     out.reset();
893     sb.append("\r\n");
894     lscpClient.setVolume(CC.getSamplerModel().getVolume());
895     sb.append(out.toString());
896     out.reset();
897     sb.append("\r\n");
898     } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }
899    
900 iliev 1204 MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();
901 iliev 1143 for(int i = 0; i < mDevs.length; i++) {
902     exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);
903     sb.append(out.toString());
904     out.reset();
905     sb.append("\r\n");
906     }
907    
908 iliev 1204 AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices();
909 iliev 1143 for(int i = 0; i < aDevs.length; i++) {
910     exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);
911     sb.append(out.toString());
912     out.reset();
913     sb.append("\r\n");
914     }
915    
916 iliev 1708 exportInstrMapsToLscpScript(lscpClient);
917     sb.append(out.toString());
918     out.reset();
919    
920 iliev 1204 SamplerChannelModel[] channels = getSamplerModel().getChannels();
921 iliev 1143
922     for(int i = 0; i < channels.length; i++) {
923 iliev 1467 SamplerChannelModel scm = channels[i];
924 iliev 1143 exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);
925     sb.append(out.toString());
926     out.reset();
927    
928     sb.append("\r\n");
929    
930     exportFxSendsToLscpScript(scm, i, lscpClient);
931     sb.append(out.toString());
932     out.reset();
933    
934     sb.append("\r\n");
935     }
936    
937     return sb.toString();
938     }
939    
940     private static void
941     exportMidiDeviceToLscpScript(MidiInputDevice mid, int devId, Client lscpCLient) {
942     try {
943     String s = mid.getDriverName();
944     lscpCLient.createMidiInputDevice(s, mid.getAdditionalParameters());
945    
946     MidiPort[] mPorts = mid.getMidiPorts();
947     int l = mPorts.length;
948     if(l != 1) lscpCLient.setMidiInputPortCount(devId, l);
949    
950     for(int i = 0; i < l; i++) {
951     Parameter[] prms = mPorts[i].getAllParameters();
952     for(Parameter p : prms) {
953     if(!p.isFixed() && p.getStringValue().length() > 0)
954     lscpCLient.setMidiInputPortParameter(devId, i, p);
955     }
956     }
957     } catch(Exception e) {
958     CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
959     }
960     }
961    
962     private static void
963     exportAudioDeviceToLscpScript(AudioOutputDevice aod, int devId, Client lscpCLient) {
964     try {
965     String s = aod.getDriverName();
966     lscpCLient.createAudioOutputDevice(s, aod.getAllParameters());
967    
968     AudioOutputChannel[] chns = aod.getAudioChannels();
969    
970     for(int i = 0; i < chns.length; i++) {
971     Parameter[] prms = chns[i].getAllParameters();
972     for(Parameter p : prms) {
973     if(p.isFixed() || p.getStringValue().length() == 0);
974     else lscpCLient.setAudioOutputChannelParameter(devId, i, p);
975     }
976     }
977     } catch(Exception e) {
978     CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
979     }
980     }
981    
982     private static void
983     exportChannelToLscpScript(SamplerChannel chn, int chnId, Client lscpCLient) {
984     try {
985     lscpCLient.addSamplerChannel();
986    
987 iliev 1467 SamplerModel sm = CC.getSamplerModel();
988     int id = chn.getMidiInputDevice();
989     if(id != -1) {
990     for(int i = 0; i < sm.getMidiDeviceCount(); i++) {
991     if(sm.getMidiDevice(i).getDeviceId() == id) {
992     lscpCLient.setChannelMidiInputDevice(chnId, i);
993     break;
994     }
995     }
996 iliev 1540 lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());
997     lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());
998 iliev 1467 }
999 iliev 1143
1000 iliev 1670 if(chn.getEngine() != null) {
1001     lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);
1002     lscpCLient.setChannelVolume(chnId, chn.getVolume());
1003 iliev 1708 int mapId = chn.getMidiInstrumentMapId();
1004     lscpCLient.setChannelMidiInstrumentMap(chnId, mapId);
1005 iliev 1670 }
1006    
1007 iliev 1467 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 iliev 1143 Integer[] routing = chn.getAudioOutputRouting();
1017    
1018     for(int j = 0; j < routing.length; j++) {
1019     int k = routing[j];
1020     if(k == j) continue;
1021    
1022     lscpCLient.setChannelAudioOutputChannel(chnId, j, k);
1023     }
1024     }
1025    
1026     String s = chn.getInstrumentFile();
1027 iliev 1467 int i = chn.getInstrumentIndex();
1028 iliev 1143 if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);
1029    
1030     if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);
1031     if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true);
1032     } catch(Exception e) {
1033     CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1034     }
1035     }
1036    
1037     private static void
1038     exportFxSendsToLscpScript(SamplerChannelModel scm, int chnId, Client lscpClient) {
1039     try {
1040     FxSend[] fxSends = scm.getFxSends();
1041    
1042     for(int i = 0; i < fxSends.length; i++) {
1043     FxSend f = fxSends[i];
1044     lscpClient.createFxSend(chnId, f.getMidiController(), f.getName());
1045    
1046     Integer[] r = f.getAudioOutputRouting();
1047     for(int j = 0; j < r.length; j++) {
1048     lscpClient.setFxSendAudioOutputChannel(chnId, i, j, r[j]);
1049     }
1050     }
1051     } catch(Exception e) {
1052     CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1053     }
1054     }
1055    
1056 iliev 1688 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 iliev 1143
1069 iliev 1688 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 iliev 911 private final static EventHandler eventHandler = new EventHandler();
1081    
1082     private static EventHandler
1083     getHandler() { return eventHandler; }
1084    
1085 iliev 787 private static class EventHandler implements ChannelCountListener, ChannelInfoListener,
1086 iliev 1143 FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,
1087 iliev 1545 TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener,
1088     OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener,
1089 iliev 1143 MidiInstrumentInfoListener, GlobalInfoListener {
1090 iliev 787
1091     /** Invoked when the number of channels has changed. */
1092     public void
1093     channelCountChanged( ChannelCountEvent e) {
1094     getTaskQueue().add(new UpdateChannels());
1095     }
1096    
1097     /** Invoked when changes to the sampler channel has occured. */
1098     public void
1099     channelInfoChanged(ChannelInfoEvent e) {
1100     /*
1101     * Because of the rapid notification flow when instrument is loaded
1102     * we need to do some optimization to decrease the traffic.
1103     */
1104     boolean b = true;
1105     Task[] tS = getTaskQueue().getPendingTasks();
1106    
1107     for(int i = tS.length - 1; i >= 0; i--) {
1108     Task t = tS[i];
1109    
1110 iliev 1143 if(t instanceof Channel.UpdateInfo) {
1111     Channel.UpdateInfo cui = (Channel.UpdateInfo)t;
1112     if(cui.getChannelId() == e.getSamplerChannel()) return;
1113 iliev 787 } else {
1114     b = false;
1115     break;
1116     }
1117     }
1118    
1119     if(b) {
1120     Task t = getTaskQueue().getRunningTask();
1121 iliev 1143 if(t instanceof Channel.UpdateInfo) {
1122     Channel.UpdateInfo cui = (Channel.UpdateInfo)t;
1123     if(cui.getChannelId() == e.getSamplerChannel()) return;
1124 iliev 787 }
1125     }
1126    
1127    
1128 iliev 1143 getTaskQueue().add(new Channel.UpdateInfo(e.getSamplerChannel()));
1129 iliev 787 }
1130    
1131     /**
1132 iliev 1143 * Invoked when the number of effect sends
1133     * on a particular sampler channel has changed.
1134     */
1135     public void
1136     fxSendCountChanged(FxSendCountEvent e) {
1137     getTaskQueue().add(new Channel.UpdateFxSends(e.getChannel()));
1138     }
1139    
1140     /**
1141     * Invoked when the settings of an effect sends are changed.
1142     */
1143     public void
1144     fxSendInfoChanged(FxSendInfoEvent e) {
1145     Task t = new Channel.UpdateFxSendInfo(e.getChannel(), e.getFxSend());
1146     getTaskQueue().add(t);
1147     }
1148    
1149     /**
1150 iliev 787 * Invoked when the number of active disk
1151     * streams in a specific sampler channel has changed.
1152     */
1153     public void
1154     streamCountChanged(StreamCountEvent e) {
1155     SamplerChannelModel scm =
1156 iliev 1204 getSamplerModel().getChannelById(e.getSamplerChannel());
1157 iliev 787
1158     if(scm == null) {
1159     CC.getLogger().log (
1160     Level.WARNING,
1161     "CC.unknownChannel!",
1162     e.getSamplerChannel()
1163     );
1164    
1165     return;
1166     }
1167    
1168     scm.setStreamCount(e.getStreamCount());
1169     }
1170    
1171     /**
1172     * Invoked when the number of active voices
1173     * in a specific sampler channel has changed.
1174     */
1175     public void
1176     voiceCountChanged(VoiceCountEvent e) {
1177     SamplerChannelModel scm =
1178 iliev 1204 getSamplerModel().getChannelById(e.getSamplerChannel());
1179 iliev 787
1180     if(scm == null) {
1181     CC.getLogger().log (
1182     Level.WARNING,
1183     "CC.unknownChannel!",
1184     e.getSamplerChannel()
1185     );
1186    
1187     return;
1188     }
1189    
1190     scm.setVoiceCount(e.getVoiceCount());
1191     }
1192    
1193 iliev 1545 /** 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 iliev 787 /** Invoked when the total number of active voices has changed. */
1200     public void
1201     totalVoiceCountChanged(TotalVoiceCountEvent e) {
1202     getTaskQueue().add(new UpdateTotalVoiceCount());
1203     }
1204 iliev 911
1205 iliev 1143 /** Invoked when the number of MIDI instruments in a MIDI instrument map is changed. */
1206     public void
1207     instrumentCountChanged(MidiInstrumentCountEvent e) {
1208     getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId()));
1209     }
1210    
1211     /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */
1212     public void
1213     instrumentInfoChanged(MidiInstrumentInfoEvent e) {
1214     Task t = new Midi.UpdateInstrumentInfo (
1215     e.getMapId(), e.getMidiBank(), e.getMidiProgram()
1216     );
1217     getTaskQueue().add(t);
1218    
1219     }
1220    
1221     /** Invoked when the global volume of the sampler is changed. */
1222     public void
1223     volumeChanged(GlobalInfoEvent e) {
1224     getSamplerModel().setVolume(e.getVolume());
1225     }
1226    
1227 iliev 911 /**
1228     * Invoked to indicate that the state of a task queue is changed.
1229     * This method is invoked only from the event-dispatching thread.
1230     */
1231     public void
1232     stateChanged(TaskQueueEvent e) {
1233     switch(e.getEventID()) {
1234     case TASK_FETCHED:
1235     getProgressIndicator().setString (
1236     ((Task)e.getSource()).getDescription()
1237     );
1238     break;
1239     case TASK_DONE:
1240     EnhancedTask t = (EnhancedTask)e.getSource();
1241 iliev 1204 if(t.doneWithErrors() && !t.isStopped()) {
1242 iliev 1285 showError(t);
1243 iliev 1204 }
1244 iliev 911 break;
1245     case NOT_IDLE:
1246     timer.start();
1247     break;
1248     case IDLE:
1249     timer.stop();
1250     getProgressIndicator().stop();
1251     break;
1252     }
1253     }
1254    
1255 iliev 1285 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 iliev 911 /** Invoked when the name of orchestra is changed. */
1274     public void
1275     nameChanged(OrchestraEvent e) { saveOrchestras(); }
1276    
1277     /** Invoked when the description of orchestra is changed. */
1278     public void
1279     descriptionChanged(OrchestraEvent e) { saveOrchestras(); }
1280    
1281     /** Invoked when an instrument is added to the orchestra. */
1282     public void
1283     instrumentAdded(OrchestraEvent e) { saveOrchestras(); }
1284    
1285     /** Invoked when an instrument is removed from the orchestra. */
1286     public void
1287     instrumentRemoved(OrchestraEvent e) { saveOrchestras(); }
1288    
1289     /** Invoked when the settings of an instrument are changed. */
1290     public void
1291     instrumentChanged(OrchestraEvent e) { saveOrchestras(); }
1292    
1293     /** Invoked when an orchestra is added to the orchestra list. */
1294     public void
1295 iliev 1143 entryAdded(ListEvent<OrchestraModel> e) {
1296     e.getEntry().addOrchestraListener(getHandler());
1297 iliev 911 saveOrchestras();
1298     }
1299    
1300     /** Invoked when an orchestra is removed from the orchestra list. */
1301     public void
1302 iliev 1143 entryRemoved(ListEvent<OrchestraModel> e) {
1303     e.getEntry().removeOrchestraListener(getHandler());
1304 iliev 911 saveOrchestras();
1305     }
1306 iliev 787 }
1307 iliev 1143
1308     private static final AudioDeviceCountListener audioDeviceCountListener =
1309     new AudioDeviceCountListener();
1310    
1311     private static class AudioDeviceCountListener implements ItemCountListener {
1312     /** Invoked when the number of audio output devices has changed. */
1313     public void
1314     itemCountChanged(ItemCountEvent e) {
1315     getTaskQueue().add(new Audio.UpdateDevices());
1316     }
1317     }
1318    
1319     private static final AudioDeviceInfoListener audioDeviceInfoListener =
1320     new AudioDeviceInfoListener();
1321    
1322     private static class AudioDeviceInfoListener implements ItemInfoListener {
1323     /** Invoked when the audio output device's settings are changed. */
1324     public void
1325     itemInfoChanged(ItemInfoEvent e) {
1326     getTaskQueue().add(new Audio.UpdateDeviceInfo(e.getItemID()));
1327     }
1328     }
1329    
1330     private static final MidiDeviceCountListener midiDeviceCountListener =
1331     new MidiDeviceCountListener();
1332    
1333     private static class MidiDeviceCountListener implements ItemCountListener {
1334     /** Invoked when the number of MIDI input devices has changed. */
1335     public void
1336     itemCountChanged(ItemCountEvent e) {
1337     getTaskQueue().add(new Midi.UpdateDevices());
1338     }
1339     }
1340    
1341     private static final MidiDeviceInfoListener midiDeviceInfoListener =
1342     new MidiDeviceInfoListener();
1343    
1344     private static class MidiDeviceInfoListener implements ItemInfoListener {
1345     /** Invoked when the MIDI input device's settings are changed. */
1346     public void
1347     itemInfoChanged(ItemInfoEvent e) {
1348     getTaskQueue().add(new Midi.UpdateDeviceInfo(e.getItemID()));
1349     }
1350     }
1351    
1352     private static final MidiInstrMapCountListener midiInstrMapCountListener =
1353     new MidiInstrMapCountListener();
1354    
1355     private static class MidiInstrMapCountListener implements ItemCountListener {
1356     /** Invoked when the number of MIDI instrument maps is changed. */
1357     public void
1358     itemCountChanged(ItemCountEvent e) {
1359     getTaskQueue().add(new Midi.UpdateInstrumentMaps());
1360     }
1361     }
1362    
1363     private static final MidiInstrMapInfoListener midiInstrMapInfoListener =
1364     new MidiInstrMapInfoListener();
1365    
1366     private static class MidiInstrMapInfoListener implements ItemInfoListener {
1367     /** Invoked when the MIDI instrument map's settings are changed. */
1368     public void
1369     itemInfoChanged(ItemInfoEvent e) {
1370     getTaskQueue().add(new Midi.UpdateInstrumentMapInfo(e.getItemID()));
1371     }
1372     }
1373 iliev 787 }

  ViewVC Help
Powered by ViewVC