Class: Synthesizer::ModulationValue
- Inherits:
-
Object
- Object
- Synthesizer::ModulationValue
- Defined in:
- lib/synthesizer/modulation_value.rb
Instance Attribute Summary collapse
-
#mods ⇒ Object
readonly
Returns the value of attribute mods.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .amp_generator(note_perform, samplecount, *modvals) ⇒ Object
- .balance_generator(note_perform, samplecount, *modvals, center: 0) ⇒ Object
- .create(value) ⇒ Object
Instance Method Summary collapse
- #add(mod, depth: 1.0) ⇒ Object
-
#initialize(value, mods = {}) ⇒ ModulationValue
constructor
A new instance of ModulationValue.
Constructor Details
#initialize(value, mods = {}) ⇒ ModulationValue
Returns a new instance of ModulationValue.
7 8 9 10 11 12 13 14 |
# File 'lib/synthesizer/modulation_value.rb', line 7 def initialize(value, mods={}) @value = value @mods = [] mods.each {|mod, depth| add(mod, depth: depth || 1.0) } end |
Instance Attribute Details
#mods ⇒ Object (readonly)
Returns the value of attribute mods.
5 6 7 |
# File 'lib/synthesizer/modulation_value.rb', line 5 def mods @mods end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/synthesizer/modulation_value.rb', line 4 def value @value end |
Class Method Details
.amp_generator(note_perform, samplecount, *modvals) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/synthesizer/modulation_value.rb', line 38 def self.amp_generator(note_perform, samplecount, *modvals) modvals = modvals.flatten.compact # value value = modvals.map(&:value).sum # mods mods = [] modvals.each {|modval| modval.mods.each {|mod, depth| mods << mod.amp_generator(note_perform, samplecount, depth) } } -> { depth = mods.map(&:[]).inject(1.0, &:*) value * depth } end |
.balance_generator(note_perform, samplecount, *modvals, center: 0) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/synthesizer/modulation_value.rb', line 58 def self.balance_generator(note_perform, samplecount, *modvals, center: 0) modvals = modvals.flatten.compact # value value = modvals.map(&:value).sum value -= (modvals.length - 1) * center # mods mods = [] modvals.each {|modval| modval.mods.each {|mod, depth| mods << mod.balance_generator(note_perform, samplecount, depth) } } -> { depth = mods.map(&:[]).sum value + depth } end |
.create(value) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/synthesizer/modulation_value.rb', line 30 def self.create(value) if ModulationValue===value value else new(value) end end |
Instance Method Details
#add(mod, depth: 1.0) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/synthesizer/modulation_value.rb', line 18 def add(mod, depth: 1.0) depth ||= 1.0 #if depth<-1.0 # depth = -1.0 #elsif 1.0<depth # depth = 1.0 #end @mods << [mod, depth] self end |