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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1142 by iliev, Mon Aug 7 18:25:58 2006 UTC revision 1143 by iliev, Mon Apr 2 21:18:31 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005 Grigor Kirilov Iliev   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 27  import java.awt.event.ActionListener; Line 27  import java.awt.event.ActionListener;
27    
28  import java.io.ByteArrayInputStream;  import java.io.ByteArrayInputStream;
29  import java.io.ByteArrayOutputStream;  import java.io.ByteArrayOutputStream;
30    import java.io.File;
31    import java.io.FileInputStream;
32  import java.io.FileOutputStream;  import java.io.FileOutputStream;
33    import java.io.InputStream;
34    
35  import java.util.Vector;  import java.util.Vector;
36    
# Line 47  import net.sf.juife.event.TaskListener; Line 50  import net.sf.juife.event.TaskListener;
50  import net.sf.juife.event.TaskQueueEvent;  import net.sf.juife.event.TaskQueueEvent;
51  import net.sf.juife.event.TaskQueueListener;  import net.sf.juife.event.TaskQueueListener;
52    
53    import org.jsampler.event.ListEvent;
54    import org.jsampler.event.ListListener;
55  import org.jsampler.event.OrchestraEvent;  import org.jsampler.event.OrchestraEvent;
 import org.jsampler.event.OrchestraListEvent;  
 import org.jsampler.event.OrchestraListListener;  
