Module: OSCAccess::Accessible

Defined in:
lib/osc-access/accessible.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/osc-access/accessible.rb', line 6

def self.included(base)
  base.extend(Class)
end

Instance Method Details

#osc_input(*args) ⇒ Object

osc_input takes arguments as such:

osc_input(8000) osc_input(:port => 8000) osc_input(8000, 8005, 8010) osc_input(8000..8010)



59
60
61
62
63
# File 'lib/osc-access/accessible.rb', line 59

def osc_input(*args)
  osc_initialize
  ports = osc_process_ports_args(args)
  ports.each { |port| @osc_receiver.add_server(port) }
end

#osc_join(options = {}) ⇒ Object



35
36
37
38
# File 'lib/osc-access/accessible.rb', line 35

def osc_join(options = {})
  osc_initialize
  @osc_receiver.join(options)
end

#osc_load_map(map) ⇒ Object



86
87
88
89
# File 'lib/osc-access/accessible.rb', line 86

def osc_load_map(map)
  osc_initialize
  map.each { |attr, mapping| osc_add_map_row(attr, mapping) }      
end

#osc_output(pair) ⇒ Object

osc_output takes arguments as such:

osc_output(:host => "localhost", :port => 9000) osc_output(:host => "localhost", :port => [9000, 9002, 9005]) osc_output(:host => "localhost", :port => 9000..9010)



46
47
48
49
50
# File 'lib/osc-access/accessible.rb', line 46

def osc_output(pair)
  osc_initialize
  ports = osc_process_ports_args(pair[:port])
  ports.each { |port| @osc_emitter.add_client(pair[:host], port) }
end

#osc_receive(pattern, options = {}, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/osc-access/accessible.rb', line 10

def osc_receive(pattern, options = {}, &block)
  osc_initialize
  @osc_receiver.add_receiver(self, pattern, options, &block)
  if !options[:accessor].nil?
    @osc_properties << EmittableProperty.new(options[:accessor], pattern, options)
  elsif !options[:initialize].nil?
    @osc_properties << EmittableProperty.new(options[:initialize], pattern, options)
  end
end

#osc_send(*a) ⇒ Object



30
31
32
33
# File 'lib/osc-access/accessible.rb', line 30

def osc_send(*a)
  osc_initialize
  a.first.kind_of?(Symbol) ? osc_send_property(a.first) : @osc_emitter.transmit(*a)      
end

#osc_send_all_properties ⇒ Object



81
82
83
84
# File 'lib/osc-access/accessible.rb', line 81

def osc_send_all_properties
  osc_initialize
  @osc_properties.each { |prop| osc_send_property(prop) }
end

#osc_send_property(prop) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/osc-access/accessible.rb', line 20

def osc_send_property(prop)
  prop = @osc_properties.find { |ep| ep.subject == prop } if prop.kind_of?(Symbol)
  val = prop.translated(self)
  msg = OSC::Message.new(prop.pattern, *val)
  @osc_emitter.transmit(msg)
  local_msg = OSC::Message.new(prop.pattern, *prop.value(self))
  local_val = osc_process_arg_option(local_msg, :arg => prop.arg)
  prop.action.call(self, local_val, local_msg) unless prop.action.nil?
end

#osc_start(options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/osc-access/accessible.rb', line 65

def osc_start(options = {})
  osc_initialize(options)
  osc_initialize_from_class_def
  osc_load_map(options[:map]) unless options[:map].nil?
  
  osc_input(options[:input_port]) unless options[:input_port].nil?
  osc_output(options[:output]) unless options[:output].nil?
  
  Thread.new do 
    sleep(1) 
    osc_send_all_properties
  end
  
  @osc_receiver.threads.first || Thread.new { Thread.abort_on_exception = true; loop {} }
end

#osc_translate(value, range, options = {}) ⇒ Object



91
92
93
# File 'lib/osc-access/accessible.rb', line 91

def osc_translate(value, range, options = {})
  Translate.using(value, range, options)
end