Module: HeadMusic::Time::RadixCarry

Included in:
MusicalPosition, SmpteTimecode
Defined in:
lib/head_music/time/radix_carry.rb

Overview

Shared helper for positional/timecode components that carry between radix-bounded fields (e.g. bars:beats:ticks, hours:minutes:seconds:frames).

Instance Method Summary collapse

Instance Method Details

#carry(component, radix) ⇒ Integer (private)

Divide the named component by its radix, store the remainder back, and return the amount to carry into the next-higher component.

Returns:

  • (Integer)

    the carry (may be negative when borrowing)



14
15
16
17
18
19
# File 'lib/head_music/time/radix_carry.rb', line 14

def carry(component, radix)
  ivar = :"@#{component}"
  delta, remainder = instance_variable_get(ivar).divmod(radix)
  instance_variable_set(ivar, remainder)
  delta
end