/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/FloatListParameter.java
ViewVC logotype

Annotation of /jlscp/trunk/src/org/linuxsampler/lscp/FloatListParameter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1393 - (hide annotations) (download)
Sun Oct 7 20:29:41 2007 UTC (16 years, 6 months ago) by iliev
File size: 4268 byte(s)
* added extended escape sequences support

1 iliev 596 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4 iliev 1139 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 596 *
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     * This class implements the <code>Parameter&lt;Float[]&gt;</code> interface.
27     * @author Grigor Iliev
28     */
29     public class FloatListParameter extends AbstractParameter<Float[]> {
30     /** Creates a new instance of <code>FloatListParameter</code> */
31     public
32     FloatListParameter() {
33     setType(ParameterType.FLOAT_LIST);
34     setMultiplicity(true);
35     }
36    
37     /**
38     * Creates a <code>FloatListParameter</code> instance with the specified name.
39     * @param name The parameter name.
40     */
41     public
42     FloatListParameter(String name) {
43     this(name, null);
44     }
45    
46     /**
47     * Creates a <code>FloatListParameter</code> instance with the specified name and value.
48     * @param name The parameter name.
49     * @param value The parameter value.
50     */
51     public
52     FloatListParameter(String name, Float[] value) {
53     this();
54     setName(name);
55     setValue(value);
56     }
57    
58     /**
59     * Creates a new instance of <code>FloatListParameter</code>
60     * and parses the specified lines.
61     * @param lnS A <code>String</code> array with lines to be parsed.
62     * @throws LscpException If the parse fail.
63     */
64     protected
65     FloatListParameter(String[] lnS) throws LscpException {
66     this();
67     parseLines(lnS);
68     }
69    
70     /**
71     * Parses a line of text.
72     * @param s The string to be parsed.
73     * @return <code>true</code> if the line has been processed, <code>false</code> otherwise.
74     * @throws LscpException If some error occurs.
75     */
76     public boolean
77     parse(String s) throws LscpException {
78     if(super.parse(s)) return true;
79     else if(s.startsWith("RANGE_MIN: ")) {
80     s = s.substring("RANGE_MIN: ".length(), s.length());
81     try {
82     setRangeMin(Float.parseFloat(s));
83     return true;
84     } catch(NumberFormatException x) { throw new LscpException (
85     LscpI18n.getLogMsg("notFloat!", "RANGE_MIN"), x
86     );}
87     } else if(s.startsWith("RANGE_MAX: ")) {
88     s = s.substring("RANGE_MAX: ".length(), s.length());
89     try {
90     setRangeMax(Float.parseFloat(s));
91     return true;
92     } catch(NumberFormatException x) { throw new LscpException (
93     LscpI18n.getLogMsg("notFloat!", "RANGE_MAX"), x
94     );}
95     } else if(s.startsWith("DEFAULT: ")) {
96     s = s.substring("DEFAULT: ".length(), s.length());
97     try {
98     setDefault(Parser.parseFloatList(s));
99     return true;
100     } catch(NumberFormatException x) { throw new LscpException (
101     LscpI18n.getLogMsg("notFloat!", "DEFAULT"), x
102     );}
103     } else if(s.startsWith("POSSIBILITIES: ")) {
104     s = s.substring("POSSIBILITIES: ".length(), s.length());
105    
106 iliev 1393 String[] sS = Parser.parseStringList(s);
107 iliev 596 Float[][] f2S = new Float[sS.length][];
108     for(int i = 0; i < sS.length; i++) f2S[i] = Parser.parseFloatList(sS[i]);
109     setPossibilities(f2S);
110    
111     return true;
112     }
113    
114     return false;
115     }
116    
117     /**
118     * Parses the specified character string and sets the value of this parameter
119     * with the parsed result.
120     * @param s A character string containing the value to be parsed.
121     * @throws LscpException If the parsing failed.
122     */
123     public void
124     parseValue(String s) throws LscpException {
125     setValue(Parser.parseFloatList(s));
126     }
127    
128     /**
129     * Gets a character string representation of the parameter's value.
130     * @return A character string representation of the parameter's value.
131     */
132     public String
133     getStringValue() {
134     Float[] ar = getValue();
135    
136     if(ar == null || ar.length == 0) return "";
137    
138     StringBuffer sb = new StringBuffer();
139     sb.append(ar[0]);
140    
141     for(int i = 1; i < ar.length; i++) sb.append(',').append(ar[i]);
142    
143     return sb.toString();
144     }
145     }

  ViewVC Help
Powered by ViewVC