Class: Synthesizer::Modulation::Glide

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

Instance Method Summary collapse

Constructor Details

#initialize(time:) ⇒ Glide

Returns a new instance of Glide.

Parameters:

  • time (AudioStream::Rate | Float)

    glide time sec (0.0~)



6
7
8
9
10
11
12
13
# File 'lib/synthesizer/modulation/glide.rb', line 6

def initialize(time:)
  @time = AudioStream::Rate.sec(time)

  @base = 0.0
  @current = 0.0
  @target = 0.0
  @diff = 0.0
end

Instance Method Details

#balance_generator(note_perform, samplecount, depth) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/synthesizer/modulation/glide.rb', line 64

def balance_generator(note_perform, samplecount, depth)
  gen = generator(note_perform, samplecount)

  -> {
    gen[] * depth
  }
end

#base=(base) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/synthesizer/modulation/glide.rb', line 15

def base=(base)
  base = base.to_f

  @base = base
  @current = base
  @target = base
  @diff = 0.0
end

#generator(note_perform, samplecount) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/synthesizer/modulation/glide.rb', line 29

def generator(note_perform, samplecount)
  soundinfo = note_perform.synth.soundinfo
  rate = @time.sample(soundinfo) / samplecount

  -> {
    ret = nil

    if !note_perform.released?
      # Note On
      if 0<rate && @target!=@current
        # Gliding
        x = @diff / rate
        if x.abs<(@target-@current).abs
          @current += x
        else
          @current = @target
        end

        ret = @current - @base
      else
        # Stay
        ret = @target - @base
      end
    else
      # Note Off
      @current = 0.0
      @target = 0.0
      @diff = 0.0
      ret = 0.0
    end

    ret
  }
end

#target=(target) ⇒ Object



24
25
26
27
# File 'lib/synthesizer/modulation/glide.rb', line 24

def target=(target)
  @target = target
  @diff = target - @current
end

#to_modvalObject



72
73
74
# File 'lib/synthesizer/modulation/glide.rb', line 72

def to_modval
  @modval ||= ModulationValue.create(0).add(self)
end