1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler 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 |
* JSampler 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 JSampler; 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.jsampler.task; |
24 |
|
25 |
import java.util.logging.Level; |
26 |
|
27 |
import org.jsampler.CC; |
28 |
import org.jsampler.HF; |
29 |
|
30 |
import org.linuxsampler.lscp.ServerInfo; |
31 |
import org.linuxsampler.lscp.Instrument; |
32 |
|
33 |
import static org.jsampler.JSI18n.i18n; |
34 |
|
35 |
|
36 |
/** |
37 |
* Provides tasks for managing the global settings of the sampler. |
38 |
* @author Grigor Iliev |
39 |
*/ |
40 |
public class Global { |
41 |
|
42 |
/** Forbits the instantiation of this class. */ |
43 |
private Global() { } |
44 |
|
45 |
/** |
46 |
* This task retrieves information about the LinuxSampler instance. |
47 |
* @author Grigor Iliev |
48 |
*/ |
49 |
public static class GetServerInfo extends EnhancedTask<ServerInfo> { |
50 |
/** Creates a new instance of <code>GetServerInfo</code>. */ |
51 |
public |
52 |
GetServerInfo() { |
53 |
setTitle("Global.GetServerInfo_task"); |
54 |
setDescription(i18n.getMessage("Global.GetServerInfo.desc")); |
55 |
} |
56 |
|
57 |
/** The entry point of the task. */ |
58 |
public void |
59 |
run() { |
60 |
try { setResult(CC.getClient().getServerInfo()); } |
61 |
catch(Exception x) { |
62 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
63 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
/** |
69 |
* This task resets the whole sampler. |
70 |
* @author Grigor Iliev |
71 |
*/ |
72 |
public static class ResetSampler extends EnhancedTask { |
73 |
/** Creates a new instance of <code>ResetSampler</code>. */ |
74 |
public |
75 |
ResetSampler() { |
76 |
setTitle("Global.ResetSampler_task"); |
77 |
setDescription(i18n.getMessage("Global.ResetSampler.desc")); |
78 |
} |
79 |
|
80 |
/** The entry point of the task. */ |
81 |
public void |
82 |
run() { |
83 |
try { CC.getClient().resetSampler(); } |
84 |
catch(Exception x) { |
85 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
86 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
87 |
} |
88 |
} |
89 |
} |
90 |
|
91 |
/** |
92 |
* This task gets the global volume of the sampler. |
93 |
*/ |
94 |
public static class GetVolume extends EnhancedTask<Float> { |
95 |
/** Creates a new instance of <code>GetVolume</code>. */ |
96 |
public |
97 |
GetVolume() { |
98 |
setTitle("Global.GetVolume_task"); |
99 |
setDescription(i18n.getMessage("Global.GetVolume.desc")); |
100 |
} |
101 |
|
102 |
/** The entry point of the task. */ |
103 |
public void |
104 |
run() { |
105 |
try { setResult(CC.getClient().getVolume()); } |
106 |
catch(Exception x) { |
107 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
108 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
|
114 |
/** |
115 |
* This task sets the global volume of the sampler. |
116 |
*/ |
117 |
public static class SetVolume extends EnhancedTask { |
118 |
private float volume; |
119 |
|
120 |
/** |
121 |
* Creates new instance of <code>SetVolume</code>. |
122 |
* @param volume The new volume value. |
123 |
*/ |
124 |
public |
125 |
SetVolume(float volume) { |
126 |
setTitle("Global.SetVolume_task"); |
127 |
setDescription(i18n.getMessage("Global.SetVolume.desc")); |
128 |
this.volume = volume; |
129 |
} |
130 |
|
131 |
/** The entry point of the task. */ |
132 |
public void |
133 |
run() { |
134 |
try { |
135 |
CC.getClient().setVolume(volume); |
136 |
} catch(Exception x) { |
137 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
138 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
139 |
} |
140 |
} |
141 |
} |
142 |
|
143 |
|
144 |
/** |
145 |
* This task sets the LSCP client's read timeout. |
146 |
*/ |
147 |
public static class SetClientReadTimeout extends EnhancedTask { |
148 |
private int timeout; |
149 |
|
150 |
/** |
151 |
* Creates new instance of <code>SetClientReadTimeout</code>. |
152 |
* @param timeout The new timeout value (in seconds). |
153 |
*/ |
154 |
public |
155 |
SetClientReadTimeout(int timeout) { |
156 |
setTitle("Global.SetClientReadTimeout_task"); |
157 |
setDescription(i18n.getMessage("Global.SetClientReadTimeout.desc")); |
158 |
this.timeout = timeout; |
159 |
} |
160 |
|
161 |
/** The entry point of the task. */ |
162 |
public void |
163 |
run() { |
164 |
try { |
165 |
CC.getClient().setSoTimeout(timeout * 1000); |
166 |
} catch(Exception x) { |
167 |
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
168 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
169 |
} |
170 |
} |
171 |
} |
172 |
|
173 |
/** |
174 |
* This task gets the list of instruments in the specified instrument file. |
175 |
*/ |
176 |
public static class GetFileInstruments extends EnhancedTask<Instrument[]> { |
177 |
private final String filename; |
178 |
|
179 |
/** Creates a new instance of <code>GetFileInstruments</code>. */ |
180 |
public |
181 |
GetFileInstruments(String filename) { |
182 |
this.filename = filename; |
183 |
setTitle("Global.GetFileInstruments_task"); |
184 |
setDescription(i18n.getMessage("Global.GetFileInstruments.desc")); |
185 |
} |
186 |
|
187 |
/** The entry point of the task. */ |
188 |
public void |
189 |
run() { |
190 |
try { setResult(CC.getClient().getFileInstruments(filename)); } |
191 |
catch(Exception x) { |
192 |
String s = getDescription() + ": " + HF.getErrorMessage(x); |
193 |
CC.getLogger().log(Level.FINE, s, x); |
194 |
} |
195 |
} |
196 |
} |
197 |
|
198 |
/** |
199 |
* This task gets information about the specified instrument. |
200 |
*/ |
201 |
public static class GetFileInstrument extends EnhancedTask<Instrument> { |
202 |
private final String filename; |
203 |
private final int instrIdx; |
204 |
|
205 |
/** Creates a new instance of <code>GetFileInstrument</code>. */ |
206 |
public |
207 |
GetFileInstrument(String filename, int instrIdx) { |
208 |
this.filename = filename; |
209 |
this.instrIdx = instrIdx; |
210 |
setTitle("Global.GetFileInstrument_task"); |
211 |
setDescription(i18n.getMessage("Global.GetFileInstrument.desc")); |
212 |
} |
213 |
|
214 |
/** The entry point of the task. */ |
215 |
public void |
216 |
run() { |
217 |
try { setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx)); } |
218 |
catch(Exception x) { |
219 |
String s = getDescription() + ": " + HF.getErrorMessage(x); |
220 |
CC.getLogger().log(Level.FINE, s, x); |
221 |
} |
222 |
} |
223 |
} |
224 |
|
225 |
public static class DummyTask extends EnhancedTask { |
226 |
public void |
227 |
run() { } |
228 |
} |
229 |
} |