/[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 1729 by iliev, Tue Apr 29 22:22:40 2008 UTC revision 1786 by iliev, Wed Oct 8 22:38:15 2008 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 25  package org.jsampler; Line 25  package org.jsampler;
25  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
27    
 import java.io.ByteArrayInputStream;  
28  import java.io.ByteArrayOutputStream;  import java.io.ByteArrayOutputStream;
29  import java.io.File;  import java.io.File;
30  import java.io.FileInputStream;  import java.io.FileInputStream;
# Line 40  import java.util.logging.Logger; Line 39  import java.util.logging.Logger;
39  import java.util.logging.SimpleFormatter;  import java.util.logging.SimpleFormatter;
40  import java.util.logging.StreamHandler;  import java.util.logging.StreamHandler;
41    
42    import javax.swing.SwingUtilities;
43  import javax.swing.Timer;  import javax.swing.Timer;
44    
45  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
# Line 80  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;
 import static org.jsampler.JSPrefs.MANUAL_SERVER_SELECT_ON_STARTUP;  
83    
84    
85  /**  /**
# Line 103  public class CC { Line 102  public class CC {
102          private final static TaskQueue taskQueue = new TaskQueue();          private final static TaskQueue taskQueue = new TaskQueue();
103          private final static Timer timer = new Timer(2000, null);          private final static Timer timer = new Timer(2000, null);
104                    
105            private static int connectionFailureCount = 0;
106            
107          /** Forbits the instantiation of this class. */          /** Forbits the instantiation of this class. */
108          private          private
109          CC() { }          CC() { }
# Line 140  public class CC { Line 141  public class CC {
141          }          }
142                    
143          /**          /**
144             * Adds the specified task to the task queue only if the last
145             * task in the is not equal to <code>t</code>.
146             */
147            public static void
148            addTask(Task t) {
149                    Task[] tasks = getTaskQueue().getPendingTasks();
150                    if(tasks.length > 0 && tasks[tasks.length - 1].equals(t)) return;
151                    getTaskQueue().add(t);
152            }
153            
154            /**
155           * Gets the configuration of the current view.           * Gets the configuration of the current view.
156           */           */
157          public static JSViewConfig          public static JSViewConfig
158          getViewConfig() { return viewConfig; }          getViewConfig() { return viewConfig; }
159                    
160          private static JSPrefs          public static JSPrefs
161          preferences() { return getViewConfig().preferences(); }          preferences() { return getViewConfig().preferences(); }
162                    
163          /**          /**
# Line 232  public class CC { Line 244  public class CC {
244                          run() { if(handler != null) handler.flush(); }                          run() { if(handler != null) handler.flush(); }
245                  }, 1000, 1000);                  }, 1000, 1000);
246                                    
247                  CC.getLogger().fine("CC.jsStarted");                  getLogger().fine("CC.jsStarted");
248                                    
249                  HF.setUIDefaultFont(Prefs.getInterfaceFont());                  HF.setUIDefaultFont(Prefs.getInterfaceFont());
250                                    
# Line 297  public class CC { Line 309  public class CC {
309                                    
310                  getClient().removeGlobalInfoListener(getHandler());                  getClient().removeGlobalInfoListener(getHandler());
311                  getClient().addGlobalInfoListener(getHandler());                  getClient().addGlobalInfoListener(getHandler());
312                    
313                    getClient().removeChannelMidiDataListener(getHandler());
314                    getClient().addChannelMidiDataListener(getHandler());
315                    
316                    CC.addConnectionEstablishedListener(new ActionListener() {
317                            public void
318                            actionPerformed(ActionEvent e) {
319                                    connectionFailureCount = 0;
320                            }
321                    });
322          }          }
323                    
324          /**          /**
# Line 315  public class CC { Line 337  public class CC {
337                          }                          }
338                  }                  }
339                                    
340                  CC.getMainFrame().installJSamplerHome();                  getMainFrame().installJSamplerHome();
341          }          }
342                    
343          /**          /**
# Line 381  public class CC { Line 403  public class CC {
403          private static ServerListListener serverListListener = new ServerListListener();          private static ServerListListener serverListListener = new ServerListListener();
404                    
405          private static class ServerListListener implements ChangeListener {          private static class ServerListListener implements ChangeListener {
406                    @Override
407                  public void                  public void
408                  stateChanged(ChangeEvent e) {                  stateChanged(ChangeEvent e) {
409                          saveServerList();                          saveServerList();
# Line 400  public class CC { Line 423  public class CC {
423           */           */
424          public static InstrumentsDbTreeModel          public static InstrumentsDbTreeModel
425          getInstrumentsDbTreeModel() {          getInstrumentsDbTreeModel() {
426                  if(CC.getSamplerModel().getServerInfo() == null) return null;                  if(getSamplerModel().getServerInfo() == null) return null;
427                  if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null;                  if(!getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) return null;
428                                    
429                  if(instrumentsDbTreeModel == null) {                  if(instrumentsDbTreeModel == null) {
430                          instrumentsDbTreeModel = new InstrumentsDbTreeModel();                          instrumentsDbTreeModel = new InstrumentsDbTreeModel();
# Line 479  public class CC { Line 502  public class CC {
502                                                    
503                          HF.createBackup("orchestras.xml", "orchestras.xml.bkp");                          HF.createBackup("orchestras.xml", "orchestras.xml.bkp");
504                                                    
505                          FileOutputStream fos;                          FileOutputStream fos2;
506                          fos = new FileOutputStream(s + File.separator + "orchestras.xml", false);                          fos2 = new FileOutputStream(s + File.separator + "orchestras.xml", false);
507                                                    
508                          Document doc = DOMUtils.createEmptyDocument();                          Document doc = DOMUtils.createEmptyDocument();
509                                    
# Line 491  public class CC { Line 514  public class CC {
514                                                    
515                          doc.replaceChild(node.getFirstChild(), node);                          doc.replaceChild(node.getFirstChild(), node);
516                                    
517                          DOMUtils.writeObject(doc, fos);                          DOMUtils.writeObject(doc, fos2);
518                                                    
519                          fos.close();                          fos2.close();
520                                                    
521                          HF.deleteFile("orchestras.xml.bkp");                          HF.deleteFile("orchestras.xml.bkp");
522                  } catch(Exception x) {                  } catch(Exception x) {
# Line 560  public class CC { Line 583  public class CC {
583                                                    
584                          HF.createBackup("servers.xml", "servers.xml.bkp");                          HF.createBackup("servers.xml", "servers.xml.bkp");
585                                                    
586                          FileOutputStream fos;                          FileOutputStream fos2;
587                          fos = new FileOutputStream(s + File.separator + "servers.xml", false);                          fos2 = new FileOutputStream(s + File.separator + "servers.xml", false);
588                                                    
589                          Document doc = DOMUtils.createEmptyDocument();                          Document doc = DOMUtils.createEmptyDocument();
590                                    
# Line 572  public class CC { Line 595  public class CC {
595                                                    
596                          doc.replaceChild(node.getFirstChild(), node);                          doc.replaceChild(node.getFirstChild(), node);
597                                    
598                          DOMUtils.writeObject(doc, fos);                          DOMUtils.writeObject(doc, fos2);
599                                                    
600                          fos.close();                          fos2.close();
601                                                    
602                          HF.deleteFile("servers.xml.bkp");                          HF.deleteFile("servers.xml.bkp");
603                  } catch(Exception x) {                  } catch(Exception x) {
# Line 596  public class CC { Line 619  public class CC {
619           */           */
620          public static void          public static void
621          cleanExit(int i) {          cleanExit(int i) {
622                  CC.getLogger().fine("CC.jsEnded");                  getLogger().fine("CC.jsEnded");
623                    try { getClient().disconnect(); } // FIXME: this might block the EDT
624                    catch(Exception x) { x.printStackTrace(); }
625                    if(backendProcess != null) backendProcess.destroy();
626                    backendProcess = null;
627                    fireBackendProcessEvent();
628                  System.exit(i);                  System.exit(i);
629          }          }
630                    
# Line 629  public class CC { Line 657  public class CC {
657                  for(ActionListener l : listeners) l.actionPerformed(e);                  for(ActionListener l : listeners) l.actionPerformed(e);
658          }          }
659                    
660            private static final Vector<ActionListener> ceListeners = new Vector<ActionListener>();
661            
662            /**
663             * Registers the specified listener to be notified when
664             * jsampler is connected successfully to LinuxSampler.
665             * @param l The <code>ActionListener</code> to register.
666             */
667            public static void
668            addConnectionEstablishedListener(ActionListener l) { ceListeners.add(l); }
669            
670            /**
671             * Removes the specified listener.
672             * @param l The <code>ActionListener</code> to remove.
673             */
674            public static void
675            removeConnectionEstablishedListener(ActionListener l) { ceListeners.remove(l); }
676            
677            private static void
678            fireConnectionEstablishedEvent() {
679                    ActionEvent e = new ActionEvent(CC.class, ActionEvent.ACTION_PERFORMED, null);
680                    for(ActionListener l : ceListeners) l.actionPerformed(e);
681            }
682            
683          private static final SamplerModel samplerModel = new DefaultSamplerModel();          private static final SamplerModel samplerModel = new DefaultSamplerModel();
684                    
685          /**          /**
# Line 663  public class CC { Line 714  public class CC {
714           * Sets the current server.           * Sets the current server.
715           */           */
716          public static void          public static void
717          setCurrentServer(Server server) { currentServer = server; }          setCurrentServer(Server server) {
718                    if(server == currentServer) return;
719                    connectionFailureCount = 0;
720                    currentServer = server;
721            }
722            
723            /**
724             * Sets the LSCP client's read timeout.
725             * @param timeout The new timeout value (in seconds).
726             */
727            public static void
728            setClientReadTimeout(int timeout) {
729                    getTaskQueue().add(new Global.SetClientReadTimeout(timeout));
730            }
731                    
732          /**          /**
733           * This method updates the information about the backend state.           * This method updates the information about the backend state.
# Line 767  public class CC { Line 831  public class CC {
831                                    
832                                    
833                  final Connect cnt = new Connect();                  final Connect cnt = new Connect();
834                    boolean b = preferences().getBoolProperty(JSPrefs.LAUNCH_BACKEND_LOCALLY);
835                    if(b && srv.isLocal() && backendProcess == null) cnt.setSilent(true);
836                  cnt.addTaskListener(new TaskListener() {                  cnt.addTaskListener(new TaskListener() {
837                          public void                          public void
838                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
839                                  if(cnt.doneWithErrors()) {                                  if(cnt.doneWithErrors()) {
840                                          setCurrentServer(null);                                          onConnectFailure();
                                         retryToConnect();  
841                                          return;                                          return;
842                                  }                                  }
843                                                                    
# Line 784  public class CC { Line 849  public class CC {
849                                  getTaskQueue().add(mgim);                                  getTaskQueue().add(mgim);
850                                  getTaskQueue().add(new Midi.UpdateDevices());                                  getTaskQueue().add(new Midi.UpdateDevices());
851                                  getTaskQueue().add(new Audio.UpdateDevices());                                  getTaskQueue().add(new Audio.UpdateDevices());
852                                  getTaskQueue().add(uc);                                  addTask(uc);
853                                    
854                                    fireConnectionEstablishedEvent();
855                          }                          }
856                  });                  });
857                                    
858                  ssa.addTaskListener(new TaskListener() {                  ssa.addTaskListener(new TaskListener() {
859                          public void                          public void
860                          taskPerformed(TaskEvent e) {                          taskPerformed(TaskEvent e) {
861                                    int t = preferences().getIntProperty(JSPrefs.SOCKET_READ_TIMEOUT);
862                                    CC.setClientReadTimeout(t * 1000);
863                                  CC.getTaskQueue().add(cnt);                                  CC.getTaskQueue().add(cnt);
864                          }                          }
865                  });                  });
# Line 808  public class CC { Line 877  public class CC {
877          }          }
878                    
879          private static void          private static void
880            onConnectFailure() {
881                    connectionFailureCount++;
882                    if(connectionFailureCount > 50) { // to prevent eventual infinite loop
883                            getLogger().warning("Reached maximum number of connection failures");
884                            return;
885                    }
886                    
887                    try {
888                            if(launchBackend()) {
889                                    int i = preferences().getIntProperty(JSPrefs.BACKEND_LAUNCH_DELAY);
890                                    if(i < 1) {
891                                            initSamplerModel(getCurrentServer());
892                                            return;
893                                    }
894                                    
895                                    LaunchBackend lb = new LaunchBackend(i, getBackendMonitor());
896                                    //CC.getTaskQueue().add(lb);
897                                    new Thread(lb).start();
898                                    return;
899                            }
900                    } catch(Exception x) {
901                            final String s = JSI18n.i18n.getError("CC.failedToLaunchBackend");
902                            CC.getLogger().log(Level.INFO, s, x);
903                            
904                            SwingUtilities.invokeLater(new Runnable() {
905                                    public void
906                                    run() { HF.showErrorMessage(s); }
907                            });
908                            return;
909                    }
910                    
911                    retryToConnect();
912            }
913            
914            private static void
915          retryToConnect() {          retryToConnect() {
916                  javax.swing.SwingUtilities.invokeLater(new Runnable() {                  javax.swing.SwingUtilities.invokeLater(new Runnable() {
917                          public void                          public void
# Line 818  public class CC { Line 922  public class CC {
922          public static void          public static void
923          changeBackend() {          changeBackend() {
924                  Server s = getMainFrame().getServer(true);                  Server s = getMainFrame().getServer(true);
925                  if(s != null) initSamplerModel(s);                  if(s != null) {
926                            connectionFailureCount = 0; // cleared because this change due to user interaction
927                            initSamplerModel(s);
928                    }
929            }
930            
931            private static final Vector<ActionListener> pListeners = new Vector<ActionListener>();
932            
933            /**
934             * Registers the specified listener to be notified when
935             * backend process is created/terminated.
936             * @param l The <code>ActionListener</code> to register.
937             */
938            public static void
939            addBackendProcessListener(ActionListener l) { pListeners.add(l); }
940            
941            /**
942             * Removes the specified listener.
943             * @param l The <code>ActionListener</code> to remove.
944             */
945            public static void
946            removeBackendProcessListener(ActionListener l) { pListeners.remove(l); }
947            
948            private static void
949            fireBackendProcessEvent() {
950                    ActionEvent e = new ActionEvent(CC.class, ActionEvent.ACTION_PERFORMED, null);
951                    for(ActionListener l : pListeners) l.actionPerformed(e);
952            }
953            
954            private static Process backendProcess = null;
955            
956            public static Process
957            getBackendProcess() { return backendProcess; }
958            
959            private static final Object backendMonitor = new Object();
960            
961            public static Object
962            getBackendMonitor() { return backendMonitor; }
963            
964            private static boolean
965            launchBackend() throws Exception {
966                    if(backendProcess != null) {
967                            try {
968                                    int i = backendProcess.exitValue();
969                                    getLogger().info("Backend exited with exit value " + i);
970                                    backendProcess = null;
971                                    fireBackendProcessEvent();
972                            } catch(IllegalThreadStateException x) { return false; }
973                    }
974                    
975                    if(!preferences().getBoolProperty(JSPrefs.LAUNCH_BACKEND_LOCALLY)) return false;
976                    if(connectionFailureCount > 1) return false;
977                    
978                    Server  s = getCurrentServer();
979                    if(s != null && s.isLocal()) {
980                            String cmd = preferences().getStringProperty(JSPrefs.BACKEND_LAUNCH_COMMAND);
981                            backendProcess = Runtime.getRuntime().exec(cmd);
982                            fireBackendProcessEvent();
983                            return true;
984                    }
985                    
986                    return false;
987          }          }
988                    
989          private static class GetFxSendsListener implements TaskListener {          private static class GetFxSendsListener implements TaskListener {
990                    @Override
991                  public void                  public void
992                  taskPerformed(TaskEvent e) {                  taskPerformed(TaskEvent e) {
993                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();                          Channel.GetFxSends gfs = (Channel.GetFxSends)e.getSource();
# Line 855  public class CC { Line 1021  public class CC {
1021          exportInstrMapsToLscpScript(Client lscpClient) {          exportInstrMapsToLscpScript(Client lscpClient) {
1022                  try {                  try {
1023                          lscpClient.removeAllMidiInstrumentMaps();                          lscpClient.removeAllMidiInstrumentMaps();
1024                          MidiInstrumentMap[] maps = CC.getSamplerModel().getMidiInstrumentMaps();                          MidiInstrumentMap[] maps = getSamplerModel().getMidiInstrumentMaps();
1025                          for(int i = 0; i < maps.length; i++) {                          for(int i = 0; i < maps.length; i++) {
1026                                  lscpClient.addMidiInstrumentMap(maps[i].getName());                                  lscpClient.addMidiInstrumentMap(maps[i].getName());
1027                                  exportInstrumentsToLscpScript(i, maps[i], lscpClient);                                  exportInstrumentsToLscpScript(i, maps[i], lscpClient);
1028                          }                          }
1029                  } catch(Exception e) {                  } catch(Exception e) {
1030                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);                          getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1031                          HF.showErrorMessage(e);                          HF.showErrorMessage(e);
1032                  }                  }
1033          }          }
# Line 870  public class CC { Line 1036  public class CC {
1036          exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient)          exportInstrumentsToLscpScript(int mapId, MidiInstrumentMap map, Client lscpClient)
1037                                                                                  throws Exception {                                                                                  throws Exception {
1038                    
1039                    boolean b = preferences().getBoolProperty(JSPrefs.LOAD_MIDI_INSTRUMENTS_IN_BACKGROUND);
1040                    
1041                  for(MidiInstrument i : map.getAllMidiInstruments()) {                  for(MidiInstrument i : map.getAllMidiInstruments()) {
1042                          lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo());                          lscpClient.mapMidiInstrument(mapId, i.getInfo().getEntry(), i.getInfo(), b);
1043                  }                  }
1044          }          }
1045                    
1046          public static String          public static String
1047          exportSessionToLscpScript() {          exportSessionToLscpScript() {
1048                  CC.getSamplerModel().setModified(false);                  getSamplerModel().setModified(false);
1049                                    
1050                  StringBuffer sb = new StringBuffer("# Exported by: ");                  StringBuffer sb = new StringBuffer("# Exported by: ");
1051                  sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");                  sb.append("JSampler - a java front-end for LinuxSampler\r\n# Version: ");
# Line 893  public class CC { Line 1061  public class CC {
1061                          sb.append(out.toString());                          sb.append(out.toString());
1062                          out.reset();                          out.reset();
1063                          sb.append("\r\n");                          sb.append("\r\n");
1064                          lscpClient.setVolume(CC.getSamplerModel().getVolume());                          lscpClient.setVolume(getSamplerModel().getVolume());
1065                          sb.append(out.toString());                          sb.append(out.toString());
1066                          out.reset();                          out.reset();
1067                          sb.append("\r\n");                          sb.append("\r\n");
1068                  } catch(Exception e) { CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }                  } catch(Exception e) { getLogger().log(Level.FINE, HF.getErrorMessage(e), e); }
1069                                                                    
1070                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();                  MidiDeviceModel[] mDevs = getSamplerModel().getMidiDevices();
1071                  for(int i = 0; i < mDevs.length; i++) {                  for(int i = 0; i < mDevs.length; i++) {
# Line 915  public class CC { Line 1083  public class CC {
1083                          sb.append("\r\n");                          sb.append("\r\n");
1084                  }                  }
1085                                    
1086                  exportInstrMapsToLscpScript(lscpClient);                  boolean b = preferences().getBoolProperty(JSPrefs.EXPORT_MIDI_MAPS_TO_SESSION_SCRIPT);
1087                  sb.append(out.toString());                  if(b) {
1088                  out.reset();                          exportInstrMapsToLscpScript(lscpClient);
1089                  sb.append("\r\n");                          sb.append(out.toString());
1090                            out.reset();
1091                            sb.append("\r\n");
1092                    }
1093                                    
1094                  SamplerChannelModel[] channels = getSamplerModel().getChannels();                  SamplerChannelModel[] channels = getSamplerModel().getChannels();
1095                                    
# Line 937  public class CC { Line 1108  public class CC {
1108                          sb.append("\r\n");                          sb.append("\r\n");
1109                  }                  }
1110                                    
1111                    //sb.append(getViewConfig().exportSessionViewConfig());
1112                    
1113                  return sb.toString();                  return sb.toString();
1114          }          }
1115                    
# Line 958  public class CC { Line 1131  public class CC {
1131                                  }                                  }
1132                          }                          }
1133                  } catch(Exception e) {                  } catch(Exception e) {
1134                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);                          getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1135                  }                  }
1136          }          }
1137                    
# Line 978  public class CC { Line 1151  public class CC {
1151                                  }                                  }
1152                          }                          }
1153                  } catch(Exception e) {                  } catch(Exception e) {
1154                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);                          getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1155                  }                  }
1156          }          }
1157                    
# Line 987  public class CC { Line 1160  public class CC {
1160                  try {                  try {
1161                          lscpCLient.addSamplerChannel();                          lscpCLient.addSamplerChannel();
1162                                                    
1163                          SamplerModel sm = CC.getSamplerModel();                          SamplerModel sm = getSamplerModel();
1164                          int id = chn.getMidiInputDevice();                          int id = chn.getMidiInputDevice();
1165                          if(id != -1) {                          if(id != -1) {
1166                                  for(int i = 0; i < sm.getMidiDeviceCount(); i++) {                                  for(int i = 0; i < sm.getMidiDeviceCount(); i++) {
# Line 1033  public class CC { Line 1206  public class CC {
1206                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);                          if(chn.isMuted()) lscpCLient.setChannelMute(chnId, true);
1207                          if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true);                          if(chn.isSoloChannel()) lscpCLient.setChannelSolo(chnId, true);
1208                  } catch(Exception e) {                  } catch(Exception e) {
1209                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);                          getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1210                  }                  }
1211          }          }
1212                    
# Line 1052  public class CC { Line 1225  public class CC {
1225                                  }                                  }
1226                          }                          }
1227                  } catch(Exception e) {                  } catch(Exception e) {
1228                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);                          getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
1229                  }                  }
1230          }          }
1231                    
# Line 1066  public class CC { Line 1239  public class CC {
1239                          }                          }
1240                  });                  });
1241                                    
1242                  CC.getTaskQueue().add(dummy);                  getTaskQueue().add(dummy);
1243          }          }
1244                    
1245          public static boolean          public static boolean
# Line 1089  public class CC { Line 1262  public class CC {
1262                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,                  FxSendCountListener, FxSendInfoListener, StreamCountListener, VoiceCountListener,
1263                  TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener,                  TotalStreamCountListener, TotalVoiceCountListener, TaskQueueListener,
1264                  OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener,                  OrchestraListener, ListListener<OrchestraModel>, MidiInstrumentCountListener,
1265                  MidiInstrumentInfoListener, GlobalInfoListener {                  MidiInstrumentInfoListener, GlobalInfoListener, ChannelMidiDataListener {
1266                                    
1267                  /** Invoked when the number of channels has changed. */                  /** Invoked when the number of channels has changed. */
1268                    @Override
1269                  public void                  public void
1270                  channelCountChanged( ChannelCountEvent e) {                  channelCountChanged( ChannelCountEvent e) {
1271                          getTaskQueue().add(new UpdateChannels());                          addTask(new UpdateChannels());
1272                  }                  }
1273                                    
1274                  /** Invoked when changes to the sampler channel has occured. */                  /** Invoked when changes to the sampler channel has occured. */
1275                    @Override
1276                  public void                  public void
1277                  channelInfoChanged(ChannelInfoEvent e) {                  channelInfoChanged(ChannelInfoEvent e) {
1278                          /*                          /*
# Line 1135  public class CC { Line 1310  public class CC {
1310                   * Invoked when the number of effect sends                   * Invoked when the number of effect sends
1311                   * on a particular sampler channel has changed.                   * on a particular sampler channel has changed.
1312                   */                   */
1313                    @Override
1314                  public void                  public void
1315                  fxSendCountChanged(FxSendCountEvent e) {                  fxSendCountChanged(FxSendCountEvent e) {
1316                          getTaskQueue().add(new Channel.UpdateFxSends(e.getChannel()));                          getTaskQueue().add(new Channel.UpdateFxSends(e.getChannel()));
# Line 1143  public class CC { Line 1319  public class CC {
1319                  /**                  /**
1320                   * Invoked when the settings of an effect sends are changed.                   * Invoked when the settings of an effect sends are changed.
1321                   */                   */
1322                    @Override
1323                  public void                  public void
1324                  fxSendInfoChanged(FxSendInfoEvent e) {                  fxSendInfoChanged(FxSendInfoEvent e) {
1325                          Task t = new Channel.UpdateFxSendInfo(e.getChannel(), e.getFxSend());                          Task t = new Channel.UpdateFxSendInfo(e.getChannel(), e.getFxSend());
# Line 1153  public class CC { Line 1330  public class CC {
1330                   * Invoked when the number of active disk                   * Invoked when the number of active disk
1331                   * streams in a specific sampler channel has changed.                   * streams in a specific sampler channel has changed.
1332                   */                   */
1333                    @Override
1334                  public void                  public void
1335                  streamCountChanged(StreamCountEvent e) {                  streamCountChanged(StreamCountEvent e) {
1336                          SamplerChannelModel scm =                          SamplerChannelModel scm =
# Line 1175  public class CC { Line 1353  public class CC {
1353                   * Invoked when the number of active voices                   * Invoked when the number of active voices
1354                   * in a specific sampler channel has changed.                   * in a specific sampler channel has changed.
1355                   */                   */
1356                    @Override
1357                  public void                  public void
1358                  voiceCountChanged(VoiceCountEvent e) {                  voiceCountChanged(VoiceCountEvent e) {
1359                          SamplerChannelModel scm =                          SamplerChannelModel scm =
# Line 1194  public class CC { Line 1373  public class CC {
1373                  }                  }
1374                                    
1375                  /** Invoked when the total number of active streams has changed. */                  /** Invoked when the total number of active streams has changed. */
1376                    @Override
1377                  public void                  public void
1378                  totalStreamCountChanged(TotalStreamCountEvent e) {                  totalStreamCountChanged(TotalStreamCountEvent e) {
1379                          getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount());                          getSamplerModel().updateActiveStreamsInfo(e.getTotalStreamCount());
1380                  }                  }
1381                                    
1382                  /** Invoked when the total number of active voices has changed. */                  /** Invoked when the total number of active voices has changed. */
1383                    @Override
1384                  public void                  public void
1385                  totalVoiceCountChanged(TotalVoiceCountEvent e) {                  totalVoiceCountChanged(TotalVoiceCountEvent e) {
1386                          getTaskQueue().add(new UpdateTotalVoiceCount());                          getTaskQueue().add(new UpdateTotalVoiceCount());
1387                  }                  }
1388                                    
1389                  /** 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. */
1390                    @Override
1391                  public void                  public void
1392                  instrumentCountChanged(MidiInstrumentCountEvent e) {                  instrumentCountChanged(MidiInstrumentCountEvent e) {
1393                          scheduleTask(new Midi.UpdateInstruments(e.getMapId()));                          scheduleTask(new Midi.UpdateInstruments(e.getMapId()));
1394                  }                  }
1395                                    
1396                  /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */                  /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */
1397                    @Override
1398                  public void                  public void
1399                  instrumentInfoChanged(MidiInstrumentInfoEvent e) {                  instrumentInfoChanged(MidiInstrumentInfoEvent e) {
1400                          Task t = new Midi.UpdateInstrumentInfo (                          Task t = new Midi.UpdateInstrumentInfo (
# Line 1222  public class CC { Line 1405  public class CC {
1405                  }                  }
1406                                    
1407                  /** Invoked when the global volume of the sampler is changed. */                  /** Invoked when the global volume of the sampler is changed. */
1408                    @Override
1409                  public void                  public void
1410                  volumeChanged(GlobalInfoEvent e) {                  volumeChanged(GlobalInfoEvent e) {
1411                          getSamplerModel().setVolume(e.getVolume());                          getSamplerModel().setVolume(e.getVolume());
# Line 1231  public class CC { Line 1415  public class CC {
1415                   * Invoked to indicate that the state of a task queue is changed.                   * Invoked to indicate that the state of a task queue is changed.
1416                   * This method is invoked only from the event-dispatching thread.                   * This method is invoked only from the event-dispatching thread.
1417                   */                   */
1418                    @Override
1419                  public void                  public void
1420                  stateChanged(TaskQueueEvent e) {                  stateChanged(TaskQueueEvent e) {
1421                          switch(e.getEventID()) {                          switch(e.getEventID()) {
# Line 1241  public class CC { Line 1426  public class CC {
1426                                  break;                                  break;
1427                          case TASK_DONE:                          case TASK_DONE:
1428                                  EnhancedTask t = (EnhancedTask)e.getSource();                                  EnhancedTask t = (EnhancedTask)e.getSource();
1429                                  if(t.doneWithErrors() && !t.isStopped()) {                                  if(t.doneWithErrors() && !t.isStopped() && !t.isSilent()) {
1430                                          showError(t);                                          showError(t);
1431                                  }                                  }
1432                                  break;                                  break;
# Line 1274  public class CC { Line 1459  public class CC {
1459                  }                  }
1460                                    
1461                  /** Invoked when the name of orchestra is changed. */                  /** Invoked when the name of orchestra is changed. */
1462                    @Override
1463                  public void                  public void
1464                  nameChanged(OrchestraEvent e) { saveOrchestras(); }                  nameChanged(OrchestraEvent e) { saveOrchestras(); }
1465                    
1466                  /** Invoked when the description of orchestra is changed. */                  /** Invoked when the description of orchestra is changed. */
1467                    @Override
1468                  public void                  public void
1469                  descriptionChanged(OrchestraEvent e) { saveOrchestras(); }                  descriptionChanged(OrchestraEvent e) { saveOrchestras(); }
1470                    
1471                  /** Invoked when an instrument is added to the orchestra. */                  /** Invoked when an instrument is added to the orchestra. */
1472                    @Override
1473                  public void                  public void
1474                  instrumentAdded(OrchestraEvent e) { saveOrchestras(); }                  instrumentAdded(OrchestraEvent e) { saveOrchestras(); }
1475                    
1476                  /** Invoked when an instrument is removed from the orchestra. */                  /** Invoked when an instrument is removed from the orchestra. */
1477                    @Override
1478                  public void                  public void
1479                  instrumentRemoved(OrchestraEvent e) { saveOrchestras(); }                  instrumentRemoved(OrchestraEvent e) { saveOrchestras(); }
1480                    
1481                  /** Invoked when the settings of an instrument are changed. */                  /** Invoked when the settings of an instrument are changed. */
1482                    @Override
1483                  public void                  public void
1484                  instrumentChanged(OrchestraEvent e) { saveOrchestras(); }                  instrumentChanged(OrchestraEvent e) { saveOrchestras(); }
1485                                    
1486                  /** Invoked when an orchestra is added to the orchestra list. */                  /** Invoked when an orchestra is added to the orchestra list. */
1487                    @Override
1488                  public void                  public void
1489                  entryAdded(ListEvent<OrchestraModel> e) {                  entryAdded(ListEvent<OrchestraModel> e) {
1490                          e.getEntry().addOrchestraListener(getHandler());                          e.getEntry().addOrchestraListener(getHandler());
# Line 1301  public class CC { Line 1492  public class CC {
1492                  }                  }
1493                    
1494                  /** Invoked when an orchestra is removed from the orchestra list. */                  /** Invoked when an orchestra is removed from the orchestra list. */
1495                    @Override
1496                  public void                  public void
1497                  entryRemoved(ListEvent<OrchestraModel> e) {                  entryRemoved(ListEvent<OrchestraModel> e) {
1498                          e.getEntry().removeOrchestraListener(getHandler());                          e.getEntry().removeOrchestraListener(getHandler());
1499                          saveOrchestras();                          saveOrchestras();
1500                  }                  }
1501                    
1502                    /**
1503                     * Invoked when MIDI data arrives.
1504                     */
1505                    @Override
1506                    public void
1507                    midiDataArrived(final ChannelMidiDataEvent e) {
1508                            try {
1509                                    javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
1510                                            public void
1511                                            run() { fireChannelMidiDataEvent(e); }
1512                                    });
1513                            } catch(Exception x) {
1514                                    CC.getLogger().log(Level.INFO, "Failed!", x);
1515                            }
1516                    }
1517            }
1518            
1519            private static void
1520            fireChannelMidiDataEvent(ChannelMidiDataEvent e) {
1521                    SamplerChannelModel chn;
1522                    chn = CC.getSamplerModel().getChannelById(e.getChannelId());
1523                    if(chn == null) {
1524                            CC.getLogger().info("Unknown channel ID: " + e.getChannelId());
1525                    }
1526                    
1527                    ((DefaultSamplerChannelModel)chn).fireMidiDataEvent(e);
1528          }          }
1529                    
1530          private static final AudioDeviceCountListener audioDeviceCountListener =          private static final AudioDeviceCountListener audioDeviceCountListener =
# Line 1313  public class CC { Line 1532  public class CC {
1532                    
1533          private static class AudioDeviceCountListener implements ItemCountListener {          private static class AudioDeviceCountListener implements ItemCountListener {
1534                  /** Invoked when the number of audio output devices has changed. */                  /** Invoked when the number of audio output devices has changed. */
1535                    @Override
1536                  public void                  public void
1537                  itemCountChanged(ItemCountEvent e) {                  itemCountChanged(ItemCountEvent e) {
1538                          getTaskQueue().add(new Audio.UpdateDevices());                          getTaskQueue().add(new Audio.UpdateDevices());
# Line 1324  public class CC { Line 1544  public class CC {
1544                    
1545          private static class AudioDeviceInfoListener implements ItemInfoListener {          private static class AudioDeviceInfoListener implements ItemInfoListener {
1546                  /** Invoked when the audio output device's settings are changed. */                  /** Invoked when the audio output device's settings are changed. */
1547                    @Override
1548                  public void                  public void
1549                  itemInfoChanged(ItemInfoEvent e) {                  itemInfoChanged(ItemInfoEvent e) {
1550                          getTaskQueue().add(new Audio.UpdateDeviceInfo(e.getItemID()));                          getTaskQueue().add(new Audio.UpdateDeviceInfo(e.getItemID()));
# Line 1335  public class CC { Line 1556  public class CC {
1556                    
1557          private static class MidiDeviceCountListener implements ItemCountListener {          private static class MidiDeviceCountListener implements ItemCountListener {
1558                  /** Invoked when the number of MIDI input devices has changed. */                  /** Invoked when the number of MIDI input devices has changed. */
1559                    @Override
1560                  public void                  public void
1561                  itemCountChanged(ItemCountEvent e) {                  itemCountChanged(ItemCountEvent e) {
1562                          getTaskQueue().add(new Midi.UpdateDevices());                          getTaskQueue().add(new Midi.UpdateDevices());
# Line 1346  public class CC { Line 1568  public class CC {
1568                    
1569          private static class MidiDeviceInfoListener implements ItemInfoListener {          private static class MidiDeviceInfoListener implements ItemInfoListener {
1570                  /** Invoked when the MIDI input device's settings are changed. */                  /** Invoked when the MIDI input device's settings are changed. */
1571                    @Override
1572                  public void                  public void
1573                  itemInfoChanged(ItemInfoEvent e) {                  itemInfoChanged(ItemInfoEvent e) {
1574                          getTaskQueue().add(new Midi.UpdateDeviceInfo(e.getItemID()));                          getTaskQueue().add(new Midi.UpdateDeviceInfo(e.getItemID()));
# Line 1357  public class CC { Line 1580  public class CC {
1580                    
1581          private static class MidiInstrMapCountListener implements ItemCountListener {          private static class MidiInstrMapCountListener implements ItemCountListener {
1582                  /** Invoked when the number of MIDI instrument maps is changed. */                  /** Invoked when the number of MIDI instrument maps is changed. */
1583                    @Override
1584                  public void                  public void
1585                  itemCountChanged(ItemCountEvent e) {                  itemCountChanged(ItemCountEvent e) {
1586                          getTaskQueue().add(new Midi.UpdateInstrumentMaps());                          getTaskQueue().add(new Midi.UpdateInstrumentMaps());
# Line 1368  public class CC { Line 1592  public class CC {
1592                    
1593          private static class MidiInstrMapInfoListener implements ItemInfoListener {          private static class MidiInstrMapInfoListener implements ItemInfoListener {
1594                  /** Invoked when the MIDI instrument map's settings are changed. */                  /** Invoked when the MIDI instrument map's settings are changed. */
1595                    @Override
1596                  public void                  public void
1597                  itemInfoChanged(ItemInfoEvent e) {                  itemInfoChanged(ItemInfoEvent e) {
1598                          getTaskQueue().add(new Midi.UpdateInstrumentMapInfo(e.getItemID()));                          getTaskQueue().add(new Midi.UpdateInstrumentMapInfo(e.getItemID()));

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

  ViewVC Help
Powered by ViewVC