/[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 1776 by iliev, Thu Sep 11 18:48:36 2008 UTC revision 2192 by iliev, Fri Jun 24 21:34:51 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.ServerInfo;  import org.linuxsampler.lscp.Effect;
31  import org.linuxsampler.lscp.Instrument;  import org.linuxsampler.lscp.Instrument;
32    import org.linuxsampler.lscp.SamplerEngine;
33    import org.linuxsampler.lscp.ServerInfo;
34    
35    
36  import static org.jsampler.JSI18n.i18n;  import static org.jsampler.JSI18n.i18n;
37    
# Line 39  import static org.jsampler.JSI18n.i18n; Line 42  import static org.jsampler.JSI18n.i18n;
42   */   */
43  public class Global {  public class Global {
44                    
45          /** Forbits the instantiation of this class. */          /** Forbids the instantiation of this class. */
46          private Global() { }          private Global() { }
47    
48            /**
49             * Establishes connection to LinuxSampler.
50             */
51            public static class Connect extends EnhancedTask {
52                    /** Creates a new instance of <code>Connect</code>. */
53                    public
54                    Connect() {
55                            setTitle("Global.Connect_task");
56                            setDescription(i18n.getMessage("Global.Connect.desc"));
57                    }
58    
59                    /** The entry point of the task. */
60                    @Override
61                    public void
62                    exec() throws Exception { CC.getClient().connect(); }
63            }
64    
65            public static class Disconnect extends EnhancedTask {
66                    /** Creates a new instance of <code>Disconnect</code>. */
67                    public
68                    Disconnect() {
69                            setSilent(true);
70                            setTitle("Global.Disconnect_task");
71                            setDescription("Disconnecting...");
72                    }
73    
74                    /** The entry point of the task. */
75                    @Override
76                    public void
77                    exec() throws Exception {
78                            CC.getClient().disconnect();
79                            if(CC.getMainFrame().getLSConsoleModel() != null) {
80                                    CC.getMainFrame().getLSConsoleModel().quit();
81                            }
82                    }
83            }
84                    
85          /**          /**
86           * This task retrieves information about the LinuxSampler instance.           * This task retrieves information about the LinuxSampler instance.
          * @author Grigor Iliev  
87           */           */
88          public static class GetServerInfo extends EnhancedTask<ServerInfo> {          public static class GetServerInfo extends EnhancedTask<ServerInfo> {
89                  /** Creates a new instance of <code>GetServerInfo</code>. */                  /** Creates a new instance of <code>GetServerInfo</code>. */
# Line 55  public class Global { Line 94  public class Global {
94                  }                  }
95                                    
96                  /** The entry point of the task. */                  /** The entry point of the task. */
97                    @Override
98                  public void                  public void
99                  run() {                  exec() throws Exception { setResult(CC.getClient().getServerInfo()); }
                         try { setResult(CC.getClient().getServerInfo()); }  
                         catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
100          }          }
101                    
102          /**          /**
103           * This task resets the whole sampler.           * This task resets the whole sampler.
          * @author Grigor Iliev  
104           */           */
105          public static class ResetSampler extends EnhancedTask {          public static class ResetSampler extends EnhancedTask {
106                  /** Creates a new instance of <code>ResetSampler</code>. */                  /** Creates a new instance of <code>ResetSampler</code>. */
# Line 78  public class Global { Line 111  public class Global {
111                  }                  }
112                                    
113                  /** The entry point of the task. */                  /** The entry point of the task. */
114                    @Override
115                  public void                  public void
116                  run() {                  exec() throws Exception { CC.getClient().resetSampler(); }
117                          try { CC.getClient().resetSampler(); }          }
118                          catch(Exception x) {  
119                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
120                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * This task retrieves the list of all available engines.
121                          }           */
122            public static class GetEngines extends EnhancedTask<SamplerEngine[]> {
123                    /** Creates a new instance of <code>GetEngines</code>. */
124                    public
125                    GetEngines() {
126                            setTitle("Global.GetEngines_task");
127                            setDescription(i18n.getMessage("Global.GetEngines.desc"));
128                  }                  }
129    
130                    /** The entry point of the task. */
131                    @Override
132                    public void
133                    exec() throws Exception { setResult(CC.getClient().getEngines()); }
134          }          }
135                    
136          /**          /**
# Line 100  public class Global { Line 145  public class Global {
145                  }                  }
146                    
147                  /** The entry point of the task. */                  /** The entry point of the task. */
148                    @Override
149                  public void                  public void
150                  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);  
                         }  
                 }  
