/[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 1545 by iliev, Tue Dec 4 18:28:29 2007 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 602  public class CC { Line 642  public class CC {
642                  taskPerformed(TaskEvent e) {                  taskPerformed(TaskEvent e) {
643                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();
644                          if(gfs.doneWithErrors()) return;                          if(gfs.doneWithErrors()) return;
645                          SamplerChannelModel m = getSamplerModel().getChannelModel(gfs.getChannel());                          SamplerChannelModel m = getSamplerModel().getChannelById(gfs.getChannel());
646                          m.removeAllFxSends();                          m.removeAllFxSends();
647                                                    
648                          for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);                          for(FxSend fxs : gfs.getResult()) m.addFxSend(fxs);
# Line 673  public class CC { Line 713  public class CC {
713                          sb.append("\r\n");                          sb.append("\r\n");
714                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }
715                                                                    
716                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDeviceModels();                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();
717                  for(int i = 0; i < mDevs.length; i++) {                  for(int i = 0; i < mDevs.length; i++) {
718                          exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);                          exportMidiDeviceToLscpScript(mDevs[i].getDeviceInfo(), i, lscpClient);
719                          sb.append(out.toString());                          sb.append(out.toString());
# Line 681  public class CC { Line 721  public class CC {
721                          sb.append("\r\n");                          sb.append("\r\n");
722                  }                  }
723                                    
724                  AudioDeviceModel[] aDevs = getSamplerModel().getAudioDeviceModels();                  AudioDeviceModel[] aDevs = getSamplerModel().getAudioDevices();
725                  for(int i = 0; i < aDevs.length; i++) {                  for(int i = 0; i < aDevs.length; i++) {
726                          exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);                          exportAudioDeviceToLscpScript(aDevs[i].getDeviceInfo(), i, lscpClient);
727                          sb.append(out.toString());                          sb.append(out.toString());
# Line 689  public class CC { Line 729  public class CC {
729                          sb.append("\r\n");                          sb.append("\r\n");
730                  }                  }
731                                    
732                  SamplerChannelModel[] channels = getSamplerModel().getChannelModels();                  SamplerChannelModel[] channels = getSamplerModel().getChannels();
733                                    
734                  for(int i = 0; i < channels.length; i++) {                  for(int i = 0; i < channels.length; i++) {
735                          SamplerChannelModel scm = getSamplerModel().getChannelModel(i);                          SamplerChannelModel scm = channels[i];
736                          exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);                          exportChannelToLscpScript(scm.getChannelInfo(), i, lscpClient);
737                          sb.append(out.toString());                          sb.append(out.toString());
738                          out.reset();                          out.reset();
# Line 760  public class CC { Line 800  public class CC {
800                  try {                  try {
801                          lscpCLient.addSamplerChannel();                          lscpCLient.addSamplerChannel();
802                                                    
803                          int i = chn.getMidiInputDevice();                          SamplerModel sm = CC.getSamplerModel();
804                          if(i != -1) lscpCLient.setChannelMidiInputDevice(chnId, i);                          int id = chn.getMidiInputDevice();
805                          lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());                          if(id != -1) {
806                          lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());                                  for(int i = 0; i < sm.getMidiDeviceCount(); i++) {
807                                                                    if(sm.getMidiDevice(i).getDeviceId() == id) {
808                          i = chn.getAudioOutputDevice();                                                  lscpCLient.setChannelMidiInputDevice(chnId, i);
809                          if(i != -1) {                                                  break;
810                                  lscpCLient.setChannelAudioOutputDevice(chnId, i);                                          }
811                                    }
812                                    lscpCLient.setChannelMidiInputPort(chnId, chn.getMidiInputPort());
813                                    lscpCLient.setChannelMidiInputChannel(chnId, chn.getMidiInputChannel());
814                            }
815                            
816                            id = chn.getAudioOutputDevice();
817                            if(id != -1) {
818                                    for(int i = 0; i < sm.getAudioDeviceCount(); i++) {
819                                            if(sm.getAudioDevice(i).getDeviceId() == id) {
820                                                    lscpCLient.setChannelAudioOutputDevice(chnId, i);
821                                                    break;
822                                            }
823                                    }
824                                    
825                                  Integer[] routing = chn.getAudioOutputRouting();                                  Integer[] routing = chn.getAudioOutputRouting();
826                                                                    
827                                  for(int j = 0; j < routing.length; j++) {                                  for(int j = 0; j < routing.length; j++) {
# Line 784  public class CC { Line 838  public class CC {
838                          }                          }
839                                                    
840                          String s = chn.getInstrumentFile();                          String s = chn.getInstrumentFile();
841                          i = chn.getInstrumentIndex();                          int i = chn.getInstrumentIndex();
842                          if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);                          if(s != null) lscpCLient.loadInstrument(s, i, chnId, true);
843                                                    
844                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);
# Line 821  public class CC { Line 875  public class CC {
875                    
876          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,          private static class EventHandler implements ChannelCountListener, ChannelInfoListener,
877                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,
878                  TotalVoiceCountListener, TaskQueueListener, OrchestraListener,                  TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener,
879                  ListListener<OrchestraModel>, MidiInstrumentCountListener,                  OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener,
880                  MidiInstrumentInfoListener, GlobalInfoListener {                  MidiInstrumentInfoListener, GlobalInfoListener {
881                                    
882                  /** Invoked when the number of channels has changed. */                  /** Invoked when the number of channels has changed. */
# Line 890  public class CC { Line 944  public class CC {
944                  public void                  public void
945                  streamCountChanged(StreamCountEvent e) {                  streamCountChanged(StreamCountEvent e) {
946                          SamplerChannelModel scm =                          SamplerChannelModel scm =
947                                  getSamplerModel().getChannelModel(e.getSamplerChannel());                                  getSamplerModel().getChannelById(e.getSamplerChannel());
948                                                    
949                          if(scm == null) {                          if(scm == null) {
950                                  CC.getLogger().log (                                  CC.getLogger().log (
# Line 912  public class CC { Line 966  public class CC {
966                  public void                  public void
967                  voiceCountChanged(VoiceCountEvent e) {                  voiceCountChanged(VoiceCountEvent e) {
968                          SamplerChannelModel scm =                          SamplerChannelModel scm =
969                                  getSamplerModel().getChannelModel(e.getSamplerChannel());                                  getSamplerModel().getChannelById(e.getSamplerChannel());
970                                                    
971                          if(scm == null) {                          if(scm == null) {
972                                  CC.getLogger().log (                                  CC.getLogger().log (
# Line 927  public class CC { Line 981  public class CC {
981                          scm.setVoiceCount(e.getVoiceCount());                          scm.setVoiceCount(e.getVoiceCount());
982                  }                  }
983                                    
984                    /** Invoked when the total number of active streams has changed. */
985                    public void
986                    totalStreamCountChanged(TotalStreamCountEvent e) {
987                            getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount());
988                    }
989                    
990                  /** Invoked when the total number of active voices has changed. */                  /** Invoked when the total number of active voices has changed. */
991                  public void                  public void
992                  totalVoiceCountChanged(TotalVoiceCountEvent e) {                  totalVoiceCountChanged(TotalVoiceCountEvent e) {
# Line 969  public class CC { Line 1029  public class CC {
1029                                  break;                                  break;
1030                          case TASK_DONE:                          case TASK_DONE:
1031                                  EnhancedTask t = (EnhancedTask)e.getSource();                                  EnhancedTask t = (EnhancedTask)e.getSource();
1032                                  if(t.doneWithErrors() && !t.isStopped())                                  if(t.doneWithErrors() && !t.isStopped()) {
1033                                          HF.showErrorMessage(t.getErrorMessage());                                          showError(t);
1034                                    }
1035                                  break;                                  break;
1036                          case NOT_IDLE:                          case NOT_IDLE:
1037                                  timer.start();                                  timer.start();
# Line 982  public class CC { Line 1043  public class CC {
1043                          }                          }
1044                  }                  }
1045                                    
1046                    private void
1047                    showError(final Task t) {
1048                            javax.swing.SwingUtilities.invokeLater(new Runnable() {
1049                                    public void
1050                                    run() {
1051                                            if(t.getErrorDetails() == null) {
1052                                                    HF.showErrorMessage(t.getErrorMessage());
1053                                            } else {
1054                                                    getMainFrame().showDetailedErrorMessage (
1055                                                            getMainFrame(),
1056                                                            t.getErrorMessage(),
1057                                                            t.getErrorDetails()
1058                                                    );
1059                                            }
1060                                    }
1061                            });
1062                    }
1063                    
1064                  /** Invoked when the name of orchestra is changed. */                  /** Invoked when the name of orchestra is changed. */
1065                  public void                  public void
1066                  nameChanged(OrchestraEvent e) { saveOrchestras(); }                  nameChanged(OrchestraEvent e) { saveOrchestras(); }

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

  ViewVC Help
Powered by ViewVC