/[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 1767 by iliev, Mon Sep 8 00:19:27 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-2007 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 55  public class Global { Line 91  public class Global {
91                  }                  }
92                                    
93                  /** The entry point of the task. */                  /** The entry point of the task. */
94                    @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 78  public class Global { Line 108  public class Global {
108                  }                  }
109                                    
110                  /** The entry point of the task. */                  /** The entry point of the task. */
111                    @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 100  public class Global { Line 142  public class Global {
142                  }                  }
143                    
144                  /** The entry point of the task. */                  /** The entry point of the task. */
145                    @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 129  public class Global { Line 166  public class Global {
166                  }                  }
167                    
168                  /** The entry point of the task. */                  /** The entry point of the task. */
169                    @Override
170                  public void                  public void
171                  run() {                  exec() throws Exception { CC.getClient().setVolume(volume); }
172                          try {          }
173                                  CC.getClient().setVolume(volume);  
174                          } catch(Exception x) {          
175                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
176                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * 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    
# Line 159  public class Global { Line 260  public class Global {
260                  }                  }
261                    
262                  /** The entry point of the task. */                  /** The entry point of the task. */
263                    @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 179  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"));
281                  }                  }
282                    
283                  /** The entry point of the task. */                  /** The entry point of the task. */
284                    @Override
285                  public void                  public void
286                  run() {                  exec() throws Exception {
287                          try { setResult(CC.getClient().getFileInstruments(filename)); }                          setResult(CC.getClient().getFileInstruments(filename));
288                          catch(Exception x) {                  }
289                                  String s = getDescription() + ": " + HF.getErrorMessage(x);          }
290                                  CC.getLogger().log(Level.FINER, s, x);          
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 {          public static class DummyTask extends EnhancedTask {
317                    @Override
318                  public void                  public void
319                  run() { }                  run() { }
320          }          }

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

  ViewVC Help
Powered by ViewVC