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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 671 - (show annotations) (download)
Wed Jun 22 06:18:33 2005 UTC (18 years, 9 months ago) by iliev
File size: 2897 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 * This class creates one MIDI input device, one audio output device and one sampler channel.
33 * Then set the MIDI input device and the audio output device of the created sampler channel
34 * with the newly created devices. Loads sampler engine and the specified instrument.
35 * @author Grigor Iliev
36 */
37 public class CreateChannel {
38 public static void
39 main(String[] args) {
40 if(args.length != 2) {
41 System.out.println("Usage: CreateChannel instrument-file instrument-index");
42 return;
43 }
44
45 initLogger();
46 Client client = new Client();
47
48 try {
49 client.connect();
50
51 int mDev, aDev, chn;
52
53 // Creates new MIDI input device using the first availble MIDI driver
54 mDev =client.createMidiInputDevice (
55 client.getMidiInputDrivers()[0].getName()
56 );
57
58 // Creates new audio output device using the first audio output driver
59 aDev = client.createAudioOutputDevice (
60 client.getAudioOutputDrivers()[0].getName()
61 );
62
63 // Creates new sampler channel
64 chn = client.addSamplerChannel();
65
66 // Setting the MIDI input device of the channel
67 client.setChannelMidiInputDevice(chn, mDev);
68
69 // Setting the audio output device of the channel
70 client.setChannelAudioOutputDevice(chn, aDev);
71
72 // Setting the engine type
73 client.loadSamplerEngine(client.getEngines()[0].getName(), chn);
74
75 // Loading instrument
76 client.loadInstrument(args[0], Integer.parseInt(args[1]), chn);
77
78 client.disconnect();
79 System.exit(0);
80 } catch(Exception x) {
81 x.printStackTrace();
82 }
83
84 System.exit(-1);
85 }
86
87 private static void
88 initLogger() {
89 final Handler handler = new StreamHandler(System.out, new SimpleFormatter());
90 Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
91
92 // Flushing logs on every second
93 new java.util.Timer().schedule(new java.util.TimerTask() {
94 public void
95 run() { handler.flush(); }
96 }, 1000, 1000);
97 }
98 }

  ViewVC Help
Powered by ViewVC