95 /**
96 * Get the source URL used to create this <code>AudioClip</code>.
97 * @return source URL as provided to the constructor
98 */
99 public String getSource() {
100 return sourceURL;
101 }
102
103 /**
104 * The relative volume level at which the clip is played. Valid range is 0.0
105 * (muted) to 1.0 (full volume). Values are clamped to this range internally
106 * so values outside this range will have no additional effect. Volume is
107 * controlled by attenuation, so values below 1.0 will reduce the sound
108 * level accordingly.
109 */
110 private DoubleProperty volume;
111
112 /**
113 * Set the default volume level. The new setting will only take effect on
114 * subsequent plays.
115 * @see #volume
116 * @param value new default volume level for this clip
117 */
118 public final void setVolume(double value) {
119 volumeProperty().set(value);
120 }
121
122 /**
123 * Get the default volume level.
124 * @see #volume
125 * @return the default volume level for this clip
126 */
127 public final double getVolume() {
128 return (null == volume) ? 1.0 : volume.get();
129 }
130 public DoubleProperty volumeProperty() {
131 if (volume == null) {
132 volume = new DoublePropertyBase(1.0) {
133 @Override
134 protected void invalidated() {
135 if (null != audioClip) {
136 audioClip.setVolume(volume.get());
137 }
138 }
139
140 @Override
141 public Object getBean() {
142 return AudioClip.this;
143 }
144
146 public String getName() {
147 return "volume";
148 }
149 };
150 }
151 return volume;
152 }
153
154 /**
155 * The relative left and right volume levels of the clip.
156 * Valid range is -1.0 to 1.0 where -1.0 gives full volume to the left
157 * channel while muting the right channel, 0.0 gives full volume to both
158 * channels and 1.0 gives full volume to right channel and mutes the left
159 * channel. Values outside this range are clamped internally.
160 */
161 private DoubleProperty balance;
162
163 /**
164 * Set the default balance level. The new value will only affect subsequent
165 * plays.
166 * @see #balance
167 * @param balance new default balance
168 */
169 public void setBalance(double balance) {
170 balanceProperty().set(balance);
171 }
172
173 /**
174 * Get the default balance level for this clip.
175 * @see #balance
176 * @return the default balance for this clip
177 */
178 public double getBalance() {
179 return (null != balance) ? balance.get() : 0.0;
180 }
181 public DoubleProperty balanceProperty() {
182 if (null == balance) {
183 balance = new DoublePropertyBase(0.0) {
184 @Override
185 protected void invalidated() {
186 if (null != audioClip) {
187 audioClip.setBalance(balance.get());
188 }
189 }
190
191 @Override
192 public Object getBean() {
193 return AudioClip.this;
194 }
195
196 @Override
197 public String getName() {
198 return "balance";
199 }
200 };
201 }
202 return balance;
203 }
204
205 /**
206 * The relative rate at which the clip is played. Valid range is 0.125
207 * (1/8 speed) to 8.0 (8x speed); values outside this range are clamped
208 * internally. Normal playback for a clip is 1.0; any other rate will affect
209 * pitch and duration accordingly.
210 */
211 private DoubleProperty rate;
212
213 /**
214 * Set the default playback rate. The new value will only affect subsequent
215 * plays.
216 * @see #rate
217 * @param rate the new default playback rate
218 */
219 public void setRate(double rate) {
220 rateProperty().set(rate);
221 }
222
223 /**
224 * Get the default playback rate.
225 * @see #rate
226 * @return default playback rate for this clip
227 */
228 public double getRate() {
229 return (null != rate) ? rate.get() : 1.0;
230 }
231 public DoubleProperty rateProperty() {
232 if (null == rate) {
233 rate = new DoublePropertyBase(1.0) {
234 @Override
235 protected void invalidated() {
236 if (null != audioClip) {
237 audioClip.setPlaybackRate(rate.get());
238 }
239 }
240
241 @Override
242 public Object getBean() {
243 return AudioClip.this;
244 }
245
249 }
250 };
251 }
252 return rate;
253 }
254
255 /**
256 * The relative "center" of the clip. A pan value of 0.0 plays
257 * the clip normally where a -1.0 pan shifts the clip entirely to the left
258 * channel and 1.0 shifts entirely to the right channel. Unlike balance this
259 * setting mixes both channels so neither channel loses data. Setting
260 * pan on a mono clip has the same effect as setting balance, but with a
261 * much higher cost in CPU overhead so this is not recommended for mono
262 * clips.
263 */
264 private DoubleProperty pan;
265
266 /**
267 * Set the default pan value. The new value will only affect subsequent
268 * plays.
269 * @see #pan
270 * @param pan the new default pan value
271 */
272 public void setPan(double pan) {
273 panProperty().set(pan);
274 }
275
276 /**
277 * Get the default pan value.
278 * @see #pan
279 * @return the default pan value for this clip
280 */
281 public double getPan() {
282 return (null != pan) ? pan.get() : 0.0;
283 }
284 public DoubleProperty panProperty() {
285 if (null == pan) {
286 pan = new DoublePropertyBase(0.0) {
287 @Override
288 protected void invalidated() {
289 if (null != audioClip) {
290 audioClip.setPan(pan.get());
291 }
292 }
293
294 @Override
295 public Object getBean() {
296 return AudioClip.this;
297 }
298
302 }
303 };
304 }
305 return pan;
306 }
307
308 /**
309 * The relative priority of the clip with respect to other clips. This value
310 * is used to determine which clips to remove when the maximum allowed number
311 * of clips is exceeded. The lower the priority, the more likely the
312 * clip is to be stopped and removed from the mixer channel it is occupying.
313 * Valid range is any integer; there are no constraints. The default priority
314 * is zero for all clips until changed. The number of simultaneous sounds
315 * that can be played is implementation- and possibly system-dependent.
316 */
317 private IntegerProperty priority;
318
319 /**
320 * Set the default playback priority. The new value will only affect
321 * subsequent plays.
322 * @see #priority
323 * @param priority the new default playback priority
324 */
325 public void setPriority(int priority) {
326 priorityProperty().set(priority);
327 }
328
329 /**
330 * Get the default playback priority.
331 * @see #priority
332 * @return the default playback priority of this clip
333 */
334 public int getPriority() {
335 return (null != priority) ? priority.get() : 0;
336 }
337 public IntegerProperty priorityProperty() {
338 if (null == priority) {
339 priority = new IntegerPropertyBase(0) {
340 @Override
341 protected void invalidated() {
342 if (null != audioClip) {
343 audioClip.setPriority(priority.get());
344 }
345 }
346
347 @Override
348 public Object getBean() {
349 return AudioClip.this;
350 }
351
362 * When {@link #cycleCountProperty cycleCount} is set to this value, the
363 * <code>AudioClip</code> will loop continuously until stopped. This value is
364 * synonymous with {@link MediaPlayer#INDEFINITE} and
365 * {@link javafx.animation.Animation#INDEFINITE}, these values may be used
366 * interchangeably.
367 */
368 public static final int INDEFINITE = -1;
369
370 /**
371 * The number of times the clip will be played when {@link #play()}
372 * is called. A cycleCount of 1 plays exactly once, a cycleCount of 2
373 * plays twice and so on. Valid range is 1 or more, but setting this to
374 * {@link #INDEFINITE INDEFINITE} will cause the clip to continue looping
375 * until {@link #stop} is called.
376 */
377 private IntegerProperty cycleCount;
378
379 /**
380 * Set the default cycle count. The new value will only affect subsequent
381 * plays.
382 * @see #cycleCount
383 * @param count the new default cycle count for this clip
384 */
385 public void setCycleCount(int count) {
386 cycleCountProperty().set(count);
387 }
388
389 /**
390 * Get the default cycle count.
391 * @see #cycleCount
392 * @return the default cycleCount for this audio clip
393 */
394 public int getCycleCount() {
395 return (null != cycleCount) ? cycleCount.get() : 1;
396 }
397 public IntegerProperty cycleCountProperty() {
398 if (null == cycleCount) {
399 cycleCount = new IntegerPropertyBase(1) {
400 @Override
401 protected void invalidated() {
402 if (null != audioClip) {
403 int value = cycleCount.get();
404 if (INDEFINITE != value) {
405 value = Math.max(1, value);
406 audioClip.setLoopCount(value - 1);
407 } else {
408 audioClip.setLoopCount(value); // INDEFINITE is the same there
409 }
410 }
411 }
|
95 /**
96 * Get the source URL used to create this <code>AudioClip</code>.
97 * @return source URL as provided to the constructor
98 */
99 public String getSource() {
100 return sourceURL;
101 }
102
103 /**
104 * The relative volume level at which the clip is played. Valid range is 0.0
105 * (muted) to 1.0 (full volume). Values are clamped to this range internally
106 * so values outside this range will have no additional effect. Volume is
107 * controlled by attenuation, so values below 1.0 will reduce the sound
108 * level accordingly.
109 */
110 private DoubleProperty volume;
111
112 /**
113 * Set the default volume level. The new setting will only take effect on
114 * subsequent plays.
115 * @see #volumeProperty()
116 * @param value new default volume level for this clip
117 */
118 public final void setVolume(double value) {
119 volumeProperty().set(value);
120 }
121
122 /**
123 * Get the default volume level.
124 * @see #volumeProperty()
125 * @return the default volume level for this clip
126 */
127 public final double getVolume() {
128 return (null == volume) ? 1.0 : volume.get();
129 }
130 public DoubleProperty volumeProperty() {
131 if (volume == null) {
132 volume = new DoublePropertyBase(1.0) {
133 @Override
134 protected void invalidated() {
135 if (null != audioClip) {
136 audioClip.setVolume(volume.get());
137 }
138 }
139
140 @Override
141 public Object getBean() {
142 return AudioClip.this;
143 }
144
146 public String getName() {
147 return "volume";
148 }
149 };
150 }
151 return volume;
152 }
153
154 /**
155 * The relative left and right volume levels of the clip.
156 * Valid range is -1.0 to 1.0 where -1.0 gives full volume to the left
157 * channel while muting the right channel, 0.0 gives full volume to both
158 * channels and 1.0 gives full volume to right channel and mutes the left
159 * channel. Values outside this range are clamped internally.
160 */
161 private DoubleProperty balance;
162
163 /**
164 * Set the default balance level. The new value will only affect subsequent
165 * plays.
166 * @see #balanceProperty()
167 * @param balance new default balance
168 */
169 public void setBalance(double balance) {
170 balanceProperty().set(balance);
171 }
172
173 /**
174 * Get the default balance level for this clip.
175 * @see #balanceProperty()
176 * @return the default balance for this clip
177 */
178 public double getBalance() {
179 return (null != balance) ? balance.get() : 0.0;
180 }
181 public DoubleProperty balanceProperty() {
182 if (null == balance) {
183 balance = new DoublePropertyBase(0.0) {
184 @Override
185 protected void invalidated() {
186 if (null != audioClip) {
187 audioClip.setBalance(balance.get());
188 }
189 }
190
191 @Override
192 public Object getBean() {
193 return AudioClip.this;
194 }
195
196 @Override
197 public String getName() {
198 return "balance";
199 }
200 };
201 }
202 return balance;
203 }
204
205 /**
206 * The relative rate at which the clip is played. Valid range is 0.125
207 * (1/8 speed) to 8.0 (8x speed); values outside this range are clamped
208 * internally. Normal playback for a clip is 1.0; any other rate will affect
209 * pitch and duration accordingly.
210 */
211 private DoubleProperty rate;
212
213 /**
214 * Set the default playback rate. The new value will only affect subsequent
215 * plays.
216 * @see #rateProperty()
217 * @param rate the new default playback rate
218 */
219 public void setRate(double rate) {
220 rateProperty().set(rate);
221 }
222
223 /**
224 * Get the default playback rate.
225 * @see #rateProperty()
226 * @return default playback rate for this clip
227 */
228 public double getRate() {
229 return (null != rate) ? rate.get() : 1.0;
230 }
231 public DoubleProperty rateProperty() {
232 if (null == rate) {
233 rate = new DoublePropertyBase(1.0) {
234 @Override
235 protected void invalidated() {
236 if (null != audioClip) {
237 audioClip.setPlaybackRate(rate.get());
238 }
239 }
240
241 @Override
242 public Object getBean() {
243 return AudioClip.this;
244 }
245
249 }
250 };
251 }
252 return rate;
253 }
254
255 /**
256 * The relative "center" of the clip. A pan value of 0.0 plays
257 * the clip normally where a -1.0 pan shifts the clip entirely to the left
258 * channel and 1.0 shifts entirely to the right channel. Unlike balance this
259 * setting mixes both channels so neither channel loses data. Setting
260 * pan on a mono clip has the same effect as setting balance, but with a
261 * much higher cost in CPU overhead so this is not recommended for mono
262 * clips.
263 */
264 private DoubleProperty pan;
265
266 /**
267 * Set the default pan value. The new value will only affect subsequent
268 * plays.
269 * @see #panProperty()
270 * @param pan the new default pan value
271 */
272 public void setPan(double pan) {
273 panProperty().set(pan);
274 }
275
276 /**
277 * Get the default pan value.
278 * @see #panProperty()
279 * @return the default pan value for this clip
280 */
281 public double getPan() {
282 return (null != pan) ? pan.get() : 0.0;
283 }
284 public DoubleProperty panProperty() {
285 if (null == pan) {
286 pan = new DoublePropertyBase(0.0) {
287 @Override
288 protected void invalidated() {
289 if (null != audioClip) {
290 audioClip.setPan(pan.get());
291 }
292 }
293
294 @Override
295 public Object getBean() {
296 return AudioClip.this;
297 }
298
302 }
303 };
304 }
305 return pan;
306 }
307
308 /**
309 * The relative priority of the clip with respect to other clips. This value
310 * is used to determine which clips to remove when the maximum allowed number
311 * of clips is exceeded. The lower the priority, the more likely the
312 * clip is to be stopped and removed from the mixer channel it is occupying.
313 * Valid range is any integer; there are no constraints. The default priority
314 * is zero for all clips until changed. The number of simultaneous sounds
315 * that can be played is implementation- and possibly system-dependent.
316 */
317 private IntegerProperty priority;
318
319 /**
320 * Set the default playback priority. The new value will only affect
321 * subsequent plays.
322 * @see #priorityProperty()
323 * @param priority the new default playback priority
324 */
325 public void setPriority(int priority) {
326 priorityProperty().set(priority);
327 }
328
329 /**
330 * Get the default playback priority.
331 * @see #priorityProperty()
332 * @return the default playback priority of this clip
333 */
334 public int getPriority() {
335 return (null != priority) ? priority.get() : 0;
336 }
337 public IntegerProperty priorityProperty() {
338 if (null == priority) {
339 priority = new IntegerPropertyBase(0) {
340 @Override
341 protected void invalidated() {
342 if (null != audioClip) {
343 audioClip.setPriority(priority.get());
344 }
345 }
346
347 @Override
348 public Object getBean() {
349 return AudioClip.this;
350 }
351
362 * When {@link #cycleCountProperty cycleCount} is set to this value, the
363 * <code>AudioClip</code> will loop continuously until stopped. This value is
364 * synonymous with {@link MediaPlayer#INDEFINITE} and
365 * {@link javafx.animation.Animation#INDEFINITE}, these values may be used
366 * interchangeably.
367 */
368 public static final int INDEFINITE = -1;
369
370 /**
371 * The number of times the clip will be played when {@link #play()}
372 * is called. A cycleCount of 1 plays exactly once, a cycleCount of 2
373 * plays twice and so on. Valid range is 1 or more, but setting this to
374 * {@link #INDEFINITE INDEFINITE} will cause the clip to continue looping
375 * until {@link #stop} is called.
376 */
377 private IntegerProperty cycleCount;
378
379 /**
380 * Set the default cycle count. The new value will only affect subsequent
381 * plays.
382 * @see #cycleCountProperty()
383 * @param count the new default cycle count for this clip
384 */
385 public void setCycleCount(int count) {
386 cycleCountProperty().set(count);
387 }
388
389 /**
390 * Get the default cycle count.
391 * @see #cycleCountProperty()
392 * @return the default cycleCount for this audio clip
393 */
394 public int getCycleCount() {
395 return (null != cycleCount) ? cycleCount.get() : 1;
396 }
397 public IntegerProperty cycleCountProperty() {
398 if (null == cycleCount) {
399 cycleCount = new IntegerPropertyBase(1) {
400 @Override
401 protected void invalidated() {
402 if (null != audioClip) {
403 int value = cycleCount.get();
404 if (INDEFINITE != value) {
405 value = Math.max(1, value);
406 audioClip.setLoopCount(value - 1);
407 } else {
408 audioClip.setLoopCount(value); // INDEFINITE is the same there
409 }
410 }
411 }
|