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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 596 - (show annotations) (download)
Wed Jun 1 07:11:31 2005 UTC (18 years, 10 months ago) by iliev
File size: 9819 byte(s)
The first alpha-release of jlscp

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

  ViewVC Help
Powered by ViewVC