Class: MIDIMessage::Process::Filter

Inherits:
Object
  • Object
show all
Includes:
Processor
Defined in:
lib/midi-message/process/filter.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Processor

included, #process

Constructor Details

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

Returns a new instance of Filter.



14
15
16
17
18
19
20
# File 'lib/midi-message/process/filter.rb', line 14

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

  initialize_processor(options)
end

Instance Attribute Details

#bandwidthObject (readonly)

Returns the value of attribute bandwidth.



12
13
14
# File 'lib/midi-message/process/filter.rb', line 12

def bandwidth
  @bandwidth
end

#propertyObject (readonly)

Returns the value of attribute property.



12
13
14
# File 'lib/midi-message/process/filter.rb', line 12

def property
  @property
end

#rejectObject (readonly)

Returns the value of attribute reject.



12
13
14
# File 'lib/midi-message/process/filter.rb', line 12

def reject
  @reject
end

Instance Method Details

#process_single(message) ⇒ Object



22
23
24
25
26
# File 'lib/midi-message/process/filter.rb', line 22

def process_single(message)
  val = message.send(@property)
  result = @bandwidth.map { |bw| val >= bw.min && val <= bw.max ? message : nil }
  result.include?(message) ^ @reject ? message : nil
end