com.pelzer.util
Class Timecode

java.lang.Object
  extended by com.pelzer.util.Timecode
All Implemented Interfaces:
Serializable, Cloneable

public class Timecode
extends Object
implements Serializable, Cloneable

Offers methods to act on timecodes, SMPTE or otherwise. Has special support for audio timecodes, which look like SMPTE but have 75 frames/sec. This class does some nice things, such as when you pass in "00:00:75:00" as a timecode, it normalizes the data to "00:01:15:00". If you pass in a code with a fifth parameter, that parameter is assumed to be samples. Any non-numeric character can be used as a delimiter, so both "00|01|12|34" and "00a01b12c34" are equivalent. toSamples() returns the total number of samples that this code represents, and is the most accurate representation with which to do arithmetic on.

See Also:
Serialized Form

Nested Class Summary
 class Timecode.TimecodeException
           
static class Timecode.Type
           
 
Constructor Summary
Timecode()
          Deprecated. This is here for XMLEncode/Decode only. Use Timecode(com.pelzer.util.Timecode.Type) instead.
Timecode(float seconds)
          Creates a new CD timecode based on seconds using default seconds->frames rate from UploadConstants
Timecode(float seconds, Timecode.Type type)
          Creates a new timecode of the given type based on seconds.
Timecode(String timecode)
          Creates a new CD timecode based on a string in the form HH:MM:SS:FF
Timecode(String timecode, Timecode.Type type)
          Creates a new timecode of the given type based on a string in the form HH:MM:SS:FF
Timecode(Timecode.Type type)
          Creates a new blank timecode of the given type set at 00:00:00:00
 
Method Summary
 void clear()
           
 boolean equals(Object obj)
           
 String getCode()
           
 String getCodeWithSamples()
           
 int getFrames()
           
 float getFramesPerSecond()
           
 int getHours()
           
 int getMinutes()
           
 long getSamples()
           
 float getSamplesPerSecond()
           
 int getSeconds()
           
 void normalize()
          Goes through the system and sanitizes badly formed values : 00:00:60:00 will become 00:01:00:00, etc.
 void setCode(double seconds)
           
 void setCode(float seconds)
          Sets the object up based on seconds...
 void setCode(int frames)
          Set the code based on frames, framesPerSecond defaults to 75.
 void setCode(String timecode)
          Sets the object based on a string in the form HH:MM:SS:FF
 void setFrames(int value)
           
 void setFramesPerSecond(float value)
           
 void setHours(int value)
           
 void setMinutes(int value)
           
 void setSamples(long value)
           
 void setSamplesPerSecond(float value)
           
 void setSeconds(int value)
           
 void setUseSamples(boolean b)
          If true, samples per second will be used in computing fractions of frames.
 double toDoubleSeconds()
           
 double toFrames()
           
 String toHHMMSS()
          Uses the default ":" delimiter
 String toHHMMSS(String delimiter)
          Units smaller than seconds are ignored completely.
 int toIntSeconds()
          Hours are added to the minutes and minutes are added to the seconds value so seconds could be larger than 60.
 String toMMSS()
          Uses the default ":" delimiter
 String toMMSS(String delimiter)
          Hours are added to the minutes value so minutes could be larger than 60.
 long toSamples()
           
 float toSeconds()
           
 String toString()
           
 boolean useSamples()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Timecode

public Timecode()
Deprecated. This is here for XMLEncode/Decode only. Use Timecode(com.pelzer.util.Timecode.Type) instead.

Creates a new blank CD timecode set at 00:00:00:00


Timecode

public Timecode(Timecode.Type type)
Creates a new blank timecode of the given type set at 00:00:00:00


Timecode

public Timecode(String timecode)
         throws Timecode.TimecodeException
Creates a new CD timecode based on a string in the form HH:MM:SS:FF

Throws:
Timecode.TimecodeException

Timecode

public Timecode(String timecode,
                Timecode.Type type)
         throws Timecode.TimecodeException
Creates a new timecode of the given type based on a string in the form HH:MM:SS:FF

Throws:
Timecode.TimecodeException

Timecode

public Timecode(float seconds)
Creates a new CD timecode based on seconds using default seconds->frames rate from UploadConstants


Timecode

public Timecode(float seconds,
                Timecode.Type type)
Creates a new timecode of the given type based on seconds.

Method Detail

clear

public void clear()

setHours

public void setHours(int value)

getHours

public int getHours()

setMinutes

public void setMinutes(int value)

getMinutes

public int getMinutes()

setSeconds

public void setSeconds(int value)

getSeconds

public int getSeconds()

setFrames

public void setFrames(int value)

getFrames

public int getFrames()

setFramesPerSecond

public void setFramesPerSecond(float value)

getFramesPerSecond

public float getFramesPerSecond()

setSamples

public void setSamples(long value)

getSamples

public long getSamples()

setSamplesPerSecond

public void setSamplesPerSecond(float value)

getSamplesPerSecond

public float getSamplesPerSecond()

useSamples

public boolean useSamples()

setUseSamples

public void setUseSamples(boolean b)
If true, samples per second will be used in computing fractions of frames. If false, frames is the smallest unit.


setCode

public void setCode(String timecode)
             throws Timecode.TimecodeException
Sets the object based on a string in the form HH:MM:SS:FF

Throws:
Timecode.TimecodeException

setCode

public void setCode(float seconds)
Sets the object up based on seconds... Will be an approximation as the code will default to 1/75 second accuracy or that set by setFramesPerSecond().)


setCode

public void setCode(double seconds)

setCode

public void setCode(int frames)
Set the code based on frames, framesPerSecond defaults to 75. For example, setCode(100) would be '00:00:01:25'


normalize

public void normalize()
Goes through the system and sanitizes badly formed values : 00:00:60:00 will become 00:01:00:00, etc.


getCode

public String getCode()

getCodeWithSamples

public String getCodeWithSamples()

toSeconds

public float toSeconds()

toDoubleSeconds

public double toDoubleSeconds()

toFrames

public double toFrames()
Returns:
the total number of frames this object represents, so for a 1 second ntsc video timecode, this would return 29.97.

toSamples

public long toSamples()
Returns:
the total number of samples this object represents, so for a 1 second timecode, this would return 44100.

toString

public String toString()
Overrides:
toString in class Object

toIntSeconds

public int toIntSeconds()
Hours are added to the minutes and minutes are added to the seconds value so seconds could be larger than 60. Units smaller than seconds are ignored completely.

Returns:
the total time in seconds.

toMMSS

public String toMMSS(String delimiter)
Hours are added to the minutes value so minutes could be larger than 60. Units smaller than seconds are ignored completely. For example the HH:MM:SS:FF string "01:03:05:07" would return "63:05"

Parameters:
delimiter -
Returns:
the total time in mm:ss format where ":" is specified by the delimiter parameter.

toMMSS

public String toMMSS()
Uses the default ":" delimiter

Returns:
the code as "MM:SS"

toHHMMSS

public String toHHMMSS()
Uses the default ":" delimiter

Returns:
the code as "HH:MM:SS"

toHHMMSS

public String toHHMMSS(String delimiter)
Units smaller than seconds are ignored completely. For example the HH:MM:SS:FF string "01:03:05:07" would return "01:03:05"

Parameters:
delimiter -
Returns:
the total time in hh:mm:ss format where ":" is specified by the delimiter parameter.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2012. All Rights Reserved.