Module: OSC

Defined in:
lib/ruby-osc/client.rb,
lib/ruby-osc.rb,
lib/ruby-osc/bundle.rb,
lib/ruby-osc/server.rb,
lib/ruby-osc/message.rb

Overview

From the Funaba osc gem:

Defined Under Namespace

Modules: OSCArgument Classes: Blob, Bundle, Client, DecodeError, Message, Server

Class Method Summary collapse

Class Method Details

.coerce_argument(arg) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ruby-osc.rb', line 27

def self.coerce_argument(arg)
  case arg
  when OSCArgument then arg.to_osc_type
  when Symbol      then arg.to_s
  when String, Float, Integer, Blob, String then arg # Osc 1.0 spec
  else
    raise(TypeError, "#{ arg.inspect } is not a valid Message argument")
  end
end

.decode(str) ⇒ Object

:nodoc:



37
38
39
# File 'lib/ruby-osc.rb', line 37

def self.decode(str) #:nodoc:
  str.match(/^#bundle/) ? Bundle.decode(str) : Message.decode(str)
end

.encoding_directive(obj) ⇒ Object

:nodoc:



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby-osc.rb', line 53

def self.encoding_directive(obj) #:nodoc:
  case obj
  when Float then [obj, "f", "g"]
  when Integer then [obj, "i", "N"]
  when Blob then [[obj.bytesize, obj], "b", "Na*x#{ padding_size obj.bytesize + 4 }"]
  when String then [obj, "s", "Z*x#{ padding_size obj.bytesize + 1 }"]
  when Time
    t1, fr = (obj.to_f + 2_208_988_800).divmod(1)
    t2 = (fr * (2**32)).to_i
    [[t1, t2], "t", "N2"]
  end
end

.padding_size(size) ⇒ Object



41
42
43
# File 'lib/ruby-osc.rb', line 41

def self.padding_size(size)
  (4 - (size) % 4) % 4
end

.runObject



45
46
47
48
49
50
51
# File 'lib/ruby-osc.rb', line 45

def self.run
  EM.run do
    EM.error_handler { |e| puts e }
    EM.set_quantum 5
    yield
  end
end