/[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 1728 by iliev, Tue Apr 29 16:04:42 2008 UTC
# Line 1  Line 1 
1  /*  /*
2   *   jlscp - a java LinuxSampler control protocol API   *   jlscp - a java LinuxSampler control protocol API
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 jlscp.   *   This file is part of jlscp.
7   *   *
# 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
44   * instance. Since it implements all commands specified in the LSCP protocol v1.1, for more   * instance. Since it implements all commands specified in the LSCP protocol v1.2, for more
45   * information look at the   * information look at the
46   * <a href=http://www.linuxsampler.org/api/lscp-1.1.html>LSCP</a> specification.   * <a href=http://www.linuxsampler.org/api/lscp-1.2.html>LSCP</a> specification.
47   *   *
48   * <p> The following code establishes connection to LinuxSampler instance and gets the   * <p> The following code establishes connection to LinuxSampler instance and gets the
49   * LinuxSampler version:   * LinuxSampler version:
# Line 163  public class Client { Line 164  public class Client {
164                  if(printOnlyMode) setPrintOnlyMode(true);                  if(printOnlyMode) setPrintOnlyMode(true);
165          }          }
166                    
167            private boolean extendedCharacterEscaping = true;
168            
169            /**
170             * Sets whether strings sent to LinuxSampler should be more aggressively escaped.
171             */
172            public synchronized void
173            setExtendedCharacterEscaping(boolean b) { extendedCharacterEscaping = b; }
174            
175            /**
176             * Determines whether strings sent to LinuxSampler should be more aggressively escaped.
177             */
178            public synchronized boolean
179            getExtendedCharacterEscaping() { return extendedCharacterEscaping; }
180            
181            private String
182            toEscapedText(String s) {
183                    s = toEscapedString(s);
184                    return conv(s);
185            }
186            
187            private String
188            toEscapedFsEntry(String s) {
189                    s = toEscapedFileName(s);
190                    return conv(s);
191            }
192            
193            /**
194             * Applies an extended character escaping to the specified string if needed.
195             */
196            private String
197            conv(String s) {
198                    return getExtendedCharacterEscaping() ? toExtendedEscapeSequence(s) : s;
199            }
200            
201          /**          /**
202           * Determines whether the client is in print-only mode.           * Determines whether the client is in print-only mode.
203           * Print-only mode means that the client will just print all           * Print-only mode means that the client will just print all
# Line 343  public class Client { Line 378  public class Client {
378                  if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");                  if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");
379                  if(!llSC.isEmpty()) subscribe("STREAM_COUNT");                  if(!llSC.isEmpty()) subscribe("STREAM_COUNT");
380                  if(!llVC.isEmpty()) subscribe("VOICE_COUNT");                  if(!llVC.isEmpty()) subscribe("VOICE_COUNT");
381                    if(!llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
382                  if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");                  if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");
383                  if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");                  if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");
384                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
# Line 353  public class Client { Line 389  public class Client {
389                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
390                          subscribe("DB_INSTRUMENT_COUNT");                          subscribe("DB_INSTRUMENT_COUNT");
391                          subscribe("DB_INSTRUMENT_INFO");                          subscribe("DB_INSTRUMENT_INFO");
392                            subscribe("DB_INSTRUMENTS_JOB_INFO");
393                  }                  }
394                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
395          }          }
# Line 484  public class Client { Line 521  public class Client {
521          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();
522          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();
523          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();
524            private final Vector<TotalStreamCountListener> llTSC = new Vector<TotalStreamCountListener>();
525          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();
526                    
527          /** MIDI instrument map count listeners */          /** MIDI instrument map count listeners */
# Line 521  public class Client { Line 559  public class Client {
559                          !llMIDI.isEmpty() ||                          !llMIDI.isEmpty() ||
560                          !llSC.isEmpty()   ||                          !llSC.isEmpty()   ||
561                          !llVC.isEmpty()   ||                          !llVC.isEmpty()   ||
562                            !llTSC.isEmpty()  ||
563                          !llTVC.isEmpty()  ||                          !llTVC.isEmpty()  ||
564                          !llMIMC.isEmpty() ||                          !llMIMC.isEmpty() ||
565                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
# Line 542  public class Client { Line 581  public class Client {
581                          if(s.startsWith("NAME ")) {                          if(s.startsWith("NAME ")) {
582                                  String[] list;                                  String[] list;
583                                  try {                                  try {
584                                          list = parseStringList(s.substring("NAME ".length()), ' ');                                          s = s.substring("NAME ".length());
585                                            list = parseEscapedStringList(s, ' ');
586                                          if(list.length != 2) throw new LscpException();                                          if(list.length != 2) throw new LscpException();
587                                            list[1] = toNonEscapedString(list[1]);
588                                          e = new InstrumentsDbEvent(this, list[0], list[1]);                                          e = new InstrumentsDbEvent(this, list[0], list[1]);
589                                          for(InstrumentsDbListener l : llID) {                                          for(InstrumentsDbListener l : llID) {
590                                                  l.directoryNameChanged(e);                                                  l.directoryNameChanged(e);
# Line 569  public class Client { Line 610  public class Client {
610                          if(s.startsWith("NAME ")) {                          if(s.startsWith("NAME ")) {
611                                  String[] list;                                  String[] list;
612                                  try {                                  try {
613                                          list = parseStringList(s.substring("NAME ".length()), ' ');                                          s = s.substring("NAME ".length());
614                                            list = parseEscapedStringList(s, ' ');
615                                          if(list.length != 2) throw new LscpException();                                          if(list.length != 2) throw new LscpException();
616                                            list[1] = toNonEscapedString(list[1]);
617                                          e = new InstrumentsDbEvent(this, list[0], list[1]);                                          e = new InstrumentsDbEvent(this, list[0], list[1]);
618                                          for(InstrumentsDbListener l : llID) {                                          for(InstrumentsDbListener l : llID) {
619                                                  l.instrumentNameChanged(e);                                                  l.instrumentNameChanged(e);
# Line 657  public class Client { Line 700  public class Client {
700                          } catch(NumberFormatException x) {                          } catch(NumberFormatException x) {
701                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);
702                          }                          }
703                    } else if(s.startsWith("TOTAL_STREAM_COUNT:")) {
704                            try {
705                                    s = s.substring("TOTAL_STREAM_COUNT:".length());
706                                    int i = Integer.parseInt(s);
707                                    TotalStreamCountEvent e = new TotalStreamCountEvent(this, i);
708                                    for(TotalStreamCountListener l : llTSC) l.totalStreamCountChanged(e);
709                            } catch(NumberFormatException x) {
710                                    getLogger().log (
711                                            Level.WARNING, "Unknown TOTAL_STREAM_COUNT format", x
712                                    );
713                            }
714                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {
715                          try {                          try {
716                                  s = s.substring("TOTAL_VOICE_COUNT:".length());                                  s = s.substring("TOTAL_VOICE_COUNT:".length());
# Line 1129  public class Client { Line 1183  public class Client {
1183          /**          /**
1184           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1185           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1186             * @param l The <code>TotalStreamCountListener</code> to register.
1187             */
1188            public synchronized void
1189            addTotalStreamCountListener(TotalStreamCountListener l) {
1190                    if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
1191                    llTSC.add(l);
1192            }
1193            
1194            /**
1195             * Removes the specified listener.
1196             * Listeners can be removed regardless of the connection state.
1197             * @param l The <code>TotalStreamCountListener</code> to remove.
1198             */
1199            public synchronized void
1200            removeTotalStreamCountListener(TotalStreamCountListener l) {
1201                    boolean b = llTSC.remove(l);
1202                    if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT");
1203            }
1204            
1205            /**
1206             * Registers the specified listener for receiving event messages.
1207             * Listeners can be registered regardless of the connection state.
1208           * @param l The <code>TotalVoiceCountListener</code> to register.           * @param l The <code>TotalVoiceCountListener</code> to register.
1209           */           */
1210          public synchronized void          public synchronized void
# Line 1355  public class Client { Line 1431  public class Client {
1431          /**          /**
1432           * Gets detailed information about a specific audio output driver.           * Gets detailed information about a specific audio output driver.
1433           * @param driverName The name of the audio output driver.           * @param driverName The name of the audio output driver.
1434           *           * @param depList An optional list of dependences parameters.
1435           * @return An <code>AudioOutputDriver</code> object containing           * @return An <code>AudioOutputDriver</code> object containing
1436           * information about the specified audio output driver.           * information about the specified audio output driver.
1437           *           *
# Line 1365  public class Client { Line 1441  public class Client {
1441           *           *
1442           * @see #getAudioOutputDriverNames           * @see #getAudioOutputDriverNames
1443           */           */
1444          private synchronized AudioOutputDriver          public synchronized AudioOutputDriver
1445          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getAudioOutputDriverInfo(String driverName, Parameter... depList)
1446                                            throws IOException, LscpException, LSException {
1447                    
1448                  verifyConnection();                  verifyConnection();
1449                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
1450                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1376  public class Client { Line 1454  public class Client {
1454                  aod.setName(driverName);                  aod.setName(driverName);
1455                                    
1456                  for(String s : aod.getParameterNames())                  for(String s : aod.getParameterNames())
1457                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s));                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s, depList));
1458                                    
1459                  return aod;                  return aod;
1460          }          }
# Line 1410  public class Client { Line 1488  public class Client {
1488                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
1489                  args.append(' ').append(param);                  args.append(' ').append(param);
1490                                    
1491                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
1492                            if(p == null || p.getName() == null || p.getValue() == null) continue;
1493                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1494                    }
1495                                    
1496                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());
1497                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1472  public class Client { Line 1552  public class Client {
1552                  verifyConnection();                  verifyConnection();
1553                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1554                                    
1555                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
1556                            if(p == null || p.getName() == null || p.getValue() == null) continue;
1557                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1558                    }
1559                                    
1560                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());
1561                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 1934  public class Client { Line 2016  public class Client {
2016          /**          /**
2017           * Gets detailed information about a specific MIDI input driver.           * Gets detailed information about a specific MIDI input driver.
2018           * @param driverName The name of the MIDI input driver.           * @param driverName The name of the MIDI input driver.
2019           *           * @param depList An optional list of dependences parameters.
2020           * @return A <code>MidiInputDriver</code> object containing           * @return A <code>MidiInputDriver</code> object containing
2021           * information about the specified MIDI input driver.           * information about the specified MIDI input driver.
2022           *           *
# Line 1944  public class Client { Line 2026  public class Client {
2026           *           *
2027           * @see #getMidiInputDriverNames           * @see #getMidiInputDriverNames
2028           */           */
2029          private synchronized MidiInputDriver          public synchronized MidiInputDriver
2030          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getMidiInputDriverInfo(String driverName, Parameter... depList)
2031                                            throws IOException, LscpException, LSException {
2032                    
2033                  verifyConnection();                  verifyConnection();
2034                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
2035                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1956  public class Client { Line 2040  public class Client {
2040                  mid.setName(driverName);                  mid.setName(driverName);
2041                                    
2042                  for(String s : mid.getParameterNames())                  for(String s : mid.getParameterNames())
2043                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s));                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s, depList));
2044                                    
2045                  return mid;                  return mid;
2046          }          }
# Line 1990  public class Client { Line 2074  public class Client {
2074                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
2075                  args.append(' ').append(param);                  args.append(' ').append(param);
2076                                    
2077                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
2078                            if(p == null || p.getName() == null || p.getValue() == null) continue;
2079                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2080                    }
2081                                    
2082                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());
2083                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 2053  public class Client { Line 2139  public class Client {
2139                  verifyConnection();                  verifyConnection();
2140                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2141                                    
2142                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
2143                            if(p == null || p.getName() == null || p.getValue() == null) continue;
2144                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2145                    }
2146                                    
2147                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());
2148                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 2199  public class Client { Line 2287  public class Client {
2287                                  mid.setActive(Boolean.parseBoolean(s));                                  mid.setActive(Boolean.parseBoolean(s));
2288                          } else if(s.startsWith("PORTS: ")) {                          } else if(s.startsWith("PORTS: ")) {
2289                                  s = s.substring("PORTS: ".length());                                  s = s.substring("PORTS: ".length());
2290                                  int ports = Parser.parseInt(s);                                  
2291                                  MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0];                                  Parameter<Integer> ports = (Parameter<Integer>)
2292                                            getMidiInputDriverParameterInfo(drv, "PORTS");
2293                                    
2294                                    ports.parseValue(s);
2295                                    mid.setPortsParameter(ports);
2296                                    
2297                                    int j = ports.getValue();
2298                                    MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0];
2299                                                                    
2300                                  for(int i = 0; i < midiPorts.length; i++)                                  for(int i = 0; i < midiPorts.length; i++)
2301                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);
# Line 2443  public class Client { Line 2538  public class Client {
2538          public synchronized int          public synchronized int
2539          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {
2540                  verifyConnection();                  verifyConnection();
2541                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + name + "'");                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedText(name) + "'");
2542                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
2543                                    
2544                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 2546  public class Client { Line 2641  public class Client {
2641                                    
2642                  for(String s : lnS) {                  for(String s : lnS) {
2643                          if(s.startsWith("NAME: ")) {                          if(s.startsWith("NAME: ")) {
2644                                  name = s.substring("NAME: ".length());                                  name = toNonEscapedString(s.substring("NAME: ".length()));
2645                          } else if(s.startsWith("DEFAULT: ")) {                          } else if(s.startsWith("DEFAULT: ")) {
2646                                  b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));                                  b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));
2647                          } else {                          } else {
# Line 2594  public class Client { Line 2689  public class Client {
2689                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
2690                                    
2691                  verifyConnection();                  verifyConnection();
2692                    name = toEscapedText(name);
2693                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");
2694                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
2695                                    
# Line 2643  public class Client { Line 2739  public class Client {
2739                  cmd.append(entry.getMidiBank()).append(' ');                  cmd.append(entry.getMidiBank()).append(' ');
2740                  cmd.append(entry.getMidiProgram()).append(' ');                  cmd.append(entry.getMidiProgram()).append(' ');
2741                  cmd.append(info.getEngine()).append(" '");                  cmd.append(info.getEngine()).append(" '");
2742                  cmd.append(info.getFilePath()).append("' ");                  cmd.append(conv(info.getFilePath())).append("' ");
2743                  cmd.append(info.getInstrumentIndex()).append(' ');                  cmd.append(info.getInstrumentIndex()).append(' ');
2744                  cmd.append(info.getVolume());                  cmd.append(info.getVolume());
2745                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
2746                          cmd.append(' ').append(info.getLoadMode().name());                          cmd.append(' ').append(info.getLoadMode().name());
2747                  }                  }
2748                  if(info.getName() != null) cmd.append(" '").append(info.getName()).append("'");                  
2749                    if(info.getName() != null) {
2750                            String s = toEscapedText(info.getName());
2751                            cmd.append(" '").append(s).append("'");
2752                    }
2753                                    
2754                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
2755                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 2738  public class Client { Line 2838  public class Client {
2838          }          }
2839                    
2840          /**          /**
2841           * Gets all MIDI instrument contained int the specified MIDI instrument map.           * Gets all MIDI instrument entries contained int the specified MIDI instrument map.
2842             * @param mapId The ID of the map, which instruments should be obtained.
2843             * @return An int array providing all MIDI instrument entries
2844             * in the specified MIDI instrument map.
2845             * @throws IOException If some I/O error occurs.
2846             * @throws LscpException If LSCP protocol corruption occurs.
2847             * @throws LSException If some other error occurs.
2848             */
2849            public synchronized int[][]
2850            getMidiInstrumentEntries(int mapId) throws IOException, LscpException, LSException {
2851                    verifyConnection();
2852                    out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId));
2853                    if(getPrintOnlyMode()) return null;
2854                    
2855                    String[] entries = parseArray(getSingleLineResultSet().getResult());
2856                    int[][] e = new int[entries.length][3];
2857                    
2858                    for(int i = 0; i < entries.length; i++) {
2859                            Integer[] vals = parseIntList(entries[i]);
2860                            if(vals.length != 3) {
2861                                    throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
2862                            }
2863                            
2864                            e[i][0] = vals[0];
2865                            e[i][1] = vals[1];
2866                            e[i][2] = vals[2];
2867                    }
2868                    
2869                    return e;
2870            }
2871            
2872            /**
2873             * Gets all MIDI instruments contained int the specified MIDI instrument map.
2874           * @param mapId The ID of the map, which instruments should be obtained.           * @param mapId The ID of the map, which instruments should be obtained.
2875           * @return A <code>MidiInstrumentInfo</code> array providing           * @return A <code>MidiInstrumentInfo</code> array providing
2876           * all MIDI instruments from all MIDI instrument maps.           * all MIDI instruments in the specified MIDI instrument map.
2877           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
2878           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
2879           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
# Line 2789  public class Client { Line 2921  public class Client {
2921                                          throws IOException, LscpException, LSException {                                          throws IOException, LscpException, LSException {
2922                    
2923                  verifyConnection();                  verifyConnection();
2924                    requestMidiInstrumentInfo(mapId, bank, program);
2925                    return getMidiInstrumentInfoResponse(mapId, bank, program);
2926            }
2927            
2928            private void
2929            requestMidiInstrumentInfo(int mapId, int bank, int program) throws IOException {
2930                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");
2931                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
2932                  cmd.append(bank).append(' ');                  cmd.append(bank).append(' ');
2933                  cmd.append(program);                  cmd.append(program);
2934                                    
2935                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
2936                  if(getPrintOnlyMode()) return null;          }
2937            
2938            private MidiInstrumentInfo
2939            getMidiInstrumentInfoResponse(int mapId, int bank, int program)
2940                                            throws IOException, LscpException, LSException {
2941                                    
2942                    if(getPrintOnlyMode()) return null;
2943                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
2944                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
2945                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());
# Line 2846  public class Client { Line 2989  public class Client {
2989                                                  throws IOException, LscpException, LSException {                                                  throws IOException, LscpException, LSException {
2990                                    
2991                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";
2992                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;                  String args = '\'' + conv(filename) + "' " + instrIdx + ' ' + samplerChn;
2993                                    
2994                  out.writeLine(cmd + args);                  out.writeLine(cmd + args);
2995                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 3498  public class Client { Line 3641  public class Client {
3641                                    
3642                  verifyConnection();                  verifyConnection();
3643                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);
3644                  if(name != null) s += " '" + name + "'";                  if(name != null) s += " '" + toEscapedText(name) + "'";
3645                  out.writeLine("CREATE FX_SEND " + s);                  out.writeLine("CREATE FX_SEND " + s);
3646                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
3647                                    
# Line 3629  public class Client { Line 3772  public class Client {
3772                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
3773                                    
3774                  verifyConnection();                  verifyConnection();
3775                  String args = " " + channel + " " + fxSend + " '" + name + "'";                  String args = " " + channel + " " + fxSend + " '" + toEscapedText(name) + "'";
3776                  out.writeLine("SET FX_SEND NAME" + args);                  out.writeLine("SET FX_SEND NAME" + args);
3777                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3778                                    
# Line 3717  public class Client { Line 3860  public class Client {
3860                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
3861          }          }
3862                    
3863            /**
3864             * Starts an instrument editor for editing the loaded instrument
3865             * on the specified sampler channel.
3866             * @param samplerChn The sampler channel number.
3867             * @throws IOException If some I/O error occurs.
3868             * @throws LscpException If LSCP protocol corruption occurs.
3869             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3870             * there is no instrument loaded on the specified sampler channel.
3871             * @see #getSamplerChannels
3872             */
3873            public synchronized void
3874            editChannelInstrument(int samplerChn) throws IOException, LscpException, LSException {
3875                    verifyConnection();
3876                    out.writeLine("EDIT CHANNEL INSTRUMENT " + samplerChn);
3877                    if(getPrintOnlyMode()) return;
3878                    
3879                    ResultSet rs = getEmptyResultSet();
3880            }
3881            
3882                    
3883                    
3884          /**          /**
3885           * Adds the specified directory to the instruments database.           * Adds the specified directory to the instruments database.
3886           * @param dir The absolute path name of the directory to add.           * @param dir The absolute (escaped) path name of the directory to add.
3887           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
3888           * @throws LSException If the creation of the directory failed.           * @throws LSException If the creation of the directory failed.
3889           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
# Line 3729  public class Client { Line 3891  public class Client {
3891          public synchronized void          public synchronized void
3892          addDbDirectory(String dir) throws IOException, LSException, LscpException {          addDbDirectory(String dir) throws IOException, LSException, LscpException {
3893                  verifyConnection();                  verifyConnection();
3894                  out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");                  out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "'");
3895                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3896                                    
3897                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3737  public class Client { Line 3899  public class Client {
3899                    
3900          /**          /**
3901           * Removes the specified directory from the instruments database.           * Removes the specified directory from the instruments database.
3902           * @param dir The absolute path name of the directory to remove.           * @param dir The absolute (escaped) path name of the directory to remove.
3903           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
3904           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
3905           * @throws LSException If the specified directory is not           * @throws LSException If the specified directory is not
# Line 3764  public class Client { Line 3926  public class Client {
3926                  verifyConnection();                  verifyConnection();
3927                  String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";                  String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3928                  if(force) s += "FORCE ";                  if(force) s += "FORCE ";
3929                  out.writeLine(s + "'" + dir + "'");                  out.writeLine(s + "'" + conv(dir) + "'");
3930                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3931                                    
3932                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3772  public class Client { Line 3934  public class Client {
3934                    
3935          /**          /**
3936           * Removes the specified directories from the instruments database.           * Removes the specified directories from the instruments database.
3937           * @param dirs The absolute path names of the directories to remove.           * @param dirs The absolute (escaped) path names of the directories to remove.
3938           * @param force If <code>true</code> forces the removal of non-empty           * @param force If <code>true</code> forces the removal of non-empty
3939           * directories.           * directories.
3940           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 3787  public class Client { Line 3949  public class Client {
3949                  String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";                  String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3950                  if(force) cmd += "FORCE ";                  if(force) cmd += "FORCE ";
3951                                    
3952                  for(String s : dirs) out.writeLine(cmd + "'" + s + "'");                  for(String s : dirs) out.writeLine(cmd + "'" + conv(s) + "'");
3953                                    
3954                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3955                                    
# Line 3825  public class Client { Line 3987  public class Client {
3987                  String s;                  String s;
3988                  if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";                  if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
3989                  else s = "GET DB_INSTRUMENT_DIRECTORIES '";                  else s = "GET DB_INSTRUMENT_DIRECTORIES '";
3990                  out.writeLine(s + dir + "'");                  out.writeLine(s + conv(dir) + "'");
3991                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
3992                                    
3993                  s = getSingleLineResultSet().getResult();                  s = getSingleLineResultSet().getResult();
# Line 3844  public class Client { Line 4006  public class Client {
4006          public synchronized String[]          public synchronized String[]
4007          getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {          getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
4008                  verifyConnection();                  verifyConnection();
4009                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + conv(dir) + "'");
4010                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4011                                    
4012                  return parseStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4013                    for(int i = 0; i < names.length; i++) {
4014                            names[i] = toNonEscapedString(names[i]);
4015                    }
4016                    return names;
4017          }          }
4018                    
4019          /**          /**
# Line 3862  public class Client { Line 4028  public class Client {
4028          public synchronized DbDirectoryInfo          public synchronized DbDirectoryInfo
4029          getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {          getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
4030                  verifyConnection();                  verifyConnection();
4031                  out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");                  out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir) + "'");
4032                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4033                                    
4034                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
4035                  DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());                  DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
4036                  if(dir.equals("/")) {                  if(dir.equals("/")) {
4037                          info.setName("/");                          info.setName("/");
4038                  } else if(dir.length() > 1 && dir.charAt(dir.length() - 1) == '/') {                  } else {
4039                          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));  
4040                  }                  }
4041                    String s = getFileName(dir);
4042                    if(s != null) info.setName(toNonEscapedFileName(s));
4043                    s = getParentDirectory(dir);
4044                    if(s != null) info.setParentDirectoryPath(s);
4045                                    
4046                  return info;                  return info;
4047          }          }
# Line 3894  public class Client { Line 4058  public class Client {
4058          public synchronized DbDirectoryInfo[]          public synchronized DbDirectoryInfo[]
4059          getDbDirectories(String dir) throws IOException, LscpException, LSException {          getDbDirectories(String dir) throws IOException, LscpException, LSException {
4060                  String[] dirS = getDbDirectoryNames(dir);                  String[] dirS = getDbDirectoryNames(dir);
4061                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(!hasEndingFileSeparator(dir)) dir += "/";
4062                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4063                  for(int i = 0; i < dirS.length; i++) infoS[i] = getDbDirectoryInfo(dir + dirS[i]);                  for(int i = 0; i < dirS.length; i++) {
4064                            infoS[i] = getDbDirectoryInfo(conv(dir) + toEscapedFsEntry(dirS[i]));
4065                    }
4066                  return infoS;                  return infoS;
4067          }          }
4068                    
# Line 3911  public class Client { Line 4077  public class Client {
4077           *           *
4078          public synchronized DbDirectoryInfo[]          public synchronized DbDirectoryInfo[]
4079          getDbDirectories(String dir) throws IOException, LscpException, LSException {          getDbDirectories(String dir) throws IOException, LscpException, LSException {
4080                  String[] dirS = getDbDirectoryNames(dir);                  String[] dirS = getDbDirectoryNames(conv(dir));
4081                  if(dirS.length == 0) return new DbDirectoryInfo[0];                  if(dirS.length == 0) return new DbDirectoryInfo[0];
4082                                    
4083                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(dir.charAt(dir.length() - 1) != '/') dir += "/"; // FIXME:
4084                                    
4085                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
4086                          out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");                          out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir + dirS[i]) + "'");
4087                  }                  }
4088                                    
4089                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 3961  public class Client { Line 4127  public class Client {
4127          public synchronized void          public synchronized void
4128          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4129                  verifyConnection();                  verifyConnection();
4130                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");                  name = toEscapedText(name);
4131                    out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + conv(dir) + "' '" + conv(name) + "'");
4132                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4133                                    
4134                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3978  public class Client { Line 4145  public class Client {
4145          public synchronized void          public synchronized void
4146          moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {          moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4147                  verifyConnection();                  verifyConnection();
4148                  out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");                  out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4149                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4150                                    
4151                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3996  public class Client { Line 4163  public class Client {
4163          moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {          moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4164                  verifyConnection();                  verifyConnection();
4165                  for(String s : dirs) {                  for(String s : dirs) {
4166                          out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");                          out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4167                  }                  }
4168                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4169                                    
# Line 4014  public class Client { Line 4181  public class Client {
4181          public synchronized void          public synchronized void
4182          copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {          copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4183                  verifyConnection();                  verifyConnection();
4184                  out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");                  out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4185                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4186                                    
4187                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4032  public class Client { Line 4199  public class Client {
4199          copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {          copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4200                  verifyConnection();                  verifyConnection();
4201                  for(String s : dirs) {                  for(String s : dirs) {
4202                          out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");                          out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4203                  }                  }
4204                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4205                                    
# Line 4053  public class Client { Line 4220  public class Client {
4220                                    
4221                  verifyConnection();                  verifyConnection();
4222                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4223                  out.writeLine(s + dir + "' '" + desc + "'");                  out.writeLine(s + conv(dir) + "' '" + toEscapedText(desc) + "'");
4224                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4225                                    
4226                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4102  public class Client { Line 4269  public class Client {
4269                  verifyConnection();                  verifyConnection();
4270                  String s = "ADD DB_INSTRUMENTS";                  String s = "ADD DB_INSTRUMENTS";
4271                  if(background) s += " NON_MODAL";                  if(background) s += " NON_MODAL";
4272                  s += " '" + dbDir + "' '" + filePath + "' ";                  s += " '" + conv(dbDir) + "' '" + conv(filePath) + "' ";
4273                  out.writeLine(s + String.valueOf(instrIndex));                  out.writeLine(s + String.valueOf(instrIndex));
4274                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4275                                    
# Line 4149  public class Client { Line 4316  public class Client {
4316                  verifyConnection();                  verifyConnection();
4317                  String s = "ADD DB_INSTRUMENTS";                  String s = "ADD DB_INSTRUMENTS";
4318                  if(background) s += " NON_MODAL";                  if(background) s += " NON_MODAL";
4319                  out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");                  out.writeLine(s + " '" + conv(dbDir) + "' '" + conv(filePath) + "'");
4320                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4321                                    
4322                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4232  public class Client { Line 4399  public class Client {
4399                                  break;                                  break;
4400                  }                  }
4401                                    
4402                  sb.append(" '").append(dbDir).append("' '").append(fsDir).append("'");                  sb.append(" '").append(conv(dbDir)).append("' '");
4403                    sb.append(conv(fsDir)).append("'");
4404                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4405                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4406                                    
# Line 4251  public class Client { Line 4419  public class Client {
4419          removeDbInstrument(String instr) throws IOException, LscpException, LSException {          removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4420                                    
4421                  verifyConnection();                  verifyConnection();
4422                  out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");                  out.writeLine("REMOVE DB_INSTRUMENT '" + conv(instr) + "'");
4423                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4424                                    
4425                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4268  public class Client { Line 4436  public class Client {
4436          removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {          removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4437                  verifyConnection();                  verifyConnection();
4438                  for(String s : instrs) {                  for(String s : instrs) {
4439                          out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");                          out.writeLine("REMOVE DB_INSTRUMENT '" + conv(s) + "'");
4440                  }                  }
4441                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4442                                    
# Line 4306  public class Client { Line 4474  public class Client {
4474                  String s;                  String s;
4475                  if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";                  if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4476                  else s = "GET DB_INSTRUMENTS '";                  else s = "GET DB_INSTRUMENTS '";
4477                  out.writeLine(s + dir + "'");                  out.writeLine(s + conv(dir) + "'");
4478                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4479                                    
4480                  s = getSingleLineResultSet().getResult();                  s = getSingleLineResultSet().getResult();
# Line 4325  public class Client { Line 4493  public class Client {
4493          public synchronized String[]          public synchronized String[]
4494          getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {          getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4495                  verifyConnection();                  verifyConnection();
4496                  out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENTS '" + conv(dir) + "'");
4497                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4498                                    
4499                  return parseStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4500                    for(int i = 0; i < names.length; i++) {
4501                            names[i] = toNonEscapedString(names[i]);
4502                    }
4503                    return names;
4504          }          }
4505                    
4506          /**          /**
# Line 4343  public class Client { Line 4515  public class Client {
4515          public synchronized DbInstrumentInfo          public synchronized DbInstrumentInfo
4516          getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {          getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4517                  verifyConnection();                  verifyConnection();
4518                  out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");                  out.writeLine("GET DB_INSTRUMENT INFO '" + conv(instr) + "'");
4519                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4520                                    
4521                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
4522                  DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());                  DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4523                  int i = instr.lastIndexOf('/');                  String s = getParentDirectory(instr);
4524                  if(i != -1 && i < instr.length() - 1) {                  if(s != null) info.setDirectoryPath(s);
4525                          info.setName(instr.substring(i + 1));                  s = getFileName(instr);
4526                          if(i == 0) info.setDirectoryPath("/");                  if(s != null) info.setName(toNonEscapedFileName(s));
                         else info.setDirectoryPath(instr.substring(0, i));  
                 }  
4527                                    
4528                  return info;                  return info;
4529          }          }
# Line 4370  public class Client { Line 4540  public class Client {
4540          public synchronized DbInstrumentInfo[]          public synchronized DbInstrumentInfo[]
4541          getDbInstruments(String dir) throws IOException, LscpException, LSException {          getDbInstruments(String dir) throws IOException, LscpException, LSException {
4542                  String[] instrS = getDbInstrumentNames(dir);                  String[] instrS = getDbInstrumentNames(dir);
4543                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(!hasEndingFileSeparator(dir)) dir += "/";
4544                                    
4545                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4546                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4547                          infoS[i] = getDbInstrumentInfo(dir + instrS[i]);                          infoS[i] = getDbInstrumentInfo(conv(dir) + toEscapedFsEntry(instrS[i]));
4548                  }                  }
4549                  return infoS;                  return infoS;
4550          }          }
# Line 4393  public class Client { Line 4563  public class Client {
4563                  String[] instrS = getDbInstrumentNames(dir);                  String[] instrS = getDbInstrumentNames(dir);
4564                  if(instrS.length == 0) return new DbInstrumentInfo[0];                  if(instrS.length == 0) return new DbInstrumentInfo[0];
4565                                    
4566                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(dir.charAt(dir.length() - 1) != '/') dir += "/"; FIXME:
4567                                    
4568                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4569                          out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");                          out.writeLine("GET DB_INSTRUMENT INFO '" + conv(dir) + instrS[i] + "'");
4570                  }                  }
4571                                    
4572                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 4442  public class Client { Line 4612  public class Client {
4612                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4613                                    
4614                  verifyConnection();                  verifyConnection();
4615                  out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");                  name = toEscapedText(name);
4616                    out.writeLine("SET DB_INSTRUMENT NAME '" + conv(instr) + "' '" + conv(name) + "'");
4617                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4618                                    
4619                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4459  public class Client { Line 4630  public class Client {
4630          public synchronized void          public synchronized void
4631          moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {          moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4632                  verifyConnection();                  verifyConnection();
4633                  out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");                  out.writeLine("MOVE DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4634                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4635                                    
4636                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4477  public class Client { Line 4648  public class Client {
4648          moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {          moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4649                  verifyConnection();                  verifyConnection();
4650                  for(String s : instrs) {                  for(String s : instrs) {
4651                          out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");                          out.writeLine("MOVE DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4652                  }                  }
4653                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4654                                    
# Line 4495  public class Client { Line 4666  public class Client {
4666          public synchronized void          public synchronized void
4667          copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {          copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4668                  verifyConnection();                  verifyConnection();
4669                  out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");                  out.writeLine("COPY DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4670                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4671                                    
4672                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4513  public class Client { Line 4684  public class Client {
4684          copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {          copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4685                  verifyConnection();                  verifyConnection();
4686                  for(String s : instrs) {                  for(String s : instrs) {
4687                          out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");                          out.writeLine("COPY DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4688                  }                  }
4689                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4690                                    
# Line 4533  public class Client { Line 4704  public class Client {
4704                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4705                                    
4706                  verifyConnection();                  verifyConnection();
4707                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");                  desc = toEscapedText(desc);
4708                    out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + conv(instr) + "' '" + desc + "'");
4709                    if(getPrintOnlyMode()) return;
4710                    
4711                    ResultSet rs = getEmptyResultSet();
4712            }
4713            
4714            /**
4715             * Substitutes all occurrences of the instrument file
4716             * <code>oldPath</code> in the database, with <code>newPath</code>.
4717             * @param oldPath The absolute path name of the instrument file to substitute.
4718             * @param newPath The new absolute path name.
4719             * @throws IOException If some I/O error occurs.
4720             * @throws LSException If the operation failed.
4721             * @throws LscpException If LSCP protocol corruption occurs.
4722             */
4723            public synchronized void
4724            setDbInstrumentFilePath(String oldPath, String newPath)
4725                                    throws IOException, LSException, LscpException {
4726                    
4727                    verifyConnection();
4728                    out.writeLine("SET DB_INSTRUMENT FILE_PATH '" + conv(oldPath) + "' '" + conv(newPath) + "'");
4729                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4730                                    
4731                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4577  public class Client { Line 4769  public class Client {
4769                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
4770                  sb.append("FIND DB_INSTRUMENT_DIRECTORIES");                  sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4771                  if(nonRecursive) sb.append(" NON_RECURSIVE");                  if(nonRecursive) sb.append(" NON_RECURSIVE");
4772                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(conv(dir)).append("'");
4773                                    
4774                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4775                          sb.append(" NAME='").append(query.name).append("'");                          sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
4776                  }                  }
4777                                    
4778                  String s = query.getCreatedAfter();                  String s = query.getCreatedAfter();
# Line 4604  public class Client { Line 4796  public class Client {
4796                  }                  }
4797                                    
4798                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
4799                          sb.append(" DESCRIPTION='").append(query.description).append("'");                          sb.append(" DESCRIPTION='");
4800                            sb.append(toEscapedText(query.description)).append("'");
4801                  }                  }
4802                                    
4803                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4804                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4805                                    
4806                  String[] dirS = parseStringList(getSingleLineResultSet().getResult());                  String[] dirS = parseEscapedStringList(getSingleLineResultSet().getResult());
4807                                    
4808                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4809                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
# Line 4657  public class Client { Line 4850  public class Client {
4850                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
4851                  sb.append("FIND DB_INSTRUMENTS");                  sb.append("FIND DB_INSTRUMENTS");
4852                  if(nonRecursive) sb.append(" NON_RECURSIVE");                  if(nonRecursive) sb.append(" NON_RECURSIVE");
4853                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(conv(dir)).append("'");
4854                                    
4855                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4856                          sb.append(" NAME='").append(query.name).append("'");                          sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
4857                  }                  }
4858                                    
4859                  if(query.formatFamilies.size() > 0) {                  if(query.formatFamilies.size() > 0) {
# Line 4700  public class Client { Line 4893  public class Client {
4893                  }                  }
4894                                    
4895                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
4896                          sb.append(" DESCRIPTION='").append(query.description).append("'");                          sb.append(" DESCRIPTION='");
4897                            sb.append(toEscapedText(query.description)).append("'");
4898                  }                  }
4899                                    
4900                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
# Line 4713  public class Client { Line 4907  public class Client {
4907                  }                  }
4908                                    
4909                  if(query.product != null && query.product.length() > 0) {                  if(query.product != null && query.product.length() > 0) {
4910                          sb.append(" PRODUCT='").append(query.product).append("'");                          sb.append(" PRODUCT='").append(toEscapedText(query.product)).append("'");
4911                  }                  }
4912                                    
4913                  if(query.artists != null && query.artists.length() > 0) {                  if(query.artists != null && query.artists.length() > 0) {
4914                          sb.append(" ARTISTS='").append(query.artists).append("'");                          sb.append(" ARTISTS='").append(toEscapedText(query.artists)).append("'");
4915                  }                  }
4916                                    
4917                  if(query.keywords != null && query.keywords.length() > 0) {                  if(query.keywords != null && query.keywords.length() > 0) {
4918                          sb.append(" KEYWORDS='").append(query.keywords).append("'");                          sb.append(" KEYWORDS='");
4919                            sb.append(toEscapedText(query.keywords)).append("'");
4920                  }                  }
4921                                    
4922                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4923                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4924                                    
4925                  String[] instrS = parseStringList(getSingleLineResultSet().getResult());                  String[] instrS = parseEscapedStringList(getSingleLineResultSet().getResult());
4926                                    
4927                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4928                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
# Line 4737  public class Client { Line 4932  public class Client {
4932          }          }
4933                    
4934          /**          /**
4935             * Returns a list of all instrument files in the database
4936             * that that doesn't exist in the filesystem.
4937             * @throws IOException If some I/O error occurs.
4938             * @throws LscpException If LSCP protocol corruption occurs.
4939             * @throws LSException If other error occurs.
4940             */
4941            public synchronized String[]
4942            findLostDbInstrumentFiles() throws IOException, LscpException, LSException {
4943                    
4944                    verifyConnection();
4945                    out.writeLine("FIND LOST DB_INSTRUMENT_FILES");
4946                    if(getPrintOnlyMode()) return null;
4947                    
4948                    return parseEscapedStringList(getSingleLineResultSet().getResult());
4949            }
4950            
4951            /**
4952           * Gets status information about the specified job.           * Gets status information about the specified job.
4953           * @param jobId The ID of the job.           * @param jobId The ID of the job.
4954           * @return A <code>ScanJobInfo</code> instance providing information           * @return A <code>ScanJobInfo</code> instance providing information
# Line 4758  public class Client { Line 4970  public class Client {
4970          }          }
4971                    
4972          /**          /**
4973             * Removes all instruments and directories and re-creates
4974             * the instruments database structure.
4975             * @throws IOException If some I/O error occurs.
4976             * @throws LscpException If LSCP protocol corruption occurs.
4977             * @throws LSException If the formatting of the instruments database failed.
4978             */
4979            public synchronized void
4980            formatInstrumentsDb() throws IOException, LscpException, LSException {
4981                    verifyConnection();
4982                    out.writeLine("FORMAT INSTRUMENTS_DB");
4983                    if(getPrintOnlyMode()) return;
4984                    
4985                    ResultSet rs = getEmptyResultSet();
4986            }
4987            
4988            /**
4989           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4990           *           *
4991           * @param samplerChn The sampler channel number.           * @param samplerChn The sampler channel number.
# Line 4794  public class Client { Line 5022  public class Client {
5022          }          }
5023                    
5024          /**          /**
5025             * Gets the current number of all active streams.
5026             * @return The current number of all active streams.
5027             * @throws IOException If some I/O error occurs.
5028             * @throws LscpException If LSCP protocol corruption occurs.
5029             * @throws LSException If some other error occurs.
5030             */
5031            public synchronized int
5032            getTotalStreamCount() throws IOException, LscpException, LSException {
5033                    verifyConnection();
5034                    out.writeLine("GET TOTAL_STREAM_COUNT");
5035                    if(getPrintOnlyMode()) return -1;
5036                    
5037                    String s = getSingleLineResultSet().getResult();
5038                    return parseInt(s);
5039            }
5040            
5041            /**
5042           * Gets the current number of all active voices.           * Gets the current number of all active voices.
5043           * @return The current number of all active voices.           * @return The current number of all active voices.
5044           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 4882  public class Client { Line 5127  public class Client {
5127                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
5128          }          }
5129                    
5130            /**
5131             * Gets the number of instruments in the specified instrument file.
5132             * @param filename The absolute path name of the instrument file.
5133             * @return The number of instruments in the specified instrument file.
5134             * @throws IOException If some I/O error occurs.
5135             * @throws LscpException If LSCP protocol corruption occurs.
5136             * @throws LSException If the file is not found, or other error occur.
5137             */
5138            public synchronized int
5139            getFileInstrumentCount(String filename) throws IOException, LscpException, LSException {
5140                    verifyConnection();
5141                    out.writeLine("GET FILE INSTRUMENTS '" + conv(filename) +"'");
5142                    if(getPrintOnlyMode()) return -1;
5143                    
5144                    String s = getSingleLineResultSet().getResult();
5145                    return parseInt(s);
5146            }
5147            
5148            /**
5149             * Gets information about the instrument with index
5150             * <code>instrIdx</code> in the specified instrument file.
5151             * @param filename The absolute path name of the instrument file.
5152             * @param instrIdx The index of the instrument in the specified instrument file.
5153             * @throws IOException If some I/O error occurs.
5154             * @throws LscpException If LSCP protocol corruption occurs.
5155             * @throws LSException If failed to retrieve information.
5156             */
5157            public synchronized Instrument
5158            getFileInstrumentInfo(String filename, int instrIdx)
5159                                    throws IOException, LscpException, LSException {
5160                    
5161                    verifyConnection();
5162                    out.writeLine("GET FILE INSTRUMENT INFO '" + conv(filename) + "' " + String.valueOf(instrIdx));
5163                    if(getPrintOnlyMode()) return null;
5164                    
5165                    ResultSet rs = getMultiLineResultSet();
5166                    Instrument instr = new FileInstrument(rs.getMultiLineResult()) { };
5167                    
5168                    return instr;
5169            }
5170            
5171            /**
5172             * Gets the list of instruments in the specified instrument file.
5173             * @param filename The absolute path name of the instrument file.
5174             * @return An <code>Instrument</code> array providing
5175             * information about all instruments in the specified instrument file.
5176             * @throws IOException If some I/O error occurs.
5177             * @throws LscpException If LSCP protocol corruption occurs.
5178             * @throws LSException If the specified file name is invalid.
5179             */
5180            public synchronized Instrument[]
5181            getFileInstruments(String filename) throws IOException, LscpException, LSException {
5182                    int l = getFileInstrumentCount(filename);
5183                    if(l < 0) return null;
5184                    Instrument[] instrS = new FileInstrument[l];
5185                    
5186                    for(int i = 0; i < instrS.length; i++) {
5187                            instrS[i] = getFileInstrumentInfo(filename, i);
5188                    }
5189                    return instrS;
5190            }
5191            
5192            private static class FileInstrument extends AbstractInstrument {
5193                    FileInstrument(String[] resultSet) throws LscpException {
5194                            super(resultSet);
5195                    }
5196                    
5197                    public String
5198                    getEngine() {
5199                            // TODO: engine lookup?
5200                            return getFormatFamily();
5201                    }
5202                    
5203                    public boolean
5204                    parse(String s) throws LscpException {
5205                            if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true;
5206                            return super.parse(s);
5207                    }
5208            }
5209            
5210          private void          private void
5211          getEmptyResultSets(int count, String err) throws LSException {          getEmptyResultSets(int count, String err) throws LSException {
5212                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();

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

  ViewVC Help
Powered by ViewVC