/[svn]/jsampler/trunk/src/org/jsampler/DefaultAudioDeviceModel.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/DefaultAudioDeviceModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2191 by iliev, Thu Dec 6 19:37:41 2007 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;  package org.jsampler;
24    
25    import java.util.ArrayList;
26  import java.util.Vector;  import java.util.Vector;
27    
28  import javax.swing.SwingUtilities;  import javax.swing.SwingUtilities;
# Line 32  import org.jsampler.event.AudioDeviceLis Line 33  import org.jsampler.event.AudioDeviceLis
33  import org.jsampler.task.Audio;  import org.jsampler.task.Audio;
34    
35  import org.linuxsampler.lscp.AudioOutputDevice;  import org.linuxsampler.lscp.AudioOutputDevice;
36    import org.linuxsampler.lscp.Effect;
37  import org.linuxsampler.lscp.Parameter;  import org.linuxsampler.lscp.Parameter;
38    
39    
# Line 42  import org.linuxsampler.lscp.Parameter; Line 44  import org.linuxsampler.lscp.Parameter;
44  public class DefaultAudioDeviceModel implements AudioDeviceModel {  public class DefaultAudioDeviceModel implements AudioDeviceModel {
45          private AudioOutputDevice audioDevice;          private AudioOutputDevice audioDevice;
46                    
47          private final Vector<AudioDeviceListener> listeners = new Vector<AudioDeviceListener>();          private final ArrayList<AudioDeviceListener> listeners = new ArrayList<AudioDeviceListener>();
48            private final ArrayList<EffectChain> effectChains = new ArrayList<EffectChain>();
49                    
50          /**          /**
51           * Creates a new instance of <code>DefaultAudioDeviceModel</code> using the           * Creates a new instance of <code>DefaultAudioDeviceModel</code> using the
# Line 64  public class DefaultAudioDeviceModel imp Line 67  public class DefaultAudioDeviceModel imp
67           * the settings of the audio device are changed.           * the settings of the audio device are changed.
68           * @param l The <code>AudioDeviceListener</code> to register.           * @param l The <code>AudioDeviceListener</code> to register.
69           */           */
70            @Override
71          public void          public void
72          addAudioDeviceListener(AudioDeviceListener l) { listeners.add(l); }          addAudioDeviceListener(AudioDeviceListener l) { listeners.add(l); }
73                    
# Line 71  public class DefaultAudioDeviceModel imp Line 75  public class DefaultAudioDeviceModel imp
75           * Removes the specified listener.           * Removes the specified listener.
76           * @param l The <code>AudioDeviceListener</code> to remove.           * @param l The <code>AudioDeviceListener</code> to remove.
77           */           */
78            @Override
79          public void          public void
80          removeAudioDeviceListener(AudioDeviceListener l) { listeners.remove(l); }          removeAudioDeviceListener(AudioDeviceListener l) { listeners.remove(l); }
81                    
# Line 79  public class DefaultAudioDeviceModel imp Line 84  public class DefaultAudioDeviceModel imp
84           * @return The numerical ID of this audio device or           * @return The numerical ID of this audio device or
85           * -1 if the device number is not set.           * -1 if the device number is not set.
86           */           */
87            @Override
88          public int          public int
89          getDeviceId() { return audioDevice.getDeviceId(); }          getDeviceId() { return audioDevice.getDeviceId(); }
90                    
# Line 87  public class DefaultAudioDeviceModel imp Line 93  public class DefaultAudioDeviceModel imp
93           * @return <code>AudioOutputDevice</code> instance providing           * @return <code>AudioOutputDevice</code> instance providing
94           * the current settings of the audio device represented by this model.           * the current settings of the audio device represented by this model.
95           */           */
96            @Override
97          public AudioOutputDevice          public AudioOutputDevice
98          getDeviceInfo() { return audioDevice; }          getDeviceInfo() { return audioDevice; }
99                    
# Line 94  public class DefaultAudioDeviceModel imp Line 101  public class DefaultAudioDeviceModel imp
101           * Updates the settings of the audio device represented by this model.           * Updates the settings of the audio device represented by this model.
102           * @param device The new audio device settings.           * @param device The new audio device settings.
103           */           */
104            @Override
105          public void          public void
106          setDeviceInfo(AudioOutputDevice device) {          setDeviceInfo(AudioOutputDevice device) {
107                  audioDevice = device;                  audioDevice = device;
# Line 105  public class DefaultAudioDeviceModel imp Line 113  public class DefaultAudioDeviceModel imp
113           * @param active If <code>true</code> the audio device is enabled,           * @param active If <code>true</code> the audio device is enabled,
114           * else the device is disabled.           * else the device is disabled.
115           */           */
116            @Override
117          public void          public void
118          setActive(boolean active) {          setActive(boolean active) {
119                  if(active == getDeviceInfo().isActive()) return;                  if(active == getDeviceInfo().isActive()) return;
# Line 117  public class DefaultAudioDeviceModel imp Line 126  public class DefaultAudioDeviceModel imp
126           * Determines whether the audio device is active.           * Determines whether the audio device is active.
127           * @return <code>true</code> if the device is enabled and <code>false</code> otherwise.           * @return <code>true</code> if the device is enabled and <code>false</code> otherwise.
128           */           */
129            @Override
130          public boolean          public boolean
131          isActive() { return audioDevice.isActive(); }          isActive() { return audioDevice.isActive(); }
132                    
# Line 125  public class DefaultAudioDeviceModel imp Line 135  public class DefaultAudioDeviceModel imp
135           * @param active If <code>true</code> the audio device is enabled,           * @param active If <code>true</code> the audio device is enabled,
136           * else the device is disabled.           * else the device is disabled.
137           */           */
138            @Override
139          public void          public void
140          setBackendActive(boolean active) {          setBackendActive(boolean active) {
141                  CC.getTaskQueue().add(new Audio.EnableDevice(getDeviceId(), active));                  CC.getTaskQueue().add(new Audio.EnableDevice(getDeviceId(), active));
# Line 135  public class DefaultAudioDeviceModel imp Line 146  public class DefaultAudioDeviceModel imp
146           * a specific setting of the audio output device.           * a specific setting of the audio output device.
147           * @param prm The parameter to be set.           * @param prm The parameter to be set.
148           */           */
149            @Override
150          public void          public void
151          setBackendDeviceParameter(Parameter prm) {          setBackendDeviceParameter(Parameter prm) {
152                  CC.getTaskQueue().add(new Audio.SetDeviceParameter(getDeviceId(), prm));                  CC.getTaskQueue().add(new Audio.SetDeviceParameter(getDeviceId(), prm));
# Line 144  public class DefaultAudioDeviceModel imp Line 156  public class DefaultAudioDeviceModel imp
156           * Schedules a new task for changing the channel number of the audio device.           * Schedules a new task for changing the channel number of the audio device.
157           * @param channels The new number of audio channels.           * @param channels The new number of audio channels.
158           */           */
159            @Override
160          public void          public void
161          setBackendChannelCount(int channels) {          setBackendChannelCount(int channels) {
162                  CC.getTaskQueue().add(new Audio.SetChannelCount(getDeviceId(), channels));                  CC.getTaskQueue().add(new Audio.SetChannelCount(getDeviceId(), channels));
# Line 155  public class DefaultAudioDeviceModel imp Line 168  public class DefaultAudioDeviceModel imp
168           * @param channel The channel number.           * @param channel The channel number.
169           * @param prm The parameter to be set.           * @param prm The parameter to be set.
170           */           */
171            @Override
172          public void          public void
173          setBackendChannelParameter(int channel, Parameter prm) {          setBackendChannelParameter(int channel, Parameter prm) {
174                  CC.getTaskQueue().add(new Audio.SetChannelParameter(getDeviceId(), channel, prm));                  CC.getTaskQueue().add(new Audio.SetChannelParameter(getDeviceId(), channel, prm));
175          }          }
176                    
177            /** Gets the current number of send effect chains. */
178            @Override
179            public int
180            getSendEffectChainCount() { return effectChains.size(); }
181            
182            /** Gets the effect chain at the specified position. */
183            @Override
184            public EffectChain
185            getSendEffectChain(int chainIdx) { return effectChains.get(chainIdx); }
186            
187            @Override
188            public EffectChain
189            getSendEffectChainById(int chainId) {
190                    for(int i = 0; i < getSendEffectChainCount(); i++) {
191                            EffectChain chain = getSendEffectChain(i);
192                            if(chain.getChainId() == chainId) return chain;
193                    }
194                    
195                    return null;
196            }
197            
198            /**
199             * Adds the specified send effect chain to the specified audio output device.
200             */
201            @Override
202            public void
203            addSendEffectChain(EffectChain chain) {
204                    effectChains.add(chain);
205                    fireSendEffectChainAdded(chain);
206            }
207            
208            /**
209             * Removes the specified send effect chain from the audio output device.
210             */
211            @Override
212            public void
213            removeSendEffectChain(int chainId) {
214                    for(int i = 0; i < effectChains.size(); i++) {
215                            if(effectChains.get(i).getChainId() == chainId) {
216                                    fireSendEffectChainRemoved(effectChains.remove(i));
217                                    return;
218                            }
219                    }
220            }
221            
222            public void
223            removeAllSendEffectChains() {
224                    for(int i = effectChains.size() - 1; i >= 0; i--) {
225                            fireSendEffectChainRemoved(effectChains.remove(i));
226                    }
227            }
228            
229            /**
230             * Schedules a new task for adding a new send effect chain and
231             * assigning it to the specified audio output device.
232             */
233            @Override
234            public void
235            addBackendSendEffectChain() {
236                    CC.getTaskQueue().add(new Audio.AddSendEffectChain(getDeviceId()));
237            }
238            
239            /** Schedules a new task for removing the specified send effect chain. */
240            @Override
241            public void
242            removeBackendSendEffectChain(int chainId) {
243                    CC.getTaskQueue().add(new Audio.RemoveSendEffectChain(getDeviceId(), chainId));
244            }
245            
246            /**
247             * Schedules a new task for creating new effect instances and inserting them
248             * in the specified send effect chain at the specified position.
249             */
250            @Override
251            public void
252            addBackendEffectInstances(Effect[] effects, int chainId, int index) {
253                    CC.getTaskQueue().add (
254                            new Audio.AddNewEffectInstances(effects, getDeviceId(), chainId, index)
255                    );
256            }
257            
258            /**
259             * Schedules a new task for removing the specified
260             * effect instance from the specified send effect chain.
261             */
262            @Override
263            public void
264            removeBackendEffectInstance(int chainId, int instanceId) {
265                    CC.getTaskQueue().add(new Audio.RemoveEffectInstance(getDeviceId(), chainId, instanceId));
266            }
267            
268          /**          /**
269           * Notifies listeners that the settings of the audio device are changed.           * Notifies listeners that the settings of the audio device are changed.
270           */           */
# Line 183  public class DefaultAudioDeviceModel imp Line 288  public class DefaultAudioDeviceModel imp
288                  CC.getSamplerModel().setModified(true);                  CC.getSamplerModel().setModified(true);
289                  for(AudioDeviceListener l : listeners) l.settingsChanged(e);                  for(AudioDeviceListener l : listeners) l.settingsChanged(e);
290          }          }
291            
292            private void
293            fireSendEffectChainAdded(final EffectChain chain) {
294                    SwingUtilities.invokeLater(new Runnable() {
295                            public void
296                            run() {
297                                    AudioDeviceModel m = DefaultAudioDeviceModel.this;
298                                    fireSendEffectChainAdded(new AudioDeviceEvent(m, m, chain));
299                            }
300                    });
301            }
302            
303            /** This method should be invoked from the event-dispatching thread. */
304            private void
305            fireSendEffectChainAdded(final AudioDeviceEvent e) {
306                    CC.getSamplerModel().setModified(true);
307                    for(AudioDeviceListener l : listeners) l.sendEffectChainAdded(e);
308            }
309            
310            private void
311            fireSendEffectChainRemoved(final EffectChain chain) {
312                    SwingUtilities.invokeLater(new Runnable() {
313                            public void
314                            run() {
315                                    AudioDeviceModel m = DefaultAudioDeviceModel.this;
316                                    fireSendEffectChainRemoved(new AudioDeviceEvent(m, m, chain));
317                            }
318                    });
319            }
320            
321            /** This method should be invoked from the event-dispatching thread. */
322            private void
323            fireSendEffectChainRemoved(final AudioDeviceEvent e) {
324                    CC.getSamplerModel().setModified(true);
325                    for(AudioDeviceListener l : listeners) l.sendEffectChainRemoved(e);
326            }
327  }  }

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

  ViewVC Help
Powered by ViewVC