Class: Synthesizer::PolySynth

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oscillators:, filter: nil, amplifier:, quality: Quality::LOW, soundinfo:) ⇒ PolySynth

Returns a new instance of PolySynth.

Parameters:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/synthesizer/poly_synth.rb', line 20

def initialize(oscillators:, filter: nil, amplifier:, quality: Quality::LOW, soundinfo:)
  @oscillators = [oscillators].flatten.compact
  @filter = filter
  @amplifier = amplifier

  @quality = quality
  @soundinfo = soundinfo

  @processor = Processor.create(quality)
  @performs = {}
  @pitch_bend = 0.0
end

Instance Attribute Details

#amplifierObject (readonly)

Returns the value of attribute amplifier.



6
7
8
# File 'lib/synthesizer/poly_synth.rb', line 6

def amplifier
  @amplifier
end

#filterObject (readonly)

Returns the value of attribute filter.



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

def filter
  @filter
end

#glideObject (readonly)

Returns the value of attribute glide.



12
13
14
# File 'lib/synthesizer/poly_synth.rb', line 12

def glide
  @glide
end

#oscillatorsObject (readonly)

Returns the value of attribute oscillators.



4
5
6
# File 'lib/synthesizer/poly_synth.rb', line 4

def oscillators
  @oscillators
end

#pitch_bendObject

Returns the value of attribute pitch_bend.



13
14
15
# File 'lib/synthesizer/poly_synth.rb', line 13

def pitch_bend
  @pitch_bend
end

#processorObject (readonly)

Returns the value of attribute processor.



7
8
9
# File 'lib/synthesizer/poly_synth.rb', line 7

def processor
  @processor
end

#qualityObject (readonly)

Returns the value of attribute quality.



9
10
11
# File 'lib/synthesizer/poly_synth.rb', line 9

def quality
  @quality
end

#soundinfoObject (readonly)

Returns the value of attribute soundinfo.



10
11
12
# File 'lib/synthesizer/poly_synth.rb', line 10

def soundinfo
  @soundinfo
end

Instance Method Details

#nextObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/synthesizer/poly_synth.rb', line 33

def next
  buf = nil
  if 0<@performs.length
    bufs = @performs.values.map(&:next).compact

    # delete released note performs
    @performs.delete_if {|note_num, perform| perform.released? }

    if 0<bufs.length
      buf = AudioStream::Buffer.merge(bufs)
    end
  end
  buf || AudioStream::Buffer.create(@soundinfo.window_size, @soundinfo.channels)
end

#note_off(note) ⇒ Object

Parameters:



63
64
65
66
67
68
69
# File 'lib/synthesizer/poly_synth.rb', line 63

def note_off(note)
  # Note Off
  perform = @performs[note.num]
  if perform
    perform.note_off!
  end
end

#note_on(note, velocity: 1.0) ⇒ Object

Parameters:

  • note (Synthesizer::Note)
  • velocity (Float) (defaults to: 1.0)

    volume percent (0.0~1.0)



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/synthesizer/poly_synth.rb', line 50

def note_on(note, velocity: 1.0)
  # Note Off
  perform = @performs[note.num]
  if perform
    perform.note_off!
  end

  # Note On
  perform = NotePerform.new(self, note, velocity)
  @performs[note.num] = perform
end