/[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 1143 by iliev, Mon Apr 2 21:18:31 2007 UTC revision 1737 by iliev, Thu May 8 17:26:19 2008 UTC
# Line 25  package org.jsampler; Line 25  package org.jsampler;
25  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
27    
 import java.io.ByteArrayInputStream;  
28  import java.io.ByteArrayOutputStream;  import java.io.ByteArrayOutputStream;
29  import java.io.File;  import java.io.File;
30  import java.io.FileInputStream;  import java.io.FileInputStream;
# Line 42  import java.util.logging.StreamHandler; Line 41  import java.util.logging.StreamHandler;
41    
42  import javax.swing.Timer;  import javax.swing.Timer;
43    
44    import javax.swing.event.ChangeEvent;
45    import javax.swing.event.ChangeListener;
46    
47  import net.sf.juife.Task;  import net.sf.juife.Task;
48  import net.sf.juife.TaskQueue;  import net.sf.juife.TaskQueue;
49    
# Line 59  import org.jsampler.task.*; Line 61  import org.jsampler.task.*;
61    
62  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
63  import org.jsampler.view.JSProgress;  import org.jsampler.view.JSProgress;
64    import org.jsampler.view.JSViewConfig;
65    import org.jsampler.view.InstrumentsDbTreeModel;
66    
67  import org.linuxsampler.lscp.AudioOutputChannel;  import org.linuxsampler.lscp.AudioOutputChannel;
68  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
# Line 86  public class CC { Line 90  public class CC {
90          private static Handler handler;          private static Handler handler;
91          private static FileOutputStream fos;          private static FileOutputStream fos;
92                    
93            private static JSViewConfig viewConfig = null;
94          private static JSMainFrame mainFrame = null;          private static JSMainFrame mainFrame = null;
95          private static JSProgress progress = null;          private static JSProgress progress = null;
96                    
# Line 122  public class CC { Line 127  public class CC {
127          getTaskQueue() { return taskQueue; }          getTaskQueue() { return taskQueue; }
128                    
129          /**          /**
130             * Adds the specified task to the task queue. All task in the
131             * queue equal to the specified task are removed from the queue.
132             */
133            public static void
134            scheduleTask(Task t) {
135                    while(getTaskQueue().removeTask(t)) { }
136                    
137                    getTaskQueue().add(t);
138            }
139            
140            /**
141             * Adds the specified task to the task queue only if the last
142             * task in the is not equal to <code>t</code>.
143             */
144            public static void
145            addTask(Task t) {
146                    Task[] tasks = getTaskQueue().getPendingTasks();
147                    if(tasks.length > 0 && tasks[tasks.length - 1].equals(t)) return;
148                    getTaskQueue().add(t);
149            }
150            
151            /**
152             * Gets the configuration of the current view.
153             */
154            public static JSViewConfig
155            getViewConfig() { return viewConfig; }
156            
157            private static JSPrefs
158            preferences() { return getViewConfig().preferences(); }
159            
160            /**
161             * Sets the configuration of the current view.
162             */
163            public static void
164            setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; }
165            
166            /**
167           * Returns the main window of this application.           * Returns the main window of this application.
168           * @return The main window of this application.           * @return The main window of this application.
169           */           */
# Line 190  public class CC { Line 232  public class CC {
232                  handler.setLevel(Level.FINE);                  handler.setLevel(Level.FINE);
233                  getLogger().addHandler(handler);                  getLogger().addHandler(handler);
234                  getLogger().setLevel(Level.FINE);                  getLogger().setLevel(Level.FINE);
                 Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);  
