ptolemy.actor.lib.javasound
Class ClipPlayer
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.javasound.ClipPlayer
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.sound.sampled.LineListener, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
public class ClipPlayer
- extends TypedAtomicActor
- implements javax.sound.sampled.LineListener
An actor that plays an audio clip given in a file. If the overlay
parameter is false (the default), then it will terminate any previously
playing clip before playing the new instance. Otherwise, it will mix
in the new instance with the currently playing clip.
- Since:
- Ptolemy II 6.1
- Version:
- $Id: ClipPlayer.java,v 1.6.4.2 2008/03/25 22:32:53 cxh Exp $
- Author:
- Edward A. Lee
- See Also:
LiveSound,
AudioCapture,
AudioReader,
AudioWriter,
Serialized Form
- Accepted Rating:
- Proposed Rating:
|
Field Summary |
protected java.util.List<javax.sound.sampled.Clip> |
_clips
The clip to playback. |
FileParameter |
fileOrURL
The file or URL giving the audio clip. |
TypedIOPort |
output
Output port used to indicate starts and stops. |
Parameter |
overlay
If true, then if the actor fires before the previous clip
has finished playing, then a new instance of the clip will
be played on top of the tail of the previous instance, as
long as the underlying mixer supports adding additional clips. |
TypedIOPort |
trigger
The trigger. |
| Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
|
Constructor Summary |
ClipPlayer(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
|
Method Summary |
void |
fire()
Produce outputs indicating that the clip has started or stopped. |
boolean |
postfire()
Read an input array and send to the audio hardware. |
void |
update(javax.sound.sampled.LineEvent event)
Called to notify this object of changes in the status of
a clip. |
void |
wrapup()
Stop audio playback and free up any audio resources used
for audio playback. |
| Methods inherited from class ptolemy.actor.AtomicActor |
_actorFiring, _actorFiring, _createReceivers, addActorFiringListener, addInitializable, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate |
| Methods inherited from class ptolemy.kernel.ComponentEntity |
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName |
| Methods inherited from class ptolemy.kernel.Entity |
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName |
| Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
fileOrURL
public FileParameter fileOrURL
- The file or URL giving the audio clip.
This is set by default to a file containing a voice signal.
output
public TypedIOPort output
- Output port used to indicate starts and stops.
This is a boolean port. A true output indicates that
a clip has been started, and a false output indicates that
one has stopped.
overlay
public Parameter overlay
- If true, then if the actor fires before the previous clip
has finished playing, then a new instance of the clip will
be played on top of the tail of the previous instance, as
long as the underlying mixer supports adding additional clips.
This is a boolean that is false by default, which means that
the clip is stopped and restarted each time the actor fires.
trigger
public TypedIOPort trigger
- The trigger. When this port receives a token of any type,
the actor begins playing the audio clip.
_clips
protected java.util.List<javax.sound.sampled.Clip> _clips
- The clip to playback.
ClipPlayer
public ClipPlayer(CompositeEntity container,
java.lang.String name)
throws IllegalActionException,
NameDuplicationException
- Construct an actor with the given container and name.
- Parameters:
container - The container.name - The name of this actor.
- Throws:
IllegalActionException - If the actor cannot be contained
by the proposed container.
NameDuplicationException - If the container already has an
actor with this name.
fire
public void fire()
throws IllegalActionException
- Produce outputs indicating that the clip has started or stopped.
- Specified by:
fire in interface Executable- Overrides:
fire in class AtomicActor
- Throws:
IllegalActionException - Not thrown in this class.
postfire
public boolean postfire()
throws IllegalActionException
- Read an input array and send to the audio hardware.
If the audio buffer cannot accept the samples, then this
method will stall the calling thread until it can.
- Specified by:
postfire in interface Executable- Overrides:
postfire in class AtomicActor
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException - If there is a problem
playing audio.
update
public void update(javax.sound.sampled.LineEvent event)
- Called to notify this object of changes in the status of
a clip.
- Specified by:
update in interface javax.sound.sampled.LineListener
- Parameters:
event - The event, with one of type OPEN, CLOSE,
START, STOP of class LineEvent.Type.
wrapup
public void wrapup()
throws IllegalActionException
- Stop audio playback and free up any audio resources used
for audio playback.
- Specified by:
wrapup in interface Initializable- Overrides:
wrapup in class AtomicActor
- Throws:
IllegalActionException - If there is a problem
stopping audio playback.