package timecode; our $fps = 25; sub fps { $fps = $_[1]; } sub _smpte2int { my $tc = shift; my @hmsf = split ':' , $tc; my ($hours , $mins, $secs , $frames); $hours = 60*60*$fps*$hmsf[0]; $mins = 60*$fps* $hmsf[1]; $secs = $fps * $hmsf[2]; $frames= $hmsf[3]; return $hours+$mins+$secs+$frames; } sub _int2smpte { my $int = shift; my ($hours , $mins , $secs , $frames); my $r; $r = $int % ($fps*60*60); $hours = sprintf '%02d' , int ( ($int-$r) / ($fps*60*60) ) ; $int = $r; $r = $int % ($fps*60); $mins = sprintf '%02d' , int ( ($int-$r) / ($fps*60) ); $int = $r; $r = $int % ($fps); $secs = sprintf '%02d' , int ( ($int-$r) / ($fps) ); $int = $r; $frames = sprintf '%02d' , $int; return join ":", $hours,$mins,$secs,$frames ; } sub new { my $self = shift; my %tc = @_; #@tc{qw/in out/} = ( _smpte2int($in) , _smpte2int($out) ); die @_ unless ( defined $tc{in} ); die @_ unless (defined $tc{out}); $tc{in} = _smpte2int($tc{in}); $tc{out} = _smpte2int($tc{out}); return bless \%tc, $self; } sub copy { my $self=shift; my $ref =shift; my %tc = %$ref; return bless \%tc, $self; } sub asEdl { my $self = shift; my $in = _int2smpte($self->{in}); my $out= _int2smpte($self->{out}); return join '' , $self->{event}, ' 'x2, $self->{roll}, ' 'x6, $self->{channel}, ' 'x5, $self->{type}, ' 'x8, "$in $out $in $out \n"; } sub check { my $self = shift; return _int2smpte ( $self->{in} ) , _int2smpte( $self->{out} ); }