/[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 1849 by iliev, Sat Feb 28 21:35:09 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   *   jlscp - a java LinuxSampler control protocol API   *   jlscp - a java LinuxSampler control protocol API
3   *   *
4   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of jlscp.   *   This file is part of jlscp.
7   *   *
# Line 28  import java.io.OutputStream; Line 28  import java.io.OutputStream;
28  import java.net.InetSocketAddress;  import java.net.InetSocketAddress;
29  import java.net.Socket;  import java.net.Socket;
30  import java.net.SocketTimeoutException;  import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;  
31    
32  import java.util.Vector;  import java.util.Vector;
33  import java.util.logging.Level;  import java.util.logging.Level;
34  import java.util.logging.Logger;  import java.util.logging.Logger;
35    
 import static org.linuxsampler.lscp.Parser.*;  
36  import org.linuxsampler.lscp.event.*;  import org.linuxsampler.lscp.event.*;
37    
38    import static org.linuxsampler.lscp.Parser.*;
39    
40    
41  /**  /**
42   * 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
43   * instance. Since it implements all commands specified in the LSCP protocol v1.1, for more   * instance. Since it implements all commands specified in the LSCP protocol v1.3, for more
44   * information look at the   * information look at the
45   * <a href=http://www.linuxsampler.org/api/lscp-1.1.html>LSCP</a> specification.   * <a href=http://www.linuxsampler.org/api/lscp-1.3.html>LSCP</a> specification.
46   *   *
47   * <p> The following code establishes connection to LinuxSampler instance and gets the   * <p> The following code establishes connection to LinuxSampler instance and gets the
48   * LinuxSampler version:   * LinuxSampler version:
# Line 69  public class Client { Line 69  public class Client {
69          private String address;          private String address;
70          private int port;          private int port;
71          private Socket sock = null;          private Socket sock = null;
72          private int soTimeout = 10000;          private int soTimeout = 20000;
73                    
74          private LscpInputStream in = null;          private LscpInputStream in = null;
75          private LscpOutputStream out = null;          private LscpOutputStream out = null;
# Line 79  public class Client { Line 79  public class Client {
79          private boolean printOnlyMode = false;          private boolean printOnlyMode = false;
80                    
81          class EventThread extends Thread {          class EventThread extends Thread {
82                    private Vector<String> queue = new Vector<String>();
83                  private boolean terminate = false;                  private boolean terminate = false;
84                                    
85                  EventThread() { super("LSCP-Event-Thread"); }                  EventThread() { super("LSCP-Event-Thread"); }
86                                    
87                    @Override
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 144  public class Client { Line 164  public class Client {
164                  if(printOnlyMode) setPrintOnlyMode(true);                  if(printOnlyMode) setPrintOnlyMode(true);
165          }          }
166                    
167            private boolean extendedCharacterEscaping = true;
168            
169            /**
170             * Sets whether strings sent to LinuxSampler should be more aggressively escaped.
171             */
172            public synchronized void
173            setExtendedCharacterEscaping(boolean b) { extendedCharacterEscaping = b; }
174            
175            /**
176             * Determines whether strings sent to LinuxSampler should be more aggressively escaped.
177             */
178            public synchronized boolean
179            getExtendedCharacterEscaping() { return extendedCharacterEscaping; }
180            
181            /**
182             * @see java.net.Socket#setSoTimeout
183             */
184            public synchronized void
185            setSoTimeout(int timeout) {
186                    soTimeout = timeout;
187                    
188                    try { if(sock != null) sock.setSoTimeout(timeout); }
189                    catch(Exception x) { getLogger().log(Level.INFO, "Unable to set timeout", x); }
190            }
191            
192            private String
193            toEscapedText(String s) {
194                    s = toEscapedString(s);
195                    return conv(s);
196            }
197            
198            private String
199            toEscapedFsEntry(String s) {
200                    s = toEscapedFileName(s);
201                    return conv(s);
202            }
203            
204            /**
205             * Applies an extended character escaping to the specified string if needed.
206             */
207            private String
208            conv(String s) {
209                    return getExtendedCharacterEscaping() ? toExtendedEscapeSequence(s) : s;
210            }
211            
212          /**          /**
213           * Determines whether the client is in print-only mode.           * Determines whether the client is in print-only mode.
214           * Print-only mode means that the client will just print all           * Print-only mode means that the client will just print all
# Line 324  public class Client { Line 389  public class Client {
389                  if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");                  if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");
390                  if(!llSC.isEmpty()) subscribe("STREAM_COUNT");                  if(!llSC.isEmpty()) subscribe("STREAM_COUNT");
391                  if(!llVC.isEmpty()) subscribe("VOICE_COUNT");                  if(!llVC.isEmpty()) subscribe("VOICE_COUNT");
392                    if(!llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
393                  if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");                  if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");
394                  if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");                  if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");
395                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
396                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
397                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
398                    if(!llDMD.isEmpty()) subscribe("DEVICE_MIDI");
399                    if(!llCMD.isEmpty()) subscribe("CHANNEL_MIDI");
400                    if(!llID.isEmpty()) {
401                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
402                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
403                            subscribe("DB_INSTRUMENT_COUNT");
404                            subscribe("DB_INSTRUMENT_INFO");
405                            subscribe("DB_INSTRUMENTS_JOB_INFO");
406                    }
407                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
408          }          }
409                    
# Line 376  public class Client { Line 451  public class Client {
451                  String s;                  String s;
452                  for(;;) {                  for(;;) {
453                          s = in.readLine();                          s = in.readLine();
454                          if(s.startsWith("NOTIFY:")) fireEvent(s.substring("NOTIFY:".length()));                          if(s.startsWith("NOTIFY:")) {
455                                    eventThread.scheduleNotification(s.substring("NOTIFY:".length()));
456                            }
457                          else break;                          else break;
458                  }                  }
459                  return s;                  return s;
# Line 457  public class Client { Line 534  public class Client {
534          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();          private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();
535          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();          private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();
536          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();          private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();
537            private final Vector<TotalStreamCountListener> llTSC = new Vector<TotalStreamCountListener>();
538          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();          private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();
539                    
540          /** MIDI instrument map count listeners */          /** MIDI instrument map count listeners */
# Line 469  public class Client { Line 547  public class Client {
547          /** MIDI instrument info listeners */          /** MIDI instrument info listeners */
548          private final Vector<MidiInstrumentInfoListener> llMII =          private final Vector<MidiInstrumentInfoListener> llMII =
549                  new Vector<MidiInstrumentInfoListener>();                  new Vector<MidiInstrumentInfoListener>();
550            private final Vector<DeviceMidiDataListener> llDMD = new Vector<DeviceMidiDataListener>();
551            private final Vector<ChannelMidiDataListener> llCMD = new Vector<ChannelMidiDataListener>();
552            private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();
553          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();
554                    
555                    
# Line 493  public class Client { Line 574  public class Client {
574                          !llMIDI.isEmpty() ||                          !llMIDI.isEmpty() ||
575                          !llSC.isEmpty()   ||                          !llSC.isEmpty()   ||
576                          !llVC.isEmpty()   ||                          !llVC.isEmpty()   ||
577                            !llTSC.isEmpty()  ||
578                          !llTVC.isEmpty()  ||                          !llTVC.isEmpty()  ||
579                          !llMIMC.isEmpty() ||                          !llMIMC.isEmpty() ||
580                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
581                          !llMIC.isEmpty()  ||                          !llMIC.isEmpty()  ||
582                          !llMII.isEmpty()  ||                          !llMII.isEmpty()  ||
583                            !llDMD.isEmpty()  ||
584                            !llCMD.isEmpty()  ||
585                            !llID.isEmpty()   ||
586                          !llGI.isEmpty();                          !llGI.isEmpty();
587          }          }
588                    
589          private void          private synchronized void
590            fireDeviceMidiDataEvent(String s) {
591                    try {
592                            String[] list = parseList(s, ' ');
593                            if(list.length != 5) {
594                                    getLogger().warning("Unknown DEVICE_MIDI format");
595                                    return;
596                            }
597                            
598                            int dev = parseInt(list[0]);
599                            int port = parseInt(list[1]);
600                            
601                            MidiDataEvent.Type type = parseMidiDataType(list[2]);
602                            if(type == null) return;
603                            
604                            int note = parseInt(list[3]);
605                            int velocity = parseInt(list[4]);
606                            
607                            DeviceMidiDataEvent e = new DeviceMidiDataEvent(this, type, note, velocity);
608                            e.setDeviceId(dev);
609                            e.setPortId(port);
610                            for(DeviceMidiDataListener l : llDMD) l.midiDataArrived(e);
611                    } catch(LscpException x) {
612                            getLogger().log (
613                                    Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x
614                            );
615                    }
616            }
617            
618            private synchronized void
619            fireChannelMidiDataEvent(String s) {
620                    try {
621                            String[] list = parseList(s, ' ');
622                            if(list.length != 4) {
623                                    getLogger().warning("Unknown CHANNEL_MIDI format");
624                                    return;
625                            }
626                            
627                            int channel = parseInt(list[0]);
628                            
629                            MidiDataEvent.Type type = parseMidiDataType(list[1]);
630                            if(type == null) return;
631                            
632                            int note = parseInt(list[2]);
633                            int velocity = parseInt(list[3]);
634                            
635                            ChannelMidiDataEvent e = new ChannelMidiDataEvent(this, type, note, velocity);
636                            e.setChannelId(channel);
637                            for(ChannelMidiDataListener l : llCMD) l.midiDataArrived(e);
638                    } catch(LscpException x) {
639                            getLogger().log (
640                                    Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x
641                            );
642                    }
643            }
644            
645            private MidiDataEvent.Type
646            parseMidiDataType(String s) {
647                    if("NOTE_ON".equals(s)) return MidiDataEvent.Type.NOTE_ON;
648                    if("NOTE_OFF".equals(s)) return MidiDataEvent.Type.NOTE_OFF;
649                    
650                    getLogger().warning("Unknown MIDI data type: " + s);
651                    return null;
652            }
653            
654            private synchronized void
655          fireEvent(String s) {          fireEvent(String s) {
656                  if(s.startsWith("CHANNEL_COUNT:")) {                  // Sort by priority
657                    
658                     if(s.startsWith("CHANNEL_MIDI:")) {
659                            s = s.substring("CHANNEL_MIDI:".length());
660                            fireChannelMidiDataEvent(s);
661                    } else if(s.startsWith("DEVICE_MIDI:")) {
662                            s = s.substring("DEVICE_MIDI:".length());
663                            fireDeviceMidiDataEvent(s);
664                    } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {
665                            s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
666                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
667                            for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
668                    } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_INFO:")) {
669                            InstrumentsDbEvent e;
670                            s = s.substring("DB_INSTRUMENT_DIRECTORY_INFO:".length());
671                            if(s.startsWith("NAME ")) {
672                                    String[] list;
673                                    try {
674                                            s = s.substring("NAME ".length());
675                                            list = parseEscapedStringList(s, ' ');
676                                            if(list.length != 2) throw new LscpException();
677                                            list[1] = toNonEscapedString(list[1]);
678                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
679                                            for(InstrumentsDbListener l : llID) {
680                                                    l.directoryNameChanged(e);
681                                            }
682                                    } catch(LscpException x) {
683                                            getLogger().log (
684                                                    Level.WARNING,
685                                                    LscpI18n.getLogMsg("CommandFailed!"),
686                                                    x
687                                            );
688                                    }
689                            } else {
690                                    e = new InstrumentsDbEvent(this, s);
691                                    for(InstrumentsDbListener l : llID) l.directoryInfoChanged(e);
692                            }
693                    } else if(s.startsWith("DB_INSTRUMENT_COUNT:")) {
694                            s = s.substring("DB_INSTRUMENT_COUNT:".length());
695                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
696                            for(InstrumentsDbListener l : llID) l.instrumentCountChanged(e);
697                    } else if(s.startsWith("DB_INSTRUMENT_INFO:")) {
698                            InstrumentsDbEvent e;
699                            s = s.substring("DB_INSTRUMENT_INFO:".length());
700                            if(s.startsWith("NAME ")) {
701                                    String[] list;
702                                    try {
703                                            s = s.substring("NAME ".length());
704                                            list = parseEscapedStringList(s, ' ');
705                                            if(list.length != 2) throw new LscpException();
706                                            list[1] = toNonEscapedString(list[1]);
707                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
708                                            for(InstrumentsDbListener l : llID) {
709                                                    l.instrumentNameChanged(e);
710                                            }
711                                    } catch(LscpException x) {
712                                            getLogger().log (
713                                                    Level.WARNING,
714                                                    LscpI18n.getLogMsg("CommandFailed!"),
715                                                    x
716                                            );
717                                    }
718                            } else {
719                                    e = new InstrumentsDbEvent(this, s);
720                                    for(InstrumentsDbListener l : llID) l.instrumentInfoChanged(e);
721                            }
722                    } else if(s.startsWith("DB_INSTRUMENTS_JOB_INFO:")) {
723                            s = s.substring("DB_INSTRUMENTS_JOB_INFO:".length());
724                            try {
725                                    int i = Integer.parseInt(s);
726                                    InstrumentsDbEvent e = new InstrumentsDbEvent(this, i);
727                                    for(InstrumentsDbListener l : llID) l.jobStatusChanged(e);
728                            } catch(NumberFormatException x) {
729                                    s = "Unknown DB_INSTRUMENTS_JOB_INFO format";
730                                    getLogger().log(Level.WARNING, s, x);
731                            }
732                            
733                    } else if(s.startsWith("CHANNEL_COUNT:")) {
734                          try {                          try {
735                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));
736                                  ChannelCountEvent e = new ChannelCountEvent(this, i);                                  ChannelCountEvent e = new ChannelCountEvent(this, i);
# Line 563  public class Client { Line 790  public class Client {
790                          } catch(NumberFormatException x) {                          } catch(NumberFormatException x) {
791                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);                                  getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);
792                          }                          }
793                    } else if(s.startsWith("TOTAL_STREAM_COUNT:")) {
794                            try {
795                                    s = s.substring("TOTAL_STREAM_COUNT:".length());
796                                    int i = Integer.parseInt(s);
797                                    TotalStreamCountEvent e = new TotalStreamCountEvent(this, i);
798                                    for(TotalStreamCountListener l : llTSC) l.totalStreamCountChanged(e);
799                            } catch(NumberFormatException x) {
800                                    getLogger().log (
801                                            Level.WARNING, "Unknown TOTAL_STREAM_COUNT format", x
802                                    );
803                            }
804                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {                  } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {
805                          try {                          try {
806                                  s = s.substring("TOTAL_VOICE_COUNT:".length());                                  s = s.substring("TOTAL_VOICE_COUNT:".length());
# Line 726  public class Client { Line 964  public class Client {
964                                  float f = Float.parseFloat(s.substring("VOLUME ".length()));                                  float f = Float.parseFloat(s.substring("VOLUME ".length()));
965                                  GlobalInfoEvent e = new GlobalInfoEvent(this, f);                                  GlobalInfoEvent e = new GlobalInfoEvent(this, f);
966                                  for(GlobalInfoListener l : llGI) l.volumeChanged(e);                                  for(GlobalInfoListener l : llGI) l.volumeChanged(e);
967                            } else if(s.startsWith("VOICES ")) {
968                                    int i = Integer.parseInt(s.substring("VOICES ".length()));
969                                    GlobalInfoEvent e = new GlobalInfoEvent(this, i, -1);
970                                    for(GlobalInfoListener l : llGI) l.voiceLimitChanged(e);
971                            } else if(s.startsWith("STREAMS ")) {
972                                    int i = Integer.parseInt(s.substring("STREAMS ".length()));
973                                    GlobalInfoEvent e = new GlobalInfoEvent(this, -1, i);
974                                    for(GlobalInfoListener l : llGI) l.streamLimitChanged(e);
975                            } else {
976                                    getLogger().info("Unknown GLOBAL_INFO format: " + s);
977                          }                          }
978                  } catch(NumberFormatException x) {                  } catch(NumberFormatException x) {
979                          getLogger().log(Level.WARNING, "Unknown GLOBAL_INFO format", x);                          getLogger().log(Level.WARNING, "Unknown GLOBAL_INFO format", x);
# Line 1035  public class Client { Line 1283  public class Client {
1283          /**          /**
1284           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1285           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1286             * @param l The <code>TotalStreamCountListener</code> to register.
1287             */
1288            public synchronized void
1289            addTotalStreamCountListener(TotalStreamCountListener l) {
1290                    if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
1291                    llTSC.add(l);
1292            }
1293            
1294            /**
1295             * Removes the specified listener.
1296             * Listeners can be removed regardless of the connection state.
1297             * @param l The <code>TotalStreamCountListener</code> to remove.
1298             */
1299            public synchronized void
1300            removeTotalStreamCountListener(TotalStreamCountListener l) {
1301                    boolean b = llTSC.remove(l);
1302                    if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT");
1303            }
1304            
1305            /**
1306             * Registers the specified listener for receiving event messages.
1307             * Listeners can be registered regardless of the connection state.
1308           * @param l The <code>TotalVoiceCountListener</code> to register.           * @param l The <code>TotalVoiceCountListener</code> to register.
1309           */           */
1310          public synchronized void          public synchronized void
# Line 1145  public class Client { Line 1415  public class Client {
1415          /**          /**
1416           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1417           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1418             * @param l The <code>DeviceMidiDataListener</code> to register.
1419             */
1420            public synchronized void
1421            addDeviceMidiDataListener(DeviceMidiDataListener l) {
1422                    if(llDMD.isEmpty()) subscribe("DEVICE_MIDI");
1423                    llDMD.add(l);
1424            }
1425            
1426            /**
1427             * Removes the specified listener.
1428             * Listeners can be removed regardless of the connection state.
1429             * @param l The <code>DeviceMidiDataListener</code> to remove.
1430             */
1431            public synchronized void
1432            removeDeviceMidiDataListener(DeviceMidiDataListener l) {
1433                    boolean b = llDMD.remove(l);
1434                    if(b && llDMD.isEmpty()) unsubscribe("DEVICE_MIDI");
1435            }
1436            
1437            /**
1438             * Registers the specified listener for receiving event messages.
1439             * Listeners can be registered regardless of the connection state.
1440             * @param l The <code>ChannelMidiDataListener</code> to register.
1441             */
1442            public synchronized void
1443            addChannelMidiDataListener(ChannelMidiDataListener l) {
1444                    if(llCMD.isEmpty()) subscribe("CHANNEL_MIDI");
1445                    llCMD.add(l);
1446            }
1447            
1448            /**
1449             * Removes the specified listener.
1450             * Listeners can be removed regardless of the connection state.
1451             * @param l The <code>ChannelMidiDataListener</code> to remove.
1452             */
1453            public synchronized void
1454            removeChannelMidiDataListener(ChannelMidiDataListener l) {
1455                    boolean b = llCMD.remove(l);
1456                    if(b && llCMD.isEmpty()) unsubscribe("CHANNEL_MIDI");
1457            }
1458            
1459            /**
1460             * Registers the specified listener for receiving event messages.
1461             * Listeners can be registered regardless of the connection state.
1462             * @param l The <code>InstrumentsDbListener</code> to register.
1463             */
1464            public synchronized void
1465            addInstrumentsDbListener(InstrumentsDbListener l) {
1466                    if(llID.isEmpty()) {
1467                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1468                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1469                            subscribe("DB_INSTRUMENT_COUNT");
1470                            subscribe("DB_INSTRUMENT_INFO");
1471                            subscribe("DB_INSTRUMENTS_JOB_INFO");
1472                    }
1473                    llID.add(l);
1474            }
1475            
1476            /**
1477             * Removes the specified listener.
1478             * Listeners can be removed regardless of the connection state.
1479             * @param l The <code>InstrumentsDbListener</code> to remove.
1480             */
1481            public synchronized void
1482            removeInstrumentsDbListener(InstrumentsDbListener l) {
1483                    boolean b = llID.remove(l);
1484                    if(b && llID.isEmpty()) {
1485                            unsubscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1486                            unsubscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1487                            unsubscribe("DB_INSTRUMENT_COUNT");
1488                            unsubscribe("DB_INSTRUMENT_INFO");
1489                            unsubscribe("DB_INSTRUMENTS_JOB_INFO");
1490                    }
1491            }
1492            
1493            /**
1494             * Registers the specified listener for receiving event messages.
1495             * Listeners can be registered regardless of the connection state.
1496           * @param l The <code>GlobalInfoListener</code> to register.           * @param l The <code>GlobalInfoListener</code> to register.
1497           */           */
1498          public synchronized void          public synchronized void
# Line 1227  public class Client { Line 1575  public class Client {
1575          /**          /**
1576           * Gets detailed information about a specific audio output driver.           * Gets detailed information about a specific audio output driver.
1577           * @param driverName The name of the audio output driver.           * @param driverName The name of the audio output driver.
1578           *           * @param depList An optional list of dependences parameters.
1579           * @return An <code>AudioOutputDriver</code> object containing           * @return An <code>AudioOutputDriver</code> object containing
1580           * information about the specified audio output driver.           * information about the specified audio output driver.
1581           *           *
# Line 1237  public class Client { Line 1585  public class Client {
1585           *           *
1586           * @see #getAudioOutputDriverNames           * @see #getAudioOutputDriverNames
1587           */           */
1588          private synchronized AudioOutputDriver          public synchronized AudioOutputDriver
1589          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getAudioOutputDriverInfo(String driverName, Parameter... depList)
1590                                            throws IOException, LscpException, LSException {
1591                    
1592                  verifyConnection();                  verifyConnection();
1593                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
1594                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1248  public class Client { Line 1598  public class Client {
1598                  aod.setName(driverName);                  aod.setName(driverName);
1599                                    
1600                  for(String s : aod.getParameterNames())                  for(String s : aod.getParameterNames())
1601                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s));                          aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s, depList));
1602                                    
1603                  return aod;                  return aod;
1604          }          }
# Line 1282  public class Client { Line 1632  public class Client {
1632                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
1633                  args.append(' ').append(param);                  args.append(' ').append(param);
1634                                    
1635                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
1636                            if(p == null || p.getName() == null || p.getValue() == null) continue;
1637                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1638                    }
1639                                    
1640                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());
1641                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1344  public class Client { Line 1696  public class Client {
1696                  verifyConnection();                  verifyConnection();
1697                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1698                                    
1699                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
1700                            if(p == null || p.getName() == null || p.getValue() == null) continue;
1701                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1702                    }
1703                                    
1704                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());                  out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());
1705                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 1806  public class Client { Line 2160  public class Client {
2160          /**          /**
2161           * Gets detailed information about a specific MIDI input driver.           * Gets detailed information about a specific MIDI input driver.
2162           * @param driverName The name of the MIDI input driver.           * @param driverName The name of the MIDI input driver.
2163           *           * @param depList An optional list of dependences parameters.
2164           * @return A <code>MidiInputDriver</code> object containing           * @return A <code>MidiInputDriver</code> object containing
2165           * information about the specified MIDI input driver.           * information about the specified MIDI input driver.
2166           *           *
# Line 1816  public class Client { Line 2170  public class Client {
2170           *           *
2171           * @see #getMidiInputDriverNames           * @see #getMidiInputDriverNames
2172           */           */
2173          private synchronized MidiInputDriver          public synchronized MidiInputDriver
2174          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getMidiInputDriverInfo(String driverName, Parameter... depList)
2175                                            throws IOException, LscpException, LSException {
2176                    
2177                  verifyConnection();                  verifyConnection();
2178                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
2179                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1828  public class Client { Line 2184  public class Client {
2184                  mid.setName(driverName);                  mid.setName(driverName);
2185                                    
2186                  for(String s : mid.getParameterNames())                  for(String s : mid.getParameterNames())
2187                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s));                          mid.addParameter(getMidiInputDriverParameterInfo(driverName, s, depList));
2188                                    
2189                  return mid;                  return mid;
2190          }          }
# Line 1862  public class Client { Line 2218  public class Client {
2218                  StringBuffer args = new StringBuffer(driver);                  StringBuffer args = new StringBuffer(driver);
2219                  args.append(' ').append(param);                  args.append(' ').append(param);
2220                                    
2221                  for(Parameter p : deplist)                  for(Parameter p : deplist) {
2222                            if(p == null || p.getName() == null || p.getValue() == null) continue;
2223                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2224                    }
2225                                    
2226                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());                  out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());
2227                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 1925  public class Client { Line 2283  public class Client {
2283                  verifyConnection();                  verifyConnection();
2284                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2285                                    
2286                  for(Parameter p : paramList)                  for(Parameter p : paramList) {
2287                            if(p == null || p.getName() == null || p.getValue() == null) continue;
2288                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2289                    }
2290                                    
2291                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());                  out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());
2292                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
# Line 2071  public class Client { Line 2431  public class Client {
2431                                  mid.setActive(Boolean.parseBoolean(s));                                  mid.setActive(Boolean.parseBoolean(s));
2432                          } else if(s.startsWith("PORTS: ")) {                          } else if(s.startsWith("PORTS: ")) {
2433                                  s = s.substring("PORTS: ".length());                                  s = s.substring("PORTS: ".length());
2434                                  int ports = Parser.parseInt(s);                                  
2435                                  MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0];                                  Parameter<Integer> ports = (Parameter<Integer>)
2436                                            getMidiInputDriverParameterInfo(drv, "PORTS");
2437                                    
2438                                    ports.parseValue(s);
2439                                    mid.setPortsParameter(ports);
2440                                    
2441                                    int j = ports.getValue();
2442                                    MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0];
2443                                                                    
2444                                  for(int i = 0; i < midiPorts.length; i++)                                  for(int i = 0; i < midiPorts.length; i++)
2445                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);
# Line 2315  public class Client { Line 2682  public class Client {
2682          public synchronized int          public synchronized int
2683          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {
2684                  verifyConnection();                  verifyConnection();
2685                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + name + "'");                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedText(name) + "'");
2686                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
2687                                    
2688                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 2418  public class Client { Line 2785  public class Client {
2785                                    
2786                  for(String s : lnS) {                  for(String s : lnS) {
2787                          if(s.startsWith("NAME: ")) {                          if(s.startsWith("NAME: ")) {
2788                                  name = s.substring("NAME: ".length());                                  name = toNonEscapedString(s.substring("NAME: ".length()));
2789                          } else if(s.startsWith("DEFAULT: ")) {                          } else if(s.startsWith("DEFAULT: ")) {
2790                                  b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));                                  b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));
2791                          } else {                          } else {
# Line 2466  public class Client { Line 2833  public class Client {
2833                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
2834                                    
2835                  verifyConnection();                  verifyConnection();
2836                    name = toEscapedText(name);
2837                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");
2838                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
2839                                    
2840                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
2841          }          }
2842                    
2843            
2844            
2845          /**          /**
2846           * Creates or replaces a MIDI instrument map entry.           * Creates or replaces a MIDI instrument map entry.
2847           * @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 2856  public class Client {
2856          public synchronized void          public synchronized void
2857          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)
2858                                          throws IOException, LSException, LscpException {                                          throws IOException, LSException, LscpException {
2859                    mapMidiInstrument(mapId, entry, info, false);
2860            }
2861            
2862            /**
2863             * Creates or replaces a MIDI instrument map entry.
2864             * @param mapId The ID of the map, where this instrument should be mapped.
2865             * @param entry Specifies the position of the MIDI instrument in the MIDI instrument map.
2866             * @param info Provides the needed information of the
2867             * MIDI instrument, which will be mapped to the specified MIDI instrument map.
2868             * @param nonModal If <code>true</code> the function returns immediately
2869             * and the mapping is established in the background.
2870             * @throws IOException If some I/O error occurs.
2871             * @throws LSException If the mapping failed.
2872             * @throws LscpException If LSCP protocol corruption occurs.
2873             * @see #unmapMidiInstrument
2874             */
2875            public synchronized void
2876            mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info, boolean nonModal)
2877                                            throws IOException, LSException, LscpException {
2878                                    
2879                  verifyConnection();                  verifyConnection();
2880                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");
2881                    if(nonModal) cmd.append("NON_MODAL ");
2882                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
2883                  cmd.append(entry.getMidiBank()).append(' ');                  cmd.append(entry.getMidiBank()).append(' ');
2884                  cmd.append(entry.getMidiProgram()).append(' ');                  cmd.append(entry.getMidiProgram()).append(' ');
2885                  cmd.append(info.getEngine()).append(" '");                  cmd.append(info.getEngine()).append(" '");
2886                  cmd.append(info.getFileName()).append("' ");                  cmd.append(conv(info.getFilePath())).append("' ");
2887                  cmd.append(info.getInstrumentIndex()).append(' ');                  cmd.append(info.getInstrumentIndex()).append(' ');
2888                  cmd.append(info.getVolume());                  cmd.append(info.getVolume());
2889                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
2890                          cmd.append(' ').append(info.getLoadMode().name());                          cmd.append(' ').append(info.getLoadMode().name());
2891                  }                  }
2892                  if(info.getName() != null) cmd.append(" '").append(info.getName()).append("'");                  
2893                    if(info.getName() != null) {
2894                            String s = toEscapedText(info.getName());
2895                            cmd.append(" '").append(s).append("'");
2896                    }
2897                                    
2898                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
2899                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 2588  public class Client { Line 2982  public class Client {
2982          }          }
2983                    
2984          /**          /**
2985           * Gets all MIDI instrument contained int the specified MIDI instrument map.           * Gets all MIDI instrument entries contained int the specified MIDI instrument map.
2986             * @param mapId The ID of the map, which instruments should be obtained.
2987             * @return An int array providing all MIDI instrument entries
2988             * in the specified MIDI instrument map.
2989             * @throws IOException If some I/O error occurs.
2990             * @throws LscpException If LSCP protocol corruption occurs.
2991             * @throws LSException If some other error occurs.
2992             */
2993            public synchronized int[][]
2994            getMidiInstrumentEntries(int mapId) throws IOException, LscpException, LSException {
2995                    verifyConnection();
2996                    out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId));
2997                    if(getPrintOnlyMode()) return null;
2998                    
2999                    String[] entries = parseArray(getSingleLineResultSet().getResult());
3000                    int[][] e = new int[entries.length][3];
3001                    
3002                    for(int i = 0; i < entries.length; i++) {
3003                            Integer[] vals = parseIntList(entries[i]);
3004                            if(vals.length != 3) {
3005                                    throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
3006                            }
3007                            
3008                            e[i][0] = vals[0];
3009                            e[i][1] = vals[1];
3010                            e[i][2] = vals[2];
3011                    }
3012                    
3013                    return e;
3014            }
3015            
3016            /**
3017             * Gets all MIDI instruments contained int the specified MIDI instrument map.
3018           * @param mapId The ID of the map, which instruments should be obtained.           * @param mapId The ID of the map, which instruments should be obtained.
3019           * @return A <code>MidiInstrumentInfo</code> array providing           * @return A <code>MidiInstrumentInfo</code> array providing
3020           * all MIDI instruments from all MIDI instrument maps.           * all MIDI instruments in the specified MIDI instrument map.
3021           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
3022           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
3023           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
# Line 2639  public class Client { Line 3065  public class Client {
3065                                          throws IOException, LscpException, LSException {                                          throws IOException, LscpException, LSException {
3066                    
3067                  verifyConnection();                  verifyConnection();
3068                    requestMidiInstrumentInfo(mapId, bank, program);
3069                    return getMidiInstrumentInfoResponse(mapId, bank, program);
3070            }
3071            
3072            private void
3073            requestMidiInstrumentInfo(int mapId, int bank, int program) throws IOException {
3074                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");
3075                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
3076                  cmd.append(bank).append(' ');                  cmd.append(bank).append(' ');
3077                  cmd.append(program);                  cmd.append(program);
3078                                    
3079                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
3080                  if(getPrintOnlyMode()) return null;          }
3081            
3082            private MidiInstrumentInfo
3083            getMidiInstrumentInfoResponse(int mapId, int bank, int program)
3084                                            throws IOException, LscpException, LSException {
3085                                    
3086                    if(getPrintOnlyMode()) return null;
3087                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
3088                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
3089                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());
# Line 2696  public class Client { Line 3133  public class Client {
3133                                                  throws IOException, LscpException, LSException {                                                  throws IOException, LscpException, LSException {
3134                                    
3135                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";
3136                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;                  String args = '\'' + conv(filename) + "' " + instrIdx + ' ' + samplerChn;
3137                                    
3138                  out.writeLine(cmd + args);                  out.writeLine(cmd + args);
3139                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 3348  public class Client { Line 3785  public class Client {
3785                                    
3786                  verifyConnection();                  verifyConnection();
3787                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);
3788                  if(name != null) s += " '" + name + "'";                  if(name != null) s += " '" + toEscapedText(name) + "'";
3789                  out.writeLine("CREATE FX_SEND " + s);                  out.writeLine("CREATE FX_SEND " + s);
3790                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
3791                                    
# Line 3479  public class Client { Line 3916  public class Client {
3916                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
3917                                    
3918                  verifyConnection();                  verifyConnection();
3919                  String args = " " + channel + " " + fxSend + " '" + name + "'";                  String args = " " + channel + " " + fxSend + " '" + toEscapedText(name) + "'";
3920                  out.writeLine("SET FX_SEND NAME" + args);                  out.writeLine("SET FX_SEND NAME" + args);
3921                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3922                                    
# Line 3568  public class Client { Line 4005  public class Client {
4005          }          }
4006                    
4007          /**          /**
4008             * Starts an instrument editor for editing the loaded instrument
4009             * on the specified sampler channel.
4010             * @param samplerChn The sampler channel number.
4011             * @throws IOException If some I/O error occurs.
4012             * @throws LscpException If LSCP protocol corruption occurs.
4013             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
4014             * there is no instrument loaded on the specified sampler channel.
4015             * @see #getSamplerChannels
4016             */
4017            public synchronized void
4018            editChannelInstrument(int samplerChn) throws IOException, LscpException, LSException {
4019                    verifyConnection();
4020                    out.writeLine("EDIT CHANNEL INSTRUMENT " + samplerChn);
4021                    if(getPrintOnlyMode()) return;
4022                    
4023                    ResultSet rs = getEmptyResultSet();
4024            }
4025            
4026            /**
4027             * Sends a MIDI event to this sampler channel.
4028             * @param samplerChn The sampler channel number.
4029             * @param type The type of MIDI message to send.
4030             * @throws IOException If some I/O error occurs.
4031             * @throws LscpException If LSCP protocol corruption occurs.
4032             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
4033             * there is no instrument loaded on the specified sampler channel.
4034             * @see #getSamplerChannels
4035             */
4036            public synchronized void
4037            sendChannelMidiData(int samplerChn, MidiDataEvent.Type type, int arg1, int arg2)
4038                                                    throws IOException, LscpException, LSException {
4039                    
4040                    verifyConnection();
4041                    StringBuffer sb = new StringBuffer();
4042                    sb.append("SEND CHANNEL MIDI_DATA ");
4043                    sb.append(type).append(" ").append(samplerChn).append(" ");
4044                    sb.append(arg1).append(" ").append(arg2);
4045                    
4046                    out.writeLine(sb.toString());
4047                    if(getPrintOnlyMode()) return;
4048                    
4049                    ResultSet rs = getEmptyResultSet();
4050            }
4051            
4052            /**
4053           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4054           *           *
4055           * @param samplerChn The sampler channel number.           * @param samplerChn The sampler channel number.
# Line 3587  public class Client { Line 4069  public class Client {
4069                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4070          }          }
4071                    
4072            
4073            
4074            /**
4075             * Adds the specified directory to the instruments database.
4076             * @param dir The absolute (escaped) path name of the directory to add.
4077             * @throws IOException If some I/O error occurs.
4078             * @throws LSException If the creation of the directory failed.
4079             * @throws LscpException If LSCP protocol corruption occurs.
4080             */
4081            public synchronized void
4082            addDbDirectory(String dir) throws IOException, LSException, LscpException {
4083                    verifyConnection();
4084                    out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "'");
4085                    if(getPrintOnlyMode()) return;
4086                    
4087                    ResultSet rs = getEmptyResultSet();
4088            }
4089            
4090            /**
4091             * Removes the specified directory from the instruments database.
4092             * @param dir The absolute (escaped) path name of the directory to remove.
4093             * @throws IOException If some I/O error occurs.
4094             * @throws LscpException If LSCP protocol corruption occurs.
4095             * @throws LSException If the specified directory is not
4096             * empty or if the removal of the directory failed.
4097             */
4098            public synchronized void
4099            removeDbDirectory(String dir) throws IOException, LscpException, LSException {
4100                    removeDbDirectory(dir, false);
4101            }
4102            
4103            /**
4104             * Removes the specified directory from the instruments database.
4105             * @param dir The absolute path name of the directory to remove.
4106             * @param force If <code>true</code> forces the removal of non-empty
4107             * directory and all its content.
4108             * @throws IOException If some I/O error occurs.
4109             * @throws LscpException If LSCP protocol corruption occurs.
4110             * @throws LSException If the removing of the directory failed.
4111             */
4112            public synchronized void
4113            removeDbDirectory(String dir, boolean force)
4114                                    throws IOException, LscpException, LSException {
4115                    
4116                    verifyConnection();
4117                    String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
4118                    if(force) s += "FORCE ";
4119                    out.writeLine(s + "'" + conv(dir) + "'");
4120                    if(getPrintOnlyMode()) return;
4121                    
4122                    ResultSet rs = getEmptyResultSet();
4123            }
4124            
4125            /**
4126             * Removes the specified directories from the instruments database.
4127             * @param dirs The absolute (escaped) path names of the directories to remove.
4128             * @param force If <code>true</code> forces the removal of non-empty
4129             * directories.
4130             * @throws IOException If some I/O error occurs.
4131             * @throws LscpException If LSCP protocol corruption occurs.
4132             * @throws LSException If the removing of the directores failed.
4133             */
4134            public synchronized void
4135            removeDbDirectories(String[] dirs, boolean force)
4136                                    throws IOException, LscpException, LSException {
4137                    
4138                    verifyConnection();
4139                    String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
4140                    if(force) cmd += "FORCE ";
4141                    
4142                    for(String s : dirs) out.writeLine(cmd + "'" + conv(s) + "'");
4143                    
4144                    if(getPrintOnlyMode()) return;
4145                    
4146                    getEmptyResultSets(dirs.length, "Client.dirDeletionFailed!");
4147            }
4148            
4149            /**
4150             * Gets the number of directories in the specified directory.
4151             * @return The current number of directories in the specified directory.
4152             * @param dir The absolute path name of the directory.
4153             * @throws IOException If some I/O error occurs.
4154             * @throws LscpException If LSCP protocol corruption occurs.
4155             * @throws LSException If some other error occurs.
4156             */
4157            public synchronized int
4158            getDbDirectoryCount(String dir) throws IOException, LscpException, LSException {
4159                    return getDbDirectoryCount(dir, false);
4160            }
4161            
4162            /**
4163             * Gets the number of directories in the specified directory.
4164             * @return The current number of directories in the specified directory.
4165             * @param dir The absolute path name of the directory.
4166             * @param recursive If <code>true</code>, the number of all directories
4167             * in the specified subtree will be returned.
4168             * @throws IOException If some I/O error occurs.
4169             * @throws LscpException If LSCP protocol corruption occurs.
4170             * @throws LSException If some other error occurs.
4171             */
4172            public synchronized int
4173            getDbDirectoryCount(String dir, boolean recursive)
4174                                    throws IOException, LscpException, LSException {
4175                    
4176                    verifyConnection();
4177                    String s;
4178                    if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
4179                    else s = "GET DB_INSTRUMENT_DIRECTORIES '";
4180                    out.writeLine(s + conv(dir) + "'");
4181                    if(getPrintOnlyMode()) return -1;
4182                    
4183                    s = getSingleLineResultSet().getResult();
4184                    return parseInt(s);
4185            }
4186            
4187            /**
4188             * Gets the list of directories in the specified directory.
4189             * @param dir The absolute path name of the directory.
4190             * @return A <code>String</code> array providing the names of
4191             * all directories in the specified directory.
4192             * @throws IOException If some I/O error occurs.
4193             * @throws LscpException If LSCP protocol corruption occurs.
4194             * @throws LSException If the specified path name is invalid.
4195             */
4196            public synchronized String[]
4197            getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
4198                    verifyConnection();
4199                    out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + conv(dir) + "'");
4200                    if(getPrintOnlyMode()) return null;
4201                    
4202                    String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4203                    for(int i = 0; i < names.length; i++) {
4204                            names[i] = toNonEscapedString(names[i]);
4205                    }
4206                    return names;
4207            }
4208            
4209            /**
4210             * Gets information about the specified directory.
4211             * @param dir The absolute path name of the directory.
4212             * @return A <code>DbDirectoryInfo</code> instance providing information
4213             * about the specified directory.
4214             * @throws IOException If some I/O error occurs.
4215             * @throws LscpException If LSCP protocol corruption occurs.
4216             * @throws LSException If the specified directory is not found.
4217             */
4218            public synchronized DbDirectoryInfo
4219            getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
4220                    verifyConnection();
4221                    out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir) + "'");
4222                    if(getPrintOnlyMode()) return null;
4223                    
4224                    ResultSet rs = getMultiLineResultSet();
4225                    DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
4226                    if(dir.equals("/")) {
4227                            info.setName("/");
4228                    } else {
4229                            dir = removeEndingFileSeparator(dir);
4230                    }
4231                    String s = getFileName(dir);
4232                    if(s != null) info.setName(toNonEscapedFileName(s));
4233                    s = getParentDirectory(dir);
4234                    if(s != null) info.setParentDirectoryPath(s);
4235                    
4236                    return info;
4237            }
4238            
4239            /**
4240             * Gets the list of directories in the specified directory.
4241             * @param dir The absolute path name of the directory.
4242             * @return A <code>DbDirectoryInfo</code> array providing
4243             * information about all directories in the specified directory.
4244             * @throws IOException If some I/O error occurs.
4245             * @throws LscpException If LSCP protocol corruption occurs.
4246             * @throws LSException If the specified path name is invalid.
4247             */
4248            public synchronized DbDirectoryInfo[]
4249            getDbDirectories(String dir) throws IOException, LscpException, LSException {
4250                    String[] dirS = getDbDirectoryNames(dir);
4251                    if(!hasEndingFileSeparator(dir)) dir += "/";
4252                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4253                    for(int i = 0; i < dirS.length; i++) {
4254                            infoS[i] = getDbDirectoryInfo(conv(dir) + toEscapedFsEntry(dirS[i]));
4255                    }
4256                    return infoS;
4257            }
4258            
4259            /**
4260             * Gets the list of directories in the specified directory.
4261             * @param dir The absolute path name of the directory.
4262             * @return A <code>DbDirectoryInfo</code> array providing
4263             * information about all directories in the specified directory.
4264             * @throws IOException If some I/O error occurs.
4265             * @throws LscpException If LSCP protocol corruption occurs.
4266             * @throws LSException If the specified path name is invalid.
4267             *
4268            public synchronized DbDirectoryInfo[]
4269            getDbDirectories(String dir) throws IOException, LscpException, LSException {
4270                    String[] dirS = getDbDirectoryNames(conv(dir));
4271                    if(dirS.length == 0) return new DbDirectoryInfo[0];
4272                    
4273                    if(dir.charAt(dir.length() - 1) != '/') dir += "/"; // FIXME:
4274                    
4275                    for(int i = 0; i < dirS.length; i++) {
4276                            out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir + dirS[i]) + "'");
4277                    }
4278                    
4279                    if(getPrintOnlyMode()) return null;
4280                    
4281                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4282                    StringBuffer sb = new StringBuffer();
4283                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4284                    for(int i = 0; i < dirS.length; i++) {
4285                            try {
4286                                    ResultSet rs = getMultiLineResultSet();
4287                                    infoS[i] = new DbDirectoryInfo(rs.getMultiLineResult());
4288                                    infoS[i].setName(dirS[i]);
4289                                    infoS[i].setParentDirectoryPath(dir);
4290                            } catch (SocketTimeoutException e) {
4291                                    getLogger().log(Level.FINE, e.getMessage(), e);
4292                                    sb.append(e.getMessage()).append("\n");
4293                                    break;
4294                            } catch (Exception e) {
4295                                    getLogger().log(Level.FINE, e.getMessage(), e);
4296                                    sb.append(e.getMessage()).append("\n");
4297                            }
4298                    }
4299                    
4300                    String details = sb.toString();
4301                    if(details.length() > 0) {
4302                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4303                            throw new LSException(0, err, details);
4304                    }
4305                    
4306                    return infoS;
4307            }*/
4308            
4309            /**
4310             * Renames the specified directory.
4311             * @param dir The absolute path name of the directory to rename.
4312             * @param name The new name for the directory.
4313             * @throws IOException If some I/O error occurs.
4314             * @throws LSException If the renaming of the directory failed.
4315             * @throws LscpException If LSCP protocol corruption occurs.
4316             */
4317            public synchronized void
4318            renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4319                    verifyConnection();
4320                    name = toEscapedText(name);
4321                    out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + conv(dir) + "' '" + conv(name) + "'");
4322                    if(getPrintOnlyMode()) return;
4323                    
4324                    ResultSet rs = getEmptyResultSet();
4325            }
4326            
4327            /**
4328             * Moves the specified directory into the specified location.
4329             * @param dir The absolute path name of the directory to move.
4330             * @param dst The location where the directory will be moved to.
4331             * @throws IOException If some I/O error occurs.
4332             * @throws LSException If the operation failed.
4333             * @throws LscpException If LSCP protocol corruption occurs.
4334             */
4335            public synchronized void
4336            moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4337                    verifyConnection();
4338                    out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4339                    if(getPrintOnlyMode()) return;
4340                    
4341                    ResultSet rs = getEmptyResultSet();
4342            }
4343            
4344            /**
4345             * Moves the specified directories into the specified location.
4346             * @param dirs The absolute path names of the directories to move.
4347             * @param dst The location where the directories will be moved to.
4348             * @throws IOException If some I/O error occurs.
4349             * @throws LSException If the operation failed.
4350             * @throws LscpException If LSCP protocol corruption occurs.
4351             */
4352            public synchronized void
4353            moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4354                    verifyConnection();
4355                    for(String s : dirs) {
4356                            out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4357                    }
4358                    if(getPrintOnlyMode()) return;
4359                    
4360                    getEmptyResultSets(dirs.length, "Client.dirMovingFailed!");
4361            }
4362            
4363            /**
4364             * Copies the specified directory into the specified location.
4365             * @param dir The absolute path name of the directory to copy.
4366             * @param dst The location where the directory will be copied to.
4367             * @throws IOException If some I/O error occurs.
4368             * @throws LSException If the operation failed.
4369             * @throws LscpException If LSCP protocol corruption occurs.
4370             */
4371            public synchronized void
4372            copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4373                    verifyConnection();
4374                    out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4375                    if(getPrintOnlyMode()) return;
4376                    
4377                    ResultSet rs = getEmptyResultSet();
4378            }
4379            
4380            /**
4381             * Copies the specified directories into the specified location.
4382             * @param dirs The absolute path names of the directories to copy.
4383             * @param dst The location where the directories will be copied to.
4384             * @throws IOException If some I/O error occurs.
4385             * @throws LSException If the operation failed.
4386             * @throws LscpException If LSCP protocol corruption occurs.
4387             */
4388            public synchronized void
4389            copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4390                    verifyConnection();
4391                    for(String s : dirs) {
4392                            out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4393                    }
4394                    if(getPrintOnlyMode()) return;
4395                    
4396                    getEmptyResultSets(dirs.length, "Client.dirCopyingFailed!");
4397            }
4398            
4399            /**
4400             * Changes the description of the specified directory.
4401             * @param dir The absolute path name of the directory.
4402             * @param desc The new description for the directory.
4403             * @throws IOException If some I/O error occurs.
4404             * @throws LSException If failed to change the description.
4405             * @throws LscpException If LSCP protocol corruption occurs.
4406             */
4407            public synchronized void
4408            setDbDirectoryDescription(String dir, String desc)
4409                                    throws IOException, LSException, LscpException {
4410                    
4411                    verifyConnection();
4412                    String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4413                    out.writeLine(s + conv(dir) + "' '" + toEscapedText(desc) + "'");
4414                    if(getPrintOnlyMode()) return;
4415                    
4416                    ResultSet rs = getEmptyResultSet();
4417            }
4418            
4419            public static enum ScanMode {
4420                    RECURSIVE, NON_RECURSIVE, FLAT
4421            }
4422            
4423            /**
4424             * Adds the specified instrument to the specified instruments database directory.
4425             * @param dbDir The absolute path name of the database directory in which the
4426             * specified instrument will be added.
4427             * @param filePath The absolute path name of the instrument file.
4428             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4429             * @throws IOException If some I/O error occurs.
4430             * @throws LSException If the operation failed.
4431             * @throws LscpException If LSCP protocol corruption occurs.
4432             */
4433            public synchronized void
4434            addDbInstrument(String dbDir, String filePath, int instrIndex)
4435                                            throws IOException, LSException, LscpException {
4436                    
4437                    addDbInstrument(dbDir, filePath, instrIndex, false);
4438            }
4439            
4440            /**
4441             * Adds the specified instrument to the specified instruments database directory.
4442             * @param dbDir The absolute path name of the database directory in which the
4443             * specified instrument will be added.
4444             * @param filePath The absolute path name of the instrument file.
4445             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4446             * @param background If <code>true</code>, the scan will be done
4447             * in background and this method may return before the job is finished.
4448             * @return If <code>background</code> is <code>true</code>, the ID
4449             * of the scan job.
4450             * @throws IOException If some I/O error occurs.
4451             * @throws LSException If the operation failed.
4452             * @throws LscpException If LSCP protocol corruption occurs.
4453             * @see #addInstrumentsDbListener
4454             */
4455            public synchronized int
4456            addDbInstrument(String dbDir, String filePath, int instrIndex, boolean background)
4457                                            throws IOException, LSException, LscpException {
4458                    
4459                    verifyConnection();
4460                    String s = "ADD DB_INSTRUMENTS";
4461                    if(background) s += " NON_MODAL";
4462                    s += " '" + conv(dbDir) + "' '" + conv(filePath) + "' ";
4463                    out.writeLine(s + String.valueOf(instrIndex));
4464                    if(getPrintOnlyMode()) return -1;
4465                    
4466                    ResultSet rs = getEmptyResultSet();
4467                    return rs.getIndex();
4468            }
4469            
4470            /**
4471             * Adds the instruments in the specified file to the specified
4472             * instruments database directory.
4473             * @param dbDir The absolute path name of the database directory
4474             * in which the the supported instruments will be added.
4475             * @param filePath The absolute path name of the file to scan for instruments.
4476             * @throws IOException If some I/O error occurs.
4477             * @throws LSException If the operation failed.
4478             * @throws LscpException If LSCP protocol corruption occurs.
4479             */
4480            public synchronized void
4481            addDbInstruments(String dbDir, String filePath)
4482                                            throws IOException, LSException, LscpException {
4483                    
4484                    addDbInstruments(dbDir, filePath, false);
4485            }
4486            
4487            /**
4488             * Adds the instruments in the specified file to the specified
4489             * instruments database directory.
4490             * @param dbDir The absolute path name of the database directory
4491             * in which the the supported instruments will be added.
4492             * @param filePath The absolute path name of the file to scan for instruments.
4493             * @param background If <code>true</code>, the scan will be done
4494             * in background and this method may return before the job is finished.
4495             * @return If <code>background</code> is <code>true</code>, the ID
4496             * of the scan job.
4497             * @throws IOException If some I/O error occurs.
4498             * @throws LSException If the operation failed.
4499             * @throws LscpException If LSCP protocol corruption occurs.
4500             * @see #addInstrumentsDbListener
4501             */
4502            public synchronized int
4503            addDbInstruments(String dbDir, String filePath, boolean background)
4504                                            throws IOException, LSException, LscpException {
4505                    
4506                    verifyConnection();
4507                    String s = "ADD DB_INSTRUMENTS";
4508                    if(background) s += " NON_MODAL";
4509                    out.writeLine(s + " '" + conv(dbDir) + "' '" + conv(filePath) + "'");
4510                    if(getPrintOnlyMode()) return -1;
4511                    
4512                    ResultSet rs = getEmptyResultSet();
4513                    return rs.getIndex();
4514            }
4515            
4516            /**
4517             * Adds the instruments in the specified file system directory
4518             * to the specified instruments database directory.
4519             * @param mode Determines the scanning mode. If RECURSIVE is
4520             * specified, all supported instruments in the specified file system
4521             * direcotry will be added to the specified instruments database
4522             * directory, including the instruments in subdirectories
4523             * of the supplied directory. If NON_RECURSIVE is specified,
4524             * the instruments in the subdirectories will not be processed.
4525             * If FLAT is specified, all supported instruments in the specified
4526             * file system direcotry will be added, including the instruments in
4527             * subdirectories of the supplied directory, but the respective
4528             * subdirectory structure will not be recreated in the instruments
4529             * database and all instruments will be added directly in the
4530             * specified database directory.
4531             * @param dbDir The absolute path name of the database directory
4532             * in which the supported instruments will be added.
4533             * @param fsDir The absolute path name of the file system directory.
4534             * @throws IOException If some I/O error occurs.
4535             * @throws LSException If the operation failed.
4536             * @throws LscpException If LSCP protocol corruption occurs.
4537             */
4538            public synchronized void
4539            addDbInstruments(ScanMode mode, String dbDir, String fsDir)
4540                                            throws IOException, LSException, LscpException {
4541                    
4542                    addDbInstruments(mode, dbDir, fsDir, false);
4543            }
4544            
4545            /**
4546             * Adds the instruments in the specified file system directory
4547             * to the specified instruments database directory.
4548             * @param mode Determines the scanning mode. If RECURSIVE is
4549             * specified, all supported instruments in the specified file system
4550             * direcotry will be added to the specified instruments database
4551             * directory, including the instruments in subdirectories
4552             * of the supplied directory. If NON_RECURSIVE is specified,
4553             * the instruments in the subdirectories will not be processed.
4554             * If FLAT is specified, all supported instruments in the specified
4555             * file system direcotry will be added, including the instruments in
4556             * subdirectories of the supplied directory, but the respective
4557             * subdirectory structure will not be recreated in the instruments
4558             * database and all instruments will be added directly in the
4559             * specified database directory.
4560             * @param dbDir The absolute path name of the database directory
4561             * in which the supported instruments will be added.
4562             * @param fsDir The absolute path name of the file system directory.
4563             * @param background If <code>true</code>, the scan will be done
4564             * in background and this method may return before the job is finished.
4565             * @return If <code>background</code> is <code>true</code>, the ID
4566             * of the scan job.
4567             * @throws IOException If some I/O error occurs.
4568             * @throws LSException If the operation failed.
4569             * @throws LscpException If LSCP protocol corruption occurs.
4570             * @see #addInstrumentsDbListener
4571             */
4572            public synchronized int
4573            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4574                                            throws IOException, LSException, LscpException {
4575                    
4576                    return addDbInstruments(mode, dbDir, fsDir, background, false);
4577            }
4578            
4579            /**
4580             * Adds the instruments in the specified file system directory
4581             * to the specified instruments database directory.
4582             * @param mode Determines the scanning mode. If RECURSIVE is
4583             * specified, all supported instruments in the specified file system
4584             * direcotry will be added to the specified instruments database
4585             * directory, including the instruments in subdirectories
4586             * of the supplied directory. If NON_RECURSIVE is specified,
4587             * the instruments in the subdirectories will not be processed.
4588             * If FLAT is specified, all supported instruments in the specified
4589             * file system direcotry will be added, including the instruments in
4590             * subdirectories of the supplied directory, but the respective
4591             * subdirectory structure will not be recreated in the instruments
4592             * database and all instruments will be added directly in the
4593             * specified database directory.
4594             * @param dbDir The absolute path name of the database directory
4595             * in which the supported instruments will be added.
4596             * @param fsDir The absolute path name of the file system directory.
4597             * @param background If <code>true</code>, the scan will be done
4598             * in background and this method may return before the job is finished.
4599             * @param insDir If <code>true</code> a drieectory is created for each
4600             * instrument file.
4601             * @return If <code>background</code> is <code>true</code>, the ID
4602             * of the scan job.
4603             * @throws IOException If some I/O error occurs.
4604             * @throws LSException If the operation failed.
4605             * @throws LscpException If LSCP protocol corruption occurs.
4606             * @see #addInstrumentsDbListener
4607             */
4608            public synchronized int
4609            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background, boolean insDir)
4610                                            throws IOException, LSException, LscpException {
4611                    
4612                    verifyConnection();
4613                    StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4614                    if(background) sb.append(" NON_MODAL");
4615                    
4616                    switch(mode) {
4617                            case RECURSIVE:
4618                                    sb.append(" RECURSIVE");
4619                                    break;
4620                            case NON_RECURSIVE:
4621                                    sb.append(" NON_RECURSIVE");
4622                                    break;
4623                            case FLAT:
4624                                    sb.append(" FLAT");
4625                                    break;
4626                    }
4627                    if(insDir)
4628                            sb.append(" FILE_AS_DIR");
4629                    
4630                    sb.append(" '").append(conv(dbDir)).append("' '");
4631                    sb.append(conv(fsDir)).append("'");
4632                    out.writeLine(sb.toString());
4633                    if(getPrintOnlyMode()) return -1;
4634                    
4635                    ResultSet rs = getEmptyResultSet();
4636                    return rs.getIndex();
4637            }
4638    
4639            /**
4640             * Removes the specified instrument from the instruments database.
4641             * @param instr The absolute path name of the instrument to remove.
4642             * @throws IOException If some I/O error occurs.
4643             * @throws LscpException If LSCP protocol corruption occurs.
4644             * @throws LSException If the removing of the instrument failed.
4645             */
4646            public synchronized void
4647            removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4648                    
4649                    verifyConnection();
4650                    out.writeLine("REMOVE DB_INSTRUMENT '" + conv(instr) + "'");
4651                    if(getPrintOnlyMode()) return;
4652                    
4653                    ResultSet rs = getEmptyResultSet();
4654            }
4655            
4656            /**
4657             * Removes the specified instruments from the instruments database.
4658             * @param instrs The absolute path names of the instruments to remove.
4659             * @throws IOException If some I/O error occurs.
4660             * @throws LscpException If LSCP protocol corruption occurs.
4661             * @throws LSException If the removing of the instruments failed.
4662             */
4663            public synchronized void
4664            removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4665                    verifyConnection();
4666                    for(String s : instrs) {
4667                            out.writeLine("REMOVE DB_INSTRUMENT '" + conv(s) + "'");
4668                    }
4669                    if(getPrintOnlyMode()) return;
4670                    
4671                    getEmptyResultSets(instrs.length, "Client.instrDeletionFailed!");
4672            }
4673            
4674            /**
4675             * Gets the number of instruments in the specified directory.
4676             * @return The current number of instruments in the specified directory.
4677             * @param dir The absolute path name of the directory.
4678             * @throws IOException If some I/O error occurs.
4679             * @throws LscpException If LSCP protocol corruption occurs.
4680             * @throws LSException If some other error occurs.
4681             */
4682            public synchronized int
4683            getDbInstrumentCount(String dir) throws IOException, LscpException, LSException {
4684                    return getDbInstrumentCount(dir, false);
4685            }
4686            
4687            /**
4688             * Gets the number of instruments in the specified directory.
4689             * @return The current number of instruments in the specified directory.
4690             * @param dir The absolute path name of the directory.
4691             * @param recursive If <code>true</code>, the number of all instruments
4692             * in the specified subtree will be returned.
4693             * @throws IOException If some I/O error occurs.
4694             * @throws LscpException If LSCP protocol corruption occurs.
4695             * @throws LSException If some other error occurs.
4696             */
4697            public synchronized int
4698            getDbInstrumentCount(String dir, boolean recursive)
4699                                    throws IOException, LscpException, LSException {
4700                    
4701                    verifyConnection();
4702                    String s;
4703                    if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4704                    else s = "GET DB_INSTRUMENTS '";
4705                    out.writeLine(s + conv(dir) + "'");
4706                    if(getPrintOnlyMode()) return -1;
4707                    
4708                    s = getSingleLineResultSet().getResult();
4709                    return parseInt(s);
4710            }
4711            
4712            /**
4713             * Gets the list of instruments in the specified directory.
4714             * @param dir The absolute path name of the directory.
4715             * @return A <code>String</code> array providing the names of
4716             * all instruments in the specified directory.
4717             * @throws IOException If some I/O error occurs.
4718             * @throws LscpException If LSCP protocol corruption occurs.
4719             * @throws LSException If the specified path name is invalid.
4720             */
4721            public synchronized String[]
4722            getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4723                    verifyConnection();
4724                    out.writeLine("LIST DB_INSTRUMENTS '" + conv(dir) + "'");
4725                    if(getPrintOnlyMode()) return null;
4726                    
4727                    String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4728                    for(int i = 0; i < names.length; i++) {
4729                            names[i] = toNonEscapedString(names[i]);
4730                    }
4731                    return names;
4732            }
4733            
4734            /**
4735             * Gets information about the specified instrument.
4736             * @param instr The absolute path name of the instrument.
4737             * @return A <code>DbInstrumentInfo</code> instance providing information
4738             * about the specified instrument.
4739             * @throws IOException If some I/O error occurs.
4740             * @throws LscpException If LSCP protocol corruption occurs.
4741             * @throws LSException If the specified instrument is not found.
4742             */
4743            public synchronized DbInstrumentInfo
4744            getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4745                    verifyConnection();
4746                    out.writeLine("GET DB_INSTRUMENT INFO '" + conv(instr) + "'");
4747                    if(getPrintOnlyMode()) return null;
4748                    
4749                    ResultSet rs = getMultiLineResultSet();
4750                    DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4751                    String s = getParentDirectory(instr);
4752                    if(s != null) info.setDirectoryPath(s);
4753                    s = getFileName(instr);
4754                    if(s != null) info.setName(toNonEscapedFileName(s));
4755                    
4756                    return info;
4757            }
4758            
4759            /**
4760             * Gets the list of instruments in the specified directory.
4761             * @param dir The absolute path name of the directory.
4762             * @return A <code>DbInstrumentInfo</code> array providing
4763             * information about all instruments in the specified directory.
4764             * @throws IOException If some I/O error occurs.
4765             * @throws LscpException If LSCP protocol corruption occurs.
4766             * @throws LSException If the specified path name is invalid.
4767             */
4768            public synchronized DbInstrumentInfo[]
4769            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4770                    String[] instrS = getDbInstrumentNames(dir);
4771                    if(!hasEndingFileSeparator(dir)) dir += "/";
4772                    
4773                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4774                    for(int i = 0; i < instrS.length; i++) {
4775                            infoS[i] = getDbInstrumentInfo(conv(dir) + toEscapedFsEntry(instrS[i]));
4776                    }
4777                    return infoS;
4778            }
4779            
4780            /**
4781             * Gets the list of instruments in the specified directory.
4782             * @param dir The absolute path name of the directory.
4783             * @return A <code>DbInstrumentInfo</code> array providing
4784             * information about all instruments in the specified directory.
4785             * @throws IOException If some I/O error occurs.
4786             * @throws LscpException If LSCP protocol corruption occurs.
4787             * @throws LSException If the specified path name is invalid.
4788             *
4789            public synchronized DbInstrumentInfo[]
4790            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4791                    String[] instrS = getDbInstrumentNames(dir);
4792                    if(instrS.length == 0) return new DbInstrumentInfo[0];
4793                    
4794                    if(dir.charAt(dir.length() - 1) != '/') dir += "/"; FIXME:
4795                    
4796                    for(int i = 0; i < instrS.length; i++) {
4797                            out.writeLine("GET DB_INSTRUMENT INFO '" + conv(dir) + instrS[i] + "'");
4798                    }
4799                    
4800                    if(getPrintOnlyMode()) return null;
4801                    
4802                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4803                    StringBuffer sb = new StringBuffer();
4804                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4805                    for(int i = 0; i < instrS.length; i++) {
4806                            try {
4807                                    ResultSet rs = getMultiLineResultSet();
4808                                    infoS[i] = new DbInstrumentInfo(rs.getMultiLineResult());
4809                                    infoS[i].setName(instrS[i]);
4810                                    infoS[i].setDirectoryPath(dir);
4811                            } catch (SocketTimeoutException e) {
4812                                    getLogger().log(Level.FINE, e.getMessage(), e);
4813                                    sb.append(e.getMessage()).append("\n");
4814                                    break;
4815                            } catch (Exception e) {
4816                                    getLogger().log(Level.FINE, e.getMessage(), e);
4817                                    sb.append(e.getMessage()).append("\n");
4818                            }
4819                    }
4820                    
4821                    String details = sb.toString();
4822                    if(details.length() > 0) {
4823                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4824                            throw new LSException(0, err, details);
4825                    }
4826                    
4827                    return infoS;
4828            }*/
4829            
4830            /**
4831             * Renames the specified instrument.
4832             * @param instr The absolute path name of the instrument to rename.
4833             * @param name The new name for the instrument.
4834             * @throws IOException If some I/O error occurs.
4835             * @throws LSException If the renaming of the instrument failed.
4836             * @throws LscpException If LSCP protocol corruption occurs.
4837             */
4838            public synchronized void
4839            renameDbInstrument(String instr, String name)
4840                                    throws IOException, LSException, LscpException {
4841                    
4842                    verifyConnection();
4843                    name = toEscapedText(name);
4844                    out.writeLine("SET DB_INSTRUMENT NAME '" + conv(instr) + "' '" + conv(name) + "'");
4845                    if(getPrintOnlyMode()) return;
4846                    
4847                    ResultSet rs = getEmptyResultSet();
4848            }
4849            
4850            /**
4851             * Moves the specified instrument into the specified location.
4852             * @param instr The absolute path name of the instrument to move.
4853             * @param dst The directory where the specified instrument will be moved to.
4854             * @throws IOException If some I/O error occurs.
4855             * @throws LSException If the operation failed.
4856             * @throws LscpException If LSCP protocol corruption occurs.
4857             */
4858            public synchronized void
4859            moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4860                    verifyConnection();
4861                    out.writeLine("MOVE DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4862                    if(getPrintOnlyMode()) return;
4863                    
4864                    ResultSet rs = getEmptyResultSet();
4865            }
4866            
4867            /**
4868             * Moves the specified instruments into the specified location.
4869             * @param instrs The absolute path names of the instruments to move.
4870             * @param dst The directory where the specified instruments will be moved to.
4871             * @throws IOException If some I/O error occurs.
4872             * @throws LSException If the operation failed.
4873             * @throws LscpException If LSCP protocol corruption occurs.
4874             */
4875            public synchronized void
4876            moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4877                    verifyConnection();
4878                    for(String s : instrs) {
4879                            out.writeLine("MOVE DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4880                    }
4881                    if(getPrintOnlyMode()) return;
4882                    
4883                    getEmptyResultSets(instrs.length, "Client.instrMovingFailed!");
4884            }
4885            
4886            /**
4887             * Copies the specified instrument into the specified location.
4888             * @param instr The absolute path name of the instrument to copy.
4889             * @param dst The directory where the specified instrument will be copied to.
4890             * @throws IOException If some I/O error occurs.
4891             * @throws LSException If the operation failed.
4892             * @throws LscpException If LSCP protocol corruption occurs.
4893             */
4894            public synchronized void
4895            copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4896                    verifyConnection();
4897                    out.writeLine("COPY DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4898                    if(getPrintOnlyMode()) return;
4899                    
4900                    ResultSet rs = getEmptyResultSet();
4901            }
4902            
4903            /**
4904             * Copies the specified instruments into the specified location.
4905             * @param instrs The absolute path name of the instruments to copy.
4906             * @param dst The directory where the specified instruments will be copied to.
4907             * @throws IOException If some I/O error occurs.
4908             * @throws LSException If the operation failed.
4909             * @throws LscpException If LSCP protocol corruption occurs.
4910             */
4911            public synchronized void
4912            copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4913                    verifyConnection();
4914                    for(String s : instrs) {
4915                            out.writeLine("COPY DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4916                    }
4917                    if(getPrintOnlyMode()) return;
4918                    
4919                    getEmptyResultSets(instrs.length, "Client.instrCopyingFailed!");
4920            }
4921            
4922            /**
4923             * Changes the description of the specified instrument.
4924             * @param instr The absolute path name of the instrument.
4925             * @param desc The new description for the instrument.
4926             * @throws IOException If some I/O error occurs.
4927             * @throws LSException If failed to change the description.
4928             * @throws LscpException If LSCP protocol corruption occurs.
4929             */
4930            public synchronized void
4931            setDbInstrumentDescription(String instr, String desc)
4932                                    throws IOException, LSException, LscpException {
4933                    
4934                    verifyConnection();
4935                    desc = toEscapedText(desc);
4936                    out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + conv(instr) + "' '" + desc + "'");
4937                    if(getPrintOnlyMode()) return;
4938                    
4939                    ResultSet rs = getEmptyResultSet();
4940            }
4941            
4942            /**
4943             * Substitutes all occurrences of the instrument file
4944             * <code>oldPath</code> in the database, with <code>newPath</code>.
4945             * @param oldPath The absolute path name of the instrument file to substitute.
4946             * @param newPath The new absolute path name.
4947             * @throws IOException If some I/O error occurs.
4948             * @throws LSException If the operation failed.
4949             * @throws LscpException If LSCP protocol corruption occurs.
4950             */
4951            public synchronized void
4952            setDbInstrumentFilePath(String oldPath, String newPath)
4953                                    throws IOException, LSException, LscpException {
4954                    
4955                    verifyConnection();
4956                    out.writeLine("SET DB_INSTRUMENT FILE_PATH '" + conv(oldPath) + "' '" + conv(newPath) + "'");
4957                    if(getPrintOnlyMode()) return;
4958                    
4959                    ResultSet rs = getEmptyResultSet();
4960            }
4961            
4962            /**
4963             * Finds all directories in the specified directory
4964             * that corresponds to the specified search criterias.
4965             * @param dir The absolute path name of the directory to search.
4966             * @param query Provides the search criterias.
4967             * @return A <code>DbDirectoryInfo</code> array providing
4968             * information about all directories that are found in the specified directory.
4969             * @throws IOException If some I/O error occurs.
4970             * @throws LscpException If LSCP protocol corruption occurs.
4971             * @throws LSException If the specified path name is invalid.
4972             */
4973            public synchronized DbDirectoryInfo[]
4974            findDbDirectories(String dir, DbSearchQuery query)
4975                                    throws IOException, LscpException, LSException {
4976                    
4977                    return findDbDirectories(dir, query, false);
4978            }
4979            
4980            /**
4981             * Finds all directories in the specified directory
4982             * that corresponds to the specified search criterias.
4983             * @param dir The absolute path name of the directory to search.
4984             * @param query Provides the search criterias.
4985             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4986             * @return A <code>DbDirectoryInfo</code> array providing
4987             * information about all directories that are found in the specified directory.
4988             * @throws IOException If some I/O error occurs.
4989             * @throws LscpException If LSCP protocol corruption occurs.
4990             * @throws LSException If the specified path name is invalid.
4991             */
4992            public synchronized DbDirectoryInfo[]
4993            findDbDirectories(String dir, DbSearchQuery query, boolean nonRecursive)
4994                                    throws IOException, LscpException, LSException {
4995                    
4996                    verifyConnection();
4997                    StringBuffer sb = new StringBuffer();
4998                    sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4999                    if(nonRecursive) sb.append(" NON_RECURSIVE");
5000                    sb.append(" '").append(conv(dir)).append("'");
5001                    
5002                    if(query.name != null && query.name.length() > 0) {
5003                            sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
5004                    }
5005                    
5006                    String s = query.getCreatedAfter();
5007                    String s2 = query.getCreatedBefore();
5008                    if(s != null || s2 != null) {
5009                            sb.append(" CREATED='");
5010                            if(s != null) sb.append(s);
5011                            sb.append("..");
5012                            if(s2 != null) sb.append(s2);
5013                            sb.append("'");
5014                    }
5015                    
5016                    s = query.getModifiedAfter();
5017                    s2 = query.getModifiedBefore();
5018                    if(s != null || s2 != null) {
5019                            sb.append(" MODIFIED='");
5020                            if(s != null) sb.append(s);
5021                            sb.append("..");
5022                            if(s2 != null) sb.append(s2);
5023                            sb.append("'");
5024                    }
5025                    
5026                    if(query.description != null && query.description.length() > 0) {
5027                            sb.append(" DESCRIPTION='");
5028                            sb.append(toEscapedText(query.description)).append("'");
5029                    }
5030                    
5031                    out.writeLine(sb.toString());
5032                    if(getPrintOnlyMode()) return null;
5033                    
5034                    String[] dirS = parseEscapedStringList(getSingleLineResultSet().getResult());
5035                    
5036                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
5037                    for(int i = 0; i < dirS.length; i++) {
5038                            infoS[i] = getDbDirectoryInfo(dirS[i]);
5039                    }
5040                    return infoS;
5041            }
5042            
5043            /**
5044             * Finds all instruments in the specified directory
5045             * that corresponds to the specified search criterias.
5046             * @param dir The absolute path name of the directory to search.
5047             * @param query Provides the search criterias.
5048             * @return A <code>DbInstrumentInfo</code> array providing
5049             * information about all instruments that are found in the specified directory.
5050             * @throws IOException If some I/O error occurs.
5051             * @throws LscpException If LSCP protocol corruption occurs.
5052             * @throws LSException If the specified path name is invalid.
5053             */
5054            public synchronized DbInstrumentInfo[]
5055            findDbInstruments(String dir, DbSearchQuery query)
5056                                    throws IOException, LscpException, LSException {
5057                    
5058                    return findDbInstruments(dir, query, false);
5059            }
5060            
5061            /**
5062             * Finds all instruments in the specified directory
5063             * that corresponds to the specified search criterias.
5064             * @param dir The absolute path name of the directory to search.
5065             * @param query Provides the search criterias.
5066             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
5067             * @return A <code>DbInstrumentInfo</code> array providing
5068             * information about all instruments that are found in the specified directory.
5069             * @throws IOException If some I/O error occurs.
5070             * @throws LscpException If LSCP protocol corruption occurs.
5071             * @throws LSException If the specified path name is invalid.
5072             */
5073            public synchronized DbInstrumentInfo[]
5074            findDbInstruments(String dir, DbSearchQuery query, boolean nonRecursive)
5075                                    throws IOException, LscpException, LSException {
5076                    
5077                    verifyConnection();
5078                    StringBuffer sb = new StringBuffer();
5079                    sb.append("FIND DB_INSTRUMENTS");
5080                    if(nonRecursive) sb.append(" NON_RECURSIVE");
5081                    sb.append(" '").append(conv(dir)).append("'");
5082                    
5083                    if(query.name != null && query.name.length() > 0) {
5084                            sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
5085                    }
5086                    
5087                    if(query.formatFamilies.size() > 0) {
5088                            sb.append(" FORMAT_FAMILIES='").append(query.formatFamilies.get(0));
5089                            for(int i = 1; i < query.formatFamilies.size(); i++) {
5090                                    sb.append(',').append(query.formatFamilies.get(i));
5091                            }
5092                            sb.append("'");
5093                    }
5094                    
5095                    if(query.minSize != -1 || query.maxSize != -1) {
5096                            sb.append(" SIZE='");
5097                            if(query.minSize != -1) sb.append(query.minSize);
5098                            sb.append("..");
5099                            if(query.maxSize != -1) sb.append(query.maxSize);
5100                            sb.append("'");
5101                    }
5102                    
5103                    String s = query.getCreatedAfter();
5104                    String s2 = query.getCreatedBefore();
5105                    if(s != null || s2 != null) {
5106                            sb.append(" CREATED='");
5107                            if(s != null) sb.append(s);
5108                            sb.append("..");
5109                            if(s2 != null) sb.append(s2);
5110                            sb.append("'");
5111                    }
5112                    
5113                    s = query.getModifiedAfter();
5114                    s2 = query.getModifiedBefore();
5115                    if(s != null || s2 != null) {
5116                            sb.append(" MODIFIED='");
5117                            if(s != null) sb.append(s);
5118                            sb.append("..");
5119                            if(s2 != null) sb.append(s2);
5120                            sb.append("'");
5121                    }
5122                    
5123                    if(query.description != null && query.description.length() > 0) {
5124                            sb.append(" DESCRIPTION='");
5125                            sb.append(toEscapedText(query.description)).append("'");
5126                    }
5127                    
5128                    if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
5129                            sb.append(" IS_DRUM=");
5130                            if(query.instrumentType == DbSearchQuery.InstrumentType.DRUM) {
5131                                    sb.append("'true'");
5132                            } else {
5133                                    sb.append("'false'");
5134                            }
5135                    }
5136                    
5137                    if(query.product != null && query.product.length() > 0) {
5138                            sb.append(" PRODUCT='").append(toEscapedText(query.product)).append("'");
5139                    }
5140                    
5141                    if(query.artists != null && query.artists.length() > 0) {
5142                            sb.append(" ARTISTS='").append(toEscapedText(query.artists)).append("'");
5143                    }
5144                    
5145                    if(query.keywords != null && query.keywords.length() > 0) {
5146                            sb.append(" KEYWORDS='");
5147                            sb.append(toEscapedText(query.keywords)).append("'");
5148                    }
5149                    
5150                    out.writeLine(sb.toString());
5151                    if(getPrintOnlyMode()) return null;
5152                    
5153                    String[] instrS = parseEscapedStringList(getSingleLineResultSet().getResult());
5154                    
5155                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
5156                    for(int i = 0; i < instrS.length; i++) {
5157                            infoS[i] = getDbInstrumentInfo(instrS[i]);
5158                    }
5159                    return infoS;
5160            }
5161            
5162            /**
5163             * Returns a list of all instrument files in the database
5164             * that that don't exist in the filesystem.
5165             * @throws IOException If some I/O error occurs.
5166             * @throws LscpException If LSCP protocol corruption occurs.
5167             * @throws LSException If other error occurs.
5168             */
5169            public synchronized String[]
5170            findLostDbInstrumentFiles() throws IOException, LscpException, LSException {
5171                    
5172                    verifyConnection();
5173                    out.writeLine("FIND LOST DB_INSTRUMENT_FILES");
5174                    if(getPrintOnlyMode()) return null;
5175                    
5176                    return parseEscapedStringList(getSingleLineResultSet().getResult());
5177            }
5178            
5179            /**
5180             * Gets status information about the specified job.
5181             * @param jobId The ID of the job.
5182             * @return A <code>ScanJobInfo</code> instance providing information
5183             * about the specified job.
5184             * @throws IOException If some I/O error occurs.
5185             * @throws LscpException If LSCP protocol corruption occurs.
5186             * @throws LSException If the specified job is not found.
5187             */
5188            public synchronized ScanJobInfo
5189            getDbInstrumentsJobInfo(int jobId) throws IOException, LscpException, LSException {
5190                    verifyConnection();
5191                    out.writeLine("GET DB_INSTRUMENTS_JOB INFO " + String.valueOf(jobId));
5192                    if(getPrintOnlyMode()) return null;
5193                    
5194                    ResultSet rs = getMultiLineResultSet();
5195                    ScanJobInfo info = new ScanJobInfo(rs.getMultiLineResult());
5196                    
5197                    return info;
5198            }
5199            
5200            /**
5201             * Removes all instruments and directories and re-creates
5202             * the instruments database structure.
5203             * @throws IOException If some I/O error occurs.
5204             * @throws LscpException If LSCP protocol corruption occurs.
5205             * @throws LSException If the formatting of the instruments database failed.
5206             */
5207            public synchronized void
5208            formatInstrumentsDb() throws IOException, LscpException, LSException {
5209                    verifyConnection();
5210                    out.writeLine("FORMAT INSTRUMENTS_DB");
5211                    if(getPrintOnlyMode()) return;
5212                    
5213                    ResultSet rs = getEmptyResultSet();
5214            }
5215            
5216          /**          /**
5217           * Resets the whole sampler.           * Resets the whole sampler.
5218           *           *
# Line 3604  public class Client { Line 5230  public class Client {
5230          }          }
5231                    
5232          /**          /**
5233             * Gets the current number of all active streams.
5234             * @return The current number of all active streams.
5235             * @throws IOException If some I/O error occurs.
5236             * @throws LscpException If LSCP protocol corruption occurs.
5237             * @throws LSException If some other error occurs.
5238             */
5239            public synchronized int
5240            getTotalStreamCount() throws IOException, LscpException, LSException {
5241                    verifyConnection();
5242                    out.writeLine("GET TOTAL_STREAM_COUNT");
5243                    if(getPrintOnlyMode()) return -1;
5244                    
5245                    String s = getSingleLineResultSet().getResult();
5246                    return parseInt(s);
5247            }
5248            
5249            /**
5250           * Gets the current number of all active voices.           * Gets the current number of all active voices.
5251           * @return The current number of all active voices.           * @return The current number of all active voices.
5252           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 3658  public class Client { Line 5301  public class Client {
5301          }          }
5302                    
5303          /**          /**
5304           * Gets the golobal volume of the sampler.           * Gets the global volume of the sampler.
5305           * @return The golobal volume of the sampler.           * @return The global volume of the sampler.
5306           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
5307           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
5308           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
# Line 3693  public class Client { Line 5336  public class Client {
5336          }          }
5337                    
5338          /**          /**
5339             * Gets the global sampler-wide limit of maximum voices.
5340             * @return The global sampler-wide limit of maximum voices.
5341             * @throws IOException If some I/O error occurs.
5342             * @throws LscpException If LSCP protocol corruption occurs.
5343             * @throws LSException If some other error occurs.
5344             */
5345            public synchronized int
5346            getGlobalVoiceLimit() throws IOException, LscpException, LSException {
5347                    verifyConnection();
5348                    out.writeLine("GET VOICES");
5349                    if(getPrintOnlyMode()) return -1;
5350                    
5351                    String s = getSingleLineResultSet().getResult();
5352                    return parseInt(s);
5353            }
5354            
5355            /**
5356             * Sets the global sampler-wide limit of maximum voices.
5357             * @param maxVoices The new global limit of maximum voices.
5358             * @throws IOException If some I/O error occurs.
5359             * @throws LscpException If LSCP protocol corruption occurs.
5360             * @throws LSException If some other error occurs.
5361             * @see #getVolume
5362             */
5363            public synchronized void
5364            setGlobalVoiceLimit(int maxVoices) throws IOException, LscpException, LSException {
5365                    verifyConnection();
5366                    out.writeLine("SET VOICES " + maxVoices);
5367                    if(getPrintOnlyMode()) return;
5368                    
5369                    ResultSet rs = getEmptyResultSet();
5370            }
5371            
5372            /**
5373             * Gets the global sampler-wide limit of maximum disk streams.
5374             * @return The global sampler-wide limit of maximum disk streams.
5375             * @throws IOException If some I/O error occurs.
5376             * @throws LscpException If LSCP protocol corruption occurs.
5377             * @throws LSException If some other error occurs.
5378             */
5379            public synchronized int
5380            getGlobalStreamLimit() throws IOException, LscpException, LSException {
5381                    verifyConnection();
5382                    out.writeLine("GET STREAMS");
5383                    if(getPrintOnlyMode()) return -1;
5384                    
5385                    String s = getSingleLineResultSet().getResult();
5386                    return parseInt(s);
5387            }
5388            
5389            /**
5390             * Sets the global sampler-wide limit for maximum disk streams.
5391             * @param maxVoices The new global limit of maximum disk streams.
5392             * @throws IOException If some I/O error occurs.
5393             * @throws LscpException If LSCP protocol corruption occurs.
5394             * @throws LSException If some other error occurs.
5395             * @see #getVolume
5396             */
5397            public synchronized void
5398            setGlobalStreamLimit(int maxStreams) throws IOException, LscpException, LSException {
5399                    verifyConnection();
5400                    out.writeLine("SET STREAMS " + maxStreams);
5401                    if(getPrintOnlyMode()) return;
5402                    
5403                    ResultSet rs = getEmptyResultSet();
5404            }
5405            
5406            /**
5407             * Gets the number of instruments in the specified instrument file.
5408             * @param filename The absolute path name of the instrument file.
5409             * @return The number of instruments in the specified instrument file.
5410             * @throws IOException If some I/O error occurs.
5411             * @throws LscpException If LSCP protocol corruption occurs.
5412             * @throws LSException If the file is not found, or other error occur.
5413             */
5414            public synchronized int
5415            getFileInstrumentCount(String filename) throws IOException, LscpException, LSException {
5416                    verifyConnection();
5417                    out.writeLine("GET FILE INSTRUMENTS '" + conv(filename) +"'");
5418                    if(getPrintOnlyMode()) return -1;
5419                    
5420                    String s = getSingleLineResultSet().getResult();
5421                    return parseInt(s);
5422            }
5423            
5424            /**
5425             * Gets information about the instrument with index
5426             * <code>instrIdx</code> in the specified instrument file.
5427             * @param filename The absolute path name of the instrument file.
5428             * @param instrIdx The index of the instrument in the specified instrument file.
5429             * @throws IOException If some I/O error occurs.
5430             * @throws LscpException If LSCP protocol corruption occurs.
5431             * @throws LSException If failed to retrieve information.
5432             */
5433            public synchronized Instrument
5434            getFileInstrumentInfo(String filename, int instrIdx)
5435                                    throws IOException, LscpException, LSException {
5436                    
5437                    verifyConnection();
5438                    out.writeLine("GET FILE INSTRUMENT INFO '" + conv(filename) + "' " + String.valueOf(instrIdx));
5439                    if(getPrintOnlyMode()) return null;
5440                    
5441                    ResultSet rs = getMultiLineResultSet();
5442                    Instrument instr = new FileInstrument(rs.getMultiLineResult()) { };
5443                    
5444                    return instr;
5445            }
5446            
5447            /**
5448             * Gets the list of instruments in the specified instrument file.
5449             * @param filename The absolute path name of the instrument file.
5450             * @return An <code>Instrument</code> array providing
5451             * information about all instruments in the specified instrument file.
5452             * @throws IOException If some I/O error occurs.
5453             * @throws LscpException If LSCP protocol corruption occurs.
5454             * @throws LSException If the specified file name is invalid.
5455             */
5456            public synchronized Instrument[]
5457            getFileInstruments(String filename) throws IOException, LscpException, LSException {
5458                    int l = getFileInstrumentCount(filename);
5459                    if(l < 0) return null;
5460                    Instrument[] instrS = new FileInstrument[l];
5461                    
5462                    for(int i = 0; i < instrS.length; i++) {
5463                            instrS[i] = getFileInstrumentInfo(filename, i);
5464                    }
5465                    return instrS;
5466            }
5467            
5468            private static class FileInstrument extends AbstractInstrument {
5469                    FileInstrument(String[] resultSet) throws LscpException {
5470                            super(resultSet);
5471                    }
5472                    
5473                    public String
5474                    getEngine() {
5475                            // TODO: engine lookup?
5476                            return getFormatFamily();
5477                    }
5478                    
5479                    @Override
5480                    public boolean
5481                    parse(String s) throws LscpException {
5482                            if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true;
5483                            return super.parse(s);
5484                    }
5485            }
5486            
5487            private void
5488            getEmptyResultSets(int count, String err) throws LSException {
5489                    StringBuffer sb = new StringBuffer();
5490                    for(int i = 0; i < count; i++) {
5491                            try { getEmptyResultSet(); }
5492                            catch (SocketTimeoutException e) {
5493                                    getLogger().log(Level.FINE, e.getMessage(), e);
5494                                    sb.append(e.getMessage()).append("\n");
5495                                    break;
5496                            } catch (Exception e) {
5497                                    getLogger().log(Level.FINE, e.getMessage(), e);
5498                                    sb.append(e.getMessage()).append("\n");
5499                            }
5500                    }
5501                    
5502                    String details = sb.toString();
5503                    if(details.length() > 0) {
5504                            String s = LscpI18n.getLogMsg(err);
5505                            throw new LSException(0, s, details);
5506                    }
5507            }
5508            
5509            /**
5510           * Returns the logger for this library.           * Returns the logger for this library.
5511           * @return The logger for this library.           * @return The logger for this library.
5512           */           */

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

  ViewVC Help
Powered by ViewVC