Class: OSCAccess::Analog::Output::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/osc-access/translate.rb

Instance Method Summary collapse

Constructor Details

#initialize(from, to_range, options = {}) ⇒ Range

Returns a new instance of Range.



60
61
62
63
64
65
# File 'lib/osc-access/translate.rb', line 60

def initialize(from, to_range, options = {})
  @type = options[:type]

  @from = from
  @to_range = to_range
end

Instance Method Details

#process(input, options = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/osc-access/translate.rb', line 67

def process(input, options = {})
  to_range_len = (@to_range.last - @to_range.first).abs
  
  proportion = to_range_len.to_f / @from.denominator
  abs_output = proportion.to_f * @from.numerator(input)
  output = abs_output + @to_range.first

  type = options[:type] || @type
  float_requested = !type.nil? && type.to_s.downcase == "float"
  float_requested ? output : output.to_i
end