1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2011 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 org.jsampler.AudioDeviceModel; |
26 |
import org.jsampler.CC; |
27 |
import org.jsampler.EffectChain; |
28 |
import org.jsampler.SamplerModel; |
29 |
|
30 |
import org.linuxsampler.lscp.Effect; |
31 |
import org.linuxsampler.lscp.EffectChainInfo; |
32 |
import org.linuxsampler.lscp.Instrument; |
33 |
import org.linuxsampler.lscp.SamplerEngine; |
34 |
import org.linuxsampler.lscp.ServerInfo; |
35 |
|
36 |
|
37 |
import static org.jsampler.JSI18n.i18n; |
38 |
|
39 |
|
40 |
/** |
41 |
* Provides tasks for managing the global settings of the sampler. |
42 |
* @author Grigor Iliev |
43 |
*/ |
44 |
public class Global { |
45 |
|
46 |
/** Forbids the instantiation of this class. */ |
47 |
private Global() { } |
48 |
|
49 |
/** |
50 |
* Establishes connection to LinuxSampler. |
51 |
*/ |
52 |
public static class Connect extends EnhancedTask { |
53 |
/** Creates a new instance of <code>Connect</code>. */ |
54 |
public |
55 |
Connect() { |
56 |
setTitle("Global.Connect_task"); |
57 |
setDescription(i18n.getMessage("Global.Connect.desc")); |
58 |
} |
59 |
|
60 |
/** The entry point of the task. */ |
61 |
@Override |
62 |
public void |
63 |
exec() throws Exception { CC.getClient().connect(); } |
64 |
} |
65 |
|
66 |
public static class Disconnect extends EnhancedTask { |
67 |
/** Creates a new instance of <code>Disconnect</code>. */ |
68 |
public |
69 |
Disconnect() { |
70 |
setSilent(true); |
71 |
setTitle("Global.Disconnect_task"); |
72 |
setDescription("Disconnecting..."); |
73 |
} |
74 |
|
75 |
/** The entry point of the task. */ |
76 |
@Override |
77 |
public void |
78 |
exec() throws Exception { |
79 |
CC.getClient().disconnect(); |
80 |
if(CC.getMainFrame().getLSConsoleModel() != null) { |
81 |
CC.getMainFrame().getLSConsoleModel().quit(); |
82 |
} |
83 |
} |
84 |
} |
85 |
|
86 |
/** |
87 |
* This task retrieves information about the LinuxSampler instance. |
88 |
*/ |
89 |
public static class GetServerInfo extends EnhancedTask<ServerInfo> { |
90 |
/** Creates a new instance of <code>GetServerInfo</code>. */ |
91 |
public |
92 |
GetServerInfo() { |
93 |
setTitle("Global.GetServerInfo_task"); |
94 |
setDescription(i18n.getMessage("Global.GetServerInfo.desc")); |
95 |
} |
96 |
|
97 |
/** The entry point of the task. */ |
98 |
@Override |
99 |
public void |
100 |
exec() throws Exception { setResult(CC.getClient().getServerInfo()); } |
101 |
} |
102 |
|
103 |
/** |
104 |
* This task resets the whole sampler. |
105 |
*/ |
106 |
public static class ResetSampler extends EnhancedTask { |
107 |
/** Creates a new instance of <code>ResetSampler</code>. */ |
108 |
public |
109 |
ResetSampler() { |
110 |
setTitle("Global.ResetSampler_task"); |
111 |
setDescription(i18n.getMessage("Global.ResetSampler.desc")); |
112 |
} |
113 |
|
114 |
/** The entry point of the task. */ |
115 |
@Override |
116 |
public void |
117 |
exec() throws Exception { CC.getClient().resetSampler(); } |
118 |
} |
119 |
|
120 |
/** |
121 |
* This task retrieves the list of all available engines. |
122 |
*/ |
123 |
public static class GetEngines extends EnhancedTask<SamplerEngine[]> { |
124 |
/** Creates a new instance of <code>GetEngines</code>. */ |
125 |
public |
126 |
GetEngines() { |
127 |
setTitle("Global.GetEngines_task"); |
128 |
setDescription(i18n.getMessage("Global.GetEngines.desc")); |
129 |
} |
130 |
|
131 |
/** The entry point of the task. */ |
132 |
@Override |
133 |
public void |
134 |
exec() throws Exception { setResult(CC.getClient().getEngines()); } |
135 |
} |
136 |
|
137 |
/** |
138 |
* This task gets the global volume of the sampler. |
139 |
*/ |
140 |
public static class GetVolume extends EnhancedTask<Float> { |
141 |
/** Creates a new instance of <code>GetVolume</code>. */ |
142 |
public |
143 |
GetVolume() { |
144 |
setTitle("Global.GetVolume_task"); |
145 |
setDescription(i18n.getMessage("Global.GetVolume.desc")); |
146 |
} |
147 |
|
148 |
/** The entry point of the task. */ |
149 |
@Override |
150 |
public void |
151 |
exec() throws Exception { setResult(CC.getClient().getVolume()); } |
152 |
} |
153 |
|
154 |
|
155 |
/** |
156 |
* This task sets the global volume of the sampler. |
157 |
*/ |
158 |
public static class SetVolume extends EnhancedTask { |
159 |
private float volume; |
160 |
|
161 |
/** |
162 |
* Creates new instance of <code>SetVolume</code>. |
163 |
* @param volume The new volume value. |
164 |
*/ |
165 |
public |
166 |
SetVolume(float volume) { |
167 |
setTitle("Global.SetVolume_task"); |
168 |
setDescription(i18n.getMessage("Global.SetVolume.desc")); |
169 |
this.volume = volume; |
170 |
} |
171 |
|
172 |
/** The entry point of the task. */ |
173 |
@Override |
174 |
public void |
175 |
exec() throws Exception { CC.getClient().setVolume(volume); } |
176 |
} |
177 |
|
178 |
|
179 |
/** |
180 |
* This task sets the global sampler-wide limits of maximum voices and streams. |
181 |
*/ |
182 |
public static class SetPolyphony extends EnhancedTask { |
183 |
private int maxVoices; |
184 |
private int maxStreams; |
185 |
|
186 |
/** |
187 |
* Creates new instance of <code>SetPolyphony</code>. |
188 |
* @param maxVoices The new global limit of maximum voices or |
189 |
* <code>-1</code> to ignore it. |
190 |
* @param maxStreams The new global limit of maximum disk streams or |
191 |
* <code>-1</code> to ignore it. |
192 |
*/ |
193 |
public |
194 |
SetPolyphony(int maxVoices, int maxStreams) { |
195 |
setTitle("Global.SetPolyphony_task"); |
196 |
setDescription(i18n.getMessage("Global.SetPolyphony.desc")); |
197 |
this.maxVoices = maxVoices; |
198 |
this.maxStreams = maxStreams; |
199 |
} |
200 |
|
201 |
/** The entry point of the task. */ |
202 |
@Override |
203 |
public void |
204 |
exec() throws Exception { |
205 |
if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices); |
206 |
if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams); |
207 |
} |
208 |
} |
209 |
|
210 |
/** |
211 |
* This task updates the current number of all active voices |
212 |
* and the maximum number of active voices allowed. |
213 |
*/ |
214 |
public static class UpdateTotalVoiceCount extends EnhancedTask { |
215 |
/** Creates a new instance of <code>UpdateTotalVoiceCount</code>. */ |
216 |
public |
217 |
UpdateTotalVoiceCount() { |
218 |
setSilent(true); |
219 |
setTitle("Global.UpdateTotalVoiceCount_task"); |
220 |
setDescription(i18n.getMessage("Global.UpdateTotalVoiceCount.desc")); |
221 |
} |
222 |
|
223 |
/** The entry point of the task. */ |
224 |
@Override |
225 |
public void |
226 |
exec() throws Exception { |
227 |
SamplerModel sm = CC.getSamplerModel(); |
228 |
int voices = CC.getClient().getTotalVoiceCount(); |
229 |
int voicesMax = CC.getClient().getTotalVoiceCountMax(); |
230 |
sm.updateActiveVoiceInfo(voices, voicesMax); |
231 |
} |
232 |
|
233 |
/** |
234 |
* Used to decrease the traffic. All task in the queue |
235 |
* equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}. |
236 |
* @see org.jsampler.CC#addTask |
237 |
*/ |
238 |
@Override |
239 |
public boolean |
240 |
equals(Object obj) { |
241 |
if(obj == null) return false; |
242 |
if(!(obj instanceof UpdateTotalVoiceCount)) return false; |
243 |
|
244 |
return true; |
245 |
} |
246 |
} |
247 |
|
248 |
|
249 |
/** |
250 |
* This task sets the LSCP client's read timeout. |
251 |
*/ |
252 |
public static class SetClientReadTimeout extends EnhancedTask { |
253 |
private int timeout; |
254 |
|
255 |
/** |
256 |
* Creates new instance of <code>SetClientReadTimeout</code>. |
257 |
* @param timeout The new timeout value (in seconds). |
258 |
*/ |
259 |
public |
260 |
SetClientReadTimeout(int timeout) { |
261 |
setTitle("Global.SetClientReadTimeout_task"); |
262 |
setDescription(i18n.getMessage("Global.SetClientReadTimeout.desc")); |
263 |
this.timeout = timeout; |
264 |
} |
265 |
|
266 |
/** The entry point of the task. */ |
267 |
@Override |
268 |
public void |
269 |
exec() throws Exception { CC.getClient().setSoTimeout(timeout * 1000); } |
270 |
} |
271 |
|
272 |
/** |
273 |
* This task gets the list of instruments in the specified instrument file. |
274 |
*/ |
275 |
public static class GetFileInstruments extends EnhancedTask<Instrument[]> { |
276 |
private final String filename; |
277 |
|
278 |
/** Creates a new instance of <code>GetFileInstruments</code>. */ |
279 |
public |
280 |
GetFileInstruments(String filename) { |
281 |
setSilent(true); |
282 |
this.filename = filename; |
283 |
setTitle("Global.GetFileInstruments_task"); |
284 |
setDescription(i18n.getMessage("Global.GetFileInstruments.desc")); |
285 |
} |
286 |
|
287 |
/** The entry point of the task. */ |
288 |
@Override |
289 |
public void |
290 |
exec() throws Exception { |
291 |
setResult(CC.getClient().getFileInstruments(filename)); |
292 |
} |
293 |
} |
294 |
|
295 |
/** |
296 |
* This task gets information about the specified instrument. |
297 |
*/ |
298 |
public static class GetFileInstrument extends EnhancedTask<Instrument> { |
299 |
private final String filename; |
300 |
private final int instrIdx; |
301 |
|
302 |
/** Creates a new instance of <code>GetFileInstrument</code>. */ |
303 |
public |
304 |
GetFileInstrument(String filename, int instrIdx) { |
305 |
setSilent(true); |
306 |
this.filename = filename; |
307 |
this.instrIdx = instrIdx; |
308 |
setTitle("Global.GetFileInstrument_task"); |
309 |
setDescription(i18n.getMessage("Global.GetFileInstrument.desc")); |
310 |
} |
311 |
|
312 |
/** The entry point of the task. */ |
313 |
@Override |
314 |
public void |
315 |
exec() throws Exception { |
316 |
setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx)); |
317 |
} |
318 |
} |
319 |
|
320 |
/** |
321 |
* This task retrieves the list of internal effects, available to the sampler. |
322 |
*/ |
323 |
public static class GetEffects extends EnhancedTask<Effect[]> { |
324 |
/** Creates a new instance of <code>GetEffects</code>. */ |
325 |
public |
326 |
GetEffects() { |
327 |
setTitle("Global.GetEffects_task"); |
328 |
setDescription(i18n.getMessage("Global.GetEffects.desc")); |
329 |
} |
330 |
|
331 |
/** The entry point of the task. */ |
332 |
@Override |
333 |
public void |
334 |
exec() throws Exception { setResult(CC.getClient().getEffects()); } |
335 |
} |
336 |
|
337 |
/** |
338 |
* This task updates the send effect chains and the effect instances in those chains. |
339 |
*/ |
340 |
public static class UpdateSendEffectChains extends EnhancedTask { |
341 |
private final int audioDeviceId; |
342 |
|
343 |
/** Creates a new instance of <code>UpdateSendEffectChains</code>. */ |
344 |
public |
345 |
UpdateSendEffectChains() { this(-1); } |
346 |
|
347 |
/** Creates a new instance of <code>UpdateSendEffectChains</code>. */ |
348 |
public |
349 |
UpdateSendEffectChains(int audioDeviceId) { |
350 |
this.audioDeviceId = audioDeviceId; |
351 |
setTitle("Global.UpdateSendEffectChains_task"); |
352 |
setDescription(i18n.getMessage("Global.UpdateSendEffectChains.desc")); |
353 |
} |
354 |
|
355 |
/** The entry point of the task. */ |
356 |
@Override |
357 |
public void |
358 |
exec() throws Exception { |
359 |
// TODO: synchornization |
360 |
|
361 |
if(audioDeviceId < 0) { |
362 |
Integer[] aodIDs = CC.getClient().getAudioOutputDeviceIDs(); |
363 |
for(int id : aodIDs) { updateSendEffectChains(id); } |
364 |
} else { |
365 |
updateSendEffectChains(audioDeviceId); |
366 |
} |
367 |
} |
368 |
|
369 |
private void |
370 |
updateSendEffectChains(int devId) throws Exception { |
371 |
EffectChainInfo[] chains = CC.getClient().getSendEffectChains(devId); |
372 |
|
373 |
AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(devId); |
374 |
adm.removeAllSendEffectChains(); |
375 |
|
376 |
for(EffectChainInfo c : chains) { |
377 |
adm.addSendEffectChain(new EffectChain(c)); |
378 |
} |
379 |
} |
380 |
} |
381 |
|
382 |
public static class DummyTask extends EnhancedTask { |
383 |
@Override |
384 |
public void |
385 |
run() { } |
386 |
} |
387 |
} |