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

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

  ViewVC Help
Powered by ViewVC