ddf.minim.ugens
Class FilePlayer

java.lang.Object
  extended by ddf.minim.ugens.UGen
      extended by ddf.minim.ugens.FilePlayer
All Implemented Interfaces:
Playable

public class FilePlayer
extends UGen
implements Playable

The FilePlayer UGen provides a way for you to wrap an AudioRecordingStream with the UGen interface, allowing you to patching into a UGen graph any way you choose. You can get an AudioRecordingStream from Minim by calling Minim.loadFileStream.

Author:
Damien Di Fede

Nested Class Summary
 
Nested classes/interfaces inherited from class ddf.minim.ugens.UGen
UGen.InputType, UGen.UGenInput
 
Constructor Summary
FilePlayer(AudioRecordingStream iFileStream)
          Construct a FilePlayer that will read from iFileStream.
 
Method Summary
 void close()
          Calling close will close the AudioStream that this wraps, which is proper cleanup for using the stream.
 void cue(int millis)
          Sets the position to millis milliseconds from the beginning.
 AudioMetaData getMetaData()
          Returns the meta data for the recording being played by this player.
 AudioRecordingStream getStream()
          Returns the wrapped AudioRecordingStream.
 boolean isLooping()
          Returns true if this is currently playing and has more than one loop left to play.
 boolean isPlaying()
          Returns true if this currently playing.
 int length()
          Returns the length of the sound in milliseconds.
 void loop()
          Sets looping to continuous.
 void loop(int n)
          Sets this to loop num times.
 int loopCount()
          Returns the number of loops left to do.
 void pause()
          Pauses playback.
 void play()
          Starts playback from the current position.
 void play(int millis)
          Starts playback millis from the beginning.
 int position()
          Returns the current position of the "playhead" (ie how much of the sound has already been played)
 void rewind()
          Rewinds to the beginning.
 void setLoopPoints(int start, int stop)
          Sets the loop points used when looping.
 void skip(int millis)
          Skips millis from the current position.
protected  void uGenerate(float[] channels)
          Implement this method when you extend UGen.
 
Methods inherited from class ddf.minim.ugens.UGen
addInput, getLastValues, patch, patch, patch, printInputs, removeInput, sampleRate, sampleRateChanged, setSampleRate, tick, unpatch, unpatch
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilePlayer

public FilePlayer(AudioRecordingStream iFileStream)
Construct a FilePlayer that will read from iFileStream.

Parameters:
iFileStream - the AudioRecordingStream this should read from
Method Detail

getStream

public AudioRecordingStream getStream()
Returns the wrapped AudioRecordingStream.

Returns:
the wrapped AudioRecordingStream

play

public void play()
Description copied from interface: Playable
Starts playback from the current position. If this was previous set to loop, looping will be disabled.

Specified by:
play in interface Playable

play

public void play(int millis)
Description copied from interface: Playable
Starts playback millis from the beginning. If this was previous set to loop, looping will be disabled.

Specified by:
play in interface Playable

pause

public void pause()
Description copied from interface: Playable
Pauses playback.

Specified by:
pause in interface Playable

rewind

public void rewind()
Description copied from interface: Playable
Rewinds to the beginning. This does not stop playback.

Specified by:
rewind in interface Playable

loop

public void loop()
Description copied from interface: Playable
Sets looping to continuous. If this is already playing, the position will not be reset to the beginning. If this is not playing, it will start playing.

Specified by:
loop in interface Playable

loop

public void loop(int n)
Description copied from interface: Playable
Sets this to loop num times. If this is already playing, the position will not be reset to the beginning. If this is not playing, it will start playing.

Specified by:
loop in interface Playable
Parameters:
n - the number of times to loop

loopCount

public int loopCount()
Description copied from interface: Playable
Returns the number of loops left to do.

Specified by:
loopCount in interface Playable
Returns:
the number of loops left

length

public int length()
Description copied from interface: Playable
Returns the length of the sound in milliseconds. If for any reason the length could not be determined, this will return -1. However, an unknown length should not impact playback.

Specified by:
length in interface Playable
Returns:
the length of the sound in milliseconds

position

public int position()
Description copied from interface: Playable
Returns the current position of the "playhead" (ie how much of the sound has already been played)

Specified by:
position in interface Playable
Returns:
the current position of the "playhead"

cue

public void cue(int millis)
Description copied from interface: Playable
Sets the position to millis milliseconds from the beginning. This will not change the playstate. If an error occurs while trying to cue, the position will not change. If you try to cue to a negative position or try to a position that is greater than length(), the amount will be clamped to zero or length().

Specified by:
cue in interface Playable
Parameters:
millis - the position to place the "playhead"

skip

public void skip(int millis)
Description copied from interface: Playable
Skips millis from the current position. millis can be negative, which will make this skip backwards. If the skip amount would result in a negative position or a position that is greater than length(), the new position will be clamped to zero or length().

Specified by:
skip in interface Playable
Parameters:
millis - how many milliseconds to skip, sign indicates direction

isLooping

public boolean isLooping()
Description copied from interface: Playable
Returns true if this is currently playing and has more than one loop left to play.

Specified by:
isLooping in interface Playable
Returns:
true if this is looping

isPlaying

public boolean isPlaying()
Description copied from interface: Playable
Returns true if this currently playing.

Specified by:
isPlaying in interface Playable
Returns:
true if this is currently playing

getMetaData

public AudioMetaData getMetaData()
Returns the meta data for the recording being played by this player.

Specified by:
getMetaData in interface Playable
Returns:
the meta data for this player's recording

setLoopPoints

public void setLoopPoints(int start,
                          int stop)
Description copied from interface: Playable
Sets the loop points used when looping.

Specified by:
setLoopPoints in interface Playable
Parameters:
start - the start of the loop in milliseconds
stop - the end of the loop in milliseconds

close

public void close()
Calling close will close the AudioStream that this wraps, which is proper cleanup for using the stream.


uGenerate

protected void uGenerate(float[] channels)
Description copied from class: UGen
Implement this method when you extend UGen. It will be called when your UGen needs to generate one sample frame of audio. It is expected that you will assign values to the array and not simply modify the existing values. In the case where you write a UGen that takes audio input and modifies it, the pattern to follow is to have the first UGenInput you create be your audio input and then in uGenerate you will use the getLastValues method of your audio UGenInput to retrieve the audio you want to modify, which you will then modify however you need to, assigning the result to the values in channels.

Specified by:
uGenerate in class UGen
Parameters:
channels - an array representing one sample frame.