102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/osc-access/translate.rb', line 102
def self.using(value, range, options = {})
to_local = options[:to_local].nil? ? true : options[:to_local]
new_vals = [value].flatten.compact.map do |single_val|
if range == :boolean
to_local ? (single_val <= 0 ? false : true) : (single_val ? 1 : 0)
else
if range.kind_of?(Range) || range.kind_of?(Array)
remote = DefaultRemoteRange
local = range
type = options[:type]
else
remote = range[:remote] || DefaultRemoteRange
local = range[:local]
type = range[:type] || options[:type]
end
analog = to_local ? Analog.new(remote, local) : Analog.new(local, remote)
type = to_local ? type : :float
analog.process(single_val, :type => type)
end
end
value.kind_of?(Array) ? new_vals : new_vals.first
end
|