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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 671 - (show annotations) (download)
Wed Jun 22 06:18:33 2005 UTC (18 years, 10 months ago) by iliev
File size: 9702 byte(s)
Updating to version 0.2a

1 /*
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 AudioOutputDriver[] aodS = client.getAudioOutputDrivers();
72 showList(aodS);
73
74 System.out.println();
75
76 for(AudioOutputDriver d : aodS) {
77 showDriverInfo(d);
78 for(Parameter p : d.getParameters()) showParameterInfo(p);
79 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 Integer[] devices = client.getAudioOutputDevices();
88 showCommaList(devices);
89 System.out.println();
90
91 for(Integer i : devices) {
92 System.out.println();
93 System.out.println("Audio output device: " + i);
94 AudioOutputDevice aoDevice = client.getAudioOutputDeviceInfo(i);
95 showAODeviceInfo(aoDevice);
96
97 for(int j = 0; j < aoDevice.getChannelCount(); j++) {
98 AudioOutputChannel aoc = client.getAudioOutputChannelInfo(i, j);
99 System.out.println(" Channel: " + aoc.getName());
100 if(aoc.isMixChannel()) System.out.println (
101 " Mix channel destincation: " + aoc.getMixChannelDest()
102 );
103 if(aoc.hasAdditionalParameters()) {
104 for(Parameter p : aoc.getAdditionalParameters())
105 showParameterInfo(p);
106 }
107
108 System.out.println();
109 }
110 }
111
112 System.out.print("Number of available MIDI input drivers: ");
113 System.out.println(client.getMidiInputDriverCount());
114 System.out.println();
115
116 System.out.println("Available MIDI input drivers: ");
117 MidiInputDriver[] midS = client.getMidiInputDrivers();
118 showList(midS);
119
120 for(MidiInputDriver d : midS) {
121 showDriverInfo(d);
122 for(Parameter p : d.getParameters()) showParameterInfo(p);
123 System.out.println();
124 }
125
126 System.out.print("Number of MIDI input devices: ");
127 System.out.println(client.getMidiInputDeviceCount());
128
129 System.out.print("Numerical IDs of all created MIDI input devices: ");
130 devices = client.getMidiInputDevices();
131 showCommaList(devices);
132 System.out.println();
133
134 for(Integer i : devices) {
135 System.out.println();
136 System.out.println("MIDI input device: " + i);
137 MidiInputDevice miDevice = client.getMidiInputDeviceInfo(i);
138 showDeviceInfo(miDevice);
139 }
140
141 System.out.print("Number of sampler channels: ");
142 System.out.println(client.getSamplerChannelCount());
143 System.out.println();
144
145 System.out.print("Numerical IDs of all created sampler channels: ");
146 Integer[] channels = client.getSamplerChannels();
147 showCommaList(channels);
148 System.out.println();
149 System.out.println();
150 for(int i : channels) {
151 showChannelInfo(client.getSamplerChannelInfo(i));
152 }
153
154
155
156 System.out.print("Number of available engines: ");
157 System.out.println(client.getEngineCount());
158 System.out.println();
159
160 System.out.println("Available engines:");
161
162 SamplerEngine[] engines = client.getEngines();
163 showList(engines);
164
165 for(SamplerEngine se : engines) showEngineInfo(se);
166 }
167
168 private static void
169 showList(Object[] list) { showList(list, " - "); }
170
171 private static void
172 showList(Object[] list, String prefix) {
173 for(Object o : list) System.out.println(prefix + o.toString());
174 }
175
176 private static void
177 showCommaList(Object[] list) { showCommaList(list, ""); }
178
179 private static void
180 showCommaList(Object[] list, String prefix) {
181 if(list.length == 0) {
182 return;
183 }
184 System.out.print(prefix + "'" + list[0].toString() + "'");
185
186 for(int i = 1; i < list.length; i++)
187 System.out.print(", '" + list[i].toString() + "'");
188 }
189
190 private static void
191 showDriverInfo(Driver drv) {
192 System.out.println("Driver: " + drv.getName());
193 System.out.println("Version: " + drv.getVersion());
194 System.out.println("Description: " + drv.getDescription());
195 System.out.println("Driver parameters: ");
196 showList(drv.getParameters());
197
198 System.out.println();
199 }
200
201 private static void
202 showAODeviceInfo(AudioOutputDevice aoDevice) {
203 showDeviceInfo(aoDevice);
204 showParameterInfo(aoDevice.getChannelsParameter());
205
206
207 }
208
209 private static void
210 showDeviceInfo(Device device) {
211 System.out.println(" Driver: " + device.getDriverName());
212 System.out.println(" Active: " + device.isActive());
213 for(Parameter p : device.getAdditionalParameters()) showParameterInfo(p);
214 }
215
216 private static void
217 showParameterInfo(Parameter p) {
218 System.out.println(" Parameter: " + p.getName());
219 System.out.println(" Type: " + p.getType().name());
220 System.out.println(" Description: " + p.getDescription());
221 if(p.hasDependances()) {
222 System.out.println(" Depends on: ");
223 showList(p.getDependances(), " - ");
224 }
225
226 switch(p.getType()) {
227 case BOOL:
228 Parameter<Boolean> pb = (Parameter<Boolean>)p;
229
230 showValue(pb.getValue());
231 if(pb.hasPossibilities()) {
232 System.out.println(" Possibilities: ");
233 showList(pb.getPossibilities(), " - ");
234 }
235 break;
236 case FLOAT:
237 Parameter<Float> pf = (Parameter<Float>)p;
238
239 showValue(pf.getValue());
240 if(pf.hasPossibilities()) {
241 System.out.println(" Possibilities: ");
242 showList(pf.getPossibilities(), " - ");
243 }
244 break;
245 case INT:
246 Parameter<Integer> pi = (Parameter<Integer>)p;
247
248 showValue(pi.getValue());
249 if(pi.hasPossibilities()) {
250 System.out.println(" Possibilities: ");
251 showList(pi.getPossibilities(), " - ");
252 }
253 break;
254 case STRING:
255 Parameter<String> ps = (Parameter<String>)p;
256
257 showValue(ps.getValue());
258 if(ps.hasPossibilities()) {
259 System.out.println(" Possibilities: ");
260 showList(ps.getPossibilities(), " - ");
261 }
262 break;
263 case BOOL_LIST:
264 Parameter<Boolean[]> pbS = (Parameter<Boolean[]>)p;
265
266 showListValue(pbS.getValue());
267
268 if(pbS.hasPossibilities()) showPossibilities(pbS.getPossibilities());
269 break;
270 case FLOAT_LIST:
271 Parameter<Float[]> pfS = (Parameter<Float[]>)p;
272
273 showListValue(pfS.getValue());
274
275 if(pfS.hasPossibilities()) showPossibilities(pfS.getPossibilities());
276 break;
277 case INT_LIST:
278 Parameter<Integer[]> piS = (Parameter<Integer[]>)p;
279
280 showListValue(piS.getValue());
281
282 if(piS.hasPossibilities()) showPossibilities(piS.getPossibilities());
283 break;
284 case STRING_LIST:
285 Parameter<String[]> psS = (Parameter<String[]>)p;
286
287 showListValue(psS.getValue());
288
289 if(p.hasPossibilities()) showPossibilities(psS.getPossibilities());
290 break;
291 default: throw new RuntimeException("Unknown parameter type");
292 }
293
294 System.out.println();
295 }
296
297 private static void
298 showValue(Object o) { if(o != null) System.out.println(" Value: " + o); }
299
300 private static void
301 showListValue(Object[] objs) {
302 if(objs != null) {
303 System.out.print( " Value: ");
304 showCommaList(objs);
305 System.out.println();
306 }
307 }
308
309 private static void
310 showPossibilities(Object[][] args) {
311 System.out.println(" Possibilities: ");
312
313 for(int i = 0; i < args.length; i++) {
314 System.out.print(" " + (i + 1) + ") ");
315 showCommaList(args[i]);
316 System.out.println();
317 }
318 }
319
320 private static void
321 showChannelInfo(SamplerChannel channel) {
322 System.out.println("Sampler channel ID: " + channel.getChannelID());
323 System.out.println();
324 }
325
326 private static void
327 showEngineInfo(SamplerEngine engine) {
328 System.out.println("Engine: " + engine.getName());
329 System.out.println("Version: " + engine.getVersion());
330 System.out.println("Description: " + engine.getDescription());
331
332 System.out.println();
333 }
334
335 private static void
336 initLogger() {
337 final Handler handler = new StreamHandler(System.out, new SimpleFormatter());
338 Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
339
340 // Flushing logs on every second
341 new java.util.Timer().schedule(new java.util.TimerTask() {
342 public void
343 run() { handler.flush(); }
344 }, 1000, 1000);
345 }
346 }

  ViewVC Help
Powered by ViewVC