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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 911 - (show annotations) (download)
Mon Aug 7 18:25:58 2006 UTC (17 years, 8 months ago) by iliev
File size: 4240 byte(s)
updating to JSampler 0.3a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005 Grigor Kirilov Iliev
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler;
24
25 import java.util.Vector;
26
27 import javax.swing.SwingUtilities;
28
29 import org.jsampler.event.AudioDeviceEvent;
30 import org.jsampler.event.AudioDeviceListener;
31
32 import org.linuxsampler.lscp.AudioOutputDevice;
33
34
35 /**
36 * This class provides default implementation of the <code>AudioDeviceModel</code> interface.
37 * @author Grigor Iliev
38 */
39 public class DefaultAudioDeviceModel implements AudioDeviceModel {
40 private AudioOutputDevice audioDevice;
41
42 private final Vector<AudioDeviceListener> listeners = new Vector<AudioDeviceListener>();
43
44 /**
45 * Creates a new instance of <code>DefaultAudioDeviceModel</code> using the
46 * specified non-null audio device.
47 * @param audioDevice An <code>AudioOutputDevice</code> instance providing the current
48 * settings of the audio device which will be represented by this model.
49 * @throws IllegalArgumentException If <code>audioDevice</code> is <code>null</code>.
50 */
51 public
52 DefaultAudioDeviceModel(AudioOutputDevice audioDevice) {
53 if(audioDevice == null)
54 throw new IllegalArgumentException("audioDevice must be non null");
55
56 this.audioDevice = audioDevice;
57 }
58
59 /**
60 * Registers the specified listener to be notified when
61 * the settings of the audio device are changed.
62 * @param l The <code>AudioDeviceListener</code> to register.
63 */
64 public void
65 addAudioDeviceListener(AudioDeviceListener l) { listeners.add(l); }
66
67 /**
68 * Removes the specified listener.
69 * @param l The <code>AudioDeviceListener</code> to remove.
70 */
71 public void
72 removeAudioDeviceListener(AudioDeviceListener l) { listeners.remove(l); }
73
74 /**
75 * Gets the numerical ID of this audio device.
76 * @return The numerical ID of this audio device or
77 * -1 if the device number is not set.
78 */
79 public int
80 getDeviceID() { return audioDevice.getDeviceID(); }
81
82 /**
83 * Gets the current settings of the audio device represented by this model.
84 * @return <code>AudioOutputDevice</code> instance providing
85 * the current settings of the audio device represented by this model.
86 */
87 public AudioOutputDevice
88 getDeviceInfo() { return audioDevice; }
89
90 /**
91 * Updates the settings of the audio device represented by this model.
92 * @param device The new audio device settings.
93 */
94 public void
95 setDeviceInfo(AudioOutputDevice device) {
96 audioDevice = device;
97 fireSettingsChanged();
98 }
99
100 /**
101 * Sets whether the audio device is enabled or disabled.
102 * @param active If <code>true</code> the audio device is enabled,
103 * else the device is disabled.
104 */
105 public void
106 setActive(boolean active) {
107 if(active == getDeviceInfo().isActive()) return;
108
109 audioDevice.setActive(active);
110 fireSettingsChanged();
111 }
112
113 /**
114 * Determines whether the audio device is active.
115 * @return <code>true</code> if the device is enabled and <code>false</code> otherwise.
116 */
117 public boolean
118 isActive() { return audioDevice.isActive(); }
119
120 /**
121 * Notifies listeners that the settings of the audio device are changed.
122 */
123 private void
124 fireSettingsChanged() {
125 fireSettingsChanged(new AudioDeviceEvent(this, this));
126 }
127
128 /**
129 * Notifies listeners that the settings of the audio device are changed.
130 * This method should be invoked from the event-dispatching thread.
131 */
132 private void
133 fireSettingsChanged(final AudioDeviceEvent e) {
134 SwingUtilities.invokeLater(new Runnable() {
135 public void
136 run() { for(AudioDeviceListener l : listeners) l.settingsChanged(e); }
137 });
138 }
139 }

  ViewVC Help
Powered by ViewVC