235                  Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE);                  Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE);
236                    Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
237                                    
238                  // Flushing logs on every second                  // Flushing logs on every second
239                  new java.util.Timer().schedule(new java.util.TimerTask() {                  new java.util.Timer().schedule(new java.util.TimerTask() {
# Line 203  public class CC { Line 245  public class CC {
245                                    
246                  HF.setUIDefaultFont(Prefs.getInterfaceFont());                  HF.setUIDefaultFont(Prefs.getInterfaceFont());
247                                    
                 getClient().setServerAddress(Prefs.getLSAddress());  
                 getClient().setServerPort(Prefs.getLSPort());  
                   
248                  timer.setRepeats(false);                  timer.setRepeats(false);
249                                    
250                  timer.addActionListener(new ActionListener() {                  timer.addActionListener(new ActionListener() {
# Line 235  public class CC { Line 274  public class CC {
274                  getClient().removeVoiceCountListener(getHandler());                  getClient().removeVoiceCountListener(getHandler());
275                  getClient().addVoiceCountListener(getHandler());                  getClient().addVoiceCountListener(getHandler());
276                                    
277                    getClient().removeTotalStreamCountListener(getHandler());
278                    getClient().addTotalStreamCountListener(getHandler());
279                    
280                  getClient().removeTotalVoiceCountListener(getHandler());                  getClient().removeTotalVoiceCountListener(getHandler());
281                  getClient().addTotalVoiceCountListener(getHandler());                  getClient().addTotalVoiceCountListener(getHandler());
282                                    
# Line 277  public class CC { Line 319  public class CC {
319          checkJSamplerHome() {          checkJSamplerHome() {
320                  if(getJSamplerHome() != null) {                  if(getJSamplerHome() != null) {
321                          File f = new File(getJSamplerHome());                          File f = new File(getJSamplerHome());
322                          if(f.isDirectory()) return;                          if(f.exists() && f.isDirectory()) {
323                                    return;
324                            }
325                  }                  }
326                                    
327                  CC.getMainFrame().installJSamplerHome();                  CC.getMainFrame().installJSamplerHome();
# Line 293  public class CC { Line 337  public class CC {
337          public static void          public static void
338          changeJSamplerHome(String path) {          changeJSamplerHome(String path) {
339                  File fNew = new File(path);                  File fNew = new File(path);
340                  if(fNew.isFile()) {                  if(fNew.exists() && fNew.isFile()) {
341                          HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!"));                          HF.showErrorMessage(i18n.getError("CC.JSamplerHomeIsNotDir!"));
342                          return;                          return;
343                  }                  }
344                                    
345                  if(!fNew.isDirectory()) {                  if(!fNew.exists()) {
346                          if(!fNew.mkdir()) {                          if(!fNew.mkdir()) {
347                                  String s = fNew.getAbsolutePath();                                  String s = fNew.getAbsolutePath();
348                                  HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s));                                  HF.showErrorMessage(i18n.getError("CC.mkdirFailed", s));
# Line 306  public class CC { Line 350  public class CC {
350                          }                          }
351                  }                  }
352                                    
353                  if(getJSamplerHome() == null) {                  if(getJSamplerHome() == null || path.equals(getJSamplerHome())) {
354                          setJSamplerHome(fNew.getAbsolutePath());                          setJSamplerHome(fNew.getAbsolutePath());
355                          return;                          return;
356                  }                  }
357                                    
358                  File fOld = new File(getJSamplerHome());                  File fOld = new File(getJSamplerHome());
359                  if(!fOld.isDirectory()) {                  if(!fOld.exists() || !fOld.isDirectory()) {
360                          setJSamplerHome(fNew.getAbsolutePath());                          setJSamplerHome(fNew.getAbsolutePath());
361                          return;                          return;
362                  }                  }
# Line 337  public class CC { Line 381  public class CC {
381          public static OrchestraListModel          public static OrchestraListModel
382          getOrchestras() { return orchestras; }          getOrchestras() { return orchestras; }
383                    
384            private final static ServerList servers = new ServerList();
385            
386            /** Returns the server list. */
387            public static ServerList
388            getServerList() { return servers; }
389            
390            private static ServerListListener serverListListener = new ServerListListener();
391            
392            private static class ServerListListener implements ChangeListener {
393                    public void
394                    stateChanged(ChangeEvent e) {
395                            saveServerList();
396                    }
397            }
398            
399            private static final Vector<ChangeListener> idtmListeners = new Vector<ChangeListener>();
400            private static InstrumentsDbTreeModel instrumentsDbTreeModel = null;
401            
402            /**
403             * Gets the tree model of the instruments database.
404             * If the currently used view doesn't have instruments
405             * database support the tree model is initialized on first use.
406             * @return The tree model of the instruments database or
407             * <code>null</code> if the backend doesn't have instruments database support.
408             * @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport
409             */
410            public static InstrumentsDbTreeModel
411            getInstrumentsDbTreeModel() {
412                    if(CC.getSamplerModel().getServerInfo() == null) return null;
413                    if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null;
414                    
415                    if(instrumentsDbTreeModel == null) {
416                            instrumentsDbTreeModel = new InstrumentsDbTreeModel();
417                            for(ChangeListener l : idtmListeners) l.stateChanged(null);
418                    }
419                    
420                    return instrumentsDbTreeModel;
421            }
422            
423            public static void
424            addInstrumentsDbChangeListener(ChangeListener l) {
425                    idtmListeners.add(l);
426            }
427            
428            public static void
429            removeInstrumentsDbChangeListener(ChangeListener l) {
430                    idtmListeners.remove(l);
431            }
432            
433            private static final LostFilesModel lostFilesModel = new LostFilesModel();
434            
435            public static LostFilesModel
436            getLostFilesModel() { return lostFilesModel; }
437            
438          /**          /**
439           * Loads the orchestras described in <code>&lt;jsampler_home&gt;/orchestras.xml</code>.           * Loads the orchestras described in <code>&lt;jsampler_home&gt;/orchestras.xml</code>.
440           * If file with name <code>orchestras.xml.bkp</code> exist in the JSampler's home           * If file with name <code>orchestras.xml.bkp</code> exist in the JSampler's home
# Line 348  public class CC { Line 446  public class CC {
446          loadOrchestras() {          loadOrchestras() {
447                  if(getJSamplerHome() == null) return;                  if(getJSamplerHome() == null) return;
448                                    
                 //TODO: This should be removed in the next release (including loadOrchestras0())  
                 File f2 = new File(getJSamplerHome() + File.separator + "orchestras.xml");  
                 if(!f2.isFile()) {  
                         loadOrchestras0();  
                         saveOrchestras();  
                         return;  
                 }  
                 ///////  
                   
449                  try {                  try {
450                          String s = getJSamplerHome();                          String s = getJSamplerHome();
                         if(s == null) return;  
451                                                    
452                          File f = new File(s + File.separator + "orchestras.xml.bkp");                          File f = new File(s + File.separator + "orchestras.xml.bkp");
453                          if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec");                          if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec");
# Line 372  public class CC { Line 460  public class CC {
460                  } catch(Exception x) {                  } catch(Exception x) {
461                          getLogger().log(Level.INFO, HF.getErrorMessage(x), x);                          getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
462                  }                  }
463                    
464                    getOrchestras().addOrchestraListListener(getHandler());
465          }          }
466                    
467                    
# Line 388  public class CC { Line 478  public class CC {
478                  for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {                  for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {
479                          getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());                          getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());
480                  }                  }
                 getOrchestras().addOrchestraListListener(getHandler());  
         }  
           
         private static void  
         loadOrchestras0() {  
                 String s = Prefs.getOrchestras();  
                 if(s == null) return;  
                   
                 ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());  
                 Document doc = DOMUtils.readObject(bais);  
                   
                 try { getOrchestras().readObject(doc.getDocumentElement()); }  
                 catch(Exception x) { HF.showErrorMessage(x, "Loading orchestras: "); }  
481          }          }
482                    
483          private static void          private static void
# Line 435  public class CC { Line 512  public class CC {
512          }          }
513                    
514          /**          /**
515             * Loads the servers' info described in <code>&lt;jsampler_home&gt;/servers.xml</code>.
516             * If file with name <code>servers.xml.bkp</code> exist in the JSampler's home
517             * directory, this means that the last save has failed. In that case a recovery file
518             * <code>servers.xml.rec</code> is created and a recovery procedure
519             * will be initiated.
520             */
521            public static void
522            loadServerList() {
523                    if(getJSamplerHome() == null) return;
524                    
525                    try {
526                            String s = getJSamplerHome();
527                            
528                            File f = new File(s + File.separator + "servers.xml.bkp");
529                            if(f.isFile()) HF.createBackup("servers.xml.bkp", "servers.xml.rec");
530                            
531                            FileInputStream fis;
532                            fis = new FileInputStream(s + File.separator + "servers.xml");
533                            
534                            loadServerList(fis);
535                            fis.close();
536                    } catch(Exception x) {
537                            getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
538                    }
539                    
540                    getServerList().addChangeListener(serverListListener);
541                    
542                    /* We should have at least one server to connect. */
543                    if(getServerList().getServerCount() == 0) {
544                            Server server = new Server();
545                            server.setName("127.0.0.1:8888");
546                            server.setAddress("127.0.0.1");
547                            server.setPort(8888);
548                            getServerList().addServer(server);
549                    }
550            }
551            
552            
553            private static void
554            loadServerList(InputStream in) {
555                    Document doc = DOMUtils.readObject(in);
556                    
557                    try { getServerList().readObject(doc.getDocumentElement()); }
558                    catch(Exception x) {
559                            HF.showErrorMessage(x, "Loading server list: ");
560                            return;
561                    }
562            }
563            
564            private static void
565            saveServerList() {
566                    try {
567                            String s = getJSamplerHome();
568                            if(s == null) return;
569                            
570                            HF.createBackup("servers.xml", "servers.xml.bkp");
571                            
572                            FileOutputStream fos;
573                            fos = new FileOutputStream(s + File.separator + "servers.xml", false);
574                            
575                            Document doc = DOMUtils.createEmptyDocument();
576                    
577                            Node node = doc.createElement("temp");
578                            doc.appendChild(node);
579                            
580                            getServerList().writeObject(doc, doc.getDocumentElement());
581                            
582                            doc.replaceChild(node.getFirstChild(), node);
583                    
584                            DOMUtils.writeObject(doc, fos);
585                            
586                            fos.close();
587                            
588                            HF.deleteFile("servers.xml.bkp");
589                    } catch(Exception x) {
590                            HF.showErrorMessage(x, "Saving server list: ");
591                            return;
592                    }
593            }
594            
595            /**
596           * The exit point of the application which ensures clean exit with default exit status 0.           * The exit point of the application which ensures clean exit with default exit status 0.
597           *  @see #cleanExit(int i)           *  @see #cleanExit(int i)
598           */           */
# Line 490  public class CC { Line 648  public class CC {
648          getSamplerModel() { return samplerModel; }          getSamplerModel() { return samplerModel; }
649                    
650          /**          /**
651             * Connects to LinuxSampler.
652             */
653            public static void
654            connect() { initSamplerModel(); }
655            
656            /**
657           * Reconnects to LinuxSampler.           * Reconnects to LinuxSampler.
658           */           */
659          public static void          public static void
660          reconnect() {          reconnect() { initSamplerModel(getCurrentServer()); }
661                  initSamplerModel();          
662                  fireReconnectEvent();          private static Server currentServer = null;
         }  
663                    
664          /**          /**
665           * This method updates the information about the backend state.           * Gets the server, to which the frontend is going to connect
666             * or is already connected.
667             */
668            public static Server
669            getCurrentServer() { return currentServer; }
670            
671            /**
672             * Sets the current server.
673           */           */
674          public static void          public static void
675            setCurrentServer(Server server) { currentServer = server; }
676            
677            /**
678             * This method updates the information about the backend state.
679             */
680            private static void
681          initSamplerModel() {          initSamplerModel() {
682                    Server srv = getMainFrame().getServer();
683                    if(srv == null) return;
684                    initSamplerModel(srv);
685            }
686            
687            /**
688             * This method updates the information about the backend state.
689             */
690            private static void
691            initSamplerModel(Server srv) {
692                    setCurrentServer(srv);
693                    final SetServerAddress ssa = new SetServerAddress(srv.getAddress(), srv.getPort());
694                    
695                  final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel();                  final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel();
696                                    
697                  final GetServerInfo gsi = new GetServerInfo();                  final Global.GetServerInfo gsi = new Global.GetServerInfo();
698                  gsi.addTaskListener(new TaskListener() {                  gsi.addTaskListener(new TaskListener() {
699                          public void                          public void
700                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
701                                  if(!gsi.doneWithErrors()) model.setServerInfo(gsi.getResult());                                  if(gsi.doneWithErrors()) return;
702                                    
703                                    model.setServerInfo(gsi.getResult());
704                                    
705                                    if(CC.getViewConfig().getInstrumentsDbSupport()) {
706                                            getInstrumentsDbTreeModel();
707                                    }
708                          }                          }
709                  });                  });
710                                    
# Line 565  public class CC { Line 760  public class CC {
760                  uc.addTaskListener(new TaskListener() {                  uc.addTaskListener(new TaskListener() {
761                          public void                          public void
762                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
763                                  for(SamplerChannelModel c : model.getChannelModels()) {                                  for(SamplerChannelModel c : model.getChannels()) {
764                                          if(c.getChannelInfo().getEngine() == null) continue;                                          if(c.getChannelInfo().getEngine() == null) continue;
765                                                                                    
766                                          Channel.GetFxSends gfs = new Channel.GetFxSends();                                          Channel.GetFxSends gfs = new Channel.GetFxSends();
# Line 573  public class CC { Line 768  public class CC {
768                                          gfs.addTaskListener(new GetFxSendsListener());                                          gfs.addTaskListener(new GetFxSendsListener());
769                                          getTaskQueue().add(gfs);                                          getTaskQueue().add(gfs);
770                                  }                                  }
771                                    
772                                    // TODO: This should be done after the fx sends are set
773                                    //CC.getSamplerModel().setModified(false);
774                          }                          }
775                  });                  });
776                                    
# Line 581  public class CC { Line 779  public class CC {
779                  cnt.addTaskListener(new TaskListener() {                  cnt.addTaskListener(new TaskListener() {
780                          public void                          public void
781                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
782                                  if(cnt.doneWithErrors()) return;                                  if(cnt.doneWithErrors()) {
783                                            setCurrentServer(null);
784                                            retryToConnect();
785                                            return;
786                                    }
787                                                                    
788                                  getTaskQueue().add(gsi);                                  getTaskQueue().add(gsi);
789                                  getTaskQueue().add(gaod);                                  getTaskQueue().add(gaod);
# Line 591  public class CC { Line 793  public class CC {
793                                  getTaskQueue().add(mgim);                                  getTaskQueue().add(mgim);
794                                  getTaskQueue().add(new Midi.UpdateDevices());                                  getTaskQueue().add(new Midi.UpdateDevices());
795                                  getTaskQueue().add(new Audio.UpdateDevices());                                  getTaskQueue().add(new Audio.UpdateDevices());
796                                  getTaskQueue().add(uc);                                  addTask(uc);
797                          }                          }
798                  });                  });
799                  getTaskQueue().add(cnt);                  
800                    ssa.addTaskListener(new TaskListener() {
801                            public void
802                            taskPerformed(TaskEvent e) {
803                                    CC.getTaskQueue().add(cnt);
804                            }
805                    });
806                    
807                    getSamplerModel().reset();
808                    if(instrumentsDbTreeModel != null) {
809                            instrumentsDbTreeModel.reset();
810                            instrumentsDbTreeModel = null;
811                    }
812                    
813                    getTaskQueue().removePendingTasks();
814                    getTaskQueue().add(ssa);
815                    
816                    fireReconnectEvent();
817            }
818            
819            private static void
820            retryToConnect() {
821                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
822                            public void
823                            run() { changeBackend(); }
824                    });
825            }
826            
827            public static void
828            changeBackend() {
829                    Server s = getMainFrame().getServer(true);
830                    if(s != null) initSamplerModel(s);
831          }          }
832                    
833          private static class GetFxSendsListener implements TaskListener {          private static class GetFxSendsListener implements TaskListener {
# Line 602  public class CC { Line 835  public class CC {
835                  taskPerformed(TaskEvent e) {                  taskPerformed(TaskEvent e) {
836                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();
837                          if(gfs.doneWithErrors()) return;                          if(gfs.doneWithErrors()) return;
838                          SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel());                          SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel());
839                          m.removeAllFxSends();                          m.removeAllFxSends();
840                                                    
841                          for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);                          for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);
# Line 653  public class CC { Line 886  public class CC {
886                    
887          public static String          public static String
888          exportSessionToLscpScript() {          exportSessionToLscpScript() {
889                    CC.getSamplerModel().setModified(false);
890                    
891                  StringBuffer sb = new StringBuffer("# Exported by: ");                  StringBuffer sb = new StringBuffer("# Exported by: ");
892                  sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");                  sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
893                  sb.append(JSampler.VERSION).append("\r\n");                  sb.append(JSampler.VERSION).append("\r\n");
# Line 673  public class CC { Line 908  public class CC {
908                          sb.append("\r\n");                          sb.append("\r\n");
909                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }
910                                                                    
911                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels();                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();
912                  for(int i = 0; i < mDevs.length; i++) {                  for(int i = 0; i < mDevs.length; i++) {
913                          exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);                          exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);
914                          sb.append(out.toString());                          sb.append(out.toString());
# Line 681  public class CC { Line 916  public class CC {
916                          sb.append("\r\n");                          sb.append("\r\n");
917                  }                  }
918                                    
919                  AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels();                  AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices();
920                  for(int i = 0; i < aDevs.length; i++) {                  for(int i = 0; i < aDevs.length; i++) {
921                          exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);                          exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);
922                          sb.append(out.toString());                          sb.append(out.toString());
# Line 689  public class CC { Line 924  public class CC {
924                          sb.append("\r\n");                          sb.append("\r\n");
925                  }                  }
926                                    
927                  SamplerChannelModel[] channels = getSamplerModel().getChannelModels();                  exportInstrMapsToLscpScript(lscpClient);
928                    sb.append(out.toString());
929                    out.reset();
930                    sb.append("\r\n");
931                    
932                    SamplerChannelModel[] channels = getSamplerModel().getChannels();
933                                    
934                  for(int i = 0; i < channels.length; i++) {                  for(int i = 0; i < channels.length; i++) {
935                          SamplerChannelModel scm = getSamplerModel().getChannelModel(i);                          SamplerChannelModel scm = channels[i];
936                          exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);                          exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);
937                          sb.append(out.toString());                          sb.append(out.toString());
938                          out.reset();                          out.reset();
# Line 706  public class CC { Line 946  public class CC {
946                          sb.append("\r\n");                          sb.append("\r\n");
947                  }                  }
948                                    
                 exportInstrMapsToLscpScript(lscpClient);  
                 sb.append(out.toString());  
                 out.reset();  
                   
