/[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 1766 by iliev, Mon Sep 8 00:16:17 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.2, for more
45   * information look at the   * information look at the
46   * <a href=http://www.linuxsampler.org/api/lscp-1.1.html>LSCP</a> specification.   * <a href=http://www.linuxsampler.org/api/lscp-1.2.html>LSCP</a> specification.
47   *   *
48   * <p> The following code establishes connection to LinuxSampler instance and gets the   * <p> The following code establishes connection to LinuxSampler instance and gets the
49   * LinuxSampler version:   * LinuxSampler version:
# Line 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 = parseStringList(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 = parseStringList(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 3770  public class Client { Line 4025  public class Client {
4025          public synchronized void          public synchronized void
4026          addDbDirectory(String dir) throws IOException, LSException, LscpException {          addDbDirectory(String dir) throws IOException, LSException, LscpException {
4027                  verifyConnection();                  verifyConnection();
4028                  out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");                  out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "'");
4029                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4030                                    
4031                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3805  public class Client { Line 4060  public class Client {
4060                  verifyConnection();                  verifyConnection();
4061                  String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";                  String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
4062                  if(force) s += "FORCE ";                  if(force) s += "FORCE ";
4063                  out.writeLine(s + "'" + dir + "'");                  out.writeLine(s + "'" + conv(dir) + "'");
4064                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4065                                    
4066                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 3828  public class Client { Line 4083  public class Client {
4083                  String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";                  String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
4084                  if(force) cmd += "FORCE ";                  if(force) cmd += "FORCE ";
4085                                    
4086                  for(String s : dirs) out.writeLine(cmd + "'" + s + "'");                  for(String s : dirs) out.writeLine(cmd + "'" + conv(s) + "'");
4087                                    
4088                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4089                                    
# Line 3866  public class Client { Line 4121  public class Client {
4121                  String s;                  String s;
4122                  if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";                  if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
4123                  else s = "GET DB_INSTRUMENT_DIRECTORIES '";                  else s = "GET DB_INSTRUMENT_DIRECTORIES '";
4124                  out.writeLine(s + dir + "'");                  out.writeLine(s + conv(dir) + "'");
4125                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4126                                    
4127                  s = getSingleLineResultSet().getResult();                  s = getSingleLineResultSet().getResult();
# Line 3885  public class Client { Line 4140  public class Client {
4140          public synchronized String[]          public synchronized String[]
4141          getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {          getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
4142                  verifyConnection();                  verifyConnection();
4143                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + conv(dir) + "'");
4144                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4145                                    
4146                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
# Line 3907  public class Client { Line 4162  public class Client {
4162          public synchronized DbDirectoryInfo          public synchronized DbDirectoryInfo
4163          getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {          getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
4164                  verifyConnection();                  verifyConnection();
4165                  out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");                  out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir) + "'");
4166                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4167                                    
4168                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
# Line 3940  public class Client { Line 4195  public class Client {
4195                  if(!hasEndingFileSeparator(dir)) dir += "/";                  if(!hasEndingFileSeparator(dir)) dir += "/";
4196                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];                  DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4197                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
4198                          infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i]));                          infoS[i] = getDbDirectoryInfo(conv(dir) + toEscapedFsEntry(dirS[i]));
4199                  }                  }
4200                  return infoS;                  return infoS;
4201          }          }
# Line 3956  public class Client { Line 4211  public class Client {
4211           *           *
4212          public synchronized DbDirectoryInfo[]          public synchronized DbDirectoryInfo[]
4213          getDbDirectories(String dir) throws IOException, LscpException, LSException {          getDbDirectories(String dir) throws IOException, LscpException, LSException {
4214                  String[] dirS = getDbDirectoryNames(dir);                  String[] dirS = getDbDirectoryNames(conv(dir));
4215                  if(dirS.length == 0) return new DbDirectoryInfo[0];                  if(dirS.length == 0) return new DbDirectoryInfo[0];
4216                                    
4217                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(dir.charAt(dir.length() - 1) != '/') dir += "/"; // FIXME:
4218                                    
4219                  for(int i = 0; i < dirS.length; i++) {                  for(int i = 0; i < dirS.length; i++) {
4220                          out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");                          out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + conv(dir + dirS[i]) + "'");
4221                  }                  }
4222                                    
4223                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 4006  public class Client { Line 4261  public class Client {
4261          public synchronized void          public synchronized void
4262          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {          renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4263                  verifyConnection();                  verifyConnection();
4264                  name = toEscapedString(name);                  name = toEscapedText(name);
4265                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");                  out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + conv(dir) + "' '" + conv(name) + "'");
4266                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4267                                    
4268                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4024  public class Client { Line 4279  public class Client {
4279          public synchronized void          public synchronized void
4280          moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {          moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4281                  verifyConnection();                  verifyConnection();
4282                  out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");                  out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4283                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4284                                    
4285                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4042  public class Client { Line 4297  public class Client {
4297          moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {          moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4298                  verifyConnection();                  verifyConnection();
4299                  for(String s : dirs) {                  for(String s : dirs) {
4300                          out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");                          out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4301                  }                  }
4302                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4303                                    
# Line 4060  public class Client { Line 4315  public class Client {
4315          public synchronized void          public synchronized void
4316          copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {          copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4317                  verifyConnection();                  verifyConnection();
4318                  out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");                  out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(dir) + "' '" + conv(dst) + "'");
4319                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4320                                    
4321                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4078  public class Client { Line 4333  public class Client {
4333          copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {          copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4334                  verifyConnection();                  verifyConnection();
4335                  for(String s : dirs) {                  for(String s : dirs) {
4336                          out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");                          out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + conv(s) + "' '" + conv(dst) + "'");
4337                  }                  }
4338                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4339                                    
# Line 4099  public class Client { Line 4354  public class Client {
4354                                    
4355                  verifyConnection();                  verifyConnection();
4356                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";                  String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4357                  out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'");                  out.writeLine(s + conv(dir) + "' '" + toEscapedText(desc) + "'");
4358                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4359                                    
4360                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4148  public class Client { Line 4403  public class Client {
4403                  verifyConnection();                  verifyConnection();
4404                  String s = "ADD DB_INSTRUMENTS";                  String s = "ADD DB_INSTRUMENTS";
4405                  if(background) s += " NON_MODAL";                  if(background) s += " NON_MODAL";
4406                  s += " '" + dbDir + "' '" + filePath + "' ";                  s += " '" + conv(dbDir) + "' '" + conv(filePath) + "' ";
4407                  out.writeLine(s + String.valueOf(instrIndex));                  out.writeLine(s + String.valueOf(instrIndex));
4408                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4409                                    
# Line 4195  public class Client { Line 4450  public class Client {
4450                  verifyConnection();                  verifyConnection();
4451                  String s = "ADD DB_INSTRUMENTS";                  String s = "ADD DB_INSTRUMENTS";
4452                  if(background) s += " NON_MODAL";                  if(background) s += " NON_MODAL";
4453                  out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");                  out.writeLine(s + " '" + conv(dbDir) + "' '" + conv(filePath) + "'");
4454                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4455                                    
4456                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4278  public class Client { Line 4533  public class Client {
4533                                  break;                                  break;
4534                  }                  }
4535                                    
4536                  sb.append(" '").append(dbDir).append("' '");                  sb.append(" '").append(conv(dbDir)).append("' '");
4537                  sb.append(fsDir).append("'");                  sb.append(conv(fsDir)).append("'");
4538                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
4539                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4540                                    
# Line 4298  public class Client { Line 4553  public class Client {
4553          removeDbInstrument(String instr) throws IOException, LscpException, LSException {          removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4554                                    
4555                  verifyConnection();                  verifyConnection();
4556                  out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");                  out.writeLine("REMOVE DB_INSTRUMENT '" + conv(instr) + "'");
4557                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4558                                    
4559                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4315  public class Client { Line 4570  public class Client {
4570          removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {          removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4571                  verifyConnection();                  verifyConnection();
4572                  for(String s : instrs) {                  for(String s : instrs) {
4573                          out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");                          out.writeLine("REMOVE DB_INSTRUMENT '" + conv(s) + "'");
4574                  }                  }
4575                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4576                                    
# Line 4353  public class Client { Line 4608  public class Client {
4608                  String s;                  String s;
4609                  if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";                  if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4610                  else s = "GET DB_INSTRUMENTS '";                  else s = "GET DB_INSTRUMENTS '";
4611                  out.writeLine(s + dir + "'");                  out.writeLine(s + conv(dir) + "'");
4612                  if(getPrintOnlyMode()) return -1;                  if(getPrintOnlyMode()) return -1;
4613                                    
4614                  s = getSingleLineResultSet().getResult();                  s = getSingleLineResultSet().getResult();
# Line 4372  public class Client { Line 4627  public class Client {
4627          public synchronized String[]          public synchronized String[]
4628          getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {          getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4629                  verifyConnection();                  verifyConnection();
4630                  out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");                  out.writeLine("LIST DB_INSTRUMENTS '" + conv(dir) + "'");
4631                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4632                                    
4633                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());                  String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
# Line 4394  public class Client { Line 4649  public class Client {
4649          public synchronized DbInstrumentInfo          public synchronized DbInstrumentInfo
4650          getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {          getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4651                  verifyConnection();                  verifyConnection();
4652                  out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");                  out.writeLine("GET DB_INSTRUMENT INFO '" + conv(instr) + "'");
4653                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
4654                                    
4655                  ResultSet rs = getMultiLineResultSet();                  ResultSet rs = getMultiLineResultSet();
# Line 4423  public class Client { Line 4678  public class Client {
4678                                    
4679                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];                  DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4680                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4681                          infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i]));                          infoS[i] = getDbInstrumentInfo(conv(dir) + toEscapedFsEntry(instrS[i]));
4682                  }                  }
4683                  return infoS;                  return infoS;
4684          }          }
# Line 4442  public class Client { Line 4697  public class Client {
4697                  String[] instrS = getDbInstrumentNames(dir);                  String[] instrS = getDbInstrumentNames(dir);
4698                  if(instrS.length == 0) return new DbInstrumentInfo[0];                  if(instrS.length == 0) return new DbInstrumentInfo[0];
4699                                    
4700                  if(dir.charAt(dir.length() - 1) != '/') dir += "/";                  if(dir.charAt(dir.length() - 1) != '/') dir += "/"; FIXME:
4701                                    
4702                  for(int i = 0; i < instrS.length; i++) {                  for(int i = 0; i < instrS.length; i++) {
4703                          out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");                          out.writeLine("GET DB_INSTRUMENT INFO '" + conv(dir) + instrS[i] + "'");
4704                  }                  }
4705                                    
4706                  if(getPrintOnlyMode()) return null;                  if(getPrintOnlyMode()) return null;
# Line 4491  public class Client { Line 4746  public class Client {
4746                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4747                                    
4748                  verifyConnection();                  verifyConnection();
4749                  name = toEscapedString(name);                  name = toEscapedText(name);
4750                  out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");                  out.writeLine("SET DB_INSTRUMENT NAME '" + conv(instr) + "' '" + conv(name) + "'");
4751                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4752                                    
4753                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4509  public class Client { Line 4764  public class Client {
4764          public synchronized void          public synchronized void
4765          moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {          moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4766                  verifyConnection();                  verifyConnection();
4767                  out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");                  out.writeLine("MOVE DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4768                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4769                                    
4770                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4527  public class Client { Line 4782  public class Client {
4782          moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {          moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4783                  verifyConnection();                  verifyConnection();
4784                  for(String s : instrs) {                  for(String s : instrs) {
4785                          out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");                          out.writeLine("MOVE DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4786                  }                  }
4787                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4788                                    
# Line 4545  public class Client { Line 4800  public class Client {
4800          public synchronized void          public synchronized void
4801          copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {          copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4802                  verifyConnection();                  verifyConnection();
4803                  out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");                  out.writeLine("COPY DB_INSTRUMENT '" + conv(instr) + "' '" + conv(dst) + "'");
4804                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4805                                    
4806                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4563  public class Client { Line 4818  public class Client {
4818          copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {          copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4819                  verifyConnection();                  verifyConnection();
4820                  for(String s : instrs) {                  for(String s : instrs) {
4821                          out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");                          out.writeLine("COPY DB_INSTRUMENT '" + conv(s) + "' '" + conv(dst) + "'");
4822                  }                  }
4823                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4824                                    
# Line 4583  public class Client { Line 4838  public class Client {
4838                                  throws IOException, LSException, LscpException {                                  throws IOException, LSException, LscpException {
4839                                    
4840                  verifyConnection();                  verifyConnection();
4841                  desc = toEscapedString(desc);                  desc = toEscapedText(desc);
4842                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");                  out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + conv(instr) + "' '" + desc + "'");
4843                    if(getPrintOnlyMode()) return;
4844                    
4845                    ResultSet rs = getEmptyResultSet();
4846            }
4847            
4848            /**
4849             * Substitutes all occurrences of the instrument file
4850             * <code>oldPath</code> in the database, with <code>newPath</code>.
4851             * @param oldPath The absolute path name of the instrument file to substitute.
4852             * @param newPath The new absolute path name.
4853             * @throws IOException If some I/O error occurs.
4854             * @throws LSException If the operation failed.
4855             * @throws LscpException If LSCP protocol corruption occurs.
4856             */
4857            public synchronized void
4858            setDbInstrumentFilePath(String oldPath, String newPath)
4859                                    throws IOException, LSException, LscpException {
4860                    
4861                    verifyConnection();
4862                    out.writeLine("SET DB_INSTRUMENT FILE_PATH '" + conv(oldPath) + "' '" + conv(newPath) + "'");
4863                  if(getPrintOnlyMode()) return;                  if(getPrintOnlyMode()) return;
4864                                    
4865                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
# Line 4628  public class Client { Line 4903  public class Client {
4903                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
4904                  sb.append("FIND DB_INSTRUMENT_DIRECTORIES");                  sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4905                  if(nonRecursive) sb.append(" NON_RECURSIVE");                  if(nonRecursive) sb.append(" NON_RECURSIVE");
4906                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(conv(dir)).append("'");
4907                                    
4908                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4909                          sb.append(" NAME='").append(toEscapedString(query.name)).append("'");                          sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
4910                  }                  }
4911                                    
4912                  String s = query.getCreatedAfter();                  String s = query.getCreatedAfter();
# Line 4656  public class Client { Line 4931  public class Client {
4931                                    
4932                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
4933                          sb.append(" DESCRIPTION='");                          sb.append(" DESCRIPTION='");
4934                          sb.append(toEscapedString(query.description)).append("'");                          sb.append(toEscapedText(query.description)).append("'");
4935                  }                  }
4936                                    
4937                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
# Line 4709  public class Client { Line 4984  public class Client {
4984                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
4985                  sb.append("FIND DB_INSTRUMENTS");                  sb.append("FIND DB_INSTRUMENTS");
4986                  if(nonRecursive) sb.append(" NON_RECURSIVE");                  if(nonRecursive) sb.append(" NON_RECURSIVE");
4987                  sb.append(" '").append(dir).append("'");                  sb.append(" '").append(conv(dir)).append("'");
4988                                    
4989                  if(query.name != null && query.name.length() > 0) {                  if(query.name != null && query.name.length() > 0) {
4990                          sb.append(" NAME='").append(toEscapedString(query.name)).append("'");                          sb.append(" NAME='").append(toEscapedText(query.name)).append("'");
4991                  }                  }
4992                                    
4993                  if(query.formatFamilies.size() > 0) {                  if(query.formatFamilies.size() > 0) {
# Line 4753  public class Client { Line 5028  public class Client {
5028                                    
5029                  if(query.description != null && query.description.length() > 0) {                  if(query.description != null && query.description.length() > 0) {
5030                          sb.append(" DESCRIPTION='");                          sb.append(" DESCRIPTION='");
5031                          sb.append(toEscapedString(query.description)).append("'");                          sb.append(toEscapedText(query.description)).append("'");
5032                  }                  }
5033                                    
5034                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {                  if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
# Line 4766  public class Client { Line 5041  public class Client {
5041                  }                  }
5042                                    
5043                  if(query.product != null && query.product.length() > 0) {                  if(query.product != null && query.product.length() > 0) {
5044                          sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'");                          sb.append(" PRODUCT='").append(toEscapedText(query.product)).append("'");
5045                  }                  }
5046                                    
5047                  if(query.artists != null && query.artists.length() > 0) {                  if(query.artists != null && query.artists.length() > 0) {
5048                          sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'");                          sb.append(" ARTISTS='").append(toEscapedText(query.artists)).append("'");
5049                  }                  }
5050                                    
5051                  if(query.keywords != null && query.keywords.length() > 0) {                  if(query.keywords != null && query.keywords.length() > 0) {
5052                          sb.append(" KEYWORDS='");                          sb.append(" KEYWORDS='");
5053                          sb.append(toEscapedString(query.keywords)).append("'");                          sb.append(toEscapedText(query.keywords)).append("'");
5054                  }                  }
5055                                    
5056                  out.writeLine(sb.toString());                  out.writeLine(sb.toString());
# Line 4791  public class Client { Line 5066  public class Client {
5066          }          }
5067                    
5068          /**          /**
5069             * Returns a list of all instrument files in the database
5070             * that that don't exist in the filesystem.
5071             * @throws IOException If some I/O error occurs.
5072             * @throws LscpException If LSCP protocol corruption occurs.
5073             * @throws LSException If other error occurs.
5074             */
5075            public synchronized String[]
5076            findLostDbInstrumentFiles() throws IOException, LscpException, LSException {
5077                    
5078                    verifyConnection();
5079                    out.writeLine("FIND LOST DB_INSTRUMENT_FILES");
5080                    if(getPrintOnlyMode()) return null;
5081                    
5082                    return parseEscapedStringList(getSingleLineResultSet().getResult());
5083            }
5084            
5085            /**
5086           * Gets status information about the specified job.           * Gets status information about the specified job.
5087           * @param jobId The ID of the job.           * @param jobId The ID of the job.
5088           * @return A <code>ScanJobInfo</code> instance providing information           * @return A <code>ScanJobInfo</code> instance providing information
# Line 4864  public class Client { Line 5156  public class Client {
5156          }          }
5157                    
5158          /**          /**
5159             * Gets the current number of all active streams.
5160             * @return The current number of all active streams.
5161             * @throws IOException If some I/O error occurs.
5162             * @throws LscpException If LSCP protocol corruption occurs.
5163             * @throws LSException If some other error occurs.
5164             */
5165            public synchronized int
5166            getTotalStreamCount() throws IOException, LscpException, LSException {
5167                    verifyConnection();
5168                    out.writeLine("GET TOTAL_STREAM_COUNT");
5169                    if(getPrintOnlyMode()) return -1;
5170                    
5171                    String s = getSingleLineResultSet().getResult();
5172                    return parseInt(s);
5173            }
5174            
5175            /**
5176           * Gets the current number of all active voices.           * Gets the current number of all active voices.
5177           * @return The current number of all active voices.           * @return The current number of all active voices.
5178           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
# Line 4952  public class Client { Line 5261  public class Client {
5261                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
5262          }          }
5263                    
5264            /**
5265             * Gets the number of instruments in the specified instrument file.
5266             * @param filename The absolute path name of the instrument file.
5267             * @return The number of instruments in the specified instrument file.
5268             * @throws IOException If some I/O error occurs.
5269             * @throws LscpException If LSCP protocol corruption occurs.
5270             * @throws LSException If the file is not found, or other error occur.
5271             */
5272            public synchronized int
5273            getFileInstrumentCount(String filename) throws IOException, LscpException, LSException {
5274                    verifyConnection();
5275                    out.writeLine("GET FILE INSTRUMENTS '" + conv(filename) +"'");
5276                    if(getPrintOnlyMode()) return -1;
5277                    
5278                    String s = getSingleLineResultSet().getResult();
5279                    return parseInt(s);
5280            }
5281            
5282            /**
5283             * Gets information about the instrument with index
5284             * <code>instrIdx</code> in the specified instrument file.
5285             * @param filename The absolute path name of the instrument file.
5286             * @param instrIdx The index of the instrument in the specified instrument file.
5287             * @throws IOException If some I/O error occurs.
5288             * @throws LscpException If LSCP protocol corruption occurs.
5289             * @throws LSException If failed to retrieve information.
5290             */
5291            public synchronized Instrument
5292            getFileInstrumentInfo(String filename, int instrIdx)
5293                                    throws IOException, LscpException, LSException {
5294                    
5295                    verifyConnection();
5296                    out.writeLine("GET FILE INSTRUMENT INFO '" + conv(filename) + "' " + String.valueOf(instrIdx));
5297                    if(getPrintOnlyMode()) return null;
5298                    
5299                    ResultSet rs = getMultiLineResultSet();
5300                    Instrument instr = new FileInstrument(rs.getMultiLineResult()) { };
5301                    
5302                    return instr;
5303            }
5304            
5305            /**
5306             * Gets the list of instruments in the specified instrument file.
5307             * @param filename The absolute path name of the instrument file.
5308             * @return An <code>Instrument</code> array providing
5309             * information about all instruments in the specified instrument file.
5310             * @throws IOException If some I/O error occurs.
5311             * @throws LscpException If LSCP protocol corruption occurs.
5312             * @throws LSException If the specified file name is invalid.
5313             */
5314            public synchronized Instrument[]
5315            getFileInstruments(String filename) throws IOException, LscpException, LSException {
5316                    int l = getFileInstrumentCount(filename);
5317                    if(l < 0) return null;
5318                    Instrument[] instrS = new FileInstrument[l];
5319                    
5320                    for(int i = 0; i < instrS.length; i++) {
5321                            instrS[i] = getFileInstrumentInfo(filename, i);
5322                    }
5323                    return instrS;
5324            }
5325            
5326            private static class FileInstrument extends AbstractInstrument {
5327                    FileInstrument(String[] resultSet) throws LscpException {
5328                            super(resultSet);
5329                    }
5330                    
5331                    public String
5332                    getEngine() {
5333                            // TODO: engine lookup?
5334                            return getFormatFamily();
5335                    }
5336                    
5337                    public boolean
5338                    parse(String s) throws LscpException {
5339                            if(s.startsWith("PRODUCT: ") || s.startsWith("ARTISTS: ")) return true;
5340                            return super.parse(s);
5341                    }
5342            }
5343            
5344          private void          private void
5345          getEmptyResultSets(int count, String err) throws LSException {          getEmptyResultSets(int count, String err) throws LSException {
5346                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();

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

  ViewVC Help
Powered by ViewVC