Class: MIDIFX::Filter

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

Overview

Use the Filter superclass when you need a multi-band filter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, bandwidth, options = {}) ⇒ Filter

Returns a new instance of Filter.



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

def initialize(property, bandwidth, options = {})
  @bandwidth = [bandwidth].flatten
  @property = property
  @reject = options[:reject] || false
  @name = options[:name]
end

Instance Attribute Details

#bandwidthObject (readonly)

Returns the value of attribute bandwidth.



6
7
8
# File 'lib/midi-fx/filter.rb', line 6

def bandwidth
  @bandwidth
end

#propertyObject (readonly)

Returns the value of attribute property.



6
7
8
# File 'lib/midi-fx/filter.rb', line 6

def property
  @property
end

#rejectObject (readonly)

Returns the value of attribute reject.



6
7
8
# File 'lib/midi-fx/filter.rb', line 6

def reject
  @reject
end

Instance Method Details

#process(message) ⇒ Object



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

def process(message)
  val = message.send(@property)
  result = @bandwidth.map do |bw| 
    case bw
    when Range then val >= bw.min && val <= bw.max ? message : nil
    when Numeric then val == bw ? message : nil
    end
  end
  result.include?(message) ^ @reject ? message : nil
end