Class OSC::TimeTag
In: lib/osc.rb
Parent: Object

64-bit big-endian fixed-point time tag

Methods

method_missing   new   now   time   to_a   to_f   to_i   to_s   to_time   to_yaml  

Constants

JAN_1970 = 0x83aa7e80

Attributes

frac  [RW] 
int  [RW] 

Public Class methods

nil:immediately
Numeric:seconds since January 1, 1900 00:00
Numeric,Numeric:int,frac parts of a TimeTag.
Time:convert from Time object

[Source]

    # 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

[Source]

    # File lib/osc.rb, line 73
73:     def self.now; TimeTag.new(Time.now); end

Public Instance methods

[Source]

    # File lib/osc.rb, line 74
74:     def method_missing(sym, *args)
75:       time.__send__(sym, *args)
76:     end
time()

Alias for to_time

[int,frac]

[Source]

    # File lib/osc.rb, line 67
67:     def to_a; [@int,@frac]; end

Ruby‘s Float can handle the 64 bits so we have the luxury of dealing with Float directly

[Source]

    # File lib/osc.rb, line 65
65:     def to_f; @int.to_f + @frac.to_f/(2**32); end

[Source]

    # File lib/osc.rb, line 62
62:     def to_i; to_f.to_i; end

Human-readable, like the output of Time#to_s

[Source]

    # File lib/osc.rb, line 69
69:     def to_s; to_time.to_s; end

Ruby Time object

[Source]

    # File lib/osc.rb, line 71
71:     def to_time; Time.at(to_f-JAN_1970); end

[Source]

    # File lib/osc.rb, line 77
77:     def to_yaml
78:       to_a.to_yaml
79:     end

[Validate]