Class: InevitableCacophony::Rhythm::Beat

Inherits:
Struct
  • Object
show all
Defined in:
lib/inevitable_cacophony/rhythm.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#amplitudeObject

Returns the value of attribute amplitude

Returns:

  • (Object)

    the current value of amplitude



17
18
19
# File 'lib/inevitable_cacophony/rhythm.rb', line 17

def amplitude
  @amplitude
end

#durationObject

Returns the value of attribute duration

Returns:

  • (Object)

    the current value of duration



17
18
19
# File 'lib/inevitable_cacophony/rhythm.rb', line 17

def duration
  @duration
end

#timingObject

Returns the value of attribute timing

Returns:

  • (Object)

    the current value of timing



17
18
19
# File 'lib/inevitable_cacophony/rhythm.rb', line 17

def timing
  @timing
end

Instance Method Details

#after_delayFloat

How much silence there is after this note ends, before the next note’s timeslot.

Returns:

  • (Float)


41
42
43
# File 'lib/inevitable_cacophony/rhythm.rb', line 41

def after_delay
	start_and_after_delays.last * duration
end

#sounding_timeObject

How long this note sounds for, excluding any start/end delays.



47
48
49
# File 'lib/inevitable_cacophony/rhythm.rb', line 47

def sounding_time
        duration * (1 - start_and_after_delays.sum)
end

#start_delayFloat

How much silence there is before this note starts, after the previous note has finished its time (like padding in CSS).

Returns:

  • (Float)


33
34
35
# File 'lib/inevitable_cacophony/rhythm.rb', line 33

def start_delay
	start_and_after_delays.first * duration
end

#start_offsetFloat

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.

Returns:

  • (Float)


24
25
26
27
# File 'lib/inevitable_cacophony/rhythm.rb', line 24

def start_offset
	standard_start_delay = START_DELAY * duration
	start_delay - standard_start_delay
end