/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/Client.java
ViewVC logotype

Diff of /jlscp/trunk/src/org/linuxsampler/lscp/Client.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1421 by iliev, Sun Oct 14 18:08:45 2007 UTC revision 1718 by iliev, Wed Mar 19 10:05:33 2008 UTC
# Line 344  public class Client { Line 344  public class Client {
344                  if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");                  if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");
345                  if(!llSC.isEmpty()) subscribe("STREAM_COUNT");                  if(!llSC.isEmpty()) subscribe("STREAM_COUNT");
346                  if(!llVC.isEmpty()) subscribe("VOICE_COUNT");                  if(!llVC.isEmpty()) subscribe("VOICE_COUNT");
347                    if(!llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
348                  if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");                  if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");
349                  if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");                  if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");
350                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
# Line 354  public class Client { Line 355  public class Client {
355                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
356                          subscribe("DB_INSTRUMENT_COUNT");                          subscribe("DB_INSTRUMENT_COUNT");
357                          subscribe("DB_INSTRUMENT_INFO");                          subscribe("DB_INSTRUMENT_INFO");
358                            subscribe("DB_INSTRUMENTS_JOB_INFO");
359                  }                  }
360                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
361          }          }
# Line 485  public class Client { Line 487  public class Client {
487          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();
488          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();
489          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();
490            private final Vector<TotalStreamCountListener> llTSC = new Vector<TotalStreamCountListener>();
491          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();
492                    
493          /** MIDI instrument map count listeners */          /** MIDI instrument map count listeners */
# Line 522  public class Client { Line 525  public class Client {
525                          !llMIDI.isEmpty() ||                          !llMIDI.isEmpty() ||
526                          !llSC.isEmpty()   ||                          !llSC.isEmpty()   ||
527                          !llVC.isEmpty()   ||                          !llVC.isEmpty()   ||
528                            !llTSC.isEmpty()  ||
529                          !llTVC.isEmpty()  ||                          !llTVC.isEmpty()  ||
530                          !llMIMC.isEmpty() ||                          !llMIMC.isEmpty() ||
531                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
# Line 662  public class Client { Line 666  public class Client {
666                          } catch(NumberFormatException x) {                          } catch(NumberFormatException x) {
667                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);
668                          }                          }
669                    } else if(s.startsWith("TOTAL_STREAM_COUNT:")) {
670                            try {
671                                    s = s.substring("TOTAL_STREAM_COUNT:".length());
672                                    int i = Integer.parseInt(s);
673                                    TotalStreamCountEvent e = new TotalStreamCountEvent(this, i);
674                                    for(TotalStreamCountListener l : llTSC) l.totalStreamCountChanged(e);
675                            } catch(NumberFormatException x) {
676                                    getLogger().log (
677                                            Level.WARNING, "Unknown TOTAL_STREAM_COUNT format", x
678                                    );
679                            }
680                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {
681                          try {                          try {
682                                  s = s.substring("TOTAL_VOICE_COUNT:".length());                                  s = s.substring("TOTAL_VOICE_COUNT:".length());
# Line 1134  public class Client { Line 1149  public class Client {
1149          /**          /**
1150           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1151           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1152             * @param l The <code>TotalStreamCountListener</code> to register.
1153             */
1154            public synchronized void
1155            addTotalStreamCountListener(TotalStreamCountListener l) {
1156                    if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
1157                    llTSC.add(l);
1158            }
1159            
1160            /**
1161             * Removes the specified listener.
1162             * Listeners can be removed regardless of the connection state.
1163             * @param l The <code>TotalStreamCountListener</code> to remove.
1164             */
1165            public synchronized void
1166            removeTotalStreamCountListener(TotalStreamCountListener l) {
1167                    boolean b = llTSC.remove(l);
1168                    if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT");
1169            }
1170            
1171            /**
1172             * Registers the specified listener for receiving event messages.
1173             * Listeners can be registered regardless of the connection state.
1174           * @param l The <code>TotalVoiceCountListener</code> to register.           * @param l The <code>TotalVoiceCountListener</code> to register.
1175           */           */
1176          public synchronized void          public synchronized void
# Line 1418  public class Client { Line 1455  public class Client {
1455                  args.append(' ').append(param);                  args.append(' ').append(param);
1456                                    
1457                  for(Parameter p : deplist) {                  for(Parameter p : deplist) {
1458                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
1459                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1460                  }                  }
1461                                    
# Line 1482  public class Client { Line 1519  public class Client {
1519                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1520                                    
1521                  for(Parameter p : paramList) {                  for(Parameter p : paramList) {
1522                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
1523                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1524                  }                  }
1525                                    
# Line 2004  public class Client { Line 2041  public class Client {
2041                  args.append(' ').append(param);                  args.append(' ').append(param);
2042                                    
2043                  for(Parameter p : deplist) {                  for(Parameter p : deplist) {
2044                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
2045                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2046                  }                  }
2047                                    
# Line 2069  public class Client { Line 2106  public class Client {
2106                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2107                                    
2108                  for(Parameter p : paramList) {                  for(Parameter p : paramList) {
2109                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
2110                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2111                  }                  }
2112                                    
# Line 2216  public class Client { Line 2253  public class Client {
2253                                  mid.setActive(Boolean.parseBoolean(s));                                  mid.setActive(Boolean.parseBoolean(s));
2254                          } else if(s.startsWith("PORTS: ")) {                          } else if(s.startsWith("PORTS: ")) {
2255                                  s = s.substring("PORTS: ".length());                                  s = s.substring("PORTS: ".length());
2256                                  int ports = Parser.parseInt(s);                                  
2257                                  MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0];                                  Parameter<Integer> ports = (Parameter<Integer>)
2258                                            getMidiInputDriverParameterInfo(drv, "PORTS");
2259                                    
2260                                    ports.parseValue(s);
2261                                    mid.setPortsParameter(ports);
2262                                    
2263                                    int j = ports.getValue();
2264                                    MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0];
2265                                                                    
2266                                  for(int i = 0; i < midiPorts.length; i++)                                  for(int i = 0; i < midiPorts.length; i++)
2267                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);
# Line 2760  public class Client { Line 2804  public class Client {
2804          }          }
2805                    
2806          /**          /**
2807           * Gets all MIDI instrument contained int the specified MIDI instrument map.           * Gets all MIDI instrument entries contained int the specified MIDI instrument map.
2808             * @param mapId The ID of the map, which instruments should be obtained.
2809             * @return An int array providing all MIDI instrument entries
2810             * in the specified MIDI instrument map.
2811             * @throws IOException If some I/O error occurs.
2812             * @throws LscpException If LSCP protocol corruption occurs.
2813             * @throws LSException If some other error occurs.
2814             */
2815            public synchronized int[][]
2816            getMidiInstrumentEntries(int mapId) throws IOException, LscpException, LSException {
2817                    verifyConnection();
2818                    out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId));
2819                    if(getPrintOnlyMode()) return null;
2820                    
2821                    String[] entries = parseArray(getSingleLineResultSet().getResult());
2822                    int[][] e = new int[entries.length][3];
2823                    
2824                    for(int i = 0; i < entries.length; i++) {
2825                            Integer[] vals = parseIntList(entries[i]);
2826                            if(vals.length != 3) {
2827                                    throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
2828                            }
2829                            
2830                            e[i][0] = vals[0];
2831                            e[i][1] = vals[1];
2832                            e[i][2] = vals[2];
2833                    }
2834                    
2835                    return e;
2836            }
2837            
2838            /**
2839             * Gets all MIDI instruments contained int the specified MIDI instrument map.
2840           * @param mapId The ID of the map, which instruments should be obtained.           * @param mapId The ID of the map, which instruments should be obtained.
2841           * @return A <code>MidiInstrumentInfo</code> array providing           * @return A <code>MidiInstrumentInfo</code> array providing
2842           * all MIDI instruments from all MIDI instrument maps.           * all MIDI instruments in the specified MIDI instrument map.
2843           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
2844           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
2845           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
# Line 2811  public class Client { Line 2887  public class Client {
2887                                          throws IOException, LscpException, LSException {                                          throws IOException, LscpException, LSException {
2888                    
2889                  verifyConnection();                  verifyConnection();
2890                    requestMidiInstrumentInfo(mapId, bank, program);
2891                    return getMidiInstrumentInfoResponse(mapId, bank, program);
2892            }
2893            
2894            private void
2895            requestMidiInstrumentInfo(int mapId, int bank, int program) throws IOException {
2896                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");
2897                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
2898                  cmd.append(bank).append(' ');                  cmd.append(bank).append(' ');
2899                  cmd.append(program);                  cmd.append(program);
2900                                    
2901                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
2902                  if(getPrintOnlyMode()) return null;          }
2903            
2904            private MidiInstrumentInfo
2905            getMidiInstrumentInfoResponse(int mapId, int bank, int program)
2906                                            throws IOException, LscpException, LSException {
2907                                    
2908                    if(getPrintOnlyMode()) return null;
2909                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
2910                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
2911                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());
# Line 4864  public class Client { Line 4951  public class Client {
4951          }          }
4952                    
4953          /**          /**
4954             * Gets the current number of all active streams.
4955             * @return The current number of all active streams.
4956             * @throws IOException If some I/O error occurs.
4957             * @throws LscpException If LSCP protocol corruption occurs.
4958             * @throws LSException If some other error occurs.
4959             */
4960            public synchronized int
4961            getTotalStreamCount() throws IOException, LscpException, LSException {
4962                    verifyConnection();
4963                    out.writeLine("GET TOTAL_STREAM_COUNT");
4964                    if(getPrintOnlyMode()) return -1;
4965                    
4966                    String s = getSingleLineResultSet().getResult();
4967                    return parseInt(s);
4968            }
4969            
4970            /**
4971           * Gets the current number of all active voices.           * Gets the current number of all active voices.
4972           * @return The current number of all active voices.           * @return The current number of all active voices.
4973           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 4952  public class Client { Line 5056  public class Client {
5056                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
5057          }          }
5058                    
5059            /**
5060             * Gets the number of instruments in the specified instrument file.
5061             * @param filename The absolute path name of the instrument file.
5062             * @return The number of instruments in the specified instrument file.
5063             * @throws IOException If some I/O error occurs.
5064             * @throws LscpException If LSCP protocol corruption occurs.
5065             * @throws LSException If the file is not found, or other error occur.
5066             */
5067            public synchronized int
5068            getFileInstrumentCount(String filename) throws IOException, LscpException, LSException {
5069                    verifyConnection();
5070                    out.writeLine("GET FILE INSTRUMENTS '" + filename +"'");
5071                    if(getPrintOnlyMode()) return -1;
5072                    
5073                    String s = getSingleLineResultSet().getResult();
5074                    return parseInt(s);
5075            }
5076            
5077            /**
5078             * Gets information about the instrument with index
5079             * <code>instrIdx</code> in the specified instrument file.
5080             * @param filename The absolute path name of the instrument file.
5081             * @param instrIdx The index of the instrument in the specified instrument file.
5082             * @throws IOException If some I/O error occurs.
5083             * @throws LscpException If LSCP protocol corruption occurs.
5084             * @throws LSException If failed to retrieve information.
5085             */
5086            public synchronized Instrument
5087            getFileInstrumentInfo(String filename, int instrIdx)
5088                                    throws IOException, LscpException, LSException {
5089                    
5090                    verifyConnection();
5091                    out.writeLine("GET FILE INSTRUMENT INFO '" + filename + "' " + String.valueOf(instrIdx));
5092                    if(getPrintOnlyMode()) return null;
5093                    
5094                    ResultSet rs = getMultiLineResultSet();
5095                    Instrument instr = new FileInstrument(rs.getMultiLineResult()) { };
5096                    
5097                    return instr;
5098            }
5099            
5100            /**
5101             * Gets the list of instruments in the specified instrument file.
5102             * @param filename The absolute path name of the instrument file.
5103             * @return An <code>Instrument</code> array providing
5104             * information about all instruments in the specified instrument file.
5105             * @throws IOException If some I/O error occurs.
5106             * @throws LscpException If LSCP protocol corruption occurs.
5107             * @throws LSException If the specified file name is invalid.
5108             */
5109            public synchronized Instrument[]
5110            getFileInstruments(String filename) throws IOException, LscpException, LSException {
5111                    int l = getFileInstrumentCount(filename);
5112                    if(l < 0) return null;
5113                    Instrument[] instrS = new FileInstrument[l];
5114                    
5115                    for(int i = 0; i < instrS.length; i++) {
5116                            instrS[i] = getFileInstrumentInfo(filename, i);
5117                    }
5118                    return instrS;
5119            }
5120            
5121            private static class FileInstrument extends AbstractInstrument {
5122                    FileInstrument(String[] resultSet) throws LscpException {
5123                            super(resultSet);
5124                    }
5125                    
5126                    public String
5127                    getEngine() {
5128                            // TODO: engine lookup?
5129                            return getFormatFamily();
5130                    }
5131                    
5132                    public boolean
5133                    parse(String s) throws LscpException {
5134                            if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true;
5135                            return super.parse(s);
5136                    }
5137            }
5138            
5139          private void          private void
5140          getEmptyResultSets(int count, String err) throws LSException {          getEmptyResultSets(int count, String err) throws LSException {
5141                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();

Legend:
Removed from v.1421  
changed lines
  Added in v.1718

  ViewVC Help
Powered by ViewVC