Class: Synthesizer::MonoSynth
- Inherits:
-
Object
- Object
- Synthesizer::MonoSynth
- Defined in:
- lib/synthesizer/mono_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:, glide: AudioStream::Rate.sec(0.1), quality: Quality::LOW, soundinfo:) ⇒ MonoSynth
constructor
A new instance of MonoSynth.
- #next ⇒ Object
- #note_off(note) ⇒ Object
- #note_on(note, velocity: 1.0) ⇒ Object
Constructor Details
#initialize(oscillators:, filter: nil, amplifier:, glide: AudioStream::Rate.sec(0.1), quality: Quality::LOW, soundinfo:) ⇒ MonoSynth
Returns a new instance of MonoSynth.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/synthesizer/mono_synth.rb', line 21 def initialize(oscillators:, filter: nil, amplifier:, glide: AudioStream::Rate.sec(0.1), quality: Quality::LOW, soundinfo:) @oscillators = [oscillators].flatten.compact @filter = filter @amplifier = amplifier @quality = quality @soundinfo = soundinfo @processor = Processor.create(quality) @note_nums = [] @perform = nil @glide = Modulation::Glide.new(time: glide) @pitch_bend = 0.0 end |
Instance Attribute Details
#amplifier ⇒ Object (readonly)
Returns the value of attribute amplifier.
6 7 8 |
# File 'lib/synthesizer/mono_synth.rb', line 6 def amplifier @amplifier end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
5 6 7 |
# File 'lib/synthesizer/mono_synth.rb', line 5 def filter @filter end |
#glide ⇒ Object (readonly)
Returns the value of attribute glide.
12 13 14 |
# File 'lib/synthesizer/mono_synth.rb', line 12 def glide @glide end |
#oscillators ⇒ Object (readonly)
Returns the value of attribute oscillators.
4 5 6 |
# File 'lib/synthesizer/mono_synth.rb', line 4 def oscillators @oscillators end |
#pitch_bend ⇒ Object
Returns the value of attribute pitch_bend.
13 14 15 |
# File 'lib/synthesizer/mono_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/mono_synth.rb', line 7 def processor @processor end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
9 10 11 |
# File 'lib/synthesizer/mono_synth.rb', line 9 def quality @quality end |
#soundinfo ⇒ Object (readonly)
Returns the value of attribute soundinfo.
10 11 12 |
# File 'lib/synthesizer/mono_synth.rb', line 10 def soundinfo @soundinfo end |
Instance Method Details
#next ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/synthesizer/mono_synth.rb', line 36 def next buf = nil if @perform buf = @perform.next # delete released note perform if @perform.released? @perform = nil end end buf || AudioStream::Buffer.create(@soundinfo.window_size, @soundinfo.channels) end |
#note_off(note) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/synthesizer/mono_synth.rb', line 67 def note_off(note) # Note Off @note_nums.delete_if {|note_num| note_num==note.num} if @perform if @note_nums.length==0 # Note Off @perform.note_off! else # Glide @glide.target = @note_nums.last end end end |
#note_on(note, velocity: 1.0) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/synthesizer/mono_synth.rb', line 51 def note_on(note, velocity: 1.0) # Note Off note_off(note) if @perform && @perform.note_on? # Glide @glide.target = note.num else # Note On @perform = NotePerform.new(self, note, velocity) @glide.base = note.num end @note_nums << note.num end |