Hello,
please excuse my stupidity both in programming and generally in understanding PD. i've been trying to figure a way to convert a frame number (received with OSC) to a timecode but the code i tried to adapt from a matlab script by Malcolm A. MacIver that i found here http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=1116&objectType=File
involves some for...loop and i dont know how to do the same in PD... can anyone explain, please?
i guess the field part of the smpte timcode (and other bits of information) are usually not needed, for most people HH:MM:SS:FF Information will be ok... maybe with an adjustable framerate between 30 (ntsc) and 25 (pal)
greetings,
till
function smpte = dec2smpte(init, framecount, field)
% convert the smpte time from the total elapsed frames and field as an integer
% to the new smpte time
first_field=init(9);
weight=[1080000 108000 18000 1800 300 30 10 1];
ns=[];
remain=framecount;
for i=1:8
ns(i)=floor(remain/weight(i));
remain=remain- (ns(i)*weight(i));
end
if strcmp(first_field,':')
second_field='.';
else
second_field=':';
end
if field==1
field_flag=first_field;
else
field_flag=second_field;
end
smpte=[ ...
num2str(ns(1)) num2str(ns(2)) ':' ...
num2str(ns(3)) num2str(ns(4)) ':' ...
num2str(ns(5)) num2str(ns(6)) field_flag ...
num2str(ns(7)) num2str(ns(8))];
different approach here
function itc (int "framecount", float "rate", bool "ms")
{
rate=default(rate,25)
ms = default(ms, false)
drop = (rate==29.97)? true : false
rate2 = (drop==true)? 30 : rate
hours=floor((framecount/rate)/3600)%60
mins=floor((framecount/rate)/60.0)%60
secs=floor(framecount/rate)%60
milli=floor(1000*framecount/rate)%6000%1000
fmilli=framecount/rate - floor(framecount/rate)
#frames=floor(fmilli*rate2)
frames=framecount%int(rate)
dframes = (drop==false)? frames : (secs==0)&&(mins%10!=0)? floor(fmilli*rate2) + 2 : frames
return (ms==false)? (string(hours,"%02.0f")+":"+string(mins,"%02.0f")+":"+string(secs,"%02.0f")+":"+string(frames,"%02.0f")) :
\ (string(hours,"%02.0f")+":"+string(mins,"%02.0f")+":"+string(secs,"%02.0f")+":"+string(milli,"%03.0f"))
}