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<Integer[]></code> interface. |
27 |
|
|
* @author Grigor Iliev |
28 |
|
|
*/ |
29 |
|
|
public class IntListParameter extends AbstractParameter<Integer[]> { |
30 |
|
|
/** Creates a new instance of <code>IntListParameter</code> */ |
31 |
|
|
public |
32 |
|
|
IntListParameter() { |
33 |
|
|
setType(ParameterType.INT_LIST); |
34 |
|
|
setMultiplicity(true); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
/** |
38 |
|
|
* Creates a <code>IntListParameter</code> instance with the specified name. |
39 |
|
|
* @param name The parameter name. |
40 |
|
|
*/ |
41 |
|
|
public |
42 |
|
|
IntListParameter(String name) { |
43 |
|
|
this(name, null); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* Creates a <code>IntListParameter</code> instance with the specified name and value. |
48 |
|
|
* @param name The parameter name. |
49 |
|
|
* @param value The parameter value. |
50 |
|
|
*/ |
51 |
|
|
public |
52 |
|
|
IntListParameter(String name, Integer[] value) { |
53 |
|
|
this(); |
54 |
|
|
setName(name); |
55 |
|
|
setValue(value); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Creates a new instance of <code>IntListParameter</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 |
|
|
public |
65 |
|
|
IntListParameter(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(Integer.parseInt(s)); |
83 |
|
|
return true; |
84 |
|
|
} catch(NumberFormatException x) { throw new LscpException ( |
85 |
|
|
LscpI18n.getLogMsg("notInt!", "RANGE_MIN"), x |
86 |
|
|
);} |
87 |
|
|
} else if(s.startsWith("RANGE_MAX: ")) { |
88 |
|
|
s = s.substring("RANGE_MAX: ".length(), s.length()); |
89 |
|
|
try { |
90 |
|
|
setRangeMax(Integer.parseInt(s)); |
91 |
|
|
return true; |
92 |
|
|
} catch(NumberFormatException x) { throw new LscpException ( |
93 |
|
|
LscpI18n.getLogMsg("notInt!", "RANGE_MAX"), x |
94 |
|
|
);} |
95 |
|
|
} else if(s.startsWith("DEFAULT: ")) { |
96 |
|
|
s = s.substring("DEFAULT: ".length(), s.length()); |
97 |
|
|
try { |
98 |
|
|
setDefault(Parser.parseIntList(s)); |
99 |
|
|
return true; |
100 |
|
|
} catch(NumberFormatException x) { throw new LscpException ( |
101 |
|
|
LscpI18n.getLogMsg("notInt!", "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 |
Integer[][] i2S = new Integer[sS.length][]; |
108 |
|
|
for(int i = 0; i < sS.length; i++) i2S[i] = Parser.parseIntList(sS[i]); |
109 |
|
|
setPossibilities(i2S); |
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.parseIntList(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 |
|
|
Integer[] 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 |
|
|
} |