Class: MicroOSC::Context

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
OSCAccessible
Defined in:
lib/micro-osc/context.rb,
lib/micro-osc/shorthand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Context

Returns a new instance of Context.



19
20
21
22
23
# File 'lib/micro-osc/context.rb', line 19

def initialize(options = {}, &block)
  @state = State.new
  osc_start(options.merge({}))
  edit(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



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

def method_missing(m, *a, &b)
  outp = nil
  options = a.last.kind_of?(Hash) ? a.last : {}
  do_output = options[:output] || true
  outp = super
  @state.record(m, a, b, outp)
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



12
13
14
# File 'lib/micro-osc/context.rb', line 12

def state
  @state
end

Instance Method Details

#edit(&block) ⇒ Object

open a block for editing/live coding in this Context



26
27
28
# File 'lib/micro-osc/context.rb', line 26

def edit(&block)
  self.instance_eval(&block)
end

#input_portsObject

shortcut to an array of port numbers



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

def input_ports
  @osc_receiver.servers.keys
end

#join(options = {}) ⇒ Object Also known as: wait_for_input



53
54
55
# File 'lib/micro-osc/context.rb', line 53

def join(options = {})
  osc_join(options)
end

#repeatObject Also known as: r

repeat the last command



36
37
38
# File 'lib/micro-osc/context.rb', line 36

def repeat
  self.send(@state.last_command[:method], *@state.last_command[:args]) unless @state.last_command.nil?
end