class EasyAudioSequencer::Sound

Attributes

frame[RW]
freq[RW]
step[RW]

Public Class Methods

new(freq: 1, &block) click to toggle source
# File lib/easy_audio_sequencer/sound.rb, line 4
def initialize(freq: 1, &block)
  @freq = freq
  @fn = block
  @frame = 0
  @step = 0
end

Public Instance Methods

calculate_step() click to toggle source
# File lib/easy_audio_sequencer/sound.rb, line 19
def calculate_step
  @step = (step * @freq.to_f) % 1.0
end
e(fn = nil, &block) click to toggle source
# File lib/easy_audio_sequencer/sound.rb, line 23
def e(fn = nil, &block)
  instance_exec(&(fn || block))
end
f(fn = nil, note, &block) click to toggle source
# File lib/easy_audio_sequencer/sound.rb, line 27
def f(fn = nil, note, &block)
  orig_freq, orig_step = @freq, @step
  @freq = freq_for_note(note)
  calculate_step
  result = e(fn || block)
  @freq = orig_freq
  @step = orig_step
  result
end
fr(fn = nil, freq, &block) click to toggle source
# File lib/easy_audio_sequencer/sound.rb, line 37
def fr(fn = nil, freq, &block)
  orig_freq, orig_step = @freq, @step
  @freq = freq
  calculate_step
  result = e(fn || block)
  @freq = orig_freq
  @step = orig_step
  result
end
next_frame(frame, step) click to toggle source
# File lib/easy_audio_sequencer/sound.rb, line 13
def next_frame(frame, step)
  @frame, @step = frame, step
  calculate_step
  instance_exec(&@fn)
end