Class: Sidtool::Synth
- Inherits:
-
Object
- Object
- Sidtool::Synth
- Defined in:
- lib/sidtool/synth.rb
Instance Attribute Summary collapse
-
#attack ⇒ Object
writeonly
Sets the attribute attack.
-
#decay ⇒ Object
writeonly
Sets the attribute decay.
-
#release ⇒ Object
writeonly
Sets the attribute release.
-
#waveform ⇒ Object
writeonly
Sets the attribute waveform.
Instance Method Summary collapse
- #frequency=(frequency) ⇒ Object
-
#initialize(start_frame) ⇒ Synth
constructor
A new instance of Synth.
- #release! ⇒ Object
- #stop! ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(start_frame) ⇒ Synth
Returns a new instance of Synth.
8 9 10 11 |
# File 'lib/sidtool/synth.rb', line 8 def initialize(start_frame) @start_frame = start_frame @controls = [] end |
Instance Attribute Details
#attack=(value) ⇒ Object (writeonly)
Sets the attribute attack
4 5 6 |
# File 'lib/sidtool/synth.rb', line 4 def attack=(value) @attack = value end |
#decay=(value) ⇒ Object (writeonly)
Sets the attribute decay
5 6 7 |
# File 'lib/sidtool/synth.rb', line 5 def decay=(value) @decay = value end |
#release=(value) ⇒ Object (writeonly)
Sets the attribute release
6 7 8 |
# File 'lib/sidtool/synth.rb', line 6 def release=(value) @release = value end |
#waveform=(value) ⇒ Object (writeonly)
Sets the attribute waveform
3 4 5 |
# File 'lib/sidtool/synth.rb', line 3 def waveform=(value) @waveform = value end |
Instance Method Details
#frequency=(frequency) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/sidtool/synth.rb', line 13 def frequency=(frequency) if @frequency previous_midi, current_midi = sid_frequency_to_nearest_midi(@frequency), sid_frequency_to_nearest_midi(frequency) @controls << [STATE.current_frame, current_midi] if previous_midi != current_midi end @frequency = frequency end |
#release! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sidtool/synth.rb', line 21 def release! length_of_attack_decay_sustain = (STATE.current_frame - @start_frame) / FRAMES_PER_SECOND if length_of_attack_decay_sustain < @attack @attack = length_of_attack_decay_sustain @decay, @sustain_length = 0, 0 elsif length_of_attack_decay_sustain < @attack + @decay @decay = length_of_attack_decay_sustain - @attack @sustain_length = 0 else @sustain_length = length_of_attack_decay_sustain - @attack - @decay end end |
#stop! ⇒ Object
34 35 36 37 |
# File 'lib/sidtool/synth.rb', line 34 def stop! # TODO: Should also cut off any remaining release release! end |
#to_a ⇒ Object
39 40 41 42 |
# File 'lib/sidtool/synth.rb', line 39 def to_a tone = sid_frequency_to_nearest_midi(@frequency) [@start_frame, tone, @waveform, @attack.round(3), @decay.round(3), @sustain_length, @release.round(3), @controls] end |