Class: Sidtool::Synth

Inherits:
Object
  • Object
show all
Defined in:
lib/sidtool/synth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute attack to.



4
5
6
# File 'lib/sidtool/synth.rb', line 4

def attack=(value)
  @attack = value
end

#decay=(value) ⇒ Object (writeonly)

Sets the attribute decay

Parameters:

  • value

    the value to set the attribute decay to.



5
6
7
# File 'lib/sidtool/synth.rb', line 5

def decay=(value)
  @decay = value
end

#release=(value) ⇒ Object (writeonly)

Sets the attribute release

Parameters:

  • value

    the value to set the attribute release to.



6
7
8
# File 'lib/sidtool/synth.rb', line 6

def release=(value)
  @release = value
end

#waveform=(value) ⇒ Object (writeonly)

Sets the attribute waveform

Parameters:

  • value

    the value to set the attribute waveform to.



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_aObject



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