Class BaseSound
java.lang.Object
org.web3d.vrml.renderer.common.nodes.AbstractNode
org.web3d.vrml.renderer.common.nodes.sound.BaseSound
- All Implemented Interfaces:
VRMLNode,FrameStateListener,VRMLChildNodeType,VRMLContentStateListener,VRMLNodeType,VRMLSoundNodeType,VRMLSoundStateListener,VRMLTimeDependentNodeType,VRMLWorldRootChildNodeType
public class BaseSound
extends AbstractNode
implements VRMLContentStateListener, VRMLSoundStateListener, VRMLTimeDependentNodeType, VRMLSoundNodeType
Common Sound node implementation for handling all the fields.
The sound node is defined by X3D to be the following:
Sound : X3DSoundNode {
SFVec3f [in,out] direction 0 0 1 (-inf,inf)
SFFloat [in,out] intensity 1 [0,1]
SFVec3f [in,out] location 0 0 0 (-inf,inf)
SFFloat [in,out] maxBack 10 [0,inf)
SFFloat [in,out] maxFront 10 [0,inf)
SFNode [in,out] metadata NULL [X3DMetadataObject]
SFFloat [in,out] minBack 1 [0,inf)
SFFloat [in,out] minFront 1 [0,inf)
SFFloat [in,out] priority 0 [0,1]
SFNode [in,out] source NULL [X3DSoundSourceNode]
SFBool [] spatialize TRUE
}
- Version:
- $Revision: 1.15 $
- Author:
- Guy Carpenter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static VRMLFieldDeclaration[]Array of VRMLFieldDeclarationsHashmap between a field name and its indexprotected VRMLProtoInstanceproto version of the source nodeprotected static final StringMessage for when the node is not a AudioClip node typeprotected static final StringMessage for when the proto is not a AudioClip node typeprotected float[]exposedField SFVec3f direction, default 0 0 1protected floatexposedField SFFloat intensity, default 1protected float[]exposedField SFVec3f location, default 0 0 0protected floatexposedField SFFloat maxBack, default 10protected floatexposedField SFFloat maxFront, default 10protected floatexposedField SFFloat minBack, default 1protected floatexposedField SFFloat minFront, default 1protected floatexposedField SFFloat priority, default 0protected VRMLAudioClipNodeTypeexposedField SFNode source, default NULLprotected booleanfield SFBool spatialize, default TRUEprotected VRMLClockThe sim clock this node usesFields inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
errorReporter, FIELD_METADATA, fieldLocalData, hasChanged, inSetup, isDEF, isStatic, LAST_NODE_INDEX, layerIds, nodeName, pMetadata, refCounts, removedLayerIds, stateManager, STATIC_SCENE_GRAPH, vfMetadata, vrmlMajorVersion, vrmlMinorVersion -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcontentStateChanged(VRMLNodeType node, int index, int state) Called when the contentState of the child audio source changes.voidcopy(VRMLNodeType node) Copies all of the field values from the passed nodes into our own node.voidDelete all containedsourcecontentgetFieldDeclaration(int index) Get the declaration of the field at the given index.intgetFieldIndex(String fieldName) Get the index of the given field name.getFieldValue(int index) Get the value of a field.int[]Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode).intGet the number of fields.intGet the primary type of this node.int[]Get the secondary type of this node.Get node content forsourcevoidsendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.booleansetDirection(float[] direction) Changes the direction vector for this sound.booleansetIntensity(float intensity) Changes the intensity (global gain) for this sound.booleansetLocation(float[] location) Changes the location of this sound.booleansetMaxBack(float maxBack) Changes the maxBack distance for this sound.booleansetMaxFront(float maxFront) Changes the maxFront distance for this sound.booleansetMinBack(float minBack) Changes the minBack distance for this sound.booleansetMinFront(float minFront) Changes the minFront distance for this sound.booleansetPriority(float priority) Changes the sound priority.voidsetSource(VRMLNodeType source) Set node content as replacement for the audio sourcesvoidCalled when the construction phase of this node has finished.voidsetValue(int index, boolean value) Set the value of the field at the given index as a boolean.voidsetValue(int index, float value) Set the value of the field at the given index as a float.voidsetValue(int index, float[] value, int numValid) Set the value of the field at the given index as an array of floats.voidsetValue(int index, VRMLNodeType child) Set the value of the field at the given index to a node.voidsetVRMLClock(VRMLClock clk) Set the vrmlClock that this time dependent node will be running with.voidsoundStateChanged(VRMLNodeType node, boolean newIsActive, boolean newLoop, float newPitch, double startTime) Called when the soundState of the child audio source changes.Methods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
addNodeListener, allEventsComplete, checkNodeType, checkSecondaryType, checkSecondaryType, clearRemovedLayerIds, fireFieldChanged, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, getUserData, getVRMLNodeName, hasFieldChanged, isDEF, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setErrorReporter, setFrameStateManager, setMetadataObject, setUserData, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setVersion, throwInitOnlyWriteException, throwInputOnlyWriteException, throwInvalidNodeException, throwInvalidProtoException, throwOutputOnlyWriteException, updateRefCount, updateRefsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.web3d.vrml.nodes.FrameStateListener
allEventsCompleteMethods inherited from interface org.web3d.vrml.lang.VRMLNode
getUserData, getVRMLNodeName, isDEF, setErrorReporter, setUserData, setVersionMethods inherited from interface org.web3d.vrml.nodes.VRMLNodeType
addNodeListener, clearRemovedLayerIds, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, hasFieldChanged, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setFrameStateManager, setMetadataObject, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, updateRefCount
-
Field Details
-
SOURCE_PROTO_MSG
Message for when the proto is not a AudioClip node type- See Also:
-
SOURCE_NODE_MSG
Message for when the node is not a AudioClip node type- See Also:
-
vrmlClock
The sim clock this node uses -
fieldDecl
Array of VRMLFieldDeclarations -
fieldMap
-
vfDirection
protected float[] vfDirectionexposedField SFVec3f direction, default 0 0 1 -
vfIntensity
protected float vfIntensityexposedField SFFloat intensity, default 1 -
vfLocation
protected float[] vfLocationexposedField SFVec3f location, default 0 0 0 -
vfMaxBack
protected float vfMaxBackexposedField SFFloat maxBack, default 10 -
vfMaxFront
protected float vfMaxFrontexposedField SFFloat maxFront, default 10 -
vfMinBack
protected float vfMinBackexposedField SFFloat minBack, default 1 -
vfMinFront
protected float vfMinFrontexposedField SFFloat minFront, default 1 -
vfPriority
protected float vfPriorityexposedField SFFloat priority, default 0 -
vfSpatialize
protected boolean vfSpatializefield SFBool spatialize, default TRUE -
vfSource
exposedField SFNode source, default NULL -
pSource
proto version of the source node
-
-
Constructor Details
-
BaseSound
public BaseSound()Constructs a new default BaseSound.
-
-
Method Details
-
copy
Copies all of the field values from the passed nodes into our own node.- Parameters:
node- The node to copy- Throws:
IllegalArgumentException- The node is not a compatible node
-
setDirection
public boolean setDirection(float[] direction) Changes the direction vector for this sound. Stores the direction vector in vfDirection and fires a fieldChanged event. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
direction- New direction vector- Returns:
- true if the field value was actually changed.
-
setIntensity
public boolean setIntensity(float intensity) Changes the intensity (global gain) for this sound. Stores the new intensity in vfIntensity and fires a fieldChanged event.A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.
- Parameters:
intensity- New intensity value- Returns:
-
setLocation
public boolean setLocation(float[] location) Changes the location of this sound. Stores the new location in vfLocation and fires a fieldChanged event. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
location- New location vector- Returns:
-
setMaxBack
public boolean setMaxBack(float maxBack) Changes the maxBack distance for this sound. Stores the new value in vfMaxBack and fires a fieldChanged event. The maxback value specifies the point at which the distance/gain ramp falls to zero behind the sound source. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
maxBack- New maxBack value.- Returns:
-
setMaxFront
public boolean setMaxFront(float maxFront) Changes the maxFront distance for this sound. Stores the new value in vfMaxFront and fires a fieldChanged event. The maxfront value specifies the point at which the distance/gain ramp falls to zero in front of the sound source. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
maxFront- New maxFront value.- Returns:
-
setMinBack
public boolean setMinBack(float minBack) Changes the minBack distance for this sound. Stores the new value in vfMinBack and fires a fieldChanged event. The minback value specifies the point at which the distance/gain ramp starts to fall off from 0db behind the sound source. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
minBack- New minBack value.- Returns:
-
setMinFront
public boolean setMinFront(float minFront) Changes the minFront distance for this sound. Stores the new value in vfMinFront and fires a fieldChanged event. The minfront value specifies the point at which the distance/gain ramp starts to fall off from 0db in front of the sound source. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
minFront- New minFront value.- Returns:
-
setPriority
public boolean setPriority(float priority) Changes the sound priority. Sets vfPriority and fires a FieldChanged event. A false return value indicates the value was unchanged either because it was already set to this value, or because the new value was out of range.- Parameters:
priority- New priority value.- Returns:
- true if the new priority value is accepted.
-
setupFinished
public void setupFinished()Called when the construction phase of this node has finished.- Specified by:
setupFinishedin interfaceVRMLNodeType- Overrides:
setupFinishedin classAbstractNode
-
getFieldIndex
Get the index of the given field name. If the name does not exist for this node then return a value of -1.- Specified by:
getFieldIndexin interfaceVRMLNode- Parameters:
fieldName- The name of the field we want the index from- Returns:
- The index of the field name or -1
-
getNodeFieldIndices
public int[] getNodeFieldIndices()Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode). Used for blind scene graph traversal without needing to spend time querying for all fields etc. If a node does not have any fields that contain nodes, this shall return null. The field list covers all field types, regardless of whether they are readable or not at the VRML-level.- Specified by:
getNodeFieldIndicesin interfaceVRMLNode- Returns:
- The list of field indices that correspond to SF/MFnode fields or null if none
-
getPrimaryType
public int getPrimaryType()Get the primary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getPrimaryTypein interfaceVRMLNode- Returns:
- The primary type
-
getFieldDeclaration
Get the declaration of the field at the given index. This allows for reverse lookup if needed. If the field does not exist, this will give a value of null.- Specified by:
getFieldDeclarationin interfaceVRMLNode- Parameters:
index- The index of the field to get information- Returns:
- A representation of this field's information
-
getNumFields
public int getNumFields()Get the number of fields.- Specified by:
getNumFieldsin interfaceVRMLNode- Returns:
- The number of fields.
-
getFieldValue
Get the value of a field. If the field is a primitive type, it will return a class representing the value. For arrays or nodes it will return the instance directly.- Specified by:
getFieldValuein interfaceVRMLNodeType- Overrides:
getFieldValuein classAbstractNode- Parameters:
index- The index of the field to change.- Returns:
- The class representing the field value
- Throws:
InvalidFieldException- The field index is not known
-
sendRoute
Send a routed value from this node to the given destination node. The route should use the appropriate setValue() method of the destination node. It should not attempt to cast the node up to a higher level. Routing should also follow the standard rules for the loop breaking and other appropriate rules for the specification.- Specified by:
sendRoutein interfaceVRMLNodeType- Overrides:
sendRoutein classAbstractNode- Parameters:
time- The time that this route occurred (not necessarily epoch time. Should be treated as a relative value only)srcIndex- The index of the field in this node that the value should be sent fromdestNode- The node reference that we will be sending the value todestIndex- The index of the field in the destination node that the value should be sent to.
-
setValue
public void setValue(int index, boolean value) throws InvalidFieldException, InvalidFieldValueException, InvalidFieldAccessException Set the value of the field at the given index as a boolean. This would be used to set SFBoolean field types.- Specified by:
setValuein interfaceVRMLNodeType- Overrides:
setValuein classAbstractNode- Parameters:
index- The index of destination field to setvalue- The new value to use for the node- Throws:
InvalidFieldException- The field index is not knownInvalidFieldValueException- The value provided is not in range or not appropriate for this fieldInvalidFieldAccessException- The call is attempting to write to a field that does not permit writing now
-
setValue
public void setValue(int index, float value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a float. This would be used to set SFFloat field types.- Specified by:
setValuein interfaceVRMLNodeType- Overrides:
setValuein classAbstractNode- Parameters:
index- The index of destination field to setvalue- The new value to use for the node- Throws:
InvalidFieldException- The field index is not knownInvalidFieldValueException- The value provided is not in range or not appropriate for this fieldInvalidFieldAccessException- The call is attempting to write to a field that does not permit writing now
-
setValue
public void setValue(int index, float[] value, int numValid) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as an array of floats. This would be used to set MFFloat, SFVec2f, SFVec3f and SFRotation field types.- Specified by:
setValuein interfaceVRMLNodeType- Overrides:
setValuein classAbstractNode- Parameters:
index- The index of destination field to setvalue- The new value to use for the nodenumValid- The number of valid values to copy from the array- Throws:
InvalidFieldException- The field index is not knownInvalidFieldValueException- The value provided does not fit this type of nodeInvalidFieldAccessException- The call is attempting to write to a field that does not permit writing now
-
setValue
Set the value of the field at the given index to a node. This would be used to set SFNode field types.- Specified by:
setValuein interfaceVRMLNodeType- Overrides:
setValuein classAbstractNode- Parameters:
index- The index of destination field to setchild- The new value to use for the node- Throws:
InvalidFieldException- The field index is not known
-
contentStateChanged
Called when the contentState of the child audio source changes. The base implementation does nothing. Subclasses can trap this call to determine when the audio source is available for use (when state==LOAD_COMPLETE).- Specified by:
contentStateChangedin interfaceVRMLContentStateListener- Parameters:
node- The child sound source node.index- The index of the field that has changed state.state- The new state value.
-
soundStateChanged
public void soundStateChanged(VRMLNodeType node, boolean newIsActive, boolean newLoop, float newPitch, double startTime) Called when the soundState of the child audio source changes. The base implementation does nothing. Subclasses can trap this call to act when any of the sound state parameters (isActive, loop, and pitch) change.- Specified by:
soundStateChangedin interfaceVRMLSoundStateListener- Parameters:
node- The child sound source node.newIsActive-newLoop-newPitch-startTime- The current value of the startTime field
-
setVRMLClock
Set the vrmlClock that this time dependent node will be running with.- Specified by:
setVRMLClockin interfaceVRMLTimeDependentNodeType- Parameters:
clk- The vrmlClock to use for this node
-
getSecondaryType
public int[] getSecondaryType()Get the secondary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getSecondaryTypein interfaceVRMLNode- Overrides:
getSecondaryTypein classAbstractNode- Returns:
- The secondary type
-
getSource
Get node content forsource- Specified by:
getSourcein interfaceVRMLSoundNodeType- Returns:
- The current source
-
setSource
Set node content as replacement for the audio sources- Specified by:
setSourcein interfaceVRMLSoundNodeType- Parameters:
source- The new source. null will act like delete
-
deleteSource
public void deleteSource()Delete all containedsourcecontent- Specified by:
deleteSourcein interfaceVRMLSoundNodeType
-