/[svn]/jlscp/trunk/examples/Poll.java
ViewVC logotype

Annotation of /jlscp/trunk/examples/Poll.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 784 - (hide annotations) (download)
Mon Oct 10 14:55:44 2005 UTC (18 years, 6 months ago) by iliev
File size: 9601 byte(s)
* Updating to version 0.3a (see ChangeLog)

1 iliev 596 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4     * Copyright (C) 2005 Grigor Kirilov Iliev
5     *
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     import java.util.logging.Handler;
24     import java.util.logging.Logger;
25     import java.util.logging.SimpleFormatter;
26     import java.util.logging.StreamHandler;
27    
28     import org.linuxsampler.lscp.*;
29    
30    
31     /**
32     * Displays information about the current state of running LinuxSampler instance.
33     * @author Grigor Iliev
34     */
35     public class Poll {
36     public static void
37     main(String[] args) {
38     initLogger();
39     Client client = new Client();
40    
41     try {
42     client.connect();
43    
44     poll(client);
45    
46     client.disconnect();
47     System.exit(0);
48     } catch(Exception x) {
49     x.printStackTrace();
50     }
51    
52     System.exit(-1);
53     }
54    
55     private static void
56     poll(Client client) throws java.io.IOException, LscpException, LSException {
57     ServerInfo si = client.getServerInfo();
58     System.out.print("Sampler description: ");
59     System.out.println(si.getDescription());
60     System.out.print("Sampler version: ");
61     System.out.println(si.getVersion());
62     System.out.print("LSCP protocol version: ");
63     System.out.println(si.getProtocolVersion());
64     System.out.println();
65    
66     System.out.print("Number of available audio output drivers: ");
67     System.out.println(client.getAudioOutputDriverCount());
68     System.out.println();
69    
70     System.out.println("Available audio output drivers: ");
71 iliev 671 AudioOutputDriver[] aodS = client.getAudioOutputDrivers();
72     showList(aodS);
73 iliev 596
74     System.out.println();
75    
76 iliev 671 for(AudioOutputDriver d : aodS) {
77     showDriverInfo(d);
78     for(Parameter p : d.getParameters()) showParameterInfo(p);
79 iliev 596 System.out.println();
80     }
81    
82    
83     System.out.print("Number of audio output devices: ");
84     System.out.println(client.getAudioOutputDeviceCount());
85    
86     System.out.print("Numerical IDs of all created audio output devices: ");
87 iliev 784 AudioOutputDevice[] audioDevices = client.getAudioOutputDevices();
88     showCommaList(audioDevices);
89 iliev 596 System.out.println();
90    
91 iliev 784 for(AudioOutputDevice d : audioDevices) {
92 iliev 596 System.out.println();
93 iliev 784 showAODeviceInfo(d);
94 iliev 596
95 iliev 784 for(int j = 0; j < d.getChannelCount(); j++) {
96     AudioOutputChannel aoc =
97     client.getAudioOutputChannelInfo(d.getDeviceID(), j);
98 iliev 596 System.out.println(" Channel: " + aoc.getName());
99     if(aoc.isMixChannel()) System.out.println (
100     " Mix channel destincation: " + aoc.getMixChannelDest()
101     );
102     if(aoc.hasAdditionalParameters()) {
103     for(Parameter p : aoc.getAdditionalParameters())
104     showParameterInfo(p);
105     }
106    
107     System.out.println();
108     }
109     }
110    
111     System.out.print("Number of available MIDI input drivers: ");
112     System.out.println(client.getMidiInputDriverCount());
113     System.out.println();
114    
115     System.out.println("Available MIDI input drivers: ");
116 iliev 671 MidiInputDriver[] midS = client.getMidiInputDrivers();
117     showList(midS);
118 iliev 596
119 iliev 671 for(MidiInputDriver d : midS) {
120     showDriverInfo(d);
121     for(Parameter p : d.getParameters()) showParameterInfo(p);
122 iliev 596 System.out.println();
123     }
124    
125     System.out.print("Number of MIDI input devices: ");
126     System.out.println(client.getMidiInputDeviceCount());
127    
128     System.out.print("Numerical IDs of all created MIDI input devices: ");
129 iliev 784 MidiInputDevice[] midiDevices = client.getMidiInputDevices();
130     showCommaList(midiDevices);
131 iliev 596 System.out.println();
132    
133 iliev 784 for(MidiInputDevice d : midiDevices) {
134 iliev 596 System.out.println();
135 iliev 784 showDeviceInfo(d);
136 iliev 596 }
137    
138     System.out.print("Number of sampler channels: ");
139     System.out.println(client.getSamplerChannelCount());
140     System.out.println();
141    
142     System.out.print("Numerical IDs of all created sampler channels: ");
143 iliev 784 Integer[] channels = client.getSamplerChannelIDs();
144 iliev 596 showCommaList(channels);
145     System.out.println();
146     System.out.println();
147     for(int i : channels) {
148     showChannelInfo(client.getSamplerChannelInfo(i));
149     }
150    
151    
152    
153     System.out.print("Number of available engines: ");
154     System.out.println(client.getEngineCount());
155     System.out.println();
156    
157     System.out.println("Available engines:");
158    
159 iliev 671 SamplerEngine[] engines = client.getEngines();
160 iliev 596 showList(engines);
161    
162 iliev 671 for(SamplerEngine se : engines) showEngineInfo(se);
163 iliev 596 }
164    
165     private static void
166     showList(Object[] list) { showList(list, " - "); }
167    
168     private static void
169     showList(Object[] list, String prefix) {
170     for(Object o : list) System.out.println(prefix + o.toString());
171     }
172    
173     private static void
174     showCommaList(Object[] list) { showCommaList(list, ""); }
175    
176     private static void
177     showCommaList(Object[] list, String prefix) {
178     if(list.length == 0) {
179     return;
180     }
181     System.out.print(prefix + "'" + list[0].toString() + "'");
182    
183     for(int i = 1; i < list.length; i++)
184     System.out.print(", '" + list[i].toString() + "'");
185     }
186    
187     private static void
188     showDriverInfo(Driver drv) {
189     System.out.println("Driver: " + drv.getName());
190     System.out.println("Version: " + drv.getVersion());
191     System.out.println("Description: " + drv.getDescription());
192     System.out.println("Driver parameters: ");
193     showList(drv.getParameters());
194    
195     System.out.println();
196     }
197    
198     private static void
199     showAODeviceInfo(AudioOutputDevice aoDevice) {
200     showDeviceInfo(aoDevice);
201     showParameterInfo(aoDevice.getChannelsParameter());
202    
203    
204     }
205    
206     private static void
207     showDeviceInfo(Device device) {
208 iliev 784 System.out.println("Device ID: " + device.getDeviceID());
209 iliev 596 System.out.println(" Driver: " + device.getDriverName());
210     System.out.println(" Active: " + device.isActive());
211     for(Parameter p : device.getAdditionalParameters()) showParameterInfo(p);
212     }
213    
214     private static void
215     showParameterInfo(Parameter p) {
216     System.out.println(" Parameter: " + p.getName());
217     System.out.println(" Type: " + p.getType().name());
218     System.out.println(" Description: " + p.getDescription());
219     if(p.hasDependances()) {
220     System.out.println(" Depends on: ");
221     showList(p.getDependances(), " - ");
222     }
223    
224     switch(p.getType()) {
225     case BOOL:
226     Parameter<Boolean> pb = (Parameter<Boolean>)p;
227    
228     showValue(pb.getValue());
229     if(pb.hasPossibilities()) {
230     System.out.println(" Possibilities: ");
231     showList(pb.getPossibilities(), " - ");
232     }
233     break;
234     case FLOAT:
235     Parameter<Float> pf = (Parameter<Float>)p;
236    
237     showValue(pf.getValue());
238     if(pf.hasPossibilities()) {
239     System.out.println(" Possibilities: ");
240     showList(pf.getPossibilities(), " - ");
241     }
242     break;
243     case INT:
244     Parameter<Integer> pi = (Parameter<Integer>)p;
245    
246     showValue(pi.getValue());
247     if(pi.hasPossibilities()) {
248     System.out.println(" Possibilities: ");
249     showList(pi.getPossibilities(), " - ");
250     }
251     break;
252     case STRING:
253     Parameter<String> ps = (Parameter<String>)p;
254    
255     showValue(ps.getValue());
256     if(ps.hasPossibilities()) {
257     System.out.println(" Possibilities: ");
258     showList(ps.getPossibilities(), " - ");
259     }
260     break;
261     case BOOL_LIST:
262     Parameter<Boolean[]> pbS = (Parameter<Boolean[]>)p;
263    
264     showListValue(pbS.getValue());
265    
266     if(pbS.hasPossibilities()) showPossibilities(pbS.getPossibilities());
267     break;
268     case FLOAT_LIST:
269     Parameter<Float[]> pfS = (Parameter<Float[]>)p;
270    
271     showListValue(pfS.getValue());
272    
273     if(pfS.hasPossibilities()) showPossibilities(pfS.getPossibilities());
274     break;
275     case INT_LIST:
276     Parameter<Integer[]> piS = (Parameter<Integer[]>)p;
277    
278     showListValue(piS.getValue());
279    
280     if(piS.hasPossibilities()) showPossibilities(piS.getPossibilities());
281     break;
282     case STRING_LIST:
283     Parameter<String[]> psS = (Parameter<String[]>)p;
284    
285     showListValue(psS.getValue());
286    
287     if(p.hasPossibilities()) showPossibilities(psS.getPossibilities());
288     break;
289     default: throw new RuntimeException("Unknown parameter type");
290     }
291    
292     System.out.println();
293     }
294    
295     private static void
296     showValue(Object o) { if(o != null) System.out.println(" Value: " + o); }
297    
298     private static void
299     showListValue(Object[] objs) {
300     if(objs != null) {
301     System.out.print( " Value: ");
302     showCommaList(objs);
303     System.out.println();
304     }
305     }
306    
307     private static void
308     showPossibilities(Object[][] args) {
309     System.out.println(" Possibilities: ");
310    
311     for(int i = 0; i < args.length; i++) {
312     System.out.print(" " + (i + 1) + ") ");
313     showCommaList(args[i]);
314     System.out.println();
315     }
316     }
317    
318     private static void
319     showChannelInfo(SamplerChannel channel) {
320     System.out.println("Sampler channel ID: " + channel.getChannelID());
321     System.out.println();
322     }
323    
324     private static void
325     showEngineInfo(SamplerEngine engine) {
326     System.out.println("Engine: " + engine.getName());
327     System.out.println("Version: " + engine.getVersion());
328     System.out.println("Description: " + engine.getDescription());
329    
330     System.out.println();
331     }
332    
333     private static void
334     initLogger() {
335     final Handler handler = new StreamHandler(System.out, new SimpleFormatter());
336     Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
337    
338     // Flushing logs on every second
339     new java.util.Timer().schedule(new java.util.TimerTask() {
340     public void
341     run() { handler.flush(); }
342     }, 1000, 1000);
343     }
344     }

  ViewVC Help
Powered by ViewVC