Class: MicroOSC::State

Inherits:
Object
  • Object
show all
Defined in:
lib/micro-osc/state.rb

Constant Summary collapse

Default =
{
  :channel => 0,
  :octave => 2,
  :velocity => 100
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ State

Returns a new instance of State.



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

def initialize(options = {})
  @auto_output = true
  @last_command = nil    
  @super_sticky = false

  @channel = options[:channel] || Default[:channel]
  @velocity = options[:velocity] || Default[:velocity]
  @octave = options[:octave] || Default[:octave]  
  
end

Instance Attribute Details

#auto_outputObject

Returns the value of attribute auto_output.



13
14
15
# File 'lib/micro-osc/state.rb', line 13

def auto_output
  @auto_output
end

#last_commandObject (readonly)

Returns the value of attribute last_command.



17
18
19
# File 'lib/micro-osc/state.rb', line 17

def last_command
  @last_command
end

#output_cacheObject (readonly)

Returns the value of attribute output_cache.



17
18
19
# File 'lib/micro-osc/state.rb', line 17

def output_cache
  @output_cache
end

#patternObject

Returns the value of attribute pattern.



13
14
15
# File 'lib/micro-osc/state.rb', line 13

def pattern
  @pattern
end

#super_stickyObject

Returns the value of attribute super_sticky.



13
14
15
# File 'lib/micro-osc/state.rb', line 13

def super_sticky
  @super_sticky
end

Instance Method Details

#message_properties(opts, *props) ⇒ Object



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

def message_properties(opts, *props)
  output = {}
  props.each do |prop|
    output[prop] = opts[prop]
    self.send("#{prop.to_s}=", output[prop]) if !output[prop].nil? && (self.send(prop).nil? || @super_sticky)
    output[prop] ||= self.send(prop.to_s)
  end
  output
end

#record(m, a, b, outp) ⇒ Object



31
32
33
34
35
# File 'lib/micro-osc/state.rb', line 31

def record(m, a, b, outp)
  ts = now
  @output_cache << { :message => outp, :timestamp => ts }
  @last_command = { :method => m, :args => a, :block => b, :timestamp => ts }
end

#toggle_auto_outputObject



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

def toggle_auto_output
  @auto_output = !@auto_output
end

#toggle_super_stickyObject



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

def toggle_super_sticky
  @super_sticky = !@super_sticky
end