/[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 1567 - (show annotations) (download)
Thu Dec 6 19:37:41 2007 UTC (16 years, 4 months ago) by iliev
File size: 5651 byte(s)
* added confirmation dialog on exit
* some minor gui enhancements
* preparations for release 0.8a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
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.jsampler.task.Audio;
33
34 import org.linuxsampler.lscp.AudioOutputDevice;
35 import org.linuxsampler.lscp.Parameter;
36
37
38 /**
39 * This class provides default implementation of the <code>AudioDeviceModel</code> interface.
40 * @author Grigor Iliev
41 */
42 public class DefaultAudioDeviceModel implements AudioDeviceModel {
43 private AudioOutputDevice audioDevice;
44
45 private final Vector<AudioDeviceListener> listeners = new Vector<AudioDeviceListener>();
46
47 /**
48 * Creates a new instance of <code>DefaultAudioDeviceModel</code> using the
49 * specified non-null audio device.
50 * @param audioDevice An <code>AudioOutputDevice</code> instance providing the current
51 * settings of the audio device which will be represented by this model.
52 * @throws IllegalArgumentException If <code>audioDevice</code> is <code>null</code>.
53 */
54 public
55 DefaultAudioDeviceModel(AudioOutputDevice audioDevice) {
56 if(audioDevice == null)
57 throw new IllegalArgumentException("audioDevice must be non null");
58
59 this.audioDevice = audioDevice;
60 }
61
62 /**
63 * Registers the specified listener to be notified when
64 * the settings of the audio device are changed.
65 * @param l The <code>AudioDeviceListener</code> to register.
66 */
67 public void
68 addAudioDeviceListener(AudioDeviceListener l) { listeners.add(l); }
69
70 /**
71 * Removes the specified listener.
72 * @param l The <code>AudioDeviceListener</code> to remove.
73 */
74 public void
75 removeAudioDeviceListener(AudioDeviceListener l) { listeners.remove(l); }
76
77 /**
78 * Gets the numerical ID of this audio device.
79 * @return The numerical ID of this audio device or
80 * -1 if the device number is not set.
81 */
82 public int
83 getDeviceId() { return audioDevice.getDeviceId(); }
84
85 /**
86 * Gets the current settings of the audio device represented by this model.
87 * @return <code>AudioOutputDevice</code> instance providing
88 * the current settings of the audio device represented by this model.
89 */
90 public AudioOutputDevice
91 getDeviceInfo() { return audioDevice; }
92
93 /**
94 * Updates the settings of the audio device represented by this model.
95 * @param device The new audio device settings.
96 */
97 public void
98 setDeviceInfo(AudioOutputDevice device) {
99 audioDevice = device;
100 fireSettingsChanged();
101 }
102
103 /**
104 * Sets whether the audio device is enabled or disabled.
105 * @param active If <code>true</code> the audio device is enabled,
106 * else the device is disabled.
107 */
108 public void
109 setActive(boolean active) {
110 if(active == getDeviceInfo().isActive()) return;
111
112 audioDevice.setActive(active);
113 fireSettingsChanged();
114 }
115
116 /**
117 * Determines whether the audio device is active.
118 * @return <code>true</code> if the device is enabled and <code>false</code> otherwise.
119 */
120 public boolean
121 isActive() { return audioDevice.isActive(); }
122
123 /**
124 * Schedules a new task for enabling/disabling the audio device.
125 * @param active If <code>true</code> the audio device is enabled,
126 * else the device is disabled.
127 */
128 public void
129 setBackendActive(boolean active) {
130 CC.getTaskQueue().add(new Audio.EnableDevice(getDeviceId(), active));
131 }
132
133 /**
134 * Schedules a new task for altering
135 * a specific setting of the audio output device.
136 * @param prm The parameter to be set.
137 */
138 public void
139 setBackendDeviceParameter(Parameter prm) {
140 CC.getTaskQueue().add(new Audio.SetDeviceParameter(getDeviceId(), prm));
141 }
142
143 /**
144 * Schedules a new task for changing the channel number of the audio device.
145 * @param channels The new number of audio channels.
146 */
147 public void
148 setBackendChannelCount(int channels) {
149 CC.getTaskQueue().add(new Audio.SetChannelCount(getDeviceId(), channels));
150 }
151
152 /**
153 * Schedules a new task for altering a specific
154 * setting of the specified audio output channel.
155 * @param channel The channel number.
156 * @param prm The parameter to be set.
157 */
158 public void
159 setBackendChannelParameter(int channel, Parameter prm) {
160 CC.getTaskQueue().add(new Audio.SetChannelParameter(getDeviceId(), channel, prm));
161 }
162
163 /**
164 * Notifies listeners that the settings of the audio device are changed.
165 */
166 private void
167 fireSettingsChanged() {
168 SwingUtilities.invokeLater(new Runnable() {
169 public void
170 run() {
171 AudioDeviceModel model = DefaultAudioDeviceModel.this;
172 fireSettingsChanged(new AudioDeviceEvent(model, model));
173 }
174 });
175 }
176
177 /**
178 * Notifies listeners that the settings of the audio device are changed.
179 * This method should be invoked from the event-dispatching thread.
180 */
181 private void
182 fireSettingsChanged(final AudioDeviceEvent e) {
183 CC.getSamplerModel().setModified(true);
184 for(AudioDeviceListener l : listeners) l.settingsChanged(e);
185 }
186 }

  ViewVC Help
Powered by ViewVC