/[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 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-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 { 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 55  public class Global { Line 86  public class Global {
86                  }                  }
87                                    
88                  /** The entry point of the task. */                  /** The entry point of the task. */
89                    @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 78  public class Global { Line 103  public class Global {
103                  }                  }
104                                    
105                  /** The entry point of the task. */                  /** The entry point of the task. */
106                    @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 100  public class Global { Line 137  public class Global {
137                  }                  }
138                    
139                  /** The entry point of the task. */                  /** The entry point of the task. */
140                    @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 129  public class Global { Line 161  public class Global {
161                  }                  }
162                    
163                  /** The entry point of the task. */                  /** The entry point of the task. */
164                    @Override
165                  public void                  public void
166                  run() {                  exec() throws Exception { CC.getClient().setVolume(volume); }
167                          try {          }
168                                  CC.getClient().setVolume(volume);  
169                          } catch(Exception x) {          
170                                  setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));          /**
171                                  CC.getLogger().log(Level.FINE, getErrorMessage(), x);           * This task sets the global sampler-wide limits of maximum voices and streams.
172                          }           */
173            public static class SetPolyphony extends EnhancedTask {
174                    private int maxVoices;
175                    private int maxStreams;
176                    
177                    /**
178                     * Creates new instance of <code>SetPolyphony</code>.
179                     * @param maxVoices The new global limit of maximum voices or
180                     * <code>-1</code> to ignore it.
181                     * @param maxStreams The new global limit of maximum disk streams or
182                     * <code>-1</code> to ignore it.
183                     */
184                    public
185                    SetPolyphony(int maxVoices, int maxStreams) {
186                            setTitle("Global.SetPolyphony_task");
187                            setDescription(i18n.getMessage("Global.SetPolyphony.desc"));
188                            this.maxVoices = maxVoices;
189                            this.maxStreams = maxStreams;
190                    }
191            
192                    /** The entry point of the task. */
193                    @Override
194                    public void
195                    exec() throws Exception {
196                            if(maxVoices != -1) CC.getClient().setGlobalVoiceLimit(maxVoices);
197                            if(maxStreams != -1) CC.getClient().setGlobalStreamLimit(maxStreams);
198                    }
199            }
200    
201            /**
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 159  public class Global { Line 255  public class Global {
255                  }                  }
256                    
257                  /** The entry point of the task. */                  /** The entry point of the task. */
258                    @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 179  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"));
276                  }                  }
277                    
278                  /** The entry point of the task. */                  /** The entry point of the task. */
279                    @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 205  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 212  public class Global { Line 301  public class Global {
301                  }                  }
302                    
303                  /** The entry point of the task. */                  /** The entry point of the task. */
304                    @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                    
311          public static class DummyTask extends EnhancedTask {          public static class DummyTask extends EnhancedTask {
312                    @Override
313                  public void                  public void
314                  run() { }                  run() { }
315          }          }

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

  ViewVC Help
Powered by ViewVC