/[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 1670 by iliev, Tue Feb 5 23:17:27 2008 UTC
# Line 59  import org.jsampler.task.*; Line 59  import org.jsampler.task.*;
59    
60  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
61  import org.jsampler.view.JSProgress;  import org.jsampler.view.JSProgress;
62    import org.jsampler.view.JSViewConfig;
63    import org.jsampler.view.InstrumentsDbTreeModel;
64    
65  import org.linuxsampler.lscp.AudioOutputChannel;  import org.linuxsampler.lscp.AudioOutputChannel;
66  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
# Line 86  public class CC { Line 88  public class CC {
88          private static Handler handler;          private static Handler handler;
89          private static FileOutputStream fos;          private static FileOutputStream fos;
90                    
91            private static JSViewConfig viewConfig = null;
92          private static JSMainFrame mainFrame = null;          private static JSMainFrame mainFrame = null;
93          private static JSProgress progress = null;          private static JSProgress progress = null;
94                    
# Line 122  public class CC { Line 125  public class CC {
125          getTaskQueue() { return taskQueue; }          getTaskQueue() { return taskQueue; }
126                    
127          /**          /**
128             * Adds the specified task to the task queue. All task in the
129             * queue equal to the specified task are removed from the queue.
130             */
131            public static void
132            scheduleTask(Task t) {
133                    while(getTaskQueue().removeTask(t)) { }
134                    
135                    if(getTaskQueue().getPendingTaskCount() == 0) {
136                            if(t.equals(getTaskQueue().getRunningTask())) return;
137                    }
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            /**
149             * Sets the configuration of the current view.
150             */
151            public static void
152            setViewConfig(JSViewConfig viewConfig) { CC.viewConfig = viewConfig; }
153            
154            /**
155           * Returns the main window of this application.           * Returns the main window of this application.
156           * @return The main window of this application.           * @return The main window of this application.
157           */           */
# Line 190  public class CC { Line 220  public class CC {
220                  handler.setLevel(Level.FINE);                  handler.setLevel(Level.FINE);
221                  getLogger().addHandler(handler);                  getLogger().addHandler(handler);
222                  getLogger().setLevel(Level.FINE);                  getLogger().setLevel(Level.FINE);
                 Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);  
223                  Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE);                  Logger.getLogger("org.linuxsampler.lscp").setLevel(Level.FINE);
224                    Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
225                                    
226                  // Flushing logs on every second                  // Flushing logs on every second
227                  new java.util.Timer().schedule(new java.util.TimerTask() {                  new java.util.Timer().schedule(new java.util.TimerTask() {
# 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 static InstrumentsDbTreeModel instrumentsDbTreeModel = null;
376            /**
377             * Gets the tree model of the instruments database.
378             * If the currently used view doesn't have instruments
379             * database support the tree model is initialized on first use.
380             * @return The tree model of the instruments database or
381             * <code>null</code> if the backend doesn't have instruments database support.
382             * @see org.jsampler.view.JSViewConfig#getInstrumentsDbSupport
383             */
384            public static InstrumentsDbTreeModel
385            getInstrumentsDbTreeModel() {
386                    if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null;
387                    
388                    if(instrumentsDbTreeModel == null) {
389                            instrumentsDbTreeModel = new InstrumentsDbTreeModel();
390                    }
391                    
392                    return instrumentsDbTreeModel;
393            }
394            
395          /**          /**
396           * 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>.
397           * 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 403  public class CC {
403          loadOrchestras() {          loadOrchestras() {
404                  if(getJSamplerHome() == null) return;                  if(getJSamplerHome() == null) return;
405                                    
                 //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;  
                 }  
                 ///////  
                   
406                  try {                  try {
407                          String s = getJSamplerHome();                          String s = getJSamplerHome();
408                          if(s == null) return;                          if(s == null) return;
409                            getOrchestras().addOrchestraListListener(getHandler());
410                                                    
411                          File f = new File(s + File.separator + "orchestras.xml.bkp");                          File f = new File(s + File.separator + "orchestras.xml.bkp");
412                          if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec");                          if(f.isFile()) HF.createBackup("orchestras.xml.bkp", "orchestras.xml.rec");
# Line 388  public class CC { Line 435  public class CC {
435                  for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {                  for(int i = 0; i < getOrchestras().getOrchestraCount(); i++) {
436                          getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());                          getOrchestras().getOrchestra(i).addOrchestraListener(getHandler());
437                  }                  }
                 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: "); }  
438          }          }
439                    
440          private static void          private static void
# Line 505  public class CC { Line 539  public class CC {
539          initSamplerModel() {          initSamplerModel() {
540                  final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel();                  final DefaultSamplerModel model = (DefaultSamplerModel)getSamplerModel();
541                                    
542                  final GetServerInfo gsi = new GetServerInfo();                  final Global.GetServerInfo gsi = new Global.GetServerInfo();
543                  gsi.addTaskListener(new TaskListener() {                  gsi.addTaskListener(new TaskListener() {
544                          public void                          public void
545                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
546                                  if(!gsi.doneWithErrors()) model.setServerInfo(gsi.getResult());                                  if(gsi.doneWithErrors()) return;
547                                    
548                                    model.setServerInfo(gsi.getResult());
549                                    
550                                    if(CC.getViewConfig().getInstrumentsDbSupport()) {
551                                            getInstrumentsDbTreeModel();
552                                    }
553                          }                          }
554                  });                  });
555                                    
# Line 565  public class CC { Line 605  public class CC {
605                  uc.addTaskListener(new TaskListener() {                  uc.addTaskListener(new TaskListener() {
606                          public void                          public void
607                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
608                                  for(SamplerChannelModel c : model.getChannelModels()) {                                  for(SamplerChannelModel c : model.getChannels()) {
609                                          if(c.getChannelInfo().getEngine() == null) continue;                                          if(c.getChannelInfo().getEngine() == null) continue;
610                                                                                    
611                                          Channel.GetFxSends gfs = new Channel.GetFxSends();                                          Channel.GetFxSends gfs = new Channel.GetFxSends();
# Line 573  public class CC { Line 613  public class CC {
613                                          gfs.addTaskListener(new GetFxSendsListener());                                          gfs.addTaskListener(new GetFxSendsListener());
614                                          getTaskQueue().add(gfs);                                          getTaskQueue().add(gfs);
615                                  }                                  }
616                                    
617                                    // TODO: This should be done after the fx sends are set
618                                    //CC.getSamplerModel().setModified(false);
619                          }                          }
620                  });                  });
621                                    
# Line 602  public class CC { Line 645  public class CC {
645                  taskPerformed(TaskEvent e) {                  taskPerformed(TaskEvent e) {
646                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();
647                          if(gfs.doneWithErrors()) return;                          if(gfs.doneWithErrors()) return;
648                          SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel());                          SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel());
649                          m.removeAllFxSends();                          m.removeAllFxSends();
650                                                    
651                          for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);                          for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);
# Line 653  public class CC { Line 696  public class CC {
696                    
697          public static String          public static String
698          exportSessionToLscpScript() {          exportSessionToLscpScript() {
699                    CC.getSamplerModel().setModified(false);
700                    
701                  StringBuffer sb = new StringBuffer("# Exported by: ");                  StringBuffer sb = new StringBuffer("# Exported by: ");
702                  sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");                  sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
703                  sb.append(JSampler.VERSION).append("\r\n");                  sb.append(JSampler.VERSION).append("\r\n");
# Line 673  public class CC { Line 718  public class CC {
718                          sb.append("\r\n");                          sb.append("\r\n");
719                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }
720                                                                    
721                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels();                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();
722                  for(int i = 0; i < mDevs.length; i++) {                  for(int i = 0; i < mDevs.length; i++) {
723                          exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);                          exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);
724                          sb.append(out.toString());                          sb.append(out.toString());
# Line 681  public class CC { Line 726  public class CC {
726                          sb.append("\r\n");                          sb.append("\r\n");
727                  }                  }
728                                    
729                  AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels();                  AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices();
730                  for(int i = 0; i < aDevs.length; i++) {                  for(int i = 0; i < aDevs.length; i++) {
731                          exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);                          exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);
732                          sb.append(out.toString());                          sb.append(out.toString());
# Line 689  public class CC { Line 734  public class CC {
734                          sb.append("\r\n");                          sb.append("\r\n");
735                  }                  }
736                                    
737                  SamplerChannelModel[] channels = getSamplerModel().getChannelModels();                  SamplerChannelModel[] channels = getSamplerModel().getChannels();
738                                    
739                  for(int i = 0; i < channels.length; i++) {                  for(int i = 0; i < channels.length; i++) {
740                          SamplerChannelModel scm = getSamplerModel().getChannelModel(i);                          SamplerChannelModel scm = channels[i];
741                          exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);                          exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);
742                          sb.append(out.toString());                          sb.append(out.toString());
743                          out.reset();                          out.reset();
# Line 760  public class CC { Line 805  public class CC {
805                  try {                  try {
806                          lscpCLient.addSamplerChannel();                          lscpCLient.addSamplerChannel();
807                                                    
808                          int i = chn.getMidiInputDevice();                          SamplerModel sm = CC.getSamplerModel();
809                          if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i);                          int id = chn.getMidiInputDevice();
810                          lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());                          if(id != -1) {
811                          lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());                                  for(int i = 0; i < sm.getMidiDeviceCount(); i++) {
812                                                                    if(sm.getMidiDevice(i).getDeviceId() == id) {
813                          i = chn.getAudioOutputDevice();                                                  lscpCLient.setChannelMidiInputDevice(chnId, i);
814                          if(i != -1) {                                                  break;
815                                  lscpCLient.setChannelAudioOutputDevice(chnId, i);                                          }
816                                    }
817                                    lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());
818                                    lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());
819                            }
820                            
821                            if(chn.getEngine() != null) {
822                                    lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);
823                                    lscpCLient.setChannelVolume(chnId, chn.getVolume());
824                            }
825                            
826                            id = chn.getAudioOutputDevice();
827                            if(id != -1) {
828                                    for(int i = 0; i < sm.getAudioDeviceCount(); i++) {
829                                            if(sm.getAudioDevice(i).getDeviceId() == id) {
830                                                    lscpCLient.setChannelAudioOutputDevice(chnId, i);
831                                                    break;
832                                            }
833                                    }
834                                    
835                                  Integer[] routing = chn.getAudioOutputRouting();                                  Integer[] routing = chn.getAudioOutputRouting();
836                                                                    
837                                  for(int j = 0; j < routing.length; j++) {                                  for(int j = 0; j < routing.length; j++) {
# Line 778  public class CC { Line 842  public class CC {
842                                  }                                  }
843                          }                          }
844                                                    
                         if(chn.getEngine() != null) {  
                                 lscpCLient.loadSamplerEngine(chn.getEngine().getName(), chnId);  
                                 lscpCLient.setChannelVolume(chnId, chn.getVolume());  
                         }  
                           
845                          String s = chn.getInstrumentFile();                          String s = chn.getInstrumentFile();
846                          i = chn.getInstrumentIndex();                          int i = chn.getInstrumentIndex();
847                          if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);                          if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);
848                                                    
849                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);
# Line 821  public class CC { Line 880  public class CC {
880                    
881          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,
882                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,
883                  TotalVoiceCountListener, TaskQueueListener, OrchestraListener,                  TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener,
884                  ListListener<OrchestraModel>, MidiInstrumentCountListener,                  OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener,
885                  MidiInstrumentInfoListener, GlobalInfoListener {                  MidiInstrumentInfoListener, GlobalInfoListener {
886                                    
887                  /** Invoked when the number of channels has changed. */                  /** Invoked when the number of channels has changed. */
# Line 890  public class CC { Line 949  public class CC {
949                  public void                  public void
950                  streamCountChanged(StreamCountEvent e) {                  streamCountChanged(StreamCountEvent e) {
951                          SamplerChannelModel scm =                          SamplerChannelModel scm =
952                                  getSamplerModel().getChannelModel(e.getSamplerChannel());                                  getSamplerModel().getChannelById(e.getSamplerChannel());
953                                                    
954                          if(scm == null) {                          if(scm == null) {
955                                  CC.getLogger().log (                                  CC.getLogger().log (
# Line 912  public class CC { Line 971  public class CC {
971                  public void                  public void
972                  voiceCountChanged(VoiceCountEvent e) {                  voiceCountChanged(VoiceCountEvent e) {
973                          SamplerChannelModel scm =                          SamplerChannelModel scm =
974                                  getSamplerModel().getChannelModel(e.getSamplerChannel());                                  getSamplerModel().getChannelById(e.getSamplerChannel());
975                                                    
976                          if(scm == null) {                          if(scm == null) {
977                                  CC.getLogger().log (                                  CC.getLogger().log (
# Line 927  public class CC { Line 986  public class CC {
986                          scm.setVoiceCount(e.getVoiceCount());                          scm.setVoiceCount(e.getVoiceCount());
987                  }                  }
988                                    
989                    /** Invoked when the total number of active streams has changed. */
990                    public void
991                    totalStreamCountChanged(TotalStreamCountEvent e) {
992                            getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount());
993                    }
994                    
995                  /** Invoked when the total number of active voices has changed. */                  /** Invoked when the total number of active voices has changed. */
996                  public void                  public void
997                  totalVoiceCountChanged(TotalVoiceCountEvent e) {                  totalVoiceCountChanged(TotalVoiceCountEvent e) {
# Line 969  public class CC { Line 1034  public class CC {
1034                                  break;                                  break;
1035                          case TASK_DONE:                          case TASK_DONE:
1036                                  EnhancedTask t = (EnhancedTask)e.getSource();                                  EnhancedTask t = (EnhancedTask)e.getSource();
1037                                  if(t.doneWithErrors() && !t.isStopped())                                  if(t.doneWithErrors() && !t.isStopped()) {
1038                                          HF.showErrorMessage(t.getErrorMessage());                                          showError(t);
1039                                    }
1040                                  break;                                  break;
1041                          case NOT_IDLE:                          case NOT_IDLE:
1042                                  timer.start();                                  timer.start();
# Line 982  public class CC { Line 1048  public class CC {
1048                          }                          }
1049                  }                  }
1050                                    
1051                    private void
1052                    showError(final Task t) {
1053                            javax.swing.SwingUtilities.invokeLater(new Runnable() {
1054                                    public void
1055                                    run() {
1056                                            if(t.getErrorDetails() == null) {
1057                                                    HF.showErrorMessage(t.getErrorMessage());
1058                                            } else {
1059                                                    getMainFrame().showDetailedErrorMessage (
1060                                                            getMainFrame(),
1061                                                            t.getErrorMessage(),
1062                                                            t.getErrorDetails()
1063                                                    );
1064                                            }
1065                                    }
1066                            });
1067                    }
1068                    
1069                  /** Invoked when the name of orchestra is changed. */                  /** Invoked when the name of orchestra is changed. */
1070                  public void                  public void
1071                  nameChanged(OrchestraEvent e) { saveOrchestras(); }                  nameChanged(OrchestraEvent e) { saveOrchestras(); }

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

  ViewVC Help
Powered by ViewVC