|
|
|
@ -44,18 +44,19 @@ import java.util.logging.Level; |
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* AudioTrack is a track to add to an existing animation, to paly a sound during an animations |
|
|
|
|
* for example : gun shot, foot step, shout, etc... |
|
|
|
|
* |
|
|
|
|
* usage is |
|
|
|
|
* AudioTrack is a track to add to an existing animation, to paly a sound during |
|
|
|
|
* an animations for example : gun shot, foot step, shout, etc... |
|
|
|
|
* |
|
|
|
|
* usage is |
|
|
|
|
* <pre> |
|
|
|
|
* AnimControl control model.getControl(AnimControl.class); |
|
|
|
|
* AudioTrack track = new AudioTrack(existionAudioNode, control.getAnim("TheAnim").getLength()); |
|
|
|
|
* control.getAnim("TheAnim").addTrack(track); |
|
|
|
|
* </pre> |
|
|
|
|
* |
|
|
|
|
* This is mostly intended for short sounds, playInstance will be called on the AudioNode at time 0 + startOffset. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* This is mostly intended for short sounds, playInstance will be called on the |
|
|
|
|
* AudioNode at time 0 + startOffset. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Nehon |
|
|
|
|
*/ |
|
|
|
@ -76,7 +77,6 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -88,8 +88,10 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates an AudioTrack |
|
|
|
|
* |
|
|
|
|
* @param audio the AudioNode |
|
|
|
|
* @param length the length of the track (usually the length of the animation you want to add the track to) |
|
|
|
|
* @param length the length of the track (usually the length of the |
|
|
|
|
* animation you want to add the track to) |
|
|
|
|
*/ |
|
|
|
|
public AudioTrack(AudioNode audio, float length) { |
|
|
|
|
this.audio = audio; |
|
|
|
@ -99,9 +101,12 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates an AudioTrack |
|
|
|
|
* |
|
|
|
|
* @param audio the AudioNode |
|
|
|
|
* @param length the length of the track (usually the length of the animation you want to add the track to) |
|
|
|
|
* @param startOffset the time in second when the sound will be played after the animation starts (default is 0) |
|
|
|
|
* @param length the length of the track (usually the length of the |
|
|
|
|
* animation you want to add the track to) |
|
|
|
|
* @param startOffset the time in second when the sound will be played after |
|
|
|
|
* the animation starts (default is 0) |
|
|
|
|
*/ |
|
|
|
|
public AudioTrack(AudioNode audio, float length, float startOffset) { |
|
|
|
|
this(audio, length); |
|
|
|
@ -110,10 +115,15 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Internal use only |
|
|
|
|
* @see Track#setTime(float, float, com.jme3.animation.AnimControl, com.jme3.animation.AnimChannel, com.jme3.util.TempVars) |
|
|
|
|
* |
|
|
|
|
* @see Track#setTime(float, float, com.jme3.animation.AnimControl, |
|
|
|
|
* com.jme3.animation.AnimChannel, com.jme3.util.TempVars) |
|
|
|
|
*/ |
|
|
|
|
public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) { |
|
|
|
|
|
|
|
|
|
if (time == length) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!initialized) { |
|
|
|
|
control.addListener(new OnEndListener()); |
|
|
|
|
initialized = true; |
|
|
|
@ -132,6 +142,7 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retruns the length of the track |
|
|
|
|
* |
|
|
|
|
* @return length of the track |
|
|
|
|
*/ |
|
|
|
|
public float getLength() { |
|
|
|
@ -140,7 +151,8 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Clone this track |
|
|
|
|
* @return |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Track clone() { |
|
|
|
@ -148,8 +160,11 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This method clone the Track and search for the cloned counterpart of the original audio node in the given cloned spatial. |
|
|
|
|
* The spatial is assumed to be the Spatial holding the AnimControl controling the animation using this Track. |
|
|
|
|
* This method clone the Track and search for the cloned counterpart of the |
|
|
|
|
* original audio node in the given cloned spatial. The spatial is assumed |
|
|
|
|
* to be the Spatial holding the AnimControl controling the animation using |
|
|
|
|
* this Track. |
|
|
|
|
* |
|
|
|
|
* @param spatial the Spatial holding the AnimControl |
|
|
|
|
* @return the cloned Track with proper reference |
|
|
|
|
*/ |
|
|
|
@ -167,14 +182,15 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
//setting user data on the new AudioNode and marking it with a reference to the cloned Track.
|
|
|
|
|
setUserData(audioTrack); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return audioTrack; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* recursive function responsible for finding the newly cloned AudioNode |
|
|
|
|
* |
|
|
|
|
* @param spat |
|
|
|
|
* @return |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private AudioNode findAudio(Spatial spat) { |
|
|
|
|
if (spat instanceof AudioNode) { |
|
|
|
@ -213,16 +229,15 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void cleanUp() { |
|
|
|
|
TrackInfo t = (TrackInfo) audio.getUserData("TrackInfo"); |
|
|
|
|
t.getTracks().remove(this); |
|
|
|
|
if(!t.getTracks().isEmpty()){ |
|
|
|
|
audio.setUserData("TrackInfo", null); |
|
|
|
|
} |
|
|
|
|
TrackInfo t = (TrackInfo) audio.getUserData("TrackInfo"); |
|
|
|
|
t.getTracks().remove(this); |
|
|
|
|
if (!t.getTracks().isEmpty()) { |
|
|
|
|
audio.setUserData("TrackInfo", null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return the audio node used by this track |
|
|
|
|
*/ |
|
|
|
|
public AudioNode getAudio() { |
|
|
|
@ -231,7 +246,8 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* sets the audio node to be used for this track |
|
|
|
|
* @param audio |
|
|
|
|
* |
|
|
|
|
* @param audio |
|
|
|
|
*/ |
|
|
|
|
public void setAudio(AudioNode audio) { |
|
|
|
|
if (this.audio != null) { |
|
|
|
@ -243,7 +259,7 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return the start offset of the track |
|
|
|
|
*/ |
|
|
|
|
public float getStartOffset() { |
|
|
|
@ -252,7 +268,8 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* set the start offset of the track |
|
|
|
|
* @param startOffset |
|
|
|
|
* |
|
|
|
|
* @param startOffset |
|
|
|
|
*/ |
|
|
|
|
public void setStartOffset(float startOffset) { |
|
|
|
|
this.startOffset = startOffset; |
|
|
|
@ -260,6 +277,7 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Internal use only serialization |
|
|
|
|
* |
|
|
|
|
* @param ex exporter |
|
|
|
|
* @throws IOException exception |
|
|
|
|
*/ |
|
|
|
@ -272,6 +290,7 @@ public class AudioTrack implements ClonableTrack { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Internal use only serialization |
|
|
|
|
* |
|
|
|
|
* @param im importer |
|
|
|
|
* @throws IOException Exception |
|
|
|
|
*/ |
|
|
|
|