class InevitableCacophony::Rhythm::Beat
Amplitude – how loud the beat is, on a scale from silent to MAX VOLUME. Duration – how long it is, in arbitrary beat units (think metronome ticks) Timing – how early or late the beat is, relative to the same metaphorical metronome.
Public Instance Methods
How much silence there is after this note ends, before the next note's timeslot.
@return [Float]
# File lib/inevitable_cacophony/rhythm.rb, line 41 def after_delay start_and_after_delays.last * duration end
How long this note sounds for, excluding any start/end delays.
# File lib/inevitable_cacophony/rhythm.rb, line 47 def sounding_time duration * (1 - start_and_after_delays.sum) end
How much silence there is before this note starts, after the previous note has finished its time (like padding in CSS).
@return [Float]
# File lib/inevitable_cacophony/rhythm.rb, line 33 def start_delay start_and_after_delays.first * duration end
How much earlier or later than normal this beat's time slice should start, accounting for the standard start/end delays, timing, and duration. Negative numbers start earlier, positive ones later.
@return [Float]
# File lib/inevitable_cacophony/rhythm.rb, line 24 def start_offset standard_start_delay = START_DELAY * duration start_delay - standard_start_delay end
Private Instance Methods
Calculate the before-note and after-note delays together, to ensure they add up correctly.
# File lib/inevitable_cacophony/rhythm.rb, line 55 def start_and_after_delays @start_and_after_delays ||= begin # Positive values from 0 to 1. # Higher numbers mean move more of this offset to the other side of the note # (e.g. start earlier for start offset). start_offset = -[timing, 0].min end_offset = [timing, 0].max # This is basically matrix multiplication; multiply [START_DELAY, END_DELAY] # by [ # (1 - start_offset) end_offset # start_offset (1 - end_offset) # ] [ ((1 - start_offset) * START_DELAY) + (end_offset * AFTER_DELAY), (start_offset * START_DELAY) + ((1 - end_offset) * AFTER_DELAY) ] end end