/[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 1866 by iliev, Wed Dec 24 17:29:47 2008 UTC revision 1867 by iliev, Mon Mar 16 22:12:32 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 { CC.getClient().disconnect(); }
75            }
76                    
77          /**          /**
78           * This task retrieves information about the LinuxSampler instance.           * This task retrieves information about the LinuxSampler instance.
          * @author Grigor Iliev  
79           */           */
80          public static class GetServerInfo extends EnhancedTask<ServerInfo> {          public static class GetServerInfo extends EnhancedTask<ServerInfo> {
81                  /** Creates a new instance of <code>GetServerInfo</code>. */                  /** Creates a new instance of <code>GetServerInfo</code>. */
# Line 57  public class Global { Line 88  public class Global {
88                  /** The entry point of the task. */                  /** The entry point of the task. */
89                  @Override                  @Override
90                  public void                  public void
91                  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);  
                         }  
                 }  
92          }          }
93                    
94          /**          /**
95           * This task resets the whole sampler.           * This task resets the whole sampler.
          * @author Grigor Iliev  
96           */           */
97          public static class ResetSampler extends EnhancedTask {          public static class ResetSampler extends EnhancedTask {
98                  /** Creates a new instance of <code>ResetSampler</code>. */                  /** Creates a new instance of <code>ResetSampler</code>. */
# Line 81  public class Global { Line 105  public class Global {
105                  /** The entry point of the task. */                  /** The entry point of the task. */
106                  @Override                  @Override
107                  public void                  public void
108                  run() {                  exec() throws Exception { CC.getClient().resetSampler(); }
109                          try { CC.getClient().resetSampler(); }          }
110                          catch(Exception x) {  
111                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
112                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * 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          /**          /**
# Line 104  public class Global { Line 139  public class Global {
139                  /** The entry point of the task. */                  /** The entry point of the task. */
140                  @Override                  @Override
141                  public void                  public void
142                  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);  
                         }  
                 }  
143          }          }
144    
145                    
# Line 134  public class Global { Line 163  public class Global {
163                  /** The entry point of the task. */                  /** The entry point of the task. */
164                  @Override                  @Override
165                  public void                  public void
166                  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);  
                         }  
                 }  
167          }          }
168    
169                    
# Line 170  public class Global { Line 192  public class Global {
192                  /** The entry point of the task. */                  /** The entry point of the task. */
193                  @Override                  @Override
194                  public void                  public void
195                  run() {                  exec() throws Exception {
196                          try {                          if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);
197                                  if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);                          if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);
198                                  if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);                  }
199                          } catch(Exception x) {          }
200                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));  
201                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);          /**
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    
# Line 202  public class Global { Line 257  public class Global {
257                  /** The entry point of the task. */                  /** The entry point of the task. */
258                  @Override                  @Override
259                  public void                  public void
260                  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);  
                         }  
                 }  
261          }          }
262                    
263          /**          /**
# Line 221  public class Global { Line 269  public class Global {
269                  /** Creates a new instance of <code>GetFileInstruments</code>. */                  /** Creates a new instance of <code>GetFileInstruments</code>. */
270                  public                  public
271                  GetFileInstruments(String filename) {                  GetFileInstruments(String filename) {
272                            setSilent(true);
273                          this.filename = filename;                          this.filename = filename;
274                          setTitle("Global.GetFileInstruments_task");                          setTitle("Global.GetFileInstruments_task");
275                          setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));                          setDescription(i18n.getMessage("Global.GetFileInstruments.desc"));
# Line 229  public class Global { Line 278  public class Global {
278                  /** The entry point of the task. */                  /** The entry point of the task. */
279                  @Override                  @Override
280                  public void                  public void
281                  run() {                  exec() throws Exception {
282                          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);  
                         }  
283                  }                  }
284          }          }
285                    
# Line 248  public class Global { Line 293  public class Global {
293                  /** Creates a new instance of <code>GetFileInstrument</code>. */                  /** Creates a new instance of <code>GetFileInstrument</code>. */
294                  public                  public
295                  GetFileInstrument(String filename, int instrIdx) {                  GetFileInstrument(String filename, int instrIdx) {
296                            setSilent(true);
297                          this.filename = filename;                          this.filename = filename;
298                          this.instrIdx = instrIdx;                          this.instrIdx = instrIdx;
299                          setTitle("Global.GetFileInstrument_task");                          setTitle("Global.GetFileInstrument_task");
# Line 257  public class Global { Line 303  public class Global {
303                  /** The entry point of the task. */                  /** The entry point of the task. */
304                  @Override                  @Override
305                  public void                  public void
306                  run() {                  exec() throws Exception {
307                          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);  
                         }  
308                  }                  }
309          }          }
310                    

Legend:
Removed from v.1866  
changed lines
  Added in v.1867

  ViewVC Help
Powered by ViewVC