Class: OSC::OSCPacket
- Inherits:
-
Object
- Object
- OSC::OSCPacket
- Defined in:
- lib/osc-ruby/osc_packet.rb
Class Method Summary collapse
- .decode_simple_message(time, osc_packet) ⇒ Object
- .messages_from_network(string, ip_info = nil) ⇒ Object
Instance Method Summary collapse
- #bundle? ⇒ Boolean
- #get_arguments ⇒ Object
- #get_blob ⇒ Object
- #get_bundle_messages ⇒ Object
- #get_double64 ⇒ Object
- #get_float32 ⇒ Object
- #get_int32 ⇒ Object
- #get_string ⇒ Object
- #get_timestamp ⇒ Object
-
#initialize(string) ⇒ OSCPacket
constructor
A new instance of OSCPacket.
- #string_delemeter ⇒ Object
Constructor Details
#initialize(string) ⇒ OSCPacket
Returns a new instance of OSCPacket.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/osc-ruby/osc_packet.rb', line 46 def initialize(string) @packet = NetworkPacket.new(string) @types = { "i" => lambda{OSCInt32.new(get_int32)}, "f" => lambda{ OSCFloat32.new(get_float32)}, "d" => lambda{ OSCDouble64.new(get_double64)}, "s" => lambda{ OSCString.new(get_string)}, "b" => lambda{ OSCBlob.new(get_blob)} } end |
Class Method Details
.decode_simple_message(time, osc_packet) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/osc-ruby/osc_packet.rb', line 39 def self.(time, osc_packet) address = osc_packet.get_string args = osc_packet.get_arguments Message.new_with_time(address, time, nil, *args) end |
.messages_from_network(string, ip_info = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/osc-ruby/osc_packet.rb', line 8 def self.(string, ip_info=nil) = [] osc = new(string) if osc.bundle? osc.get_string time = osc. osc..each do || msg = (time, OSCPacket.new()) if ip_info # Append info for the ip address msg.ip_port = ip_info.shift msg.ip_address = ip_info.join(".") end << msg end else msg = (time, osc) if ip_info # Append info for the ip address msg.ip_port = ip_info.shift msg.ip_address = ip_info.join(".") end << msg end return end |
Instance Method Details
#bundle? ⇒ Boolean
132 133 134 |
# File 'lib/osc-ruby/osc_packet.rb', line 132 def bundle? !(@packet.to_s =~ /\A\#bundle/).nil? end |
#get_arguments ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/osc-ruby/osc_packet.rb', line 92 def get_arguments if (@packet.getc == ?,) = get_string args = [] .scan(/./) do |tag| type_handler = @types[tag] raise(UnknownType, "Unknown OSC type: #{tag}") unless type_handler args << type_handler.call end args end end |
#get_blob ⇒ Object
125 126 127 128 129 130 |
# File 'lib/osc-ruby/osc_packet.rb', line 125 def get_blob l = @packet.getn(4).unpack('N')[0] b = @packet.getn(l) @packet.skip_padding b end |
#get_bundle_messages ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/osc-ruby/osc_packet.rb', line 58 def = [] until @packet.eof? l = @packet.getn(4).unpack('N')[0] << @packet.getn(l) end end |
#get_double64 ⇒ Object
119 120 121 122 123 |
# File 'lib/osc-ruby/osc_packet.rb', line 119 def get_double64 f = @packet.getn(8).unpack('G')[0] @packet.skip_padding f end |
#get_float32 ⇒ Object
113 114 115 116 117 |
# File 'lib/osc-ruby/osc_packet.rb', line 113 def get_float32 f = @packet.getn(4).unpack('g')[0] @packet.skip_padding f end |
#get_int32 ⇒ Object
106 107 108 109 110 111 |
# File 'lib/osc-ruby/osc_packet.rb', line 106 def get_int32 i = @packet.getn(4).unpack('N')[0] i -= 2**32 if i > (2**31-1) @packet.skip_padding i end |
#get_string ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/osc-ruby/osc_packet.rb', line 68 def get_string result = '' until ((c = @packet.getc) == string_delemeter) result << c end @packet.skip_padding result end |
#get_timestamp ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/osc-ruby/osc_packet.rb', line 77 def #TODO: refactor this so a mortal can figure it out t1 = @packet.getn(4).unpack('N')[0] t2 = @packet.getn(4).unpack('N')[0] @packet.skip_padding if t1 == 0 && t2 == 1 time = nil else time = t1 + t2.to_f / (2**32) end time end |
#string_delemeter ⇒ Object
136 137 138 |
# File 'lib/osc-ruby/osc_packet.rb', line 136 def string_delemeter "\x00" end |