/[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 1818 by iliev, Wed Dec 24 17:29:47 2008 UTC revision 1883 by iliev, Sun Apr 5 09:15:35 2009 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-2008 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2009 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    
 import java.util.logging.Level;  
   
25  import org.jsampler.CC;  import org.jsampler.CC;
 import org.jsampler.HF;  
26    
27    import org.linuxsampler.lscp.SamplerEngine;
28  import org.linuxsampler.lscp.ServerInfo;  import org.linuxsampler.lscp.ServerInfo;
29  import org.linuxsampler.lscp.Instrument;  import org.linuxsampler.lscp.Instrument;
30    
31    import org.jsampler.SamplerModel;
32    
33  import static org.jsampler.JSI18n.i18n;  import static org.jsampler.JSI18n.i18n;
34    
35    
# Line 41  public class Global { Line 41  public class Global {
41                    
42          /** Forbits the instantiation of this class. */          /** Forbits the instantiation of this class. */
43          private Global() { }          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.           * This task retrieves information about the LinuxSampler instance.
          * @author Grigor Iliev  
84           */           */
85          public static class GetServerInfo extends EnhancedTask<ServerInfo> {          public static class GetServerInfo extends EnhancedTask<ServerInfo> {
86                  /** Creates a new instance of <code>GetServerInfo</code>. */                  /** Creates a new instance of <code>GetServerInfo</code>. */
# Line 57  public class Global { Line 93  public class Global {
93                  /** The entry point of the task. */                  /** The entry point of the task. */
94                  @Override                  @Override
95                  public void                  public void
96                  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);  
                         }  
                 }  
97          }          }
98                    
99          /**          /**
100           * This task resets the whole sampler.           * This task resets the whole sampler.
          * @author Grigor Iliev  
101           */           */
102          public static class ResetSampler extends EnhancedTask {          public static class ResetSampler extends EnhancedTask {
103                  /** Creates a new instance of <code>ResetSampler</code>. */                  /** Creates a new instance of <code>ResetSampler</code>. */
# Line 81  public class Global { Line 110  public class Global {
110                  /** The entry point of the task. */                  /** The entry point of the task. */
111                  @Override                  @Override
112                  public void                  public void
113                  run() {                  exec() throws Exception { CC.getClient().resetSampler(); }
114                          try { CC.getClient().resetSampler(); }          }
115                          catch(Exception x) {  
116                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
117                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * 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          /**          /**
# Line 104  public class Global { Line 144  public class Global {
144                  /** The entry point of the task. */                  /** The entry point of the task. */
145                  @Override                  @Override
146                  public void                  public void
147                  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);  
                         }  
                 }  
148          }          }
149    
150                    
# Line 134  public class Global { Line 168  public class Global {
168                  /** The entry point of the task. */                  /** The entry point of the task. */
169                  @Override                  @Override
170                  public void                  public void
171                  run() {                  exec() throws Exception { CC.getClient().setVolume(volume); }
                         try {  
                                 CC.getClient().setVolume(volume);  
                         } catch(Exception x) {  
                                 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
                                 CC.getLogger().log(Level.FINE, getErrorMessage(), x);  
                         }  
                 }  
172          }          }
173    
174                    
# Line 170  public class Global { Line 197  public class Global {
197                  /** The entry point of the task. */                  /** The entry point of the task. */
198                  @Override                  @Override
199                  public void                  public void
200                  run() {                  exec() throws Exception {
201                          try {                          if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);
202                                  if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);                          if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);
203                                  if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);                  }
204                          } catch(Exception x) {          }
205                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
206                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);          /**
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    
# Line 202  public class Global { Line 262  public class Global {
262                  /** The entry point of the task. */                  /** The entry point of the task. */
263                  @Override                  @Override
264                  public void                  public void
265                  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);  
                         }  
                 }  
266          }          }
267                    
268          /**          /**
# Line 221  public class Global { Line 274  public class Global {
274                  /** Creates a new instance of <code>GetFileInstruments</code>. */                  /** Creates a new instance of <code>GetFileInstruments</code>. */
275                  public                  public
276                  GetFileInstruments(String filename) {                  GetFileInstruments(String filename) {
277                            setSilent(true);
278                          this.filename = filename;                          this.filename = filename;
279                          setTitle("Global.GetFileInstruments_task");                          setTitle("Global.GetFileInstruments_task");
280                          setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));                          setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));
# Line 229  public class Global { Line 283  public class Global {
283                  /** The entry point of the task. */                  /** The entry point of the task. */
284                  @Override                  @Override
285                  public void                  public void
286                  run() {                  exec() throws Exception {
287                          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);  
                         }  
288                  }                  }
289          }          }
290                    
# Line 248  public class Global { Line 298  public class Global {
298                  /** Creates a new instance of <code>GetFileInstrument</code>. */                  /** Creates a new instance of <code>GetFileInstrument</code>. */
299                  public                  public
300                  GetFileInstrument(String filename, int instrIdx) {                  GetFileInstrument(String filename, int instrIdx) {
301                            setSilent(true);
302                          this.filename = filename;                          this.filename = filename;
303                          this.instrIdx = instrIdx;                          this.instrIdx = instrIdx;
304                          setTitle("Global.GetFileInstrument_task");                          setTitle("Global.GetFileInstrument_task");
# Line 257  public class Global { Line 308  public class Global {
308                  /** The entry point of the task. */                  /** The entry point of the task. */
309                  @Override                  @Override
310                  public void                  public void
311                  run() {                  exec() throws Exception {
312                          try { setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx)); }                          setResult(CC.getClient().getFileInstrumentInfo(filename, instrIdx));
                         catch(Exception x) {  
                                 String s = getDescription() + ": " + HF.getErrorMessage(x);  
                                 CC.getLogger().log(Level.FINE, s, x);  
                         }  
313                  }                  }
314          }          }
315                    

Legend:
Removed from v.1818  
changed lines
  Added in v.1883

  ViewVC Help
Powered by ViewVC