Sha256: b34bac5c29c39ce9f6d7326bfd36c77d60d731f9e50c0130966ded42af04a656

Contents?: true

Size: 869 Bytes

Versions: 2

Compression:

Stored size: 869 Bytes

Contents

module OSC
  class Bundle
    attr_accessor :timetag

    def initialize(timetag=nil, *args)
      @timetag = timetag
      @args = args
    end

    def encode()
      s = OSCString.new('#bundle').encode
      s << encode_timetag(@timetag)
      s << @args.collect do |x|
        x2 = x.encode; [x2.size].pack('N') + x2
      end.join
    end

    def to_a() @args.collect{|x| x.to_a} end

  private

    def encode_timetag(t)
      case t
        when nil # immediately
          t1 = 0
          t2 = 1
        when Numeric
          t1, t2 = construct_timetag( t )
        when Time
          t1, t2 = construct_timetag( t.to_ntp )
        else
          raise ArgumentError, 'invalid time'
      end
      [t1, t2].pack('N2')
    end

    def construct_timetag( time )
      t1, fr = time.divmod(1)
      t2 = (fr * (2**32)).to_i

      [t1, t2]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
osc-ruby-1.1.3 lib/osc-ruby/bundle.rb
osc-ruby-1.1.2 lib/osc-ruby/bundle.rb