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

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

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

revision 1421 by iliev, Sun Oct 14 18:08:45 2007 UTC revision 1781 by iliev, Mon Sep 29 18:21:21 2008 UTC
# Line 1  Line 1 
1  /*  /*
2   *   jlscp - a java LinuxSampler control protocol API   *   jlscp - a java LinuxSampler control protocol API
3   *   *
4   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of jlscp.   *   This file is part of jlscp.
7   *   *
# Line 41  import static org.linuxsampler.lscp.Pars Line 41  import static org.linuxsampler.lscp.Pars
41    
42  /**  /**
43   * This class is the abstraction representing a client endpoint for communication with LinuxSampler   * This class is the abstraction representing a client endpoint for communication with LinuxSampler
44   * instance. Since it implements all commands specified in the LSCP protocol v1.1, for more   * instance. Since it implements all commands specified in the LSCP protocol v1.3, for more
45   * information look at the   * information look at the
46   * <a href=http://www.linuxsampler.org/api/lscp-1.1.html>LSCP</a> specification.   * <a href=http://www.linuxsampler.org/api/lscp-1.3.html>LSCP</a> specification.
47   *   *
48   * <p> The following code establishes connection to LinuxSampler instance and gets the   * <p> The following code establishes connection to LinuxSampler instance and gets the
49   * LinuxSampler version:   * LinuxSampler version:
# Line 164  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) { this.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 344  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()) {                  if(!llID.isEmpty()) {
401                          subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");                          subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
402                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
403                          subscribe("DB_INSTRUMENT_COUNT");                          subscribe("DB_INSTRUMENT_COUNT");
404                          subscribe("DB_INSTRUMENT_INFO");                          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          }          }
# Line 485  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 497  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>();          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                    
# Line 522  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()   ||                          !llID.isEmpty()   ||
586                          !llGI.isEmpty();                          !llGI.isEmpty();
587          }          }
588                    
589          private synchronized 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("DB_INSTRUMENT_DIRECTORY_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());                          s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
666                          InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);                          InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
667                          for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);                          for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
# Line 662  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 1134  public class Client { Line 1273  public class Client {
1273          /**          /**
1274           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1275           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1276             * @param l The <code>TotalStreamCountListener</code> to register.
1277             */
1278            public synchronized void
1279            addTotalStreamCountListener(TotalStreamCountListener l) {
1280                    if(llTSC.isEmpty()) subscribe("TOTAL_STREAM_COUNT");
1281                    llTSC.add(l);
1282            }
1283            
1284            /**
1285             * Removes the specified listener.
1286             * Listeners can be removed regardless of the connection state.
1287             * @param l The <code>TotalStreamCountListener</code> to remove.
1288             */
1289            public synchronized void
1290            removeTotalStreamCountListener(TotalStreamCountListener l) {
1291                    boolean b = llTSC.remove(l);
1292                    if(b && llTSC.isEmpty()) unsubscribe("TOTAL_STREAM_COUNT");
1293            }
1294            
1295            /**
1296             * Registers the specified listener for receiving event messages.
1297             * Listeners can be registered regardless of the connection state.
1298           * @param l The <code>TotalVoiceCountListener</code> to register.           * @param l The <code>TotalVoiceCountListener</code> to register.
1299           */           */
1300          public synchronized void          public synchronized void
# Line 1244  public class Client { Line 1405  public class Client {
1405          /**          /**
1406           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1407           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1408             * @param l The <code>DeviceMidiDataListener</code> to register.
1409             */
1410            public synchronized void
1411            addDeviceMidiDataListener(DeviceMidiDataListener l) {
1412                    if(llDMD.isEmpty()) subscribe("DEVICE_MIDI");
1413                    llDMD.add(l);
1414            }
1415            
1416            /**
1417             * Removes the specified listener.
1418             * Listeners can be removed regardless of the connection state.
1419             * @param l The <code>DeviceMidiDataListener</code> to remove.
1420             */
1421            public synchronized void
1422            removeDeviceMidiDataListener(DeviceMidiDataListener l) {
1423                    boolean b = llDMD.remove(l);
1424                    if(b && llDMD.isEmpty()) unsubscribe("DEVICE_MIDI");
1425            }
1426            
1427            /**
1428             * Registers the specified listener for receiving event messages.
1429             * Listeners can be registered regardless of the connection state.
1430             * @param l The <code>ChannelMidiDataListener</code> to register.
1431             */
1432            public synchronized void
1433            addChannelMidiDataListener(ChannelMidiDataListener l) {
1434                    if(llCMD.isEmpty()) subscribe("CHANNEL_MIDI");
1435                    llCMD.add(l);
1436            }
1437            
1438            /**
1439             * Removes the specified listener.
1440             * Listeners can be removed regardless of the connection state.
1441             * @param l The <code>ChannelMidiDataListener</code> to remove.
1442             */
1443            public synchronized void
1444            removeChannelMidiDataListener(ChannelMidiDataListener l) {
1445                    boolean b = llCMD.remove(l);
1446                    if(b && llCMD.isEmpty()) unsubscribe("CHANNEL_MIDI");
1447            }
1448            
1449            /**
1450             * Registers the specified listener for receiving event messages.
1451             * Listeners can be registered regardless of the connection state.
1452           * @param l The <code>InstrumentsDbListener</code> to register.           * @param l The <code>InstrumentsDbListener</code> to register.
1453           */           */
1454          public synchronized void          public synchronized void
# Line 1418  public class Client { Line 1623  public class Client {
1623                  args.append(' ').append(param);                  args.append(' ').append(param);
1624                                    
1625                  for(Parameter p : deplist) {                  for(Parameter p : deplist) {
1626                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
1627                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1628                  }                  }
1629                                    
# Line 1482  public class Client { Line 1687  public class Client {
1687                  StringBuffer args = new StringBuffer(aoDriver);                  StringBuffer args = new StringBuffer(aoDriver);
1688                                    
1689                  for(Parameter p : paramList) {                  for(Parameter p : paramList) {
1690                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
1691                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1692                  }                  }
1693                                    
# Line 2004  public class Client { Line 2209  public class Client {
2209                  args.append(' ').append(param);                  args.append(' ').append(param);
2210                                    
2211                  for(Parameter p : deplist) {                  for(Parameter p : deplist) {
2212                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
2213                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2214                  }                  }
2215                                    
# Line 2069  public class Client { Line 2274  public class Client {
2274                  StringBuffer args = new StringBuffer(miDriver);                  StringBuffer args = new StringBuffer(miDriver);
2275                                    
2276                  for(Parameter p : paramList) {                  for(Parameter p : paramList) {
2277                          if(p.getValue() == null) continue;                          if(p == null || p.getName() == null || p.getValue() == null) continue;
2278                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());                          args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2279                  }                  }
2280                                    
# Line 2216  public class Client { Line 2421  public class Client {
2421                                  mid.setActive(Boolean.parseBoolean(s));                                  mid.setActive(Boolean.parseBoolean(s));
2422                          } else if(s.startsWith("PORTS: ")) {                          } else if(s.startsWith("PORTS: ")) {
2423                                  s = s.substring("PORTS: ".length());                                  s = s.substring("PORTS: ".length());
2424                                  int ports = Parser.parseInt(s);                                  
2425                                  MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0];                                  Parameter<Integer> ports = (Parameter<Integer>)
2426                                            getMidiInputDriverParameterInfo(drv, "PORTS");
2427                                    
2428                                    ports.parseValue(s);
2429                                    mid.setPortsParameter(ports);
2430                                    
2431                                    int j = ports.getValue();
2432                                    MidiPort[] midiPorts = new MidiPort[j > 0 ? j : 0];
2433                                                                    
2434                                  for(int i = 0; i < midiPorts.length; i++)                                  for(int i = 0; i < midiPorts.length; i++)
2435                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);                                          midiPorts[i] = getMidiInputPortInfo(deviceId, i);
# Line 2460  public class Client { Line 2672  public class Client {
2672          public synchronized int          public synchronized int
2673          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {          addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {
2674                  verifyConnection();                  verifyConnection();
2675                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedString(name) + "'");                  out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedText(name) + "'");
2676                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
2677                                    
2678                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 2611  public class Client { Line 2823  public class Client {
2823                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
2824                                    
2825                  verifyConnection();                  verifyConnection();
2826                  name = toEscapedString(name);                  name = toEscapedText(name);
2827                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");                  out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " +  + mapId + " '" + name + "'");
2828                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
2829                                    
# Line 2661  public class Client { Line 2873  public class Client {
2873                  cmd.append(entry.getMidiBank()).append(' ');                  cmd.append(entry.getMidiBank()).append(' ');
2874                  cmd.append(entry.getMidiProgram()).append(' ');                  cmd.append(entry.getMidiProgram()).append(' ');
2875                  cmd.append(info.getEngine()).append(" '");                  cmd.append(info.getEngine()).append(" '");
2876                  cmd.append(info.getFilePath()).append("' ");                  cmd.append(conv(info.getFilePath())).append("' ");
2877                  cmd.append(info.getInstrumentIndex()).append(' ');                  cmd.append(info.getInstrumentIndex()).append(' ');
2878                  cmd.append(info.getVolume());                  cmd.append(info.getVolume());
2879                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
# Line 2669  public class Client { Line 2881  public class Client {
2881                  }                  }
2882                                    
2883                  if(info.getName() != null) {                  if(info.getName() != null) {
2884                          String s = toEscapedString(info.getName());                          String s = toEscapedText(info.getName());
2885                          cmd.append(" '").append(s).append("'");                          cmd.append(" '").append(s).append("'");
2886                  }                  }
2887                                    
# Line 2760  public class Client { Line 2972  public class Client {
2972          }          }
2973                    
2974          /**          /**
2975           * Gets all MIDI instrument contained int the specified MIDI instrument map.           * Gets all MIDI instrument entries contained int the specified MIDI instrument map.
2976             * @param mapId The ID of the map, which instruments should be obtained.
2977             * @return An int array providing all MIDI instrument entries
2978             * in the specified MIDI instrument map.
2979             * @throws IOException If some I/O error occurs.
2980             * @throws LscpException If LSCP protocol corruption occurs.
2981             * @throws LSException If some other error occurs.
2982             */
2983            public synchronized int[][]
2984            getMidiInstrumentEntries(int mapId) throws IOException, LscpException, LSException {
2985                    verifyConnection();
2986                    out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId));
2987                    if(getPrintOnlyMode()) return null;
2988                    
2989                    String[] entries = parseArray(getSingleLineResultSet().getResult());
2990                    int[][] e = new int[entries.length][3];
2991                    
2992                    for(int i = 0; i < entries.length; i++) {
2993                            Integer[] vals = parseIntList(entries[i]);
2994                            if(vals.length != 3) {
2995                                    throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
2996                            }
2997                            
2998                            e[i][0] = vals[0];
2999                            e[i][1] = vals[1];
3000                            e[i][2] = vals[2];
3001                    }
3002                    
3003                    return e;
3004            }
3005            
3006            /**
3007             * Gets all MIDI instruments contained int the specified MIDI instrument map.
3008           * @param mapId The ID of the map, which instruments should be obtained.           * @param mapId The ID of the map, which instruments should be obtained.
3009           * @return A <code>MidiInstrumentInfo</code> array providing           * @return A <code>MidiInstrumentInfo</code> array providing
3010           * all MIDI instruments from all MIDI instrument maps.           * all MIDI instruments in the specified MIDI instrument map.
3011           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
3012           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
3013           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
# Line 2811  public class Client { Line 3055  public class Client {
3055                                          throws IOException, LscpException, LSException {                                          throws IOException, LscpException, LSException {
3056                    
3057                  verifyConnection();                  verifyConnection();
3058                    requestMidiInstrumentInfo(mapId, bank, program);
3059                    return getMidiInstrumentInfoResponse(mapId, bank, program);
3060            }
3061            
3062            private void
3063            requestMidiInstrumentInfo(int mapId, int bank, int program) throws IOException {
3064                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");                  StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");
3065                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
3066                  cmd.append(bank).append(' ');                  cmd.append(bank).append(' ');
3067                  cmd.append(program);                  cmd.append(program);
3068                                    
3069                  out.writeLine(cmd.toString());                  out.writeLine(cmd.toString());
3070                  if(getPrintOnlyMode()) return null;          }
3071            
3072            private MidiInstrumentInfo
3073            getMidiInstrumentInfoResponse(int mapId, int bank, int program)
3074                                            throws IOException, LscpException, LSException {
3075                                    
3076                    if(getPrintOnlyMode()) return null;
3077                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
3078                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);                  MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
3079                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());                  return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());
# Line 2868  public class Client { Line 3123  public class Client {
3123                                                  throws IOException, LscpException, LSException {                                                  throws IOException, LscpException, LSException {
3124                                    
3125                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";
3126                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;                  String args = '\'' + conv(filename) + "' " + instrIdx + ' ' + samplerChn;
3127                                    
3128                  out.writeLine(cmd + args);                  out.writeLine(cmd + args);
3129                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
# Line 3520  public class Client { Line 3775  public class Client {
3775                                    
3776                  verifyConnection();                  verifyConnection();
3777                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);                  String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);
3778                  if(name != null) s += " '" + toEscapedString(name) + "'";                  if(name != null) s += " '" + toEscapedText(name) + "'";
3779                  out.writeLine("CREATE FX_SEND " + s);                  out.writeLine("CREATE FX_SEND " + s);
3780                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
3781                                    
# Line 3651  public class Client { Line 3906  public class Client {
3906                                  throws IOException, LscpException, LSException {                                  throws IOException, LscpException, LSException {
3907                                    
3908                  verifyConnection();                  verifyConnection();
3909                  String args = " " + channel + " " + fxSend + " '" + toEscapedString(name) + "'";                  String args = " " + channel + " " + fxSend + " '" + toEscapedText(name) + "'";
3910                  out.writeLine("SET FX_SEND NAME" + args);                  out.writeLine("SET FX_SEND NAME" + args);
3911                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
3912                                    
# Line 3758  public class Client { Line 4013  public class Client {
4013                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4014          }          }
4015                    
4016            /**
4017             * Sends a MIDI event to this sampler channel.
4018             * @param samplerChn The sampler channel number.
4019             * @param type The type of MIDI message to send.
4020             * @throws IOException If some I/O error occurs.
4021             * @throws LscpException If LSCP protocol corruption occurs.
4022             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
4023             * there is no instrument loaded on the specified sampler channel.
4024             * @see #getSamplerChannels
4025             */
4026            public synchronized void
4027            sendChannelMidiData(int samplerChn, MidiDataEvent.Type type, int arg1, int arg2)
4028                                                    throws IOException, LscpException, LSException {
4029                    
4030                    verifyConnection();
4031                    StringBuffer sb = new StringBuffer();
4032                    sb.append("SEND CHANNEL MIDI_DATA ");
4033                    sb.append(type).append(" ").append(samplerChn).append(" ");
4034                    sb.append(arg1).append(" ").append(arg2);
4035                    
4036                    out.writeLine(sb.toString());
4037                    if(getPrintOnlyMode()) return;
4038                    
4039                    ResultSet rs = getEmptyResultSet();
4040            }
4041            
4042            /**
4043             * Resets the specified sampler channel.
4044             *
4045             * @param samplerChn The sampler channel number.
4046             *
4047             * @throws IOException If some I/O error occurs.
4048             * @throws LscpException If LSCP protocol corruption occurs.
4049             * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
4050             * there is no engine assigned yet to the specified sampler channel.
4051             * @see #getSamplerChannels
4052             */
4053            public synchronized void
4054            resetChannel(int samplerChn) throws IOException, LscpException, LSException {
4055                    verifyConnection();
4056                    out.writeLine("RESET CHANNEL " + samplerChn);
4057                    if(getPrintOnlyMode()) return;
4058                    
4059                    ResultSet rs = getEmptyResultSet();
4060            }
4061            
4062                    
4063                    
4064          /**          /**
# Line 3770  public class Client { Line 4071  public class Client {
4071          public synchronized void          public synchronized void
4072          addDbDirectory(String dir) throws IOException, LSException, LscpException {          addDbDirectory(String dir) throws IOException, LSException, LscpException {
4073                  verifyConnection();                  verifyConnection();
4074                  out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");                  out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "'");
4075                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4076                                    
4077                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3805  public class Client { Line 4106  public class Client {
4106                  verifyConnection();                  verifyConnection();
4107                  String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";                  String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
4108                  if(force) s += "FORCE ";                  if(force) s += "FORCE ";
4109                  out.writeLine(s + "'" + dir + "'");                  out.writeLine(s + "'" + conv(dir) + "'");
4110                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4111                                    
4112                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3828  public class Client { Line 4129  public class Client {
4129                  String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";                  String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
4130                  if(force) cmd += "FORCE ";                  if(force) cmd += "FORCE ";
4131                                    
4132                  for(String s : dirs) out.writeLine(cmd + "'" + s + "'");                  for(String s : dirs) out.writeLine(cmd + "'" + conv(s) + "'");
4133                                    
4134                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4135                                    
# Line 3866  public class Client { Line 4167  public class Client {
4167                  String s;                  String s;
4168                  if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";                  if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
4169                  else s = "GET DB_INSTRUMENT_DIRECTORIES '";                  else s = "GET DB_INSTRUMENT_DIRECTORIES '";
4170                  out.writeLine(s + dir + "'");                  out.writeLine(s + conv(dir) + "'");
4171                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4172                                    
4173                  s = getSingleLineResultSet().getResult();                  s = getSingleLineResultSet().getResult();
# Line 3885  public class Client { Line 4186  public class Client {
4186          public synchronized String[]          public synchronized String[]
4187          getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {          getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
4188                  verifyConnection();                  verifyConnection();
4189                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + conv(dir) + "'");
4190                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4191                                    
4192                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
# Line 3907  public class Client { Line 4208  public class Client {
4208          public synchronized DbDirectoryInfo          public synchronized DbDirectoryInfo
4209          getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {          getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
4210                  verifyConnection();                  verifyConnection();
4211                  out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");                  out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir) + "'");
4212                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4213                                    
4214                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
# Line 3940  public class Client { Line 4241  public class Client {
4241                  if(!hasEndingFileSeparator(dir)) dir += "/";                  if(!hasEndingFileSeparator(dir)) dir += "/";
4242                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4243                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
4244                          infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i]));                          infoS[i] = getDbDirectoryInfo(conv(dir) + toEscapedFsEntry(dirS[i]));
4245                  }                  }
4246                  return infoS;                  return infoS;
4247          }          }
# Line 3956  public class Client { Line 4257  public class Client {
4257           *           *
4258          public synchronized DbDirectoryInfo[]          public synchronized DbDirectoryInfo[]
4259          getDbDirectories(String dir) throws IOException, LscpException, LSException {          getDbDirectories(String dir) throws IOException, LscpException, LSException {
4260                  String[] dirS = getDbDirectoryNames(dir);                  String[] dirS = getDbDirectoryNames(conv(dir));
4261                  if(dirS.length == 0) return new DbDirectoryInfo[0];                  if(dirS.length == 0) return new DbDirectoryInfo[0];
4262                                    
4263                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(dir.charAt(dir.length() - 1) != '/') dir += "/"; // FIXME:
4264                                    
4265                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
4266                          out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");                          out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir + dirS[i]) + "'");
4267                  }                  }
4268                                    
4269                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 4006  public class Client { Line 4307  public class Client {
4307          public synchronized void          public synchronized void
4308          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4309                  verifyConnection();                  verifyConnection();
4310                  name = toEscapedString(name);                  name = toEscapedText(name);
4311                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + conv(dir) + "' '" + conv(name) + "'");
4312                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4313                                    
4314                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4024  public class Client { Line 4325  public class Client {
4325          public synchronized void          public synchronized void
4326          moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {          moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4327                  verifyConnection();                  verifyConnection();
4328                  out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");                  out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4329                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4330                                    
4331                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4042  public class Client { Line 4343  public class Client {
4343          moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {          moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4344                  verifyConnection();                  verifyConnection();
4345                  for(String s : dirs) {                  for(String s : dirs) {
4346                          out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");                          out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4347                  }                  }
4348                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4349                                    
# Line 4060  public class Client { Line 4361  public class Client {
4361          public synchronized void          public synchronized void
4362          copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {          copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4363                  verifyConnection();                  verifyConnection();
4364                  out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");                  out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4365                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4366                                    
4367                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4078  public class Client { Line 4379  public class Client {
4379          copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {          copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4380                  verifyConnection();                  verifyConnection();
4381                  for(String s : dirs) {                  for(String s : dirs) {
4382                          out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");                          out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4383                  }                  }
4384                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4385                                    
# Line 4099  public class Client { Line 4400  public class Client {
4400                                    
4401                  verifyConnection();                  verifyConnection();
4402                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4403                  out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'");                  out.writeLine(s + conv(dir) + "' '" + toEscapedText(desc) + "'");
4404                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4405                                    
4406                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4148  public class Client { Line 4449  public class Client {
4449                  verifyConnection();                  verifyConnection();
4450                  String s = "ADD DB_INSTRUMENTS";                  String s = "ADD DB_INSTRUMENTS";
4451                  if(background) s += " NON_MODAL";                  if(background) s += " NON_MODAL";
4452                  s += " '" + dbDir + "' '" + filePath + "' ";                  s += " '" + conv(dbDir) + "' '" + conv(filePath) + "' ";
4453                  out.writeLine(s + String.valueOf(instrIndex));                  out.writeLine(s + String.valueOf(instrIndex));
4454                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4455                                    
# Line 4195  public class Client { Line 4496  public class Client {
4496                  verifyConnection();                  verifyConnection();
4497                  String s = "ADD DB_INSTRUMENTS";                  String s = "ADD DB_INSTRUMENTS";
4498                  if(background) s += " NON_MODAL";                  if(background) s += " NON_MODAL";
4499                  out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");                  out.writeLine(s + " '" + conv(dbDir) + "' '" + conv(filePath) + "'");
4500                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4501                                    
4502                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4262  public class Client { Line 4563  public class Client {
4563          addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)          addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4564                                          throws IOException, LSException, LscpException {                                          throws IOException, LSException, LscpException {
4565                                    
4566                    return addDbInstruments(mode, dbDir, fsDir, background, false);
4567            }
4568            
4569            /**
4570             * Adds the instruments in the specified file system directory
4571             * to the specified instruments database directory.
4572             * @param mode Determines the scanning mode. If RECURSIVE is
4573             * specified, all supported instruments in the specified file system
4574             * direcotry will be added to the specified instruments database
4575             * directory, including the instruments in subdirectories
4576             * of the supplied directory. If NON_RECURSIVE is specified,
4577             * the instruments in the subdirectories will not be processed.
4578             * If FLAT is specified, all supported instruments in the specified
4579             * file system direcotry will be added, including the instruments in
4580             * subdirectories of the supplied directory, but the respective
4581             * subdirectory structure will not be recreated in the instruments
4582             * database and all instruments will be added directly in the
4583             * specified database directory.
4584             * @param dbDir The absolute path name of the database directory
4585             * in which the supported instruments will be added.
4586             * @param fsDir The absolute path name of the file system directory.
4587             * @param background If <code>true</code>, the scan will be done
4588             * in background and this method may return before the job is finished.
4589             * @param insDir If <code>true</code> a drieectory is created for each
4590             * instrument file.
4591             * @return If <code>background</code> is <code>true</code>, the ID
4592             * of the scan job.
4593             * @throws IOException If some I/O error occurs.
4594             * @throws LSException If the operation failed.
4595             * @throws LscpException If LSCP protocol corruption occurs.
4596             * @see #addInstrumentsDbListener
4597             */
4598            public synchronized int
4599            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background, boolean insDir)
4600                                            throws IOException, LSException, LscpException {
4601                    
4602                  verifyConnection();                  verifyConnection();
4603                  StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");                  StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4604                  if(background) sb.append(" NON_MODAL");                  if(background) sb.append(" NON_MODAL");
# Line 4277  public class Client { Line 4614  public class Client {
4614                                  sb.append(" FLAT");                                  sb.append(" FLAT");
4615                                  break;                                  break;
4616                  }                  }
4617                    if(insDir)
4618                            sb.append(" FILE_AS_DIR");
4619                                    
4620                  sb.append(" '").append(dbDir).append("' '");                  sb.append(" '").append(conv(dbDir)).append("' '");
4621                  sb.append(fsDir).append("'");                  sb.append(conv(fsDir)).append("'");
4622                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4623                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4624                                    
4625                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4626                  return rs.getIndex();                  return rs.getIndex();
4627          }          }
4628            
4629          /**          /**
4630           * Removes the specified instrument from the instruments database.           * Removes the specified instrument from the instruments database.
4631           * @param instr The absolute path name of the instrument to remove.           * @param instr The absolute path name of the instrument to remove.
# Line 4298  public class Client { Line 4637  public class Client {
4637          removeDbInstrument(String instr) throws IOException, LscpException, LSException {          removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4638                                    
4639                  verifyConnection();                  verifyConnection();
4640                  out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");                  out.writeLine("REMOVE DB_INSTRUMENT '" + conv(instr) + "'");
4641                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4642                                    
4643                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4315  public class Client { Line 4654  public class Client {
4654          removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {          removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4655                  verifyConnection();                  verifyConnection();
4656                  for(String s : instrs) {                  for(String s : instrs) {
4657                          out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");                          out.writeLine("REMOVE DB_INSTRUMENT '" + conv(s) + "'");
4658                  }                  }
4659                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4660                                    
# Line 4353  public class Client { Line 4692  public class Client {
4692                  String s;                  String s;
4693                  if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";                  if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4694                  else s = "GET DB_INSTRUMENTS '";                  else s = "GET DB_INSTRUMENTS '";
4695                  out.writeLine(s + dir + "'");                  out.writeLine(s + conv(dir) + "'");
4696                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4697                                    
4698                  s = getSingleLineResultSet().getResult();                  s = getSingleLineResultSet().getResult();
# Line 4372  public class Client { Line 4711  public class Client {
4711          public synchronized String[]          public synchronized String[]
4712          getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {          getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4713                  verifyConnection();                  verifyConnection();
4714                  out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENTS '" + conv(dir) + "'");
4715                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4716                                    
4717                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
# Line 4394  public class Client { Line 4733  public class Client {
4733          public synchronized DbInstrumentInfo          public synchronized DbInstrumentInfo
4734          getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {          getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4735                  verifyConnection();                  verifyConnection();
4736                  out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");                  out.writeLine("GET DB_INSTRUMENT INFO '" + conv(instr) + "'");
4737                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4738                                    
4739                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
# Line 4423  public class Client { Line 4762  public class Client {
4762                                    
4763                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4764                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4765                          infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i]));                          infoS[i] = getDbInstrumentInfo(conv(dir) + toEscapedFsEntry(instrS[i]));
4766                  }                  }
4767                  return infoS;                  return infoS;
4768          }          }
# Line 4442  public class Client { Line 4781  public class Client {
4781                  String[] instrS = getDbInstrumentNames(dir);                  String[] instrS = getDbInstrumentNames(dir);
4782                  if(instrS.length == 0) return new DbInstrumentInfo[0];                  if(instrS.length == 0) return new DbInstrumentInfo[0];
4783                                    
4784                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(dir.charAt(dir.length() - 1) != '/') dir += "/"; FIXME:
4785                                    
4786                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4787                          out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");                          out.writeLine("GET DB_INSTRUMENT INFO '" + conv(dir) + instrS[i] + "'");
4788                  }                  }
4789                                    
4790                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 4491  public class Client { Line 4830  public class Client {
4830                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4831                                    
4832                  verifyConnection();                  verifyConnection();
4833                  name = toEscapedString(name);                  name = toEscapedText(name);
4834                  out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");                  out.writeLine("SET DB_INSTRUMENT NAME '" + conv(instr) + "' '" + conv(name) + "'");
4835                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4836                                    
4837                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4509  public class Client { Line 4848  public class Client {
4848          public synchronized void          public synchronized void
4849          moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {          moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4850                  verifyConnection();                  verifyConnection();
4851                  out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");                  out.writeLine("MOVE DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4852                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4853                                    
4854                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4527  public class Client { Line 4866  public class Client {
4866          moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {          moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4867                  verifyConnection();                  verifyConnection();
4868                  for(String s : instrs) {                  for(String s : instrs) {
4869                          out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");                          out.writeLine("MOVE DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4870                  }                  }
4871                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4872                                    
# Line 4545  public class Client { Line 4884  public class Client {
4884          public synchronized void          public synchronized void
4885          copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {          copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4886                  verifyConnection();                  verifyConnection();
4887                  out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");                  out.writeLine("COPY DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4888                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4889                                    
4890                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4563  public class Client { Line 4902  public class Client {
4902          copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {          copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4903                  verifyConnection();                  verifyConnection();
4904                  for(String s : instrs) {                  for(String s : instrs) {
4905                          out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");                          out.writeLine("COPY DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4906                  }                  }
4907                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4908                                    
# Line 4583  public class Client { Line 4922  public class Client {
4922                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4923                                    
4924                  verifyConnection();                  verifyConnection();
4925                  desc = toEscapedString(desc);                  desc = toEscapedText(desc);
4926                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + conv(instr) + "' '" + desc + "'");
4927                    if(getPrintOnlyMode()) return;
4928                    
4929                    ResultSet rs = getEmptyResultSet();
4930            }
4931            
4932            /**
4933             * Substitutes all occurrences of the instrument file
4934             * <code>oldPath</code> in the database, with <code>newPath</code>.
4935             * @param oldPath The absolute path name of the instrument file to substitute.
4936             * @param newPath The new absolute path name.
4937             * @throws IOException If some I/O error occurs.
4938             * @throws LSException If the operation failed.
4939             * @throws LscpException If LSCP protocol corruption occurs.
4940             */
4941            public synchronized void
4942            setDbInstrumentFilePath(String oldPath, String newPath)
4943                                    throws IOException, LSException, LscpException {
4944                    
4945                    verifyConnection();
4946                    out.writeLine("SET DB_INSTRUMENT FILE_PATH '" + conv(oldPath) + "' '" + conv(newPath) + "'");
4947                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4948                                    
4949                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4628  public class Client { Line 4987  public class Client {
4987                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
4988                  sb.append("FIND DB_INSTRUMENT_DIRECTORIES");                  sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4989                  if(nonRecursive) sb.append(" NON_RECURSIVE");                  if(nonRecursive) sb.append(" NON_RECURSIVE");
4990                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(conv(dir)).append("'");
4991                                    
4992                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4993                          sb.append(" NAME='").append(toEscapedString(query.name)).append("'");                          sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
4994                  }                  }
4995                                    
4996                  String s = query.getCreatedAfter();                  String s = query.getCreatedAfter();
# Line 4656  public class Client { Line 5015  public class Client {
5015                                    
5016                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
5017                          sb.append(" DESCRIPTION='");                          sb.append(" DESCRIPTION='");
5018                          sb.append(toEscapedString(query.description)).append("'");                          sb.append(toEscapedText(query.description)).append("'");
5019                  }                  }
5020                                    
5021                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
# Line 4709  public class Client { Line 5068  public class Client {
5068                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
5069                  sb.append("FIND DB_INSTRUMENTS");                  sb.append("FIND DB_INSTRUMENTS");
5070                  if(nonRecursive) sb.append(" NON_RECURSIVE");                  if(nonRecursive) sb.append(" NON_RECURSIVE");
5071                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(conv(dir)).append("'");
5072                                    
5073                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
5074                          sb.append(" NAME='").append(toEscapedString(query.name)).append("'");                          sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
5075                  }                  }
5076                                    
5077                  if(query.formatFamilies.size() > 0) {                  if(query.formatFamilies.size() > 0) {
# Line 4753  public class Client { Line 5112  public class Client {
5112                                    
5113                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
5114                          sb.append(" DESCRIPTION='");                          sb.append(" DESCRIPTION='");
5115                          sb.append(toEscapedString(query.description)).append("'");                          sb.append(toEscapedText(query.description)).append("'");
5116                  }                  }
5117                                    
5118                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
# Line 4766  public class Client { Line 5125  public class Client {
5125                  }                  }
5126                                    
5127                  if(query.product != null && query.product.length() > 0) {                  if(query.product != null && query.product.length() > 0) {
5128                          sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'");                          sb.append(" PRODUCT='").append(toEscapedText(query.product)).append("'");
5129                  }                  }
5130                                    
5131                  if(query.artists != null && query.artists.length() > 0) {                  if(query.artists != null && query.artists.length() > 0) {
5132                          sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'");                          sb.append(" ARTISTS='").append(toEscapedText(query.artists)).append("'");
5133                  }                  }
5134                                    
5135                  if(query.keywords != null && query.keywords.length() > 0) {                  if(query.keywords != null && query.keywords.length() > 0) {
5136                          sb.append(" KEYWORDS='");                          sb.append(" KEYWORDS='");
5137                          sb.append(toEscapedString(query.keywords)).append("'");                          sb.append(toEscapedText(query.keywords)).append("'");
5138                  }                  }
5139                                    
5140                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
# Line 4791  public class Client { Line 5150  public class Client {
5150          }          }
5151                    
5152          /**          /**
5153             * Returns a list of all instrument files in the database
5154             * that that don't exist in the filesystem.
5155             * @throws IOException If some I/O error occurs.
5156             * @throws LscpException If LSCP protocol corruption occurs.
5157             * @throws LSException If other error occurs.
5158             */
5159            public synchronized String[]
5160            findLostDbInstrumentFiles() throws IOException, LscpException, LSException {
5161                    
5162                    verifyConnection();
5163                    out.writeLine("FIND LOST DB_INSTRUMENT_FILES");
5164                    if(getPrintOnlyMode()) return null;
5165                    
5166                    return parseEscapedStringList(getSingleLineResultSet().getResult());
5167            }
5168            
5169            /**
5170           * Gets status information about the specified job.           * Gets status information about the specified job.
5171           * @param jobId The ID of the job.           * @param jobId The ID of the job.
5172           * @return A <code>ScanJobInfo</code> instance providing information           * @return A <code>ScanJobInfo</code> instance providing information
# Line 4828  public class Client { Line 5204  public class Client {
5204          }          }
5205                    
5206          /**          /**
5207           * Resets the specified sampler channel.           * Resets the whole sampler.
5208           *           *
          * @param samplerChn The sampler channel number.  
          *  
5209           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
5210           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
          * @throws LSException If <code>samplerChn</code> is not a valid channel number or if  
          * there is no engine assigned yet to the specified sampler channel.  
          * @see #getSamplerChannels  
5211           */           */
5212          public synchronized void          public synchronized void
5213          resetChannel(int samplerChn) throws IOException, LscpException, LSException {          resetSampler() throws IOException, LscpException {
5214                  verifyConnection();                  verifyConnection();
5215                  out.writeLine("RESET CHANNEL " + samplerChn);                  out.writeLine("RESET");
5216                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
5217                                    
5218                  ResultSet rs = getEmptyResultSet();                  try { ResultSet rs = getEmptyResultSet(); }
5219                    catch(LSException x) { getLogger().warning(x.getMessage()); }
5220          }          }
5221                    
5222          /**          /**
5223           * Resets the whole sampler.           * Gets the current number of all active streams.
5224           *           * @return The current number of all active streams.
5225           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
5226           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
5227             * @throws LSException If some other error occurs.
5228           */           */
5229          public synchronized void          public synchronized int
5230          resetSampler() throws IOException, LscpException {          getTotalStreamCount() throws IOException, LscpException, LSException {
5231                  verifyConnection();                  verifyConnection();
5232                  out.writeLine("RESET");                  out.writeLine("GET TOTAL_STREAM_COUNT");
5233                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return -1;
5234                                    
5235                  try { ResultSet rs = getEmptyResultSet(); }                  String s = getSingleLineResultSet().getResult();
5236                  catch(LSException x) { getLogger().warning(x.getMessage()); }                  return parseInt(s);
5237          }          }
5238                    
5239          /**          /**
# Line 4952  public class Client { Line 5325  public class Client {
5325                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
5326          }          }
5327                    
5328            /**
5329             * Gets the number of instruments in the specified instrument file.
5330             * @param filename The absolute path name of the instrument file.
5331             * @return The number of instruments in the specified instrument file.
5332             * @throws IOException If some I/O error occurs.
5333             * @throws LscpException If LSCP protocol corruption occurs.
5334             * @throws LSException If the file is not found, or other error occur.
5335             */
5336            public synchronized int
5337            getFileInstrumentCount(String filename) throws IOException, LscpException, LSException {
5338                    verifyConnection();
5339                    out.writeLine("GET FILE INSTRUMENTS '" + conv(filename) +"'");
5340                    if(getPrintOnlyMode()) return -1;
5341                    
5342                    String s = getSingleLineResultSet().getResult();
5343                    return parseInt(s);
5344            }
5345            
5346            /**
5347             * Gets information about the instrument with index
5348             * <code>instrIdx</code> in the specified instrument file.
5349             * @param filename The absolute path name of the instrument file.
5350             * @param instrIdx The index of the instrument in the specified instrument file.
5351             * @throws IOException If some I/O error occurs.
5352             * @throws LscpException If LSCP protocol corruption occurs.
5353             * @throws LSException If failed to retrieve information.
5354             */
5355            public synchronized Instrument
5356            getFileInstrumentInfo(String filename, int instrIdx)
5357                                    throws IOException, LscpException, LSException {
5358                    
5359                    verifyConnection();
5360                    out.writeLine("GET FILE INSTRUMENT INFO '" + conv(filename) + "' " + String.valueOf(instrIdx));
5361                    if(getPrintOnlyMode()) return null;
5362                    
5363                    ResultSet rs = getMultiLineResultSet();
5364                    Instrument instr = new FileInstrument(rs.getMultiLineResult()) { };
5365                    
5366                    return instr;
5367            }
5368            
5369            /**
5370             * Gets the list of instruments in the specified instrument file.
5371             * @param filename The absolute path name of the instrument file.
5372             * @return An <code>Instrument</code> array providing
5373             * information about all instruments in the specified instrument file.
5374             * @throws IOException If some I/O error occurs.
5375             * @throws LscpException If LSCP protocol corruption occurs.
5376             * @throws LSException If the specified file name is invalid.
5377             */
5378            public synchronized Instrument[]
5379            getFileInstruments(String filename) throws IOException, LscpException, LSException {
5380                    int l = getFileInstrumentCount(filename);
5381                    if(l < 0) return null;
5382                    Instrument[] instrS = new FileInstrument[l];
5383                    
5384                    for(int i = 0; i < instrS.length; i++) {
5385                            instrS[i] = getFileInstrumentInfo(filename, i);
5386                    }
5387                    return instrS;
5388            }
5389            
5390            private static class FileInstrument extends AbstractInstrument {
5391                    FileInstrument(String[] resultSet) throws LscpException {
5392                            super(resultSet);
5393                    }
5394                    
5395                    public String
5396                    getEngine() {
5397                            // TODO: engine lookup?
5398                            return getFormatFamily();
5399                    }
5400                    
5401                    public boolean
5402                    parse(String s) throws LscpException {
5403                            if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true;
5404                            return super.parse(s);
5405                    }
5406            }
5407            
5408          private void          private void
5409          getEmptyResultSets(int count, String err) throws LSException {          getEmptyResultSets(int count, String err) throws LSException {
5410                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();

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

  ViewVC Help
Powered by ViewVC