/[svn]/jlscp/branches/jlscp_0_3a/src/org/linuxsampler/lscp/SamplerChannel.java
ViewVC logotype

Annotation of /jlscp/branches/jlscp_0_3a/src/org/linuxsampler/lscp/SamplerChannel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 785 - (hide annotations) (download)
Mon Oct 10 14:55:45 2005 UTC (18 years, 6 months ago) by (unknown author)
File size: 9774 byte(s)
This commit was manufactured by cvs2svn to create branch 'jlscp_0_3a'.
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     package org.linuxsampler.lscp;
24    
25     /**
26     * Provides information about current settings of a specific sampler channel.
27     * @author Grigor Iliev
28     */
29     public class SamplerChannel implements Parseable {
30 iliev 784 /** Indicates that the channel is muted because of the presence of a solo channel. */
31     private final static int MUTED_BY_SOLO = -1;
32    
33 iliev 596 private int chnID = -1;
34    
35 iliev 784 private SamplerEngine engine = null;
36 iliev 596 private int aoDevice = -1;
37     private int aoChannels = 0;
38     private Integer[] aor = null;
39     private String instrFile = null;
40     private int instrIdx = 0;
41     private String instrName = null;
42     private int instrStat = 0;
43     private int miDev = -1;
44     private int miPort = 0;
45     private int miChn = -1;
46     private float vol = 0;
47 iliev 784 private int mute = 0;
48     private boolean solo = false;
49 iliev 596
50     /** Creates a new instance of SamplerChannel */
51     public
52     SamplerChannel() {
53     }
54    
55     /**
56     * Creates a new instance of <code>SamplerChannel</code> and parses the information
57     * about a specific sampler channel described by <code>resultSet</code>.
58     * @param resultSet An array with information categories about a sampler channel.
59     * @throws LscpException If the parse fail.
60     */
61     public
62     SamplerChannel(String[] resultSet) throws LscpException {
63     for(String s : resultSet)
64     if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s));
65     }
66    
67     /**
68     * Gets the sampler channel number.
69     * @return The sampler channel number or -1 if the sampler channel number is not set.
70     */
71     public int
72     getChannelID() { return chnID; }
73    
74     /**
75     * Sets the sampler channel number.
76     * @param id The new sampler channel number.
77     */
78     public void
79     setChannelID(int id) { chnID = id; }
80    
81     /**
82 iliev 784 * Gets the engine that is deployed on the sampler channel.
83     * @return The engine that is deployed on the sampler channel
84 iliev 596 * or <code>null</code> if there is no engine deployed yet for this sampler channel.
85     */
86 iliev 784 public SamplerEngine
87     getEngine() { return engine; }
88 iliev 596
89     /**
90 iliev 784 * Associates the specified sampler engine to this sampler channel.
91     * @param engine A <code>SamplerEngine</code> instance containing the information
92     * about the engine to be assigned to this channel.
93     */
94     public void
95     setEngine(SamplerEngine engine) { this.engine = engine; }
96    
97     /**
98 iliev 596 * Gets the numerical ID of the audio output device which is currently connected
99     * to this sampler channel to output the audio signal.
100     *
101     * @return The numerical ID of the audio output device or -1 if there is no
102     * device connected to this sampler channel.
103     */
104     public int
105     getAudioOutputDevice() { return aoDevice; }
106    
107     /**
108     * Gets the number of output channels the sampler channel offers.
109     * @return The number of output channels the sampler channel offers.
110     */
111     public int
112     getAudioOutputChannels() { return aoChannels; }
113    
114     /**
115     * Gets a list which reflects to which audio channel of the selected audio output device
116     * each sampler output channel is routed to.
117     * @return A list which reflects to which audio channel of the selected audio output device
118     * each sampler output channel is routed to.
119     */
120     public Integer[]
121     getAudioOutputRouting() { return aor; }
122    
123     /**
124     * Gets the file name of the loaded instrument.
125     * @return The file name of the loaded instrument.
126     * or <code>null</code> if there is no instrument yet loaded for this sampler channel.
127     */
128     public String
129     getInstrumentFile() { return instrFile; }
130    
131     /**
132     * Gets the instrument index number of the loaded instrument.
133     * @return The instrument index number of the loaded instrument.
134     */
135     public int
136     getInstrumentIndex() { return instrIdx; }
137    
138     /**
139 iliev 784 * Gets the name of the loaded instrument.
140     * @return The name of the loaded instrument or
141     * <code>null</code> if there is no instrument loaded.
142 iliev 596 */
143     public String
144     getInstrumentName() { return instrName; }
145    
146     /**
147     * Gets the instrument status - an integer values from 0 to 100 indicating loading
148     * progress percentage for the instrument. Negative value indicates a loading exception.
149     * Value of 100 indicates that the instrument is fully loaded.
150     * @return The instrument status.
151     */
152     public int
153     getInstrumentStatus() { return instrStat; }
154    
155     /**
156     * Gets the numerical ID of the MIDI input device which is currently connected
157     * to this sampler channel to deliver MIDI input commands.
158     * @return The numerical ID of the MIDI input device which is currently connected
159     * to this sampler channel to deliver MIDI input commands or -1 if there is no device
160     * connected to this sampler channel.
161     */
162     public int
163     getMidiInputDevice() { return miDev; }
164    
165     /**
166     * Gets the port number of the MIDI input device.
167     * @return The port number of the MIDI input device.
168     */
169     public int
170     getMidiInputPort() { return miPort; }
171    
172     /**
173     * Gets the MIDI input channel number this sampler channel should listen to
174     * or -1 to listen on all MIDI channels.
175     * @return The MIDI input channel number this sampler channel should listen to
176     * or -1 to listen on all MIDI channels.
177     */
178     public int
179     getMidiInputChannel() { return miChn; }
180    
181     /**
182     * Gets the channel volume factor. Value less then 1.0 means attenuation,
183     * value greater then 1.0 means amplification.
184     * @return The channel volume factor.
185     */
186     public float
187     getVolume() { return vol; }
188    
189     /**
190 iliev 784 * Determines whether this channel is muted.
191     * @return <code>true</code> if the channel is muted, <code>false</code> otherwise.
192     */
193     public boolean
194     isMuted() { return mute != 0; }
195    
196     /**
197     * Determines whether this channel is muted because of the presence of a solo channel.
198     * All channels, muted because of the presence of a solo channel, will be
199     * automatically unmuted when there are no solo channels left.
200     * @return <code>true</code> if the channel is muted because of the presence of a solo
201     * channel, <code>false</code> otherwise.
202     */
203     public boolean
204     isMutedBySolo() { return mute == MUTED_BY_SOLO; }
205    
206     /**
207     * Determines whether this channel is a solo channel.
208     * @return <code>true</code> if the channel is a solo channel, <code>false</code> otherwise.
209     */
210     public boolean
211     isSoloChannel() { return solo; }
212    
213     /**
214 iliev 596 * Parses a line of text.
215     * @param s The string to be parsed.
216     * @return <code>true</code> if the line has been processed, <code>false</code> otherwise.
217     * @throws LscpException If some error occurs.
218     */
219     public boolean
220     parse(String s) throws LscpException {
221     if(s.startsWith("ENGINE_NAME: ")) {
222     s = s.substring("ENGINE_NAME: ".length());
223     if(s.equals("NONE")) engine = null;
224 iliev 784 else {
225     engine = new SamplerEngine();
226     engine.setName(s);
227     }
228 iliev 596 } else if(s.startsWith("AUDIO_OUTPUT_DEVICE: ")) {
229     s = s.substring("AUDIO_OUTPUT_DEVICE: ".length());
230     if(s.equals("NONE")) aoDevice = -1;
231     else aoDevice = Parser.parseInt(s);
232     } else if(s.startsWith("AUDIO_OUTPUT_CHANNELS: ")) {
233     s = s.substring("AUDIO_OUTPUT_CHANNELS: ".length());
234     if(s.equals("NONE")) aoChannels = -1;
235     else aoChannels = Parser.parseInt(s);
236     } else if(s.startsWith("AUDIO_OUTPUT_ROUTING: ")) {
237     s = s.substring("AUDIO_OUTPUT_ROUTING: ".length());
238     aor = Parser.parseIntList(s);
239     } else if(s.startsWith("INSTRUMENT_FILE: ")) {
240     s = s.substring("INSTRUMENT_FILE: ".length());
241     if(s.equals("NONE")) instrFile = null;
242     else instrFile = s;
243     } else if(s.startsWith("INSTRUMENT_NR: ")) {
244     s = s.substring("INSTRUMENT_NR: ".length());
245     if(s.equals("NONE")) instrIdx = -1;
246     else instrIdx = Parser.parseInt(s);
247     } else if(s.startsWith("INSTRUMENT_NAME: ")) {
248 iliev 784 s = s.substring("INSTRUMENT_NAME: ".length());
249     if(s.equals("NONE")) instrName = null;
250     else instrName = s;
251 iliev 596 } else if(s.startsWith("INSTRUMENT_STATUS: ")) {
252     s = s.substring("INSTRUMENT_STATUS: ".length());
253     instrStat = Parser.parseInt(s);
254     } else if(s.startsWith("MIDI_INPUT_DEVICE: ")) {
255     s = s.substring("MIDI_INPUT_DEVICE: ".length());
256     if(s.equals("NONE")) miDev = -1;
257     else miDev = Parser.parseInt(s);
258     } else if(s.startsWith("MIDI_INPUT_PORT: ")) {
259     s = s.substring("MIDI_INPUT_PORT: ".length());
260     if(s.equals("NONE")) miPort = -1;
261     else miPort = Parser.parseInt(s);
262     } else if(s.startsWith("MIDI_INPUT_CHANNEL: ")) {
263     s = s.substring("MIDI_INPUT_CHANNEL: ".length());
264     if(s.equals("ALL")) miChn = -1;
265     else miChn = Parser.parseInt(s);
266     } else if(s.startsWith("VOLUME: ")) {
267     s = s.substring("VOLUME: ".length());
268     try { vol = Float.parseFloat(s); }
269     catch(NumberFormatException x) { throw new LscpException (
270     LscpI18n.getLogMsg("CommandFailed!"), x
271     );}
272 iliev 784 } else if(s.startsWith("MUTE: ")) {
273     s = s.substring("MUTE: ".length());
274     if(s.equals("MUTED_BY_SOLO")) mute = MUTED_BY_SOLO;
275     else mute = Boolean.parseBoolean(s) ? 1 : 0;
276     } else if(s.startsWith("SOLO: ")) {
277     s = s.substring("SOLO: ".length());
278     solo = Boolean.parseBoolean(s);
279 iliev 596 } else return false;
280    
281     return true;
282     }
283 iliev 784
284     /**
285     * Returns the numerical ID of this sampler channel.
286     * @return The numerical ID of this sampler channel.
287     */
288     public String
289     toString() { return String.valueOf(getChannelID()); }
290 iliev 596 }

  ViewVC Help
Powered by ViewVC