summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/share/sampled/mixer
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/org/tritonus/share/sampled/mixer')
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TBaseDataLine.java107
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TBooleanControl.java128
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TClip.java340
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TCompoundControl.java90
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TCompoundControlType.java55
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TControlController.java98
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TControllable.java62
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TDataLine.java304
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TEnumControl.java92
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TFloatControl.java134
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TLine.java362
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TMixer.java506
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TMixerInfo.java56
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TMixerProvider.java240
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TPort.java77
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TSoftClip.java318
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/package.html14
17 files changed, 0 insertions, 2983 deletions
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TBaseDataLine.java b/songdbj/org/tritonus/share/sampled/mixer/TBaseDataLine.java
deleted file mode 100644
index e589439838..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TBaseDataLine.java
+++ /dev/null
@@ -1,107 +0,0 @@
1/*
2 * TBaseDataLine.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 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/*
26|<--- this code is formatted to fit into 80 columns --->|
27*/
28
29package org.tritonus.share.sampled.mixer;
30
31import java.util.Collection;
32import java.util.EventListener;
33import java.util.EventObject;
34import java.util.HashSet;
35import java.util.Set;
36
37import javax.sound.sampled.AudioFormat;
38import javax.sound.sampled.AudioSystem;
39import javax.sound.sampled.Control;
40import javax.sound.sampled.DataLine;
41import javax.sound.sampled.LineEvent;
42import javax.sound.sampled.Line;
43import javax.sound.sampled.LineUnavailableException;
44
45import org.tritonus.share.TDebug;
46
47
48
49/** Base class for implementing SourceDataLine or TargetDataLine.
50 */
51public abstract class TBaseDataLine
52extends TDataLine
53{
54 public TBaseDataLine(TMixer mixer,
55 DataLine.Info info)
56 {
57 super(mixer,
58 info);
59 }
60
61
62
63 public TBaseDataLine(TMixer mixer,
64 DataLine.Info info,
65 Collection<Control> controls)
66 {
67 super(mixer,
68 info,
69 controls);
70 }
71
72
73
74 public void open(AudioFormat format, int nBufferSize)
75 throws LineUnavailableException
76 {
77 if (TDebug.TraceDataLine) { TDebug.out("TBaseDataLine.open(AudioFormat, int): called with buffer size: " + nBufferSize); }
78 setBufferSize(nBufferSize);
79 open(format);
80 }
81
82
83
84 public void open(AudioFormat format)
85 throws LineUnavailableException
86 {
87 if (TDebug.TraceDataLine) { TDebug.out("TBaseDataLine.open(AudioFormat): called"); }
88 setFormat(format);
89 open();
90 }
91
92
93 // IDEA: move to TDataLine or TLine?
94 // necessary and wise at all?
95 protected void finalize()
96 {
97 if (isOpen())
98 {
99 close();
100 }
101 }
102}
103
104
105
106/*** TBaseDataLine.java ***/
107
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TBooleanControl.java b/songdbj/org/tritonus/share/sampled/mixer/TBooleanControl.java
deleted file mode 100644
index a722edbf31..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TBooleanControl.java
+++ /dev/null
@@ -1,128 +0,0 @@
1/*
2 * TBooleanControl.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 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
31package org.tritonus.share.sampled.mixer;
32
33import javax.sound.sampled.BooleanControl;
34
35import org.tritonus.share.TDebug;
36
37
38
39
40/** Base class for classes implementing BooleanControl.
41 */
42public class TBooleanControl
43extends BooleanControl
44implements TControllable
45{
46 private TControlController m_controller;
47
48
49
50 public TBooleanControl(BooleanControl.Type type,
51 boolean bInitialValue)
52 {
53 this(type, bInitialValue, null);
54 }
55
56
57
58 public TBooleanControl(BooleanControl.Type type,
59 boolean bInitialValue,
60 TCompoundControl parentControl)
61 {
62 super(type, bInitialValue);
63 if (TDebug.TraceControl)
64 {
65 TDebug.out("TBooleanControl.<init>: begin");
66 }
67 m_controller = new TControlController();
68 if (TDebug.TraceControl)
69 {
70 TDebug.out("TBooleanControl.<init>: end");
71 }
72 }
73
74
75
76 public TBooleanControl(BooleanControl.Type type,
77 boolean bInitialValue,
78 String strTrueStateLabel,
79 String strFalseStateLabel)
80 {
81 this(type, bInitialValue, strTrueStateLabel, strFalseStateLabel, null);
82 }
83
84
85
86 public TBooleanControl(BooleanControl.Type type,
87 boolean bInitialValue,
88 String strTrueStateLabel,
89 String strFalseStateLabel,
90 TCompoundControl parentControl)
91 {
92 super(type, bInitialValue, strTrueStateLabel, strFalseStateLabel);
93 if (TDebug.TraceControl)
94 {
95 TDebug.out("TBooleanControl.<init>: begin");
96 }
97 m_controller = new TControlController();
98 if (TDebug.TraceControl)
99 {
100 TDebug.out("TBooleanControl.<init>: end");
101 }
102 }
103
104
105
106 public void setParentControl(TCompoundControl compoundControl)
107 {
108 m_controller.setParentControl(compoundControl);
109 }
110
111
112
113 public TCompoundControl getParentControl()
114 {
115 return m_controller.getParentControl();
116 }
117
118
119
120 public void commit()
121 {
122 m_controller.commit();
123 }
124}
125
126
127
128/*** TBooleanControl.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TClip.java b/songdbj/org/tritonus/share/sampled/mixer/TClip.java
deleted file mode 100644
index e0a8140c37..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TClip.java
+++ /dev/null
@@ -1,340 +0,0 @@
1/*
2 * TClip.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 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26/*
27|<--- this code is formatted to fit into 80 columns --->|
28*/
29
30package org.tritonus.share.sampled.mixer;
31
32import java.io.IOException;
33import java.io.ByteArrayInputStream;
34import java.util.Collection;
35
36import javax.sound.sampled.AudioFormat;
37import javax.sound.sampled.AudioSystem;
38import javax.sound.sampled.Clip;
39import javax.sound.sampled.Control;
40import javax.sound.sampled.DataLine;
41import javax.sound.sampled.SourceDataLine;
42import javax.sound.sampled.AudioInputStream;
43import javax.sound.sampled.LineUnavailableException;
44import javax.sound.sampled.Mixer;
45
46import org.tritonus.share.TDebug;
47import org.tritonus.share.sampled.mixer.TDataLine;
48
49
50
51public class TClip
52extends TDataLine
53implements Clip
54{
55 private static final Class[] CONTROL_CLASSES = {/*GainControl.class*/};
56 private static final int BUFFER_FRAMES = 16384;
57
58
59 public TClip(DataLine.Info info)
60 {
61 super(null, // TMixer
62 info);
63 }
64
65
66
67 public TClip(DataLine.Info info,
68 Collection<Control> controls)
69 {
70 super(null, // TMixer
71 info,
72 controls);
73 }
74
75
76
77 public void open(AudioFormat audioFormat,
78 byte[] abData,
79 int nOffset,
80 int nLength)
81 throws LineUnavailableException
82 {
83 // int nBufferLength = nNumFrames * audioFormat.getFrameSize();
84 // TODO: check if nOffset + nBufferLength <= abData.length
85 // perhaps truncate automatically
86 ByteArrayInputStream bais = new ByteArrayInputStream(abData, nOffset, nLength);
87 AudioInputStream audioInputStream = new AudioInputStream(bais, audioFormat, AudioSystem.NOT_SPECIFIED);
88 try
89 {
90 open(audioInputStream);
91 }
92 catch (IOException e)
93 {
94 if (TDebug.TraceAllExceptions)
95 {
96 TDebug.out(e);
97 }
98 throw new LineUnavailableException("IOException occured");
99 }
100 }
101
102
103
104 public void open(AudioInputStream audioInputStream)
105 throws LineUnavailableException, IOException
106 {
107 AudioFormat audioFormat = audioInputStream.getFormat();
108 // TOOD:
109 DataLine.Info info = new DataLine.Info(Clip.class,
110 audioFormat, -1/*nBufferSize*/);
111/*
112 setLineInfo(info);
113 int nFrameSize = audioFormat.getFrameSize();
114 long lTotalLength = audioInputStream.getFrameLength() * nFrameSize;
115 int nFormat = Esd.ESD_STREAM | Esd.ESD_PLAY | EsdUtils.getEsdFormat(audioFormat);
116 if (TDebug.TraceClip)
117 {
118 TDebug.out("format: " + nFormat);
119 TDebug.out("sample rate: " + audioFormat.getSampleRate());
120 }
121 // m_esdSample.open(nFormat, (int) audioFormat.getSampleRate(), (int) lTotalLength);
122 if (TDebug.TraceClip)
123 {
124 TDebug.out("size in esd: " + audioInputStream.getFrameLength() * nFrameSize);
125 }
126 int nBufferLength = BUFFER_FRAMES * nFrameSize;
127 byte[] abData = new byte[nBufferLength];
128 int nBytesRead = 0;
129 int nTotalBytes = 0;
130 while (nBytesRead != -1)
131 {
132 try
133 {
134 nBytesRead = audioInputStream.read(abData, 0, abData.length);
135 }
136 catch (IOException e)
137 {
138 if (TDebug.TraceClip || TDebug.TraceAllExceptions)
139 {
140 TDebug.out(e);
141 }
142 }
143 if (nBytesRead >= 0)
144 {
145 nTotalBytes += nBytesRead;
146 if (TDebug.TraceClip)
147 {
148 TDebug.out("TClip.open(): total bytes: " + nTotalBytes);
149 TDebug.out("TClip.open(): Trying to write: " + nBytesRead);
150 }
151 int nBytesWritten = 0; //m_esdSample.write(abData, 0, nBytesRead);
152 if (TDebug.TraceClip)
153 {
154 TDebug.out("TClip.open(): Written: " + nBytesWritten);
155 }
156 }
157 }
158 // to trigger the events
159 // open();
160 */
161 }
162
163
164
165 public int getFrameLength()
166 {
167 // TODO:
168 return -1;
169 }
170
171
172
173 public long getMicrosecondLength()
174 {
175 // TODO:
176 return -1;
177 }
178
179
180
181 public void setFramePosition(int nPosition)
182 {
183 // TOOD:
184 }
185
186
187
188 public void setMicrosecondPosition(long lPosition)
189 {
190 // TOOD:
191 }
192
193
194
195 public int getFramePosition()
196 {
197 // TOOD:
198 return -1;
199 }
200
201
202
203 public long getMicrosecondPosition()
204 {
205 // TOOD:
206 return -1;
207 }
208
209
210
211 public void setLoopPoints(int nStart, int nEnd)
212 {
213 // TOOD:
214 }
215
216
217
218 public void loop(int nCount)
219 {
220 if (TDebug.TraceClip)
221 {
222 TDebug.out("TClip.loop(int): called; count = " + nCount);
223 }
224 if (false/*isStarted()*/)
225 {
226 /*
227 * only allow zero count to stop the looping
228 * at the end of an iteration.
229 */
230 if (nCount == 0)
231 {
232 if (TDebug.TraceClip)
233 {
234 TDebug.out("TClip.loop(int): stopping sample");
235 }
236 // m_esdSample.stop();
237 }
238 }
239 else
240 {
241 if (nCount == 0)
242 {
243 if (TDebug.TraceClip)
244 {
245 TDebug.out("TClip.loop(int): starting sample (once)");
246 }
247 // m_esdSample.play();
248 }
249 else
250 {
251 /*
252 * we're ignoring the count, because esd
253 * cannot loop for a fixed number of
254 * times.
255 */
256 // TDebug.out("hallo");
257 if (TDebug.TraceClip)
258 {
259 TDebug.out("TClip.loop(int): starting sample (forever)");
260 }
261 // m_esdSample.loop();
262 }
263 }
264 // TOOD:
265 }
266
267
268
269 public void flush()
270 {
271 // TOOD:
272 }
273
274
275
276 public void drain()
277 {
278 // TOOD:
279 }
280
281
282
283 public void close()
284 {
285 // m_esdSample.free();
286 // m_esdSample.close();
287 // TOOD:
288 }
289
290
291
292
293 public void open()
294 {
295 // TODO:
296 }
297
298
299
300 public void start()
301 {
302 if (TDebug.TraceClip)
303 {
304 TDebug.out("TClip.start(): called");
305 }
306 /*
307 * This is a hack. What start() really should do is
308 * start playing at the position playback was stopped.
309 */
310 if (TDebug.TraceClip)
311 {
312 TDebug.out("TClip.start(): calling 'loop(0)' [hack]");
313 }
314 loop(0);
315 }
316
317
318
319 public void stop()
320 {
321 // TODO:
322 // m_esdSample.kill();
323 }
324
325
326
327 /*
328 * This method is enforced by DataLine, but doesn't make any
329 * sense for Clips.
330 */
331 public int available()
332 {
333 return -1;
334 }
335}
336
337
338
339/*** TClip.java ***/
340
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TCompoundControl.java b/songdbj/org/tritonus/share/sampled/mixer/TCompoundControl.java
deleted file mode 100644
index 4a370eb86c..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TCompoundControl.java
+++ /dev/null
@@ -1,90 +0,0 @@
1/*
2 * TCompoundControl.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 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
31package org.tritonus.share.sampled.mixer;
32
33import javax.sound.sampled.CompoundControl;
34import javax.sound.sampled.Control;
35
36import org.tritonus.share.TDebug;
37
38
39
40
41/** Base class for classes implementing Line.
42 */
43public class TCompoundControl
44extends CompoundControl
45implements TControllable
46{
47 private TControlController m_controller;
48
49
50
51 public TCompoundControl(CompoundControl.Type type,
52 Control[] aMemberControls)
53 {
54 super(type, aMemberControls);
55 if (TDebug.TraceControl)
56 {
57 TDebug.out("TCompoundControl.<init>: begin");
58 }
59 m_controller = new TControlController();
60 if (TDebug.TraceControl)
61 {
62 TDebug.out("TCompoundControl.<init>: end");
63 }
64 }
65
66
67
68 public void setParentControl(TCompoundControl compoundControl)
69 {
70 m_controller.setParentControl(compoundControl);
71 }
72
73
74
75 public TCompoundControl getParentControl()
76 {
77 return m_controller.getParentControl();
78 }
79
80
81
82 public void commit()
83 {
84 m_controller.commit();
85 }
86}
87
88
89
90/*** TCompoundControl.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TCompoundControlType.java b/songdbj/org/tritonus/share/sampled/mixer/TCompoundControlType.java
deleted file mode 100644
index 1b90b1a673..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TCompoundControlType.java
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 * TCompoundControlType.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 by Matthias Pfisterer
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/*
26|<--- this code is formatted to fit into 80 columns --->|
27*/
28
29package org.tritonus.share.sampled.mixer;
30
31import javax.sound.sampled.CompoundControl;
32
33
34
35/** CompoundControl.Type class.
36 This class is only needed to provide a public constructor.
37 */
38public class TCompoundControlType
39extends CompoundControl.Type
40{
41 /** Constructor.
42 Constructs a CompoundControl.Type with the
43 name given.
44
45 @param strName The name of the control.
46 */
47 public TCompoundControlType(String strName)
48 {
49 super(strName);
50 }
51}
52
53
54
55/*** TCompoundControlType.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TControlController.java b/songdbj/org/tritonus/share/sampled/mixer/TControlController.java
deleted file mode 100644
index ec17c45b59..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TControlController.java
+++ /dev/null
@@ -1,98 +0,0 @@
1/*
2 * TControlController.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 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
31package org.tritonus.share.sampled.mixer;
32
33import java.util.Collection;
34import java.util.ArrayList;
35import java.util.HashSet;
36import java.util.Iterator;
37import java.util.List;
38import java.util.Set;
39
40import javax.sound.sampled.AudioSystem;
41import javax.sound.sampled.Control;
42import javax.sound.sampled.Line;
43import javax.sound.sampled.LineEvent;
44import javax.sound.sampled.LineListener;
45import javax.sound.sampled.LineUnavailableException;
46import javax.sound.sampled.Port;
47
48import org.tritonus.share.TDebug;
49
50
51
52
53/** Base class for classes implementing Line.
54 */
55public class TControlController
56implements TControllable
57{
58 /** The parent (compound) control.
59 In case this control is part of a compound control, the parentControl
60 property is set to a value other than null.
61 */
62 private TCompoundControl m_parentControl;
63
64
65 public TControlController()
66 {
67 }
68
69
70
71 public void setParentControl(TCompoundControl compoundControl)
72 {
73 m_parentControl = compoundControl;
74 }
75
76
77 public TCompoundControl getParentControl()
78 {
79 return m_parentControl;
80 }
81
82
83 public void commit()
84 {
85 if (TDebug.TraceControl)
86 {
87 TDebug.out("TControlController.commit(): called [" + this.getClass().getName() + "]");
88 }
89 if (getParentControl() != null)
90 {
91 getParentControl().commit();
92 }
93 }
94}
95
96
97
98/*** TControlController.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TControllable.java b/songdbj/org/tritonus/share/sampled/mixer/TControllable.java
deleted file mode 100644
index b89d34a2b3..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TControllable.java
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * TControllable.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 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
31package org.tritonus.share.sampled.mixer;
32
33import java.util.Collection;
34import java.util.ArrayList;
35import java.util.HashSet;
36import java.util.Iterator;
37import java.util.List;
38import java.util.Set;
39
40import javax.sound.sampled.AudioSystem;
41import javax.sound.sampled.Control;
42import javax.sound.sampled.Line;
43import javax.sound.sampled.LineEvent;
44import javax.sound.sampled.LineListener;
45import javax.sound.sampled.LineUnavailableException;
46import javax.sound.sampled.Port;
47
48import org.tritonus.share.TDebug;
49
50
51
52
53public interface TControllable
54{
55 public void setParentControl(TCompoundControl compoundControl);
56 public TCompoundControl getParentControl();
57 public void commit();
58}
59
60
61
62/*** TControllable.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java b/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java
deleted file mode 100644
index a493bac6c5..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java
+++ /dev/null
@@ -1,304 +0,0 @@
1/*
2 * TDataLine.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
31package org.tritonus.share.sampled.mixer;
32
33import java.util.Collection;
34import java.util.EventListener;
35import java.util.EventObject;
36import java.util.HashSet;
37import java.util.Set;
38
39import javax.sound.sampled.AudioFormat;
40import javax.sound.sampled.AudioSystem;
41import javax.sound.sampled.Control;
42import javax.sound.sampled.DataLine;
43import javax.sound.sampled.LineEvent;
44import javax.sound.sampled.Line;
45
46import org.tritonus.share.TDebug;
47
48
49
50/** Base class for classes implementing DataLine.
51 */
52public abstract class TDataLine
53extends TLine
54implements DataLine
55{
56 private static final int DEFAULT_BUFFER_SIZE = 128000;
57
58 private AudioFormat m_format;
59 private int m_nBufferSize;
60 private boolean m_bRunning;
61 // private boolean m_bActive;
62
63
64
65
66 public TDataLine(TMixer mixer,
67 DataLine.Info info)
68 {
69 super(mixer,
70 info);
71 init(info);
72 }
73
74
75
76 public TDataLine(TMixer mixer,
77 DataLine.Info info,
78 Collection<Control> controls)
79 {
80 super(mixer,
81 info,
82 controls);
83 init(info);
84 }
85
86
87
88 // IDEA: extract format and bufsize from info?
89 private void init(DataLine.Info info)
90 {
91 m_format = null;
92 m_nBufferSize = AudioSystem.NOT_SPECIFIED;
93 setRunning(false);
94 // setActive(false);
95 }
96
97
98
99 // not defined here:
100 // public void drain()
101 // public void flush()
102
103
104
105 public void start()
106 {
107 if (TDebug.TraceSourceDataLine)
108 {
109 TDebug.out("TDataLine.start(): called");
110 }
111 setRunning(true);
112 }
113
114
115
116 public void stop()
117 {
118 if (TDebug.TraceSourceDataLine)
119 {
120 TDebug.out("TDataLine.stop(): called");
121 }
122 setRunning(false);
123 }
124
125
126
127 public boolean isRunning()
128 {
129 return m_bRunning;
130 }
131
132
133
134 // TODO: recheck
135 protected void setRunning(boolean bRunning)
136 {
137 boolean bOldValue = isRunning();
138 m_bRunning = bRunning;
139 if (bOldValue != isRunning())
140 {
141 if (isRunning())
142 {
143 startImpl();
144 notifyLineEvent(LineEvent.Type.START);
145 }
146 else
147 {
148 stopImpl();
149 notifyLineEvent(LineEvent.Type.STOP);
150 }
151 }
152 }
153
154
155
156 protected void startImpl()
157 {
158 }
159
160
161
162 protected void stopImpl()
163 {
164 }
165
166
167
168 /**
169 * This implementation returns the status of isRunning().
170 * Subclasses should overwrite this method if there is more
171 * precise information about the status of the line available.
172 */
173 public boolean isActive()
174 {
175 return isRunning();
176 }
177
178
179/*
180 public boolean isStarted()
181 {
182 return m_bStarted;
183 }
184*/
185
186 // TODO: should only ALLOW engaging in data I/O.
187 // actual START event should only be sent when line really becomes active
188/*
189 protected void setStarted(boolean bStarted)
190 {
191 m_bStarted = bStarted;
192 if (!isRunning())
193 {
194 setActive(false);
195 }
196 }
197*/
198
199
200 public AudioFormat getFormat()
201 {
202 return m_format;
203 }
204
205
206
207 protected void setFormat(AudioFormat format)
208 {
209 if (TDebug.TraceDataLine)
210 {
211 TDebug.out("TDataLine.setFormat(): setting: " + format);
212 }
213 m_format = format;
214 }
215
216
217
218 public int getBufferSize()
219 {
220 return m_nBufferSize;
221 }
222
223
224
225 protected void setBufferSize(int nBufferSize)
226 {
227 if (TDebug.TraceDataLine)
228 {
229 TDebug.out("TDataLine.setBufferSize(): setting: " + nBufferSize);
230 }
231 m_nBufferSize = nBufferSize;
232 }
233
234
235
236 // not defined here:
237 // public int available()
238
239
240
241 public int getFramePosition()
242 {
243 // TODO:
244 return -1;
245 }
246
247
248
249 public long getLongFramePosition()
250 {
251 // TODO:
252 return -1;
253 }
254
255
256
257 public long getMicrosecondPosition()
258 {
259 return (long) (getFramePosition() * getFormat().getFrameRate() * 1000000);
260 }
261
262
263
264 /*
265 * Has to be overridden to be useful.
266 */
267 public float getLevel()
268 {
269 return AudioSystem.NOT_SPECIFIED;
270 }
271
272
273
274 protected void checkOpen()
275 {
276 if (getFormat() == null)
277 {
278 throw new IllegalStateException("format must be specified");
279 }
280 if (getBufferSize() == AudioSystem.NOT_SPECIFIED)
281 {
282 setBufferSize(getDefaultBufferSize());
283 }
284 }
285
286
287
288 protected int getDefaultBufferSize()
289 {
290 return DEFAULT_BUFFER_SIZE;
291 }
292
293
294
295 protected void notifyLineEvent(LineEvent.Type type)
296 {
297 notifyLineEvent(new LineEvent(this, type, getFramePosition()));
298 }
299}
300
301
302
303/*** TDataLine.java ***/
304
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TEnumControl.java b/songdbj/org/tritonus/share/sampled/mixer/TEnumControl.java
deleted file mode 100644
index 2c9132401f..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TEnumControl.java
+++ /dev/null
@@ -1,92 +0,0 @@
1/*
2 * TEnumControl.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 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
31package org.tritonus.share.sampled.mixer;
32
33import javax.sound.sampled.EnumControl;
34
35import org.tritonus.share.TDebug;
36
37
38
39
40/** Base class for classes implementing Line.
41 */
42public class TEnumControl
43extends EnumControl
44implements TControllable
45{
46 private TControlController m_controller;
47
48
49
50 public TEnumControl(EnumControl.Type type,
51 Object[] aValues,
52 Object value)
53 {
54 super(type,
55 aValues,
56 value);
57 if (TDebug.TraceControl)
58 {
59 TDebug.out("TEnumControl.<init>: begin");
60 }
61 m_controller = new TControlController();
62 if (TDebug.TraceControl)
63 {
64 TDebug.out("TEnumControl.<init>: end");
65 }
66 }
67
68
69
70 public void setParentControl(TCompoundControl compoundControl)
71 {
72 m_controller.setParentControl(compoundControl);
73 }
74
75
76
77 public TCompoundControl getParentControl()
78 {
79 return m_controller.getParentControl();
80 }
81
82
83
84 public void commit()
85 {
86 m_controller.commit();
87 }
88}
89
90
91
92/*** TEnumControl.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TFloatControl.java b/songdbj/org/tritonus/share/sampled/mixer/TFloatControl.java
deleted file mode 100644
index 8a80016865..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TFloatControl.java
+++ /dev/null
@@ -1,134 +0,0 @@
1/*
2 * TFloatControl.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2001 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
31package org.tritonus.share.sampled.mixer;
32
33import javax.sound.sampled.FloatControl;
34
35import org.tritonus.share.TDebug;
36
37
38
39
40/** Base class for classes implementing Line.
41 */
42public class TFloatControl
43extends FloatControl
44implements TControllable
45{
46 private TControlController m_controller;
47
48
49
50 public TFloatControl(FloatControl.Type type,
51 float fMinimum,
52 float fMaximum,
53 float fPrecision,
54 int nUpdatePeriod,
55 float fInitialValue,
56 String strUnits)
57 {
58 super(type,
59 fMinimum,
60 fMaximum,
61 fPrecision,
62 nUpdatePeriod,
63 fInitialValue,
64 strUnits);
65 if (TDebug.TraceControl)
66 {
67 TDebug.out("TFloatControl.<init>: begin");
68 }
69 m_controller = new TControlController();
70 if (TDebug.TraceControl)
71 {
72 TDebug.out("TFloatControl.<init>: end");
73 }
74 }
75
76
77
78 public TFloatControl(FloatControl.Type type,
79 float fMinimum,
80 float fMaximum,
81 float fPrecision,
82 int nUpdatePeriod,
83 float fInitialValue,
84 String strUnits,
85 String strMinLabel,
86 String strMidLabel,
87 String strMaxLabel)
88 {
89 super(type,
90 fMinimum,
91 fMaximum,
92 fPrecision,
93 nUpdatePeriod,
94 fInitialValue,
95 strUnits,
96 strMinLabel,
97 strMidLabel,
98 strMaxLabel);
99 if (TDebug.TraceControl)
100 {
101 TDebug.out("TFloatControl.<init>: begin");
102 }
103 m_controller = new TControlController();
104 if (TDebug.TraceControl)
105 {
106 TDebug.out("TFloatControl.<init>: end");
107 }
108 }
109
110
111
112 public void setParentControl(TCompoundControl compoundControl)
113 {
114 m_controller.setParentControl(compoundControl);
115 }
116
117
118
119 public TCompoundControl getParentControl()
120 {
121 return m_controller.getParentControl();
122 }
123
124
125
126 public void commit()
127 {
128 m_controller.commit();
129 }
130}
131
132
133
134/*** TFloatControl.java ***/
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
31package org.tritonus.share.sampled.mixer;
32
33import java.util.Collection;
34import java.util.ArrayList;
35import java.util.HashSet;
36import java.util.Iterator;
37import java.util.List;
38import java.util.Set;
39
40import javax.sound.sampled.AudioSystem;
41import javax.sound.sampled.Control;
42import javax.sound.sampled.Line;
43import javax.sound.sampled.LineEvent;
44import javax.sound.sampled.LineListener;
45import javax.sound.sampled.LineUnavailableException;
46
47import org.tritonus.share.TDebug;
48import org.tritonus.share.TNotifier;
49
50
51
52
53/** Base class for classes implementing Line.
54 */
55public abstract class TLine
56implements 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 ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TMixer.java b/songdbj/org/tritonus/share/sampled/mixer/TMixer.java
deleted file mode 100644
index 6a5dc4db72..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TMixer.java
+++ /dev/null
@@ -1,506 +0,0 @@
1/*
2 * TMixer.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
31package org.tritonus.share.sampled.mixer;
32
33import java.util.ArrayList;
34import java.util.Collection;
35import java.util.Iterator;
36import java.util.Set;
37
38import javax.sound.sampled.AudioFormat;
39import javax.sound.sampled.Clip;
40import javax.sound.sampled.DataLine;
41import javax.sound.sampled.Line;
42import javax.sound.sampled.LineUnavailableException;
43import javax.sound.sampled.Mixer;
44import javax.sound.sampled.Port;
45import javax.sound.sampled.SourceDataLine;
46import javax.sound.sampled.TargetDataLine;
47
48import org.tritonus.share.TDebug;
49import org.tritonus.share.sampled.AudioFormats;
50import org.tritonus.share.ArraySet;
51
52
53
54// TODO: global controls (that use the system mixer)
55public abstract class TMixer
56extends TLine
57implements Mixer
58{
59 private static Line.Info[] EMPTY_LINE_INFO_ARRAY = new Line.Info[0];
60 private static Line[] EMPTY_LINE_ARRAY = new Line[0];
61
62 private Mixer.Info m_mixerInfo;
63 private Collection<AudioFormat> m_supportedSourceFormats;
64 private Collection<AudioFormat> m_supportedTargetFormats;
65 private Collection<Line.Info> m_supportedSourceLineInfos;
66 private Collection<Line.Info> m_supportedTargetLineInfos;
67 private Set<SourceDataLine> m_openSourceDataLines;
68 private Set<TargetDataLine> m_openTargetDataLines;
69
70
71 /** Constructor for mixers that use setSupportInformation().
72 */
73 protected TMixer(Mixer.Info mixerInfo,
74 Line.Info lineInfo)
75 {
76 this(mixerInfo,
77 lineInfo,
78 new ArrayList<AudioFormat>(),
79 new ArrayList<AudioFormat>(),
80 new ArrayList<Line.Info>(),
81 new ArrayList<Line.Info>());
82 }
83
84
85
86 /** Constructor for mixers.
87 */
88 protected TMixer(Mixer.Info mixerInfo,
89 Line.Info lineInfo,
90 Collection<AudioFormat> supportedSourceFormats,
91 Collection<AudioFormat> supportedTargetFormats,
92 Collection<Line.Info> supportedSourceLineInfos,
93 Collection<Line.Info> supportedTargetLineInfos)
94 {
95 super(null, // TMixer
96 lineInfo);
97 if (TDebug.TraceMixer) { TDebug.out("TMixer.<init>(): begin"); }
98 m_mixerInfo = mixerInfo;
99 setSupportInformation(
100 supportedSourceFormats,
101 supportedTargetFormats,
102 supportedSourceLineInfos,
103 supportedTargetLineInfos);
104 m_openSourceDataLines = new ArraySet<SourceDataLine>();
105 m_openTargetDataLines = new ArraySet<TargetDataLine>();
106 if (TDebug.TraceMixer) { TDebug.out("TMixer.<init>(): end"); }
107 }
108
109
110
111 protected void setSupportInformation(
112 Collection<AudioFormat> supportedSourceFormats,
113 Collection<AudioFormat> supportedTargetFormats,
114 Collection<Line.Info> supportedSourceLineInfos,
115 Collection<Line.Info> supportedTargetLineInfos)
116 {
117 if (TDebug.TraceMixer) { TDebug.out("TMixer.setSupportInformation(): begin"); }
118 m_supportedSourceFormats = supportedSourceFormats;
119 m_supportedTargetFormats = supportedTargetFormats;
120 m_supportedSourceLineInfos = supportedSourceLineInfos;
121 m_supportedTargetLineInfos = supportedTargetLineInfos;
122 if (TDebug.TraceMixer) { TDebug.out("TMixer.setSupportInformation(): end"); }
123 }
124
125
126
127 public Mixer.Info getMixerInfo()
128 {
129 if (TDebug.TraceMixer) { TDebug.out("TMixer.getMixerInfo(): begin"); }
130 if (TDebug.TraceMixer) { TDebug.out("TMixer.getMixerInfo(): end"); }
131 return m_mixerInfo;
132 }
133
134
135
136 public Line.Info[] getSourceLineInfo()
137 {
138 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSourceLineInfo(): begin"); }
139 Line.Info[] infos = (Line.Info[]) m_supportedSourceLineInfos.toArray(EMPTY_LINE_INFO_ARRAY);
140 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSourceLineInfo(): end"); }
141 return infos;
142 }
143
144
145
146 public Line.Info[] getTargetLineInfo()
147 {
148 if (TDebug.TraceMixer) { TDebug.out("TMixer.getTargetLineInfo(): begin"); }
149 Line.Info[] infos = (Line.Info[]) m_supportedTargetLineInfos.toArray(EMPTY_LINE_INFO_ARRAY);
150 if (TDebug.TraceMixer) { TDebug.out("TMixer.getTargetLineInfo(): end"); }
151 return infos;
152 }
153
154
155
156 public Line.Info[] getSourceLineInfo(Line.Info info)
157 {
158 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSourceLineInfo(Line.Info): info to test: " + info); }
159 // TODO:
160 return EMPTY_LINE_INFO_ARRAY;
161 }
162
163
164
165 public Line.Info[] getTargetLineInfo(Line.Info info)
166 {
167 if (TDebug.TraceMixer) { TDebug.out("TMixer.getTargetLineInfo(Line.Info): info to test: " + info); }
168 // TODO:
169 return EMPTY_LINE_INFO_ARRAY;
170 }
171
172
173
174 public boolean isLineSupported(Line.Info info)
175 {
176 if (TDebug.TraceMixer) { TDebug.out("TMixer.isLineSupported(): info to test: " + info); }
177 Class lineClass = info.getLineClass();
178 if (lineClass.equals(SourceDataLine.class))
179 {
180 return isLineSupportedImpl(info, m_supportedSourceLineInfos);
181 }
182 else if (lineClass.equals(TargetDataLine.class))
183 {
184 return isLineSupportedImpl(info, m_supportedTargetLineInfos);
185 }
186 else if (lineClass.equals(Port.class))
187 {
188 return isLineSupportedImpl(info, m_supportedSourceLineInfos) || isLineSupportedImpl(info, m_supportedTargetLineInfos);
189 }
190 else
191 {
192 return false;
193 }
194 }
195
196
197
198 private static boolean isLineSupportedImpl(Line.Info info, Collection supportedLineInfos)
199 {
200 Iterator iterator = supportedLineInfos.iterator();
201 while (iterator.hasNext())
202 {
203 Line.Info info2 = (Line.Info) iterator.next();
204 if (info2.matches(info))
205 {
206 return true;
207 }
208 }
209 return false;
210 }
211
212
213
214 public Line getLine(Line.Info info)
215 throws LineUnavailableException
216 {
217 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): begin"); }
218 Class lineClass = info.getLineClass();
219 DataLine.Info dataLineInfo = null;
220 Port.Info portInfo = null;
221 AudioFormat[] aFormats = null;
222 if (info instanceof DataLine.Info)
223 {
224 dataLineInfo = (DataLine.Info) info;
225 aFormats = dataLineInfo.getFormats();
226 }
227 else if (info instanceof Port.Info)
228 {
229 portInfo = (Port.Info) info;
230 }
231 AudioFormat format = null;
232 Line line = null;
233 if (lineClass == SourceDataLine.class)
234 {
235 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): type: SourceDataLine"); }
236 if (dataLineInfo == null)
237 {
238 throw new IllegalArgumentException("need DataLine.Info for SourceDataLine");
239 }
240 format = getSupportedSourceFormat(aFormats);
241 line = getSourceDataLine(format, dataLineInfo.getMaxBufferSize());
242 }
243 else if (lineClass == Clip.class)
244 {
245 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): type: Clip"); }
246 if (dataLineInfo == null)
247 {
248 throw new IllegalArgumentException("need DataLine.Info for Clip");
249 }
250 format = getSupportedSourceFormat(aFormats);
251 line = getClip(format);
252 }
253 else if (lineClass == TargetDataLine.class)
254 {
255 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): type: TargetDataLine"); }
256 if (dataLineInfo == null)
257 {
258 throw new IllegalArgumentException("need DataLine.Info for TargetDataLine");
259 }
260 format = getSupportedTargetFormat(aFormats);
261 line = getTargetDataLine(format, dataLineInfo.getMaxBufferSize());
262 }
263 else if (lineClass == Port.class)
264 {
265 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): type: TargetDataLine"); }
266 if (portInfo == null)
267 {
268 throw new IllegalArgumentException("need Port.Info for Port");
269 }
270 line = getPort(portInfo);
271 }
272 else
273 {
274 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): unknown line type, will throw exception"); }
275 throw new LineUnavailableException("unknown line class: " + lineClass);
276 }
277 if (TDebug.TraceMixer) { TDebug.out("TMixer.getLine(): end"); }
278 return line;
279 }
280
281
282
283 protected SourceDataLine getSourceDataLine(AudioFormat format, int nBufferSize)
284 throws LineUnavailableException
285 {
286 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSourceDataLine(): begin"); }
287 throw new IllegalArgumentException("this mixer does not support SourceDataLines");
288 }
289
290
291
292 protected Clip getClip(AudioFormat format)
293 throws LineUnavailableException
294 {
295 if (TDebug.TraceMixer) { TDebug.out("TMixer.getClip(): begin"); }
296 throw new IllegalArgumentException("this mixer does not support Clips");
297 }
298
299
300
301 protected TargetDataLine getTargetDataLine(AudioFormat format, int nBufferSize)
302 throws LineUnavailableException
303 {
304 if (TDebug.TraceMixer) { TDebug.out("TMixer.getTargetDataLine(): begin"); }
305 throw new IllegalArgumentException("this mixer does not support TargetDataLines");
306 }
307
308
309
310 protected Port getPort(Port.Info info)
311 throws LineUnavailableException
312 {
313 if (TDebug.TraceMixer) { TDebug.out("TMixer.getTargetDataLine(): begin"); }
314 throw new IllegalArgumentException("this mixer does not support Ports");
315 }
316
317
318
319 private AudioFormat getSupportedSourceFormat(AudioFormat[] aFormats)
320 {
321 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedSourceFormat(): begin"); }
322 AudioFormat format = null;
323 for (int i = 0; i < aFormats.length; i++)
324 {
325 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedSourceFormat(): checking " + aFormats[i] + "..."); }
326 if (isSourceFormatSupported(aFormats[i]))
327 {
328 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedSourceFormat(): ...supported"); }
329 format = aFormats[i];
330 break;
331 }
332 else
333 {
334 if (TDebug.TraceMixer)
335 {
336 TDebug.out("TMixer.getSupportedSourceFormat(): ...no luck");
337 }
338 }
339 }
340 if (format == null)
341 {
342 throw new IllegalArgumentException("no line matchine one of the passed formats");
343 }
344 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedSourceFormat(): end"); }
345 return format;
346 }
347
348
349
350 private AudioFormat getSupportedTargetFormat(AudioFormat[] aFormats)
351 {
352 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedTargetFormat(): begin"); }
353 AudioFormat format = null;
354 for (int i = 0; i < aFormats.length; i++)
355 {
356 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedTargetFormat(): checking " + aFormats[i] + " ..."); }
357 if (isTargetFormatSupported(aFormats[i]))
358 {
359 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedTargetFormat(): ...supported"); }
360 format = aFormats[i];
361 break;
362 }
363 else
364 {
365 if (TDebug.TraceMixer)
366 {
367 TDebug.out("TMixer.getSupportedTargetFormat(): ...no luck");
368 }
369 }
370 }
371 if (format == null)
372 {
373 throw new IllegalArgumentException("no line matchine one of the passed formats");
374 }
375 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSupportedTargetFormat(): end"); }
376 return format;
377 }
378
379
380
381/*
382 not implemented here:
383 getMaxLines(Line.Info)
384*/
385
386
387
388 public Line[] getSourceLines()
389 {
390 if (TDebug.TraceMixer) { TDebug.out("TMixer.getSourceLines(): called"); }
391 return (Line[]) m_openSourceDataLines.toArray(EMPTY_LINE_ARRAY);
392 }
393
394
395
396 public Line[] getTargetLines()
397 {
398 if (TDebug.TraceMixer) { TDebug.out("TMixer.getTargetLines(): called"); }
399 return (Line[]) m_openTargetDataLines.toArray(EMPTY_LINE_ARRAY);
400 }
401
402
403
404 public void synchronize(Line[] aLines,
405 boolean bMaintainSync)
406 {
407 throw new IllegalArgumentException("synchronization not supported");
408 }
409
410
411
412 public void unsynchronize(Line[] aLines)
413 {
414 throw new IllegalArgumentException("synchronization not supported");
415 }
416
417
418
419 public boolean isSynchronizationSupported(Line[] aLines,
420 boolean bMaintainSync)
421 {
422 return false;
423 }
424
425
426
427 protected boolean isSourceFormatSupported(AudioFormat format)
428 {
429 if (TDebug.TraceMixer) { TDebug.out("TMixer.isSourceFormatSupported(): format to test: " + format); }
430 Iterator<AudioFormat> iterator = m_supportedSourceFormats.iterator();
431 while (iterator.hasNext())
432 {
433 AudioFormat supportedFormat = iterator.next();
434 if (AudioFormats.matches(supportedFormat, format))
435 {
436 return true;
437 }
438 }
439 return false;
440 }
441
442
443
444 protected boolean isTargetFormatSupported(AudioFormat format)
445 {
446 if (TDebug.TraceMixer) { TDebug.out("TMixer.isTargetFormatSupported(): format to test: " + format); }
447 Iterator<AudioFormat> iterator = m_supportedTargetFormats.iterator();
448 while (iterator.hasNext())
449 {
450 AudioFormat supportedFormat = iterator.next();
451 if (AudioFormats.matches(supportedFormat, format))
452 {
453 return true;
454 }
455 }
456 return false;
457 }
458
459
460
461 /*package*/ void registerOpenLine(Line line)
462 {
463 if (TDebug.TraceMixer) { TDebug.out("TMixer.registerOpenLine(): line to register: " + line);
464 }
465 if (line instanceof SourceDataLine)
466 {
467 synchronized (m_openSourceDataLines)
468 {
469 m_openSourceDataLines.add((SourceDataLine) line);
470 }
471 }
472 else if (line instanceof TargetDataLine)
473 {
474 synchronized (m_openSourceDataLines)
475 {
476 m_openTargetDataLines.add((TargetDataLine) line);
477 }
478 }
479 }
480
481
482
483 /*package*/ void unregisterOpenLine(Line line)
484 {
485 if (TDebug.TraceMixer) { TDebug.out("TMixer.unregisterOpenLine(): line to unregister: " + line); }
486 if (line instanceof SourceDataLine)
487 {
488 synchronized (m_openSourceDataLines)
489 {
490 m_openSourceDataLines.remove((SourceDataLine) line);
491 }
492 }
493 else if (line instanceof TargetDataLine)
494 {
495 synchronized (m_openTargetDataLines)
496 {
497 m_openTargetDataLines.remove((TargetDataLine) line);
498 }
499 }
500 }
501}
502
503
504
505/*** TMixer.java ***/
506
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TMixerInfo.java b/songdbj/org/tritonus/share/sampled/mixer/TMixerInfo.java
deleted file mode 100644
index cb4b7cc860..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TMixerInfo.java
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * TMixerInfo.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 1999, 2000 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
31package org.tritonus.share.sampled.mixer;
32
33import javax.sound.sampled.Mixer;
34
35import org.tritonus.share.TDebug;
36
37
38
39
40/*
41 * This is needed only because Mixer.Info's constructor
42 * is protected (in the Sun jdk1.3).
43 */
44public class TMixerInfo
45extends Mixer.Info
46{
47 public TMixerInfo(String a, String b, String c, String d)
48 {
49 super(a, b, c, d);
50 }
51}
52
53
54
55/*** TMixerInfo.java ***/
56
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TMixerProvider.java b/songdbj/org/tritonus/share/sampled/mixer/TMixerProvider.java
deleted file mode 100644
index 3116d74dc3..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TMixerProvider.java
+++ /dev/null
@@ -1,240 +0,0 @@
1/*
2 * TMixerProvider.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 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/*
26|<--- this code is formatted to fit into 80 columns --->|
27*/
28
29package org.tritonus.share.sampled.mixer;
30
31import java.util.ArrayList;
32import java.util.HashMap;
33import java.util.HashSet;
34import java.util.Iterator;
35import java.util.List;
36import java.util.Map;
37import java.util.Set;
38
39import javax.sound.sampled.Mixer;
40import javax.sound.sampled.spi.MixerProvider;
41
42import org.tritonus.share.TDebug;
43
44
45
46public abstract class TMixerProvider
47extends MixerProvider
48{
49 private static final Mixer.Info[] EMPTY_MIXER_INFO_ARRAY = new Mixer.Info[0];
50
51 private static Map<Class, MixerProviderStruct> sm_mixerProviderStructs = new HashMap<Class, MixerProviderStruct>();
52
53 private boolean m_bDisabled = false;
54
55
56
57
58 public TMixerProvider()
59 {
60 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.<init>(): begin"); }
61 // currently does nothing
62 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.<init>(): end"); }
63 }
64
65
66
67 /*
68 Override this method if you want a thread-safe static initializaiton.
69 */
70 protected void staticInit()
71 {
72 }
73
74
75
76 private MixerProviderStruct getMixerProviderStruct()
77 {
78 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixerProviderStruct(): begin"); }
79 Class cls = this.getClass();
80 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixerProviderStruct(): called from " + cls); }
81 // Thread.dumpStack();
82 synchronized (TMixerProvider.class)
83 {
84 MixerProviderStruct struct = sm_mixerProviderStructs.get(cls);
85 if (struct == null)
86 {
87 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixerProviderStruct(): creating new MixerProviderStruct for " + cls); }
88 struct = new MixerProviderStruct();
89 sm_mixerProviderStructs.put(cls, struct);
90 }
91 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixerProviderStruct(): end"); }
92 return struct;
93 }
94 }
95
96
97
98 protected void disable()
99 {
100 if (TDebug.TraceMixerProvider) { TDebug.out("disabling " + getClass().getName()); }
101 m_bDisabled = true;
102 }
103
104
105 protected boolean isDisabled()
106 {
107 return m_bDisabled;
108 }
109
110
111
112 protected void addMixer(Mixer mixer)
113 {
114 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.addMixer(): begin"); }
115 MixerProviderStruct struct = getMixerProviderStruct();
116 synchronized (struct)
117 {
118 struct.m_mixers.add(mixer);
119 if (struct.m_defaultMixer == null)
120 {
121 struct.m_defaultMixer = mixer;
122 }
123 }
124 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.addMixer(): end"); }
125 }
126
127
128
129 protected void removeMixer(Mixer mixer)
130 {
131 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.removeMixer(): begin"); }
132 MixerProviderStruct struct = getMixerProviderStruct();
133 synchronized (struct)
134 {
135 struct.m_mixers.remove(mixer);
136 // TODO: should search for another mixer
137 if (struct.m_defaultMixer == mixer)
138 {
139 struct.m_defaultMixer = null;
140 }
141 }
142 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.removeMixer(): end"); }
143 }
144
145
146 // $$mp 2003/01/11: TODO: this implementation may become obsolete once the overridden method in spi.MixerProvider is implemented in a way documented officially.
147 public boolean isMixerSupported(Mixer.Info info)
148 {
149 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.isMixerSupported(): begin"); }
150 boolean bIsSupported = false;
151 Mixer.Info[] infos = getMixerInfo();
152 for (int i = 0; i < infos.length; i++)
153 {
154 if (infos[i].equals(info))
155 {
156 bIsSupported = true;
157 break;
158 }
159 }
160 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.isMixerSupported(): end"); }
161 return bIsSupported;
162 }
163
164
165
166 /**
167 */
168 public Mixer getMixer(Mixer.Info info)
169 {
170 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixer(): begin"); }
171 MixerProviderStruct struct = getMixerProviderStruct();
172 Mixer mixerResult = null;
173 synchronized (struct)
174 {
175 if (info == null)
176 {
177 mixerResult = struct.m_defaultMixer;
178 }
179 else
180 {
181 Iterator mixers = struct.m_mixers.iterator();
182 while (mixers.hasNext())
183 {
184 Mixer mixer = (Mixer) mixers.next();
185 if (mixer.getMixerInfo().equals(info))
186 {
187 mixerResult = mixer;
188 break;
189 }
190 }
191 }
192 }
193 if (mixerResult == null)
194 {
195 throw new IllegalArgumentException("no mixer available for " + info);
196 }
197 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixer(): end"); }
198 return mixerResult;
199 }
200
201
202
203 public Mixer.Info[] getMixerInfo()
204 {
205 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixerInfo(): begin"); }
206 Set<Mixer.Info> mixerInfos = new HashSet<Mixer.Info>();
207 MixerProviderStruct struct = getMixerProviderStruct();
208 synchronized (struct)
209 {
210 Iterator<Mixer> mixers = struct.m_mixers.iterator();
211 while (mixers.hasNext())
212 {
213 Mixer mixer = mixers.next();
214 mixerInfos.add(mixer.getMixerInfo());
215 }
216 }
217 if (TDebug.TraceMixerProvider) { TDebug.out("TMixerProvider.getMixerInfo(): end"); }
218 return mixerInfos.toArray(EMPTY_MIXER_INFO_ARRAY);
219 }
220
221
222
223 private class MixerProviderStruct
224 {
225 public List<Mixer> m_mixers;
226 public Mixer m_defaultMixer;
227
228
229
230 public MixerProviderStruct()
231 {
232 m_mixers = new ArrayList<Mixer>();
233 m_defaultMixer = null;
234 }
235 }
236}
237
238
239
240/*** TMixerProvider.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TPort.java b/songdbj/org/tritonus/share/sampled/mixer/TPort.java
deleted file mode 100644
index 18d5abae00..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TPort.java
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * TPort.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
31package org.tritonus.share.sampled.mixer;
32
33import java.util.Collection;
34import java.util.ArrayList;
35import java.util.HashSet;
36import java.util.Iterator;
37import java.util.List;
38import java.util.Set;
39
40import javax.sound.sampled.AudioSystem;
41import javax.sound.sampled.Control;
42import javax.sound.sampled.Line;
43import javax.sound.sampled.LineEvent;
44import javax.sound.sampled.LineListener;
45import javax.sound.sampled.LineUnavailableException;
46import javax.sound.sampled.Port;
47
48import org.tritonus.share.TDebug;
49
50
51
52
53/** Base class for Ports.
54 */
55public class TPort
56extends TLine
57implements Port
58{
59 public TPort(TMixer mixer,
60 Line.Info info)
61 {
62 super(mixer, info);
63 }
64
65
66
67 public TPort(TMixer mixer,
68 Line.Info info,
69 Collection<Control> controls)
70 {
71 super(mixer, info, controls);
72 }
73}
74
75
76
77/*** TPort.java ***/
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TSoftClip.java b/songdbj/org/tritonus/share/sampled/mixer/TSoftClip.java
deleted file mode 100644
index b5a8aea2c1..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TSoftClip.java
+++ /dev/null
@@ -1,318 +0,0 @@
1/*
2 * TSoftClip.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 1999 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
31package org.tritonus.share.sampled.mixer;
32
33import java.io.IOException;
34import java.io.ByteArrayInputStream;
35import java.io.ByteArrayOutputStream;
36
37import javax.sound.sampled.AudioFormat;
38import javax.sound.sampled.AudioSystem;
39import javax.sound.sampled.Clip;
40import javax.sound.sampled.DataLine;
41import javax.sound.sampled.SourceDataLine;
42import javax.sound.sampled.AudioInputStream;
43import javax.sound.sampled.LineUnavailableException;
44import javax.sound.sampled.Mixer;
45
46import org.tritonus.share.TDebug;
47import org.tritonus.share.sampled.mixer.TDataLine;
48
49
50
51public class TSoftClip
52extends TClip
53implements Runnable
54{
55 private static final Class[] CONTROL_CLASSES = {/*GainControl.class*/};
56 private static final int BUFFER_SIZE = 16384;
57
58
59 private Mixer m_mixer;
60 private SourceDataLine m_line;
61 private byte[] m_abClip;
62 private int m_nRepeatCount;
63 private Thread m_thread;
64
65 public TSoftClip(Mixer mixer, AudioFormat format)
66 throws LineUnavailableException
67 {
68 // TODO: info object
69/*
70 DataLine.Info info = new DataLine.Info(Clip.class,
71 audioFormat, -1);
72*/
73 super(null);
74 m_mixer = mixer;
75 DataLine.Info info = new DataLine.Info(
76 SourceDataLine.class,
77 // TODO: should pass a real AudioFormat object that isn't too restrictive
78 format);
79 m_line = (SourceDataLine) AudioSystem.getLine(info);
80 }
81
82
83
84 public void open(AudioInputStream audioInputStream)
85 throws LineUnavailableException, IOException
86 {
87 AudioFormat audioFormat = audioInputStream.getFormat();
88 setFormat(audioFormat);
89 int nFrameSize = audioFormat.getFrameSize();
90 if (nFrameSize < 1)
91 {
92 throw new IllegalArgumentException("frame size must be positive");
93 }
94 if (TDebug.TraceClip)
95 {
96 TDebug.out("TSoftClip.open(): format: " + audioFormat);
97 // TDebug.out("sample rate: " + audioFormat.getSampleRate());
98 }
99 byte[] abData = new byte[BUFFER_SIZE];
100 ByteArrayOutputStream baos = new ByteArrayOutputStream();
101 int nBytesRead = 0;
102 while (nBytesRead != -1)
103 {
104 try
105 {
106 nBytesRead = audioInputStream.read(abData, 0, abData.length);
107 }
108 catch (IOException e)
109 {
110 if (TDebug.TraceClip || TDebug.TraceAllExceptions)
111 {
112 TDebug.out(e);
113 }
114 }
115 if (nBytesRead >= 0)
116 {
117 if (TDebug.TraceClip)
118 {
119 TDebug.out("TSoftClip.open(): Trying to write: " + nBytesRead);
120 }
121 baos.write(abData, 0, nBytesRead);
122 if (TDebug.TraceClip)
123 {
124 TDebug.out("TSoftClip.open(): Written: " + nBytesRead);
125 }
126 }
127 }
128 m_abClip = baos.toByteArray();
129 setBufferSize(m_abClip.length);
130 // open the line
131 m_line.open(getFormat());
132 // to trigger the events
133 // open();
134 }
135
136
137
138 public int getFrameLength()
139 {
140 if (isOpen())
141 {
142 return getBufferSize() / getFormat().getFrameSize();
143 }
144 else
145 {
146 return AudioSystem.NOT_SPECIFIED;
147 }
148 }
149
150
151
152 public long getMicrosecondLength()
153 {
154 if (isOpen())
155 {
156 return (long) (getFrameLength() * getFormat().getFrameRate() * 1000000);
157 }
158 else
159 {
160 return AudioSystem.NOT_SPECIFIED;
161 }
162 }
163
164
165
166 public void setFramePosition(int nPosition)
167 {
168 // TOOD:
169 }
170
171
172
173 public void setMicrosecondPosition(long lPosition)
174 {
175 // TOOD:
176 }
177
178
179
180 public int getFramePosition()
181 {
182 // TOOD:
183 return -1;
184 }
185
186
187
188 public long getMicrosecondPosition()
189 {
190 // TOOD:
191 return -1;
192 }
193
194
195
196 public void setLoopPoints(int nStart, int nEnd)
197 {
198 // TOOD:
199 }
200
201
202
203 public void loop(int nCount)
204 {
205 if (TDebug.TraceClip)
206 {
207 TDebug.out("TSoftClip.loop(int): called; count = " + nCount);
208 }
209 if (false/*isStarted()*/)
210 {
211 /*
212 * only allow zero count to stop the looping
213 * at the end of an iteration.
214 */
215 if (nCount == 0)
216 {
217 if (TDebug.TraceClip)
218 {
219 TDebug.out("TSoftClip.loop(int): stopping sample");
220 }
221 // m_esdSample.stop();
222 }
223 }
224 else
225 {
226 m_nRepeatCount = nCount;
227 m_thread = new Thread(this);
228 m_thread.start();
229 }
230 // TOOD:
231 }
232
233
234
235 public void flush()
236 {
237 // TOOD:
238 }
239
240
241
242 public void drain()
243 {
244 // TOOD:
245 }
246
247
248
249 public void close()
250 {
251 // m_esdSample.free();
252 // m_esdSample.close();
253 // TOOD:
254 }
255
256
257
258
259 public void open()
260 {
261 // TODO:
262 }
263
264
265
266 public void start()
267 {
268 if (TDebug.TraceClip)
269 {
270 TDebug.out("TSoftClip.start(): called");
271 }
272 /*
273 * This is a hack. What start() really should do is
274 * start playing at the position playback was stopped.
275 */
276 if (TDebug.TraceClip)
277 {
278 TDebug.out("TSoftClip.start(): calling 'loop(0)' [hack]");
279 }
280 loop(0);
281 }
282
283
284
285 public void stop()
286 {
287 // TODO:
288 // m_esdSample.kill();
289 }
290
291
292
293 /*
294 * This method is enforced by DataLine, but doesn't make any
295 * sense for Clips.
296 */
297 public int available()
298 {
299 return -1;
300 }
301
302
303
304 public void run()
305 {
306 while (m_nRepeatCount >= 0)
307 {
308 m_line.write(m_abClip, 0, m_abClip.length);
309 m_nRepeatCount--;
310 }
311 }
312
313}
314
315
316
317/*** TSoftClip.java ***/
318
diff --git a/songdbj/org/tritonus/share/sampled/mixer/package.html b/songdbj/org/tritonus/share/sampled/mixer/package.html
deleted file mode 100644
index 681024bc9d..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/package.html
+++ /dev/null
@@ -1,14 +0,0 @@
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3 <head>
4 </head>
5
6 <body>
7 <p>Base classes for the implementation of MixerProviders.
8 The classes provided here .</p>
9
10 @see javax.sound.sampled.spi.MixerProvider
11 @see org.tritonus.sampled.mixer.alsa
12 @see org.tritonus.sampled.mixer.esd
13 </body>
14</html>