Class: Oschii::OscMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/oschii/osc_monitor.rb

Constant Summary collapse

COL_WIDTH =
40

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cloud) ⇒ OscMonitor

Returns a new instance of OscMonitor.



5
6
7
8
# File 'lib/oschii/osc_monitor.rb', line 5

def initialize(cloud)
  @cloud = cloud
  @values = {}
end

Instance Attribute Details

#cloudObject (readonly)

Returns the value of attribute cloud.



10
11
12
# File 'lib/oschii/osc_monitor.rb', line 10

def cloud
  @cloud
end

#valuesObject (readonly)

Returns the value of attribute values.



10
11
12
# File 'lib/oschii/osc_monitor.rb', line 10

def values
  @values
end

Instance Method Details

#add(name, max: 100) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/oschii/osc_monitor.rb', line 12

def add(name, max: 100)
  unless values[name.to_sym]
    values[name.to_sym] = {value: nil, max: max}
    cloud.capture_osc name do |value|
      values[name.to_sym][:value] = value
    end
  end

  values[name.to_sym][:max] = max
end

#renderObject



35
36
37
38
39
40
# File 'lib/oschii/osc_monitor.rb', line 35

def render
  print "\r"
  values.each do |k, v|
    print sensor_bar(v)
  end
end

#runObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oschii/osc_monitor.rb', line 23

def run
  puts
  values.each do |k, v|
    print " #{k}".ljust (COL_WIDTH+4)
  end
  puts
  while true
    render
    sleep 0.01
  end
end

#sensor_bar(value) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/oschii/osc_monitor.rb', line 42

def sensor_bar(value)
  result = '['
  norm = [value[:value].to_f / value[:max], 1.0].min * COL_WIDTH
  COL_WIDTH.times do |i|
    if i < norm
      result += ''
    else
      result += ':'
    end
  end
  result += ']  '
end