/[svn]/jsampler/trunk/src/org/jsampler/task/Global.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/task/Global.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1867 - (show annotations) (download)
Mon Mar 16 22:12:32 2009 UTC (15 years, 1 month ago) by iliev
File size: 8618 byte(s)
* proper handling of connection failures
* renamed Channels Panels to Channel Lanes
* code cleanup

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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.CC;
26
27 import org.linuxsampler.lscp.SamplerEngine;
28 import org.linuxsampler.lscp.ServerInfo;
29 import org.linuxsampler.lscp.Instrument;
30
31 import org.jsampler.SamplerModel;
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 * Establishes connection to LinuxSampler.
47 */
48 public static class Connect extends EnhancedTask {
49 /** Creates a new instance of <code>Connect</code>. */
50 public
51 Connect() {
52 setTitle("Global.Connect_task");
53 setDescription(i18n.getMessage("Global.Connect.desc"));
54 }
55
56 /** The entry point of the task. */
57 @Override
58 public void
59 exec() throws Exception { CC.getClient().connect(); }
60 }
61
62 public static class Disconnect extends EnhancedTask {
63 /** Creates a new instance of <code>Disconnect</code>. */
64 public
65 Disconnect() {
66 setSilent(true);
67 setTitle("Global.Disconnect_task");
68 setDescription("Disconnecting...");
69 }
70
71 /** The entry point of the task. */
72 @Override
73 public void
74 exec() throws Exception { CC.getClient().disconnect(); }
75 }
76
77 /**
78 * This task retrieves information about the LinuxSampler instance.
79 */
80 public static class GetServerInfo extends EnhancedTask<ServerInfo> {
81 /** Creates a new instance of <code>GetServerInfo</code>. */
82 public
83 GetServerInfo() {
84 setTitle("Global.GetServerInfo_task");
85 setDescription(i18n.getMessage("Global.GetServerInfo.desc"));
86 }
87
88 /** The entry point of the task. */
89 @Override
90 public void
91 exec() throws Exception { setResult(CC.getClient().getServerInfo()); }
92 }
93
94 /**
95 * This task resets the whole sampler.
96 */
97 public static class ResetSampler extends EnhancedTask {
98 /** Creates a new instance of <code>ResetSampler</code>. */
99 public
100 ResetSampler() {
101 setTitle("Global.ResetSampler_task");
102 setDescription(i18n.getMessage("Global.ResetSampler.desc"));
103 }
104
105 /** The entry point of the task. */
106 @Override
107 public void
108 exec() throws Exception { CC.getClient().resetSampler(); }
109 }
110
111 /**
112 * This task retrieves the list of all available engines.
113 */
114 public static class GetEngines extends EnhancedTask<SamplerEngine[]> {
115 /** Creates a new instance of <code>GetEngines</code>. */
116 public
117 GetEngines() {
118 setTitle("Global.GetEngines_task");
119 setDescription(i18n.getMessage("Global.GetEngines.desc"));
120 }
121
122 /** The entry point of the task. */
123 @Override
124 public void
125 exec() throws Exception { setResult(CC.getClient().getEngines()); }
126 }
127
128 /**
129 * This task gets the global volume of the sampler.
130 */
131 public static class GetVolume extends EnhancedTask<Float> {
132 /** Creates a new instance of <code>GetVolume</code>. */
133 public
134 GetVolume() {
135 setTitle("Global.GetVolume_task");
136 setDescription(i18n.getMessage("Global.GetVolume.desc"));
137 }
138
139 /** The entry point of the task. */
140 @Override
141 public void
142 exec() throws Exception { setResult(CC.getClient().getVolume()); }
143 }
144
145
146 /**
147 * This task sets the global volume of the sampler.
148 */
149 public static class SetVolume extends EnhancedTask {
150 private float volume;
151
152 /**
153 * Creates new instance of <code>SetVolume</code>.
154 * @param volume The new volume value.
155 */
156 public
157 SetVolume(float volume) {
158 setTitle("Global.SetVolume_task");
159 setDescription(i18n.getMessage("Global.SetVolume.desc"));
160 this.volume = volume;
161 }
162
163 /** The entry point of the task. */
164 @Override
165 public void
166 exec() throws Exception { CC.getClient().setVolume(volume); }
167 }
168
169
170 /**
171 * This task sets the global sampler-wide limits of maximum voices and streams.
172 */
173 public static class SetPolyphony extends EnhancedTask {
174 private int maxVoices;
175 private int maxStreams;
176
177 /**
178 * Creates new instance of <code>SetPolyphony</code>.
179 * @param maxVoices The new global limit of maximum voices or
180 * <code>-1</code> to ignore it.
181 * @param maxStreams The new global limit of maximum disk streams or
182 * <code>-1</code> to ignore it.
183 */
184 public
185 SetPolyphony(int maxVoices, int maxStreams) {
186 setTitle("Global.SetPolyphony_task");
187 setDescription(i18n.getMessage("Global.SetPolyphony.desc"));
188 this.maxVoices = maxVoices;
189 this.maxStreams = maxStreams;
190 }
191
192 /** The entry point of the task. */
193 @Override
194 public void
195 exec() throws Exception {
196 if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);
197 if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);
198 }
199 }
200
201 /**
202 * This task updates the current number of all active voices
203 * and the maximum number of active voices allowed.
204 */
205 public static class UpdateTotalVoiceCount extends EnhancedTask {
206 /** Creates a new instance of <code>UpdateTotalVoiceCount</code>. */
207 public
208 UpdateTotalVoiceCount() {
209 setSilent(true);
210 setTitle("Global.UpdateTotalVoiceCount_task");
211 setDescription(i18n.getMessage("Global.UpdateTotalVoiceCount.desc"));
212 }
213
214 /** The entry point of the task. */
215 @Override
216 public void
217 exec() throws Exception {
218 SamplerModel sm = CC.getSamplerModel();
219 int voices = CC.getClient().getTotalVoiceCount();
220 int voicesMax = CC.getClient().getTotalVoiceCountMax();
221 sm.updateActiveVoiceInfo(voices, voicesMax);
222 }
223
224 /**
225 * Used to decrease the traffic. All task in the queue
226 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
227 * @see org.jsampler.CC#addTask
228 */
229 @Override
230 public boolean
231 equals(Object obj) {
232 if(obj == null) return false;
233 if(!(obj instanceof UpdateTotalVoiceCount)) return false;
234
235 return true;
236 }
237 }
238
239
240 /**
241 * This task sets the LSCP client's read timeout.
242 */
243 public static class SetClientReadTimeout extends EnhancedTask {
244 private int timeout;
245
246 /**
247 * Creates new instance of <code>SetClientReadTimeout</code>.
248 * @param timeout The new timeout value (in seconds).
249 */
250 public
251 SetClientReadTimeout(int timeout) {
252 setTitle("Global.SetClientReadTimeout_task");
253 setDescription(i18n.getMessage("Global.SetClientReadTimeout.desc"));
254 this.timeout = timeout;
255 }
256
257 /** The entry point of the task. */
258 @Override
259 public void
260 exec() throws Exception { CC.getClient().setSoTimeout(timeout * 1000); }
261 }
262
263 /**
264 * This task gets the list of instruments in the specified instrument file.
265 */
266 public static class GetFileInstruments extends EnhancedTask<Instrument[]> {
267 private final String filename;
268
269 /** Creates a new instance of <code>GetFileInstruments</code>. */
270 public
271 GetFileInstruments(String filename) {
272 setSilent(true);
273 this.filename = filename;
274 setTitle("Global.GetFileInstruments_task");
275 setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));
276 }
277
278 /** The entry point of the task. */
279 @Override
280 public void
281 exec() throws Exception {
282 setResult(CC.getClient().getFileInstruments(filename));
283 }
284 }
285
286 /**
287 * This task gets information about the specified instrument.
288 */
289 public static class GetFileInstrument extends EnhancedTask<Instrument> {
290 private final String filename;
291 private final int instrIdx;
292
293 /** Creates a new instance of <code>GetFileInstrument</code>. */
294 public
295 GetFileInstrument(String filename, int instrIdx) {
296 setSilent(true);
297 this.filename = filename;
298 this.instrIdx = instrIdx;
299 setTitle("Global.GetFileInstrument_task");
300 setDescription(i18n.getMessage("Global.GetFileInstrument.desc"));
301 }
302
303 /** The entry point of the task. */
304 @Override
305 public void
306 exec() throws Exception {
307 setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx));
308 }
309 }
310
311 public static class DummyTask extends EnhancedTask {
312 @Override
313 public void
314 run() { }
315 }
316 }

  ViewVC Help
Powered by ViewVC