Class: Synthesizer::PolySynth
- Inherits:
-
Object
- Object
- Synthesizer::PolySynth
- Defined in:
- lib/synthesizer/poly_synth.rb
Instance Attribute Summary collapse
-
#amplifier ⇒ Object
readonly
Returns the value of attribute amplifier.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#glide ⇒ Object
readonly
Returns the value of attribute glide.
-
#oscillators ⇒ Object
readonly
Returns the value of attribute oscillators.
-
#pitch_bend ⇒ Object
Returns the value of attribute pitch_bend.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#soundinfo ⇒ Object
readonly
Returns the value of attribute soundinfo.
Instance Method Summary collapse
-
#initialize(oscillators:, filter: nil, amplifier:, quality: Quality::LOW, soundinfo:) ⇒ PolySynth
constructor
A new instance of PolySynth.
- #next ⇒ Object
- #note_off(note) ⇒ Object
- #note_on(note, velocity: 1.0) ⇒ Object
Constructor Details
#initialize(oscillators:, filter: nil, amplifier:, quality: Quality::LOW, soundinfo:) ⇒ PolySynth
Returns a new instance of PolySynth.
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
#amplifier ⇒ Object (readonly)
Returns the value of attribute amplifier.
6 7 8 |
# File 'lib/synthesizer/poly_synth.rb', line 6 def amplifier @amplifier end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
5 6 7 |
# File 'lib/synthesizer/poly_synth.rb', line 5 def filter @filter end |
#glide ⇒ Object (readonly)
Returns the value of attribute glide.
12 13 14 |
# File 'lib/synthesizer/poly_synth.rb', line 12 def glide @glide end |
#oscillators ⇒ Object (readonly)
Returns the value of attribute oscillators.
4 5 6 |
# File 'lib/synthesizer/poly_synth.rb', line 4 def oscillators @oscillators end |
#pitch_bend ⇒ Object
Returns the value of attribute pitch_bend.
13 14 15 |
# File 'lib/synthesizer/poly_synth.rb', line 13 def pitch_bend @pitch_bend end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
7 8 9 |
# File 'lib/synthesizer/poly_synth.rb', line 7 def processor @processor end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
9 10 11 |
# File 'lib/synthesizer/poly_synth.rb', line 9 def quality @quality end |
#soundinfo ⇒ Object (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
#next ⇒ Object
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
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
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 |