Class | OSC::TimeTag |
In: |
lib/osc.rb
|
Parent: | Object |
64-bit big-endian fixed-point time tag
JAN_1970 | = | 0x83aa7e80 |
frac | [RW] | |
int | [RW] |
nil: | immediately |
Numeric: | seconds since January 1, 1900 00:00 |
Numeric,Numeric: | int,frac parts of a TimeTag. |
Time: | convert from Time object |
# File lib/osc.rb, line 42 42: def initialize(*args) 43: t = args 44: t = t.first if t and t.size == 1 45: case t 46: when NIL # immediately 47: @int = 0 48: @frac = 1 49: when Numeric 50: @int, fr = t.divmod(1) 51: @frac = (fr * (2**32)).to_i 52: when Array 53: @int,@frac = t 54: when Time 55: @int, fr = (t.to_f+JAN_1970).divmod(1) 56: @frac = (fr * (2**32)).to_i 57: else 58: raise ArgumentError 59: end 60: end
Ruby‘s Float can handle the 64 bits so we have the luxury of dealing with Float directly
# File lib/osc.rb, line 65 65: def to_f; @int.to_f + @frac.to_f/(2**32); end
Human-readable, like the output of Time#to_s
# File lib/osc.rb, line 69 69: def to_s; to_time.to_s; end