Class: MIDIFX::Limit

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-fx/limit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, limit_to, options = {}) ⇒ Limit



8
9
10
11
12
# File 'lib/midi-fx/limit.rb', line 8

def initialize(property, limit_to, options = {})
  @limit_to = limit_to
  @property = property
  @name = options[:name]
end

Instance Attribute Details

#limit_toObject (readonly) Also known as: range

Returns the value of attribute limit_to.



5
6
7
# File 'lib/midi-fx/limit.rb', line 5

def limit_to
  @limit_to
end

#propertyObject (readonly)

Returns the value of attribute property.



5
6
7
# File 'lib/midi-fx/limit.rb', line 5

def property
  @property
end

Instance Method Details

#process(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/midi-fx/limit.rb', line 14

def process(message)
  val = message.send(@property)
  if @limit_to.kind_of?(Range)
    message.send("#{@property}=", @limit_to.min) if val < @limit_to.min
    message.send("#{@property}=", @limit_to.max) if val > @limit_to.max
  elsif @limit_to.kind_of?(Numeric)
    message.send("#{@property}=", @limit_to)
  end
  message
end