949                  return sb.toString();                  return sb.toString();
950          }          }
951                    
# Line 760  public class CC { Line 996  public class CC {
996                  try {                  try {
997                          lscpCLient.addSamplerChannel();                          lscpCLient.addSamplerChannel();
998                                                    
999                          int i = chn.getMidiInputDevice();                          SamplerModel sm = CC.getSamplerModel();
1000                          if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i);                          int id = chn.getMidiInputDevice();
1001                          lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());                          if(id != -1) {
1002                          lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());                                  for(int i = 0; i < sm.getMidiDeviceCount(); i++) {
1003                                                                    if(sm.getMidiDevice(i).getDeviceId() == id) {
1004                          i = chn.getAudioOutputDevice();                                                  lscpCLient.setChannelMidiInputDevice(chnId, i);
1005                          if(i != -1) {                                                  break;
1006                                  lscpCLient.setChannelAudioOutputDevice(chnId, i);                                          }
1007                                    }
1008                                    lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());
1009                                    lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());
1010                            }
1011                            
1012                            if(chn.getEngine() != null) {
1013                                    lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);
1014                                    lscpCLient.setChannelVolume(chnId, chn.getVolume());
1015                                    int mapId = chn.getMidiInstrumentMapId();
1016                                    lscpCLient.setChannelMidiInstrumentMap(chnId, mapId);
1017                            }
1018                            
1019                            id = chn.getAudioOutputDevice();
1020                            if(id != -1) {
1021                                    for(int i = 0; i < sm.getAudioDeviceCount(); i++) {
1022                                            if(sm.getAudioDevice(i).getDeviceId() == id) {
1023                                                    lscpCLient.setChannelAudioOutputDevice(chnId, i);
1024                                                    break;
1025                                            }
1026                                    }
1027                                    
1028                                  Integer[] routing = chn.getAudioOutputRouting();                                  Integer[] routing = chn.getAudioOutputRouting();
1029                                                                    
1030                                  for(int j = 0; j < routing.length; j++) {                                  for(int j = 0; j < routing.length; j++) {
# Line 778  public class CC { Line 1035  public class CC {
1035                                  }                                  }
1036                          }                          }
1037                                                    
                         if(chn.getEngine() != null) {  
                                 lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);  
                                 lscpCLient.setChannelVolume(chnId, chn.getVolume());  
                         }  
                           
