SMPTE

part of wslib


The SMPTE object holds timecode values and provides noumerous ways for handling timecode.

The object shows in the post window as an array with hours, minutes, seconds, frames and subFrames.

All values are rounded to whole numbers except the subframes.


Used by SMPTEView, TransportWindow and SimpleMIDIFile


By default the frameRate is 25 (25 per second), and the subFrameRate 100 (100 per frame).


please note: the SMPTE class does not generate nor recognise SMPTE timecode signals.



Creation


SMPTE( inSeconds, fps )

Generates a new SMPTE object


inSeconds - raw seconds from which SMPTE will calculate hours, minutes, seconds, frames and subframes.

fps - frame rate (defaults to 25, standard for europe). Dropped frames are not supported, but the frame rate doesn't have to be a whole number.



SMPTE( 5 );  // -> SMPTE[ 0, 0, 5, 0, 0 ]


SMPTE( 65.5);  // -> SMPTE[ 0, 1, 5, 12, 50 ] (1 minute, 5 seconds, 12 frames, 50 subFrames (1/100))



SMPTE[ hours, minutes, seconds, frames, subFrames ]

Creates a SMPTE object directly. This only works when all five values are entered.



SMPTE[ 0, 10, 30, 5, 0 ]; // -> SMPTE[ 0, 10, 30, 5, 0 ]


SMPTE[ 0, 10, 70, 5, 0 ]; // -> SMPTE[ 0, 10, 70, 5, 0 ] (does not recalculate)


SMPTE[ 0, 10, 70, 5, 0 ].reCalculate; // -> SMPTE[ 0, 11, 10, 5, 0 ]



SMPTE.hours( inHours, fps ), SMPTE.minutes( inMinutes, fps ), 

SMPTE.frames( inFrames, fps ), SMPTE.subFrames( inSubFrames, fps )

Generates a new SMPTE object with raw values as input


SMPTE.hours( 1.25 );  // -> SMPTE[ 1, 15, 0, 0, 0 ] (1 hour, 15 minutes)



SMPTE.type( input, type, fps )

Generates a new SMPTE object with raw values with specified types as input


type - a Symbol, can be:

\hours, \minutes, \seconds, \frames, \subFrames

SMPTE.type( 1.25, \hours ); // -> SMPTE[ 1, 15, 0, 0, 0 ] (1 hour, 15 minutes)



SMPTE.minSec( minutes, seconds )

Generates a new SMPTE object with raw minutes and seconds as input


SMPTE.minSec( 10, 5 ); // -> SMPTE[ 0, 10, 5, 0, 0 ]


SMPTE.minSec( 70, 80.5 ); // -> SMPTE[ 1, 11, 20, 12, 50 ]



SMPTE.fromString( string, fps )


string - a string with ":" characters as dividers for hours, minutes, seconds and frames



SMPTE.fromString( "00:10:05:00" ); // -> SMPTE[ 0, 10, 5, 0, 0 ]



SMPTE.localtime

Creates a new SMPTE object with the current system time




Methods:


asSeconds

returns the raw seconds


SMPTE( 65.5).asSeconds; // -> 65.5


asHours, asMinutes, asFrames, asSubframes

returns raw values for hours, minutes, frames or subFrames


SMPTE( 65.5).asMinutes; // -> 1.0916666666667


SMPTE( 65.5).asSubFrames; // -> 163750



hours, minutes, seconds, frames, subFrames

acces values directly


SMPTE( 65.5).minutes; // -> 1


SMPTE( 65.5).seconds; // -> 5


hours_ , minutes_ , seconds_ , frames_ , subFrames_

set values directly. Does recaclulate internally.


SMPTE( 0 ).minutes_( 5.5 ); // -> SMPTE[ 0, 5, 30, 0, 0 ]



fps_( newFps )

set framerate and recalculate


SMPTE( 65.5).frames; // -> 12


SMPTE( 65.5).fps_(30).frames; // -> 15


setFps( newFps )

set framerate without recalculation


SMPTE( 65.5).setFps(30).frames; // -> 12


toString

returns a time string separated by ":" characters. Subframes are ignored


SMPTE( 65.5 ).toString; // -> 00:01:05:12


SMPTE( 65.5, fps: 1000).toString; // -> 00:01:05:500



reCalculate

recalculates any invalid time values to valid time values. This is called internally in most methods.


asMinSec

returns an array with raw minutes and seconds (as used by the *minSec creation method)


SMPTE.minSec(10, 21.1).asMinSec; // -> [10, 21.1]




Operators:


+, -, *, /

SMPTE objects can be added, substracted, multiplied and divided with other SMPTE objects, Numbers or Arrays. For numbers the type can be specified with an adverb (.hours, .minutes, .seconds, .frames, .subFrames).

The framerate (fps) of the first object will be used for the output object.


SMPTE( 20 ) + SMPTE( 50 ); // -> SMPTE[ 0, 1, 10, 0, 0 ]


SMPTE( 20 ) + 50; // -> SMPTE[ 0, 1, 10, 0, 0 ]


SMPTE( 20 ) +.minutes 2.5; // -> SMPTE[ 0, 2, 50, 0, 0 ] (plus 2 minutes and 30 seconds)


SMPTE[ 0, 10, 5, 0, 0 ] + [0, 1, 2, 3 ]; // -> SMPTE[ 0, 11, 7, 3, 0 ]


SMPTE( 0.1 ) + SMPTE.frames( 3, fps: 30 ); // -> SMPTE[ 0, 0, 0, 5, 0 ] (fps = 25)


SMPTE( 20 ) * 2; // -> SMPTE[ 0, 0, 40, 0, 0 ]


( SMPTE.minSec( 4, 33 ) + SMPTE.minSec( 10, 55 ) ).asMinSec; // -> [ 15, 28 ] (here you go Sciss!)




<, <=, ==, =>, >, !=

Binary operators


SMPTE( 10 ) > SMPTE( 5 ); // -> true


SMPTE.hours( 1.1 ) == SMPTE.frames( 99000 ); // -> true