/[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 1202 by iliev, Thu May 24 20:17:25 2007 UTC revision 1542 by iliev, Tue Dec 4 18:14:31 2007 UTC
# Line 34  import java.util.Vector; Line 34  import java.util.Vector;
34  import java.util.logging.Level;  import java.util.logging.Level;
35  import java.util.logging.Logger;  import java.util.logging.Logger;
36    
 import static org.linuxsampler.lscp.Parser.*;  
37  import org.linuxsampler.lscp.event.*;  import org.linuxsampler.lscp.event.*;
38    
39    import static org.linuxsampler.lscp.Parser.*;
40    
41    
42  /**  /**
43   * This class is the abstraction representing a client endpoint for communication with LinuxSampler   * This class is the abstraction representing a client endpoint for communication with LinuxSampler
# Line 343  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 484  public class Client { Line 486  public class Client {
486          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();
487          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();
488          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();
489            private final Vector<TotalStreamCountListener> llTSC = new Vector<TotalStreamCountListener>();
490          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();
491                    
492          /** MIDI instrument map count listeners */          /** MIDI instrument map count listeners */
# Line 521  public class Client { Line 524  public class Client {
524                          !llMIDI.isEmpty() ||                          !llMIDI.isEmpty() ||
525                          !llSC.isEmpty()   ||                          !llSC.isEmpty()   ||
526                          !llVC.isEmpty()   ||                          !llVC.isEmpty()   ||
527                            !llTSC.isEmpty()  ||
528                          !llTVC.isEmpty()  ||                          !llTVC.isEmpty()  ||
529                          !llMIMC.isEmpty() ||                          !llMIMC.isEmpty() ||
530                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
# Line 542  public class Client { Line 546  public class Client {
546                          if(s.startsWith("NAME ")) {                          if(s.startsWith("NAME ")) {
547                                  String[] list;                                  String[] list;
548                                  try {                                  try {
549                                          list = parseStringList(s.substring("NAME ".length()), ' ');                                          s = s.substring("NAME ".length());
550                                            list = parseEscapedStringList(s, ' ');
551                                          if(list.length != 2) throw new LscpException();                                          if(list.length != 2) throw new LscpException();
552                                            list[1] = toNonEscapedString(list[1]);
553                                          e = new InstrumentsDbEvent(this, list[0], list[1]);                                          e = new InstrumentsDbEvent(this, list[0], list[1]);
554                                          for(InstrumentsDbListener l : llID) {                                          for(InstrumentsDbListener l : llID) {
555                                                  l.directoryNameChanged(e);                                                  l.directoryNameChanged(e);
# Line 569  public class Client { Line 575  public class Client {
575                          if(s.startsWith("NAME ")) {                          if(s.startsWith("NAME ")) {
576                                  String[] list;                                  String[] list;
577                                  try {                                  try {
578                                          list = parseStringList(s.substring("NAME ".length()), ' ');                                          s = s.substring("NAME ".length());
579                                            list = parseEscapedStringList(s, ' ');
580                                          if(list.length != 2) throw new LscpException();                                          if(list.length != 2) throw new LscpException();
581                                            list[1] = toNonEscapedString(list[1]);
582                                          e = new InstrumentsDbEvent(this, list[0], list[1]);                                          e = new InstrumentsDbEvent(this, list[0], list[1]);
583                                          for(InstrumentsDbListener l : llID) {                                          for(InstrumentsDbListener l : llID) {
584                                                  l.instrumentNameChanged(e);                                                  l.instrumentNameChanged(e);
# Line 657  public class Client { Line 665  public class Client {
665                          } catch(NumberFormatException x) {                          } catch(NumberFormatException x) {
666                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);
667                          }                          }
668                    } else if(s.startsWith("TOTAL_STREAM_COUNT:")) {
669                            try {
670                                    s = s.substring("TOTAL_STREAM_COUNT:".length());
671                                    int i = Integer.parseInt(s);
672                                    TotalStreamCountEvent e = new TotalStreamCountEvent(this, i);
673                                    for(TotalStreamCountListener l : llTSC) l.totalStreamCountChanged(e);
674                            } catch(NumberFormatException x) {
675                                    getLogger().log (
676                                            Level.WARNING, "Unknown TOTAL_STREAM_COUNT format", x
677                                    );
678                            }
679                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {
680                          try {                          try {
681                                  s = s.substring("TOTAL_VOICE_COUNT:".length());                                  s = s.substring("TOTAL_VOICE_COUNT:".length());
# Line 1129  public class Client { Line 1148  public class Client {
1148          /**          /**
1149           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1150           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1151             * @param l The <code>TotalStreamCountListener</code> to register.
1152             */
1153            public synchronized void
1154            addTotalStreamCountListener(TotalStreamCountListener l) {
1155                    if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
1156                    llTSC.add(l);
1157            }
1158            
1159            /**
1160             * Removes the specified listener.
1161             * Listeners can be removed regardless of the connection state.
1162             * @param l The <code>TotalStreamCountListener</code> to remove.
1163             */
1164            public synchronized void
1165            removeTotalStreamCountListener(TotalStreamCountListener l) {
1166                    boolean b = llTSC.remove(l);
1167                    if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT");
1168            }
1169            
1170            /**
1171             * Registers the specified listener for receiving event messages.
1172             * Listeners can be registered regardless of the connection state.
1173           * @param l The <code>TotalVoiceCountListener</code> to register.           * @param l The <code>TotalVoiceCountListener</code> to register.
1174           */           */
1175          public synchronized void          public synchronized void
# Line 1355  public class Client { Line 1396  public class Client {
1396          /**          /**
1397           * Gets detailed information about a specific audio output driver.           * Gets detailed information about a specific audio output driver.
1398           * @param driverName The name of the audio output driver.           * @param driverName The name of the audio output driver.
1399           *           * @param depList An optional list of dependences parameters.
1400           * @return An <code>AudioOutputDriver</code> object containing           * @return An <code>AudioOutputDriver</code> object containing
1401           * information about the specified audio output driver.           * information about the specified audio output driver.
1402           *           *
# Line 1365  public class Client { Line 1406  public class Client {
1406           *           *
1407           * @see #getAudioOutputDriverNames           * @see #getAudioOutputDriverNames
1408           */           */
1409          private synchronized AudioOutputDriver          public synchronized AudioOutputDriver
1410          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getAudioOutputDriverInfo(String driverName, Parameter... depList)
1411                                            throws IOException, LscpException, LSException {
1412                    
1413                  verifyConnection();                  verifyConnection();
1414                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
1415                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1376  public class Client { Line 1419  public class Client {
1419                  aod.setName(driverName);                  aod.setName(driverName);
1420                                    
1421                  for(String s : aod.getParameterNames())                  for(String s : aod.getParameterNames())
1422                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s));                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s, depList));
1423                                    
1424                  return aod;                  return aod;
1425          }          }
# Line 1410  public class Client { Line 1453  public class Client {
1453                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
1454                  args.append(' ').append(param);                  args.append(' ').append(param);
1455                                    
1456                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
1457                            if(p.getValue() == null) continue;
1458                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1459                    }
1460                                    
1461                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());
1462                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1472  public class Client { Line 1517  public class Client {
1517                  verifyConnection();                  verifyConnection();
1518                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1519                                    
1520                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
1521                            if(p.getValue() == null) continue;
1522                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1523                    }
1524                                    
1525                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());
1526                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 1934  public class Client { Line 1981  public class Client {
1981          /**          /**
1982           * Gets detailed information about a specific MIDI input driver.           * Gets detailed information about a specific MIDI input driver.
1983           * @param driverName The name of the MIDI input driver.           * @param driverName The name of the MIDI input driver.
1984           *           * @param depList An optional list of dependences parameters.
1985           * @return A <code>MidiInputDriver</code> object containing           * @return A <code>MidiInputDriver</code> object containing
1986           * information about the specified MIDI input driver.           * information about the specified MIDI input driver.
1987           *           *
# Line 1944  public class Client { Line 1991  public class Client {
1991           *           *
1992           * @see #getMidiInputDriverNames           * @see #getMidiInputDriverNames
1993           */           */
1994          private synchronized MidiInputDriver          public synchronized MidiInputDriver
1995          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getMidiInputDriverInfo(String driverName, Parameter... depList)
1996                                            throws IOException, LscpException, LSException {
1997                    
1998                  verifyConnection();                  verifyConnection();
1999                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
2000                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1956  public class Client { Line 2005  public class Client {
2005                  mid.setName(driverName);                  mid.setName(driverName);
2006                                    
2007                  for(String s : mid.getParameterNames())                  for(String s : mid.getParameterNames())
2008                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s));                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s, depList));
2009                                    
2010                  return mid;                  return mid;
2011          }          }
# Line 1990  public class Client { Line 2039  public class Client {
2039                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
2040                  args.append(' ').append(param);                  args.append(' ').append(param);
2041                                    
2042                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
2043                            if(p.getValue() == null) continue;
2044                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2045                    }
2046                                    
2047                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());
2048                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 2053  public class Client { Line 2104  public class Client {
2104                  verifyConnection();                  verifyConnection();
2105                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2106                                    
2107                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
2108                            if(p.getValue() == null) continue;
2109                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2110                    }
2111                                    
2112                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());
2113                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 2199  public class Client { Line 2252  public class Client {
2252                                  mid.setActive(Boolean.parseBoolean(s));                                  mid.setActive(Boolean.parseBoolean(s));
2253                          } else if(s.startsWith("PORTS: ")) {                          } else if(s.startsWith("PORTS: ")) {
2254                                  s = s.substring("PORTS: ".length());                                  s = s.substring("PORTS: ".length());
2255                                  int ports = Parser.parseInt(s);                                  
2256                                  MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0];                                  Parameter<Integer> ports = (Parameter<Integer>)
2257                                            getMidiInputDriverParameterInfo(drv, "PORTS");
2258                                    
2259                                    ports.parseValue(s);
2260                                    mid.setPortsParameter(ports);
2261                                    
2262                                    int j = ports.getValue();
2263                                    MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0];
2264                                                                    
2265                                  for(int i = 0; i < midiPorts.length; i++)                                  for(int i = 0; i < midiPorts.length; i++)
2266                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);
# Line 2443  public class Client { Line 2503  public class Client {
2503          public synchronized int          public synchronized int
2504          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {
2505                  verifyConnection();                  verifyConnection();
2506                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + name + "'");                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedString(name) + "'");
2507                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
2508                                    
2509                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 2546  public class Client { Line 2606  public class Client {
2606                                    
2607                  for(String s : lnS) {                  for(String s : lnS) {
2608                          if(s.startsWith("NAME: ")) {                          if(s.startsWith("NAME: ")) {
2609                                  name = s.substring("NAME: ".length());                                  name = toNonEscapedString(s.substring("NAME: ".length()));
2610                          } else if(s.startsWith("DEFAULT: ")) {                          } else if(s.startsWith("DEFAULT: ")) {
2611                                  b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));                                  b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));
2612                          } else {                          } else {
# Line 2594  public class Client { Line 2654  public class Client {
2654                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
2655                                    
2656                  verifyConnection();                  verifyConnection();
2657                    name = toEscapedString(name);
2658                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");
2659                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
2660                                    
# Line 2649  public class Client { Line 2710  public class Client {
2710                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
2711                          cmd.append(' ').append(info.getLoadMode().name());                          cmd.append(' ').append(info.getLoadMode().name());
2712                  }                  }
2713                  if(info.getName() != null) cmd.append(" '").append(info.getName()).append("'");                  
2714                    if(info.getName() != null) {
2715                            String s = toEscapedString(info.getName());
2716                            cmd.append(" '").append(s).append("'");
2717                    }
2718                                    
2719                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
2720                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 3498  public class Client { Line 3563  public class Client {
3563                                    
3564                  verifyConnection();                  verifyConnection();
3565                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);
3566                  if(name != null) s += " '" + name + "'";                  if(name != null) s += " '" + toEscapedString(name) + "'";
3567                  out.writeLine("CREATE FX_SEND " + s);                  out.writeLine("CREATE FX_SEND " + s);
3568                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
3569                                    
# Line 3629  public class Client { Line 3694  public class Client {
3694                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
3695                                    
3696                  verifyConnection();                  verifyConnection();
3697                  String args = " " + channel + " " + fxSend + " '" + name + "'";                  String args = " " + channel + " " + fxSend + " '" + toEscapedString(name) + "'";
3698                  out.writeLine("SET FX_SEND NAME" + args);                  out.writeLine("SET FX_SEND NAME" + args);
3699                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3700                                    
# Line 3717  public class Client { Line 3782  public class Client {
3782                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
3783          }          }
3784                    
3785            /**
3786             * Starts an instrument editor for editing the loaded instrument
3787             * on the specified sampler channel.
3788             * @param samplerChn The sampler channel number.
3789             * @throws IOException If some I/O error occurs.
3790             * @throws LscpException If LSCP protocol corruption occurs.
3791             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3792             * there is no instrument loaded on the specified sampler channel.
3793             * @see #getSamplerChannels
3794             */
3795            public synchronized void
3796            editChannelInstrument(int samplerChn) throws IOException, LscpException, LSException {
3797                    verifyConnection();
3798                    out.writeLine("EDIT CHANNEL INSTRUMENT " + samplerChn);
3799                    if(getPrintOnlyMode()) return;
3800                    
3801                    ResultSet rs = getEmptyResultSet();
3802            }
3803            
3804                    
3805                    
3806          /**          /**
3807           * Adds the specified directory to the instruments database.           * Adds the specified directory to the instruments database.
3808           * @param dir The absolute path name of the directory to add.           * @param dir The absolute (escaped) path name of the directory to add.
3809           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
3810           * @throws LSException If the creation of the directory failed.           * @throws LSException If the creation of the directory failed.
3811           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
# Line 3737  public class Client { Line 3821  public class Client {
3821                    
3822          /**          /**
3823           * Removes the specified directory from the instruments database.           * Removes the specified directory from the instruments database.
3824           * @param dir The absolute path name of the directory to remove.           * @param dir The absolute (escaped) path name of the directory to remove.
3825           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
3826           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
3827           * @throws LSException If the specified directory is not           * @throws LSException If the specified directory is not
# Line 3772  public class Client { Line 3856  public class Client {
3856                    
3857          /**          /**
3858           * Removes the specified directories from the instruments database.           * Removes the specified directories from the instruments database.
3859           * @param dirs The absolute path names of the directories to remove.           * @param dirs The absolute (escaped) path names of the directories to remove.
3860           * @param force If <code>true</code> forces the removal of non-empty           * @param force If <code>true</code> forces the removal of non-empty
3861           * directories.           * directories.
3862           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 3847  public class Client { Line 3931  public class Client {
3931                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");
3932                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
3933                                    
3934                  return parseStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
3935                    for(int i = 0; i < names.length; i++) {
3936                            names[i] = toNonEscapedString(names[i]);
3937                    }
3938                    return names;
3939          }          }
3940                    
3941          /**          /**
# Line 3869  public class Client { Line 3957  public class Client {
3957                  DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());                  DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
3958                  if(dir.equals("/")) {                  if(dir.equals("/")) {
3959                          info.setName("/");                          info.setName("/");
3960                  } else if(dir.length() > 1 && dir.charAt(dir.length() - 1) == '/') {                  } else {
3961                          dir = dir.substring(0, dir.length() - 1);                          dir = removeEndingFileSeparator(dir);
                 }  
                 int i = dir.lastIndexOf('/');  
                 if(i != -1 && i < dir.length() - 1) {  
                         info.setName(dir.substring(i + 1));  
                         if(i == 0) info.setParentDirectoryPath("/");  
                         else info.setParentDirectoryPath(dir.substring(0, i));  
3962                  }                  }
3963                    String s = getFileName(dir);
3964                    if(s != null) info.setName(toNonEscapedFileName(s));
3965                    s = getParentDirectory(dir);
3966                    if(s != null) info.setParentDirectoryPath(s);
3967                                    
3968                  return info;                  return info;
3969          }          }
# Line 3894  public class Client { Line 3980  public class Client {
3980          public synchronized DbDirectoryInfo[]          public synchronized DbDirectoryInfo[]
3981          getDbDirectories(String dir) throws IOException, LscpException, LSException {          getDbDirectories(String dir) throws IOException, LscpException, LSException {
3982                  String[] dirS = getDbDirectoryNames(dir);                  String[] dirS = getDbDirectoryNames(dir);
3983                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(!hasEndingFileSeparator(dir)) dir += "/";
3984                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3985                  for(int i = 0; i < dirS.length; i++) infoS[i] = getDbDirectoryInfo(dir + dirS[i]);                  for(int i = 0; i < dirS.length; i++) {
3986                            infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i]));
3987                    }
3988                  return infoS;                  return infoS;
3989          }          }
3990                    
# Line 3961  public class Client { Line 4049  public class Client {
4049          public synchronized void          public synchronized void
4050          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4051                  verifyConnection();                  verifyConnection();
4052                    name = toEscapedString(name);
4053                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");
4054                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4055                                    
# Line 4053  public class Client { Line 4142  public class Client {
4142                                    
4143                  verifyConnection();                  verifyConnection();
4144                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4145                  out.writeLine(s + dir + "' '" + desc + "'");                  out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'");
4146                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4147                                    
4148                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4232  public class Client { Line 4321  public class Client {
4321                                  break;                                  break;
4322                  }                  }
4323                                    
4324                  sb.append(" '").append(dbDir).append("' '").append(fsDir).append("'");                  sb.append(" '").append(dbDir).append("' '");
4325                    sb.append(fsDir).append("'");
4326                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4327                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4328                                    
# Line 4328  public class Client { Line 4418  public class Client {
4418                  out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");
4419                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4420                                    
4421                  return parseStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4422                    for(int i = 0; i < names.length; i++) {
4423                            names[i] = toNonEscapedString(names[i]);
4424                    }
4425                    return names;
4426          }          }
4427                    
4428          /**          /**
# Line 4348  public class Client { Line 4442  public class Client {
4442                                    
4443                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
4444                  DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());                  DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4445                  int i = instr.lastIndexOf('/');                  String s = getParentDirectory(instr);
4446                  if(i != -1 && i < instr.length() - 1) {                  if(s != null) info.setDirectoryPath(s);
4447                          info.setName(instr.substring(i + 1));                  s = getFileName(instr);
4448                          if(i == 0) info.setDirectoryPath("/");                  if(s != null) info.setName(toNonEscapedFileName(s));
                         else info.setDirectoryPath(instr.substring(0, i));  
                 }  
4449                                    
4450                  return info;                  return info;
4451          }          }
# Line 4370  public class Client { Line 4462  public class Client {
4462          public synchronized DbInstrumentInfo[]          public synchronized DbInstrumentInfo[]
4463          getDbInstruments(String dir) throws IOException, LscpException, LSException {          getDbInstruments(String dir) throws IOException, LscpException, LSException {
4464                  String[] instrS = getDbInstrumentNames(dir);                  String[] instrS = getDbInstrumentNames(dir);
4465                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(!hasEndingFileSeparator(dir)) dir += "/";
4466                                    
4467                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4468                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4469                          infoS[i] = getDbInstrumentInfo(dir + instrS[i]);                          infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i]));
4470                  }                  }
4471                  return infoS;                  return infoS;
4472          }          }
# Line 4442  public class Client { Line 4534  public class Client {
4534                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4535                                    
4536                  verifyConnection();                  verifyConnection();
4537                    name = toEscapedString(name);
4538                  out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");                  out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");
4539                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4540                                    
# Line 4533  public class Client { Line 4626  public class Client {
4626                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4627                                    
4628                  verifyConnection();                  verifyConnection();
4629                    desc = toEscapedString(desc);
4630                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");
4631                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4632                                    
# Line 4580  public class Client { Line 4674  public class Client {
4674                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(dir).append("'");
4675                                    
4676                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4677                          sb.append(" NAME='").append(query.name).append("'");                          sb.append(" NAME='").append(toEscapedString(query.name)).append("'");
4678                  }                  }
4679                                    
4680                  String s = query.getCreatedAfter();                  String s = query.getCreatedAfter();
# Line 4604  public class Client { Line 4698  public class Client {
4698                  }                  }
4699                                    
4700                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
4701                          sb.append(" DESCRIPTION='").append(query.description).append("'");                          sb.append(" DESCRIPTION='");
4702                            sb.append(toEscapedString(query.description)).append("'");
4703                  }                  }
4704                                    
4705                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4706                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4707                                    
4708                  String[] dirS = parseStringList(getSingleLineResultSet().getResult());                  String[] dirS = parseEscapedStringList(getSingleLineResultSet().getResult());
4709                                    
4710                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4711                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
# Line 4660  public class Client { Line 4755  public class Client {
4755                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(dir).append("'");
4756                                    
4757                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4758                          sb.append(" NAME='").append(query.name).append("'");                          sb.append(" NAME='").append(toEscapedString(query.name)).append("'");
4759                  }                  }
4760                                    
4761                  if(query.formatFamilies.size() > 0) {                  if(query.formatFamilies.size() > 0) {
# Line 4700  public class Client { Line 4795  public class Client {
4795                  }                  }
4796                                    
4797                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
4798                          sb.append(" DESCRIPTION='").append(query.description).append("'");                          sb.append(" DESCRIPTION='");
4799                            sb.append(toEscapedString(query.description)).append("'");
4800                  }                  }
4801                                    
4802                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
# Line 4713  public class Client { Line 4809  public class Client {
4809                  }                  }
4810                                    
4811                  if(query.product != null && query.product.length() > 0) {                  if(query.product != null && query.product.length() > 0) {
4812                          sb.append(" PRODUCT='").append(query.product).append("'");                          sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'");
4813                  }                  }
4814                                    
4815                  if(query.artists != null && query.artists.length() > 0) {                  if(query.artists != null && query.artists.length() > 0) {
4816                          sb.append(" ARTISTS='").append(query.artists).append("'");                          sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'");
4817                  }                  }
4818                                    
4819                  if(query.keywords != null && query.keywords.length() > 0) {                  if(query.keywords != null && query.keywords.length() > 0) {
4820                          sb.append(" KEYWORDS='").append(query.keywords).append("'");                          sb.append(" KEYWORDS='");
4821                            sb.append(toEscapedString(query.keywords)).append("'");
4822                  }                  }
4823                                    
4824                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4825                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4826                                    
4827                  String[] instrS = parseStringList(getSingleLineResultSet().getResult());                  String[] instrS = parseEscapedStringList(getSingleLineResultSet().getResult());
4828                                    
4829                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4830                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
# Line 4758  public class Client { Line 4855  public class Client {
4855          }          }
4856                    
4857          /**          /**
4858             * Removes all instruments and directories and re-creates
4859             * the instruments database structure.
4860             * @throws IOException If some I/O error occurs.
4861             * @throws LscpException If LSCP protocol corruption occurs.
4862             * @throws LSException If the formatting of the instruments database failed.
4863             */
4864            public synchronized void
4865            formatInstrumentsDb() throws IOException, LscpException, LSException {
4866                    verifyConnection();
4867                    out.writeLine("FORMAT INSTRUMENTS_DB");
4868                    if(getPrintOnlyMode()) return;
4869                    
4870                    ResultSet rs = getEmptyResultSet();
4871            }
4872            
4873            /**
4874           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4875           *           *
4876           * @param samplerChn The sampler channel number.           * @param samplerChn The sampler channel number.
# Line 4794  public class Client { Line 4907  public class Client {
4907          }          }
4908                    
4909          /**          /**
4910             * Gets the current number of all active streams.
4911             * @return The current number of all active streams.
4912             * @throws IOException If some I/O error occurs.
4913             * @throws LscpException If LSCP protocol corruption occurs.
4914             * @throws LSException If some other error occurs.
4915             */
4916            public synchronized int
4917            getTotalStreamCount() throws IOException, LscpException, LSException {
4918                    verifyConnection();
4919                    out.writeLine("GET TOTAL_STREAM_COUNT");
4920                    if(getPrintOnlyMode()) return -1;
4921                    
4922                    String s = getSingleLineResultSet().getResult();
4923                    return parseInt(s);
4924            }
4925            
4926            /**
4927           * Gets the current number of all active voices.           * Gets the current number of all active voices.
4928           * @return The current number of all active voices.           * @return The current number of all active voices.
4929           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 4882  public class Client { Line 5012  public class Client {
5012                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
5013          }          }
5014                    
5015            /**
5016             * Gets the number of instruments in the specified instrument file.
5017             * @param filename The absolute path name of the instrument file.
5018             * @return The number of instruments in the specified instrument file.
5019             * @throws IOException If some I/O error occurs.
5020             * @throws LscpException If LSCP protocol corruption occurs.
5021             * @throws LSException If the file is not found, or other error occur.
5022             */
5023            public synchronized int
5024            getFileInstrumentCount(String filename) throws IOException, LscpException, LSException {
5025                    verifyConnection();
5026                    out.writeLine("GET FILE INSTRUMENTS '" + filename +"'");
5027                    if(getPrintOnlyMode()) return -1;
5028                    
5029                    String s = getSingleLineResultSet().getResult();
5030                    return parseInt(s);
5031            }
5032            
5033            /**
5034             * Gets information about the instrument with index
5035             * <code>instrIdx</code> in the specified instrument file.
5036             * @param filename The absolute path name of the instrument file.
5037             * @param instrIdx The index of the instrument in the specified instrument file.
5038             * @throws IOException If some I/O error occurs.
5039             * @throws LscpException If LSCP protocol corruption occurs.
5040             * @throws LSException If failed to retrieve information.
5041             */
5042            public synchronized Instrument
5043            getFileInstrumentInfo(String filename, int instrIdx)
5044                                    throws IOException, LscpException, LSException {
5045                    
5046                    verifyConnection();
5047                    out.writeLine("GET FILE INSTRUMENT INFO '" + filename + "' " + String.valueOf(instrIdx));
5048                    if(getPrintOnlyMode()) return null;
5049                    
5050                    ResultSet rs = getMultiLineResultSet();
5051                    Instrument instr = new FileInstrument(rs.getMultiLineResult()) { };
5052                    
5053                    return instr;
5054            }
5055            
5056            /**
5057             * Gets the list of instruments in the specified instrument file.
5058             * @param filename The absolute path name of the instrument file.
5059             * @return An <code>Instrument</code> array providing
5060             * information about all instruments in the specified instrument file.
5061             * @throws IOException If some I/O error occurs.
5062             * @throws LscpException If LSCP protocol corruption occurs.
5063             * @throws LSException If the specified file name is invalid.
5064             */
5065            public synchronized Instrument[]
5066            getFileInstruments(String filename) throws IOException, LscpException, LSException {
5067                    int l = getFileInstrumentCount(filename);
5068                    if(l < 0) return null;
5069                    Instrument[] instrS = new FileInstrument[l];
5070                    
5071                    for(int i = 0; i < instrS.length; i++) {
5072                            instrS[i] = getFileInstrumentInfo(filename, i);
5073                    }
5074                    return instrS;
5075            }
5076            
5077            private static class FileInstrument extends AbstractInstrument {
5078                    FileInstrument(String[] resultSet) throws LscpException {
5079                            super(resultSet);
5080                    }
5081                    
5082                    public String
5083                    getEngine() {
5084                            // TODO: engine lookup?
5085                            return getFormatFamily();
5086                    }
5087                    
5088                    public boolean
5089                    parse(String s) throws LscpException {
5090                            if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true;
5091                            return super.parse(s);
5092                    }
5093            }
5094            
5095          private void          private void
5096          getEmptyResultSets(int count, String err) throws LSException {          getEmptyResultSets(int count, String err) throws LSException {
5097                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();

Legend:
Removed from v.1202  
changed lines
  Added in v.1542

  ViewVC Help
Powered by ViewVC