Package ptolemy.actor.lib.javasound
Class ClipPlayer
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.javasound.ClipPlayer
-
- All Implemented Interfaces:
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. Each time this actor fires, it starts playing the clip given by the fileOrURL parameter. 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. If playToCompletion is true, then each firing returns only after the clip has finished playing. Otherwise, the firing returns immediately, and another firing will result in either truncating the current clip or overlaying a new instance of it, depending on the value of overlay. If outputOnlyOnStop is false (the default), then this actor will produce an output (with value false) only when the current clip has finished playing. Otherwise, it will also produce an output (with value true) when the clip starts playing. If playToCompletion is true, both of these outputs will occur in the same firing. Otherwise, when the clip starts or stops (which occurs in another thread), this actor will request that the director fire it, and when it fires, it will produce the appropriate output.- Since:
- Ptolemy II 6.1
- Version:
- $Id$
- Author:
- Edward A. Lee
- See Also:
LiveSound
,AudioCapture
,AudioReader
,AudioWriter
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<javax.sound.sampled.Clip>
_clips
The clip to playback.FilePortParameter
fileOrURL
The file or URL giving the audio clip.TypedIOPort
output
Output port used to indicate starts and stops.Parameter
outputOnlyOnStop
If true, only produce a single FALSE token upon stop.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.Parameter
playToCompletion
If true, then play the clip to completion before returning from firing.TypedIOPort
stop
Stop playback when this port receives a token of any type, if any clip is playing.TypedIOPort
trigger
The trigger.-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description ClipPlayer(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
React to a change in an attribute.java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
fire()
Produce any pending outputs indicating that the clip has started or stopped, then if the stop input has a token, stop all clips that may be playing, then if the trigger input has a token, start a new instance of the clip playing.void
update(javax.sound.sampled.LineEvent event)
Called by the clip 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.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, 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
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
fileOrURL
public FilePortParameter 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.
-
outputOnlyOnStop
public Parameter outputOnlyOnStop
If true, only produce a single FALSE token upon stop. Useful for chaining clips together in the SDF domain where multiple output tokens will cause an exception to be thrown.
-
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.
-
playToCompletion
public Parameter playToCompletion
If true, then play the clip to completion before returning from firing. This is a boolean that defaults to false.
-
stop
public TypedIOPort stop
Stop playback when this port receives a token of any type, if any clip is playing.
-
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.
-
-
Constructor Detail
-
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.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
React to a change in an attribute. In this case, check the value of the path attribute to make sure it is a valid URI.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the change is not acceptable to this container (not thrown in this base class).
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new actor.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class contains an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
fire
public void fire() throws IllegalActionException
Produce any pending outputs indicating that the clip has started or stopped, then if the stop input has a token, stop all clips that may be playing, then if the trigger input has a token, start a new instance of the clip playing. If playToCompletion is true, then do not return until the clip has completed playing. Otherwise, return immediately.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Not thrown in this class.
-
update
public void update(javax.sound.sampled.LineEvent event)
Called by the clip to notify this object of changes in the status of a clip.- Specified by:
update
in interfacejavax.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 interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is a problem stopping audio playback.
-
-