class SMF::VelComp

Public Class Methods

new() click to toggle source
# File lib/smf/toy/velcomp.rb, line 10
def initialize
  self.gain = 0
  self.thresh = 80
  self.ratio = 0.9
end

Public Instance Methods

gain=(v) click to toggle source
# File lib/smf/toy/velcomp.rb, line 25
def gain=(v) @gain = v end
ratio=(v) click to toggle source
# File lib/smf/toy/velcomp.rb, line 27
def ratio=(v) @ratio = v; @spline = nil end
thresh=(v) click to toggle source
# File lib/smf/toy/velcomp.rb, line 26
def thresh=(v) @thresh = v; @spline = nil end
velcomp(ev) click to toggle source
# File lib/smf/toy/velcomp.rb, line 29
def velcomp(ev)
  init unless @spline
  v = ev.vel + @gain
  v = 127 if v > 127
  v = 1   if v < 1
  v2 = @spline.eval(v)
  v2 = 127 if v > 127
  v2 = 1   if v < 1
  ev.vel = v2.round
end

Private Instance Methods

init() click to toggle source
# File lib/smf/toy/velcomp.rb, line 16
def init
  max = @thresh + (127 - @thresh) * @ratio
  x = GSL::Vector.alloc(0, @thresh, 127)
  y = GSL::Vector.alloc(0, @thresh, max)
  @spline = GSL::Spline.alloc('linear', x, y)
end