56  import org.jsampler.event.OrchestraListener;  import org.jsampler.event.OrchestraListener;
57    
58  import org.jsampler.task.*;  import org.jsampler.task.*;
# Line 57  import org.jsampler.task.*; Line 60  import org.jsampler.task.*;
60  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
61  import org.jsampler.view.JSProgress;  import org.jsampler.view.JSProgress;
62    
63    import org.linuxsampler.lscp.AudioOutputChannel;
64    import org.linuxsampler.lscp.AudioOutputDevice;
65  import org.linuxsampler.lscp.Client;  import org.linuxsampler.lscp.Client;
66    import org.linuxsampler.lscp.FxSend;
67    import org.linuxsampler.lscp.MidiInputDevice;
68    import org.linuxsampler.lscp.MidiPort;
69    import org.linuxsampler.lscp.Parameter;
70    import org.linuxsampler.lscp.SamplerChannel;
71    
72  import org.linuxsampler.lscp.event.*;  import org.linuxsampler.lscp.event.*;
73    
74  import org.w3c.dom.Document;  import org.w3c.dom.Document;
75  import org.w3c.dom.Node;  import org.w3c.dom.Node;
76    
77    import static org.jsampler.JSI18n.i18n;
78    
79    
80  /**  /**
81   * This class serves as a 'Control Center' of the application.   * This class serves as a 'Control Center' of the application.
# Line 78  public class CC { Line 91  public class CC {
91                    
92          private final static Client lsClient = new Client();          private final static Client lsClient = new Client();
93                    
94            private static String jSamplerHome = null;
95            
96          private final static TaskQueue taskQueue = new TaskQueue();          private final static TaskQueue taskQueue = new TaskQueue();
97          private final static Timer timer = new Timer(2000, null);          private final static Timer timer = new Timer(2000, null);
98                    
99            /** Forbits the instantiation of this class. */
100            private
101            CC() { }
102                    
103          /**          /**
104           * Returns the logger to be used for logging events.           * Returns the logger to be used for logging events.
# Line 132  public class CC { Line 150  public class CC {
150          setProgressIndicator(JSProgress progress) { CC.progress = progress; }          setProgressIndicator(JSProgress progress) { CC.progress = progress; }
151                    
152          /**          /**
153             * Gets the absolute path to the JSampler's home location.
154             * @return The absolute path to the JSampler's home location
155             * or <code>null</code> if the JSampler's home location is not specified yet.
156             */
157            public static String
158            getJSamplerHome() { return jSamplerHome; }
159            
160            /**
161             * Sets the location of the JSampler's home.
162             * @param path The new absolute path to the JSampler's home location.
163             */
164            public static void
165            setJSamplerHome(String path) {
166                    jSamplerHome = path;
167                    Prefs.setJSamplerHome(jSamplerHome);
168            }
169            
170            /**
171           * This method does the initial preparation of the application.           * This method does the initial preparation of the application.
172           */           */
173          protected static void          protected static void
174          initJSampler() {          initJSampler() {
175                  fos = null;                  fos = null;
176                                    setJSamplerHome(Prefs.getJSamplerHome());
177                  try { fos = new FileOutputStream("JSampler.log"); }                  String s = getJSamplerHome();
178                  catch(Exception x) { x.printStackTrace(); }                  try {
179                            if(s != null) {
180                                    s += File.separator + "jsampler.log";
181                                    File f = new File(s);
182                                    if(f.isFile()) HF.createBackup("jsampler.log", "jsampler.log.0");
183                                    fos = new FileOutputStream(s);
184                            }
185                    } catch(Exception x) { x.printStackTrace(); }
186                                    
187                  if(fos == null) handler = new StreamHandler(System.out, new SimpleFormatter());                  if(fos == null) handler = new StreamHandler(System.out, new SimpleFormatter());
188                  else handler = new StreamHandler(fos, new SimpleFormatter());                  else handler = new StreamHandler(fos, new SimpleFormatter());
# Line 160  public class CC { Line 203  public class CC {
203                                    
204                  HF.setUIDefaultFont(Prefs.getInterfaceFont());                  HF.setUIDefaultFont(Prefs.getInterfaceFont());
205                                    
                   
                   
206                  getClient().setServerAddress(Prefs.getLSAddress());                  getClient().setServerAddress(Prefs.getLSAddress());
207                  getClient().setServerPort(Prefs.getLSPort());                  getClient().setServerPort(Prefs.getLSPort());
208                                    
# Line 176  public class CC { Line 217  public class CC {
217                                    
218                  taskQueue.start();                  taskQueue.start();
219                                    
220                    getClient().removeChannelCountListener(getHandler());
221                  getClient().addChannelCountListener(getHandler());                  getClient().addChannelCountListener(getHandler());
222                    
223                    getClient().removeChannelInfoListener(getHandler());
224                  getClient().addChannelInfoListener(getHandler());                  getClient().addChannelInfoListener(getHandler());
225                    
226                    getClient().removeFxSendCountListener(getHandler());
227                    getClient().addFxSendCountListener(getHandler());
228                    
229                    getClient().removeFxSendInfoListener(getHandler());
230                    getClient().addFxSendInfoListener(getHandler());
231                    
232                    getClient().removeStreamCountListener(getHandler());
233                  getClient().addStreamCountListener(getHandler());                  getClient().addStreamCountListener(getHandler());
234                    
235                    getClient().removeVoiceCountListener(getHandler());
236                  getClient().addVoiceCountListener(getHandler());                  getClient().addVoiceCountListener(getHandler());
237                    
238                    getClient().removeTotalVoiceCountListener(getHandler());
239                  getClient().addTotalVoiceCountListener(getHandler());                  getClient().addTotalVoiceCountListener(getHandler());
240                                    
241                  loadOrchestras();                  getClient().removeAudioDeviceCountListener(audioDeviceCountListener);
242                    getClient().addAudioDeviceCountListener(audioDeviceCountListener);
243                                    
244                  for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {                  getClient().removeAudioDeviceInfoListener(audioDeviceInfoListener);
245                          getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());                  getClient().addAudioDeviceInfoListener(audioDeviceInfoListener);
246                    
247                    getClient().removeMidiDeviceCountListener(midiDeviceCountListener);
248                    getClient().addMidiDeviceCountListener(midiDeviceCountListener);
249                    
250                    getClient().removeMidiDeviceInfoListener(midiDeviceInfoListener);
251                    getClient().addMidiDeviceInfoListener(midiDeviceInfoListener);
252                    
253                    getClient().removeMidiInstrumentMapCountListener(midiInstrMapCountListener);
254                    getClient().addMidiInstrumentMapCountListener(midiInstrMapCountListener);
255                    
256                    getClient().removeMidiInstrumentMapInfoListener(midiInstrMapInfoListener);
257                    getClient().addMidiInstrumentMapInfoListener(midiInstrMapInfoListener);
258                    
259                    getClient().removeMidiInstrumentCountListener(getHandler());
260                    getClient().addMidiInstrumentCountListener(getHandler());
261                    
262                    getClient().removeMidiInstrumentInfoListener(getHandler());
263                    getClient().addMidiInstrumentInfoListener(getHandler());
264                    
265                    getClient().removeGlobalInfoListener(getHandler());
266                    getClient().addGlobalInfoListener(getHandler());
267            }
268            
269            /**
270             * Checks whether the JSampler home directory is specified and exist.
271             * If the JSampler home directory is not specifed, or is specified
272             * but doesn't exist, a procedure of specifying a JSampler home
273             * directory is initiated.
274             * @see org.jsampler.view.JSMainFrame#installJSamplerHome
275             */
276            public static void
277            checkJSamplerHome() {
278                    if(getJSamplerHome() != null) {
279                            File f = new File(getJSamplerHome());
280                            if(f.isDirectory()) return;
281                  }                  }
282                  getOrchestras().addOrchestraListListener(getHandler());                  
283                    CC.getMainFrame().installJSamplerHome();
284            }
285            
286            /**
287             * Changes the JSampler's home directory and moves all files from
288             * the old JSampler's home directory to the new one. If all files are
289             * moved succesfully, the old directory is deleted.
290             * @param path The location of the new JSampler's home directory. If
291             * the last directory in the path doesn't exist, it is created.
292             */
293            public static void
294            changeJSamplerHome(String path) {
295                    File fNew = new File(path);
296                    if(fNew.isFile()) {
297                            HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!"));
298                            return;
299                    }
300                    
301                    if(!fNew.isDirectory()) {
302                            if(!fNew.mkdir()) {
303                                    String s = fNew.getAbsolutePath();
304                                    HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s));
305                                    return;
306                            }
307                    }
308                    
309                    if(getJSamplerHome() == null) {
310                            setJSamplerHome(fNew.getAbsolutePath());
311                            return;
312                    }
313                    
314                    File fOld = new File(getJSamplerHome());
315                    if(!fOld.isDirectory()) {
316                            setJSamplerHome(fNew.getAbsolutePath());
317                            return;
318                    }
319                    
320                    File[] files = fOld.listFiles();
321                    boolean b = true;
322                    if(files != null) {
323                            String s = fNew.getAbsolutePath() + File.separator;
324                            for(File f : files) if(!f.renameTo(new File(s + f.getName()))) b = false;
325                    }
326                    
327                    if(b) fOld.delete();
328                    setJSamplerHome(fNew.getAbsolutePath());
329          }          }
330                    
331          private final static OrchestraListModel orchestras = new DefaultOrchestraListModel();          private final static OrchestraListModel orchestras = new DefaultOrchestraListModel();
# Line 199  public class CC { Line 337  public class CC {
337          public static OrchestraListModel          public static OrchestraListModel
338          getOrchestras() { return orchestras; }          getOrchestras() { return orchestras; }
339                    
340          private static void          /**
341             * Loads the orchestras described in <code>&lt;jsampler_home&gt;/orchestras.xml</code>.
342             * If file with name <code>orchestras.xml.bkp</code> exist in the JSampler's home
343             * directory, this means that the last save has failed. In that case a recovery file
344             * <code>orchestras.xml.rec</code> is created and a recovery procedure
345             * will be initiated.
346             */
347            public static void
348          loadOrchestras() {          loadOrchestras() {
349                    if(getJSamplerHome() == null) return;
350                    
351                    //TODO: This should be removed in the next release (including loadOrchestras0())
352                    File f2 = new File(getJSamplerHome() + File.separator + "orchestras.xml");
353                    if(!f2.isFile()) {
354                            loadOrchestras0();
355                            saveOrchestras();
356                            return;
357                    }
358                    ///////
359                    
360                    try {
361                            String s = getJSamplerHome();
362                            if(s == null) return;
363                            
364                            File f = new File(s + File.separator + "orchestras.xml.bkp");
365                            if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec");
366                            
367                            FileInputStream fis;
368                            fis = new FileInputStream(s + File.separator + "orchestras.xml");
369                            
370                            loadOrchestras(fis);
371                            fis.close();
372                    } catch(Exception x) {
373                            getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
374                    }
375            }
376            
377            
378            private static void
379            loadOrchestras(InputStream in) {
380                    Document doc = DOMUtils.readObject(in);
381                    
382                    try { getOrchestras().readObject(doc.getDocumentElement()); }
383                    catch(Exception x) {
384                            HF.showErrorMessage(x, "Loading orchestras: ");
385                            return;
386                    }
387                    
388                    for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {
389                            getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());
390                    }
391                    getOrchestras().addOrchestraListListener(getHandler());
392            }
393            
394            private static void
395            loadOrchestras0() {
396                  String s = Prefs.getOrchestras();                  String s = Prefs.getOrchestras();
397                  if(s == null) return;                  if(s == null) return;
398                                    
# Line 213  public class CC { Line 405  public class CC {
405                    
406          private static void          private static void
407          saveOrchestras() {          saveOrchestras() {
408                  Document doc = DOMUtils.createEmptyDocument();                  try {
409                                            String s = getJSamplerHome();
410                  Node node = doc.createElement("temp");                          if(s == null) return;
411                  doc.appendChild(node);                          
412                                            HF.createBackup("orchestras.xml", "orchestras.xml.bkp");
413                  getOrchestras().writeObject(doc, doc.getDocumentElement());                          
414                            FileOutputStream fos;
415                            fos = new FileOutputStream(s + File.separator + "orchestras.xml", false);
416                            
417                            Document doc = DOMUtils.createEmptyDocument();
418                                    
419                  doc.replaceChild(node.getFirstChild(), node);                          Node node = doc.createElement("temp");
420                            doc.appendChild(node);
421                            
422                            getOrchestras().writeObject(doc, doc.getDocumentElement());
423                            
424                            doc.replaceChild(node.getFirstChild(), node);
425                                    
426                  ByteArrayOutputStream baos = new ByteArrayOutputStream();                          DOMUtils.writeObject(doc, fos);
427                  DOMUtils.writeObject(doc, baos);                          
428                  Prefs.setOrchestras(baos.toString());                          fos.close();
429                            
430                            HF.deleteFile("orchestras.xml.bkp");
431                    } catch(Exception x) {
432                            HF.showErrorMessage(x, "Saving orchestras: ");
433                            return;
434                    }
435          }          }
436                    
437          /**          /**
# Line 306  public class CC { Line 513  public class CC {
513                          }                          }
514                  });                  });
515                                    
516                  final GetAODrivers gaod = new GetAODrivers();                  final Audio.GetDrivers gaod = new Audio.GetDrivers();
517                  gaod.addTaskListener(new TaskListener() {                  gaod.addTaskListener(new TaskListener() {
518                          public void                          public void
519                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
# Line 323  public class CC { Line 530  public class CC {
530                          }                          }
531                  });                  });
532                                    
533                  final GetMIDrivers gmid = new GetMIDrivers();                  final Midi.GetDrivers gmid = new Midi.GetDrivers();
534                  gmid.addTaskListener(new TaskListener() {                  gmid.addTaskListener(new TaskListener() {
535                          public void                          public void
536                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
# Line 332  public class CC { Line 539  public class CC {
539                          }                          }
540                  });                  });
541                                    
542                    final Global.GetVolume gv = new Global.GetVolume();
543                    gv.addTaskListener(new TaskListener() {
544                            public void
545                            taskPerformed(TaskEvent e) {
546                                    if(!gv.doneWithErrors())
547                                            model.setVolume(gv.getResult());
548                            }
549                    });
550                    
551                    final Midi.GetInstrumentMaps mgim = new Midi.GetInstrumentMaps();
552                    mgim.addTaskListener(new TaskListener() {
553                            public void
554                            taskPerformed(TaskEvent e) {
555                                    if(mgim.doneWithErrors()) return;
556                                    model.removeAllMidiInstrumentMaps();
557                                    
558                                    for(MidiInstrumentMap map : mgim.getResult()) {
559                                            model.addMidiInstrumentMap(map);
560                                    }
561                            }
562                    });
563                    
564                    final UpdateChannels uc = new UpdateChannels();
565                    uc.addTaskListener(new TaskListener() {
566                            public void
567                            taskPerformed(TaskEvent e) {
568                                    for(SamplerChannelModel c : model.getChannelModels()) {
569                                            if(c.getChannelInfo().getEngine() == null) continue;
570                                            
571                                            Channel.GetFxSends gfs = new Channel.GetFxSends();
572                                            gfs.setChannel(c.getChannelId());
573                                            gfs.addTaskListener(new GetFxSendsListener());
574                                            getTaskQueue().add(gfs);
575                                    }
576                            }
577                    });
578                    
579                    
580                  final Connect cnt = new Connect();                  final Connect cnt = new Connect();
581                  cnt.addTaskListener(new TaskListener() {                  cnt.addTaskListener(new TaskListener() {
582                          public void                          public void
# Line 342  public class CC { Line 587  public class CC {
587                                  getTaskQueue().add(gaod);                                  getTaskQueue().add(gaod);
588                                  getTaskQueue().add(gmid);                                  getTaskQueue().add(gmid);
589                                  getTaskQueue().add(ge);                                  getTaskQueue().add(ge);
590                                  getTaskQueue().add(new UpdateMidiDevices());                                  getTaskQueue().add(gv);
591                                  getTaskQueue().add(new UpdateAudioDevices());                                  getTaskQueue().add(mgim);
592                                  getTaskQueue().add(new UpdateChannels());                                  getTaskQueue().add(new Midi.UpdateDevices());
593                                    getTaskQueue().add(new Audio.UpdateDevices());
594                                    getTaskQueue().add(uc);
595                          }                          }
596                  });                  });
597                  getTaskQueue().add(cnt);                  getTaskQueue().add(cnt);
598          }          }
599                    
600            private static class GetFxSendsListener implements TaskListener {
601                    public void
602                    taskPerformed(TaskEvent e) {
603                            Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();
604                            if(gfs.doneWithErrors()) return;
605                            SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel());
606                            m.removeAllFxSends();
607                            
608                            for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);
609                    }
610            }
611            
612            public static String
613            exportInstrMapsToLscpScript() {
614                    StringBuffer sb = new StringBuffer("# Exported by: ");
615                    sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
616                    sb.append(JSampler.VERSION).append("\r\n");
617                    sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n");
618                    
619                    Client lscpClient = new Client(true);
620                    ByteArrayOutputStream out = new ByteArrayOutputStream();
621                    lscpClient.setPrintOnlyModeOutputStream(out);
622                    
623                    exportInstrMapsToLscpScript(lscpClient);
624                    sb.append(out.toString());
625                    out.reset();
626                    
627                    return sb.toString();
628            }
629            
630            private static void
631            exportInstrMapsToLscpScript(Client lscpClient) {
632                    try {
633                            lscpClient.removeAllMidiInstrumentMaps();
634                            MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps();
635                            for(int i = 0; i < maps.length; i++) {
636                                    lscpClient.addMidiInstrumentMap(maps[i].getName());
637                                    exportInstrumentsToLscpScript(i, maps[i], lscpClient);
638                            }
639                    } catch(Exception e) {
640                            CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
641                            HF.showErrorMessage(e);
642                    }
643            }
644            
645            private static void
646            exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient)
647                                                                                    throws Exception {
648            
649                    for(MidiInstrument i : map.getAllMidiInstruments()) {
650                            lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo());
651                    }
652            }
653            
654            public static String
655            exportSessionToLscpScript() {
656                    StringBuffer sb = new StringBuffer("# Exported by: ");
657                    sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
658                    sb.append(JSampler.VERSION).append("\r\n");
659                    sb.append("# Date: ").append(new java.util.Date().toString()).append("\r\n\r\n");
660                    
661                    Client lscpClient = new Client(true);
662                    ByteArrayOutputStream out = new ByteArrayOutputStream();
663                    lscpClient.setPrintOnlyModeOutputStream(out);
664                    
665                    try {
666                            lscpClient.resetSampler();
667                            sb.append(out.toString());
668                            out.reset();
669                            sb.append("\r\n");
670                            lscpClient.setVolume(CC.getSamplerModel().getVolume());
671                            sb.append(out.toString());
672                            out.reset();
673                            sb.append("\r\n");
674                    } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }
675                                    
676                    MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels();
677                    for(int i = 0; i < mDevs.length; i++) {
678                            exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);
679                            sb.append(out.toString());
680                            out.reset();
681                            sb.append("\r\n");
682                    }
683                    
684                    AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels();
685                    for(int i = 0; i < aDevs.length; i++) {
686                            exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);
687                            sb.append(out.toString());
688                            out.reset();
689                            sb.append("\r\n");
690                    }
691                    
692                    SamplerChannelModel[] channels = getSamplerModel().getChannelModels();
693                    
694                    for(int i = 0; i < channels.length; i++) {
695                            SamplerChannelModel scm = getSamplerModel().getChannelModel(i);
696                            exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);
697                            sb.append(out.toString());
698                            out.reset();
699                            
700                            sb.append("\r\n");
701                            
702                            exportFxSendsToLscpScript(scm, i, lscpClient);
703                            sb.append(out.toString());
704                            out.reset();
705                            
706                            sb.append("\r\n");
707                    }
708                    
709                    exportInstrMapsToLscpScript(lscpClient);
710                    sb.append(out.toString());
711                    out.reset();
712                    
713                    return sb.toString();
714            }
715            
716            private static void
717            exportMidiDeviceToLscpScript(MidiInputDevice mid, int devId, Client lscpCLient) {
718                    try {
719                            String s = mid.getDriverName();
720                            lscpCLient.createMidiInputDevice(s, mid.getAdditionalParameters());
721                            
722                            MidiPort[] mPorts = mid.getMidiPorts();
723                            int l = mPorts.length;
724                            if(l != 1) lscpCLient.setMidiInputPortCount(devId, l);
725                            
726                            for(int i = 0; i < l; i++) {
727                                    Parameter[] prms = mPorts[i].getAllParameters();
728                                    for(Parameter p : prms) {
729                                            if(!p.isFixed() && p.getStringValue().length() > 0)
730                                                    lscpCLient.setMidiInputPortParameter(devId, i, p);
731                                    }
732                            }
733                    } catch(Exception e) {
734                            CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
735                    }
736            }
737            
738            private static void
739            exportAudioDeviceToLscpScript(AudioOutputDevice aod, int devId, Client lscpCLient) {
740                    try {
741                            String s = aod.getDriverName();
742                            lscpCLient.createAudioOutputDevice(s, aod.getAllParameters());
743                            
744                            AudioOutputChannel[] chns = aod.getAudioChannels();
745                            
746                            for(int i = 0; i < chns.length; i++) {
747                                    Parameter[] prms = chns[i].getAllParameters();
748                                    for(Parameter p : prms) {
749                                            if(p.isFixed() || p.getStringValue().length() == 0);
750                                            else lscpCLient.setAudioOutputChannelParameter(devId, i, p);
751                                    }
752                            }
753                    } catch(Exception e) {
754                            CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
755                    }
756            }
757            
758            private static void
759            exportChannelToLscpScript(SamplerChannel chn, int chnId, Client lscpCLient) {
760                    try {
761                            lscpCLient.addSamplerChannel();
762                            
763                            int i = chn.getMidiInputDevice();
764                            if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i);
765                            lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());
766                            lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());
767                            
768                            i = chn.getAudioOutputDevice();
769                            if(i != -1) {
770                                    lscpCLient.setChannelAudioOutputDevice(chnId, i);
771                                    Integer[] routing = chn.getAudioOutputRouting();
772                                    
773                                    for(int j = 0; j < routing.length; j++) {
774                                            int k = routing[j];
775                                            if(k == j) continue;
776                                            
777                                            lscpCLient.setChannelAudioOutputChannel(chnId, j, k);
778                                    }
779                            }
780                            
781                            if(chn.getEngine() != null) {
782                                    lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);
783                                    lscpCLient.setChannelVolume(chnId, chn.getVolume());
784                            }
785                            
786                            String s = chn.getInstrumentFile();
787                            i = chn.getInstrumentIndex();
788                            if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);
789                            
790                            if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);
791                            if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true);
792                    } catch(Exception e) {
793                            CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
794                    }
795            }
796            
797            private static void
798            exportFxSendsToLscpScript(SamplerChannelModel scm, int chnId, Client lscpClient) {
799                    try {
800                            FxSend[] fxSends = scm.getFxSends();
801                            
802                            for(int i = 0; i < fxSends.length; i++) {
803                                    FxSend f = fxSends[i];
804                                    lscpClient.createFxSend(chnId, f.getMidiController(), f.getName());
805                                    
806                                    Integer[] r = f.getAudioOutputRouting();
807                                    for(int j = 0; j < r.length; j++) {
808                                            lscpClient.setFxSendAudioOutputChannel(chnId, i, j, r[j]);
809                                    }
810                            }
811                    } catch(Exception e) {
812                            CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
813                    }
814            }
815            
816            
817          private final static EventHandler eventHandler = new EventHandler();          private final static EventHandler eventHandler = new EventHandler();
818                    
819          private static EventHandler          private static EventHandler
820          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
821                    
822          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,
823                  StreamCountListener, VoiceCountListener, TotalVoiceCountListener,                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,
824                  TaskQueueListener, OrchestraListener, OrchestraListListener {                  TotalVoiceCountListener, TaskQueueListener, OrchestraListener,
825                    ListListener<OrchestraModel>, MidiInstrumentCountListener,
826                    MidiInstrumentInfoListener, GlobalInfoListener {
827                                    
828                  /** Invoked when the number of channels has changed. */                  /** Invoked when the number of channels has changed. */
829                  public void                  public void
# Line 378  public class CC { Line 844  public class CC {
844                          for(int i = tS.length - 1; i >= 0; i--) {                          for(int i = tS.length - 1; i >= 0; i--) {
845                                  Task t = tS[i];                                  Task t = tS[i];
846                                                                    
847                                  if(t instanceof UpdateChannelInfo) {                                  if(t instanceof Channel.UpdateInfo) {
848                                          UpdateChannelInfo uci = (UpdateChannelInfo)t;                                          Channel.UpdateInfo cui = (Channel.UpdateInfo)t;
849                                          if(uci.getChannelID() == e.getSamplerChannel()) return;                                          if(cui.getChannelId() == e.getSamplerChannel()) return;
850                                  } else {                                  } else {
851                                          b = false;                                          b = false;
852                                          break;                                          break;
# Line 389  public class CC { Line 855  public class CC {
855                                                    
856                          if(b) {                          if(b) {
857                                  Task t = getTaskQueue().getRunningTask();                                  Task t = getTaskQueue().getRunningTask();
858                                  if(t instanceof UpdateChannelInfo) {                                  if(t instanceof Channel.UpdateInfo) {
859                                          UpdateChannelInfo uci = (UpdateChannelInfo)t;                                          Channel.UpdateInfo cui = (Channel.UpdateInfo)t;
860                                          if(uci.getChannelID() == e.getSamplerChannel()) return;                                          if(cui.getChannelId() == e.getSamplerChannel()) return;
861                                  }                                  }
862                          }                          }
863                                                    
864                                                    
865                          getTaskQueue().add(new UpdateChannelInfo(e.getSamplerChannel()));                          getTaskQueue().add(new Channel.UpdateInfo(e.getSamplerChannel()));
866                    }
867                    
868                    /**
869                     * Invoked when the number of effect sends
870                     * on a particular sampler channel has changed.
871                     */
872                    public void
873                    fxSendCountChanged(FxSendCountEvent e) {
874                            getTaskQueue().add(new Channel.UpdateFxSends(e.getChannel()));
875                    }
876                    
877                    /**
878                     * Invoked when the settings of an effect sends are changed.
879                     */
880                    public void
881                    fxSendInfoChanged(FxSendInfoEvent e) {
882                            Task t = new Channel.UpdateFxSendInfo(e.getChannel(), e.getFxSend());
883                            getTaskQueue().add(t);
884                  }                  }
885                                    
886                  /**                  /**
# Line 449  public class CC { Line 933  public class CC {
933                          getTaskQueue().add(new UpdateTotalVoiceCount());                          getTaskQueue().add(new UpdateTotalVoiceCount());
934                  }                  }
935                                    
936                    /** Invoked when the number of MIDI instruments in a MIDI instrument map is changed. */
937                    public void
938                    instrumentCountChanged(MidiInstrumentCountEvent e) {
939                            getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId()));
940                    }
941                    
942                    /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */
943                    public void
944                    instrumentInfoChanged(MidiInstrumentInfoEvent e) {
945                            Task t = new Midi.UpdateInstrumentInfo (
946                                    e.getMapId(), e.getMidiBank(), e.getMidiProgram()
947                            );
948                            getTaskQueue().add(t);
949                                    
950                    }
951                    
952                    /** Invoked when the global volume of the sampler is changed. */
953                    public void
954                    volumeChanged(GlobalInfoEvent e) {
955                            getSamplerModel().setVolume(e.getVolume());
956                    }
957                    
958                  /**                  /**
959                   * Invoked to indicate that the state of a task queue is changed.                   * Invoked to indicate that the state of a task queue is changed.
960                   * This method is invoked only from the event-dispatching thread.                   * This method is invoked only from the event-dispatching thread.
# Line 498  public class CC { Line 1004  public class CC {
1004                                    
1005                  /** Invoked when an orchestra is added to the orchestra list. */                  /** Invoked when an orchestra is added to the orchestra list. */
1006                  public void                  public void
1007                  orchestraAdded(OrchestraListEvent e) {                  entryAdded(ListEvent<OrchestraModel> e) {
1008                          e.getOrchestraModel().addOrchestraListener(getHandler());                          e.getEntry().addOrchestraListener(getHandler());
1009                          saveOrchestras();                          saveOrchestras();
1010                  }                  }
1011                    
1012                  /** Invoked when an orchestra is removed from the orchestra list. */                  /** Invoked when an orchestra is removed from the orchestra list. */
1013                  public void                  public void
1014                  orchestraRemoved(OrchestraListEvent e) {                  entryRemoved(ListEvent<OrchestraModel> e) {
1015                          e.getOrchestraModel().removeOrchestraListener(getHandler());                          e.getEntry().removeOrchestraListener(getHandler());
1016                          saveOrchestras();                          saveOrchestras();
1017                  }                  }
1018          }          }
1019            
1020            private static final AudioDeviceCountListener audioDeviceCountListener =
1021                    new AudioDeviceCountListener();
1022            
1023            private static class AudioDeviceCountListener implements ItemCountListener {
1024                    /** Invoked when the number of audio output devices has changed. */
1025                    public void
1026                    itemCountChanged(ItemCountEvent e) {
1027                            getTaskQueue().add(new Audio.UpdateDevices());
1028                    }
1029            }
1030            
1031            private static final AudioDeviceInfoListener audioDeviceInfoListener =
1032                    new AudioDeviceInfoListener();
1033            
1034            private static class AudioDeviceInfoListener implements ItemInfoListener {
1035                    /** Invoked when the audio output device's settings are changed. */
1036                    public void
1037                    itemInfoChanged(ItemInfoEvent e) {
1038                            getTaskQueue().add(new Audio.UpdateDeviceInfo(e.getItemID()));
1039                    }
1040            }
1041            
1042            private static final MidiDeviceCountListener midiDeviceCountListener =
1043                    new MidiDeviceCountListener();
1044            
1045            private static class MidiDeviceCountListener implements ItemCountListener {
1046                    /** Invoked when the number of MIDI input devices has changed. */
1047                    public void
1048                    itemCountChanged(ItemCountEvent e) {
1049                            getTaskQueue().add(new Midi.UpdateDevices());
1050                    }
1051            }
1052            
1053            private static final MidiDeviceInfoListener midiDeviceInfoListener =
1054                    new MidiDeviceInfoListener();
1055            
1056            private static class MidiDeviceInfoListener implements ItemInfoListener {
1057                    /** Invoked when the MIDI input device's settings are changed. */
1058                    public void
1059                    itemInfoChanged(ItemInfoEvent e) {
1060                            getTaskQueue().add(new Midi.UpdateDeviceInfo(e.getItemID()));
1061                    }
1062            }
1063            
1064            private static final MidiInstrMapCountListener midiInstrMapCountListener =
1065                    new MidiInstrMapCountListener();
1066            
1067            private static class MidiInstrMapCountListener implements ItemCountListener {
1068                    /** Invoked when the number of MIDI instrument maps is changed. */
1069                    public void
1070                    itemCountChanged(ItemCountEvent e) {
1071                            getTaskQueue().add(new Midi.UpdateInstrumentMaps());
1072                    }
1073            }
1074            
1075            private static final MidiInstrMapInfoListener midiInstrMapInfoListener =
1076                    new MidiInstrMapInfoListener();
1077            
1078            private static class MidiInstrMapInfoListener implements ItemInfoListener {
1079                    /** Invoked when the MIDI instrument map's settings are changed. */
1080                    public void
1081                    itemInfoChanged(ItemInfoEvent e) {
1082                            getTaskQueue().add(new Midi.UpdateInstrumentMapInfo(e.getItemID()));
1083                    }
1084            }
1085  }  }

Legend:
Removed from v.1142  
changed lines
  Added in v.1143

  ViewVC Help
Powered by ViewVC