Class: Music::Performance::ValueComputer
- Inherits:
-
Object
- Object
- Music::Performance::ValueComputer
- Defined in:
- lib/music-performance/util/value_computer.rb
Overview
Given a start value, and value changes, compute the value at any offset.
Instance Attribute Summary collapse
-
#piecewise_function ⇒ Object
readonly
Returns the value of attribute piecewise_function.
Class Method Summary collapse
-
.domain_max ⇒ Object
finds the maximum domain value.
-
.domain_min ⇒ Object
finds the minimum domain value.
Instance Method Summary collapse
-
#domain_max ⇒ Object
finds the maximum domain value.
-
#domain_min ⇒ Object
finds the minimum domain value.
-
#initialize(start_value, value_changes = {}) ⇒ ValueComputer
constructor
A new instance of ValueComputer.
- #sample(xmin, xmax, srate) ⇒ Object
-
#value_at(offset) ⇒ Object
Compute the value at the given offset.
Constructor Details
#initialize(start_value, value_changes = {}) ⇒ ValueComputer
Returns a new instance of ValueComputer.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/music-performance/util/value_computer.rb', line 8 def initialize start_value, value_changes = {} @piecewise_function = PiecewiseFunction.new set_default_value start_value if value_changes.any? value_changes.sort.each do |offset,change| case change when Music::Transcription::Change::Immediate add_immediate_change change, offset when Music::Transcription::Change::Gradual add_linear_change change, offset # add_sigmoid_change change, offset end end end end |
Instance Attribute Details
#piecewise_function ⇒ Object (readonly)
Returns the value of attribute piecewise_function.
6 7 8 |
# File 'lib/music-performance/util/value_computer.rb', line 6 def piecewise_function @piecewise_function end |
Class Method Details
.domain_max ⇒ Object
finds the maximum domain value
56 57 58 |
# File 'lib/music-performance/util/value_computer.rb', line 56 def self.domain_max Float::INFINITY end |
.domain_min ⇒ Object
finds the minimum domain value
51 52 53 |
# File 'lib/music-performance/util/value_computer.rb', line 51 def self.domain_min -Float::INFINITY end |
Instance Method Details
#domain_max ⇒ Object
finds the maximum domain value
46 47 48 |
# File 'lib/music-performance/util/value_computer.rb', line 46 def domain_max Float::INFINITY end |
#domain_min ⇒ Object
finds the minimum domain value
41 42 43 |
# File 'lib/music-performance/util/value_computer.rb', line 41 def domain_min -Float::INFINITY end |
#sample(xmin, xmax, srate) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/music-performance/util/value_computer.rb', line 33 def sample xmin, xmax, srate sample_period = Rational(1,srate) ((xmin.to_r)..(xmax.to_r)).step(sample_period).map do |x| value_at(x) end end |
#value_at(offset) ⇒ Object
Compute the value at the given offset.
29 30 31 |
# File 'lib/music-performance/util/value_computer.rb', line 29 def value_at offset @piecewise_function.eval offset end |