Skip to content

Commit

Permalink
Ruby - teach OSC encoder how to encode int64 'h'
Browse files Browse the repository at this point in the history
  • Loading branch information
samaaron committed May 13, 2021
1 parent b529287 commit a7612c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/server/ruby/lib/sonicpi/osc/osc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
require_relative 'udp_client'
require_relative 'udp_server'
require_relative 'websocket_server'
require_relative 'blob'
require_relative 'osc_types'
require_relative 'oscencode'
require_relative 'oscdecode'
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(data)
# add padding

@binary = b + ("\000" * ((4 - (b.size % 4)) % 4))

end

def to_s
Expand All @@ -33,5 +34,21 @@ def inspect
end

end

class Int64
attr_reader :binary
def initialize(val)
@val = val
@binary = [val].pack('q>')
end

def to_i
@val.to_i
end

def inspect
@val.inspect
end
end
end
end
4 changes: 4 additions & 0 deletions app/server/ruby/lib/sonicpi/osc/oscencode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(use_cache = false, cache_size=1000)
@literal_low_g = 'g'.freeze
@literal_low_s = 's'.freeze
@literal_low_b = 'b'.freeze
@literal_low_h = 'h'.freeze
@literal_empty_str = ''.freeze
@literal_str_encode_regexp = /\000.*\z/
@literal_str_pad = "\000".freeze
Expand Down Expand Up @@ -99,6 +100,9 @@ def encode_single_message(address, args=[])
when SonicPi::OSC::Blob
tags << @literal_low_b
args_encoded << arg.binary
when SonicPi::OSC::Int64
tags << @literal_low_h
args_encoded << arg.binary
else
raise "Unknown arg type to encode: #{arg.inspect}"
end
Expand Down

0 comments on commit a7612c8

Please sign in to comment.