Class: Synthesizer::ModulationValue

Inherits:
Object
  • Object
show all
Defined in:
lib/synthesizer/modulation_value.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#modsObject (readonly)

Returns the value of attribute mods.



5
6
7
# File 'lib/synthesizer/modulation_value.rb', line 5

def mods
  @mods
end

#valueObject

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

Parameters:

  • mod (Synthesizer::Modulation)
  • depth (Float) (defaults to: 1.0)

    depth. volume => percent(-1.0~1.0, default=1.0), filter freq => relative value(hz), other => relative value



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