/[svn]/jlscp/branches/jlscp_0_5a/examples/CreateChannel.java
ViewVC logotype

Annotation of /jlscp/branches/jlscp_0_5a/examples/CreateChannel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 596 - (hide annotations) (download)
Wed Jun 1 07:11:31 2005 UTC (19 years ago) by iliev
Original Path: jlscp/trunk/examples/CreateChannel.java
File size: 2848 byte(s)
The first alpha-release of jlscp

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     * 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(client.getMidiInputDrivers()[0]);
55    
56     // Creates new audio output device using the first audio output driver
57     aDev = client.createAudioOutputDevice(client.getAudioOutputDrivers()[0]);
58    
59     // Creates new sampler channel
60     chn = client.addSamplerChannel();
61    
62     // Setting the MIDI input device of the channel
63     client.setChannelMidiInputDevice(chn, mDev);
64    
65     // Setting the audio output device of the channel
66     client.setChannelAudioOutputDevice(chn, aDev);
67    
68     // Setting the engine type
69     client.loadSamplerEngine(client.getEngines()[0], chn);
70    
71     // Loading instrument
72     client.loadInstrument(args[0], Integer.parseInt(args[1]), chn);
73    
74     client.disconnect();
75     System.exit(0);
76     } catch(Exception x) {
77     x.printStackTrace();
78     }
79    
80     System.exit(-1);
81     }
82    
83     private static void
84     initLogger() {
85     final Handler handler = new StreamHandler(System.out, new SimpleFormatter());
86     Logger.getLogger("org.linuxsampler.lscp").addHandler(handler);
87    
88     // Flushing logs on every second
89     new java.util.Timer().schedule(new java.util.TimerTask() {
90     public void
91     run() { handler.flush(); }
92     }, 1000, 1000);
93     }
94     }

  ViewVC Help
Powered by ViewVC