diff options
Diffstat (limited to 'songdbj/org/tritonus/share/sampled/mixer/TLine.java')
-rw-r--r-- | songdbj/org/tritonus/share/sampled/mixer/TLine.java | 362 |
1 files changed, 0 insertions, 362 deletions
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TLine.java b/songdbj/org/tritonus/share/sampled/mixer/TLine.java deleted file mode 100644 index 89b38099ed..0000000000 --- a/songdbj/org/tritonus/share/sampled/mixer/TLine.java +++ /dev/null | |||
@@ -1,362 +0,0 @@ | |||
1 | /* | ||
2 | * TLine.java | ||
3 | * | ||
4 | * This file is part of Tritonus: http://www.tritonus.org/ | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Copyright (c) 1999 - 2004 by Matthias Pfisterer | ||
9 | * | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU Library General Public License as published | ||
13 | * by the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU Library General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Library General Public | ||
22 | * License along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | /* | ||
28 | |<--- this code is formatted to fit into 80 columns --->| | ||
29 | */ | ||
30 | |||
31 | package org.tritonus.share.sampled.mixer; | ||
32 | |||
33 | import java.util.Collection; | ||
34 | import java.util.ArrayList; | ||
35 | import java.util.HashSet; | ||
36 | import java.util.Iterator; | ||
37 | import java.util.List; | ||
38 | import java.util.Set; | ||
39 | |||
40 | import javax.sound.sampled.AudioSystem; | ||
41 | import javax.sound.sampled.Control; | ||
42 | import javax.sound.sampled.Line; | ||
43 | import javax.sound.sampled.LineEvent; | ||
44 | import javax.sound.sampled.LineListener; | ||
45 | import javax.sound.sampled.LineUnavailableException; | ||
46 | |||
47 | import org.tritonus.share.TDebug; | ||
48 | import org.tritonus.share.TNotifier; | ||
49 | |||
50 | |||
51 | |||
52 | |||
53 | /** Base class for classes implementing Line. | ||
54 | */ | ||
55 | public abstract class TLine | ||
56 | implements Line | ||
57 | { | ||
58 | private static final Control[] EMPTY_CONTROL_ARRAY = new Control[0]; | ||
59 | |||
60 | private Line.Info m_info; | ||
61 | private boolean m_bOpen; | ||
62 | private List<Control> m_controls; | ||
63 | private Set<LineListener> m_lineListeners; | ||
64 | private TMixer m_mixer; | ||
65 | |||
66 | |||
67 | |||
68 | protected TLine(TMixer mixer, | ||
69 | Line.Info info) | ||
70 | { | ||
71 | setLineInfo(info); | ||
72 | setOpen(false); | ||
73 | m_controls = new ArrayList<Control>(); | ||
74 | m_lineListeners = new HashSet<LineListener>(); | ||
75 | m_mixer = mixer; | ||
76 | } | ||
77 | |||
78 | |||
79 | |||
80 | protected TLine(TMixer mixer, | ||
81 | Line.Info info, | ||
82 | Collection<Control> controls) | ||
83 | { | ||
84 | this (mixer, info); | ||
85 | m_controls.addAll(controls); | ||
86 | } | ||
87 | |||
88 | |||
89 | protected TMixer getMixer() | ||
90 | { | ||
91 | return m_mixer; | ||
92 | } | ||
93 | |||
94 | |||
95 | public Line.Info getLineInfo() | ||
96 | { | ||
97 | return m_info; | ||
98 | } | ||
99 | |||
100 | |||
101 | |||
102 | protected void setLineInfo(Line.Info info) | ||
103 | { | ||
104 | if (TDebug.TraceLine) | ||
105 | { | ||
106 | TDebug.out("TLine.setLineInfo(): setting: " + info); | ||
107 | } | ||
108 | synchronized (this) | ||
109 | { | ||
110 | m_info = info; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | |||
115 | |||
116 | public void open() | ||
117 | throws LineUnavailableException | ||
118 | { | ||
119 | if (TDebug.TraceLine) | ||
120 | { | ||
121 | TDebug.out("TLine.open(): called"); | ||
122 | } | ||
123 | if (! isOpen()) | ||
124 | { | ||
125 | if (TDebug.TraceLine) | ||
126 | { | ||
127 | TDebug.out("TLine.open(): opening"); | ||
128 | } | ||
129 | openImpl(); | ||
130 | if (getMixer() != null) | ||
131 | { | ||
132 | getMixer().registerOpenLine(this); | ||
133 | } | ||
134 | setOpen(true); | ||
135 | } | ||
136 | else | ||
137 | { | ||
138 | if (TDebug.TraceLine) | ||
139 | { | ||
140 | TDebug.out("TLine.open(): already open"); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | |||
146 | |||
147 | /** | ||
148 | * Subclasses should override this method. | ||
149 | */ | ||
150 | protected void openImpl() | ||
151 | throws LineUnavailableException | ||
152 | { | ||
153 | if (TDebug.TraceLine) | ||
154 | { | ||
155 | TDebug.out("TLine.openImpl(): called"); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | |||
160 | |||
161 | public void close() | ||
162 | { | ||
163 | if (TDebug.TraceLine) | ||
164 | { | ||
165 | TDebug.out("TLine.close(): called"); | ||
166 | } | ||
167 | if (isOpen()) | ||
168 | { | ||
169 | if (TDebug.TraceLine) | ||
170 | { | ||
171 | TDebug.out("TLine.close(): closing"); | ||
172 | } | ||
173 | if (getMixer() != null) | ||
174 | { | ||
175 | getMixer().unregisterOpenLine(this); | ||
176 | } | ||
177 | closeImpl(); | ||
178 | setOpen(false); | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | if (TDebug.TraceLine) | ||
183 | { | ||
184 | TDebug.out("TLine.close(): not open"); | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | |||
189 | |||
190 | |||
191 | /** | ||
192 | * Subclasses should override this method. | ||
193 | */ | ||
194 | protected void closeImpl() | ||
195 | { | ||
196 | if (TDebug.TraceLine) | ||
197 | { | ||
198 | TDebug.out("TLine.closeImpl(): called"); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | |||
203 | |||
204 | |||
205 | |||
206 | public boolean isOpen() | ||
207 | { | ||
208 | return m_bOpen; | ||
209 | } | ||
210 | |||
211 | |||
212 | |||
213 | |||
214 | protected void setOpen(boolean bOpen) | ||
215 | { | ||
216 | if (TDebug.TraceLine) | ||
217 | { | ||
218 | TDebug.out("TLine.setOpen(): called, value: " + bOpen); | ||
219 | } | ||
220 | boolean bOldValue = isOpen(); | ||
221 | m_bOpen = bOpen; | ||
222 | if (bOldValue != isOpen()) | ||
223 | { | ||
224 | if (isOpen()) | ||
225 | { | ||
226 | if (TDebug.TraceLine) | ||
227 | { | ||
228 | TDebug.out("TLine.setOpen(): opened"); | ||
229 | } | ||
230 | notifyLineEvent(LineEvent.Type.OPEN); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | if (TDebug.TraceLine) | ||
235 | { | ||
236 | TDebug.out("TLine.setOpen(): closed"); | ||
237 | } | ||
238 | notifyLineEvent(LineEvent.Type.CLOSE); | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | |||
243 | |||
244 | |||
245 | protected void addControl(Control control) | ||
246 | { | ||
247 | synchronized (m_controls) | ||
248 | { | ||
249 | m_controls.add(control); | ||
250 | } | ||
251 | } | ||
252 | |||
253 | |||
254 | |||
255 | protected void removeControl(Control control) | ||
256 | { | ||
257 | synchronized (m_controls) | ||
258 | { | ||
259 | m_controls.remove(control); | ||
260 | } | ||
261 | } | ||
262 | |||
263 | |||
264 | |||
265 | public Control[] getControls() | ||
266 | { | ||
267 | synchronized (m_controls) | ||
268 | { | ||
269 | return m_controls.toArray(EMPTY_CONTROL_ARRAY); | ||
270 | } | ||
271 | } | ||
272 | |||
273 | |||
274 | |||
275 | public Control getControl(Control.Type controlType) | ||
276 | { | ||
277 | synchronized (m_controls) | ||
278 | { | ||
279 | Iterator<Control> it = m_controls.iterator(); | ||
280 | while (it.hasNext()) | ||
281 | { | ||
282 | Control control = it.next(); | ||
283 | if (control.getType().equals(controlType)) | ||
284 | { | ||
285 | return control; | ||
286 | } | ||
287 | } | ||
288 | throw new IllegalArgumentException("no control of type " + controlType); | ||
289 | } | ||
290 | } | ||
291 | |||
292 | |||
293 | |||
294 | public boolean isControlSupported(Control.Type controlType) | ||
295 | { | ||
296 | // TDebug.out("TLine.isSupportedControl(): called"); | ||
297 | try | ||
298 | { | ||
299 | return getControl(controlType) != null; | ||
300 | } | ||
301 | catch (IllegalArgumentException e) | ||
302 | { | ||
303 | if (TDebug.TraceAllExceptions) | ||
304 | { | ||
305 | TDebug.out(e); | ||
306 | } | ||
307 | // TDebug.out("TLine.isSupportedControl(): returning false"); | ||
308 | return false; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | |||
313 | |||
314 | public void addLineListener(LineListener listener) | ||
315 | { | ||
316 | // TDebug.out("%% TChannel.addListener(): called"); | ||
317 | synchronized (m_lineListeners) | ||
318 | { | ||
319 | m_lineListeners.add(listener); | ||
320 | } | ||
321 | } | ||
322 | |||
323 | |||
324 | |||
325 | public void removeLineListener(LineListener listener) | ||
326 | { | ||
327 | synchronized (m_lineListeners) | ||
328 | { | ||
329 | m_lineListeners.remove(listener); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | |||
334 | |||
335 | private Set<LineListener> getLineListeners() | ||
336 | { | ||
337 | synchronized (m_lineListeners) | ||
338 | { | ||
339 | return new HashSet<LineListener>(m_lineListeners); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | |||
344 | // is overridden in TDataLine to provide a position | ||
345 | protected void notifyLineEvent(LineEvent.Type type) | ||
346 | { | ||
347 | notifyLineEvent(new LineEvent(this, type, AudioSystem.NOT_SPECIFIED)); | ||
348 | } | ||
349 | |||
350 | |||
351 | |||
352 | protected void notifyLineEvent(LineEvent event) | ||
353 | { | ||
354 | // TDebug.out("%% TChannel.notifyChannelEvent(): called"); | ||
355 | // Channel.Event event = new Channel.Event(this, type, getPosition()); | ||
356 | TNotifier.notifier.addEntry(event, getLineListeners()); | ||
357 | } | ||
358 | } | ||
359 | |||
360 | |||
361 | |||
362 | /*** TLine.java ***/ | ||