1 |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
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 |
import static org.linuxsampler.lscp.Parser.*; |
26 |
|
27 |
/** |
28 |
* |
29 |
* @author Grigor Iliev |
30 |
*/ |
31 |
public abstract class AbstractInstrument implements Instrument, Parseable { |
32 |
private String name = "Untitled"; |
33 |
private String description = ""; |
34 |
private String path = null; |
35 |
private int instrumentIndex = 0; |
36 |
private String formatFamily = ""; |
37 |
private String formatVersion = ""; |
38 |
private Integer[] keyMapping = { }; |
39 |
private Integer[] keyswitchMapping = { }; |
40 |
|
41 |
/** |
42 |
* Creates a new instance of <code>AbstractInstrument</code>. |
43 |
*/ |
44 |
public |
45 |
AbstractInstrument() { } |
46 |
|
47 |
/** |
48 |
* Creates a new instance of <code>AbstractInstrument</code>. |
49 |
* @param resultSet An array with information categories about an instrument. |
50 |
*/ |
51 |
public |
52 |
AbstractInstrument(String[] resultSet) throws LscpException { |
53 |
for(String s : resultSet) |
54 |
if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s)); |
55 |
} |
56 |
|
57 |
/** |
58 |
* Gets the name of this instrument. |
59 |
* @return The name of this instrument. |
60 |
*/ |
61 |
public String |
62 |
getName() { return name; } |
63 |
|
64 |
/** |
65 |
* Sets the name of this instrument. |
66 |
* @param name The name of this instrument. |
67 |
*/ |
68 |
public void |
69 |
setName(String name) { this.name = name; } |
70 |
|
71 |
/** |
72 |
* Gets a brief description about this instrument. |
73 |
* @return A brief description about this instrument. |
74 |
*/ |
75 |
public String |
76 |
getDescription() { return description; } |
77 |
|
78 |
/** |
79 |
* Returns the absolute path name of the instrument file. |
80 |
* @return The absolute path name of the instrument file. |
81 |
*/ |
82 |
public String |
83 |
getFilePath() { return path; } |
84 |
|
85 |
/** |
86 |
* Sets the absolute path name of the instrument file. |
87 |
* @param path Specifies the absolute path name of the instrument file. |
88 |
*/ |
89 |
public void |
90 |
setFilePath(String path) { this.path = path; } |
91 |
|
92 |
/** |
93 |
* Returns the index of the instrument in the instrument file. |
94 |
* @return The index of the instrument in the instrument file. |
95 |
*/ |
96 |
public int |
97 |
getInstrumentIndex() { return instrumentIndex; } |
98 |
|
99 |
/** |
100 |
* Sets the index of the instrument in the instrument file. |
101 |
* @param idx The index of the instrument in the instrument file. |
102 |
*/ |
103 |
public void |
104 |
setInstrumentIndex(int idx) { instrumentIndex = idx; } |
105 |
|
106 |
/** |
107 |
* Returns the format family of the instrument. |
108 |
**/ |
109 |
public String |
110 |
getFormatFamily() { return formatFamily; } |
111 |
|
112 |
/** |
113 |
* Returns the format version of the instrument. |
114 |
**/ |
115 |
public String |
116 |
getFormatVersion() { return formatVersion; } |
117 |
|
118 |
public Integer[] |
119 |
getKeyMapping() { return keyMapping; } |
120 |
|
121 |
public Integer[] |
122 |
getKeyswitchMapping() { return keyswitchMapping; } |
123 |
|
124 |
/** |
125 |
* Parses a line of text. |
126 |
* @param s The string to be parsed. |
127 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
128 |
* @throws LscpException If some error occurs. |
129 |
*/ |
130 |
public boolean |
131 |
parse(String s) throws LscpException { |
132 |
if(s.startsWith("NAME: ")) { |
133 |
setName(s.substring("NAME: ".length())); |
134 |
} else if(s.startsWith("DESCRIPTION: ")) { |
135 |
description = s.substring("DESCRIPTION: ".length()); |
136 |
description = toNonEscapedString(description); |
137 |
} else if(s.startsWith("INSTRUMENT_FILE: ")) { |
138 |
setFilePath(s.substring("INSTRUMENT_FILE: ".length())); |
139 |
} else if(s.startsWith("INSTRUMENT_NR: ")) { |
140 |
s = s.substring("INSTRUMENT_NR: ".length()); |
141 |
setInstrumentIndex(Parser.parseInt(s)); |
142 |
} else if(s.startsWith("FORMAT_FAMILY: ")) { |
143 |
formatFamily = s.substring("FORMAT_FAMILY: ".length()); |
144 |
} else if(s.startsWith("FORMAT_VERSION: ")) { |
145 |
formatVersion = s.substring("FORMAT_VERSION: ".length()); |
146 |
} else if(s.startsWith("KEY_BINDINGS: ")) { |
147 |
s = s.substring("KEY_BINDINGS: ".length()); |
148 |
keyMapping = Parser.parseIntList(s); |
149 |
} else if(s.startsWith("KEYSWITCH_BINDINGS: ")) { |
150 |
s = s.substring("KEYSWITCH_BINDINGS: ".length()); |
151 |
keyswitchMapping = Parser.parseIntList(s); |
152 |
} else return false; |
153 |
|
154 |
return true; |
155 |
} |
156 |
} |