1038                          String s = chn.getInstrumentFile();                          String s = chn.getInstrumentFile();
1039                          i = chn.getInstrumentIndex();                          int i = chn.getInstrumentIndex();
1040                          if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);                          if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);
1041                                                    
1042                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);
# Line 813  public class CC { Line 1065  public class CC {
1065                  }                  }
1066          }          }
1067                    
1068            public static void
1069            scheduleInTaskQueue(final Runnable r) {
1070                    Task dummy = new Global.DummyTask();
1071                    dummy.addTaskListener(new TaskListener() {
1072                            public void
1073                            taskPerformed(TaskEvent e) {
1074                                    javax.swing.SwingUtilities.invokeLater(r);
1075                            }
1076                    });
1077                    
1078                    CC.getTaskQueue().add(dummy);
1079            }
1080            
1081            public static boolean
1082            verifyConnection() {
1083                    if(getCurrentServer() == null) {
1084                            HF.showErrorMessage(i18n.getError("CC.notConnected"));
1085                            return false;
1086                    }
1087                    
1088                    return true;
1089            }
1090            
1091                    
1092          private final static EventHandler eventHandler = new EventHandler();          private final static EventHandler eventHandler = new EventHandler();
1093                    
# Line 821  public class CC { Line 1096  public class CC {
1096                    
1097          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,
1098                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,
1099                  TotalVoiceCountListener, TaskQueueListener, OrchestraListener,                  TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener,
1100                  ListListener<OrchestraModel>, MidiInstrumentCountListener,                  OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener,
1101                  MidiInstrumentInfoListener, GlobalInfoListener {                  MidiInstrumentInfoListener, GlobalInfoListener {
1102                                    
1103                  /** Invoked when the number of channels has changed. */                  /** Invoked when the number of channels has changed. */
1104                  public void                  public void
1105                  channelCountChanged( ChannelCountEvent e) {                  channelCountChanged( ChannelCountEvent e) {
1106                          getTaskQueue().add(new UpdateChannels());                          addTask(new UpdateChannels());
1107                  }                  }
1108                                    
1109                  /** Invoked when changes to the sampler channel has occured. */                  /** Invoked when changes to the sampler channel has occured. */
# Line 890  public class CC { Line 1165  public class CC {
1165                  public void                  public void
1166                  streamCountChanged(StreamCountEvent e) {                  streamCountChanged(StreamCountEvent e) {
1167                          SamplerChannelModel scm =                          SamplerChannelModel scm =
1168                                  getSamplerModel().getChannelModel(e.getSamplerChannel());                                  getSamplerModel().getChannelById(e.getSamplerChannel());
1169                                                    
1170                          if(scm == null) {                          if(scm == null) {
1171                                  CC.getLogger().log (                                  CC.getLogger().log (
# Line 912  public class CC { Line 1187  public class CC {
1187                  public void                  public void
1188                  voiceCountChanged(VoiceCountEvent e) {                  voiceCountChanged(VoiceCountEvent e) {
1189                          SamplerChannelModel scm =                          SamplerChannelModel scm =
1190                                  getSamplerModel().getChannelModel(e.getSamplerChannel());                                  getSamplerModel().getChannelById(e.getSamplerChannel());
1191                                                    
1192                          if(scm == null) {                          if(scm == null) {
1193                                  CC.getLogger().log (                                  CC.getLogger().log (
# Line 927  public class CC { Line 1202  public class CC {
1202                          scm.setVoiceCount(e.getVoiceCount());                          scm.setVoiceCount(e.getVoiceCount());
1203                  }                  }
1204                                    
1205                    /** Invoked when the total number of active streams has changed. */
1206                    public void
1207                    totalStreamCountChanged(TotalStreamCountEvent e) {
1208                            getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount());
1209                    }
1210                    
1211                  /** Invoked when the total number of active voices has changed. */                  /** Invoked when the total number of active voices has changed. */
1212                  public void                  public void
1213                  totalVoiceCountChanged(TotalVoiceCountEvent e) {                  totalVoiceCountChanged(TotalVoiceCountEvent e) {
# Line 936  public class CC { Line 1217  public class CC {
1217                  /** Invoked when the number of MIDI instruments in a MIDI instrument map is changed. */                  /** Invoked when the number of MIDI instruments in a MIDI instrument map is changed. */
1218                  public void                  public void
1219                  instrumentCountChanged(MidiInstrumentCountEvent e) {                  instrumentCountChanged(MidiInstrumentCountEvent e) {
1220                          getTaskQueue().add(new Midi.UpdateInstruments(e.getMapId()));                          scheduleTask(new Midi.UpdateInstruments(e.getMapId()));
1221                  }                  }
1222                                    
1223                  /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */                  /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */
# Line 969  public class CC { Line 1250  public class CC {
1250                                  break;                                  break;
1251                          case TASK_DONE:                          case TASK_DONE:
1252                                  EnhancedTask t = (EnhancedTask)e.getSource();                                  EnhancedTask t = (EnhancedTask)e.getSource();
1253                                  if(t.doneWithErrors() && !t.isStopped())                                  if(t.doneWithErrors() && !t.isStopped()) {
1254                                          HF.showErrorMessage(t.getErrorMessage());                                          showError(t);
1255                                    }
1256                                  break;                                  break;
1257                          case NOT_IDLE:                          case NOT_IDLE:
1258                                  timer.start();                                  timer.start();
# Line 982  public class CC { Line 1264  public class CC {
1264                          }                          }
1265                  }                  }
1266                                    
1267                    private void
1268                    showError(final Task t) {
1269                            javax.swing.SwingUtilities.invokeLater(new Runnable() {
1270                                    public void
1271                                    run() {
1272                                            if(t.getErrorDetails() == null) {
1273                                                    HF.showErrorMessage(t.getErrorMessage());
1274                                            } else {
1275                                                    getMainFrame().showDetailedErrorMessage (
1276                                                            getMainFrame(),
1277                                                            t.getErrorMessage(),
1278                                                            t.getErrorDetails()
1279                                                    );
1280                                            }
1281                                    }
1282                            });
1283                    }
1284                    
1285                  /** Invoked when the name of orchestra is changed. */                  /** Invoked when the name of orchestra is changed. */
1286                  public void                  public void
1287                  nameChanged(OrchestraEvent e) { saveOrchestras(); }                  nameChanged(OrchestraEvent e) { saveOrchestras(); }

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

  ViewVC Help
Powered by ViewVC