Class: Webmidi::Middleware::VelocityScale

Inherits:
Base
  • Object
show all
Defined in:
lib/webmidi/middleware/velocity_scale.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, factor: 1.0, min: 0, max: 127, curve: :linear, **options) ⇒ VelocityScale

Returns a new instance of VelocityScale.



6
7
8
9
10
11
12
13
14
# File 'lib/webmidi/middleware/velocity_scale.rb', line 6

def initialize(app, factor: 1.0, min: 0, max: 127, curve: :linear, **options)
  super(app, **options)
  validate_options!(factor, min, max, curve)
  @factor = factor
  @min = min
  @max = max
  @curve = curve
  @include_note_off = options.fetch(:include_note_off, true)
end

Instance Method Details

#call(message) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/webmidi/middleware/velocity_scale.rb', line 16

def call(message)
  if velocity_message?(message)
    scaled = apply_curve(message.velocity)
    scaled_msg = message.with(velocity: scaled)
    @app.call(scaled_msg)
  else
    @app.call(message)
  end
end