151          }          }
152    
153                    
# Line 129  public class Global { Line 169  public class Global {
169                  }                  }
170                    
171                  /** The entry point of the task. */                  /** The entry point of the task. */
172                    @Override
173                  public void                  public void
174                  run() {                  exec() throws Exception { CC.getClient().setVolume(volume); }
175                          try {          }
176                                  CC.getClient().setVolume(volume);  
177                          } catch(Exception x) {          
178                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
179                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * This task sets the global sampler-wide limits of maximum voices and streams.
180                          }           */
181            public static class SetPolyphony extends EnhancedTask {
182                    private int maxVoices;
183                    private int maxStreams;
184                    
185                    /**
186                     * Creates new instance of <code>SetPolyphony</code>.
187                     * @param maxVoices The new global limit of maximum voices or
188                     * <code>-1</code> to ignore it.
189                     * @param maxStreams The new global limit of maximum disk streams or
190                     * <code>-1</code> to ignore it.
191                     */
192                    public
193                    SetPolyphony(int maxVoices, int maxStreams) {
194                            setTitle("Global.SetPolyphony_task");
195                            setDescription(i18n.getMessage("Global.SetPolyphony.desc"));
196                            this.maxVoices = maxVoices;
197                            this.maxStreams = maxStreams;
198                    }
199            
200                    /** The entry point of the task. */
201                    @Override
202                    public void
203                    exec() throws Exception {
204                            if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);
205                            if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);
206                    }
207            }
208    
209            /**
210             * This task updates the current number of all active voices
211             * and the maximum number of active voices allowed.
212             */
213            public static class UpdateTotalVoiceCount extends EnhancedTask {
214                    /** Creates a new instance of <code>UpdateTotalVoiceCount</code>. */
215                    public
216                    UpdateTotalVoiceCount() {
217                            setSilent(true);
218                            setTitle("Global.UpdateTotalVoiceCount_task");
219                            setDescription(i18n.getMessage("Global.UpdateTotalVoiceCount.desc"));
220                    }
221    
222                    /** The entry point of the task. */
223                    @Override
224                    public void
225                    exec() throws Exception {
226                            SamplerModel sm = CC.getSamplerModel();
227                            int voices = CC.getClient().getTotalVoiceCount();
228                            int voicesMax = CC.getClient().getTotalVoiceCountMax();
229                            sm.updateActiveVoiceInfo(voices, voicesMax);
230                    }
231    
232                    /**
233                     * Used to decrease the traffic. All task in the queue
234                     * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
235                     * @see org.jsampler.CC#addTask
236                     */
237                    @Override
238                    public boolean
239                    equals(Object obj) {
240                            if(obj == null) return false;
241                            if(!(obj instanceof UpdateTotalVoiceCount)) return false;
242    
243                            return true;
244                  }                  }
245          }          }
246    
# Line 159  public class Global { Line 263  public class Global {
263                  }                  }
264                    
265                  /** The entry point of the task. */                  /** The entry point of the task. */
266                    @Override
267                  public void                  public void
268                  run() {                  exec() throws Exception { CC.getClient().setSoTimeout(timeout * 1000); }
                         try {  
                                 CC.getClient().setSoTimeout(timeout * 1000);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
269          }          }
270                    
271          /**          /**
# Line 179  public class Global { Line 277  public class Global {
277                  /** Creates a new instance of <code>GetFileInstruments</code>. */                  /** Creates a new instance of <code>GetFileInstruments</code>. */
278                  public                  public
279                  GetFileInstruments(String filename) {                  GetFileInstruments(String filename) {
280                            setSilent(true);
281                          this.filename = filename;                          this.filename = filename;
282                          setTitle("Global.GetFileInstruments_task");                          setTitle("Global.GetFileInstruments_task");
283                          setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));                          setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));
284                  }                  }
285                    
286                  /** The entry point of the task. */                  /** The entry point of the task. */
287                    @Override
288                  public void                  public void
289                  run() {                  exec() throws Exception {
290                          try { setResult(CC.getClient().getFileInstruments(filename)); }                          setResult(CC.getClient().getFileInstruments(filename));
                         catch(Exception x) {  
                                 String s = getDescription() + ": " + HF.getErrorMessage(x);  
                                 CC.getLogger().log(Level.FINE, s, x);  
                         }  
291                  }                  }
292          }          }
293                    
# Line 205  public class Global { Line 301  public class Global {
301                  /** Creates a new instance of <code>GetFileInstrument</code>. */                  /** Creates a new instance of <code>GetFileInstrument</code>. */
302                  public                  public
303                  GetFileInstrument(String filename, int instrIdx) {                  GetFileInstrument(String filename, int instrIdx) {
304                            setSilent(true);
305                          this.filename = filename;                          this.filename = filename;
306                          this.instrIdx = instrIdx;                          this.instrIdx = instrIdx;
307                          setTitle("Global.GetFileInstrument_task");                          setTitle("Global.GetFileInstrument_task");
# Line 212  public class Global { Line 309  public class Global {
309                  }                  }
310                    
311                  /** The entry point of the task. */                  /** The entry point of the task. */
312                    @Override
313                    public void
314                    exec() throws Exception {
315                            setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx));
316                    }
317            }
318    
319            /**
320             * This task retrieves the list of internal effects, available to the sampler.
321             */
322            public static class GetEffects extends EnhancedTask<Effect[]> {
323                    /** Creates a new instance of <code>GetEffects</code>. */
324                    public
325                    GetEffects() {
326                            setTitle("Global.GetEffects_task");
327                            setDescription(i18n.getMessage("Global.GetEffects.desc"));
328                    }
329            
330                    /** The entry point of the task. */
331                    @Override
332                  public void                  public void
333                  run() {                  exec() throws Exception { setResult(CC.getClient().getEffects()); }
334                          try { setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx)); }          }
335                          catch(Exception x) {  
336                                  String s = getDescription() + ": " + HF.getErrorMessage(x);          /**
337                                  CC.getLogger().log(Level.FINE, s, x);           * This task updates the send effect chains and the effect instances in those chains.
338             */
339            public static class UpdateSendEffectChains extends EnhancedTask {
340                    private final int audioDeviceId;
341                    
342                    /** Creates a new instance of <code>UpdateSendEffectChains</code>. */
343                    public
344                    UpdateSendEffectChains() { this(-1); }
345                    
346                    /** Creates a new instance of <code>UpdateSendEffectChains</code>. */
347                    public
348                    UpdateSendEffectChains(int audioDeviceId) {
349                            this.audioDeviceId = audioDeviceId;
350                            setTitle("Global.UpdateSendEffectChains_task");
351                            setDescription(i18n.getMessage("Global.UpdateSendEffectChains.desc"));
352                    }
353            
354                    /** The entry point of the task. */
355                    @Override
356                    public void
357                    exec() throws Exception {
358                            // TODO: synchornization
359                            
360                            if(audioDeviceId < 0) {
361                                    Integer[] aodIDs = CC.getClient().getAudioOutputDeviceIDs();
362                                    for(int id : aodIDs) { updateSendEffectChains(id); }
363                            } else {
364                                    updateSendEffectChains(audioDeviceId);
365                            }
366                    }
367                    
368                    private void
369                    updateSendEffectChains(int devId) throws Exception {
370                            org.linuxsampler.lscp.EffectChain[] chains =
371                                    CC.getClient().getSendEffectChains(devId);
372                            
373                            AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(devId);
374                            adm.removeAllSendEffectChains();
375                            
376                            for(org.linuxsampler.lscp.EffectChain c : chains) {
377                                    adm.addSendEffectChain(new EffectChain(c));
378                          }                          }
379                  }                  }
380          }          }
381                    
382          public static class DummyTask extends EnhancedTask {          public static class DummyTask extends EnhancedTask {
383                    @Override
384                  public void                  public void
385                  run() { }                  run() { }
386          }          }

Legend:
Removed from v.1776  
changed lines
  Added in v.2192

  ViewVC Help
Powered by ViewVC