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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1144 by iliev, Mon Apr 2 21:39:15 2007 UTC revision 2195 by iliev, Tue Jun 28 22:44:39 2011 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 22  Line 22 
22    
23  package org.jsampler.task;  package org.jsampler.task;
24    
25  import java.util.logging.Level;  import org.jsampler.AudioDeviceModel;
   
26  import org.jsampler.CC;  import org.jsampler.CC;
27  import org.jsampler.HF;  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;  import static org.jsampler.JSI18n.i18n;
38    
# Line 36  import static org.jsampler.JSI18n.i18n; Line 43  import static org.jsampler.JSI18n.i18n;
43   */   */
44  public class Global {  public class Global {
45                    
46          /** Forbits the instantiation of this class. */          /** Forbids the instantiation of this class. */
47          private Global() { }          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.           * This task gets the global volume of the sampler.
139           */           */
140          public static class GetVolume extends EnhancedTask<Float> {          public static class GetVolume extends EnhancedTask<Float> {
141                  /** Creates a new instance of <code>Get</code>. */                  /** Creates a new instance of <code>GetVolume</code>. */
142                  public                  public
143                  GetVolume() {                  GetVolume() {
144                          setTitle("Global.GetVolume_task");                          setTitle("Global.GetVolume_task");
# Line 51  public class Global { Line 146  public class Global {
146                  }                  }
147                    
148                  /** The entry point of the task. */                  /** The entry point of the task. */
149                    @Override
150                  public void                  public void
151                  run() {                  exec() throws Exception { setResult(CC.getClient().getVolume()); }
                         try { setResult(CC.getClient().getVolume()); }  
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
152          }          }
153    
154                    
# Line 80  public class Global { Line 170  public class Global {
170                  }                  }
171                    
172                  /** The entry point of the task. */                  /** The entry point of the task. */
173                    @Override
174                  public void                  public void
175                  run() {                  exec() throws Exception { CC.getClient().setVolume(volume); }
176                          try {          }
177                                  CC.getClient().setVolume(volume);  
178                          } catch(Exception x) {          
179                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
180                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * 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  }  }

Legend:
Removed from v.1144  
changed lines
  Added in v.2195

  ViewVC Help
Powered by ViewVC