Class: Sidtool::Synth
- Inherits:
-
Object
- Object
- Sidtool::Synth
- Defined in:
- lib/sidtool/synth.rb
Instance Attribute Summary collapse
-
#attack ⇒ Object
Returns the value of attribute attack.
-
#controls ⇒ Object
readonly
Returns the value of attribute controls.
-
#decay ⇒ Object
Returns the value of attribute decay.
-
#release ⇒ Object
Returns the value of attribute release.
-
#start_frame ⇒ Object
readonly
Returns the value of attribute start_frame.
-
#sustain_length ⇒ Object
readonly
Returns the value of attribute sustain_length.
-
#waveform ⇒ Object
Returns the value of attribute waveform.
Instance Method Summary collapse
- #frequency=(frequency) ⇒ Object
-
#initialize(start_frame) ⇒ Synth
constructor
A new instance of Synth.
- #release! ⇒ Object
- #released? ⇒ Boolean
- #stop! ⇒ Object
- #to_a ⇒ Object
- #tone ⇒ Object
Constructor Details
#initialize(start_frame) ⇒ Synth
Returns a new instance of Synth.
11 12 13 14 |
# File 'lib/sidtool/synth.rb', line 11 def initialize(start_frame) @start_frame = start_frame @controls = [] end |
Instance Attribute Details
#attack ⇒ Object
Returns the value of attribute attack.
5 6 7 |
# File 'lib/sidtool/synth.rb', line 5 def attack @attack end |
#controls ⇒ Object (readonly)
Returns the value of attribute controls.
9 10 11 |
# File 'lib/sidtool/synth.rb', line 9 def controls @controls end |
#decay ⇒ Object
Returns the value of attribute decay.
6 7 8 |
# File 'lib/sidtool/synth.rb', line 6 def decay @decay end |
#release ⇒ Object
Returns the value of attribute release.
8 9 10 |
# File 'lib/sidtool/synth.rb', line 8 def release @release end |
#start_frame ⇒ Object (readonly)
Returns the value of attribute start_frame.
3 4 5 |
# File 'lib/sidtool/synth.rb', line 3 def start_frame @start_frame end |
#sustain_length ⇒ Object (readonly)
Returns the value of attribute sustain_length.
7 8 9 |
# File 'lib/sidtool/synth.rb', line 7 def sustain_length @sustain_length end |
#waveform ⇒ Object
Returns the value of attribute waveform.
4 5 6 |
# File 'lib/sidtool/synth.rb', line 4 def waveform @waveform end |
Instance Method Details
#frequency=(frequency) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/sidtool/synth.rb', line 16 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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sidtool/synth.rb', line 24 def release! return if released? @released_at = STATE.current_frame 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 |
#released? ⇒ Boolean
40 41 42 |
# File 'lib/sidtool/synth.rb', line 40 def released? !!@released_at end |
#stop! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/sidtool/synth.rb', line 44 def stop! if released? @release = [@release, (STATE.current_frame - @released_at) / FRAMES_PER_SECOND].min else @release = 0 release! end end |
#to_a ⇒ Object
53 54 55 |
# File 'lib/sidtool/synth.rb', line 53 def to_a [@start_frame, tone, @waveform, @attack.round(3), @decay.round(3), @sustain_length.round(3), @release.round(3), @controls] end |
#tone ⇒ Object
57 58 59 |
# File 'lib/sidtool/synth.rb', line 57 def tone sid_frequency_to_nearest_midi(@frequency) end |