/[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 1883 - (show annotations) (download)
Sun Apr 5 09:15:35 2009 UTC (15 years ago) by iliev
File size: 8733 byte(s)
* fixed the channel order when exporting sampler configuration
* don't mute channels muted by solo channel when exporting
   sampler configuration
* don't ask whether to replace a file on Mac OS when using
  native file choosers

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

  ViewVC Help
Powered by ViewVC