/[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 670 by iliev, Wed Jun 1 07:11:31 2005 UTC revision 671 by iliev, Wed Jun 22 06:18:33 2005 UTC
# Line 39  import org.linuxsampler.lscp.event.*; Line 39  import org.linuxsampler.lscp.event.*;
39    
40  /**  /**
41   * 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
42   * instance. Since it implements all commands specified in the LSCP protocol version 1.0, for more   * instance. Since it implements all commands specified in the LSCP protocol v1.0, for more
43   * information look at   * information look at the
44   * <a href=http://www.linuxsampler.org/api/draft-linuxsampler-protocol.html>LSCP</a>   * <a href=http://www.linuxsampler.org/api/lscp-1.0.html>LSCP</a> specification.
  * specification.  
45   *   *
46   * <p> The following code establishes connection to LinuxSampler instance and gets the   * <p> The following code establishes connection to LinuxSampler instance and gets the
47   * LinuxSampler version:   * LinuxSampler version:
# Line 66  import org.linuxsampler.lscp.event.*; Line 65  import org.linuxsampler.lscp.event.*;
65   * @author  Grigor Iliev   * @author  Grigor Iliev
66   */   */
67  public class Client {  public class Client {
         /** Specifies the current version of jlscp */  
         private final static String VERSION = "0.1a";  
           
68          private String address;          private String address;
69          private int port;          private int port;
70          private Socket sock = null;          private Socket sock = null;
# Line 141  public class Client { Line 137  public class Client {
137           * @return The jlscp version.           * @return The jlscp version.
138           */           */
139          public static String          public static String
140          getClientVersion() { return VERSION; }          getClientVersion() {
141                    return Package.getPackage("org.linuxsampler.lscp").getImplementationVersion();
142            }
143                    
144          /**          /**
145           * Gets the Linux Sampler address.           * Gets the Linux Sampler address.
# Line 220  public class Client { Line 218  public class Client {
218                          );                          );
219                  }                  }
220                                    
221                    String s = Package.getPackage("org.linuxsampler.lscp").getSpecificationVersion();
222                    String s2, sv, sv2;
223                    
224                    try {
225                            s2 = s.substring(0,  s.indexOf('.'));
226                            sv = getServerInfo().getProtocolVersion();
227                            sv2 = sv.substring(0,  sv.indexOf('.'));
228                    } catch(Exception x) {
229                            disconnect();
230                            
231                            throw new LscpException (
232                                    LscpI18n.getLogMsg("Client.connectionFailed!"), x
233                            );
234                    }
235                    
236                    if(!sv2.equals(s2)) {
237                            disconnect();
238                            
239                            throw new LscpException (
240                                    LscpI18n.getLogMsg("Client.incompatibleLscpVersion!", sv)
241                            );
242                    }
243                    
244                    s2 = s.substring(s.indexOf('.'));
245                    sv2 = sv.substring(sv.indexOf('.'));
246                    
247                    if(sv2.compareToIgnoreCase(s2) < 0) getLogger().info (
248                            LscpI18n.getLogMsg("Client.incompatibleLscpMinVersion!", sv)
249                    );
250                    
251                  if(hasSubscriptions()) eventThread.start();                  if(hasSubscriptions()) eventThread.start();
252                                    
253                  if(!llM.isEmpty()) subscribe("MISCELLANEOUS");                  if(!llM.isEmpty()) subscribe("MISCELLANEOUS");
# Line 615  public class Client { Line 643  public class Client {
643                  String s = getSingleLineResultSet().getResult();                  String s = getSingleLineResultSet().getResult();
644                  return parseInt(s);                  return parseInt(s);
645          }          }
646            
647          /**          /**
648           * Gets all audio output drivers currently available for the LinuxSampler instance.           * Gets all audio output drivers currently available for the LinuxSampler instance.
649           *           *
650           * @return <code>String</code> array with all audio output drivers currently available for           * @return <code>AudioOutputDriver</code> array containing all audio output drivers
651           * the LinuxSampler instance.           * currently available for the LinuxSampler instance.
652           *           *
653           * @throws IOException If an I/O error occurs.           * @throws IOException If an I/O error occurs.
654           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
655           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
656           */           */
657          public synchronized String[]          public synchronized AudioOutputDriver[]
658          getAudioOutputDrivers() throws IOException, LscpException, LSException {          getAudioOutputDrivers() throws IOException, LscpException, LSException {
659                    String[] drivers = getAudioOutputDriverNames();
660                    AudioOutputDriver[] aod = new AudioOutputDriver[drivers.length];
661                    
662                    for(int i = 0; i < aod.length; i++) aod[i] = getAudioOutputDriverInfo(drivers[i]);
663                    
664                    return aod;
665            }
666            
667            /**
668             * Gets all audio output drivers currently available for the LinuxSampler instance.
669             *
670             * @return <code>String</code> array containing all audio output drivers currently
671             * available for the LinuxSampler instance.
672             *
673             * @throws IOException If an I/O error occurs.
674             * @throws LscpException If LSCP protocol corruption occurs.
675             * @throws LSException If some other error occurs.
676             */
677            private synchronized String[]
678            getAudioOutputDriverNames() throws IOException, LscpException, LSException {
679                  verifyConnection();                  verifyConnection();
680                  out.writeLine("LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS");                  out.writeLine("LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS");
681                  return parseList(getSingleLineResultSet().getResult());                  return parseList(getSingleLineResultSet().getResult());
# Line 643  public class Client { Line 692  public class Client {
692           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
693           * @throws LSException If there is no driver with name <code>driverName</code>.           * @throws LSException If there is no driver with name <code>driverName</code>.
694           *           *
695           * @see #getAudioOutputDrivers           * @see #getAudioOutputDriverNames
696           */           */
697          public synchronized AudioOutputDriver          private synchronized AudioOutputDriver
698          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getAudioOutputDriverInfo(String driverName) throws IOException, LscpException, LSException {
699                  verifyConnection();                  verifyConnection();
700                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);                  out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
# Line 1075  public class Client { Line 1124  public class Client {
1124          /**          /**
1125           * Gets all MIDI input drivers currently available for the LinuxSampler instance.           * Gets all MIDI input drivers currently available for the LinuxSampler instance.
1126           *           *
1127           * @return <code>String</code> array with all MIDI input drivers currently available for           * @return <code>MidiInputDriver</code> array containing all MIDI input drivers currently
1128           * the LinuxSampler instance or <code>null</code> if there are no MIDI input drivers           * available for the LinuxSampler instance.
          * currently available.  
1129           *           *
1130           * @throws IOException If an I/O error occurs.           * @throws IOException If an I/O error occurs.
1131           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
1132           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
1133           */           */
1134          public synchronized String[]          public synchronized MidiInputDriver[]
1135          getMidiInputDrivers() throws IOException, LscpException, LSException {          getMidiInputDrivers() throws IOException, LscpException, LSException {
1136                    String[] drivers = getMidiInputDriverNames();
1137                    MidiInputDriver[] mid = new MidiInputDriver[drivers.length];
1138                    
1139                    for(int i = 0; i < mid.length; i++) mid[i] = getMidiInputDriverInfo(drivers[i]);
1140                    
1141                    return mid;
1142            }
1143            
1144            /**
1145             * Gets all MIDI input drivers currently available for the LinuxSampler instance.
1146             *
1147             * @return <code>String</code> array containing all MIDI input drivers currently available
1148             * for the LinuxSampler instance.
1149             *
1150             * @throws IOException If an I/O error occurs.
1151             * @throws LscpException If LSCP protocol corruption occurs.
1152             * @throws LSException If some other error occurs.
1153             */
1154            private synchronized String[]
1155            getMidiInputDriverNames() throws IOException, LscpException, LSException {
1156                  verifyConnection();                  verifyConnection();
1157                  out.writeLine("LIST AVAILABLE_MIDI_INPUT_DRIVERS");                  out.writeLine("LIST AVAILABLE_MIDI_INPUT_DRIVERS");
1158                  return parseList(getSingleLineResultSet().getResult());                  return parseList(getSingleLineResultSet().getResult());
# Line 1094  public class Client { Line 1162  public class Client {
1162           * Gets detailed information about a specific MIDI input driver.           * Gets detailed information about a specific MIDI input driver.
1163           * @param driverName The name of the MIDI input driver.           * @param driverName The name of the MIDI input driver.
1164           *           *
1165           * @return An <code>MidiInputDriver</code> object containing           * @return A <code>MidiInputDriver</code> object containing
1166           * information about the specified MIDI input driver.           * information about the specified MIDI input driver.
1167           *           *
1168           * @throws IOException If an I/O error occurs.           * @throws IOException If an I/O error occurs.
1169           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
1170           * @throws LSException If there is no driver with name <code>driverName</code>.           * @throws LSException If there is no driver with name <code>driverName</code>.
1171           *           *
1172           * @see #getMidiInputDrivers           * @see #getMidiInputDriverNames
1173           */           */
1174          public synchronized MidiInputDriver          private synchronized MidiInputDriver
1175          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {          getMidiInputDriverInfo(String driverName) throws IOException, LscpException, LSException {
1176                  verifyConnection();                  verifyConnection();
1177                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);                  out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
# Line 1127  public class Client { Line 1195  public class Client {
1195           * <code>param</code> depends on. <code>Parameter</code> instances can be           * <code>param</code> depends on. <code>Parameter</code> instances can be
1196           * easily created using {@link ParameterFactory} factory.           * easily created using {@link ParameterFactory} factory.
1197           *           *
1198           * @return An <code>Parameter</code> object containing           * @return A <code>Parameter</code> object containing
1199           * information about the specified MIDI input driver parameter.           * information about the specified MIDI input driver parameter.
1200           *           *
1201           * @throws IOException If an I/O error occurs.           * @throws IOException If an I/O error occurs.
# Line 1654  public class Client { Line 1722  public class Client {
1722          }          }
1723                    
1724          /**          /**
1725             * Gets a list of all available engines.
1726             *
1727             * @return <code>SamplerEngine</code> array containing all available engines.
1728             * @throws IOException If some I/O error occurs.
1729             * @throws LscpException If LSCP protocol corruption occurs.
1730             * @throws LSException If some other error occurs.
1731             */
1732            public synchronized SamplerEngine[]
1733            getEngines() throws IOException, LscpException, LSException {
1734                    String[] engines = getEngineNames();
1735                    SamplerEngine[] se = new SamplerEngine[engines.length];
1736                    
1737                    for(int i = 0; i < engines.length; i++) se[i] = getEngineInfo(engines[i]);
1738                    
1739                    return se;
1740            }
1741            
1742            /**
1743           * Gets a list of all available engines' names.           * Gets a list of all available engines' names.
1744           *           *
1745           * @return <code>String</code> array with all available engines' names.           * @return <code>String</code> array with all available engines' names.
# Line 1661  public class Client { Line 1747  public class Client {
1747           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
1748           * @throws LSException If some other error occurs.           * @throws LSException If some other error occurs.
1749           */           */
1750          public synchronized String[]          private synchronized String[]
1751          getEngines() throws IOException, LscpException, LSException {          getEngineNames() throws IOException, LscpException, LSException {
1752                  verifyConnection();                  verifyConnection();
1753                  out.writeLine("LIST AVAILABLE_ENGINES");                  out.writeLine("LIST AVAILABLE_ENGINES");
1754                  return parseStringList(getSingleLineResultSet().getResult());                  return parseStringList(getSingleLineResultSet().getResult());
# Line 1678  public class Client { Line 1764  public class Client {
1764           * @throws IOException If an I/O error occurs.           * @throws IOException If an I/O error occurs.
1765           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
1766           * @throws LSException If there is no sampler engine with name <code>engineName</code>.           * @throws LSException If there is no sampler engine with name <code>engineName</code>.
1767           * @see #getEngines           * @see #getEngineNames
1768           */           */
1769          public synchronized SamplerEngine          private synchronized SamplerEngine
1770          getEngineInfo(String engineName) throws IOException, LscpException, LSException {          getEngineInfo(String engineName) throws IOException, LscpException, LSException {
1771                  verifyConnection();                  verifyConnection();
1772                  out.writeLine("GET ENGINE INFO " + engineName);                  out.writeLine("GET ENGINE INFO " + engineName);

Legend:
Removed from v.670  
changed lines
  Added in v.671

  ViewVC Help
Powered by ViewVC