class Musicality::ValueComputer

Given a start value, and value changes, compute the value at any offset.

Attributes

piecewise_function[R]

Public Class Methods

new(start_value, value_changes = {}) click to toggle source
Calls superclass method Musicality::Function::Piecewise::new
# File lib/musicality/notation/util/value_computer.rb, line 6
def initialize start_value, value_changes = {}
  super()
  set_default_value(start_value)
  if value_changes.any?
    value_changes.sort.each do |offset,change|
      add_change(offset, change)
    end
  end
end

Private Instance Methods

add_change(offset, change) click to toggle source
# File lib/musicality/notation/util/value_computer.rb, line 18
def add_change offset, change
  start_value = at(offset)
  trans = change.to_transition(offset, start_value)
  add_piece(offset..Function::DOMAIN_MAX, trans)
end
set_default_value(value) click to toggle source
# File lib/musicality/notation/util/value_computer.rb, line 24
def set_default_value value
  func = Function::Constant.new(value)
  add_piece(Function::DOMAIN_MIN..Function::DOMAIN_MAX, func)
end