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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1421 - (hide annotations) (download)
Sun Oct 14 18:08:45 2007 UTC (16 years, 5 months ago) by iliev
File size: 171792 byte(s)
* Client: renamed editInstrument to editChannelInstrument
* added extended support for escape sequences in LSCP response fields

1 iliev 596 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4 iliev 1139 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 596 *
6     * This file is part of jlscp.
7     *
8     * jlscp is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * jlscp is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with jlscp; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.linuxsampler.lscp;
24    
25     import java.io.IOException;
26 iliev 1139 import java.io.OutputStream;
27 iliev 596
28     import java.net.InetSocketAddress;
29     import java.net.Socket;
30     import java.net.SocketTimeoutException;
31     import java.net.UnknownHostException;
32    
33     import java.util.Vector;
34     import java.util.logging.Level;
35     import java.util.logging.Logger;
36    
37     import org.linuxsampler.lscp.event.*;
38    
39 iliev 1351 import static org.linuxsampler.lscp.Parser.*;
40 iliev 596
41 iliev 1351
42 iliev 596 /**
43     * This class is the abstraction representing a client endpoint for communication with LinuxSampler
44 iliev 1139 * instance. Since it implements all commands specified in the LSCP protocol v1.1, for more
45 iliev 671 * information look at the
46 iliev 1139 * <a href=http://www.linuxsampler.org/api/lscp-1.1.html>LSCP</a> specification.
47 iliev 596 *
48     * <p> The following code establishes connection to LinuxSampler instance and gets the
49     * LinuxSampler version:
50     * <pre>
51     * try {
52     * Client client = new Client();
53     * client.connect();
54     *
55     * String version = client.getServerInfo().getVersion();
56     * System.out.println(version);
57     *
58     * client.disconnect();
59     * } catch(Exception x) { x.printStackTrace(); }
60     * </pre>
61     * </p>
62     *
63     * <p>For more examples look at the <code>examples</code> directory
64     * located in the <b>jlscp</b> distribution.</p>
65     *
66     * All methods are thread safe.
67     * @author Grigor Iliev
68     */
69     public class Client {
70     private String address;
71     private int port;
72     private Socket sock = null;
73 iliev 1202 private int soTimeout = 20000;
74 iliev 596
75     private LscpInputStream in = null;
76     private LscpOutputStream out = null;
77    
78     private EventThread eventThread;
79    
80 iliev 1139 private boolean printOnlyMode = false;
81    
82 iliev 596 class EventThread extends Thread {
83 iliev 1202 private Vector<String> queue = new Vector<String>();
84 iliev 596 private boolean terminate = false;
85    
86     EventThread() { super("LSCP-Event-Thread"); }
87    
88     public void
89     run() {
90     while(!mustTerminate()) {
91 iliev 1202 try {
92     processQueue();
93     processNotifications();
94     } catch(Exception x) {
95 iliev 596 getLogger().log(Level.FINE, x.getMessage(), x);
96     }
97     try { synchronized(this) { wait(100); } }
98     catch(Exception x) {
99     getLogger().log(Level.FINE, x.getMessage(), x);
100     }
101     }
102     }
103    
104     private synchronized boolean
105     mustTerminate() { return terminate; }
106    
107     public synchronized void
108     terminate() {
109     terminate = true;
110     this.notifyAll();
111     }
112 iliev 1202
113     public synchronized void
114     scheduleNotification(String s) { queue.add(s); }
115    
116     private void
117     processQueue() {
118     String[] notifications = popAllNotifications();
119     for(String n : notifications) fireEvent(n);
120     }
121    
122     private synchronized String[]
123     popAllNotifications() {
124     String[] notifications = queue.toArray(new String[queue.size()]);
125     queue.removeAllElements();
126     return notifications;
127     }
128 iliev 596 }
129    
130     /**
131     * Creates a new instance of Client with default server address and port.
132     * The default server address and port are 127.0.0.1:8888.
133     */
134     public
135     Client() { this("127.0.0.1"); }
136    
137     /**
138     * Creates a new instance of Client with the specified address and default port.
139     * The default port is 8888.
140     * @param address The address of linux sampler server.
141     */
142     public
143     Client(String address) { this(address, 8888); }
144    
145     /**
146     * Creates a new instance of Client with the specified address and port.
147     * @param address The address of the Linux Sampler.
148     * @param port The Linux Sampler port number.
149     */
150     public
151     Client(String address, int port) {
152     setServerAddress(address);
153     setServerPort(port);
154    
155     eventThread = new EventThread();
156     }
157    
158     /**
159 iliev 1139 * Creates a new instance of Client.
160     * @param printOnlyMode Determines whether the client will be in print-only mode.
161     */
162     public
163     Client(boolean printOnlyMode) {
164     if(printOnlyMode) setPrintOnlyMode(true);
165     }
166    
167     /**
168     * Determines whether the client is in print-only mode.
169     * Print-only mode means that the client will just print all
170     * LSCP commands to the specified output stream or to the standard output stream
171     * (<code>java.lang.System.out</code>) if no output stream is specified,
172     * without taking any further actions. Thus, in print-only mode all returned
173     * values by <code>Client</code>'s methods are meaningless and should be discarded.
174     * @return <code>true</code> if the client is in
175     * print-only mode, <code>false</code> otherwise.
176     * @see #setPrintOnlyModeOutputStream
177     */
178     public synchronized boolean
179     getPrintOnlyMode() { return printOnlyMode; }
180    
181     /**
182     * Sets the print-only mode. Note that in print-only mode all returned
183     * values by <code>Client</code>'s methods are meaningless and should be discarded.
184     * The default output stream in print-only mode is <code>java.lang.System.out</code>.
185     * @param b If <code>true</code> all LSCP commands will be sent
186     * to the specified output stream or to the standard output stream
187     * (<code>java.lang.System.out</code>) if no output stream is specified,
188     * and no further actions will be taken.
189     * @throws IllegalStateException If the client is connected.
190     * @see #setPrintOnlyModeOutputStream
191     */
192     public synchronized void
193     setPrintOnlyMode(boolean b) {
194     if(printOnlyMode == b) return;
195     if(isConnected()) throw new IllegalStateException();
196    
197     printOnlyMode = b;
198     if(b) out = new LscpOutputStream(System.out);
199     }
200    
201     /**
202     * Sets the output stream to be used in print-only mode.
203     * @param out The output stream to be used in print-only mode.
204     * @throws IllegalStateException If the client is not in print-only mode.
205     * @throws IllegalArgumentException if <code>out</code> is <code>null</code>.
206     * @see #setPrintOnlyMode
207     */
208     public synchronized void
209     setPrintOnlyModeOutputStream(OutputStream out) {
210     if(!getPrintOnlyMode()) throw new IllegalStateException("Not in print-only mode");
211     if(out == null) throw new IllegalArgumentException("out must be non-null");
212     this.out = new LscpOutputStream(out);
213     }
214    
215     /**
216 iliev 596 * Specifies the jlscp version.
217     * @return The jlscp version.
218     */
219     public static String
220 iliev 671 getClientVersion() {
221     return Package.getPackage("org.linuxsampler.lscp").getImplementationVersion();
222     }
223 iliev 596
224     /**
225     * Gets the Linux Sampler address.
226     * @return The Linux Sampler address.
227     */
228     public synchronized String
229     getServerAddress() { return address; }
230    
231     /**
232     * Sets the Linux Sampler address.
233     * @param address The Linux Sampler address.
234     * If <code>address</code> is <code>null</code> sets to default address - 127.0.0.1.
235     */
236     public synchronized void
237     setServerAddress(String address) {
238     this.address = (address == null ? "127.0.0.1" : address);
239     }
240    
241     /**
242     * Gets the Linux Sampler port number.
243     * @return The Linux Sampler port number.
244     */
245     public synchronized int
246     getServerPort() { return port; }
247    
248     /**
249     * Sets the Linux Sampler port number.
250     * @param port The Linux Sampler port number.
251     */
252     public synchronized void
253     setServerPort(int port) { this.port = port; }
254    
255     /**
256     * Connects to the LinuxSampler. If there is already established connection then
257     * the currently available connection is closed berfore connecting.
258     * @throws LscpException If timeout occurs or any other I/O exception.
259     */
260     public synchronized void
261     connect() throws LscpException {
262     if(sock != null) disconnect();
263 iliev 1139 if(getPrintOnlyMode()) return;
264 iliev 596
265     // Initializing LSCP event thread
266     if(eventThread.isAlive()) {
267     getLogger().warning("LSCP event thread already running!");
268     eventThread.terminate();
269     }
270    
271     if(eventThread.getState() != Thread.State.NEW) eventThread = new EventThread();
272     ///////
273    
274     InetSocketAddress sockAddr = null;
275    
276     try { sockAddr = new InetSocketAddress(address, port); }
277     catch(IllegalArgumentException x) {
278     String s = String.valueOf(port);
279     throw new LscpException(LscpI18n.getLogMsg("Client.invalidPort!", s), x);
280     }
281    
282     if(sockAddr.isUnresolved()) throw new LscpException (
283     LscpI18n.getLogMsg("Client.unknownHost!", address)
284     );
285    
286     try {
287     sock = new Socket();
288     sock.bind(null);
289     sock.connect(sockAddr, soTimeout);
290     sock.setSoTimeout(soTimeout);
291 iliev 784 sock.setTcpNoDelay(true);
292 iliev 596
293     in = new LscpInputStream(sock.getInputStream());
294     out = new LscpOutputStream(sock.getOutputStream());
295     } catch(SocketTimeoutException x) {
296     throw new LscpException(LscpI18n.getLogMsg("Client.conTimeout!"), x);
297     } catch(Exception x) {
298     throw new LscpException (
299     LscpI18n.getLogMsg("Client.connectionFailed!"), x
300     );
301     }
302    
303 iliev 671 String s = Package.getPackage("org.linuxsampler.lscp").getSpecificationVersion();
304     String s2, sv, sv2;
305    
306     try {
307     s2 = s.substring(0, s.indexOf('.'));
308     sv = getServerInfo().getProtocolVersion();
309     sv2 = sv.substring(0, sv.indexOf('.'));
310     } catch(Exception x) {
311     disconnect();
312    
313     throw new LscpException (
314     LscpI18n.getLogMsg("Client.connectionFailed!"), x
315     );
316     }
317    
318     if(!sv2.equals(s2)) {
319     disconnect();
320    
321     throw new LscpException (
322     LscpI18n.getLogMsg("Client.incompatibleLscpVersion!", sv)
323     );
324     }
325    
326     s2 = s.substring(s.indexOf('.'));
327     sv2 = sv.substring(sv.indexOf('.'));
328    
329     if(sv2.compareToIgnoreCase(s2) < 0) getLogger().info (
330     LscpI18n.getLogMsg("Client.incompatibleLscpMinVersion!", sv)
331     );
332    
333 iliev 596 if(hasSubscriptions()) eventThread.start();
334    
335     if(!llM.isEmpty()) subscribe("MISCELLANEOUS");
336 iliev 1139 if(!llAODC.isEmpty()) subscribe("AUDIO_OUTPUT_DEVICE_COUNT");
337     if(!llAODI.isEmpty()) subscribe("AUDIO_OUTPUT_DEVICE_INFO");
338     if(!llMIDC.isEmpty()) subscribe("MIDI_INPUT_DEVICE_COUNT");
339     if(!llMIDI.isEmpty()) subscribe("MIDI_INPUT_DEVICE_INFO");
340 iliev 596 if(!llBF.isEmpty()) subscribe("BUFFER_FILL");
341     if(!llCC.isEmpty()) subscribe("CHANNEL_COUNT");
342     if(!llCI.isEmpty()) subscribe("CHANNEL_INFO");
343 iliev 1139 if(!llFSC.isEmpty()) subscribe("FX_SEND_COUNT");
344     if(!llFSI.isEmpty()) subscribe("FX_SEND_INFO");
345 iliev 596 if(!llSC.isEmpty()) subscribe("STREAM_COUNT");
346     if(!llVC.isEmpty()) subscribe("VOICE_COUNT");
347 iliev 784 if(!llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");
348 iliev 1139 if(!llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");
349     if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
350     if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
351     if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
352 iliev 1202 if(!llID.isEmpty()) {
353     subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
354     subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
355     subscribe("DB_INSTRUMENT_COUNT");
356     subscribe("DB_INSTRUMENT_INFO");
357     }
358 iliev 1139 if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
359 iliev 596 }
360    
361     /**
362     * Closes the connection to LinuxSampler.
363     */
364     public synchronized void
365     disconnect() {
366 iliev 1139 if(getPrintOnlyMode()) return;
367 iliev 596 try { if(sock != null) sock.close(); }
368     catch(Exception x) { getLogger().log(Level.FINE, x.getMessage(), x); }
369     sock = null;
370    
371     if(eventThread.getState() != Thread.State.NEW) {
372     eventThread.terminate();
373     eventThread = new EventThread();
374     }
375     }
376    
377     /**
378     * Determines whether the client is connected.
379     * @return <code>true</code> if there is established connection,
380     * <code>false</code> otherwise.
381     */
382     public synchronized boolean
383     isConnected() {
384     if(sock == null) return false;
385     else return sock.isConnected();
386     }
387    
388     /**
389     * Verifies that there is established connection.
390     * @throws IOException If the connection is not established.
391     */
392     private void
393     verifyConnection() throws IOException {
394 iliev 1139 if(getPrintOnlyMode()) return;
395    
396 iliev 596 if(!isConnected())
397     throw new IOException(LscpI18n.getLogMsg("Client.notConnected!"));
398     }
399    
400     private String
401     getLine() throws IOException, LscpException {
402     String s;
403     for(;;) {
404     s = in.readLine();
405 iliev 1202 if(s.startsWith("NOTIFY:")) {
406     eventThread.scheduleNotification(s.substring("NOTIFY:".length()));
407     }
408 iliev 596 else break;
409     }
410     return s;
411     }
412    
413 iliev 1139 /** Processes the notifications sent by LinuxSampler */
414 iliev 596 private synchronized void
415     processNotifications() throws IOException, LscpException {
416     while(in.available() > 0) {
417     String s = in.readLine();
418     if(s.startsWith("NOTIFY:")) fireEvent(s.substring("NOTIFY:".length()));
419     else getLogger().severe("Unknown notification format: " + s);
420     }
421     }
422    
423     /**
424     * Gets empty result set.
425     * @return <code>ResultSet</code> instance.
426     */
427     private ResultSet
428     getEmptyResultSet() throws IOException, LscpException, LSException {
429     return parseEmptyResultSet(getLine());
430     }
431    
432     private ResultSet
433     getSingleLineResultSet() throws IOException, LscpException, LSException {
434     ResultSet rs = new ResultSet();
435     String ln = getLine();
436    
437     if(ln.startsWith("WRN")) {
438     parseWarning(ln, rs);
439     getLogger().warning(rs.getMessage());
440     return rs;
441     } else if(ln.startsWith("ERR")) {
442     parseError(ln, rs);
443     throw new LSException(rs.getCode(), rs.getMessage());
444     } else {
445     rs.setResult(ln);
446     return rs;
447     }
448     }
449    
450     private ResultSet
451     getMultiLineResultSet() throws IOException, LscpException, LSException {
452     ResultSet rs = new ResultSet();
453     String ln = getLine();
454    
455     if(ln.startsWith("WRN")) {
456     parseWarning(ln, rs);
457     getLogger().warning(rs.getMessage());
458     return rs;
459     } else if(ln.startsWith("ERR")) {
460     parseError(ln, rs);
461     throw new LSException(rs.getCode(), rs.getMessage());
462     }
463    
464     while(!ln.equals(".")) {
465     rs.addLine(ln);
466     ln = getLine();
467     }
468    
469     return rs;
470     }
471    
472 iliev 1139 /** Audio output device count listeners */
473     private final Vector<ItemCountListener> llAODC = new Vector<ItemCountListener>();
474     /** Audio output device info listeners */
475     private final Vector<ItemInfoListener> llAODI = new Vector<ItemInfoListener>();
476 iliev 596 private final Vector<BufferFillListener> llBF = new Vector<BufferFillListener>();
477     private final Vector<ChannelCountListener> llCC = new Vector<ChannelCountListener>();
478     private final Vector<ChannelInfoListener> llCI = new Vector<ChannelInfoListener>();
479 iliev 1139 private final Vector<FxSendCountListener> llFSC = new Vector<FxSendCountListener>();
480     private final Vector<FxSendInfoListener> llFSI = new Vector<FxSendInfoListener>();
481 iliev 596 private final Vector<MiscellaneousListener> llM = new Vector<MiscellaneousListener>();
482 iliev 1139 /** MIDI input device count listeners */
483     private final Vector<ItemCountListener> llMIDC = new Vector<ItemCountListener>();
484     /** MIDI input device info listeners */
485     private final Vector<ItemInfoListener> llMIDI = new Vector<ItemInfoListener>();
486 iliev 596 private final Vector<StreamCountListener> llSC = new Vector<StreamCountListener>();
487     private final Vector<VoiceCountListener> llVC = new Vector<VoiceCountListener>();
488 iliev 784 private final Vector<TotalVoiceCountListener> llTVC = new Vector<TotalVoiceCountListener>();
489 iliev 596
490 iliev 1139 /** MIDI instrument map count listeners */
491     private final Vector<ItemCountListener> llMIMC = new Vector<ItemCountListener>();
492     /** MIDI instrument map info listeners */
493     private final Vector<ItemInfoListener> llMIMI = new Vector<ItemInfoListener>();
494     /** MIDI instrument count listeners */
495     private final Vector<MidiInstrumentCountListener> llMIC =
496     new Vector<MidiInstrumentCountListener>();
497     /** MIDI instrument info listeners */
498     private final Vector<MidiInstrumentInfoListener> llMII =
499     new Vector<MidiInstrumentInfoListener>();
500 iliev 1202 private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();
501 iliev 1139 private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();
502    
503    
504 iliev 596 /**
505     * Determines whether there is at least one subscription for notification events.
506     * Do not forget to check for additional listeners if the LSCP specification
507 iliev 784 * is extended in the future.
508 iliev 596 * @return <code>true</code> if there is at least one subscription for notification events,
509     * <code>false</code> otherwise.
510     */
511     private boolean
512     hasSubscriptions() {
513 iliev 1139 return !llAODC.isEmpty() ||
514     !llAODI.isEmpty() ||
515     !llBF.isEmpty() ||
516     !llCC.isEmpty() ||
517     !llCI.isEmpty() ||
518     !llFSC.isEmpty() ||
519     !llFSI.isEmpty() ||
520     !llM.isEmpty() ||
521     !llMIDC.isEmpty() ||
522     !llMIDI.isEmpty() ||
523     !llSC.isEmpty() ||
524     !llVC.isEmpty() ||
525     !llTVC.isEmpty() ||
526     !llMIMC.isEmpty() ||
527     !llMIMI.isEmpty() ||
528     !llMIC.isEmpty() ||
529     !llMII.isEmpty() ||
530 iliev 1202 !llID.isEmpty() ||
531 iliev 1139 !llGI.isEmpty();
532 iliev 596 }
533    
534 iliev 1202 private synchronized void
535 iliev 596 fireEvent(String s) {
536 iliev 1202 if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {
537     s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
538     InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
539     for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
540     } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_INFO:")) {
541     InstrumentsDbEvent e;
542     s = s.substring("DB_INSTRUMENT_DIRECTORY_INFO:".length());
543     if(s.startsWith("NAME ")) {
544     String[] list;
545     try {
546 iliev 1346 s = s.substring("NAME ".length());
547     list = parseEscapedStringList(s, ' ');
548 iliev 1202 if(list.length != 2) throw new LscpException();
549 iliev 1351 list[1] = toNonEscapedString(list[1]);
550 iliev 1202 e = new InstrumentsDbEvent(this, list[0], list[1]);
551     for(InstrumentsDbListener l : llID) {
552     l.directoryNameChanged(e);
553     }
554     } catch(LscpException x) {
555     getLogger().log (
556     Level.WARNING,
557     LscpI18n.getLogMsg("CommandFailed!"),
558     x
559     );
560     }
561     } else {
562     e = new InstrumentsDbEvent(this, s);
563     for(InstrumentsDbListener l : llID) l.directoryInfoChanged(e);
564     }
565     } else if(s.startsWith("DB_INSTRUMENT_COUNT:")) {
566     s = s.substring("DB_INSTRUMENT_COUNT:".length());
567     InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
568     for(InstrumentsDbListener l : llID) l.instrumentCountChanged(e);
569     } else if(s.startsWith("DB_INSTRUMENT_INFO:")) {
570     InstrumentsDbEvent e;
571     s = s.substring("DB_INSTRUMENT_INFO:".length());
572     if(s.startsWith("NAME ")) {
573     String[] list;
574     try {
575 iliev 1346 s = s.substring("NAME ".length());
576     list = parseEscapedStringList(s, ' ');
577 iliev 1202 if(list.length != 2) throw new LscpException();
578 iliev 1351 list[1] = toNonEscapedString(list[1]);
579 iliev 1202 e = new InstrumentsDbEvent(this, list[0], list[1]);
580     for(InstrumentsDbListener l : llID) {
581     l.instrumentNameChanged(e);
582     }
583     } catch(LscpException x) {
584     getLogger().log (
585     Level.WARNING,
586     LscpI18n.getLogMsg("CommandFailed!"),
587     x
588     );
589     }
590     } else {
591     e = new InstrumentsDbEvent(this, s);
592     for(InstrumentsDbListener l : llID) l.instrumentInfoChanged(e);
593     }
594     } else if(s.startsWith("DB_INSTRUMENTS_JOB_INFO:")) {
595     s = s.substring("DB_INSTRUMENTS_JOB_INFO:".length());
596 iliev 596 try {
597 iliev 1202 int i = Integer.parseInt(s);
598     InstrumentsDbEvent e = new InstrumentsDbEvent(this, i);
599     for(InstrumentsDbListener l : llID) l.jobStatusChanged(e);
600     } catch(NumberFormatException x) {
601     s = "Unknown DB_INSTRUMENTS_JOB_INFO format";
602     getLogger().log(Level.WARNING, s, x);
603     }
604    
605     } else if(s.startsWith("CHANNEL_COUNT:")) {
606     try {
607 iliev 596 int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));
608     ChannelCountEvent e = new ChannelCountEvent(this, i);
609     for(ChannelCountListener l : llCC) l.channelCountChanged(e);
610     } catch(NumberFormatException x) {
611     getLogger().log (
612     Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x
613     );
614     }
615     } else if(s.startsWith("VOICE_COUNT:")) {
616     try {
617     s = s.substring("VOICE_COUNT:".length());
618 iliev 1139 Integer[] i = parseIntList(s, ' ');
619     if(i.length != 2) {
620 iliev 596 getLogger().warning("Unknown VOICE_COUNT format");
621     return;
622     }
623 iliev 1139 VoiceCountEvent e = new VoiceCountEvent(this, i[0], i[1]);
624 iliev 596 for(VoiceCountListener l : llVC) l.voiceCountChanged(e);
625 iliev 1139 } catch(Exception x) {
626 iliev 596 getLogger().log(Level.WARNING, "Unknown VOICE_COUNT format", x);
627     }
628     } else if(s.startsWith("STREAM_COUNT:")) {
629     try {
630     s = s.substring("STREAM_COUNT:".length());
631 iliev 1139 Integer[] i = parseIntList(s, ' ');
632     if(i.length != 2) {
633 iliev 596 getLogger().warning("Unknown STREAM_COUNT format");
634     return;
635     }
636 iliev 1139 StreamCountEvent e = new StreamCountEvent(this, i[0], i[1]);
637 iliev 596 for(StreamCountListener l : llSC) l.streamCountChanged(e);
638 iliev 1139 } catch(Exception x) {
639 iliev 596 getLogger().log(Level.WARNING, "Unknown STREAM_COUNT format", x);
640     }
641     } else if(s.startsWith("BUFFER_FILL:")) {
642     try {
643     s = s.substring("BUFFER_FILL:".length());
644     int i = s.indexOf(' ');
645     if(i == -1) {
646 iliev 1139 getLogger().warning("Unknown BUFFER_FILL format");
647 iliev 596 return;
648     }
649     int j = Integer.parseInt(s.substring(0, i));
650     Vector<BufferFill> v =
651     getChannelBufferFillPercentage(s.substring(i + 1));
652     BufferFillEvent e = new BufferFillEvent(this, j, v);
653     for(BufferFillListener l : llBF) l.bufferFillChanged(e);
654     } catch(Exception x) {
655 iliev 1139 getLogger().log(Level.WARNING, "Unknown BUFFER_FILL format", x);
656 iliev 596 }
657     } else if(s.startsWith("CHANNEL_INFO:")) {
658     try {
659     int i = Integer.parseInt(s.substring("CHANNEL_INFO:".length()));
660     ChannelInfoEvent e = new ChannelInfoEvent(this, i);
661     for(ChannelInfoListener l : llCI) l.channelInfoChanged(e);
662     } catch(NumberFormatException x) {
663 iliev 1139 getLogger().log(Level.WARNING, "Unknown CHANNEL_INFO format", x);
664 iliev 596 }
665 iliev 784 } else if(s.startsWith("TOTAL_VOICE_COUNT:")) {
666     try {
667     s = s.substring("TOTAL_VOICE_COUNT:".length());
668     int i = Integer.parseInt(s);
669     TotalVoiceCountEvent e = new TotalVoiceCountEvent(this, i);
670     for(TotalVoiceCountListener l : llTVC) l.totalVoiceCountChanged(e);
671     } catch(NumberFormatException x) {
672     getLogger().log (
673     Level.WARNING, "Unknown TOTAL_VOICE_COUNT format", x
674     );
675     }
676 iliev 1139 } else if(s.startsWith("AUDIO_OUTPUT_DEVICE_COUNT:")) {
677     try {
678     s = s.substring("AUDIO_OUTPUT_DEVICE_COUNT:".length());
679     int i = Integer.parseInt(s);
680     ItemCountEvent e = new ItemCountEvent(this, i);
681     for(ItemCountListener l : llAODC) l.itemCountChanged(e);
682     } catch(NumberFormatException x) {
683     getLogger().log (
684     Level.WARNING, "Unknown AUDIO_OUTPUT_DEVICE_COUNT format", x
685     );
686     }
687     } else if(s.startsWith("AUDIO_OUTPUT_DEVICE_INFO:")) {
688     try {
689     s = s.substring("AUDIO_OUTPUT_DEVICE_INFO:".length());
690     int i = Integer.parseInt(s);
691     ItemInfoEvent e = new ItemInfoEvent(this, i);
692     for(ItemInfoListener l : llAODI) l.itemInfoChanged(e);
693     } catch(NumberFormatException x) {
694     getLogger().log (
695     Level.WARNING, "Unknown AUDIO_OUTPUT_DEVICE_INFO format", x
696     );
697     }
698     } else if(s.startsWith("MIDI_INPUT_DEVICE_COUNT:")) {
699     try {
700     s = s.substring("MIDI_INPUT_DEVICE_COUNT:".length());
701     int i = Integer.parseInt(s);
702     ItemCountEvent e = new ItemCountEvent(this, i);
703     for(ItemCountListener l : llMIDC) l.itemCountChanged(e);
704     } catch(NumberFormatException x) {
705     getLogger().log (
706     Level.WARNING, "Unknown MIDI_INPUT_DEVICE_COUNT format", x
707     );
708     }
709     } else if(s.startsWith("MIDI_INPUT_DEVICE_INFO:")) {
710     try {
711     s = s.substring("MIDI_INPUT_DEVICE_INFO:".length());
712     int i = Integer.parseInt(s);
713     ItemInfoEvent e = new ItemInfoEvent(this, i);
714     for(ItemInfoListener l : llMIDI) l.itemInfoChanged(e);
715     } catch(NumberFormatException x) {
716     getLogger().log (
717     Level.WARNING, "Unknown MIDI_INPUT_DEVICE_INFO format", x
718     );
719     }
720     } else if(s.startsWith("MIDI_INSTRUMENT_MAP_COUNT:")) {
721     try {
722     s = s.substring("MIDI_INSTRUMENT_MAP_COUNT:".length());
723     int i = Integer.parseInt(s);
724     ItemCountEvent e = new ItemCountEvent(this, i);
725     for(ItemCountListener l : llMIMC) l.itemCountChanged(e);
726     } catch(NumberFormatException x) {
727     getLogger().log (
728     Level.WARNING, "Unknown MIDI_INSTRUMENT_MAP_COUNT format", x
729     );
730     }
731     } else if(s.startsWith("MIDI_INSTRUMENT_MAP_INFO:")) {
732     try {
733     s = s.substring("MIDI_INSTRUMENT_MAP_INFO:".length());
734     int i = Integer.parseInt(s);
735     ItemInfoEvent e = new ItemInfoEvent(this, i);
736     for(ItemInfoListener l : llMIMI) l.itemInfoChanged(e);
737     } catch(NumberFormatException x) {
738     getLogger().log (
739     Level.WARNING, "Unknown MIDI_INSTRUMENT_MAP_INFO format", x
740     );
741     }
742     } else if(s.startsWith("MIDI_INSTRUMENT_COUNT:")) {
743     try {
744     s = s.substring("MIDI_INSTRUMENT_COUNT:".length());
745     Integer[] i = parseIntList(s, ' ');
746     if(i.length != 2) {
747     getLogger().warning("Unknown MIDI_INSTRUMENT_COUNT format");
748     return;
749     }
750    
751     MidiInstrumentCountEvent e =
752     new MidiInstrumentCountEvent(this, i[0], i[1]);
753    
754     for(MidiInstrumentCountListener l : llMIC) {
755     l.instrumentCountChanged(e);
756     }
757     } catch(Exception x) {
758     getLogger().log (
759     Level.WARNING, "Unknown MIDI_INSTRUMENT_COUNT format", x
760     );
761     }
762     } else if(s.startsWith("MIDI_INSTRUMENT_INFO:")) {
763     try {
764     s = s.substring("MIDI_INSTRUMENT_INFO:".length());
765     Integer[] i = parseIntList(s, ' ');
766     if(i.length != 3) {
767     getLogger().warning("Unknown MIDI_INSTRUMENT_INFO format");
768     return;
769     }
770    
771     MidiInstrumentInfoEvent e =
772     new MidiInstrumentInfoEvent(this, i[0], i[1], i[2]);
773     for(MidiInstrumentInfoListener l : llMII) {
774     l.instrumentInfoChanged(e);
775     }
776     } catch(Exception x) {
777     getLogger().log (
778     Level.WARNING, "Unknown MIDI_INSTRUMENT_INFO format", x
779     );
780     }
781     } else if(s.startsWith("FX_SEND_COUNT:")) {
782     try {
783     s = s.substring("FX_SEND_COUNT:".length());
784     Integer[] i = parseIntList(s, ' ');
785     if(i.length != 2) {
786     getLogger().warning("Unknown FX_SEND_COUNT format");
787     return;
788     }
789    
790     FxSendCountEvent e = new FxSendCountEvent(this, i[0], i[1]);
791    
792     for(FxSendCountListener l : llFSC) l.fxSendCountChanged(e);
793     } catch(Exception x) {
794     getLogger().log(Level.WARNING, "Unknown FX_SEND_COUNT format", x);
795     }
796     } else if(s.startsWith("FX_SEND_INFO:")) {
797     try {
798     s = s.substring("FX_SEND_INFO:".length());
799     Integer[] i = parseIntList(s, ' ');
800     if(i.length != 2) {
801     getLogger().warning("Unknown FX_SEND_INFO format");
802     return;
803     }
804    
805     FxSendInfoEvent e = new FxSendInfoEvent(this, i[0], i[1]);
806     for(FxSendInfoListener l : llFSI) {
807     l.fxSendInfoChanged(e);
808     }
809     } catch(Exception x) {
810     getLogger().log(Level.WARNING, "Unknown FX_SEND_INFO format", x);
811     }
812     } else if(s.startsWith("GLOBAL_INFO:")) {
813     handleGlobalInfoEvent(s.substring("GLOBAL_INFO:".length()));
814 iliev 596 } else if(s.startsWith("MISCELLANEOUS:")) {
815     s = s.substring("MISCELLANEOUS:".length());
816     MiscellaneousEvent e = new MiscellaneousEvent(this, s);
817     for(MiscellaneousListener l : llM) l.miscEventOccured(e);
818     }
819     }
820    
821     private void
822 iliev 1139 handleGlobalInfoEvent(String s) {
823     try {
824     if(s.startsWith("VOLUME ")) {
825     float f = Float.parseFloat(s.substring("VOLUME ".length()));
826     GlobalInfoEvent e = new GlobalInfoEvent(this, f);
827     for(GlobalInfoListener l : llGI) l.volumeChanged(e);
828     }
829     } catch(NumberFormatException x) {
830     getLogger().log(Level.WARNING, "Unknown GLOBAL_INFO format", x);
831     }
832     }
833    
834     private void
835 iliev 596 subscribe(String event) {
836 iliev 1139 if(!getPrintOnlyMode()) {
837     if(!isConnected()) return;
838 iliev 596
839 iliev 1139 if(!eventThread.isAlive()) eventThread.start();
840     }
841 iliev 596
842     try {
843     out.writeLine("SUBSCRIBE " + event);
844 iliev 1139 if(!getPrintOnlyMode()) getEmptyResultSet();
845 iliev 596 } catch(Exception x) {
846     getLogger().log (
847     Level.WARNING,
848     LscpI18n.getLogMsg("Client.subscriptionFailed!", event),
849     x
850     );
851     }
852     }
853    
854     private void
855     unsubscribe(String event) {
856 iliev 1139 if(!getPrintOnlyMode() && !isConnected()) return;
857 iliev 596
858     try {
859     out.writeLine("UNSUBSCRIBE " + event);
860 iliev 1139 if(!getPrintOnlyMode()) getEmptyResultSet();
861 iliev 596 } catch(Exception x) {
862     getLogger().log (
863     Level.WARNING,
864     LscpI18n.getLogMsg("Client.unsubscriptionFailed!", event),
865     x
866     );
867     }
868     }
869    
870     /**
871     * Registers the specified listener for receiving event messages.
872 iliev 1139 * Listeners can be registered regardless of the connection state.
873     * @param l The <code>ItemCountListener</code> to register.
874     */
875     public synchronized void
876     addAudioDeviceCountListener(ItemCountListener l) {
877     if(llAODC.isEmpty()) subscribe("AUDIO_OUTPUT_DEVICE_COUNT");
878     llAODC.add(l);
879     }
880    
881     /**
882     * Removes the specified listener.
883 iliev 596 * Listeners can be removed regardless of the connection state.
884 iliev 1139 * @param l The <code>ItemCountListener</code> to remove.
885     */
886     public synchronized void
887     removeAudioDeviceCountListener(ItemCountListener l) {
888     boolean b = llAODC.remove(l);
889     if(b && llAODC.isEmpty()) unsubscribe("AUDIO_OUTPUT_DEVICE_COUNT");
890     }
891    
892     /**
893     * Registers the specified listener for receiving event messages.
894     * Listeners can be registered regardless of the connection state.
895     * @param l The <code>ItemInfoListener</code> to register.
896     */
897     public synchronized void
898     addAudioDeviceInfoListener(ItemInfoListener l) {
899     if(llAODI.isEmpty()) subscribe("AUDIO_OUTPUT_DEVICE_INFO");
900     llAODI.add(l);
901     }
902    
903     /**
904     * Removes the specified listener.
905     * Listeners can be removed regardless of the connection state.
906     * @param l The <code>ItemInfoListener</code> to remove.
907     */
908     public synchronized void
909     removeAudioDeviceInfoListener(ItemInfoListener l) {
910     boolean b = llAODI.remove(l);
911     if(b && llAODI.isEmpty()) unsubscribe("AUDIO_OUTPUT_DEVICE_INFO");
912     }
913    
914     /**
915     * Registers the specified listener for receiving event messages.
916     * Listeners can be removed regardless of the connection state.
917 iliev 596 * @param l The <code>BufferFillListener</code> to register.
918     */
919     public synchronized void
920     addBufferFillListener(BufferFillListener l) {
921     if(llBF.isEmpty()) subscribe("BUFFER_FILL");
922     llBF.add(l);
923     }
924    
925     /**
926     * Removes the specified listener.
927     * Listeners can be removed regardless of the connection state.
928     * @param l The <code>BufferFillListener</code> to remove.
929     */
930     public synchronized void
931     removeBufferFillListener(BufferFillListener l) {
932     boolean b = llBF.remove(l);
933     if(b && llBF.isEmpty()) unsubscribe("BUFFER_FILL");
934     }
935    
936     /**
937     * Registers the specified listener for receiving event messages.
938     * Listeners can be registered regardless of the connection state.
939     * @param l The <code>ChannelCountListener</code> to register.
940     */
941     public synchronized void
942     addChannelCountListener(ChannelCountListener l) {
943     if(llCC.isEmpty()) subscribe("CHANNEL_COUNT");
944     llCC.add(l);
945     }
946    
947     /**
948     * Removes the specified listener.
949     * Listeners can be removed regardless of the connection state.
950     * @param l The <code>ChannelCountListener</code> to remove.
951     */
952     public synchronized void
953     removeChannelCountListener(ChannelCountListener l) {
954     boolean b = llCC.remove(l);
955     if(b && llCC.isEmpty()) unsubscribe("CHANNEL_COUNT");
956     }
957    
958     /**
959     * Registers the specified listener for receiving event messages.
960     * Listeners can be registered regardless of the connection state.
961     * @param l The <code>ChannelInfoListener</code> to register.
962     */
963     public synchronized void
964     addChannelInfoListener(ChannelInfoListener l) {
965     if(llCI.isEmpty()) subscribe("CHANNEL_INFO");
966     llCI.add(l);
967     }
968    
969     /**
970     * Removes the specified listener.
971     * Listeners can be removed regardless of the connection state.
972     * @param l The <code>ChannelInfoListener</code> to remove.
973     */
974     public synchronized void
975     removeChannelInfoListener(ChannelInfoListener l) {
976     boolean b = llCI.remove(l);
977     if(b && llCI.isEmpty()) unsubscribe("CHANNEL_INFO");
978     }
979    
980     /**
981     * Registers the specified listener for receiving event messages.
982     * Listeners can be registered regardless of the connection state.
983 iliev 1139 * @param l The <code>FxSendCountListener</code> to register.
984     */
985     public synchronized void
986     addFxSendCountListener(FxSendCountListener l) {
987     if(llFSC.isEmpty()) subscribe("FX_SEND_COUNT");
988     llFSC.add(l);
989     }
990    
991     /**
992     * Removes the specified listener.
993     * Listeners can be removed regardless of the connection state.
994     * @param l The <code>FxSendCountListener</code> to remove.
995     */
996     public synchronized void
997     removeFxSendCountListener(FxSendCountListener l) {
998     boolean b = llFSC.remove(l);
999     if(b && llFSC.isEmpty()) unsubscribe("FX_SEND_COUNT");
1000     }
1001    
1002     /**
1003     * Registers the specified listener for receiving event messages.
1004     * Listeners can be registered regardless of the connection state.
1005     * @param l The <code>FxSendInfoListener</code> to register.
1006     */
1007     public synchronized void
1008     addFxSendInfoListener(FxSendInfoListener l) {
1009     if(llFSI.isEmpty()) subscribe("FX_SEND_INFO");
1010     llFSI.add(l);
1011     }
1012    
1013     /**
1014     * Removes the specified listener.
1015     * Listeners can be removed regardless of the connection state.
1016     * @param l The <code>FxSendInfoListener</code> to remove.
1017     */
1018     public synchronized void
1019     removeFxSendInfoListener(FxSendInfoListener l) {
1020     boolean b = llFSI.remove(l);
1021     if(b && llFSI.isEmpty()) unsubscribe("FX_SEND_INFO");
1022     }
1023    
1024     /**
1025     * Registers the specified listener for receiving event messages.
1026     * Listeners can be registered regardless of the connection state.
1027     * @param l The <code>ItemCountListener</code> to register.
1028     */
1029     public synchronized void
1030     addMidiDeviceCountListener(ItemCountListener l) {
1031     if(llMIDC.isEmpty()) subscribe("MIDI_INPUT_DEVICE_COUNT");
1032     llMIDC.add(l);
1033     }
1034    
1035     /**
1036     * Removes the specified listener.
1037     * Listeners can be removed regardless of the connection state.
1038     * @param l The <code>ItemCountListener</code> to remove.
1039     */
1040     public synchronized void
1041     removeMidiDeviceCountListener(ItemCountListener l) {
1042     boolean b = llMIDC.remove(l);
1043     if(b && llMIDC.isEmpty()) unsubscribe("MIDI_INPUT_DEVICE_COUNT");
1044     }
1045    
1046     /**
1047     * Registers the specified listener for receiving event messages.
1048     * Listeners can be registered regardless of the connection state.
1049     * @param l The <code>ItemInfoListener</code> to register.
1050     */
1051     public synchronized void
1052     addMidiDeviceInfoListener(ItemInfoListener l) {
1053     if(llMIDI.isEmpty()) subscribe("MIDI_INPUT_DEVICE_INFO");
1054     llMIDI.add(l);
1055     }
1056    
1057     /**
1058     * Removes the specified listener.
1059     * Listeners can be removed regardless of the connection state.
1060     * @param l The <code>ItemInfoListener</code> to remove.
1061     */
1062     public synchronized void
1063     removeMidiDeviceInfoListener(ItemInfoListener l) {
1064     boolean b = llMIDI.remove(l);
1065     if(b && llMIDI.isEmpty()) unsubscribe("MIDI_INPUT_DEVICE_INFO");
1066     }
1067    
1068     /**
1069     * Registers the specified listener for receiving event messages.
1070     * Listeners can be registered regardless of the connection state.
1071 iliev 596 * @param l The <code>MiscellaneousListener</code> to register.
1072     */
1073     public synchronized void
1074     addMiscellaneousListener(MiscellaneousListener l) {
1075     if(llM.isEmpty()) subscribe("MISCELLANEOUS");
1076     llM.add(l);
1077     }
1078    
1079     /**
1080     * Removes the specified listener.
1081     * Listeners can be removed regardless of the connection state.
1082     * @param l The <code>MiscellaneousListener</code> to remove.
1083     */
1084     public synchronized void
1085     removeMiscellaneousListener(MiscellaneousListener l) {
1086     boolean b = llM.remove(l);
1087     if(b && llM.isEmpty()) unsubscribe("MISCELLANEOUS");
1088     }
1089    
1090     /**
1091     * Registers the specified listener for receiving event messages.
1092     * Listeners can be registered regardless of the connection state.
1093     * @param l The <code>StreamCountListener</code> to register.
1094     */
1095     public synchronized void
1096     addStreamCountListener(StreamCountListener l) {
1097     if(llSC.isEmpty()) subscribe("STREAM_COUNT");
1098     llSC.add(l);
1099     }
1100    
1101     /**
1102     * Removes the specified listener.
1103     * Listeners can be removed regardless of the connection state.
1104     * @param l The <code>StreamCountListener</code> to remove.
1105     */
1106     public synchronized void
1107     removeStreamCountListener(StreamCountListener l) {
1108     boolean b = llSC.remove(l);
1109     if(b && llSC.isEmpty()) unsubscribe("STREAM_COUNT");
1110     }
1111    
1112     /**
1113     * Registers the specified listener for receiving event messages.
1114     * Listeners can be registered regardless of the connection state.
1115     * @param l The <code>VoiceCountListener</code> to register.
1116     */
1117     public synchronized void
1118     addVoiceCountListener(VoiceCountListener l) {
1119     if(llVC.isEmpty()) subscribe("VOICE_COUNT");
1120     llVC.add(l);
1121     }
1122    
1123     /**
1124     * Removes the specified listener.
1125     * Listeners can be removed regardless of the connection state.
1126     * @param l The <code>VoiceCountListener</code> to remove.
1127     */
1128     public synchronized void
1129     removeVoiceCountListener(VoiceCountListener l) {
1130     boolean b = llVC.remove(l);
1131     if(b && llVC.isEmpty()) unsubscribe("VOICE_COUNT");
1132     }
1133    
1134     /**
1135 iliev 784 * Registers the specified listener for receiving event messages.
1136     * Listeners can be registered regardless of the connection state.
1137     * @param l The <code>TotalVoiceCountListener</code> to register.
1138     */
1139     public synchronized void
1140     addTotalVoiceCountListener(TotalVoiceCountListener l) {
1141     if(llTVC.isEmpty()) subscribe("TOTAL_VOICE_COUNT");
1142     llTVC.add(l);
1143     }
1144    
1145     /**
1146     * Removes the specified listener.
1147     * Listeners can be removed regardless of the connection state.
1148     * @param l The <code>TotalVoiceCountListener</code> to remove.
1149     */
1150     public synchronized void
1151     removeTotalVoiceCountListener(TotalVoiceCountListener l) {
1152     boolean b = llTVC.remove(l);
1153     if(b && llTVC.isEmpty()) unsubscribe("TOTAL_VOICE_COUNT");
1154     }
1155    
1156     /**
1157 iliev 1139 * Registers the specified listener for receiving event messages.
1158     * Listeners can be registered regardless of the connection state.
1159     * @param l The <code>ItemCountListener</code> to register.
1160     */
1161     public synchronized void
1162     addMidiInstrumentMapCountListener(ItemCountListener l) {
1163     if(llMIMC.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_COUNT");
1164     llMIMC.add(l);
1165     }
1166    
1167     /**
1168     * Removes the specified listener.
1169     * Listeners can be removed regardless of the connection state.
1170     * @param l The <code>ItemCountListener</code> to remove.
1171     */
1172     public synchronized void
1173     removeMidiInstrumentMapCountListener(ItemCountListener l) {
1174     boolean b = llMIMC.remove(l);
1175     if(b && llMIMC.isEmpty()) unsubscribe("MIDI_INSTRUMENT_MAP_COUNT");
1176     }
1177    
1178     /**
1179     * Registers the specified listener for receiving event messages.
1180     * Listeners can be registered regardless of the connection state.
1181     * @param l The <code>ItemInfoListener</code> to register.
1182     */
1183     public synchronized void
1184     addMidiInstrumentMapInfoListener(ItemInfoListener l) {
1185     if(llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
1186     llMIMI.add(l);
1187     }
1188    
1189     /**
1190     * Removes the specified listener.
1191     * Listeners can be removed regardless of the connection state.
1192     * @param l The <code>ItemInfoListener</code> to remove.
1193     */
1194     public synchronized void
1195     removeMidiInstrumentMapInfoListener(ItemInfoListener l) {
1196     boolean b = llMIMI.remove(l);
1197     if(b && llMIMI.isEmpty()) unsubscribe("MIDI_INSTRUMENT_MAP_INFO");
1198     }
1199    
1200     /**
1201     * Registers the specified listener for receiving event messages.
1202     * Listeners can be registered regardless of the connection state.
1203     * @param l The <code>MidiInstrumentCountListener</code> to register.
1204     */
1205     public synchronized void
1206     addMidiInstrumentCountListener(MidiInstrumentCountListener l) {
1207     if(llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
1208     llMIC.add(l);
1209     }
1210    
1211     /**
1212     * Removes the specified listener.
1213     * Listeners can be removed regardless of the connection state.
1214     * @param l The <code>MidiInstrumentCountListener</code> to remove.
1215     */
1216     public synchronized void
1217     removeMidiInstrumentCountListener(MidiInstrumentCountListener l) {
1218     boolean b = llMIC.remove(l);
1219     if(b && llMIC.isEmpty()) unsubscribe("MIDI_INSTRUMENT_COUNT");
1220     }
1221    
1222     /**
1223     * Registers the specified listener for receiving event messages.
1224     * Listeners can be registered regardless of the connection state.
1225     * @param l The <code>MidiInstrumentInfoListener</code> to register.
1226     */
1227     public synchronized void
1228     addMidiInstrumentInfoListener(MidiInstrumentInfoListener l) {
1229     if(llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
1230     llMII.add(l);
1231     }
1232    
1233     /**
1234     * Removes the specified listener.
1235     * Listeners can be removed regardless of the connection state.
1236     * @param l The <code>MidiInstrumentInfoListener</code> to remove.
1237     */
1238     public synchronized void
1239     removeMidiInstrumentInfoListener(MidiInstrumentInfoListener l) {
1240     boolean b = llMII.remove(l);
1241     if(b && llMII.isEmpty()) unsubscribe("MIDI_INSTRUMENT_INFO");
1242     }
1243    
1244     /**
1245     * Registers the specified listener for receiving event messages.
1246     * Listeners can be registered regardless of the connection state.
1247 iliev 1202 * @param l The <code>InstrumentsDbListener</code> to register.
1248     */
1249     public synchronized void
1250     addInstrumentsDbListener(InstrumentsDbListener l) {
1251     if(llID.isEmpty()) {
1252     subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1253     subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1254     subscribe("DB_INSTRUMENT_COUNT");
1255     subscribe("DB_INSTRUMENT_INFO");
1256     subscribe("DB_INSTRUMENTS_JOB_INFO");
1257     }
1258     llID.add(l);
1259     }
1260    
1261     /**
1262     * Removes the specified listener.
1263     * Listeners can be removed regardless of the connection state.
1264     * @param l The <code>InstrumentsDbListener</code> to remove.
1265     */
1266     public synchronized void
1267     removeInstrumentsDbListener(InstrumentsDbListener l) {
1268     boolean b = llID.remove(l);
1269     if(b && llID.isEmpty()) {
1270     unsubscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1271     unsubscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1272     unsubscribe("DB_INSTRUMENT_COUNT");
1273     unsubscribe("DB_INSTRUMENT_INFO");
1274     unsubscribe("DB_INSTRUMENTS_JOB_INFO");
1275     }
1276     }
1277    
1278     /**
1279     * Registers the specified listener for receiving event messages.
1280     * Listeners can be registered regardless of the connection state.
1281 iliev 1139 * @param l The <code>GlobalInfoListener</code> to register.
1282     */
1283     public synchronized void
1284     addGlobalInfoListener(GlobalInfoListener l) {
1285     if(llGI.isEmpty()) subscribe("GLOBAL_INFO");
1286     llGI.add(l);
1287     }
1288    
1289     /**
1290     * Removes the specified listener.
1291     * Listeners can be removed regardless of the connection state.
1292     * @param l The <code>GlobalInfoListener</code> to remove.
1293     */
1294     public synchronized void
1295     removeGlobalInfoListener(GlobalInfoListener l) {
1296     boolean b = llGI.remove(l);
1297     if(b && llGI.isEmpty()) unsubscribe("GLOBAL_INFO");
1298     }
1299    
1300     /**
1301 iliev 596 * Gets the number of all audio output drivers currently
1302     * available for the LinuxSampler instance.
1303     * @return The number of all audio output drivers currently
1304     * available for the LinuxSampler instance.
1305     * @throws IOException If some I/O error occurs.
1306     * @throws LscpException If LSCP protocol corruption occurs.
1307     * @throws LSException If some other error occurs.
1308     */
1309     public synchronized int
1310     getAudioOutputDriverCount() throws IOException, LscpException, LSException {
1311     verifyConnection();
1312     out.writeLine("GET AVAILABLE_AUDIO_OUTPUT_DRIVERS");
1313 iliev 1139
1314     if(getPrintOnlyMode()) return -1;
1315    
1316 iliev 596 String s = getSingleLineResultSet().getResult();
1317     return parseInt(s);
1318     }
1319 iliev 671
1320 iliev 596 /**
1321     * Gets all audio output drivers currently available for the LinuxSampler instance.
1322     *
1323 iliev 671 * @return <code>AudioOutputDriver</code> array containing all audio output drivers
1324     * currently available for the LinuxSampler instance.
1325 iliev 596 *
1326     * @throws IOException If an I/O error occurs.
1327     * @throws LscpException If LSCP protocol corruption occurs.
1328     * @throws LSException If some other error occurs.
1329     */
1330 iliev 671 public synchronized AudioOutputDriver[]
1331 iliev 596 getAudioOutputDrivers() throws IOException, LscpException, LSException {
1332 iliev 671 String[] drivers = getAudioOutputDriverNames();
1333 iliev 1139 if(getPrintOnlyMode()) return null;
1334    
1335 iliev 671 AudioOutputDriver[] aod = new AudioOutputDriver[drivers.length];
1336    
1337     for(int i = 0; i < aod.length; i++) aod[i] = getAudioOutputDriverInfo(drivers[i]);
1338    
1339     return aod;
1340     }
1341    
1342     /**
1343     * Gets all audio output drivers currently available for the LinuxSampler instance.
1344     *
1345     * @return <code>String</code> array containing all audio output drivers currently
1346     * available for the LinuxSampler instance.
1347     *
1348     * @throws IOException If an I/O error occurs.
1349     * @throws LscpException If LSCP protocol corruption occurs.
1350     * @throws LSException If some other error occurs.
1351     */
1352     private synchronized String[]
1353     getAudioOutputDriverNames() throws IOException, LscpException, LSException {
1354 iliev 596 verifyConnection();
1355     out.writeLine("LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS");
1356 iliev 1139 if(getPrintOnlyMode()) return null;
1357 iliev 596 return parseList(getSingleLineResultSet().getResult());
1358     }
1359    
1360     /**
1361     * Gets detailed information about a specific audio output driver.
1362     * @param driverName The name of the audio output driver.
1363 iliev 1326 * @param depList An optional list of dependences parameters.
1364 iliev 596 * @return An <code>AudioOutputDriver</code> object containing
1365     * information about the specified audio output driver.
1366     *
1367     * @throws IOException If an I/O error occurs.
1368     * @throws LscpException If LSCP protocol corruption occurs.
1369     * @throws LSException If there is no driver with name <code>driverName</code>.
1370     *
1371 iliev 671 * @see #getAudioOutputDriverNames
1372 iliev 596 */
1373 iliev 1326 public synchronized AudioOutputDriver
1374     getAudioOutputDriverInfo(String driverName, Parameter... depList)
1375     throws IOException, LscpException, LSException {
1376    
1377 iliev 596 verifyConnection();
1378     out.writeLine("GET AUDIO_OUTPUT_DRIVER INFO " + driverName);
1379 iliev 1139 if(getPrintOnlyMode()) return null;
1380    
1381 iliev 596 ResultSet rs = getMultiLineResultSet();
1382     AudioOutputDriver aod = new AudioOutputDriver(rs.getMultiLineResult());
1383     aod.setName(driverName);
1384    
1385     for(String s : aod.getParameterNames())
1386 iliev 1326 aod.addParameter(getAudioOutputDriverParameterInfo(driverName, s, depList));
1387 iliev 596
1388     return aod;
1389     }
1390    
1391     /**
1392     * Gets detailed information about a specific audio output driver parameter.
1393     *
1394     * @param driver The name of the audio output driver.
1395     * @param param A specific parameter name for which information should be obtained.
1396     * @param deplist An optional list of parameters on which the sought parameter
1397     * <code>param</code> depends on. <code>Parameter</code> instances can be
1398     * easily created using {@link ParameterFactory} factory.
1399     *
1400     * @return <code>Parameter</code> object containing
1401     * information about the specified audio output driver parameter.
1402     *
1403     * @throws IOException If an I/O error occurs.
1404     * @throws LscpException If LSCP protocol corruption occurs.
1405     * @throws LSException If <code>driver</code> is not a valid driver name
1406     * or <code>param</code> is not a valid parameter for the specified driver.
1407     *
1408     * @see #getAudioOutputDrivers
1409     * @see #getAudioOutputDriverInfo
1410     * @see ParameterFactory
1411     */
1412     public synchronized Parameter
1413     getAudioOutputDriverParameterInfo(String driver, String param, Parameter... deplist)
1414     throws IOException, LscpException, LSException {
1415    
1416     verifyConnection();
1417     StringBuffer args = new StringBuffer(driver);
1418     args.append(' ').append(param);
1419    
1420 iliev 1326 for(Parameter p : deplist) {
1421     if(p.getValue() == null) continue;
1422 iliev 596 args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1423 iliev 1326 }
1424 iliev 596
1425     out.writeLine("GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO " + args.toString());
1426 iliev 1139 if(getPrintOnlyMode()) return null;
1427 iliev 596
1428     ResultSet rs = getMultiLineResultSet();
1429    
1430     String[] lnS = rs.getMultiLineResult();
1431     ParameterType type = parseType(lnS);
1432     boolean multi = parseMultiplicity(lnS);
1433     Parameter prm;
1434    
1435     switch(type) {
1436     case BOOL:
1437     if(!multi) prm = new BoolParameter(lnS);
1438     else prm = new BoolListParameter(lnS);
1439     prm.setName(param);
1440 iliev 784 prm.setValue(prm.getDefault());
1441 iliev 596 return prm;
1442     case INT:
1443     if(!multi) prm = new IntParameter(lnS);
1444     else prm = new IntListParameter(lnS);
1445     prm.setName(param);
1446 iliev 784 prm.setValue(prm.getDefault());
1447 iliev 596 return prm;
1448     case FLOAT:
1449     if(!multi) prm = new FloatParameter(lnS);
1450     else prm = new FloatListParameter(lnS);
1451     prm.setName(param);
1452 iliev 784 prm.setValue(prm.getDefault());
1453 iliev 596 return prm;
1454     case STRING:
1455     if(!multi) prm = new StringParameter(lnS);
1456     else prm = new StringListParameter(lnS);
1457     prm.setName(param);
1458 iliev 784 prm.setValue(prm.getDefault());
1459 iliev 596 return prm;
1460     default: throw new LscpException(LscpI18n.getLogMsg("Client.unknownPrmType!"));
1461     }
1462     }
1463    
1464     /**
1465     * Creates a new audio output device for the desired audio output system.
1466     * @param aoDriver The desired audio output system.
1467     * @param paramList An optional list of driver specific parameters. <code>Parameter</code>
1468     * instances can be easily created using {@link ParameterFactory} factory.
1469     * @return The numerical ID of the newly created device.
1470     * @throws IOException If some I/O error occurs.
1471     * @throws LSException If the creation of the new audio output device failed.
1472     * @throws LscpException If LSCP protocol corruption occurs.
1473     * @see #getAudioOutputDrivers
1474     * @see #getAudioOutputDriverInfo
1475     * @see ParameterFactory
1476     */
1477     public synchronized int
1478     createAudioOutputDevice(String aoDriver, Parameter... paramList)
1479     throws IOException, LSException, LscpException {
1480    
1481     verifyConnection();
1482     StringBuffer args = new StringBuffer(aoDriver);
1483    
1484 iliev 1326 for(Parameter p : paramList) {
1485     if(p.getValue() == null) continue;
1486 iliev 596 args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
1487 iliev 1326 }
1488 iliev 596
1489     out.writeLine("CREATE AUDIO_OUTPUT_DEVICE " + args.toString());
1490 iliev 1139 if(getPrintOnlyMode()) return -1;
1491    
1492 iliev 596 ResultSet rs = getEmptyResultSet();
1493    
1494     return rs.getIndex();
1495     }
1496    
1497     /**
1498     * Destroys already created audio output device.
1499 iliev 1139 * @param deviceId The ID of the audio output device to be destroyed.
1500 iliev 596 * @throws IOException If some I/O error occurs.
1501     * @throws LSException If the destroying of the audio output device failed.
1502     * @throws LscpException If LSCP protocol corruption occurs.
1503     * @see #getAudioOutputDevices
1504     */
1505     public synchronized void
1506 iliev 1139 destroyAudioOutputDevice(int deviceId) throws IOException, LSException, LscpException {
1507 iliev 596 verifyConnection();
1508 iliev 1139 out.writeLine("DESTROY AUDIO_OUTPUT_DEVICE " + deviceId);
1509     if(getPrintOnlyMode()) return;
1510    
1511 iliev 596 ResultSet rs = getEmptyResultSet();
1512     }
1513    
1514 iliev 784 /**
1515     * Enables/disables the specified audio output device.
1516 iliev 1139 * @param deviceId The ID of the audio output device to be enabled/disabled.
1517 iliev 784 * @param enable If <code>true</code> the audio output device is enabled,
1518     * else the device is disabled.
1519     * @throws IOException If some I/O error occurs.
1520     * @throws LSException If there is no audio output
1521 iliev 1139 * device with numerical ID <code>deviceId</code>.
1522 iliev 784 * @throws LscpException If LSCP protocol corruption occurs.
1523     */
1524     public void
1525 iliev 1139 enableAudioOutputDevice(int deviceId, boolean enable)
1526 iliev 784 throws IOException, LSException, LscpException {
1527    
1528 iliev 1139 setAudioOutputDeviceParameter(deviceId, new BoolParameter("ACTIVE", enable));
1529 iliev 784 }
1530    
1531 iliev 596 /**
1532     * Gets the current number of all created audio output devices.
1533     * @return The current number of all created audio output devices.
1534     * @throws IOException If some I/O error occurs.
1535     * @throws LscpException If LSCP protocol corruption occurs.
1536     * @throws LSException If some other error occurs.
1537     */
1538     public synchronized int
1539     getAudioOutputDeviceCount() throws IOException, LscpException, LSException {
1540     verifyConnection();
1541     out.writeLine("GET AUDIO_OUTPUT_DEVICES");
1542 iliev 1139 if(getPrintOnlyMode()) return -1;
1543    
1544 iliev 596 String s = getSingleLineResultSet().getResult();
1545     return parseInt(s);
1546     }
1547    
1548     /**
1549 iliev 784 * Gets a list of all created audio output devices.
1550     * @return An <code>AudioOutputDevice</code> array
1551     * providing all created audio output devices.
1552     * @throws IOException If some I/O error occurs.
1553     * @throws LscpException If LSCP protocol corruption occurs.
1554     * @throws LSException If some other error occurs.
1555     */
1556     public synchronized AudioOutputDevice[]
1557     getAudioOutputDevices() throws IOException, LscpException, LSException {
1558     Integer[] idS = getAudioOutputDeviceIDs();
1559 iliev 1139 if(getPrintOnlyMode()) return null;
1560    
1561 iliev 784 AudioOutputDevice[] devices = new AudioOutputDevice[idS.length];
1562    
1563     for(int i = 0; i < devices.length; i++)
1564     devices[i] = getAudioOutputDeviceInfo(idS[i]);
1565    
1566     return devices;
1567     }
1568    
1569     /**
1570 iliev 596 * Gets a list of numerical IDs of all created audio output devices.
1571 iliev 784 * @return An <code>Integer</code> array providing the numerical IDs of
1572 iliev 596 * all created audio output devices.
1573     * @throws IOException If some I/O error occurs.
1574     * @throws LscpException If LSCP protocol corruption occurs.
1575     * @throws LSException If some other error occurs.
1576     */
1577     public synchronized Integer[]
1578 iliev 784 getAudioOutputDeviceIDs() throws IOException, LscpException, LSException {
1579 iliev 596 verifyConnection();
1580     out.writeLine("LIST AUDIO_OUTPUT_DEVICES");
1581 iliev 1139 if(getPrintOnlyMode()) return null;
1582    
1583 iliev 596 return parseIntList(getSingleLineResultSet().getResult());
1584     }
1585    
1586     /**
1587     * Gets the current settings of a specific, already created audio output device.
1588     *
1589 iliev 1139 * @param deviceId Specifies the numerical ID of the audio output device.
1590 iliev 596 *
1591     * @return An <code>AudioOutputDevice</code> instance containing information
1592     * about the specified device.
1593     *
1594     * @throws IOException If some I/O error occurs.
1595     * @throws LscpException If LSCP protocol corruption occurs.
1596     * @throws LSException If there is no audio output device
1597 iliev 1139 * with device id <code>deviceId</code>.
1598 iliev 596 *
1599     * @see #getAudioOutputDevices
1600     */
1601     public synchronized AudioOutputDevice
1602 iliev 1139 getAudioOutputDeviceInfo(int deviceId) throws IOException, LscpException, LSException {
1603 iliev 596 verifyConnection();
1604 iliev 1139 out.writeLine("GET AUDIO_OUTPUT_DEVICE INFO " + deviceId);
1605     if(getPrintOnlyMode()) return null;
1606 iliev 596
1607     ResultSet rs = getMultiLineResultSet();
1608    
1609     String[] lnS = rs.getMultiLineResult();
1610    
1611     AudioOutputDevice aod = new AudioOutputDevice();
1612 iliev 1139 aod.setDeviceId(deviceId);
1613 iliev 596 Parameter<Integer> channels;
1614     Parameter<Integer> samplerate;
1615    
1616     String drv = getCategoryInfo(lnS, "DRIVER");
1617     aod.setDriverName(drv);
1618    
1619     for(String s : lnS) {
1620     if(s.startsWith("CHANNELS: ")) {
1621     channels = (Parameter<Integer>)
1622     getAudioOutputDriverParameterInfo(drv, "CHANNELS");
1623    
1624     s = s.substring("CHANNELS: ".length(), s.length());
1625     channels.parseValue(s);
1626     aod.setChannelsParameter(channels);
1627 iliev 784 int count = channels.getValue() > 0 ? channels.getValue() : 0;
1628     AudioOutputChannel[] aoc = new AudioOutputChannel[count];
1629     for(int i = 0; i < count; i++) {
1630 iliev 1139 aoc[i] = getAudioOutputChannelInfo(deviceId, i);
1631 iliev 784 }
1632     aod.setAudioChannels(aoc);
1633 iliev 596 } else if(s.startsWith("SAMPLERATE: ")) {
1634     samplerate = (Parameter<Integer>)
1635     getAudioOutputDriverParameterInfo(drv, "SAMPLERATE");
1636    
1637     s = s.substring("SAMPLERATE: ".length(), s.length());
1638     samplerate.parseValue(s);
1639     aod.setSampleRateParameter(samplerate);
1640     } else if(s.startsWith("ACTIVE: ")) {
1641     s = s.substring("ACTIVE: ".length(), s.length());
1642     aod.setActive(Boolean.parseBoolean(s));
1643     } else if(s.startsWith("DRIVER: ")) {
1644    
1645     } else {
1646     int i = s.indexOf(": ");
1647     if(i == -1) throw new LscpException (
1648     LscpI18n.getLogMsg("CommandFailed!")
1649     );
1650    
1651     Parameter prm =
1652     getAudioOutputDriverParameterInfo(drv, s.substring(0, i));
1653    
1654     s = s.substring(i + 2);
1655     prm.parseValue(s);
1656    
1657     aod.addParameter(prm);
1658     }
1659     }
1660    
1661     return aod;
1662     }
1663    
1664     /**
1665     * Alters a specific setting of a created audio output device.
1666     *
1667 iliev 1139 * @param deviceId The numerical ID of the audio output device.
1668 iliev 596 * @param prm A <code>Parameter</code> instance containing the name of the parameter
1669     * and the new value for this parameter.
1670     *
1671     * @throws IOException If some I/O error occurs.
1672     * @throws LscpException If LSCP protocol corruption occurs.
1673     * @throws LSException If
1674     * <ul>
1675 iliev 1139 * <li>There is no audio output device with numerical ID <code>deviceId</code>;
1676 iliev 596 * <li>There is no device parameter with the specified name;
1677     * <li>The device parameter is readonly;
1678     * <li>The device parameter is from different type.
1679     * </ul>
1680     *
1681     * @see #getAudioOutputDevices
1682     * @see #getAudioOutputDeviceInfo
1683     */
1684     public synchronized void
1685 iliev 1139 setAudioOutputDeviceParameter(int deviceId, Parameter prm)
1686 iliev 596 throws IOException, LscpException, LSException {
1687    
1688     verifyConnection();
1689     String kv = prm.getName() + '=' + prm.getStringValue();
1690 iliev 1139 out.writeLine("SET AUDIO_OUTPUT_DEVICE_PARAMETER " + deviceId + ' ' + kv);
1691     if(getPrintOnlyMode()) return;
1692 iliev 596
1693     ResultSet rs = getEmptyResultSet();
1694     }
1695    
1696     /**
1697 iliev 1139 * Changes the channel number of the speicifed audio output device.
1698     * @param deviceId The numerical ID of the audio output device.
1699 iliev 784 * @param channels The new number of audio output channels.
1700     *
1701     * @throws IOException If an I/O error occurs.
1702     * @throws LscpException If LSCP protocol corruption occurs.
1703 iliev 1139 * @throws LSException If there is no device with ID <code>deviceId</code> or
1704 iliev 784 * if <code>channels</code> number is out of range.
1705     *
1706     * @see #getAudioOutputChannelInfo
1707     */
1708     public synchronized void
1709 iliev 1139 setAudioOutputChannelCount(int deviceId, int channels)
1710 iliev 784 throws IOException, LscpException, LSException {
1711    
1712 iliev 1139 setAudioOutputDeviceParameter(deviceId, new IntParameter("CHANNELS", channels));
1713 iliev 784 }
1714    
1715     /**
1716 iliev 596 * Gets information about an audio channel.
1717     *
1718 iliev 1139 * @param deviceId The numerical ID of the audio output device.
1719 iliev 596 * @param audioChn The audio channel number.
1720     *
1721     * @return An <code>AudioOutputChannel</code> instance containing the
1722     * information about the specified audio output channel.
1723     *
1724     * @throws IOException If some I/O error occurs.
1725     * @throws LscpException If LSCP protocol corruption occurs.
1726     * @throws LSException If
1727     * <ul>
1728 iliev 1139 * <li>There is no audio output device with numerical ID <code>deviceId</code>;
1729 iliev 596 * <li><code>audioChn</code> is not a valid channel number;
1730     * </ul>
1731     *
1732     * @see #getAudioOutputDevices
1733     * @see #getAudioOutputDeviceInfo
1734     */
1735     public synchronized AudioOutputChannel
1736 iliev 1139 getAudioOutputChannelInfo(int deviceId, int audioChn)
1737 iliev 596 throws IOException, LscpException, LSException {
1738    
1739     verifyConnection();
1740 iliev 1139 out.writeLine("GET AUDIO_OUTPUT_CHANNEL INFO " + deviceId + ' ' + audioChn);
1741     if(getPrintOnlyMode()) return null;
1742 iliev 596
1743     ResultSet rs = getMultiLineResultSet();
1744    
1745     AudioOutputChannel aoc = new AudioOutputChannel();
1746    
1747     String[] lnS = rs.getMultiLineResult();
1748     for(String s : lnS) {
1749     if(s.startsWith("NAME: ")) {
1750 iliev 784 s = s.substring("NAME: ".length());
1751     Parameter<String> prm = getAudioOutputChannelParameterInfo (
1752 iliev 1139 deviceId, audioChn, "NAME"
1753 iliev 784 );
1754     prm.setValue(removeQuotation(s));
1755     aoc.setNameParameter(prm);
1756 iliev 596 } else if(s.startsWith("IS_MIX_CHANNEL: ")) {
1757     s = s.substring("IS_MIX_CHANNEL: ".length());
1758 iliev 784 Parameter<Boolean> prm = getAudioOutputChannelParameterInfo (
1759 iliev 1139 deviceId, audioChn, "IS_MIX_CHANNEL"
1760 iliev 784 );
1761     prm.setValue(Boolean.parseBoolean(s));
1762     aoc.setMixChannelParameter(prm);
1763 iliev 596 } else if(s.startsWith("MIX_CHANNEL_DESTINATION: ")) {
1764     s = s.substring("MIX_CHANNEL_DESTINATION: ".length());
1765 iliev 784 Parameter<Integer> prm = getAudioOutputChannelParameterInfo (
1766 iliev 1139 deviceId, audioChn, "MIX_CHANNEL_DESTINATION"
1767 iliev 784 );
1768     prm.setValue(parseInt(s));
1769     aoc.setMixChannelDestParameter(prm);
1770 iliev 596 } else {
1771     int i = s.indexOf(": ");
1772     if(i == -1) throw new LscpException (
1773     LscpI18n.getLogMsg("CommandFailed!")
1774     );
1775    
1776     Parameter prm = getAudioOutputChannelParameterInfo (
1777 iliev 1139 deviceId, audioChn, s.substring(0, i)
1778 iliev 596 );
1779    
1780     s = s.substring(i + 2);
1781     prm.parseValue(s);
1782    
1783     aoc.addParameter(prm);
1784     }
1785     }
1786    
1787     return aoc;
1788     }
1789    
1790     /**
1791     * Gets detailed information about a specific audio output channel parameter.
1792     *
1793 iliev 1139 * @param devId The numerical ID of the audio output device.
1794 iliev 596 * @param chan The audio channel number.
1795     * @param param a specific channel parameter name for which information should be obtained.
1796     *
1797     * @return An <code>Parameter</code> instance containing
1798     * information about the specified audio output channel parameter.
1799     *
1800     * @throws IOException If an I/O error occurs.
1801     * @throws LscpException If LSCP protocol corruption occurs.
1802     * @throws LSException If
1803     * <ul>
1804 iliev 1139 * <li><code>devId</code> is not a valid device ID;
1805 iliev 596 * <li><code>chan</code> is not a valid channel number;
1806     * <li>There is no channel parameter with the specified name.
1807     * </ul>
1808     *
1809     * @see #getAudioOutputDevices
1810     * @see #getAudioOutputChannelInfo
1811     */
1812     public synchronized Parameter
1813 iliev 1139 getAudioOutputChannelParameterInfo(int devId, int chan, String param)
1814 iliev 596 throws IOException, LscpException, LSException {
1815    
1816     verifyConnection();
1817 iliev 1139 String args = devId + " " + chan + " " + param;
1818 iliev 596 out.writeLine("GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO " + args);
1819 iliev 1139 if(getPrintOnlyMode()) return null;
1820 iliev 596
1821     ResultSet rs = getMultiLineResultSet();
1822    
1823     String[] lnS = rs.getMultiLineResult();
1824     ParameterType type = parseType(lnS);
1825     boolean multi = parseMultiplicity(lnS);
1826     Parameter prm;
1827    
1828     switch(type) {
1829     case BOOL:
1830     if(!multi) prm = new BoolParameter(lnS);
1831     else prm = new BoolListParameter(lnS);
1832     prm.setName(param);
1833     return prm;
1834     case INT:
1835     if(!multi) prm = new IntParameter(lnS);
1836     else prm = new IntListParameter(lnS);
1837     prm.setName(param);
1838     return prm;
1839     case FLOAT:
1840     if(!multi) prm = new FloatParameter(lnS);
1841     else prm = new FloatListParameter(lnS);
1842     prm.setName(param);
1843     return prm;
1844     case STRING:
1845     if(!multi) prm = new StringParameter(lnS);
1846     else prm = new StringListParameter(lnS);
1847     prm.setName(param);
1848     return prm;
1849     default: throw new LscpException(LscpI18n.getLogMsg("Client.unknownPrmType!"));
1850     }
1851     }
1852    
1853     /**
1854     * Alters a specific setting of an audio output channel.
1855     *
1856 iliev 1139 * @param devId The numerical ID of the audio device.
1857 iliev 596 * @param chn The audio channel number.
1858     * @param prm A <code>Parameter</code> instance containing the name of the parameter
1859     * and the new value for this parameter.
1860     *
1861     * @throws IOException If some I/O error occurs.
1862     * @throws LscpException If LSCP protocol corruption occurs.
1863     * @throws LSException If
1864     * <ul>
1865 iliev 1139 * <li>There is no audio output device with numerical ID <code>devId</code>;
1866 iliev 596 * <li><code>chn</code> is not a valid channel number;
1867     * <li>There is no channel parameter with the specified name;
1868     * <li>The channel parameter is readonly;
1869     * <li>The channel parameter is from different type.
1870     * </ul>
1871     *
1872     * @see #getAudioOutputDevices
1873     * @see #getAudioOutputChannelInfo
1874     */
1875     public synchronized void
1876 iliev 1139 setAudioOutputChannelParameter(int devId, int chn, Parameter prm)
1877 iliev 596 throws IOException, LscpException, LSException {
1878    
1879     verifyConnection();
1880 iliev 1139 String args = devId + " " + chn + " " + prm.getName() + '=' + prm.getStringValue();
1881 iliev 596 out.writeLine("SET AUDIO_OUTPUT_CHANNEL_PARAMETER " + args);
1882 iliev 1139 if(getPrintOnlyMode()) return;
1883 iliev 596
1884     ResultSet rs = getEmptyResultSet();
1885     }
1886    
1887     /**
1888     * Gets the current number of all MIDI input drivers.
1889     * @return The current number of all MIDI input drivers.
1890     * @throws IOException If some I/O error occurs.
1891     * @throws LscpException If LSCP protocol corruption occurs.
1892     * @throws LSException If some other error occurs.
1893     */
1894     public synchronized int
1895     getMidiInputDriverCount() throws IOException, LscpException, LSException {
1896     verifyConnection();
1897     out.writeLine("GET AVAILABLE_MIDI_INPUT_DRIVERS");
1898 iliev 1139 if(getPrintOnlyMode()) return -1;
1899    
1900 iliev 596 String s = getSingleLineResultSet().getResult();
1901     return parseInt(s);
1902     }
1903    
1904     /**
1905     * Gets all MIDI input drivers currently available for the LinuxSampler instance.
1906     *
1907 iliev 671 * @return <code>MidiInputDriver</code> array containing all MIDI input drivers currently
1908     * available for the LinuxSampler instance.
1909 iliev 596 *
1910     * @throws IOException If an I/O error occurs.
1911     * @throws LscpException If LSCP protocol corruption occurs.
1912     * @throws LSException If some other error occurs.
1913     */
1914 iliev 671 public synchronized MidiInputDriver[]
1915 iliev 596 getMidiInputDrivers() throws IOException, LscpException, LSException {
1916 iliev 671 String[] drivers = getMidiInputDriverNames();
1917 iliev 1139 if(getPrintOnlyMode()) return null;
1918    
1919 iliev 671 MidiInputDriver[] mid = new MidiInputDriver[drivers.length];
1920    
1921     for(int i = 0; i < mid.length; i++) mid[i] = getMidiInputDriverInfo(drivers[i]);
1922    
1923     return mid;
1924     }
1925    
1926     /**
1927     * Gets all MIDI input drivers currently available for the LinuxSampler instance.
1928     *
1929     * @return <code>String</code> array containing all MIDI input drivers currently available
1930     * for the LinuxSampler instance.
1931     *
1932     * @throws IOException If an I/O error occurs.
1933     * @throws LscpException If LSCP protocol corruption occurs.
1934     * @throws LSException If some other error occurs.
1935     */
1936     private synchronized String[]
1937     getMidiInputDriverNames() throws IOException, LscpException, LSException {
1938 iliev 596 verifyConnection();
1939     out.writeLine("LIST AVAILABLE_MIDI_INPUT_DRIVERS");
1940 iliev 1139 if(getPrintOnlyMode()) return null;
1941    
1942 iliev 596 return parseList(getSingleLineResultSet().getResult());
1943     }
1944    
1945     /**
1946     * Gets detailed information about a specific MIDI input driver.
1947     * @param driverName The name of the MIDI input driver.
1948 iliev 1326 * @param depList An optional list of dependences parameters.
1949 iliev 671 * @return A <code>MidiInputDriver</code> object containing
1950 iliev 596 * information about the specified MIDI input driver.
1951     *
1952     * @throws IOException If an I/O error occurs.
1953     * @throws LscpException If LSCP protocol corruption occurs.
1954     * @throws LSException If there is no driver with name <code>driverName</code>.
1955     *
1956 iliev 671 * @see #getMidiInputDriverNames
1957 iliev 596 */
1958 iliev 1326 public synchronized MidiInputDriver
1959     getMidiInputDriverInfo(String driverName, Parameter... depList)
1960     throws IOException, LscpException, LSException {
1961    
1962 iliev 596 verifyConnection();
1963     out.writeLine("GET MIDI_INPUT_DRIVER INFO " + driverName);
1964 iliev 1139 if(getPrintOnlyMode()) return null;
1965    
1966 iliev 596 ResultSet rs = getMultiLineResultSet();
1967    
1968     MidiInputDriver mid = new MidiInputDriver(rs.getMultiLineResult());
1969     mid.setName(driverName);
1970    
1971     for(String s : mid.getParameterNames())
1972 iliev 1326 mid.addParameter(getMidiInputDriverParameterInfo(driverName, s, depList));
1973 iliev 596
1974     return mid;
1975     }
1976    
1977     /**
1978     * Gets detailed information about a specific MIDI input driver parameter.
1979     *
1980     * @param driver The name of the MIDI input driver.
1981     * @param param a specific parameter name for which information should be obtained.
1982     * @param deplist An optional list of parameters on which the sought parameter
1983     * <code>param</code> depends on. <code>Parameter</code> instances can be
1984     * easily created using {@link ParameterFactory} factory.
1985     *
1986 iliev 671 * @return A <code>Parameter</code> object containing
1987 iliev 596 * information about the specified MIDI input driver parameter.
1988     *
1989     * @throws IOException If an I/O error occurs.
1990     * @throws LscpException If LSCP protocol corruption occurs.
1991     * @throws LSException If <code>driver</code> is not a valid driver name
1992     * or <code>param</code> is not a valid parameter for the specified driver.
1993     *
1994     * @see #getMidiInputDrivers
1995     * @see #getMidiInputDriverInfo
1996     * @see ParameterFactory
1997     */
1998     public synchronized Parameter
1999     getMidiInputDriverParameterInfo(String driver, String param, Parameter... deplist)
2000     throws IOException, LscpException, LSException {
2001    
2002     verifyConnection();
2003     StringBuffer args = new StringBuffer(driver);
2004     args.append(' ').append(param);
2005    
2006 iliev 1326 for(Parameter p : deplist) {
2007     if(p.getValue() == null) continue;
2008 iliev 596 args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2009 iliev 1326 }
2010 iliev 596
2011     out.writeLine("GET MIDI_INPUT_DRIVER_PARAMETER INFO " + args.toString());
2012 iliev 1139 if(getPrintOnlyMode()) return null;
2013 iliev 596
2014     ResultSet rs = getMultiLineResultSet();
2015    
2016     String[] lnS = rs.getMultiLineResult();
2017     ParameterType type = parseType(lnS);
2018     boolean multi = parseMultiplicity(lnS);
2019     Parameter prm;
2020    
2021     switch(type) {
2022     case BOOL:
2023     if(!multi) prm = new BoolParameter(lnS);
2024     else prm = new BoolListParameter(lnS);
2025     prm.setName(param);
2026 iliev 784 prm.setValue(prm.getDefault());
2027 iliev 596 return prm;
2028     case INT:
2029     if(!multi) prm = new IntParameter(lnS);
2030     else prm = new IntListParameter(lnS);
2031     prm.setName(param);
2032 iliev 784 prm.setValue(prm.getDefault());
2033 iliev 596 return prm;
2034     case FLOAT:
2035     if(!multi) prm = new FloatParameter(lnS);
2036     else prm = new FloatListParameter(lnS);
2037     prm.setName(param);
2038 iliev 784 prm.setValue(prm.getDefault());
2039 iliev 596 return prm;
2040     case STRING:
2041     if(!multi) prm = new StringParameter(lnS);
2042     else prm = new StringListParameter(lnS);
2043     prm.setName(param);
2044 iliev 784 prm.setValue(prm.getDefault());
2045 iliev 596 return prm;
2046     default: throw new LscpException(LscpI18n.getLogMsg("Client.unknownPrmType!"));
2047     }
2048     }
2049    
2050     /**
2051     * Creates a new MIDI input device.
2052     * @param miDriver The desired MIDI input system.
2053     * @param paramList An optional list of driver specific parameters. <code>Parameter</code>
2054     * instances can be easily created using {@link ParameterFactory} factory.
2055     * @return The numerical ID of the newly created device.
2056     * @throws IOException If some I/O error occurs.
2057     * @throws LSException If the creation of the new MIDI input device failed.
2058     * @throws LscpException If LSCP protocol corruption occurs.
2059     *
2060     * @see #getMidiInputDrivers
2061     * @see #getMidiInputDriverInfo
2062     * @see ParameterFactory
2063     */
2064     public synchronized int
2065     createMidiInputDevice(String miDriver, Parameter... paramList)
2066     throws IOException, LSException, LscpException {
2067    
2068     verifyConnection();
2069     StringBuffer args = new StringBuffer(miDriver);
2070    
2071 iliev 1326 for(Parameter p : paramList) {
2072     if(p.getValue() == null) continue;
2073 iliev 596 args.append(' ').append(p.getName()).append('=').append(p.getStringValue());
2074 iliev 1326 }
2075 iliev 596
2076     out.writeLine("CREATE MIDI_INPUT_DEVICE " + args.toString());
2077 iliev 1139 if(getPrintOnlyMode()) return -1;
2078    
2079 iliev 596 ResultSet rs = getEmptyResultSet();
2080    
2081     return rs.getIndex();
2082     }
2083    
2084     /**
2085     * Destroys already created MIDI input device.
2086 iliev 1139 * @param deviceId The numerical ID of the MIDI input device to be destroyed.
2087 iliev 596 * @throws IOException If some I/O error occurs.
2088     * @throws LSException If the destroying of the MIDI input device failed.
2089     * @throws LscpException If LSCP protocol corruption occurs.
2090     * @see #createMidiInputDevice
2091     * @see #getMidiInputDevices
2092     */
2093     public synchronized void
2094 iliev 1139 destroyMidiInputDevice(int deviceId) throws IOException, LSException, LscpException {
2095 iliev 596 verifyConnection();
2096 iliev 1139 out.writeLine("DESTROY MIDI_INPUT_DEVICE " + deviceId);
2097     if(getPrintOnlyMode()) return;
2098    
2099 iliev 596 ResultSet rs = getEmptyResultSet();
2100     }
2101    
2102 iliev 784 /**
2103     * Enables/disables the specified MIDI input device.
2104 iliev 1139 * @param deviceId The ID of the MIDI input device to be enabled/disabled.
2105 iliev 784 * @param enable If <code>true</code> the MIDI input device is enabled,
2106     * else the device is disabled.
2107     * @throws IOException If some I/O error occurs.
2108     * @throws LSException If there is no MIDI input
2109 iliev 1139 * device with numerical ID <code>deviceId</code>.
2110 iliev 784 * @throws LscpException If LSCP protocol corruption occurs.
2111     */
2112     public void
2113 iliev 1139 enableMidiInputDevice(int deviceId, boolean enable)
2114 iliev 784 throws IOException, LSException, LscpException {
2115    
2116 iliev 1139 setMidiInputDeviceParameter(deviceId, new BoolParameter("ACTIVE", enable));
2117 iliev 784 }
2118    
2119 iliev 596 /**
2120     * Gets the current number of all created MIDI input devices.
2121     * @return The current number of all created MIDI input devices.
2122     * @throws IOException If some I/O error occurs.
2123     * @throws LscpException If LSCP protocol corruption occurs.
2124     * @throws LSException If some other error occurs.
2125     */
2126     public synchronized int
2127     getMidiInputDeviceCount() throws IOException, LscpException, LSException {
2128     verifyConnection();
2129     out.writeLine("GET MIDI_INPUT_DEVICES");
2130 iliev 1139 if(getPrintOnlyMode()) return -1;
2131    
2132 iliev 596 String s = getSingleLineResultSet().getResult();
2133     return parseInt(s);
2134     }
2135    
2136     /**
2137 iliev 784 * Gets a list of all created MIDI input devices.
2138     * @return A <code>MidiInputDevice</code> array
2139     * providing all created MIDI input devices.
2140     * @throws IOException If some I/O error occurs.
2141     * @throws LscpException If LSCP protocol corruption occurs.
2142     * @throws LSException If some other error occurs.
2143     *
2144     * @see #createMidiInputDevice
2145     * @see #destroyMidiInputDevice
2146     */
2147     public synchronized MidiInputDevice[]
2148     getMidiInputDevices() throws IOException, LscpException, LSException {
2149     Integer[] idS = getMidiInputDeviceIDs();
2150 iliev 1139 if(getPrintOnlyMode()) return null;
2151    
2152 iliev 784 MidiInputDevice[] devices = new MidiInputDevice[idS.length];
2153    
2154     for(int i = 0; i < devices.length; i++)
2155     devices[i] = getMidiInputDeviceInfo(idS[i]);
2156    
2157     return devices;
2158     }
2159    
2160     /**
2161 iliev 596 * Gets a list of numerical IDs of all created MIDI input devices.
2162 iliev 784 * @return An <code>Integer</code> array providing the numerical IDs of
2163 iliev 596 * all created MIDI input devices.
2164     * @throws IOException If some I/O error occurs.
2165     * @throws LscpException If LSCP protocol corruption occurs.
2166     * @throws LSException If some other error occurs.
2167     *
2168     * @see #createMidiInputDevice
2169     * @see #destroyMidiInputDevice
2170     */
2171     public synchronized Integer[]
2172 iliev 784 getMidiInputDeviceIDs() throws IOException, LscpException, LSException {
2173 iliev 596 verifyConnection();
2174     out.writeLine("LIST MIDI_INPUT_DEVICES");
2175 iliev 1139 if(getPrintOnlyMode()) return null;
2176    
2177 iliev 596 return parseIntList(getSingleLineResultSet().getResult());
2178     }
2179    
2180     /**
2181     * Gets the current settings of a specific, already created MIDI input device.
2182     *
2183 iliev 1139 * @param deviceId Specifies the numerical ID of the MIDI input device.
2184 iliev 596 *
2185 iliev 1139 * @return A <code>MidiInputDevice</code> instance containing information
2186 iliev 596 * about the specified device.
2187     *
2188     * @throws IOException If some I/O error occurs.
2189     * @throws LscpException If LSCP protocol corruption occurs.
2190     * @throws LSException If there is no MIDI input device
2191 iliev 1139 * with device id <code>deviceId</code>.
2192 iliev 596 *
2193     * @see #getMidiInputDevices
2194     */
2195     public synchronized MidiInputDevice
2196 iliev 1139 getMidiInputDeviceInfo(int deviceId) throws IOException, LscpException, LSException {
2197 iliev 596 verifyConnection();
2198 iliev 1139 out.writeLine("GET MIDI_INPUT_DEVICE INFO " + deviceId);
2199     if(getPrintOnlyMode()) return null;
2200 iliev 596
2201     ResultSet rs = getMultiLineResultSet();
2202    
2203     String[] lnS = rs.getMultiLineResult();
2204    
2205     MidiInputDevice mid = new MidiInputDevice();
2206 iliev 1139 mid.setDeviceId(deviceId);
2207 iliev 596
2208     String drv = getCategoryInfo(lnS, "DRIVER");
2209     mid.setDriverName(drv);
2210    
2211     for(String s : lnS) {
2212     if(s.startsWith("DRIVER: ")) {
2213    
2214     } else if(s.startsWith("ACTIVE: ")) {
2215     s = s.substring("ACTIVE: ".length());
2216     mid.setActive(Boolean.parseBoolean(s));
2217 iliev 784 } else if(s.startsWith("PORTS: ")) {
2218     s = s.substring("PORTS: ".length());
2219     int ports = Parser.parseInt(s);
2220     MidiPort[] midiPorts = new MidiPort[ports > 0 ? ports : 0];
2221    
2222     for(int i = 0; i < midiPorts.length; i++)
2223 iliev 1139 midiPorts[i] = getMidiInputPortInfo(deviceId, i);
2224 iliev 784
2225     mid.setMidiPorts(midiPorts);
2226 iliev 596 } else {
2227     int i = s.indexOf(": ");
2228     if(i == -1) throw new LscpException (
2229     LscpI18n.getLogMsg("CommandFailed!")
2230     );
2231    
2232     Parameter prm =
2233     getMidiInputDriverParameterInfo(drv, s.substring(0, i));
2234    
2235     s = s.substring(i + 2);
2236     prm.parseValue(s);
2237    
2238     mid.addParameter(prm);
2239     }
2240     }
2241    
2242     return mid;
2243     }
2244    
2245     /**
2246     * Alters a specific setting of a created MIDI input device.
2247     *
2248 iliev 1139 * @param deviceId The numerical ID of the MIDI input device.
2249 iliev 596 * @param prm A <code>Parameter</code> instance containing the name of the parameter
2250     * and the new value for this parameter.
2251     *
2252     * @throws IOException If some I/O error occurs.
2253     * @throws LscpException If LSCP protocol corruption occurs.
2254     * @throws LSException If
2255     * <ul>
2256 iliev 1139 * <li>There is no MIDI input device with numerical ID <code>deviceId</code>;
2257 iliev 596 * <li>There is no device parameter with the specified name;
2258     * <li>The device parameter is readonly;
2259     * <li>The device parameter is from different type.
2260     * </ul>
2261     *
2262     * @see #getMidiInputDevices
2263     * @see #getMidiInputDeviceInfo
2264     */
2265     public synchronized void
2266 iliev 1139 setMidiInputDeviceParameter(int deviceId, Parameter prm)
2267 iliev 596 throws IOException, LscpException, LSException {
2268    
2269     verifyConnection();
2270     String kv = prm.getName() + '=' + prm.getStringValue();
2271 iliev 1139 out.writeLine("SET MIDI_INPUT_DEVICE_PARAMETER " + deviceId + ' ' + kv);
2272     if(getPrintOnlyMode()) return;
2273 iliev 596
2274     ResultSet rs = getEmptyResultSet();
2275     }
2276    
2277 iliev 784
2278 iliev 596 /**
2279 iliev 1139 * Changes the port number of the speicified MIDI input device.
2280     * @param deviceId The numerical ID of the MIDI input device.
2281 iliev 784 * @param ports The new number of MIDI input ports.
2282     *
2283     * @throws IOException If an I/O error occurs.
2284     * @throws LscpException If LSCP protocol corruption occurs.
2285 iliev 1139 * @throws LSException If there is no device with ID <code>deviceId</code> or
2286 iliev 784 * if <code>ports</code> number is out of range.
2287     *
2288     * @see #getMidiInputPortInfo
2289     */
2290     public synchronized void
2291 iliev 1139 setMidiInputPortCount(int deviceId, int ports)
2292 iliev 784 throws IOException, LscpException, LSException {
2293    
2294 iliev 1139 setMidiInputDeviceParameter(deviceId, new IntParameter("PORTS", ports));
2295 iliev 784 }
2296    
2297     /**
2298 iliev 596 * Gets detailed information about a specific MIDI input port.
2299 iliev 1139 * @param deviceId The numerical ID of the MIDI input device.
2300 iliev 596 * @param midiPort The MIDI input port number.
2301     *
2302     * @return A <code>MidiPort</code> instance containing
2303     * information about the specified MIDI input port.
2304     *
2305     * @throws IOException If an I/O error occurs.
2306     * @throws LscpException If LSCP protocol corruption occurs.
2307 iliev 1139 * @throws LSException If there is no device with ID <code>deviceId</code> or
2308 iliev 596 * if <code>midiPort</code> is not a valid MIDI port number.
2309     *
2310     * @see #getMidiInputDevices
2311     */
2312     public synchronized MidiPort
2313 iliev 1139 getMidiInputPortInfo(int deviceId, int midiPort)
2314 iliev 596 throws IOException, LscpException, LSException {
2315    
2316     verifyConnection();
2317 iliev 1139 out.writeLine("GET MIDI_INPUT_PORT INFO " + deviceId + " " + midiPort);
2318     if(getPrintOnlyMode()) return null;
2319    
2320 iliev 596 ResultSet rs = getMultiLineResultSet();
2321    
2322     MidiPort mp = new MidiPort();
2323     String[] lnS = rs.getMultiLineResult();
2324    
2325     for(String s : lnS) {
2326     if(s.startsWith("NAME: ")) {
2327 iliev 784 s = s.substring("NAME: ".length());
2328     Parameter prm = getMidiInputPortParameterInfo (
2329 iliev 1139 deviceId, midiPort, "NAME"
2330 iliev 784 );
2331     prm.setValue(removeQuotation(s));
2332     mp.setNameParameter(prm);
2333 iliev 596 } else {
2334     int i = s.indexOf(": ");
2335     if(i == -1) throw new LscpException (
2336     LscpI18n.getLogMsg("CommandFailed!")
2337     );
2338    
2339     Parameter prm = getMidiInputPortParameterInfo (
2340 iliev 1139 deviceId, midiPort, s.substring(0, i)
2341 iliev 596 );
2342    
2343     s = s.substring(i + 2);
2344     prm.parseValue(s);
2345    
2346     mp.addParameter(prm);
2347     }
2348     }
2349    
2350     return mp;
2351     }
2352    
2353     /**
2354     * Gets detailed information about a specific MIDI input port parameter.
2355     *
2356 iliev 1139 * @param deviceId The numerical ID of the MIDI input device.
2357 iliev 596 * @param port The MIDI port number.
2358     * @param param A specific parameter name for which information should be obtained.
2359     *
2360     * @return A <code>Parameter</code> instance containing
2361     * information about the specified MIDI input port parameter.
2362     *
2363     * @throws IOException If an I/O error occurs.
2364     * @throws LscpException If LSCP protocol corruption occurs.
2365     * @throws LSException If
2366     * <ul>
2367 iliev 1139 * <li>There is no MIDI input device with numerical ID <code>deviceId</code>;
2368 iliev 596 * <li> <code>port</code> is not a valid MIDI port number;
2369     * <li><code>param</code> is not a valid parameter for the specified MIDI port.
2370     * </ul>
2371     *
2372     * @see #getMidiInputDevices
2373     * @see #getMidiInputPortInfo
2374     */
2375     public synchronized Parameter
2376 iliev 1139 getMidiInputPortParameterInfo(int deviceId, int port, String param)
2377 iliev 596 throws IOException, LscpException, LSException {
2378    
2379     verifyConnection();
2380 iliev 1139 String args = deviceId + " " + port + " " + param;
2381 iliev 596 out.writeLine("GET MIDI_INPUT_PORT_PARAMETER INFO " + args);
2382 iliev 1139 if(getPrintOnlyMode()) return null;
2383 iliev 596
2384     ResultSet rs = getMultiLineResultSet();
2385    
2386     String[] lnS = rs.getMultiLineResult();
2387     ParameterType type = parseType(lnS);
2388     boolean multi = parseMultiplicity(lnS);
2389     Parameter prm;
2390    
2391     switch(type) {
2392     case BOOL:
2393     if(!multi) prm = new BoolParameter(lnS);
2394     else prm = new BoolListParameter(lnS);
2395     prm.setName(param);
2396     return prm;
2397     case INT:
2398     if(!multi) prm = new IntParameter(lnS);
2399     else prm = new IntListParameter(lnS);
2400     prm.setName(param);
2401     return prm;
2402     case FLOAT:
2403     if(!multi) prm = new FloatParameter(lnS);
2404     else prm = new FloatListParameter(lnS);
2405     prm.setName(param);
2406     return prm;
2407     case STRING:
2408     if(!multi) prm = new StringParameter(lnS);
2409     else prm = new StringListParameter(lnS);
2410     prm.setName(param);
2411     return prm;
2412     default: throw new LscpException(LscpI18n.getLogMsg("Client.unknownPrmType!"));
2413     }
2414     }
2415    
2416     /**
2417     * Alters a specific setting of a MIDI input port.
2418     *
2419 iliev 1139 * @param deviceId The numerical ID of the MIDI device.
2420 iliev 596 * @param port The MIDI port number.
2421     * @param prm A <code>Parameter</code> instance containing the name of the parameter
2422     * and the new value for this parameter.
2423     *
2424     * @throws IOException If some I/O error occurs.
2425     * @throws LscpException If LSCP protocol corruption occurs.
2426     * @throws LSException If
2427     * <ul>
2428 iliev 1139 * <li>There is no MIDI device with numerical ID <code>deviceId</code>;
2429 iliev 596 * <li><code>port</code> is not a valid MIDI port number;
2430     * <li><code>prm</code> is not a valid parameter;
2431     * <li>The parameter is readonly;
2432     * <li>The parameter is from different type.
2433     * </ul>
2434     *
2435     * @see #getMidiInputDevices
2436     * @see #getMidiInputPortInfo
2437     */
2438     public synchronized void
2439 iliev 1139 setMidiInputPortParameter(int deviceId, int port, Parameter prm)
2440 iliev 596 throws IOException, LscpException, LSException {
2441    
2442     verifyConnection();
2443 iliev 1139 String args = deviceId + " " + port + " " +
2444 iliev 596 prm.getName() + '=' + prm.getStringValue();
2445     out.writeLine("SET MIDI_INPUT_PORT_PARAMETER " + args);
2446 iliev 1139 if(getPrintOnlyMode()) return;
2447 iliev 596
2448     ResultSet rs = getEmptyResultSet();
2449     }
2450    
2451     /**
2452 iliev 1139 * Adds a new MIDI instrument map.
2453     * @param name The name of this MIDI instrument map.
2454     * @return The number of the newly MIDI instrument map.
2455     * @throws IOException If some I/O error occurs.
2456     * @throws LSException If the creation of the new MIDI instrument map failed.
2457     * @throws LscpException If LSCP protocol corruption occurs.
2458     * @see #removeMidiInstrumentMap
2459     */
2460     public synchronized int
2461     addMidiInstrumentMap(String name) throws IOException, LSException, LscpException {
2462     verifyConnection();
2463 iliev 1393 out.writeLine("ADD MIDI_INSTRUMENT_MAP '" + toEscapedString(name) + "'");
2464 iliev 1139 if(getPrintOnlyMode()) return -1;
2465    
2466     ResultSet rs = getEmptyResultSet();
2467    
2468     return rs.getIndex();
2469     }
2470    
2471     /**
2472     * Removes the specified MIDI instrument map.
2473     * @param mapId The numerical ID of the MIDI instrument map to be removed.
2474     * @throws IOException If some I/O error occurs.
2475     * @throws LscpException If LSCP protocol corruption occurs.
2476     * @throws LSException If the removing of the MIDI instrument map failed.
2477     * @see #addMidiInstrumentMap
2478     * @see #getMidiInstrumentMapIDs
2479     */
2480     public synchronized void
2481     removeMidiInstrumentMap(int mapId) throws IOException, LscpException, LSException {
2482     verifyConnection();
2483     out.writeLine("REMOVE MIDI_INSTRUMENT_MAP " + mapId);
2484     if(getPrintOnlyMode()) return;
2485    
2486     ResultSet rs = getEmptyResultSet();
2487     }
2488    
2489     /**
2490     * Removes the all MIDI instrument maps.
2491     * @throws IOException If some I/O error occurs.
2492     * @throws LscpException If LSCP protocol corruption occurs.
2493     * @throws LSException If the removing of the MIDI instrument maps failed.
2494     */
2495     public synchronized void
2496     removeAllMidiInstrumentMaps() throws IOException, LscpException, LSException {
2497     verifyConnection();
2498     out.writeLine("REMOVE MIDI_INSTRUMENT_MAP ALL");
2499     if(getPrintOnlyMode()) return;
2500    
2501     ResultSet rs = getEmptyResultSet();
2502     }
2503    
2504     /**
2505     * Gets the current number of all MIDI instrument maps.
2506     * @return The current number of all MIDI instrument maps.
2507     * @throws IOException If some I/O error occurs.
2508     * @throws LscpException If LSCP protocol corruption occurs.
2509     * @throws LSException If some other error occurs.
2510     */
2511     public synchronized int
2512     getMidiInstrumentMapCount() throws IOException, LscpException, LSException {
2513     verifyConnection();
2514     out.writeLine("GET MIDI_INSTRUMENT_MAPS");
2515     if(getPrintOnlyMode()) return -1;
2516    
2517     String s = getSingleLineResultSet().getResult();
2518     return parseInt(s);
2519     }
2520    
2521     /**
2522     * Gets a list of numerical IDs of all created MIDI instrument maps.
2523     * @return An <code>Integer</code> array providing the numerical IDs of
2524     * all created MIDI instrument maps.
2525     * @throws IOException If some I/O error occurs.
2526     * @throws LscpException If LSCP protocol corruption occurs.
2527     * @throws LSException If some other error occurs.
2528     * @see #addMidiInstrumentMap
2529     * @see #removeMidiInstrumentMap
2530     */
2531     public synchronized Integer[]
2532     getMidiInstrumentMapIDs() throws IOException, LscpException, LSException {
2533     verifyConnection();
2534     out.writeLine("LIST MIDI_INSTRUMENT_MAPS");
2535     if(getPrintOnlyMode()) return null;
2536    
2537     return parseIntList(getSingleLineResultSet().getResult());
2538     }
2539    
2540     /**
2541     * Gets the current settings of a specific, already created MIDI instrument map.
2542     * @param mapId Specifies the numerical ID of the MIDI instrument map.
2543     * @return A <code>MidiInstrumentMapInfo</code> instance containing information
2544     * about the specified device.
2545     * @throws IOException If some I/O error occurs.
2546     * @throws LscpException If LSCP protocol corruption occurs.
2547     * @throws LSException If there is no MIDI instrument map
2548     * with map id <code>mapId</code>.
2549     * @see #getMidiInstrumentMaps
2550     */
2551     public synchronized MidiInstrumentMapInfo
2552     getMidiInstrumentMapInfo(int mapId) throws IOException, LscpException, LSException {
2553     verifyConnection();
2554     out.writeLine("GET MIDI_INSTRUMENT_MAP INFO " + mapId);
2555     if(getPrintOnlyMode()) return null;
2556    
2557     ResultSet rs = getMultiLineResultSet();
2558    
2559     String[] lnS = rs.getMultiLineResult();
2560    
2561     String name = "";
2562     boolean b = false;
2563    
2564     for(String s : lnS) {
2565     if(s.startsWith("NAME: ")) {
2566 iliev 1421 name = toNonEscapedString(s.substring("NAME: ".length()));
2567 iliev 1139 } else if(s.startsWith("DEFAULT: ")) {
2568     b = Boolean.parseBoolean(s.substring("DEFAULT: ".length()));
2569     } else {
2570     getLogger().info(LscpI18n.getLogMsg("unknownLine", s));
2571     }
2572     }
2573    
2574     return new MidiInstrumentMapInfo(mapId, name, b);
2575     }
2576    
2577     /**
2578     * Gets an information of all created MIDI instrument maps.
2579     * @return A <code>MidiInstrumentMap</code> array
2580     * providing information for all created MIDI instrument maps.
2581     * @throws IOException If some I/O error occurs.
2582     * @throws LscpException If LSCP protocol corruption occurs.
2583     * @throws LSException If some other error occurs.
2584     * @see #addMidiInstrumentMap
2585     * @see #removeMidiInstrumentMap
2586     */
2587     public synchronized MidiInstrumentMapInfo[]
2588     getMidiInstrumentMaps() throws IOException, LscpException, LSException {
2589     Integer[] idS = getMidiInstrumentMapIDs();
2590     if(getPrintOnlyMode()) return null;
2591    
2592     MidiInstrumentMapInfo[] maps = new MidiInstrumentMapInfo[idS.length];
2593    
2594     for(int i = 0; i < maps.length; i++)
2595     maps[i] = getMidiInstrumentMapInfo(idS[i]);
2596    
2597     return maps;
2598     }
2599    
2600     /**
2601     * Sets the name of the specified MIDI instrument map.
2602     * @param mapId The numerical ID of the MIDI instrument map.
2603     * @param name The new name for the specified MIDI instrument map.
2604     * @throws IOException If some I/O error occurs.
2605     * @throws LscpException If LSCP protocol corruption occurs.
2606     * @throws LSException If <code>mapId</code> is not a valid MIDI
2607     * instrument map number or <code>name</code> is not a valid name;
2608     */
2609     public synchronized void
2610     setMidiInstrumentMapName(int mapId, String name)
2611     throws IOException, LscpException, LSException {
2612    
2613     verifyConnection();
2614 iliev 1393 name = toEscapedString(name);
2615 iliev 1139 out.writeLine("SET MIDI_INSTRUMENT_MAP NAME " + + mapId + " '" + name + "'");
2616     if(getPrintOnlyMode()) return;
2617    
2618     ResultSet rs = getEmptyResultSet();
2619     }
2620    
2621 iliev 1202
2622    
2623 iliev 1139 /**
2624     * Creates or replaces a MIDI instrument map entry.
2625     * @param mapId The ID of the map, where this instrument should be mapped.
2626     * @param entry Specifies the position of the MIDI instrument in the MIDI instrument map.
2627     * @param info Provides the needed information of the
2628     * MIDI instrument, which will be mapped to the specified MIDI instrument map.
2629     * @throws IOException If some I/O error occurs.
2630     * @throws LSException If the mapping failed.
2631     * @throws LscpException If LSCP protocol corruption occurs.
2632     * @see #unmapMidiInstrument
2633     */
2634     public synchronized void
2635     mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)
2636     throws IOException, LSException, LscpException {
2637 iliev 1202 mapMidiInstrument(mapId, entry, info, false);
2638     }
2639    
2640     /**
2641     * Creates or replaces a MIDI instrument map entry.
2642     * @param mapId The ID of the map, where this instrument should be mapped.
2643     * @param entry Specifies the position of the MIDI instrument in the MIDI instrument map.
2644     * @param info Provides the needed information of the
2645     * MIDI instrument, which will be mapped to the specified MIDI instrument map.
2646     * @param nonModal If <code>true</code> the function returns immediately
2647     * and the mapping is established in the background.
2648     * @throws IOException If some I/O error occurs.
2649     * @throws LSException If the mapping failed.
2650     * @throws LscpException If LSCP protocol corruption occurs.
2651     * @see #unmapMidiInstrument
2652     */
2653     public synchronized void
2654     mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info, boolean nonModal)
2655     throws IOException, LSException, LscpException {
2656 iliev 1139
2657     verifyConnection();
2658     StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");
2659 iliev 1202 if(nonModal) cmd.append("NON_MODAL ");
2660 iliev 1139 cmd.append(mapId).append(' ');
2661     cmd.append(entry.getMidiBank()).append(' ');
2662     cmd.append(entry.getMidiProgram()).append(' ');
2663     cmd.append(info.getEngine()).append(" '");
2664 iliev 1202 cmd.append(info.getFilePath()).append("' ");
2665 iliev 1139 cmd.append(info.getInstrumentIndex()).append(' ');
2666     cmd.append(info.getVolume());
2667     if(!info.getLoadMode().name().equals("DEFAULT")) {
2668     cmd.append(' ').append(info.getLoadMode().name());
2669     }
2670    
2671 iliev 1393 if(info.getName() != null) {
2672     String s = toEscapedString(info.getName());
2673     cmd.append(" '").append(s).append("'");
2674     }
2675    
2676 iliev 1139 out.writeLine(cmd.toString());
2677     if(getPrintOnlyMode()) return;
2678    
2679     ResultSet rs = getEmptyResultSet();
2680     }
2681    
2682     /**
2683     * Removes an entry MIDI instrument map.
2684     * @param mapId The ID of the map, from which
2685     * the specified MIDI instrument should be removed.
2686     * @param entry The entry to remove from the specified MIDI instrument map.
2687     * @throws IOException If some I/O error occurs.
2688     * @throws LSException If the unmapping failed.
2689     * @throws LscpException If LSCP protocol corruption occurs.
2690     * @see #mapMidiInstrument
2691     */
2692     public synchronized void
2693     unmapMidiInstrument(int mapId, MidiInstrumentEntry entry)
2694     throws IOException, LSException, LscpException {
2695    
2696     verifyConnection();
2697     StringBuffer cmd = new StringBuffer("UNMAP MIDI_INSTRUMENT ");
2698     cmd.append(mapId).append(' ');
2699     cmd.append(entry.getMidiBank()).append(' ');
2700     cmd.append(entry.getMidiProgram());
2701    
2702     out.writeLine(cmd.toString());
2703     if(getPrintOnlyMode()) return;
2704    
2705     ResultSet rs = getEmptyResultSet();
2706     }
2707    
2708     /**
2709     * Gets the current number of all MIDI instrument in all maps.
2710     * @return The current number of all MIDI instrument in all maps.
2711     * @throws IOException If some I/O error occurs.
2712     * @throws LscpException If LSCP protocol corruption occurs.
2713     * @throws LSException If some other error occurs.
2714     */
2715     public synchronized int
2716     getMidiInstrumentCount() throws IOException, LscpException, LSException {
2717     verifyConnection();
2718     out.writeLine("GET MIDI_INSTRUMENTS ALL");
2719     if(getPrintOnlyMode()) return -1;
2720    
2721     String s = getSingleLineResultSet().getResult();
2722     return parseInt(s);
2723     }
2724    
2725     /**
2726     * Gets the current number of MIDI instrument in the specified map.
2727     * @param mapId The ID of the map.
2728     * @return The current number of MIDI instrument in the specified map.
2729     * @throws IOException If some I/O error occurs.
2730     * @throws LscpException If LSCP protocol corruption occurs.
2731     * @throws LSException If some other error occurs.
2732     */
2733     public synchronized int
2734     getMidiInstrumentCount(int mapId) throws IOException, LscpException, LSException {
2735     verifyConnection();
2736     out.writeLine("GET MIDI_INSTRUMENTS " + String.valueOf(mapId));
2737     if(getPrintOnlyMode()) return -1;
2738    
2739     String s = getSingleLineResultSet().getResult();
2740     return parseInt(s);
2741     }
2742    
2743     /**
2744     * Gets all MIDI instrument from all maps.
2745     * @return A <code>MidiInstrumentInfo</code> array providing
2746     * all MIDI instruments from all MIDI instrument maps.
2747     * @throws IOException If some I/O error occurs.
2748     * @throws LscpException If LSCP protocol corruption occurs.
2749     * @throws LSException If some other error occurs.
2750     */
2751     public synchronized MidiInstrumentInfo[]
2752     getMidiInstruments() throws IOException, LscpException, LSException {
2753     verifyConnection();
2754     out.writeLine("LIST MIDI_INSTRUMENTS ALL");
2755     if(getPrintOnlyMode()) return null;
2756    
2757     String[] entries = parseArray(getSingleLineResultSet().getResult());
2758    
2759     return getMidiInstruments(entries);
2760     }
2761    
2762     /**
2763     * Gets all MIDI instrument contained int the specified MIDI instrument map.
2764     * @param mapId The ID of the map, which instruments should be obtained.
2765     * @return A <code>MidiInstrumentInfo</code> array providing
2766     * all MIDI instruments from all MIDI instrument maps.
2767     * @throws IOException If some I/O error occurs.
2768     * @throws LscpException If LSCP protocol corruption occurs.
2769     * @throws LSException If some other error occurs.
2770     */
2771     public synchronized MidiInstrumentInfo[]
2772     getMidiInstruments(int mapId) throws IOException, LscpException, LSException {
2773     verifyConnection();
2774     out.writeLine("LIST MIDI_INSTRUMENTS " + String.valueOf(mapId));
2775     if(getPrintOnlyMode()) return null;
2776    
2777     String[] entries = parseArray(getSingleLineResultSet().getResult());
2778    
2779     return getMidiInstruments(entries);
2780     }
2781    
2782     private MidiInstrumentInfo[]
2783     getMidiInstruments(String[] entries) throws IOException, LscpException, LSException {
2784     Vector<MidiInstrumentInfo> v = new Vector<MidiInstrumentInfo>();
2785    
2786     for(String s : entries) {
2787     Integer[] vals = parseIntList(s);
2788     if(vals.length != 3) {
2789     throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
2790     }
2791    
2792     v.add(getMidiInstrumentInfo(vals[0], vals[1], vals[2]));
2793     }
2794    
2795     return v.toArray(new MidiInstrumentInfo[v.size()]);
2796     }
2797    
2798     /**
2799     * Gets the current settings of the specified MIDI instrument.
2800     * @param mapId The ID of the map.
2801     * @param bank The index of the MIDI bank.
2802     * @param program The MIDI program number of the instrument.
2803     * @return <code>MidiInstrumentInfo</code> instance containing
2804     * the current settings of the specified MIDI instrument.
2805     * @throws IOException If an I/O error occurs.
2806     * @throws LscpException If LSCP protocol corruption occurs.
2807     * @throws LSException If the specified MIDI instrument is missing.
2808     */
2809     public synchronized MidiInstrumentInfo
2810     getMidiInstrumentInfo(int mapId, int bank, int program)
2811     throws IOException, LscpException, LSException {
2812    
2813     verifyConnection();
2814     StringBuffer cmd = new StringBuffer("GET MIDI_INSTRUMENT INFO ");
2815     cmd.append(mapId).append(' ');
2816     cmd.append(bank).append(' ');
2817     cmd.append(program);
2818    
2819     out.writeLine(cmd.toString());
2820     if(getPrintOnlyMode()) return null;
2821    
2822     ResultSet rs = getMultiLineResultSet();
2823     MidiInstrumentEntry entry = new MidiInstrumentEntry(bank, program);
2824     return new MidiInstrumentInfo(mapId, entry, rs.getMultiLineResult());
2825     }
2826    
2827     /**
2828 iliev 596 * Loads and assigns an instrument to a sampler channel. Notice that this function will
2829     * return after the instrument is fully loaded and the channel is ready to be used.
2830     * @param filename The name of the instrument file
2831     * on the LinuxSampler instance's host system.
2832     * @param instrIdx The index of the instrument in the instrument file.
2833     * @param samplerChn The number of the sampler channel the instrument should be assigned to.
2834     * @throws IOException If some I/O error occurs.
2835     * @throws LscpException If LSCP protocol corruption occurs.
2836     * @throws LSException If the loading of the instrument failed.
2837     * @see #loadInstrument(String, int, int, boolean)
2838     * @see #getSamplerChannels
2839     */
2840     public synchronized void
2841     loadInstrument(String filename, int instrIdx, int samplerChn)
2842     throws IOException, LscpException, LSException {
2843    
2844     verifyConnection();
2845     loadInstrument(filename, instrIdx, samplerChn, false);
2846     }
2847    
2848     /**
2849     * Loads and assigns an instrument to a sampler channel.
2850     *
2851     * @param filename The name of the instrument file
2852     * on the LinuxSampler instance's host system.
2853     * @param instrIdx The index of the instrument in the instrument file.
2854     * @param samplerChn The number of the sampler channel the instrument should be assigned to.
2855     * @param nonModal If <code>false</code> the function will return after the instrument
2856     * has been fully loaded and the channel is ready to be used. If <code>true</code>
2857     * the function returns immediately.
2858     *
2859     * @throws IOException If some I/O error occurs.
2860     * @throws LscpException If LSCP protocol corruption occurs.
2861     * @throws LSException If the loading of the instrument failed.
2862     *
2863     * @see #loadInstrument(String, int, int)
2864     * @see #getSamplerChannels
2865     */
2866     public synchronized void
2867     loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal)
2868     throws IOException, LscpException, LSException {
2869    
2870     String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";
2871     String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;
2872    
2873     out.writeLine(cmd + args);
2874 iliev 1139 if(getPrintOnlyMode()) return;
2875 iliev 596
2876     ResultSet rs = getEmptyResultSet();
2877     }
2878    
2879     /**
2880     * Loads a sampler engine to a specific sampler channel.
2881     * @param engineName The name of the engine.
2882     * @param samplerChn The number of the sampler channel
2883     * the deployed engine should be assigned to.
2884     *
2885     * @throws IOException If some I/O error occurs.
2886     * @throws LscpException If LSCP protocol corruption occurs.
2887     * @throws LSException If the loading of the sampler engine failed.
2888     * @see #getEngines
2889     * @see #getSamplerChannels
2890     */
2891     public synchronized void
2892     loadSamplerEngine(String engineName, int samplerChn)
2893     throws IOException, LscpException, LSException {
2894    
2895     verifyConnection();
2896     out.writeLine("LOAD ENGINE " + engineName + ' ' + samplerChn);
2897 iliev 1139 if(getPrintOnlyMode()) return;
2898 iliev 596
2899     ResultSet rs = getEmptyResultSet();
2900     }
2901    
2902     /**
2903     * Gets the current number of all created sampler channels.
2904     * @return The current number of all created sampler channels.
2905     * @throws IOException If some I/O error occurs.
2906     * @throws LscpException If LSCP protocol corruption occurs.
2907     * @throws LSException If some other error occurs.
2908     */
2909     public synchronized int
2910     getSamplerChannelCount() throws IOException, LscpException, LSException {
2911     verifyConnection();
2912     out.writeLine("GET CHANNELS");
2913 iliev 1139 if(getPrintOnlyMode()) return -1;
2914    
2915 iliev 596 String s = getSingleLineResultSet().getResult();
2916     return parseInt(s);
2917     }
2918    
2919     /**
2920 iliev 784 * Gets a list of all created sampler channels.
2921     * @return A <code>SamplerChannel</code> array providing all created sampler channels.
2922     * @throws IOException If some I/O error occurs.
2923     * @throws LscpException If LSCP protocol corruption occurs.
2924     * @throws LSException If some other error occurs.
2925     * @see #addSamplerChannel
2926     * @see #removeSamplerChannel
2927     */
2928     public synchronized SamplerChannel[]
2929     getSamplerChannels() throws IOException, LscpException, LSException {
2930     Integer[] idS = getSamplerChannelIDs();
2931 iliev 1139 if(getPrintOnlyMode()) return null;
2932    
2933 iliev 784 SamplerChannel[] channels = new SamplerChannel[idS.length];
2934    
2935     for(int i = 0; i < channels.length; i++)
2936     channels[i] = getSamplerChannelInfo(idS[i]);
2937    
2938     return channels;
2939     }
2940    
2941     /**
2942 iliev 596 * Gets a list with numerical IDs of all created sampler channels.
2943 iliev 784 * @return An <code>Integer</code> array providing
2944     * the numerical IDs of all created sampler channels.
2945 iliev 596 * @throws IOException If some I/O error occurs.
2946     * @throws LscpException If LSCP protocol corruption occurs.
2947     * @throws LSException If some other error occurs.
2948     * @see #addSamplerChannel
2949     * @see #removeSamplerChannel
2950     */
2951     public synchronized Integer[]
2952 iliev 784 getSamplerChannelIDs() throws IOException, LscpException, LSException {
2953 iliev 596 verifyConnection();
2954     out.writeLine("LIST CHANNELS");
2955 iliev 1139 if(getPrintOnlyMode()) return null;
2956    
2957 iliev 596 return parseIntList(getSingleLineResultSet().getResult());
2958     }
2959    
2960     /**
2961     * Adds a new sampler channel. This method will increment the sampler channel count by one
2962     * and the new sampler channel will be appended to the end of the sampler channel list.
2963     *
2964     * @return The number of the newly created sampler channel.
2965     * @throws IOException If some I/O error occurs.
2966     * @throws LSException If the creation of the new sampler channel failed.
2967     * @throws LscpException If LSCP protocol corruption occurs.
2968     * @see #removeSamplerChannel
2969     */
2970     public synchronized int
2971     addSamplerChannel() throws IOException, LSException, LscpException {
2972     verifyConnection();
2973     out.writeLine("ADD CHANNEL");
2974 iliev 1139 if(getPrintOnlyMode()) return -1;
2975    
2976 iliev 596 ResultSet rs = getEmptyResultSet();
2977    
2978     return rs.getIndex();
2979     }
2980    
2981     /**
2982     * Removes the specified sampler channel.
2983     *
2984     * @param samplerChn The numerical ID of the sampler channel to be removed.
2985     *
2986     * @throws IOException If some I/O error occurs.
2987     * @throws LscpException If LSCP protocol corruption occurs.
2988     * @throws LSException If the removing of the sampler channel failed.
2989     * @see #addSamplerChannel
2990     * @see #getSamplerChannels
2991     */
2992     public synchronized void
2993     removeSamplerChannel(int samplerChn) throws IOException, LscpException, LSException {
2994     verifyConnection();
2995     out.writeLine("REMOVE CHANNEL " + samplerChn);
2996 iliev 1139 if(getPrintOnlyMode()) return;
2997 iliev 596
2998     ResultSet rs = getEmptyResultSet();
2999     }
3000    
3001     /**
3002     * Gets the number of all available engines.
3003     * @return The number of all available engines.
3004     * @throws IOException If some I/O error occurs.
3005     * @throws LscpException If LSCP protocol corruption occurs.
3006     * @throws LSException If some other error occurs.
3007     */
3008     public synchronized int
3009     getEngineCount() throws IOException, LscpException, LSException {
3010     verifyConnection();
3011     out.writeLine("GET AVAILABLE_ENGINES");
3012 iliev 1139 if(getPrintOnlyMode()) return -1;
3013    
3014 iliev 596 String s = getSingleLineResultSet().getResult();
3015     return parseInt(s);
3016     }
3017    
3018     /**
3019 iliev 671 * Gets a list of all available engines.
3020     *
3021     * @return <code>SamplerEngine</code> array containing all available engines.
3022     * @throws IOException If some I/O error occurs.
3023     * @throws LscpException If LSCP protocol corruption occurs.
3024     * @throws LSException If some other error occurs.
3025     */
3026     public synchronized SamplerEngine[]
3027     getEngines() throws IOException, LscpException, LSException {
3028     String[] engines = getEngineNames();
3029 iliev 1139 if(getPrintOnlyMode()) return null;
3030    
3031 iliev 671 SamplerEngine[] se = new SamplerEngine[engines.length];
3032    
3033     for(int i = 0; i < engines.length; i++) se[i] = getEngineInfo(engines[i]);
3034    
3035     return se;
3036     }
3037    
3038     /**
3039 iliev 596 * Gets a list of all available engines' names.
3040     *
3041     * @return <code>String</code> array with all available engines' names.
3042     * @throws IOException If some I/O error occurs.
3043     * @throws LscpException If LSCP protocol corruption occurs.
3044     * @throws LSException If some other error occurs.
3045     */
3046 iliev 671 private synchronized String[]
3047     getEngineNames() throws IOException, LscpException, LSException {
3048 iliev 596 verifyConnection();
3049     out.writeLine("LIST AVAILABLE_ENGINES");
3050 iliev 1139 if(getPrintOnlyMode()) return null;
3051    
3052 iliev 1393 return parseStringList(getSingleLineResultSet().getResult());
3053 iliev 596 }
3054    
3055     /**
3056     * Gets information about a specific sampler engine.
3057     * @param engineName The name of the sampler engine.
3058     *
3059     * @return <code>SamplerEngine</code> instance containing
3060     * information about the specified sampler engine.
3061     *
3062     * @throws IOException If an I/O error occurs.
3063     * @throws LscpException If LSCP protocol corruption occurs.
3064     * @throws LSException If there is no sampler engine with name <code>engineName</code>.
3065 iliev 671 * @see #getEngineNames
3066 iliev 596 */
3067 iliev 671 private synchronized SamplerEngine
3068 iliev 596 getEngineInfo(String engineName) throws IOException, LscpException, LSException {
3069     verifyConnection();
3070     out.writeLine("GET ENGINE INFO " + engineName);
3071 iliev 1139 if(getPrintOnlyMode()) return null;
3072    
3073 iliev 596 ResultSet rs = getMultiLineResultSet();
3074     SamplerEngine se = new SamplerEngine(rs.getMultiLineResult());
3075     se.setName(engineName);
3076     return se;
3077     }
3078    
3079     /**
3080     * Gets the current settings of the specified sampler channel.
3081     * @param samplerChn The sampler channel number.
3082     *
3083     * @return <code>SamplerChannel</code> instance containing
3084     * the current settings of the specified sampler channel.
3085     *
3086     * @throws IOException If an I/O error occurs.
3087     * @throws LscpException If LSCP protocol corruption occurs.
3088     * @throws LSException If there is no sampler channel with <code>samplerChn</code> number.
3089     * @see #getSamplerChannels
3090     */
3091     public synchronized SamplerChannel
3092     getSamplerChannelInfo(int samplerChn) throws IOException, LscpException, LSException {
3093     verifyConnection();
3094     out.writeLine("GET CHANNEL INFO " + samplerChn);
3095 iliev 1139 if(getPrintOnlyMode()) return null;
3096    
3097 iliev 596 ResultSet rs = getMultiLineResultSet();
3098     SamplerChannel sc = new SamplerChannel(rs.getMultiLineResult());
3099 iliev 1139 sc.setChannelId(samplerChn);
3100 iliev 784 if(sc.getEngine() != null) sc.setEngine(getEngineInfo(sc.getEngine().getName()));
3101 iliev 596
3102     return sc;
3103     }
3104    
3105     /**
3106     * Gets the current number of active voices on the specified sampler channel.
3107     *
3108     * @param samplerChn The sampler channel number.
3109     * @return The current number of active voices on the specified sampler channel.
3110     * @throws IOException If some I/O error occurs.
3111     * @throws LscpException If LSCP protocol corruption occurs.
3112     * @throws LSException If there is no sampler channel with number <code>samplerChn</code>.
3113     * @see #getSamplerChannels
3114     */
3115     public synchronized int
3116     getChannelVoiceCount(int samplerChn) throws IOException, LscpException, LSException {
3117     verifyConnection();
3118     out.writeLine("GET CHANNEL VOICE_COUNT " + samplerChn);
3119 iliev 1139 if(getPrintOnlyMode()) return -1;
3120    
3121 iliev 596 ResultSet rs = getSingleLineResultSet();
3122    
3123     return parseInt(rs.getResult());
3124     }
3125    
3126     /**
3127     * Gets the current number of active disk streams on the specified sampler channel.
3128     *
3129     * @param samplerChn The sampler channel number.
3130     * @return The current number of active disk streams on the specified sampler channel
3131     * or -1 if the engine doesn't support disk streaming.
3132     * @throws IOException If some I/O error occurs.
3133     * @throws LscpException If LSCP protocol corruption occurs.
3134     * @throws LSException If there is no sampler channel with number <code>samplerChn</code>.
3135     * @see #getSamplerChannels
3136     */
3137     public synchronized int
3138     getChannelStreamCount(int samplerChn) throws IOException, LscpException, LSException {
3139     verifyConnection();
3140     out.writeLine("GET CHANNEL STREAM_COUNT " + samplerChn);
3141 iliev 1139 if(getPrintOnlyMode()) return -1;
3142    
3143 iliev 596 ResultSet rs = getSingleLineResultSet();
3144    
3145     if(rs.getResult().equals("NA")) return -1;
3146    
3147     return parseInt(rs.getResult());
3148     }
3149    
3150     /**
3151     * Gets the current fill state of all disk streams on the specified sampler channel
3152     * in bytes.
3153     *
3154     * @param samplerChn The sampler channel number.
3155     * @return The current fill state of all disk streams on the specified sampler channel
3156     * or <code>null</code> if the engine which is deployed doesn't support disk streaming.
3157     * @throws IOException If some I/O error occurs.
3158     * @throws LscpException If LSCP protocol corruption occurs.
3159     * @throws LSException If there is no sampler channel with number <code>samplerChn</code>.
3160     * @see #getChannelBufferFillPercentage
3161     * @see #getSamplerChannels
3162     */
3163     public synchronized Vector<BufferFill>
3164     getChannelBufferFillBytes(int samplerChn) throws IOException, LscpException, LSException {
3165     verifyConnection();
3166     out.writeLine("GET CHANNEL BUFFER_FILL BYTES " + samplerChn);
3167 iliev 1139 if(getPrintOnlyMode()) return null;
3168    
3169 iliev 596 ResultSet rs = getSingleLineResultSet();
3170    
3171     if(rs.getResult().equals("NA")) return null;
3172    
3173     Vector<BufferFill> v = new Vector<BufferFill>();
3174     String[] args = parseList(rs.getResult());
3175    
3176     for(String s : args) {
3177     if(s.charAt(0) != '[')
3178     throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
3179    
3180     int i = s.indexOf(']');
3181     if(i == -1) throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
3182    
3183     BufferFill bf = new BufferFill();
3184 iliev 1139 bf.setStreamId(parseInt(s.substring(1, i)));
3185 iliev 596 bf.setValue(parseInt(s.substring(i + 1)));
3186     v.add(bf);
3187     }
3188    
3189     return v;
3190     }
3191    
3192     /**
3193     * Gets the current fill state of all disk streams on the specified sampler channel
3194     * in percent.
3195     *
3196     * @param samplerChn The sampler channel number.
3197     * @return The current fill state of all disk streams on the specified sampler channel
3198     * or <code>null</code> if the engine which is deployed doesn't support disk streaming.
3199     * @throws IOException If some I/O error occurs.
3200     * @throws LscpException If LSCP protocol corruption occurs.
3201     * @throws LSException If there is no sampler channel with number <code>samplerChn</code>.
3202     * @see #getChannelBufferFillBytes
3203     * @see #getSamplerChannels
3204     */
3205     public synchronized Vector<BufferFill>
3206     getChannelBufferFillPercentage(int samplerChn)
3207     throws IOException, LscpException, LSException {
3208    
3209     verifyConnection();
3210     out.writeLine("GET CHANNEL BUFFER_FILL PERCENTAGE " + samplerChn);
3211 iliev 1139 if(getPrintOnlyMode()) return null;
3212    
3213 iliev 596 ResultSet rs = getSingleLineResultSet();
3214    
3215     return getChannelBufferFillPercentage(rs.getResult());
3216     }
3217    
3218     private Vector<BufferFill>
3219     getChannelBufferFillPercentage(String ln) throws LscpException {
3220     if(ln.equals("NA")) return null;
3221    
3222     Vector<BufferFill> v = new Vector<BufferFill>();
3223     String[] args = parseList(ln);
3224    
3225     for(String s : args) {
3226     if(s.charAt(0) != '[')
3227     throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
3228    
3229     int i = s.indexOf(']');
3230     if(i == -1) throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
3231    
3232     if(s.charAt(s.length() - 1) != '%')
3233     throw new LscpException(LscpI18n.getLogMsg("CommandFailed!"));
3234    
3235     BufferFill bf = new BufferFill();
3236 iliev 1139 bf.setStreamId(parseInt(s.substring(1, i)));
3237 iliev 596 bf.setValue(parseInt(s.substring(i + 1, s.length() - 1)));
3238     v.add(bf);
3239     }
3240    
3241     return v;
3242     }
3243    
3244     /**
3245     * Sets the audio output device on the specified sampler channel.
3246     *
3247     * @param samplerChn The sampler channel number.
3248 iliev 1139 * @param devId The numerical ID of the audio output device.
3249 iliev 596 *
3250     * @throws IOException If some I/O error occurs.
3251     * @throws LscpException If LSCP protocol corruption occurs.
3252     * @throws LSException If
3253     * <ul>
3254     * <li><code>samplerChn</code> is not a valid channel number;
3255 iliev 1139 * <li><code>devId</code> is not a valid audio output device ID;
3256 iliev 596 * </ul>
3257     *
3258     * @see #getSamplerChannels
3259     * @see #getAudioOutputDevices
3260     */
3261     public synchronized void
3262 iliev 1139 setChannelAudioOutputDevice(int samplerChn, int devId)
3263 iliev 596 throws IOException, LscpException, LSException {
3264    
3265     verifyConnection();
3266 iliev 1139 out.writeLine("SET CHANNEL AUDIO_OUTPUT_DEVICE " + samplerChn + ' ' + devId);
3267     if(getPrintOnlyMode()) return;
3268 iliev 596
3269     ResultSet rs = getEmptyResultSet();
3270     }
3271    
3272     /**
3273     * Sets the audio output channel on the specified sampler channel.
3274     *
3275     * @param samplerChn The sampler channel number.
3276     * @param audioOut The sampler channel's audio output channel which should be rerouted.
3277     * @param audioIn The audio channel of the selected audio output device
3278     * where <code>audioOut</code> should be routed to.
3279     *
3280     * @throws IOException If some I/O error occurs.
3281     * @throws LscpException If LSCP protocol corruption occurs.
3282     * @throws LSException If
3283     * <ul>
3284     * <li><code>samplerChn</code> is not a valid channel number;
3285     * <li>There is no engine assigned yet to the specified sampler channel.
3286     * <li> There is no audio output device connected to the specified sampler channel.
3287     * </ul>
3288     *
3289     * @see #getSamplerChannels
3290     */
3291     public synchronized void
3292     setChannelAudioOutputChannel(int samplerChn, int audioOut, int audioIn)
3293     throws IOException, LscpException, LSException {
3294    
3295     verifyConnection();
3296     String args = " " + samplerChn + ' ' + audioOut + ' ' + audioIn;
3297     out.writeLine("SET CHANNEL AUDIO_OUTPUT_CHANNEL" + args);
3298 iliev 1139 if(getPrintOnlyMode()) return;
3299 iliev 596
3300     ResultSet rs = getEmptyResultSet();
3301     }
3302    
3303     /**
3304     * Sets the MIDI input device on the specified sampler channel.
3305     *
3306     * @param samplerChn The sampler channel number.
3307 iliev 1139 * @param devId The numerical ID of the MIDI input device.
3308 iliev 596 *
3309     * @throws IOException If some I/O error occurs.
3310     * @throws LscpException If LSCP protocol corruption occurs.
3311     * @throws LSException If
3312     * <ul>
3313     * <li><code>samplerChn</code> is not a valid channel number;
3314 iliev 1139 * <li><code>devId</code> is not a valid MIDI input device ID;
3315 iliev 596 * </ul>
3316     *
3317     * @see #getSamplerChannels
3318     * @see #getMidiInputDevices
3319     */
3320     public synchronized void
3321 iliev 1139 setChannelMidiInputDevice(int samplerChn, int devId)
3322 iliev 596 throws IOException, LscpException, LSException {
3323    
3324     verifyConnection();
3325 iliev 1139 out.writeLine("SET CHANNEL MIDI_INPUT_DEVICE " + samplerChn + ' ' + devId);
3326     if(getPrintOnlyMode()) return;
3327 iliev 596
3328     ResultSet rs = getEmptyResultSet();
3329     }
3330    
3331     /**
3332     * Sets the MIDI input port on the specified sampler channel.
3333     *
3334     * @param samplerChn The sampler channel number.
3335     * @param port The MIDI input port number of
3336     * the MIDI input device connected to the specified sampler channel.
3337     *
3338     * @throws IOException If some I/O error occurs.
3339     * @throws LscpException If LSCP protocol corruption occurs.
3340     * @throws LSException If <code>samplerChn</code> is not a valid channel number.
3341     * @see #getSamplerChannels
3342     */
3343     public synchronized void
3344     setChannelMidiInputPort(int samplerChn, int port)
3345     throws IOException, LscpException, LSException {
3346    
3347     verifyConnection();
3348     out.writeLine("SET CHANNEL MIDI_INPUT_PORT " + samplerChn + ' ' + port);
3349 iliev 1139 if(getPrintOnlyMode()) return;
3350 iliev 596
3351     ResultSet rs = getEmptyResultSet();
3352     }
3353    
3354     /**
3355     * Sets the MIDI input channel the specified sampler channel should listen to.
3356     *
3357     * @param samplerChn The sampler channel number.
3358     * @param midiChn The number of the new MIDI input channel where
3359     * <code>samplerChn</code> should listen to or -1 to listen on all 16 MIDI channels.
3360     *
3361     * @throws IOException If some I/O error occurs.
3362     * @throws LscpException If LSCP protocol corruption occurs.
3363     * @throws LSException If <code>samplerChn</code> is not a valid channel number.
3364     * @see #getSamplerChannels
3365     */
3366     public synchronized void
3367     setChannelMidiInputChannel(int samplerChn, int midiChn)
3368     throws IOException, LscpException, LSException {
3369    
3370     verifyConnection();
3371     String args = String.valueOf(samplerChn) + ' ';
3372     args += (midiChn == -1 ? "ALL" : String.valueOf(midiChn));
3373     out.writeLine("SET CHANNEL MIDI_INPUT_CHANNEL " + args);
3374 iliev 1139 if(getPrintOnlyMode()) return;
3375 iliev 596
3376     ResultSet rs = getEmptyResultSet();
3377     }
3378    
3379     /**
3380 iliev 1139 * Sets the MIDI instrument map to be used on the specified sampler channel.
3381     *
3382     * @param samplerChn The sampler channel number.
3383     * @param mapId Specifies the numerical ID of the MIDI instrument
3384     * map to assign. To remove the current map binding use <code>-1</code>.
3385     * To set the current map to be the default map use <code>-2</code>.
3386     *
3387     * @throws IOException If some I/O error occurs.
3388     * @throws LscpException If LSCP protocol corruption occurs.
3389     * @throws LSException If
3390     * <ul>
3391     * <li><code>samplerChn</code> is not a valid channel number;
3392     * <li><code>mapId</code> is not a valid MIDI instrument map ID;
3393     * </ul>
3394     *
3395     * @see #getSamplerChannels
3396     * @see #getMidiInstrumentMaps
3397     */
3398     public synchronized void
3399     setChannelMidiInstrumentMap(int samplerChn, int mapId)
3400     throws IOException, LscpException, LSException {
3401    
3402     verifyConnection();
3403     String s;
3404     if(mapId == -1) {
3405     s = " NONE";
3406     } else if(mapId == -2) {
3407     s = " DEFAULT";
3408     } else {
3409     s = " " + String.valueOf(mapId);
3410     }
3411     out.writeLine("SET CHANNEL MIDI_INSTRUMENT_MAP " + samplerChn + s);
3412     if(getPrintOnlyMode()) return;
3413    
3414     ResultSet rs = getEmptyResultSet();
3415     }
3416    
3417     /**
3418 iliev 596 * Sets the volume of the specified sampler channel.
3419     *
3420     * @param samplerChn The sampler channel number.
3421     * @param volume The new volume value.
3422     *
3423     * @throws IOException If some I/O error occurs.
3424     * @throws LscpException If LSCP protocol corruption occurs.
3425     * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3426     * there is no engine assigned yet to the specified sampler channel.
3427     * @see #getSamplerChannels
3428     */
3429     public synchronized void
3430     setChannelVolume(int samplerChn, float volume)
3431     throws IOException, LscpException, LSException {
3432    
3433     verifyConnection();
3434     out.writeLine("SET CHANNEL VOLUME " + samplerChn + ' ' + volume);
3435 iliev 1139 if(getPrintOnlyMode()) return;
3436 iliev 596
3437     ResultSet rs = getEmptyResultSet();
3438     }
3439    
3440     /**
3441 iliev 784 * Mute/unmute the specified sampler channel.
3442     *
3443     * @param samplerChn The sampler channel number.
3444     * @param mute If <code>true</code> the specified channel is muted, else the channel
3445     * is unmuted.
3446     *
3447     * @throws IOException If some I/O error occurs.
3448     * @throws LscpException If LSCP protocol corruption occurs.
3449     * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3450     * there is no engine assigned yet to the specified sampler channel.
3451     * @see #getSamplerChannels
3452     */
3453     public synchronized void
3454     setChannelMute(int samplerChn, boolean mute)
3455     throws IOException, LscpException, LSException {
3456    
3457     verifyConnection();
3458     out.writeLine("SET CHANNEL MUTE " + samplerChn + ' ' + (mute ? 1 : 0));
3459 iliev 1139 if(getPrintOnlyMode()) return;
3460 iliev 784
3461     ResultSet rs = getEmptyResultSet();
3462     }
3463    
3464     /**
3465     * Solo/unsolo the specified sampler channel.
3466     *
3467     * @param samplerChn The sampler channel number.
3468     * @param solo <code>true</code> to solo the specified channel, <code>false</code>
3469     * otherwise.
3470     *
3471     * @throws IOException If some I/O error occurs.
3472     * @throws LscpException If LSCP protocol corruption occurs.
3473     * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3474     * there is no engine assigned yet to the specified sampler channel.
3475     * @see #getSamplerChannels
3476     */
3477     public synchronized void
3478     setChannelSolo(int samplerChn, boolean solo)
3479     throws IOException, LscpException, LSException {
3480    
3481     verifyConnection();
3482     out.writeLine("SET CHANNEL SOLO " + samplerChn + ' ' + (solo ? 1 : 0));
3483 iliev 1139 if(getPrintOnlyMode()) return;
3484 iliev 784
3485     ResultSet rs = getEmptyResultSet();
3486     }
3487    
3488     /**
3489 iliev 1139 * Creates an additional effect send on the specified sampler channel.
3490     * @param channel The sampler channel, on which a new effect send should be added.
3491     * @param midiCtrl Defines the MIDI controller, which
3492     * will be able alter the effect send level.
3493     * @return The unique ID of the newly created effect send entity.
3494     * @throws IOException If some I/O error occurs.
3495     * @throws LSException If the creation of the effect send failed.
3496     * @throws LscpException If LSCP protocol corruption occurs.
3497     * @see #destroyFxSend
3498     */
3499     public synchronized int
3500     createFxSend(int channel, int midiCtrl)
3501     throws IOException, LSException, LscpException {
3502    
3503     return createFxSend(channel, midiCtrl, null);
3504     }
3505    
3506     /**
3507     * Creates an additional effect send on the specified sampler channel.
3508     * @param channel The sampler channel, on which the effect send should be created on.
3509     * @param midiCtrl Defines the MIDI controller, which can alter the effect send level.
3510     * @param name The name of the effect send entity. The name does not have to be unique.
3511     * @return The unique ID of the newly created effect send entity.
3512     * @throws IOException If some I/O error occurs.
3513     * @throws LSException If the creation of the effect send failed.
3514     * @throws LscpException If LSCP protocol corruption occurs.
3515     * @see #destroyFxSend
3516     */
3517     public synchronized int
3518     createFxSend(int channel, int midiCtrl, String name)
3519     throws IOException, LSException, LscpException {
3520    
3521     verifyConnection();
3522     String s = String.valueOf(channel) + " " + String.valueOf(midiCtrl);
3523 iliev 1393 if(name != null) s += " '" + toEscapedString(name) + "'";
3524 iliev 1139 out.writeLine("CREATE FX_SEND " + s);
3525     if(getPrintOnlyMode()) return -1;
3526    
3527     ResultSet rs = getEmptyResultSet();
3528    
3529     return rs.getIndex();
3530     }
3531    
3532     /**
3533     * Destroys the specified effect send on the specified sampler channel.
3534     * @param channel The sampler channel, from which
3535     * the specified effect send should be removed.
3536     * @param fxSend The ID of the effect send that should be removed.
3537     * @throws LSException If some other error occurs.
3538     * @throws LscpException If LSCP protocol corruption occurs.
3539     * @see #createFxSend
3540     */
3541     public synchronized void
3542     destroyFxSend(int channel, int fxSend)
3543     throws IOException, LSException, LscpException {
3544    
3545     verifyConnection();
3546     String s = String.valueOf(channel) + " " + String.valueOf(fxSend);
3547     out.writeLine("DESTROY FX_SEND " + s);
3548     if(getPrintOnlyMode()) return;
3549    
3550     ResultSet rs = getEmptyResultSet();
3551     }
3552    
3553     /**
3554     * Gets the current number of effect sends on the specified sampler channel.
3555     * @param channel The ID of the sampler channel.
3556     * @return The current number of effect sends on the specified sampler channels.
3557     * @throws IOException If some I/O error occurs.
3558     * @throws LscpException If LSCP protocol corruption occurs.
3559     * @throws LSException If some other error occurs.
3560     */
3561     public synchronized int
3562     getFxSoundCount(int channel) throws IOException, LscpException, LSException {
3563     verifyConnection();
3564     out.writeLine("GET FX_SENDS " + String.valueOf(channel));
3565     if(getPrintOnlyMode()) return -1;
3566    
3567     String s = getSingleLineResultSet().getResult();
3568     return parseInt(s);
3569     }
3570    
3571     /**
3572     * Gets a list of all created effect sends on the specified sampler channel.
3573     * @param channel The sampler channel number.
3574     * @return A <code>FxSend</code> array providing all created
3575     * effect sends on the specified sampler channel.
3576     * @throws IOException If some I/O error occurs.
3577     * @throws LscpException If LSCP protocol corruption occurs.
3578     * @throws LSException If <code>channel</code> is not a valid sampler channel ID.
3579     * @see #createFxSend
3580     * @see #destroyFxSend
3581     */
3582     public synchronized FxSend[]
3583     getFxSends(int channel) throws IOException, LscpException, LSException {
3584     Integer[] idS = getFxSendIDs(channel);
3585     if(getPrintOnlyMode()) return null;
3586    
3587     FxSend[] fxSends = new FxSend[idS.length];
3588    
3589     for(int i = 0; i < fxSends.length; i++)
3590     fxSends[i] = getFxSendInfo(channel, idS[i]);
3591    
3592     return fxSends;
3593     }
3594    
3595     /**
3596     * Gets a list of effect sends on the specified sampler channel.
3597     * @param channel The sampler channel number.
3598     * @return An <code>Integer</code> array providing
3599     * the numerical IDs of all effect sends on the specified sampler channel.
3600     * @throws IOException If some I/O error occurs.
3601     * @throws LscpException If LSCP protocol corruption occurs.
3602     * @throws LSException If <code>channel</code> is not a valid sampler channel ID.
3603     * @see #createFxSend
3604     * @see #destroyFxSend
3605     */
3606     public synchronized Integer[]
3607     getFxSendIDs(int channel) throws IOException, LscpException, LSException {
3608     verifyConnection();
3609     out.writeLine("LIST FX_SENDS " + channel);
3610     if(getPrintOnlyMode()) return null;
3611    
3612     return parseIntList(getSingleLineResultSet().getResult());
3613     }
3614    
3615     /**
3616     * Gets the current settings of the specified effect send entity.
3617     * @param channel The sampler channel number.
3618     * @param fxSend The numerical ID of the effect send entity.
3619     * @return <code>FxSend</code> instance containing
3620     * the current settings of the specified effect send entity.
3621     * @throws IOException If an I/O error occurs.
3622     * @throws LscpException If LSCP protocol corruption occurs.
3623     * @throws LSException If the sampler channel and/or the effect send number are invalid.
3624     */
3625     public synchronized FxSend
3626     getFxSendInfo(int channel, int fxSend) throws IOException, LscpException, LSException {
3627     verifyConnection();
3628     String s = String.valueOf(channel) + " " + String.valueOf(fxSend);
3629     out.writeLine("GET FX_SEND INFO " + s);
3630     if(getPrintOnlyMode()) return null;
3631    
3632     ResultSet rs = getMultiLineResultSet();
3633     FxSend fxs = new FxSend(rs.getMultiLineResult());
3634     fxs.setFxSendId(fxSend);
3635    
3636     return fxs;
3637     }
3638    
3639     /**
3640     * Sets the name of the specified effect send.
3641     * @param channel The sampler channel number.
3642     * @param fxSend The numerical ID of the effect send entity.
3643     * @param name The new name for the specified effect send.
3644     * @throws IOException If some I/O error occurs.
3645     * @throws LscpException If LSCP protocol corruption occurs.
3646     * @throws LSException If <code>channel</code> is not a valid channel
3647     * number or <code>fxSend</code> is not a valid effect send ID;
3648     */
3649     public synchronized void
3650     setFxSendName(int channel, int fxSend, String name)
3651     throws IOException, LscpException, LSException {
3652    
3653     verifyConnection();
3654 iliev 1393 String args = " " + channel + " " + fxSend + " '" + toEscapedString(name) + "'";
3655 iliev 1139 out.writeLine("SET FX_SEND NAME" + args);
3656     if(getPrintOnlyMode()) return;
3657    
3658     ResultSet rs = getEmptyResultSet();
3659     }
3660    
3661     /**
3662     * Sets the destination of an effect send's audio channel in the specified sampler channel.
3663     * @param channel The sampler channel number.
3664     * @param fxSend The numerical ID of the effect send entity to be rerouted.
3665     * @param audioSrc The numerical ID of the effect send's audio output channel,
3666     * which should be rerouted.
3667     * @param audioDst The audio channel of the selected audio output device
3668     * where <code>audioSrc</code> should be routed to.
3669     * @throws IOException If some I/O error occurs.
3670     * @throws LscpException If LSCP protocol corruption occurs.
3671     * @throws LSException If
3672     * <ul>
3673     * <li><code>channel</code> is not a valid channel number;
3674     * <li><code>fxSend</code> is not a valid effect send ID;
3675     * <li>There is no engine assigned yet to the specified sampler channel;
3676     * <li>There is no audio output device connected to the specified sampler channel.
3677     * </ul>
3678     */
3679     public synchronized void
3680     setFxSendAudioOutputChannel(int channel, int fxSend, int audioSrc, int audioDst)
3681     throws IOException, LscpException, LSException {
3682    
3683     verifyConnection();
3684     String args = " " + channel + " " + fxSend + " " + audioSrc + " " + audioDst;
3685     out.writeLine("SET FX_SEND AUDIO_OUTPUT_CHANNEL" + args);
3686     if(getPrintOnlyMode()) return;
3687    
3688     ResultSet rs = getEmptyResultSet();
3689     }
3690    
3691     /**
3692     * Sets the MIDI controller, which will be able to modify
3693     * the send level of the specified effect send in the specified sampler channel.
3694     * @param channel The sampler channel number.
3695     * @param fxSend The numerical ID of the effect send entity.
3696     * @param midiCtrl The MIDI controller which shall be
3697     * able to modify the effect send's send level.
3698     * @throws IOException If some I/O error occurs.
3699     * @throws LscpException If LSCP protocol corruption occurs.
3700     * @throws LSException If
3701     * <ul>
3702     * <li><code>channel</code> is not a valid channel number;
3703     * <li><code>fxSend</code> is not a valid effect send ID;
3704     * <li><code>midiCtrl</code> is not a valid controller;
3705     * </ul>
3706     */
3707     public synchronized void
3708     setFxSendMidiController(int channel, int fxSend, int midiCtrl)
3709     throws IOException, LscpException, LSException {
3710    
3711     verifyConnection();
3712     String args = " " + channel + " " + fxSend + " " + midiCtrl;
3713     out.writeLine("SET FX_SEND MIDI_CONTROLLER" + args);
3714     if(getPrintOnlyMode()) return;
3715    
3716     ResultSet rs = getEmptyResultSet();
3717     }
3718    
3719     /**
3720     * Sets the current send level of the specified
3721     * effect send entity in the specified sampler channel.
3722     * @param channel The sampler channel number.
3723     * @param fxSend The numerical ID of the effect send entity.
3724     * @param volume The new volume value (a value smaller than 1.0 means
3725     * attenuation, whereas a value greater than 1.0 means amplification).
3726     * @throws IOException If some I/O error occurs.
3727     * @throws LscpException If LSCP protocol corruption occurs.
3728     * @throws LSException If some other error occurs.
3729     */
3730     public synchronized void
3731     setFxSendLevel(int channel, int fxSend, float volume)
3732     throws IOException, LscpException, LSException {
3733    
3734     verifyConnection();
3735     String args = " " + channel + " " + fxSend + " " + String.valueOf(volume);
3736     out.writeLine("SET FX_SEND LEVEL" + args);
3737     if(getPrintOnlyMode()) return;
3738    
3739     ResultSet rs = getEmptyResultSet();
3740     }
3741    
3742 iliev 1340 /**
3743     * Starts an instrument editor for editing the loaded instrument
3744     * on the specified sampler channel.
3745     * @param samplerChn The sampler channel number.
3746     * @throws IOException If some I/O error occurs.
3747     * @throws LscpException If LSCP protocol corruption occurs.
3748     * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
3749     * there is no instrument loaded on the specified sampler channel.
3750     * @see #getSamplerChannels
3751     */
3752     public synchronized void
3753 iliev 1421 editChannelInstrument(int samplerChn) throws IOException, LscpException, LSException {
3754 iliev 1340 verifyConnection();
3755 iliev 1421 out.writeLine("EDIT CHANNEL INSTRUMENT " + samplerChn);
3756 iliev 1340 if(getPrintOnlyMode()) return;
3757    
3758     ResultSet rs = getEmptyResultSet();
3759     }
3760 iliev 1202
3761    
3762 iliev 1340
3763 iliev 1139 /**
3764 iliev 1202 * Adds the specified directory to the instruments database.
3765 iliev 1346 * @param dir The absolute (escaped) path name of the directory to add.
3766 iliev 1202 * @throws IOException If some I/O error occurs.
3767     * @throws LSException If the creation of the directory failed.
3768     * @throws LscpException If LSCP protocol corruption occurs.
3769     */
3770     public synchronized void
3771     addDbDirectory(String dir) throws IOException, LSException, LscpException {
3772     verifyConnection();
3773     out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");
3774     if(getPrintOnlyMode()) return;
3775    
3776     ResultSet rs = getEmptyResultSet();
3777     }
3778    
3779     /**
3780     * Removes the specified directory from the instruments database.
3781 iliev 1346 * @param dir The absolute (escaped) path name of the directory to remove.
3782 iliev 1202 * @throws IOException If some I/O error occurs.
3783     * @throws LscpException If LSCP protocol corruption occurs.
3784     * @throws LSException If the specified directory is not
3785     * empty or if the removal of the directory failed.
3786     */
3787     public synchronized void
3788     removeDbDirectory(String dir) throws IOException, LscpException, LSException {
3789     removeDbDirectory(dir, false);
3790     }
3791    
3792     /**
3793     * Removes the specified directory from the instruments database.
3794     * @param dir The absolute path name of the directory to remove.
3795     * @param force If <code>true</code> forces the removal of non-empty
3796     * directory and all its content.
3797     * @throws IOException If some I/O error occurs.
3798     * @throws LscpException If LSCP protocol corruption occurs.
3799     * @throws LSException If the removing of the directory failed.
3800     */
3801     public synchronized void
3802     removeDbDirectory(String dir, boolean force)
3803     throws IOException, LscpException, LSException {
3804    
3805     verifyConnection();
3806     String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3807     if(force) s += "FORCE ";
3808     out.writeLine(s + "'" + dir + "'");
3809     if(getPrintOnlyMode()) return;
3810    
3811     ResultSet rs = getEmptyResultSet();
3812     }
3813    
3814     /**
3815     * Removes the specified directories from the instruments database.
3816 iliev 1346 * @param dirs The absolute (escaped) path names of the directories to remove.
3817 iliev 1202 * @param force If <code>true</code> forces the removal of non-empty
3818     * directories.
3819     * @throws IOException If some I/O error occurs.
3820     * @throws LscpException If LSCP protocol corruption occurs.
3821     * @throws LSException If the removing of the directores failed.
3822     */
3823     public synchronized void
3824     removeDbDirectories(String[] dirs, boolean force)
3825     throws IOException, LscpException, LSException {
3826    
3827     verifyConnection();
3828     String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3829     if(force) cmd += "FORCE ";
3830    
3831     for(String s : dirs) out.writeLine(cmd + "'" + s + "'");
3832    
3833     if(getPrintOnlyMode()) return;
3834    
3835     getEmptyResultSets(dirs.length, "Client.dirDeletionFailed!");
3836     }
3837    
3838     /**
3839     * Gets the number of directories in the specified directory.
3840     * @return The current number of directories in the specified directory.
3841     * @param dir The absolute path name of the directory.
3842     * @throws IOException If some I/O error occurs.
3843     * @throws LscpException If LSCP protocol corruption occurs.
3844     * @throws LSException If some other error occurs.
3845     */
3846     public synchronized int
3847     getDbDirectoryCount(String dir) throws IOException, LscpException, LSException {
3848     return getDbDirectoryCount(dir, false);
3849     }
3850    
3851     /**
3852     * Gets the number of directories in the specified directory.
3853     * @return The current number of directories in the specified directory.
3854     * @param dir The absolute path name of the directory.
3855     * @param recursive If <code>true</code>, the number of all directories
3856     * in the specified subtree will be returned.
3857     * @throws IOException If some I/O error occurs.
3858     * @throws LscpException If LSCP protocol corruption occurs.
3859     * @throws LSException If some other error occurs.
3860     */
3861     public synchronized int
3862     getDbDirectoryCount(String dir, boolean recursive)
3863     throws IOException, LscpException, LSException {
3864    
3865     verifyConnection();
3866     String s;
3867     if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
3868     else s = "GET DB_INSTRUMENT_DIRECTORIES '";
3869     out.writeLine(s + dir + "'");
3870     if(getPrintOnlyMode()) return -1;
3871    
3872     s = getSingleLineResultSet().getResult();
3873     return parseInt(s);
3874     }
3875    
3876     /**
3877     * Gets the list of directories in the specified directory.
3878     * @param dir The absolute path name of the directory.
3879     * @return A <code>String</code> array providing the names of
3880     * all directories in the specified directory.
3881     * @throws IOException If some I/O error occurs.
3882     * @throws LscpException If LSCP protocol corruption occurs.
3883     * @throws LSException If the specified path name is invalid.
3884     */
3885     public synchronized String[]
3886     getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
3887     verifyConnection();
3888     out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");
3889     if(getPrintOnlyMode()) return null;
3890    
3891 iliev 1346 String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
3892     for(int i = 0; i < names.length; i++) {
3893 iliev 1351 names[i] = toNonEscapedString(names[i]);
3894 iliev 1346 }
3895     return names;
3896 iliev 1202 }
3897    
3898     /**
3899     * Gets information about the specified directory.
3900     * @param dir The absolute path name of the directory.
3901     * @return A <code>DbDirectoryInfo</code> instance providing information
3902     * about the specified directory.
3903     * @throws IOException If some I/O error occurs.
3904     * @throws LscpException If LSCP protocol corruption occurs.
3905     * @throws LSException If the specified directory is not found.
3906     */
3907     public synchronized DbDirectoryInfo
3908     getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
3909     verifyConnection();
3910     out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");
3911     if(getPrintOnlyMode()) return null;
3912    
3913     ResultSet rs = getMultiLineResultSet();
3914     DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
3915     if(dir.equals("/")) {
3916     info.setName("/");
3917 iliev 1346 } else {
3918     dir = removeEndingFileSeparator(dir);
3919 iliev 1202 }
3920 iliev 1346 String s = getFileName(dir);
3921     if(s != null) info.setName(toNonEscapedFileName(s));
3922     s = getParentDirectory(dir);
3923     if(s != null) info.setParentDirectoryPath(s);
3924 iliev 1202
3925     return info;
3926     }
3927    
3928     /**
3929     * Gets the list of directories in the specified directory.
3930     * @param dir The absolute path name of the directory.
3931     * @return A <code>DbDirectoryInfo</code> array providing
3932     * information about all directories in the specified directory.
3933     * @throws IOException If some I/O error occurs.
3934     * @throws LscpException If LSCP protocol corruption occurs.
3935     * @throws LSException If the specified path name is invalid.
3936     */
3937     public synchronized DbDirectoryInfo[]
3938     getDbDirectories(String dir) throws IOException, LscpException, LSException {
3939     String[] dirS = getDbDirectoryNames(dir);
3940 iliev 1346 if(!hasEndingFileSeparator(dir)) dir += "/";
3941 iliev 1202 DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3942 iliev 1346 for(int i = 0; i < dirS.length; i++) {
3943     infoS[i] = getDbDirectoryInfo(dir + toEscapedFileName(dirS[i]));
3944     }
3945 iliev 1202 return infoS;
3946     }
3947    
3948     /**
3949     * Gets the list of directories in the specified directory.
3950     * @param dir The absolute path name of the directory.
3951     * @return A <code>DbDirectoryInfo</code> array providing
3952     * information about all directories in the specified directory.
3953     * @throws IOException If some I/O error occurs.
3954     * @throws LscpException If LSCP protocol corruption occurs.
3955     * @throws LSException If the specified path name is invalid.
3956     *
3957     public synchronized DbDirectoryInfo[]
3958     getDbDirectories(String dir) throws IOException, LscpException, LSException {
3959     String[] dirS = getDbDirectoryNames(dir);
3960     if(dirS.length == 0) return new DbDirectoryInfo[0];
3961    
3962     if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3963    
3964     for(int i = 0; i < dirS.length; i++) {
3965     out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");
3966     }
3967    
3968     if(getPrintOnlyMode()) return null;
3969    
3970     if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
3971     StringBuffer sb = new StringBuffer();
3972     DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3973     for(int i = 0; i < dirS.length; i++) {
3974     try {
3975     ResultSet rs = getMultiLineResultSet();
3976     infoS[i] = new DbDirectoryInfo(rs.getMultiLineResult());
3977     infoS[i].setName(dirS[i]);
3978     infoS[i].setParentDirectoryPath(dir);
3979     } catch (SocketTimeoutException e) {
3980     getLogger().log(Level.FINE, e.getMessage(), e);
3981     sb.append(e.getMessage()).append("\n");
3982     break;
3983     } catch (Exception e) {
3984     getLogger().log(Level.FINE, e.getMessage(), e);
3985     sb.append(e.getMessage()).append("\n");
3986     }
3987     }
3988    
3989     String details = sb.toString();
3990     if(details.length() > 0) {
3991     String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
3992     throw new LSException(0, err, details);
3993     }
3994    
3995     return infoS;
3996     }*/
3997    
3998     /**
3999     * Renames the specified directory.
4000     * @param dir The absolute path name of the directory to rename.
4001     * @param name The new name for the directory.
4002     * @throws IOException If some I/O error occurs.
4003     * @throws LSException If the renaming of the directory failed.
4004     * @throws LscpException If LSCP protocol corruption occurs.
4005     */
4006     public synchronized void
4007     renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
4008     verifyConnection();
4009 iliev 1346 name = toEscapedString(name);
4010 iliev 1202 out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");
4011     if(getPrintOnlyMode()) return;
4012    
4013     ResultSet rs = getEmptyResultSet();
4014     }
4015    
4016     /**
4017     * Moves the specified directory into the specified location.
4018     * @param dir The absolute path name of the directory to move.
4019     * @param dst The location where the directory will be moved to.
4020     * @throws IOException If some I/O error occurs.
4021     * @throws LSException If the operation failed.
4022     * @throws LscpException If LSCP protocol corruption occurs.
4023     */
4024     public synchronized void
4025     moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4026     verifyConnection();
4027     out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4028     if(getPrintOnlyMode()) return;
4029    
4030     ResultSet rs = getEmptyResultSet();
4031     }
4032    
4033     /**
4034     * Moves the specified directories into the specified location.
4035     * @param dirs The absolute path names of the directories to move.
4036     * @param dst The location where the directories will be moved to.
4037     * @throws IOException If some I/O error occurs.
4038     * @throws LSException If the operation failed.
4039     * @throws LscpException If LSCP protocol corruption occurs.
4040     */
4041     public synchronized void
4042     moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
4043     verifyConnection();
4044     for(String s : dirs) {
4045     out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4046     }
4047     if(getPrintOnlyMode()) return;
4048    
4049     getEmptyResultSets(dirs.length, "Client.dirMovingFailed!");
4050     }
4051    
4052     /**
4053     * Copies the specified directory into the specified location.
4054     * @param dir The absolute path name of the directory to copy.
4055     * @param dst The location where the directory will be copied to.
4056     * @throws IOException If some I/O error occurs.
4057     * @throws LSException If the operation failed.
4058     * @throws LscpException If LSCP protocol corruption occurs.
4059     */
4060     public synchronized void
4061     copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4062     verifyConnection();
4063     out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4064     if(getPrintOnlyMode()) return;
4065    
4066     ResultSet rs = getEmptyResultSet();
4067     }
4068    
4069     /**
4070     * Copies the specified directories into the specified location.
4071     * @param dirs The absolute path names of the directories to copy.
4072     * @param dst The location where the directories will be copied to.
4073     * @throws IOException If some I/O error occurs.
4074     * @throws LSException If the operation failed.
4075     * @throws LscpException If LSCP protocol corruption occurs.
4076     */
4077     public synchronized void
4078     copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4079     verifyConnection();
4080     for(String s : dirs) {
4081     out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4082     }
4083     if(getPrintOnlyMode()) return;
4084    
4085     getEmptyResultSets(dirs.length, "Client.dirCopyingFailed!");
4086     }
4087    
4088     /**
4089     * Changes the description of the specified directory.
4090     * @param dir The absolute path name of the directory.
4091     * @param desc The new description for the directory.
4092     * @throws IOException If some I/O error occurs.
4093     * @throws LSException If failed to change the description.
4094     * @throws LscpException If LSCP protocol corruption occurs.
4095     */
4096     public synchronized void
4097     setDbDirectoryDescription(String dir, String desc)
4098     throws IOException, LSException, LscpException {
4099    
4100     verifyConnection();
4101     String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4102 iliev 1346 out.writeLine(s + dir + "' '" + toEscapedString(desc) + "'");
4103 iliev 1202 if(getPrintOnlyMode()) return;
4104    
4105     ResultSet rs = getEmptyResultSet();
4106     }
4107    
4108     public static enum ScanMode {
4109     RECURSIVE, NON_RECURSIVE, FLAT
4110     }
4111    
4112     /**
4113     * Adds the specified instrument to the specified instruments database directory.
4114     * @param dbDir The absolute path name of the database directory in which the
4115     * specified instrument will be added.
4116     * @param filePath The absolute path name of the instrument file.
4117     * @param instrIndex The index of the instrument (in the given instrument file) to add.
4118     * @throws IOException If some I/O error occurs.
4119     * @throws LSException If the operation failed.
4120     * @throws LscpException If LSCP protocol corruption occurs.
4121     */
4122     public synchronized void
4123     addDbInstrument(String dbDir, String filePath, int instrIndex)
4124     throws IOException, LSException, LscpException {
4125    
4126     addDbInstrument(dbDir, filePath, instrIndex, false);
4127     }
4128    
4129     /**
4130     * Adds the specified instrument to the specified instruments database directory.
4131     * @param dbDir The absolute path name of the database directory in which the
4132     * specified instrument will be added.
4133     * @param filePath The absolute path name of the instrument file.
4134     * @param instrIndex The index of the instrument (in the given instrument file) to add.
4135     * @param background If <code>true</code>, the scan will be done
4136     * in background and this method may return before the job is finished.
4137     * @return If <code>background</code> is <code>true</code>, the ID
4138     * of the scan job.
4139     * @throws IOException If some I/O error occurs.
4140     * @throws LSException If the operation failed.
4141     * @throws LscpException If LSCP protocol corruption occurs.
4142     * @see #addInstrumentsDbListener
4143     */
4144     public synchronized int
4145     addDbInstrument(String dbDir, String filePath, int instrIndex, boolean background)
4146     throws IOException, LSException, LscpException {
4147    
4148     verifyConnection();
4149     String s = "ADD DB_INSTRUMENTS";
4150     if(background) s += " NON_MODAL";
4151 iliev 1351 s += " '" + dbDir + "' '" + filePath + "' ";
4152 iliev 1202 out.writeLine(s + String.valueOf(instrIndex));
4153     if(getPrintOnlyMode()) return -1;
4154    
4155     ResultSet rs = getEmptyResultSet();
4156     return rs.getIndex();
4157     }
4158    
4159     /**
4160     * Adds the instruments in the specified file to the specified
4161     * instruments database directory.
4162     * @param dbDir The absolute path name of the database directory
4163     * in which the the supported instruments will be added.
4164     * @param filePath The absolute path name of the file to scan for instruments.
4165     * @throws IOException If some I/O error occurs.
4166     * @throws LSException If the operation failed.
4167     * @throws LscpException If LSCP protocol corruption occurs.
4168     */
4169     public synchronized void
4170     addDbInstruments(String dbDir, String filePath)
4171     throws IOException, LSException, LscpException {
4172    
4173     addDbInstruments(dbDir, filePath, false);
4174     }
4175    
4176     /**
4177     * Adds the instruments in the specified file to the specified
4178     * instruments database directory.
4179     * @param dbDir The absolute path name of the database directory
4180     * in which the the supported instruments will be added.
4181     * @param filePath The absolute path name of the file to scan for instruments.
4182     * @param background If <code>true</code>, the scan will be done
4183     * in background and this method may return before the job is finished.
4184     * @return If <code>background</code> is <code>true</code>, the ID
4185     * of the scan job.
4186     * @throws IOException If some I/O error occurs.
4187     * @throws LSException If the operation failed.
4188     * @throws LscpException If LSCP protocol corruption occurs.
4189     * @see #addInstrumentsDbListener
4190     */
4191     public synchronized int
4192     addDbInstruments(String dbDir, String filePath, boolean background)
4193     throws IOException, LSException, LscpException {
4194    
4195     verifyConnection();
4196     String s = "ADD DB_INSTRUMENTS";
4197     if(background) s += " NON_MODAL";
4198 iliev 1351 out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");
4199 iliev 1202 if(getPrintOnlyMode()) return -1;
4200    
4201     ResultSet rs = getEmptyResultSet();
4202     return rs.getIndex();
4203     }
4204    
4205     /**
4206     * Adds the instruments in the specified file system directory
4207     * to the specified instruments database directory.
4208     * @param mode Determines the scanning mode. If RECURSIVE is
4209     * specified, all supported instruments in the specified file system
4210     * direcotry will be added to the specified instruments database
4211     * directory, including the instruments in subdirectories
4212     * of the supplied directory. If NON_RECURSIVE is specified,
4213     * the instruments in the subdirectories will not be processed.
4214     * If FLAT is specified, all supported instruments in the specified
4215     * file system direcotry will be added, including the instruments in
4216     * subdirectories of the supplied directory, but the respective
4217     * subdirectory structure will not be recreated in the instruments
4218     * database and all instruments will be added directly in the
4219     * specified database directory.
4220     * @param dbDir The absolute path name of the database directory
4221     * in which the supported instruments will be added.
4222     * @param fsDir The absolute path name of the file system directory.
4223     * @throws IOException If some I/O error occurs.
4224     * @throws LSException If the operation failed.
4225     * @throws LscpException If LSCP protocol corruption occurs.
4226     */
4227     public synchronized void
4228     addDbInstruments(ScanMode mode, String dbDir, String fsDir)
4229     throws IOException, LSException, LscpException {
4230    
4231     addDbInstruments(mode, dbDir, fsDir, false);
4232     }
4233    
4234     /**
4235     * Adds the instruments in the specified file system directory
4236     * to the specified instruments database directory.
4237     * @param mode Determines the scanning mode. If RECURSIVE is
4238     * specified, all supported instruments in the specified file system
4239     * direcotry will be added to the specified instruments database
4240     * directory, including the instruments in subdirectories
4241     * of the supplied directory. If NON_RECURSIVE is specified,
4242     * the instruments in the subdirectories will not be processed.
4243     * If FLAT is specified, all supported instruments in the specified
4244     * file system direcotry will be added, including the instruments in
4245     * subdirectories of the supplied directory, but the respective
4246     * subdirectory structure will not be recreated in the instruments
4247     * database and all instruments will be added directly in the
4248     * specified database directory.
4249     * @param dbDir The absolute path name of the database directory
4250     * in which the supported instruments will be added.
4251     * @param fsDir The absolute path name of the file system directory.
4252     * @param background If <code>true</code>, the scan will be done
4253     * in background and this method may return before the job is finished.
4254     * @return If <code>background</code> is <code>true</code>, the ID
4255     * of the scan job.
4256     * @throws IOException If some I/O error occurs.
4257     * @throws LSException If the operation failed.
4258     * @throws LscpException If LSCP protocol corruption occurs.
4259     * @see #addInstrumentsDbListener
4260     */
4261     public synchronized int
4262     addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4263     throws IOException, LSException, LscpException {
4264    
4265     verifyConnection();
4266     StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4267     if(background) sb.append(" NON_MODAL");
4268    
4269     switch(mode) {
4270     case RECURSIVE:
4271     sb.append(" RECURSIVE");
4272     break;
4273     case NON_RECURSIVE:
4274     sb.append(" NON_RECURSIVE");
4275     break;
4276     case FLAT:
4277     sb.append(" FLAT");
4278     break;
4279     }
4280    
4281 iliev 1346 sb.append(" '").append(dbDir).append("' '");
4282 iliev 1351 sb.append(fsDir).append("'");
4283 iliev 1202 out.writeLine(sb.toString());
4284     if(getPrintOnlyMode()) return -1;
4285    
4286     ResultSet rs = getEmptyResultSet();
4287     return rs.getIndex();
4288     }
4289    
4290     /**
4291     * Removes the specified instrument from the instruments database.
4292     * @param instr The absolute path name of the instrument to remove.
4293     * @throws IOException If some I/O error occurs.
4294     * @throws LscpException If LSCP protocol corruption occurs.
4295     * @throws LSException If the removing of the instrument failed.
4296     */
4297     public synchronized void
4298     removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4299    
4300     verifyConnection();
4301     out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");
4302     if(getPrintOnlyMode()) return;
4303    
4304     ResultSet rs = getEmptyResultSet();
4305     }
4306    
4307     /**
4308     * Removes the specified instruments from the instruments database.
4309     * @param instrs The absolute path names of the instruments to remove.
4310     * @throws IOException If some I/O error occurs.
4311     * @throws LscpException If LSCP protocol corruption occurs.
4312     * @throws LSException If the removing of the instruments failed.
4313     */
4314     public synchronized void
4315     removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4316     verifyConnection();
4317     for(String s : instrs) {
4318     out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");
4319     }
4320     if(getPrintOnlyMode()) return;
4321    
4322     getEmptyResultSets(instrs.length, "Client.instrDeletionFailed!");
4323     }
4324    
4325     /**
4326     * Gets the number of instruments in the specified directory.
4327     * @return The current number of instruments in the specified directory.
4328     * @param dir The absolute path name of the directory.
4329     * @throws IOException If some I/O error occurs.
4330     * @throws LscpException If LSCP protocol corruption occurs.
4331     * @throws LSException If some other error occurs.
4332     */
4333     public synchronized int
4334     getDbInstrumentCount(String dir) throws IOException, LscpException, LSException {
4335     return getDbInstrumentCount(dir, false);
4336     }
4337    
4338     /**
4339     * Gets the number of instruments in the specified directory.
4340     * @return The current number of instruments in the specified directory.
4341     * @param dir The absolute path name of the directory.
4342     * @param recursive If <code>true</code>, the number of all instruments
4343     * in the specified subtree will be returned.
4344     * @throws IOException If some I/O error occurs.
4345     * @throws LscpException If LSCP protocol corruption occurs.
4346     * @throws LSException If some other error occurs.
4347     */
4348     public synchronized int
4349     getDbInstrumentCount(String dir, boolean recursive)
4350     throws IOException, LscpException, LSException {
4351    
4352     verifyConnection();
4353     String s;
4354     if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4355     else s = "GET DB_INSTRUMENTS '";
4356     out.writeLine(s + dir + "'");
4357     if(getPrintOnlyMode()) return -1;
4358    
4359     s = getSingleLineResultSet().getResult();
4360     return parseInt(s);
4361     }
4362    
4363     /**
4364     * Gets the list of instruments in the specified directory.
4365     * @param dir The absolute path name of the directory.
4366     * @return A <code>String</code> array providing the names of
4367     * all instruments in the specified directory.
4368     * @throws IOException If some I/O error occurs.
4369     * @throws LscpException If LSCP protocol corruption occurs.
4370     * @throws LSException If the specified path name is invalid.
4371     */
4372     public synchronized String[]
4373     getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4374     verifyConnection();
4375     out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");
4376     if(getPrintOnlyMode()) return null;
4377    
4378 iliev 1346 String[] names = parseEscapedStringList(getSingleLineResultSet().getResult());
4379     for(int i = 0; i < names.length; i++) {
4380 iliev 1351 names[i] = toNonEscapedString(names[i]);
4381 iliev 1346 }
4382     return names;
4383 iliev 1202 }
4384    
4385     /**
4386     * Gets information about the specified instrument.
4387     * @param instr The absolute path name of the instrument.
4388     * @return A <code>DbInstrumentInfo</code> instance providing information
4389     * about the specified instrument.
4390     * @throws IOException If some I/O error occurs.
4391     * @throws LscpException If LSCP protocol corruption occurs.
4392     * @throws LSException If the specified instrument is not found.
4393     */
4394     public synchronized DbInstrumentInfo
4395     getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4396     verifyConnection();
4397     out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");
4398     if(getPrintOnlyMode()) return null;
4399    
4400     ResultSet rs = getMultiLineResultSet();
4401     DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4402 iliev 1346 String s = getParentDirectory(instr);
4403     if(s != null) info.setDirectoryPath(s);
4404     s = getFileName(instr);
4405     if(s != null) info.setName(toNonEscapedFileName(s));
4406 iliev 1202
4407     return info;
4408     }
4409    
4410     /**
4411     * Gets the list of instruments in the specified directory.
4412     * @param dir The absolute path name of the directory.
4413     * @return A <code>DbInstrumentInfo</code> array providing
4414     * information about all instruments in the specified directory.
4415     * @throws IOException If some I/O error occurs.
4416     * @throws LscpException If LSCP protocol corruption occurs.
4417     * @throws LSException If the specified path name is invalid.
4418     */
4419     public synchronized DbInstrumentInfo[]
4420     getDbInstruments(String dir) throws IOException, LscpException, LSException {
4421     String[] instrS = getDbInstrumentNames(dir);
4422 iliev 1346 if(!hasEndingFileSeparator(dir)) dir += "/";
4423 iliev 1202
4424     DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4425     for(int i = 0; i < instrS.length; i++) {
4426 iliev 1346 infoS[i] = getDbInstrumentInfo(dir + toEscapedFileName(instrS[i]));
4427 iliev 1202 }
4428     return infoS;
4429     }
4430    
4431     /**
4432     * Gets the list of instruments in the specified directory.
4433     * @param dir The absolute path name of the directory.
4434     * @return A <code>DbInstrumentInfo</code> array providing
4435     * information about all instruments in the specified directory.
4436     * @throws IOException If some I/O error occurs.
4437     * @throws LscpException If LSCP protocol corruption occurs.
4438     * @throws LSException If the specified path name is invalid.
4439     *
4440     public synchronized DbInstrumentInfo[]
4441     getDbInstruments(String dir) throws IOException, LscpException, LSException {
4442     String[] instrS = getDbInstrumentNames(dir);
4443     if(instrS.length == 0) return new DbInstrumentInfo[0];
4444    
4445     if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4446    
4447     for(int i = 0; i < instrS.length; i++) {
4448     out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");
4449     }
4450    
4451     if(getPrintOnlyMode()) return null;
4452    
4453     if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4454     StringBuffer sb = new StringBuffer();
4455     DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4456     for(int i = 0; i < instrS.length; i++) {
4457     try {
4458     ResultSet rs = getMultiLineResultSet();
4459     infoS[i] = new DbInstrumentInfo(rs.getMultiLineResult());
4460     infoS[i].setName(instrS[i]);
4461     infoS[i].setDirectoryPath(dir);
4462     } catch (SocketTimeoutException e) {
4463     getLogger().log(Level.FINE, e.getMessage(), e);
4464     sb.append(e.getMessage()).append("\n");
4465     break;
4466     } catch (Exception e) {
4467     getLogger().log(Level.FINE, e.getMessage(), e);
4468     sb.append(e.getMessage()).append("\n");
4469     }
4470     }
4471    
4472     String details = sb.toString();
4473     if(details.length() > 0) {
4474     String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4475     throw new LSException(0, err, details);
4476     }
4477    
4478     return infoS;
4479     }*/
4480    
4481     /**
4482     * Renames the specified instrument.
4483     * @param instr The absolute path name of the instrument to rename.
4484     * @param name The new name for the instrument.
4485     * @throws IOException If some I/O error occurs.
4486     * @throws LSException If the renaming of the instrument failed.
4487     * @throws LscpException If LSCP protocol corruption occurs.
4488     */
4489     public synchronized void
4490     renameDbInstrument(String instr, String name)
4491     throws IOException, LSException, LscpException {
4492    
4493     verifyConnection();
4494 iliev 1346 name = toEscapedString(name);
4495 iliev 1202 out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");
4496     if(getPrintOnlyMode()) return;
4497    
4498     ResultSet rs = getEmptyResultSet();
4499     }
4500    
4501     /**
4502     * Moves the specified instrument into the specified location.
4503     * @param instr The absolute path name of the instrument to move.
4504     * @param dst The directory where the specified instrument will be moved to.
4505     * @throws IOException If some I/O error occurs.
4506     * @throws LSException If the operation failed.
4507     * @throws LscpException If LSCP protocol corruption occurs.
4508     */
4509     public synchronized void
4510     moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4511     verifyConnection();
4512     out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4513     if(getPrintOnlyMode()) return;
4514    
4515     ResultSet rs = getEmptyResultSet();
4516     }
4517    
4518     /**
4519     * Moves the specified instruments into the specified location.
4520     * @param instrs The absolute path names of the instruments to move.
4521     * @param dst The directory where the specified instruments will be moved to.
4522     * @throws IOException If some I/O error occurs.
4523     * @throws LSException If the operation failed.
4524     * @throws LscpException If LSCP protocol corruption occurs.
4525     */
4526     public synchronized void
4527     moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4528     verifyConnection();
4529     for(String s : instrs) {
4530     out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");
4531     }
4532     if(getPrintOnlyMode()) return;
4533    
4534     getEmptyResultSets(instrs.length, "Client.instrMovingFailed!");
4535     }
4536    
4537     /**
4538     * Copies the specified instrument into the specified location.
4539     * @param instr The absolute path name of the instrument to copy.
4540     * @param dst The directory where the specified instrument will be copied to.
4541     * @throws IOException If some I/O error occurs.
4542     * @throws LSException If the operation failed.
4543     * @throws LscpException If LSCP protocol corruption occurs.
4544     */
4545     public synchronized void
4546     copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4547     verifyConnection();
4548     out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4549     if(getPrintOnlyMode()) return;
4550    
4551     ResultSet rs = getEmptyResultSet();
4552     }
4553    
4554     /**
4555     * Copies the specified instruments into the specified location.
4556     * @param instrs The absolute path name of the instruments to copy.
4557     * @param dst The directory where the specified instruments will be copied to.
4558     * @throws IOException If some I/O error occurs.
4559     * @throws LSException If the operation failed.
4560     * @throws LscpException If LSCP protocol corruption occurs.
4561     */
4562     public synchronized void
4563     copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4564     verifyConnection();
4565     for(String s : instrs) {
4566     out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");
4567     }
4568     if(getPrintOnlyMode()) return;
4569    
4570     getEmptyResultSets(instrs.length, "Client.instrCopyingFailed!");
4571     }
4572    
4573     /**
4574     * Changes the description of the specified instrument.
4575     * @param instr The absolute path name of the instrument.
4576     * @param desc The new description for the instrument.
4577     * @throws IOException If some I/O error occurs.
4578     * @throws LSException If failed to change the description.
4579     * @throws LscpException If LSCP protocol corruption occurs.
4580     */
4581     public synchronized void
4582     setDbInstrumentDescription(String instr, String desc)
4583     throws IOException, LSException, LscpException {
4584    
4585     verifyConnection();
4586 iliev 1346 desc = toEscapedString(desc);
4587 iliev 1202 out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");
4588     if(getPrintOnlyMode()) return;
4589    
4590     ResultSet rs = getEmptyResultSet();
4591     }
4592    
4593     /**
4594     * Finds all directories in the specified directory
4595     * that corresponds to the specified search criterias.
4596     * @param dir The absolute path name of the directory to search.
4597     * @param query Provides the search criterias.
4598     * @return A <code>DbDirectoryInfo</code> array providing
4599     * information about all directories that are found in the specified directory.
4600     * @throws IOException If some I/O error occurs.
4601     * @throws LscpException If LSCP protocol corruption occurs.
4602     * @throws LSException If the specified path name is invalid.
4603     */
4604     public synchronized DbDirectoryInfo[]
4605     findDbDirectories(String dir, DbSearchQuery query)
4606     throws IOException, LscpException, LSException {
4607    
4608     return findDbDirectories(dir, query, false);
4609     }
4610    
4611     /**
4612     * Finds all directories in the specified directory
4613     * that corresponds to the specified search criterias.
4614     * @param dir The absolute path name of the directory to search.
4615     * @param query Provides the search criterias.
4616     * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4617     * @return A <code>DbDirectoryInfo</code> array providing
4618     * information about all directories that are found in the specified directory.
4619     * @throws IOException If some I/O error occurs.
4620     * @throws LscpException If LSCP protocol corruption occurs.
4621     * @throws LSException If the specified path name is invalid.
4622     */
4623     public synchronized DbDirectoryInfo[]
4624     findDbDirectories(String dir, DbSearchQuery query, boolean nonRecursive)
4625     throws IOException, LscpException, LSException {
4626    
4627     verifyConnection();
4628     StringBuffer sb = new StringBuffer();
4629     sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4630     if(nonRecursive) sb.append(" NON_RECURSIVE");
4631     sb.append(" '").append(dir).append("'");
4632    
4633     if(query.name != null && query.name.length() > 0) {
4634 iliev 1346 sb.append(" NAME='").append(toEscapedString(query.name)).append("'");
4635 iliev 1202 }
4636    
4637     String s = query.getCreatedAfter();
4638     String s2 = query.getCreatedBefore();
4639     if(s != null || s2 != null) {
4640     sb.append(" CREATED='");
4641     if(s != null) sb.append(s);
4642     sb.append("..");
4643     if(s2 != null) sb.append(s2);
4644     sb.append("'");
4645     }
4646    
4647     s = query.getModifiedAfter();
4648     s2 = query.getModifiedBefore();
4649     if(s != null || s2 != null) {
4650     sb.append(" MODIFIED='");
4651     if(s != null) sb.append(s);
4652     sb.append("..");
4653     if(s2 != null) sb.append(s2);
4654     sb.append("'");
4655     }
4656    
4657     if(query.description != null && query.description.length() > 0) {
4658 iliev 1346 sb.append(" DESCRIPTION='");
4659     sb.append(toEscapedString(query.description)).append("'");
4660 iliev 1202 }
4661    
4662     out.writeLine(sb.toString());
4663     if(getPrintOnlyMode()) return null;
4664    
4665 iliev 1346 String[] dirS = parseEscapedStringList(getSingleLineResultSet().getResult());
4666 iliev 1202
4667     DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4668     for(int i = 0; i < dirS.length; i++) {
4669     infoS[i] = getDbDirectoryInfo(dirS[i]);
4670     }
4671     return infoS;
4672     }
4673    
4674     /**
4675     * Finds all instruments in the specified directory
4676     * that corresponds to the specified search criterias.
4677     * @param dir The absolute path name of the directory to search.
4678     * @param query Provides the search criterias.
4679     * @return A <code>DbInstrumentInfo</code> array providing
4680     * information about all instruments that are found in the specified directory.
4681     * @throws IOException If some I/O error occurs.
4682     * @throws LscpException If LSCP protocol corruption occurs.
4683     * @throws LSException If the specified path name is invalid.
4684     */
4685     public synchronized DbInstrumentInfo[]
4686     findDbInstruments(String dir, DbSearchQuery query)
4687     throws IOException, LscpException, LSException {
4688    
4689     return findDbInstruments(dir, query, false);
4690     }
4691    
4692     /**
4693     * Finds all instruments in the specified directory
4694     * that corresponds to the specified search criterias.
4695     * @param dir The absolute path name of the directory to search.
4696     * @param query Provides the search criterias.
4697     * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4698     * @return A <code>DbInstrumentInfo</code> array providing
4699     * information about all instruments that are found in the specified directory.
4700     * @throws IOException If some I/O error occurs.
4701     * @throws LscpException If LSCP protocol corruption occurs.
4702     * @throws LSException If the specified path name is invalid.
4703     */
4704     public synchronized DbInstrumentInfo[]
4705     findDbInstruments(String dir, DbSearchQuery query, boolean nonRecursive)
4706     throws IOException, LscpException, LSException {
4707    
4708     verifyConnection();
4709     StringBuffer sb = new StringBuffer();
4710     sb.append("FIND DB_INSTRUMENTS");
4711     if(nonRecursive) sb.append(" NON_RECURSIVE");
4712     sb.append(" '").append(dir).append("'");
4713    
4714     if(query.name != null && query.name.length() > 0) {
4715 iliev 1346 sb.append(" NAME='").append(toEscapedString(query.name)).append("'");
4716 iliev 1202 }
4717    
4718     if(query.formatFamilies.size() > 0) {
4719     sb.append(" FORMAT_FAMILIES='").append(query.formatFamilies.get(0));
4720     for(int i = 1; i < query.formatFamilies.size(); i++) {
4721     sb.append(',').append(query.formatFamilies.get(i));
4722     }
4723     sb.append("'");
4724     }
4725    
4726     if(query.minSize != -1 || query.maxSize != -1) {
4727     sb.append(" SIZE='");
4728     if(query.minSize != -1) sb.append(query.minSize);
4729     sb.append("..");
4730     if(query.maxSize != -1) sb.append(query.maxSize);
4731     sb.append("'");
4732     }
4733    
4734     String s = query.getCreatedAfter();
4735     String s2 = query.getCreatedBefore();
4736     if(s != null || s2 != null) {
4737     sb.append(" CREATED='");
4738     if(s != null) sb.append(s);
4739     sb.append("..");
4740     if(s2 != null) sb.append(s2);
4741     sb.append("'");
4742     }
4743    
4744     s = query.getModifiedAfter();
4745     s2 = query.getModifiedBefore();
4746     if(s != null || s2 != null) {
4747     sb.append(" MODIFIED='");
4748     if(s != null) sb.append(s);
4749     sb.append("..");
4750     if(s2 != null) sb.append(s2);
4751     sb.append("'");
4752     }
4753    
4754     if(query.description != null && query.description.length() > 0) {
4755 iliev 1346 sb.append(" DESCRIPTION='");
4756     sb.append(toEscapedString(query.description)).append("'");
4757 iliev 1202 }
4758    
4759     if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
4760     sb.append(" IS_DRUM=");
4761     if(query.instrumentType == DbSearchQuery.InstrumentType.DRUM) {
4762     sb.append("'true'");
4763     } else {
4764     sb.append("'false'");
4765     }
4766     }
4767    
4768     if(query.product != null && query.product.length() > 0) {
4769 iliev 1346 sb.append(" PRODUCT='").append(toEscapedString(query.product)).append("'");
4770 iliev 1202 }
4771    
4772     if(query.artists != null && query.artists.length() > 0) {
4773 iliev 1346 sb.append(" ARTISTS='").append(toEscapedString(query.artists)).append("'");
4774 iliev 1202 }
4775    
4776     if(query.keywords != null && query.keywords.length() > 0) {
4777 iliev 1346 sb.append(" KEYWORDS='");
4778     sb.append(toEscapedString(query.keywords)).append("'");
4779 iliev 1202 }
4780    
4781     out.writeLine(sb.toString());
4782     if(getPrintOnlyMode()) return null;
4783    
4784 iliev 1346 String[] instrS = parseEscapedStringList(getSingleLineResultSet().getResult());
4785 iliev 1202
4786     DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4787     for(int i = 0; i < instrS.length; i++) {
4788     infoS[i] = getDbInstrumentInfo(instrS[i]);
4789     }
4790     return infoS;
4791     }
4792    
4793     /**
4794     * Gets status information about the specified job.
4795     * @param jobId The ID of the job.
4796     * @return A <code>ScanJobInfo</code> instance providing information
4797     * about the specified job.
4798     * @throws IOException If some I/O error occurs.
4799     * @throws LscpException If LSCP protocol corruption occurs.
4800     * @throws LSException If the specified job is not found.
4801     */
4802     public synchronized ScanJobInfo
4803     getDbInstrumentsJobInfo(int jobId) throws IOException, LscpException, LSException {
4804     verifyConnection();
4805     out.writeLine("GET DB_INSTRUMENTS_JOB INFO " + String.valueOf(jobId));
4806     if(getPrintOnlyMode()) return null;
4807    
4808     ResultSet rs = getMultiLineResultSet();
4809     ScanJobInfo info = new ScanJobInfo(rs.getMultiLineResult());
4810    
4811     return info;
4812     }
4813    
4814     /**
4815 iliev 1354 * Removes all instruments and directories and re-creates
4816     * the instruments database structure.
4817     * @throws IOException If some I/O error occurs.
4818     * @throws LscpException If LSCP protocol corruption occurs.
4819     * @throws LSException If the formatting of the instruments database failed.
4820     */
4821     public synchronized void
4822     formatInstrumentsDb() throws IOException, LscpException, LSException {
4823     verifyConnection();
4824     out.writeLine("FORMAT INSTRUMENTS_DB");
4825     if(getPrintOnlyMode()) return;
4826    
4827     ResultSet rs = getEmptyResultSet();
4828     }
4829    
4830     /**
4831 iliev 596 * Resets the specified sampler channel.
4832     *
4833     * @param samplerChn The sampler channel number.
4834     *
4835     * @throws IOException If some I/O error occurs.
4836     * @throws LscpException If LSCP protocol corruption occurs.
4837     * @throws LSException If <code>samplerChn</code> is not a valid channel number or if
4838     * there is no engine assigned yet to the specified sampler channel.
4839     * @see #getSamplerChannels
4840     */
4841     public synchronized void
4842     resetChannel(int samplerChn) throws IOException, LscpException, LSException {
4843     verifyConnection();
4844     out.writeLine("RESET CHANNEL " + samplerChn);
4845 iliev 1139 if(getPrintOnlyMode()) return;
4846 iliev 596
4847     ResultSet rs = getEmptyResultSet();
4848     }
4849    
4850     /**
4851     * Resets the whole sampler.
4852     *
4853     * @throws IOException If some I/O error occurs.
4854     * @throws LscpException If LSCP protocol corruption occurs.
4855     */
4856     public synchronized void
4857     resetSampler() throws IOException, LscpException {
4858     verifyConnection();
4859     out.writeLine("RESET");
4860 iliev 1139 if(getPrintOnlyMode()) return;
4861    
4862 iliev 596 try { ResultSet rs = getEmptyResultSet(); }
4863     catch(LSException x) { getLogger().warning(x.getMessage()); }
4864     }
4865    
4866     /**
4867 iliev 784 * Gets the current number of all active voices.
4868     * @return The current number of all active voices.
4869     * @throws IOException If some I/O error occurs.
4870     * @throws LscpException If LSCP protocol corruption occurs.
4871     * @throws LSException If some other error occurs.
4872     */
4873     public synchronized int
4874     getTotalVoiceCount() throws IOException, LscpException, LSException {
4875     verifyConnection();
4876     out.writeLine("GET TOTAL_VOICE_COUNT");
4877 iliev 1139 if(getPrintOnlyMode()) return -1;
4878    
4879 iliev 784 String s = getSingleLineResultSet().getResult();
4880     return parseInt(s);
4881     }
4882    
4883     /**
4884     * Gets the maximum number of active voices.
4885     * @return The maximum number of active voices.
4886     * @throws IOException If some I/O error occurs.
4887     * @throws LscpException If LSCP protocol corruption occurs.
4888     * @throws LSException If some other error occurs.
4889     */
4890     public synchronized int
4891     getTotalVoiceCountMax() throws IOException, LscpException, LSException {
4892     verifyConnection();
4893     out.writeLine("GET TOTAL_VOICE_COUNT_MAX");
4894 iliev 1139 if(getPrintOnlyMode()) return -1;
4895    
4896 iliev 784 String s = getSingleLineResultSet().getResult();
4897     return parseInt(s);
4898     }
4899    
4900     /**
4901 iliev 596 * Gets information about the LinuxSampler instance.
4902     *
4903     * @return <code>ServerInfo</code> instance containing
4904     * information about the LinuxSampler instance.
4905     *
4906     * @throws IOException If an I/O error occurs.
4907     * @throws LscpException If LSCP protocol corruption occurs.
4908     * @throws LSException If some other error occurs.
4909     */
4910     public synchronized ServerInfo
4911     getServerInfo() throws IOException, LscpException, LSException {
4912     verifyConnection();
4913     out.writeLine("GET SERVER INFO");
4914 iliev 1139 if(getPrintOnlyMode()) return null;
4915    
4916 iliev 596 ResultSet rs = getMultiLineResultSet();
4917     return new ServerInfo(rs.getMultiLineResult());
4918     }
4919    
4920     /**
4921 iliev 1139 * Gets the golobal volume of the sampler.
4922     * @return The golobal volume of the sampler.
4923     * @throws IOException If some I/O error occurs.
4924     * @throws LscpException If LSCP protocol corruption occurs.
4925     * @throws LSException If some other error occurs.
4926     */
4927     public synchronized float
4928     getVolume() throws IOException, LscpException, LSException {
4929     verifyConnection();
4930     out.writeLine("GET VOLUME");
4931     if(getPrintOnlyMode()) return -1;
4932    
4933     String s = getSingleLineResultSet().getResult();
4934     return parseFloat(s);
4935     }
4936    
4937     /**
4938     * Sets the global volume of the sampler.
4939     * @param volume The new volume value.
4940     * @throws IOException If some I/O error occurs.
4941     * @throws LscpException If LSCP protocol corruption occurs.
4942     * @throws LSException If some other error occurs.
4943     * @see #getVolume
4944     */
4945     public synchronized void
4946     setVolume(float volume) throws IOException, LscpException, LSException {
4947    
4948     verifyConnection();
4949     out.writeLine("SET VOLUME " + volume);
4950     if(getPrintOnlyMode()) return;
4951    
4952     ResultSet rs = getEmptyResultSet();
4953     }
4954    
4955 iliev 1202 private void
4956     getEmptyResultSets(int count, String err) throws LSException {
4957     StringBuffer sb = new StringBuffer();
4958     for(int i = 0; i < count; i++) {
4959     try { getEmptyResultSet(); }
4960     catch (SocketTimeoutException e) {
4961     getLogger().log(Level.FINE, e.getMessage(), e);
4962     sb.append(e.getMessage()).append("\n");
4963     break;
4964     } catch (Exception e) {
4965     getLogger().log(Level.FINE, e.getMessage(), e);
4966     sb.append(e.getMessage()).append("\n");
4967     }
4968     }
4969    
4970     String details = sb.toString();
4971     if(details.length() > 0) {
4972     String s = LscpI18n.getLogMsg(err);
4973     throw new LSException(0, s, details);
4974     }
4975     }
4976    
4977 iliev 1139 /**
4978 iliev 596 * Returns the logger for this library.
4979     * @return The logger for this library.
4980     */
4981     protected static Logger
4982     getLogger() { return Logger.getLogger("org.linuxsampler.lscp"); }
4983     }

  ViewVC Help
Powered by ViewVC