ptolemy.actor.lib.javasound
Class ClipPlayer

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by 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 57046 2010-01-27 23:35:53Z cxh $
Author:
Edward A. Lee
See Also:
LiveSound, AudioCapture, AudioReader, AudioWriter, Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
protected  java.util.List<javax.sound.sampled.Clip> _clips
          The clip to playback.
private  java.util.List<BooleanToken> _outputEvents
          The output values to be produced on the next firing.
private  java.util.List<BooleanToken> _outputEventsCopy
          The output values to be produced on the next firing.
 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.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _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
ClipPlayer(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 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.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, 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.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, 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, 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
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, 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
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

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.


_outputEvents

private java.util.List<BooleanToken> _outputEvents
The output values to be produced on the next firing.


_outputEventsCopy

private java.util.List<BooleanToken> _outputEventsCopy
The output values to be produced on the next firing.

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

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.

Overrides:
clone in class AtomicActor
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 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.