/[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 1139 by iliev, Mon Apr 2 20:43:58 2007 UTC revision 1393 by iliev, Sun Oct 7 20:29:41 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 69  public class Client { Line 70  public class Client {
70          private String address;          private String address;
71          private int port;          private int port;
72          private Socket sock = null;          private Socket sock = null;
73          private int soTimeout = 10000;          private int soTimeout = 20000;
74                    
75          private LscpInputStream in = null;          private LscpInputStream in = null;
76          private LscpOutputStream out = null;          private LscpOutputStream out = null;
# Line 79  public class Client { Line 80  public class Client {
80          private boolean printOnlyMode = false;          private boolean printOnlyMode = false;
81                    
82          class EventThread extends Thread {          class EventThread extends Thread {
83                    private Vector<String> queue = new Vector<String>();
84                  private boolean terminate = false;                  private boolean terminate = false;
85                                    
86                  EventThread() { super("LSCP-Event-Thread"); }                  EventThread() { super("LSCP-Event-Thread"); }
# Line 86  public class Client { Line 88  public class Client {
88                  public void                  public void
89                  run() {                  run() {
90                          while(!mustTerminate()) {                          while(!mustTerminate()) {
91                                  try { processNotifications(); }                                  try {
92                                  catch(Exception x) {                                          processQueue();
93                                            processNotifications();
94                                    } catch(Exception x) {
95                                          getLogger().log(Level.FINE, x.getMessage(), x);                                          getLogger().log(Level.FINE, x.getMessage(), x);
96                                  }                                  }
97                                  try { synchronized(this) { wait(100); } }                                  try { synchronized(this) { wait(100); } }
# Line 105  public class Client { Line 109  public class Client {
109                          terminate = true;                          terminate = true;
110                          this.notifyAll();                          this.notifyAll();
111                  }                  }
112                    
113                    public synchronized void
114                    scheduleNotification(String s) { queue.add(s); }
115                    
116                    private void
117                    processQueue() {
118                            String[] notifications = popAllNotifications();
119                            for(String n : notifications) fireEvent(n);
120                    }
121                    
122                    private synchronized String[]
123                    popAllNotifications() {
124                            String[] notifications = queue.toArray(new String[queue.size()]);
125                            queue.removeAllElements();
126                            return notifications;
127                    }
128          }          }
129                    
130          /**          /**
# Line 329  public class Client { Line 349  public class Client {
349                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
350                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
351                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
352                    if(!llID.isEmpty()) {
353                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
354                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
355                            subscribe("DB_INSTRUMENT_COUNT");
356                            subscribe("DB_INSTRUMENT_INFO");
357                    }
358                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
359          }          }
360                    
# Line 376  public class Client { Line 402  public class Client {
402                  String s;                  String s;
403                  for(;;) {                  for(;;) {
404                          s = in.readLine();                          s = in.readLine();
405                          if(s.startsWith("NOTIFY:")) fireEvent(s.substring("NOTIFY:".length()));                          if(s.startsWith("NOTIFY:")) {
406                                    eventThread.scheduleNotification(s.substring("NOTIFY:".length()));
407                            }
408                          else break;                          else break;
409                  }                  }
410                  return s;                  return s;
# Line 469  public class Client { Line 497  public class Client {
497          /** MIDI instrument info listeners */          /** MIDI instrument info listeners */
498          private final Vector<MidiInstrumentInfoListener> llMII =          private final Vector<MidiInstrumentInfoListener> llMII =
499                  new Vector<MidiInstrumentInfoListener>();                  new Vector<MidiInstrumentInfoListener>();
500            private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();
501          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();
502                    
503                    
# Line 498  public class Client { Line 527  public class Client {
527                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
528                          !llMIC.isEmpty()  ||                          !llMIC.isEmpty()  ||
529                          !llMII.isEmpty()  ||                          !llMII.isEmpty()  ||
530                            !llID.isEmpty()   ||
531                          !llGI.isEmpty();                          !llGI.isEmpty();
532          }          }
533                    
534          private void          private synchronized void
535          fireEvent(String s) {          fireEvent(String s) {
536                  if(s.startsWith("CHANNEL_COUNT:")) {                   if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {
537                            s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
538                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
539                            for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
540                    } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_INFO:")) {
541                            InstrumentsDbEvent e;
542                            s = s.substring("DB_INSTRUMENT_DIRECTORY_INFO:".length());
543                            if(s.startsWith("NAME ")) {
544                                    String[] list;
545                                    try {
546                                            s = s.substring("NAME ".length());
547                                            list = parseEscapedStringList(s, ' ');
548                                            if(list.length != 2) throw new LscpException();
549                                            list[1] = toNonEscapedString(list[1]);
550                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
551                                            for(InstrumentsDbListener l : llID) {
552                                                    l.directoryNameChanged(e);
553                                            }
554                                    } catch(LscpException x) {
555                                            getLogger().log (
556                                                    Level.WARNING,
557                                                    LscpI18n.getLogMsg("CommandFailed!"),
558                                                    x
559                                            );
560                                    }
561                            } else {
562                                    e = new InstrumentsDbEvent(this, s);
563                                    for(InstrumentsDbListener l : llID) l.directoryInfoChanged(e);
564                            }
565                    } else if(s.startsWith("DB_INSTRUMENT_COUNT:")) {
566                            s = s.substring("DB_INSTRUMENT_COUNT:".length());
567                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
568                            for(InstrumentsDbListener l : llID) l.instrumentCountChanged(e);
569                    } else if(s.startsWith("DB_INSTRUMENT_INFO:")) {
570                            InstrumentsDbEvent e;
571                            s = s.substring("DB_INSTRUMENT_INFO:".length());
572                            if(s.startsWith("NAME ")) {
573                                    String[] list;
574                                    try {
575                                            s = s.substring("NAME ".length());
576                                            list = parseEscapedStringList(s, ' ');
577                                            if(list.length != 2) throw new LscpException();
578                                            list[1] = toNonEscapedString(list[1]);
579                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
580                                            for(InstrumentsDbListener l : llID) {
581                                                    l.instrumentNameChanged(e);
582                                            }
583                                    } catch(LscpException x) {
584                                            getLogger().log (
585                                                    Level.WARNING,
586                                                    LscpI18n.getLogMsg("CommandFailed!"),
587                                                    x
588                                            );
589                                    }
590                            } else {
591                                    e = new InstrumentsDbEvent(this, s);
592                                    for(InstrumentsDbListener l : llID) l.instrumentInfoChanged(e);
593                            }
594                    } else if(s.startsWith("DB_INSTRUMENTS_JOB_INFO:")) {
595                            s = s.substring("DB_INSTRUMENTS_JOB_INFO:".length());
596                            try {
597                                    int i = Integer.parseInt(s);
598                                    InstrumentsDbEvent e = new InstrumentsDbEvent(this, i);
599                                    for(InstrumentsDbListener l : llID) l.jobStatusChanged(e);
600                            } catch(NumberFormatException x) {
601                                    s = "Unknown DB_INSTRUMENTS_JOB_INFO format";
602                                    getLogger().log(Level.WARNING, s, x);
603                            }
604                            
605                    } else if(s.startsWith("CHANNEL_COUNT:")) {
606                          try {                          try {
607                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));
608                                  ChannelCountEvent e = new ChannelCountEvent(this, i);                                  ChannelCountEvent e = new ChannelCountEvent(this, i);
# Line 1145  public class Client { Line 1244  public class Client {
1244          /**          /**
1245           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1246           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1247             * @param l The <code>InstrumentsDbListener</code> to register.
1248             */
1249            public synchronized void
1250            addInstrumentsDbListener(InstrumentsDbListener l) {
1251                    if(llID.isEmpty()) {
1252                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1253                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1254                            subscribe("DB_INSTRUMENT_COUNT");
1255                            subscribe("DB_INSTRUMENT_INFO");
1256                            subscribe("DB_INSTRUMENTS_JOB_INFO");
1257                    }
1258                    llID.add(l);
1259            }
1260            
1261            /**
1262             * Removes the specified listener.
1263             * Listeners can be removed regardless of the connection state.
1264             * @param l The <code>InstrumentsDbListener</code> to remove.
1265             */
1266            public synchronized void
1267            removeInstrumentsDbListener(InstrumentsDbListener l) {
1268                    boolean b = llID.remove(l);
1269                    if(b && llID.isEmpty()) {
1270                            unsubscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1271                            unsubscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1272                            unsubscribe("DB_INSTRUMENT_COUNT");
1273                            unsubscribe("DB_INSTRUMENT_INFO");
1274                            unsubscribe("DB_INSTRUMENTS_JOB_INFO");
1275                    }
1276            }
1277            
1278            /**
1279             * Registers the specified listener for receiving event messages.
1280             * Listeners can be registered regardless of the connection state.
1281           * @param l The <code>GlobalInfoListener</code> to register.           * @param l The <code>GlobalInfoListener</code> to register.
1282           */           */
1283          public synchronized void          public synchronized void
# Line 1227  public class Client { Line 1360  public class Client {
1360          /**          /**
1361           * Gets detailed information about a specific audio output driver.           * Gets detailed information about a specific audio output driver.
1362           * @param driverName The name of the audio output driver.           * @param driverName The name of the audio output driver.
1363           *           * @param depList An optional list of dependences parameters.
1364           * @return An <code>AudioOutputDriver</code> object containing           * @return An <code>AudioOutputDriver</code> object containing
1365           * information about the specified audio output driver.           * information about the specified audio output driver.
1366           *           *
# Line 1237  public class Client { Line 1370  public class Client {
1370           *           *
1371           * @see #getAudioOutputDriverNames           * @see #getAudioOutputDriverNames
1372           */           */
1373          private synchronized AudioOutputDriver          public synchronized AudioOutputDriver
1374          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getAudioOutputDriverInfo(String driverName, Parameter... depList)
1375                                            throws IOException, LscpException, LSException {
1376                    
1377                  verifyConnection();                  verifyConnection();
1378                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
1379                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1248  public class Client { Line 1383  public class Client {
1383                  aod.setName(driverName);                  aod.setName(driverName);
1384                                    
1385                  for(String s : aod.getParameterNames())                  for(String s : aod.getParameterNames())
1386                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s));                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s, depList));
1387                                    
1388                  return aod;                  return aod;
1389          }          }
# Line 1282  public class Client { Line 1417  public class Client {
1417                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
1418                  args.append(' ').append(param);                  args.append(' ').append(param);
1419                                    
1420                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
1421                            if(p.getValue() == null) continue;
1422                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1423                    }
1424                                    
1425                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());
1426                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1344  public class Client { Line 1481  public class Client {
1481                  verifyConnection();                  verifyConnection();
1482                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1483                                    
1484                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
1485                            if(p.getValue() == null) continue;
1486                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1487                    }
1488                                    
1489                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());
1490                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 1806  public class Client { Line 1945  public class Client {
1945          /**          /**
1946           * Gets detailed information about a specific MIDI input driver.           * Gets detailed information about a specific MIDI input driver.
1947           * @param driverName The name of the MIDI input driver.           * @param driverName The name of the MIDI input driver.
1948           *           * @param depList An optional list of dependences parameters.
1949           * @return A <code>MidiInputDriver</code> object containing           * @return A <code>MidiInputDriver</code> object containing
1950           * information about the specified MIDI input driver.           * information about the specified MIDI input driver.
1951           *           *
# Line 1816  public class Client { Line 1955  public class Client {
1955           *           *
1956           * @see #getMidiInputDriverNames           * @see #getMidiInputDriverNames
1957           */           */
1958          private synchronized MidiInputDriver          public synchronized MidiInputDriver
1959          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getMidiInputDriverInfo(String driverName, Parameter... depList)
1960                                            throws IOException, LscpException, LSException {
1961                    
1962                  verifyConnection();                  verifyConnection();
1963                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
1964                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1828  public class Client { Line 1969  public class Client {
1969                  mid.setName(driverName);                  mid.setName(driverName);
1970                                    
1971                  for(String s : mid.getParameterNames())                  for(String s : mid.getParameterNames())
1972                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s));                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s, depList));
1973                                    
1974                  return mid;                  return mid;
1975          }          }
# Line 1862  public class Client { Line 2003  public class Client {
2003                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
2004                  args.append(' ').append(param);                  args.append(' ').append(param);
2005                                    
2006                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
2007                            if(p.getValue() == null) continue;
2008                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2009                    }
2010                                    
2011                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());
2012                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1925  public class Client { Line 2068  public class Client {
2068                  verifyConnection();                  verifyConnection();
2069                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2070                                    
2071                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
2072                            if(p.getValue() == null) continue;
2073                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2074                    }
2075                                    
2076                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());
2077                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 2315  public class Client { Line 2460  public class Client {
2460          public synchronized int          public synchronized int
2461          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {
2462                  verifyConnection();                  verifyConnection();
2463                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + name + "'");                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedString(name) + "'");
2464                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
2465                                    
2466                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 2466  public class Client { Line 2611  public class Client {
2611                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
2612                                    
2613                  verifyConnection();                  verifyConnection();
2614                    name = toEscapedString(name);
2615                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");
2616                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
2617                                    
2618                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
2619          }          }
2620                    
2621            
2622            
2623          /**          /**
2624           * Creates or replaces a MIDI instrument map entry.           * Creates or replaces a MIDI instrument map entry.
2625           * @param mapId The ID of the map, where this instrument should be mapped.           * @param mapId The ID of the map, where this instrument should be mapped.
# Line 2486  public class Client { Line 2634  public class Client {
2634          public synchronized void          public synchronized void
2635          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)
2636                                          throws IOException, LSException, LscpException {                                          throws IOException, LSException, LscpException {
2637                    mapMidiInstrument(mapId, entry, info, false);
2638            }
2639            
2640            /**
2641             * Creates or replaces a MIDI instrument map entry.
2642             * @param mapId The ID of the map, where this instrument should be mapped.
2643             * @param entry Specifies the position of the MIDI instrument in the MIDI instrument map.
2644             * @param info Provides the needed information of the
2645             * MIDI instrument, which will be mapped to the specified MIDI instrument map.
2646             * @param nonModal If <code>true</code> the function returns immediately
2647             * and the mapping is established in the background.
2648             * @throws IOException If some I/O error occurs.
2649             * @throws LSException If the mapping failed.
2650             * @throws LscpException If LSCP protocol corruption occurs.
2651             * @see #unmapMidiInstrument
2652             */
2653            public synchronized void
2654            mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info, boolean nonModal)
2655                                            throws IOException, LSException, LscpException {
2656                                    
2657                  verifyConnection();                  verifyConnection();
2658                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");
2659                    if(nonModal) cmd.append("NON_MODAL ");
2660                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
2661                  cmd.append(entry.getMidiBank()).append(' ');                  cmd.append(entry.getMidiBank()).append(' ');
2662                  cmd.append(entry.getMidiProgram()).append(' ');                  cmd.append(entry.getMidiProgram()).append(' ');
2663                  cmd.append(info.getEngine()).append(" '");                  cmd.append(info.getEngine()).append(" '");
2664                  cmd.append(info.getFileName()).append("' ");                  cmd.append(info.getFilePath()).append("' ");
2665                  cmd.append(info.getInstrumentIndex()).append(' ');                  cmd.append(info.getInstrumentIndex()).append(' ');
2666                  cmd.append(info.getVolume());                  cmd.append(info.getVolume());
2667                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
2668                          cmd.append(' ').append(info.getLoadMode().name());                          cmd.append(' ').append(info.getLoadMode().name());
2669                  }                  }
2670                  if(info.getName() != null) cmd.append(" '").append(info.getName()).append("'");                  
2671                    if(info.getName() != null) {
2672                            String s = toEscapedString(info.getName());
2673                            cmd.append(" '").append(s).append("'");
2674                    }
2675                                    
2676                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
2677                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 3348  public class Client { Line 3520  public class Client {
3520                                    
3521                  verifyConnection();                  verifyConnection();
3522                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);
3523                  if(name != null) s += " '" + name + "'";                  if(name != null) s += " '" + toEscapedString(name) + "'";
3524                  out.writeLine("CREATE FX_SEND " + s);                  out.writeLine("CREATE FX_SEND " + s);
3525                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
3526                                    
# Line 3479  public class Client { Line 3651  public class Client {
3651                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
3652                                    
3653                  verifyConnection();                  verifyConnection();
3654                  String args = " " + channel + " " + fxSend + " '" + name + "'";                  String args = " " + channel + " " + fxSend + " '" + toEscapedString(name) + "'";
3655                  out.writeLine("SET FX_SEND NAME" + args);                  out.writeLine("SET FX_SEND NAME" + args);
3656                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3657                                    
# Line 3568  public class Client { Line 3740  public class Client {
3740          }          }
3741                    
3742          /**          /**
3743             * Starts an instrument editor for editing the loaded instrument
3744             * on the specified sampler channel.
3745             * @param samplerChn The sampler channel number.
3746             * @throws IOException If some I/O error occurs.
3747             * @throws LscpException If LSCP protocol corruption occurs.
3748             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3749             * there is no instrument loaded on the specified sampler channel.
3750             * @see #getSamplerChannels
3751             */
3752            public synchronized void
3753            editInstrument(int samplerChn) throws IOException, LscpException, LSException {
3754                    verifyConnection();
3755                    out.writeLine("EDIT INSTRUMENT " + samplerChn);
3756                    if(getPrintOnlyMode()) return;
3757                    
3758                    ResultSet rs = getEmptyResultSet();
3759            }
3760            
3761            
3762            
3763            /**
3764             * Adds the specified directory to the instruments database.
3765             * @param dir The absolute (escaped) path name of the directory to add.
3766             * @throws IOException If some I/O error occurs.
3767             * @throws LSException If the creation of the directory failed.
3768             * @throws LscpException If LSCP protocol corruption occurs.
3769             */
3770            public synchronized void
3771            addDbDirectory(String dir) throws IOException, LSException, LscpException {
3772                    verifyConnection();
3773                    out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");
3774                    if(getPrintOnlyMode()) return;
3775                    
3776                    ResultSet rs = getEmptyResultSet();
3777            }
3778            
3779            /**
3780             * Removes the specified directory from the instruments database.
3781             * @param dir The absolute (escaped) path name of the directory to remove.
3782             * @throws IOException If some I/O error occurs.
3783             * @throws LscpException If LSCP protocol corruption occurs.
3784             * @throws LSException If the specified directory is not
3785             * empty or if the removal of the directory failed.
3786             */
3787            public synchronized void
3788            removeDbDirectory(String dir) throws IOException, LscpException, LSException {
3789                    removeDbDirectory(dir, false);
3790            }
3791            
3792            /**
3793             * Removes the specified directory from the instruments database.
3794             * @param dir The absolute path name of the directory to remove.
3795             * @param force If <code>true</code> forces the removal of non-empty
3796             * directory and all its content.
3797             * @throws IOException If some I/O error occurs.
3798             * @throws LscpException If LSCP protocol corruption occurs.
3799             * @throws LSException If the removing of the directory failed.
3800             */
3801            public synchronized void
3802            removeDbDirectory(String dir, boolean force)
3803                                    throws IOException, LscpException, LSException {
3804                    
3805                    verifyConnection();
3806                    String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3807                    if(force) s += "FORCE ";
3808                    out.writeLine(s + "'" + dir + "'");
3809                    if(getPrintOnlyMode()) return;
3810                    
3811                    ResultSet rs = getEmptyResultSet();
3812            }
3813            
3814            /**
3815             * Removes the specified directories from the instruments database.
3816             * @param dirs The absolute (escaped) path names of the directories to remove.
3817             * @param force If <code>true</code> forces the removal of non-empty
3818             * directories.
3819             * @throws IOException If some I/O error occurs.
3820             * @throws LscpException If LSCP protocol corruption occurs.
3821             * @throws LSException If the removing of the directores failed.
3822             */
3823            public synchronized void
3824            removeDbDirectories(String[] dirs, boolean force)
3825                                    throws IOException, LscpException, LSException {
3826                    
3827                    verifyConnection();
3828                    String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3829                    if(force) cmd += "FORCE ";
3830                    
3831                    for(String s : dirs) out.writeLine(cmd + "'" + s + "'");
3832                    
3833                    if(getPrintOnlyMode()) return;
3834                    
3835                    getEmptyResultSets(dirs.length, "Client.dirDeletionFailed!");
3836            }
3837            
3838            /**
3839             * Gets the number of directories in the specified directory.
3840             * @return The current number of directories in the specified directory.
3841             * @param dir The absolute path name of the directory.
3842             * @throws IOException If some I/O error occurs.
3843             * @throws LscpException If LSCP protocol corruption occurs.
3844             * @throws LSException If some other error occurs.
3845             */
3846            public synchronized int
3847            getDbDirectoryCount(String dir) throws IOException, LscpException, LSException {
3848                    return getDbDirectoryCount(dir, false);
3849            }
3850            
3851            /**
3852             * Gets the number of directories in the specified directory.
3853             * @return The current number of directories in the specified directory.
3854             * @param dir The absolute path name of the directory.
3855             * @param recursive If <code>true</code>, the number of all directories
3856             * in the specified subtree will be returned.
3857             * @throws IOException If some I/O error occurs.
3858             * @throws LscpException If LSCP protocol corruption occurs.
3859             * @throws LSException If some other error occurs.
3860             */
3861            public synchronized int
3862            getDbDirectoryCount(String dir, boolean recursive)
3863                                    throws IOException, LscpException, LSException {
3864                    
3865                    verifyConnection();
3866                    String s;
3867                    if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
3868                    else s = "GET DB_INSTRUMENT_DIRECTORIES '";
3869                    out.writeLine(s + dir + "'");
3870                    if(getPrintOnlyMode()) return -1;
3871                    
3872                    s = getSingleLineResultSet().getResult();
3873                    return parseInt(s);
3874            }
3875            
3876            /**
3877             * Gets the list of directories in the specified directory.
3878             * @param dir The absolute path name of the directory.
3879             * @return A <code>String</code> array providing the names of
3880             * all directories in the specified directory.
3881             * @throws IOException If some I/O error occurs.
3882             * @throws LscpException If LSCP protocol corruption occurs.
3883             * @throws LSException If the specified path name is invalid.
3884             */
3885            public synchronized String[]
3886            getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
3887                    verifyConnection();
3888                    out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");
3889                    if(getPrintOnlyMode()) return null;
3890                    
3891                    String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
3892                    for(int i = 0; i < names.length; i++) {
3893                            names[i] = toNonEscapedString(names[i]);
3894                    }
3895                    return names;
3896            }
3897            
3898            /**
3899             * Gets information about the specified directory.
3900             * @param dir The absolute path name of the directory.
3901             * @return A <code>DbDirectoryInfo</code> instance providing information
3902             * about the specified directory.
3903             * @throws IOException If some I/O error occurs.
3904             * @throws LscpException If LSCP protocol corruption occurs.
3905             * @throws LSException If the specified directory is not found.
3906             */
3907            public synchronized DbDirectoryInfo
3908            getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
3909                    verifyConnection();
3910                    out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");
3911                    if(getPrintOnlyMode()) return null;
3912                    
3913                    ResultSet rs = getMultiLineResultSet();
3914                    DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
3915                    if(dir.equals("/")) {
3916                            info.setName("/");
3917                    } else {
3918                            dir = removeEndingFileSeparator(dir);
3919                    }
3920                    String s = getFileName(dir);
3921                    if(s != null) info.setName(toNonEscapedFileName(s));
3922                    s = getParentDirectory(dir);
3923                    if(s != null) info.setParentDirectoryPath(s);
3924                    
3925                    return info;
3926            }
3927            
3928            /**
3929             * Gets the list of directories in the specified directory.
3930             * @param dir The absolute path name of the directory.
3931             * @return A <code>DbDirectoryInfo</code> array providing
3932             * information about all directories in the specified directory.
3933             * @throws IOException If some I/O error occurs.
3934             * @throws LscpException If LSCP protocol corruption occurs.
3935             * @throws LSException If the specified path name is invalid.
3936             */
3937            public synchronized DbDirectoryInfo[]
3938            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3939                    String[] dirS = getDbDirectoryNames(dir);
3940                    if(!hasEndingFileSeparator(dir)) dir += "/";
3941                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3942                    for(int i = 0; i < dirS.length; i++) {
3943                            infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i]));
3944                    }
3945                    return infoS;
3946            }
3947            
3948            /**
3949             * Gets the list of directories in the specified directory.
3950             * @param dir The absolute path name of the directory.
3951             * @return A <code>DbDirectoryInfo</code> array providing
3952             * information about all directories in the specified directory.
3953             * @throws IOException If some I/O error occurs.
3954             * @throws LscpException If LSCP protocol corruption occurs.
3955             * @throws LSException If the specified path name is invalid.
3956             *
3957            public synchronized DbDirectoryInfo[]
3958            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3959                    String[] dirS = getDbDirectoryNames(dir);
3960                    if(dirS.length == 0) return new DbDirectoryInfo[0];
3961                    
3962                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3963                    
3964                    for(int i = 0; i < dirS.length; i++) {
3965                            out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");
3966                    }
3967                    
3968                    if(getPrintOnlyMode()) return null;
3969                    
3970                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
3971                    StringBuffer sb = new StringBuffer();
3972                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3973                    for(int i = 0; i < dirS.length; i++) {
3974                            try {
3975                                    ResultSet rs = getMultiLineResultSet();
3976                                    infoS[i] = new DbDirectoryInfo(rs.getMultiLineResult());
3977                                    infoS[i].setName(dirS[i]);
3978                                    infoS[i].setParentDirectoryPath(dir);
3979                            } catch (SocketTimeoutException e) {
3980                                    getLogger().log(Level.FINE, e.getMessage(), e);
3981                                    sb.append(e.getMessage()).append("\n");
3982                                    break;
3983                            } catch (Exception e) {
3984                                    getLogger().log(Level.FINE, e.getMessage(), e);
3985                                    sb.append(e.getMessage()).append("\n");
3986                            }
3987                    }
3988                    
3989                    String details = sb.toString();
3990                    if(details.length() > 0) {
3991                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
3992                            throw new LSException(0, err, details);
3993                    }
3994                    
3995                    return infoS;
3996            }*/
3997            
3998            /**
3999             * Renames the specified directory.
4000             * @param dir The absolute path name of the directory to rename.
4001             * @param name The new name for the directory.
4002             * @throws IOException If some I/O error occurs.
4003             * @throws LSException If the renaming of the directory failed.
4004             * @throws LscpException If LSCP protocol corruption occurs.
4005             */
4006            public synchronized void
4007            renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4008                    verifyConnection();
4009                    name = toEscapedString(name);
4010                    out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");
4011                    if(getPrintOnlyMode()) return;
4012                    
4013                    ResultSet rs = getEmptyResultSet();
4014            }
4015            
4016            /**
4017             * Moves the specified directory into the specified location.
4018             * @param dir The absolute path name of the directory to move.
4019             * @param dst The location where the directory will be moved to.
4020             * @throws IOException If some I/O error occurs.
4021             * @throws LSException If the operation failed.
4022             * @throws LscpException If LSCP protocol corruption occurs.
4023             */
4024            public synchronized void
4025            moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4026                    verifyConnection();
4027                    out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4028                    if(getPrintOnlyMode()) return;
4029                    
4030                    ResultSet rs = getEmptyResultSet();
4031            }
4032            
4033            /**
4034             * Moves the specified directories into the specified location.
4035             * @param dirs The absolute path names of the directories to move.
4036             * @param dst The location where the directories will be moved to.
4037             * @throws IOException If some I/O error occurs.
4038             * @throws LSException If the operation failed.
4039             * @throws LscpException If LSCP protocol corruption occurs.
4040             */
4041            public synchronized void
4042            moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4043                    verifyConnection();
4044                    for(String s : dirs) {
4045                            out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4046                    }
4047                    if(getPrintOnlyMode()) return;
4048                    
4049                    getEmptyResultSets(dirs.length, "Client.dirMovingFailed!");
4050            }
4051            
4052            /**
4053             * Copies the specified directory into the specified location.
4054             * @param dir The absolute path name of the directory to copy.
4055             * @param dst The location where the directory will be copied to.
4056             * @throws IOException If some I/O error occurs.
4057             * @throws LSException If the operation failed.
4058             * @throws LscpException If LSCP protocol corruption occurs.
4059             */
4060            public synchronized void
4061            copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4062                    verifyConnection();
4063                    out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4064                    if(getPrintOnlyMode()) return;
4065                    
4066                    ResultSet rs = getEmptyResultSet();
4067            }
4068            
4069            /**
4070             * Copies the specified directories into the specified location.
4071             * @param dirs The absolute path names of the directories to copy.
4072             * @param dst The location where the directories will be copied to.
4073             * @throws IOException If some I/O error occurs.
4074             * @throws LSException If the operation failed.
4075             * @throws LscpException If LSCP protocol corruption occurs.
4076             */
4077            public synchronized void
4078            copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4079                    verifyConnection();
4080                    for(String s : dirs) {
4081                            out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4082                    }
4083                    if(getPrintOnlyMode()) return;
4084                    
4085                    getEmptyResultSets(dirs.length, "Client.dirCopyingFailed!");
4086            }
4087            
4088            /**
4089             * Changes the description of the specified directory.
4090             * @param dir The absolute path name of the directory.
4091             * @param desc The new description for the directory.
4092             * @throws IOException If some I/O error occurs.
4093             * @throws LSException If failed to change the description.
4094             * @throws LscpException If LSCP protocol corruption occurs.
4095             */
4096            public synchronized void
4097            setDbDirectoryDescription(String dir, String desc)
4098                                    throws IOException, LSException, LscpException {
4099                    
4100                    verifyConnection();
4101                    String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4102                    out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'");
4103                    if(getPrintOnlyMode()) return;
4104                    
4105                    ResultSet rs = getEmptyResultSet();
4106            }
4107            
4108            public static enum ScanMode {
4109                    RECURSIVE, NON_RECURSIVE, FLAT
4110            }
4111            
4112            /**
4113             * Adds the specified instrument to the specified instruments database directory.
4114             * @param dbDir The absolute path name of the database directory in which the
4115             * specified instrument will be added.
4116             * @param filePath The absolute path name of the instrument file.
4117             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4118             * @throws IOException If some I/O error occurs.
4119             * @throws LSException If the operation failed.
4120             * @throws LscpException If LSCP protocol corruption occurs.
4121             */
4122            public synchronized void
4123            addDbInstrument(String dbDir, String filePath, int instrIndex)
4124                                            throws IOException, LSException, LscpException {
4125                    
4126                    addDbInstrument(dbDir, filePath, instrIndex, false);
4127            }
4128            
4129            /**
4130             * Adds the specified instrument to the specified instruments database directory.
4131             * @param dbDir The absolute path name of the database directory in which the
4132             * specified instrument will be added.
4133             * @param filePath The absolute path name of the instrument file.
4134             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4135             * @param background If <code>true</code>, the scan will be done
4136             * in background and this method may return before the job is finished.
4137             * @return If <code>background</code> is <code>true</code>, the ID
4138             * of the scan job.
4139             * @throws IOException If some I/O error occurs.
4140             * @throws LSException If the operation failed.
4141             * @throws LscpException If LSCP protocol corruption occurs.
4142             * @see #addInstrumentsDbListener
4143             */
4144            public synchronized int
4145            addDbInstrument(String dbDir, String filePath, int instrIndex, boolean background)
4146                                            throws IOException, LSException, LscpException {
4147                    
4148                    verifyConnection();
4149                    String s = "ADD DB_INSTRUMENTS";
4150                    if(background) s += " NON_MODAL";
4151                    s += " '" + dbDir + "' '" + filePath + "' ";
4152                    out.writeLine(s + String.valueOf(instrIndex));
4153                    if(getPrintOnlyMode()) return -1;
4154                    
4155                    ResultSet rs = getEmptyResultSet();
4156                    return rs.getIndex();
4157            }
4158            
4159            /**
4160             * Adds the instruments in the specified file to the specified
4161             * instruments database directory.
4162             * @param dbDir The absolute path name of the database directory
4163             * in which the the supported instruments will be added.
4164             * @param filePath The absolute path name of the file to scan for instruments.
4165             * @throws IOException If some I/O error occurs.
4166             * @throws LSException If the operation failed.
4167             * @throws LscpException If LSCP protocol corruption occurs.
4168             */
4169            public synchronized void
4170            addDbInstruments(String dbDir, String filePath)
4171                                            throws IOException, LSException, LscpException {
4172                    
4173                    addDbInstruments(dbDir, filePath, false);
4174            }
4175            
4176            /**
4177             * Adds the instruments in the specified file to the specified
4178             * instruments database directory.
4179             * @param dbDir The absolute path name of the database directory
4180             * in which the the supported instruments will be added.
4181             * @param filePath The absolute path name of the file to scan for instruments.
4182             * @param background If <code>true</code>, the scan will be done
4183             * in background and this method may return before the job is finished.
4184             * @return If <code>background</code> is <code>true</code>, the ID
4185             * of the scan job.
4186             * @throws IOException If some I/O error occurs.
4187             * @throws LSException If the operation failed.
4188             * @throws LscpException If LSCP protocol corruption occurs.
4189             * @see #addInstrumentsDbListener
4190             */
4191            public synchronized int
4192            addDbInstruments(String dbDir, String filePath, boolean background)
4193                                            throws IOException, LSException, LscpException {
4194                    
4195                    verifyConnection();
4196                    String s = "ADD DB_INSTRUMENTS";
4197                    if(background) s += " NON_MODAL";
4198                    out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");
4199                    if(getPrintOnlyMode()) return -1;
4200                    
4201                    ResultSet rs = getEmptyResultSet();
4202                    return rs.getIndex();
4203            }
4204            
4205            /**
4206             * Adds the instruments in the specified file system directory
4207             * to the specified instruments database directory.
4208             * @param mode Determines the scanning mode. If RECURSIVE is
4209             * specified, all supported instruments in the specified file system
4210             * direcotry will be added to the specified instruments database
4211             * directory, including the instruments in subdirectories
4212             * of the supplied directory. If NON_RECURSIVE is specified,
4213             * the instruments in the subdirectories will not be processed.
4214             * If FLAT is specified, all supported instruments in the specified
4215             * file system direcotry will be added, including the instruments in
4216             * subdirectories of the supplied directory, but the respective
4217             * subdirectory structure will not be recreated in the instruments
4218             * database and all instruments will be added directly in the
4219             * specified database directory.
4220             * @param dbDir The absolute path name of the database directory
4221             * in which the supported instruments will be added.
4222             * @param fsDir The absolute path name of the file system directory.
4223             * @throws IOException If some I/O error occurs.
4224             * @throws LSException If the operation failed.
4225             * @throws LscpException If LSCP protocol corruption occurs.
4226             */
4227            public synchronized void
4228            addDbInstruments(ScanMode mode, String dbDir, String fsDir)
4229                                            throws IOException, LSException, LscpException {
4230                    
4231                    addDbInstruments(mode, dbDir, fsDir, false);
4232            }
4233            
4234            /**
4235             * Adds the instruments in the specified file system directory
4236             * to the specified instruments database directory.
4237             * @param mode Determines the scanning mode. If RECURSIVE is
4238             * specified, all supported instruments in the specified file system
4239             * direcotry will be added to the specified instruments database
4240             * directory, including the instruments in subdirectories
4241             * of the supplied directory. If NON_RECURSIVE is specified,
4242             * the instruments in the subdirectories will not be processed.
4243             * If FLAT is specified, all supported instruments in the specified
4244             * file system direcotry will be added, including the instruments in
4245             * subdirectories of the supplied directory, but the respective
4246             * subdirectory structure will not be recreated in the instruments
4247             * database and all instruments will be added directly in the
4248             * specified database directory.
4249             * @param dbDir The absolute path name of the database directory
4250             * in which the supported instruments will be added.
4251             * @param fsDir The absolute path name of the file system directory.
4252             * @param background If <code>true</code>, the scan will be done
4253             * in background and this method may return before the job is finished.
4254             * @return If <code>background</code> is <code>true</code>, the ID
4255             * of the scan job.
4256             * @throws IOException If some I/O error occurs.
4257             * @throws LSException If the operation failed.
4258             * @throws LscpException If LSCP protocol corruption occurs.
4259             * @see #addInstrumentsDbListener
4260             */
4261            public synchronized int
4262            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4263                                            throws IOException, LSException, LscpException {
4264                    
4265                    verifyConnection();
4266                    StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4267                    if(background) sb.append(" NON_MODAL");
4268                    
4269                    switch(mode) {
4270                            case RECURSIVE:
4271                                    sb.append(" RECURSIVE");
4272                                    break;
4273                            case NON_RECURSIVE:
4274                                    sb.append(" NON_RECURSIVE");
4275                                    break;
4276                            case FLAT:
4277                                    sb.append(" FLAT");
4278                                    break;
4279                    }
4280                    
4281                    sb.append(" '").append(dbDir).append("' '");
4282                    sb.append(fsDir).append("'");
4283                    out.writeLine(sb.toString());
4284                    if(getPrintOnlyMode()) return -1;
4285                    
4286                    ResultSet rs = getEmptyResultSet();
4287                    return rs.getIndex();
4288            }
4289            
4290            /**
4291             * Removes the specified instrument from the instruments database.
4292             * @param instr The absolute path name of the instrument to remove.
4293             * @throws IOException If some I/O error occurs.
4294             * @throws LscpException If LSCP protocol corruption occurs.
4295             * @throws LSException If the removing of the instrument failed.
4296             */
4297            public synchronized void
4298            removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4299                    
4300                    verifyConnection();
4301                    out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");
4302                    if(getPrintOnlyMode()) return;
4303                    
4304                    ResultSet rs = getEmptyResultSet();
4305            }
4306            
4307            /**
4308             * Removes the specified instruments from the instruments database.
4309             * @param instrs The absolute path names of the instruments to remove.
4310             * @throws IOException If some I/O error occurs.
4311             * @throws LscpException If LSCP protocol corruption occurs.
4312             * @throws LSException If the removing of the instruments failed.
4313             */
4314            public synchronized void
4315            removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4316                    verifyConnection();
4317                    for(String s : instrs) {
4318                            out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");
4319                    }
4320                    if(getPrintOnlyMode()) return;
4321                    
4322                    getEmptyResultSets(instrs.length, "Client.instrDeletionFailed!");
4323            }
4324            
4325            /**
4326             * Gets the number of instruments in the specified directory.
4327             * @return The current number of instruments in the specified directory.
4328             * @param dir The absolute path name of the directory.
4329             * @throws IOException If some I/O error occurs.
4330             * @throws LscpException If LSCP protocol corruption occurs.
4331             * @throws LSException If some other error occurs.
4332             */
4333            public synchronized int
4334            getDbInstrumentCount(String dir) throws IOException, LscpException, LSException {
4335                    return getDbInstrumentCount(dir, false);
4336            }
4337            
4338            /**
4339             * Gets the number of instruments in the specified directory.
4340             * @return The current number of instruments in the specified directory.
4341             * @param dir The absolute path name of the directory.
4342             * @param recursive If <code>true</code>, the number of all instruments
4343             * in the specified subtree will be returned.
4344             * @throws IOException If some I/O error occurs.
4345             * @throws LscpException If LSCP protocol corruption occurs.
4346             * @throws LSException If some other error occurs.
4347             */
4348            public synchronized int
4349            getDbInstrumentCount(String dir, boolean recursive)
4350                                    throws IOException, LscpException, LSException {
4351                    
4352                    verifyConnection();
4353                    String s;
4354                    if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4355                    else s = "GET DB_INSTRUMENTS '";
4356                    out.writeLine(s + dir + "'");
4357                    if(getPrintOnlyMode()) return -1;
4358                    
4359                    s = getSingleLineResultSet().getResult();
4360                    return parseInt(s);
4361            }
4362            
4363            /**
4364             * Gets the list of instruments in the specified directory.
4365             * @param dir The absolute path name of the directory.
4366             * @return A <code>String</code> array providing the names of
4367             * all instruments in the specified directory.
4368             * @throws IOException If some I/O error occurs.
4369             * @throws LscpException If LSCP protocol corruption occurs.
4370             * @throws LSException If the specified path name is invalid.
4371             */
4372            public synchronized String[]
4373            getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4374                    verifyConnection();
4375                    out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");
4376                    if(getPrintOnlyMode()) return null;
4377                    
4378                    String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4379                    for(int i = 0; i < names.length; i++) {
4380                            names[i] = toNonEscapedString(names[i]);
4381                    }
4382                    return names;
4383            }
4384            
4385            /**
4386             * Gets information about the specified instrument.
4387             * @param instr The absolute path name of the instrument.
4388             * @return A <code>DbInstrumentInfo</code> instance providing information
4389             * about the specified instrument.
4390             * @throws IOException If some I/O error occurs.
4391             * @throws LscpException If LSCP protocol corruption occurs.
4392             * @throws LSException If the specified instrument is not found.
4393             */
4394            public synchronized DbInstrumentInfo
4395            getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4396                    verifyConnection();
4397                    out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");
4398                    if(getPrintOnlyMode()) return null;
4399                    
4400                    ResultSet rs = getMultiLineResultSet();
4401                    DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4402                    String s = getParentDirectory(instr);
4403                    if(s != null) info.setDirectoryPath(s);
4404                    s = getFileName(instr);
4405                    if(s != null) info.setName(toNonEscapedFileName(s));
4406                    
4407                    return info;
4408            }
4409            
4410            /**
4411             * Gets the list of instruments in the specified directory.
4412             * @param dir The absolute path name of the directory.
4413             * @return A <code>DbInstrumentInfo</code> array providing
4414             * information about all instruments in the specified directory.
4415             * @throws IOException If some I/O error occurs.
4416             * @throws LscpException If LSCP protocol corruption occurs.
4417             * @throws LSException If the specified path name is invalid.
4418             */
4419            public synchronized DbInstrumentInfo[]
4420            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4421                    String[] instrS = getDbInstrumentNames(dir);
4422                    if(!hasEndingFileSeparator(dir)) dir += "/";
4423                    
4424                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4425                    for(int i = 0; i < instrS.length; i++) {
4426                            infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i]));
4427                    }
4428                    return infoS;
4429            }
4430            
4431            /**
4432             * Gets the list of instruments in the specified directory.
4433             * @param dir The absolute path name of the directory.
4434             * @return A <code>DbInstrumentInfo</code> array providing
4435             * information about all instruments in the specified directory.
4436             * @throws IOException If some I/O error occurs.
4437             * @throws LscpException If LSCP protocol corruption occurs.
4438             * @throws LSException If the specified path name is invalid.
4439             *
4440            public synchronized DbInstrumentInfo[]
4441            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4442                    String[] instrS = getDbInstrumentNames(dir);
4443                    if(instrS.length == 0) return new DbInstrumentInfo[0];
4444                    
4445                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4446                    
4447                    for(int i = 0; i < instrS.length; i++) {
4448                            out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");
4449                    }
4450                    
4451                    if(getPrintOnlyMode()) return null;
4452                    
4453                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4454                    StringBuffer sb = new StringBuffer();
4455                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4456                    for(int i = 0; i < instrS.length; i++) {
4457                            try {
4458                                    ResultSet rs = getMultiLineResultSet();
4459                                    infoS[i] = new DbInstrumentInfo(rs.getMultiLineResult());
4460                                    infoS[i].setName(instrS[i]);
4461                                    infoS[i].setDirectoryPath(dir);
4462                            } catch (SocketTimeoutException e) {
4463                                    getLogger().log(Level.FINE, e.getMessage(), e);
4464                                    sb.append(e.getMessage()).append("\n");
4465                                    break;
4466                            } catch (Exception e) {
4467                                    getLogger().log(Level.FINE, e.getMessage(), e);
4468                                    sb.append(e.getMessage()).append("\n");
4469                            }
4470                    }
4471                    
4472                    String details = sb.toString();
4473                    if(details.length() > 0) {
4474                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4475                            throw new LSException(0, err, details);
4476                    }
4477                    
4478                    return infoS;
4479            }*/
4480            
4481            /**
4482             * Renames the specified instrument.
4483             * @param instr The absolute path name of the instrument to rename.
4484             * @param name The new name for the instrument.
4485             * @throws IOException If some I/O error occurs.
4486             * @throws LSException If the renaming of the instrument failed.
4487             * @throws LscpException If LSCP protocol corruption occurs.
4488             */
4489            public synchronized void
4490            renameDbInstrument(String instr, String name)
4491                                    throws IOException, LSException, LscpException {
4492                    
4493                    verifyConnection();
4494                    name = toEscapedString(name);
4495                    out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");
4496                    if(getPrintOnlyMode()) return;
4497                    
4498                    ResultSet rs = getEmptyResultSet();
4499            }
4500            
4501            /**
4502             * Moves the specified instrument into the specified location.
4503             * @param instr The absolute path name of the instrument to move.
4504             * @param dst The directory where the specified instrument will be moved to.
4505             * @throws IOException If some I/O error occurs.
4506             * @throws LSException If the operation failed.
4507             * @throws LscpException If LSCP protocol corruption occurs.
4508             */
4509            public synchronized void
4510            moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4511                    verifyConnection();
4512                    out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4513                    if(getPrintOnlyMode()) return;
4514                    
4515                    ResultSet rs = getEmptyResultSet();
4516            }
4517            
4518            /**
4519             * Moves the specified instruments into the specified location.
4520             * @param instrs The absolute path names of the instruments to move.
4521             * @param dst The directory where the specified instruments will be moved to.
4522             * @throws IOException If some I/O error occurs.
4523             * @throws LSException If the operation failed.
4524             * @throws LscpException If LSCP protocol corruption occurs.
4525             */
4526            public synchronized void
4527            moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4528                    verifyConnection();
4529                    for(String s : instrs) {
4530                            out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");
4531                    }
4532                    if(getPrintOnlyMode()) return;
4533                    
4534                    getEmptyResultSets(instrs.length, "Client.instrMovingFailed!");
4535            }
4536            
4537            /**
4538             * Copies the specified instrument into the specified location.
4539             * @param instr The absolute path name of the instrument to copy.
4540             * @param dst The directory where the specified instrument will be copied to.
4541             * @throws IOException If some I/O error occurs.
4542             * @throws LSException If the operation failed.
4543             * @throws LscpException If LSCP protocol corruption occurs.
4544             */
4545            public synchronized void
4546            copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4547                    verifyConnection();
4548                    out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4549                    if(getPrintOnlyMode()) return;
4550                    
4551                    ResultSet rs = getEmptyResultSet();
4552            }
4553            
4554            /**
4555             * Copies the specified instruments into the specified location.
4556             * @param instrs The absolute path name of the instruments to copy.
4557             * @param dst The directory where the specified instruments will be copied to.
4558             * @throws IOException If some I/O error occurs.
4559             * @throws LSException If the operation failed.
4560             * @throws LscpException If LSCP protocol corruption occurs.
4561             */
4562            public synchronized void
4563            copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4564                    verifyConnection();
4565                    for(String s : instrs) {
4566                            out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");
4567                    }
4568                    if(getPrintOnlyMode()) return;
4569                    
4570                    getEmptyResultSets(instrs.length, "Client.instrCopyingFailed!");
4571            }
4572            
4573            /**
4574             * Changes the description of the specified instrument.
4575             * @param instr The absolute path name of the instrument.
4576             * @param desc The new description for the instrument.
4577             * @throws IOException If some I/O error occurs.
4578             * @throws LSException If failed to change the description.
4579             * @throws LscpException If LSCP protocol corruption occurs.
4580             */
4581            public synchronized void
4582            setDbInstrumentDescription(String instr, String desc)
4583                                    throws IOException, LSException, LscpException {
4584                    
4585                    verifyConnection();
4586                    desc = toEscapedString(desc);
4587                    out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");
4588                    if(getPrintOnlyMode()) return;
4589                    
4590                    ResultSet rs = getEmptyResultSet();
4591            }
4592            
4593            /**
4594             * Finds all directories in the specified directory
4595             * that corresponds to the specified search criterias.
4596             * @param dir The absolute path name of the directory to search.
4597             * @param query Provides the search criterias.
4598             * @return A <code>DbDirectoryInfo</code> array providing
4599             * information about all directories that are found in the specified directory.
4600             * @throws IOException If some I/O error occurs.
4601             * @throws LscpException If LSCP protocol corruption occurs.
4602             * @throws LSException If the specified path name is invalid.
4603             */
4604            public synchronized DbDirectoryInfo[]
4605            findDbDirectories(String dir, DbSearchQuery query)
4606                                    throws IOException, LscpException, LSException {
4607                    
4608                    return findDbDirectories(dir, query, false);
4609            }
4610            
4611            /**
4612             * Finds all directories in the specified directory
4613             * that corresponds to the specified search criterias.
4614             * @param dir The absolute path name of the directory to search.
4615             * @param query Provides the search criterias.
4616             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4617             * @return A <code>DbDirectoryInfo</code> array providing
4618             * information about all directories that are found in the specified directory.
4619             * @throws IOException If some I/O error occurs.
4620             * @throws LscpException If LSCP protocol corruption occurs.
4621             * @throws LSException If the specified path name is invalid.
4622             */
4623            public synchronized DbDirectoryInfo[]
4624            findDbDirectories(String dir, DbSearchQuery query, boolean nonRecursive)
4625                                    throws IOException, LscpException, LSException {
4626                    
4627                    verifyConnection();
4628                    StringBuffer sb = new StringBuffer();
4629                    sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4630                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4631                    sb.append(" '").append(dir).append("'");
4632                    
4633                    if(query.name != null && query.name.length() > 0) {
4634                            sb.append(" NAME='").append(toEscapedString(query.name)).append("'");
4635                    }
4636                    
4637                    String s = query.getCreatedAfter();
4638                    String s2 = query.getCreatedBefore();
4639                    if(s != null || s2 != null) {
4640                            sb.append(" CREATED='");
4641                            if(s != null) sb.append(s);
4642                            sb.append("..");
4643                            if(s2 != null) sb.append(s2);
4644                            sb.append("'");
4645                    }
4646                    
4647                    s = query.getModifiedAfter();
4648                    s2 = query.getModifiedBefore();
4649                    if(s != null || s2 != null) {
4650                            sb.append(" MODIFIED='");
4651                            if(s != null) sb.append(s);
4652                            sb.append("..");
4653                            if(s2 != null) sb.append(s2);
4654                            sb.append("'");
4655                    }
4656                    
4657                    if(query.description != null && query.description.length() > 0) {
4658                            sb.append(" DESCRIPTION='");
4659                            sb.append(toEscapedString(query.description)).append("'");
4660                    }
4661                    
4662                    out.writeLine(sb.toString());
4663                    if(getPrintOnlyMode()) return null;
4664                    
4665                    String[] dirS = parseEscapedStringList(getSingleLineResultSet().getResult());
4666                    
4667                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4668                    for(int i = 0; i < dirS.length; i++) {
4669                            infoS[i] = getDbDirectoryInfo(dirS[i]);
4670                    }
4671                    return infoS;
4672            }
4673            
4674            /**
4675             * Finds all instruments in the specified directory
4676             * that corresponds to the specified search criterias.
4677             * @param dir The absolute path name of the directory to search.
4678             * @param query Provides the search criterias.
4679             * @return A <code>DbInstrumentInfo</code> array providing
4680             * information about all instruments that are found in the specified directory.
4681             * @throws IOException If some I/O error occurs.
4682             * @throws LscpException If LSCP protocol corruption occurs.
4683             * @throws LSException If the specified path name is invalid.
4684             */
4685            public synchronized DbInstrumentInfo[]
4686            findDbInstruments(String dir, DbSearchQuery query)
4687                                    throws IOException, LscpException, LSException {
4688                    
4689                    return findDbInstruments(dir, query, false);
4690            }
4691            
4692            /**
4693             * Finds all instruments in the specified directory
4694             * that corresponds to the specified search criterias.
4695             * @param dir The absolute path name of the directory to search.
4696             * @param query Provides the search criterias.
4697             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4698             * @return A <code>DbInstrumentInfo</code> array providing
4699             * information about all instruments that are found in the specified directory.
4700             * @throws IOException If some I/O error occurs.
4701             * @throws LscpException If LSCP protocol corruption occurs.
4702             * @throws LSException If the specified path name is invalid.
4703             */
4704            public synchronized DbInstrumentInfo[]
4705            findDbInstruments(String dir, DbSearchQuery query, boolean nonRecursive)
4706                                    throws IOException, LscpException, LSException {
4707                    
4708                    verifyConnection();
4709                    StringBuffer sb = new StringBuffer();
4710                    sb.append("FIND DB_INSTRUMENTS");
4711                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4712                    sb.append(" '").append(dir).append("'");
4713                    
4714                    if(query.name != null && query.name.length() > 0) {
4715                            sb.append(" NAME='").append(toEscapedString(query.name)).append("'");
4716                    }
4717                    
4718                    if(query.formatFamilies.size() > 0) {
4719                            sb.append(" FORMAT_FAMILIES='").append(query.formatFamilies.get(0));
4720                            for(int i = 1; i < query.formatFamilies.size(); i++) {
4721                                    sb.append(',').append(query.formatFamilies.get(i));
4722                            }
4723                            sb.append("'");
4724                    }
4725                    
4726                    if(query.minSize != -1 || query.maxSize != -1) {
4727                            sb.append(" SIZE='");
4728                            if(query.minSize != -1) sb.append(query.minSize);
4729                            sb.append("..");
4730                            if(query.maxSize != -1) sb.append(query.maxSize);
4731                            sb.append("'");
4732                    }
4733                    
4734                    String s = query.getCreatedAfter();
4735                    String s2 = query.getCreatedBefore();
4736                    if(s != null || s2 != null) {
4737                            sb.append(" CREATED='");
4738                            if(s != null) sb.append(s);
4739                            sb.append("..");
4740                            if(s2 != null) sb.append(s2);
4741                            sb.append("'");
4742                    }
4743                    
4744                    s = query.getModifiedAfter();
4745                    s2 = query.getModifiedBefore();
4746                    if(s != null || s2 != null) {
4747                            sb.append(" MODIFIED='");
4748                            if(s != null) sb.append(s);
4749                            sb.append("..");
4750                            if(s2 != null) sb.append(s2);
4751                            sb.append("'");
4752                    }
4753                    
4754                    if(query.description != null && query.description.length() > 0) {
4755                            sb.append(" DESCRIPTION='");
4756                            sb.append(toEscapedString(query.description)).append("'");
4757                    }
4758                    
4759                    if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
4760                            sb.append(" IS_DRUM=");
4761                            if(query.instrumentType == DbSearchQuery.InstrumentType.DRUM) {
4762                                    sb.append("'true'");
4763                            } else {
4764                                    sb.append("'false'");
4765                            }
4766                    }
4767                    
4768                    if(query.product != null && query.product.length() > 0) {
4769                            sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'");
4770                    }
4771                    
4772                    if(query.artists != null && query.artists.length() > 0) {
4773                            sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'");
4774                    }
4775                    
4776                    if(query.keywords != null && query.keywords.length() > 0) {
4777                            sb.append(" KEYWORDS='");
4778                            sb.append(toEscapedString(query.keywords)).append("'");
4779                    }
4780                    
4781                    out.writeLine(sb.toString());
4782                    if(getPrintOnlyMode()) return null;
4783                    
4784                    String[] instrS = parseEscapedStringList(getSingleLineResultSet().getResult());
4785                    
4786                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4787                    for(int i = 0; i < instrS.length; i++) {
4788                            infoS[i] = getDbInstrumentInfo(instrS[i]);
4789                    }
4790                    return infoS;
4791            }
4792            
4793            /**
4794             * Gets status information about the specified job.
4795             * @param jobId The ID of the job.
4796             * @return A <code>ScanJobInfo</code> instance providing information
4797             * about the specified job.
4798             * @throws IOException If some I/O error occurs.
4799             * @throws LscpException If LSCP protocol corruption occurs.
4800             * @throws LSException If the specified job is not found.
4801             */
4802            public synchronized ScanJobInfo
4803            getDbInstrumentsJobInfo(int jobId) throws IOException, LscpException, LSException {
4804                    verifyConnection();
4805                    out.writeLine("GET DB_INSTRUMENTS_JOB INFO " + String.valueOf(jobId));
4806                    if(getPrintOnlyMode()) return null;
4807                    
4808                    ResultSet rs = getMultiLineResultSet();
4809                    ScanJobInfo info = new ScanJobInfo(rs.getMultiLineResult());
4810                    
4811                    return info;
4812            }
4813            
4814            /**
4815             * Removes all instruments and directories and re-creates
4816             * the instruments database structure.
4817             * @throws IOException If some I/O error occurs.
4818             * @throws LscpException If LSCP protocol corruption occurs.
4819             * @throws LSException If the formatting of the instruments database failed.
4820             */
4821            public synchronized void
4822            formatInstrumentsDb() throws IOException, LscpException, LSException {
4823                    verifyConnection();
4824                    out.writeLine("FORMAT INSTRUMENTS_DB");
4825                    if(getPrintOnlyMode()) return;
4826                    
4827                    ResultSet rs = getEmptyResultSet();
4828            }
4829            
4830            /**
4831           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4832           *           *
4833           * @param samplerChn The sampler channel number.           * @param samplerChn The sampler channel number.
# Line 3692  public class Client { Line 4952  public class Client {
4952                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4953          }          }
4954                    
4955            private void
4956            getEmptyResultSets(int count, String err) throws LSException {
4957                    StringBuffer sb = new StringBuffer();
4958                    for(int i = 0; i < count; i++) {
4959                            try { getEmptyResultSet(); }
4960                            catch (SocketTimeoutException e) {
4961                                    getLogger().log(Level.FINE, e.getMessage(), e);
4962                                    sb.append(e.getMessage()).append("\n");
4963                                    break;
4964                            } catch (Exception e) {
4965                                    getLogger().log(Level.FINE, e.getMessage(), e);
4966                                    sb.append(e.getMessage()).append("\n");
4967                            }
4968                    }
4969                    
4970                    String details = sb.toString();
4971                    if(details.length() > 0) {
4972                            String s = LscpI18n.getLogMsg(err);
4973                            throw new LSException(0, s, details);
4974                    }
4975            }
4976            
4977          /**          /**
4978           * Returns the logger for this library.           * Returns the logger for this library.
4979           * @return The logger for this library.           * @return The logger for this library.

Legend:
Removed from v.1139  
changed lines
  Added in v.1393

  ViewVC Help
Powered by ViewVC