class WaveFile::SMPTETimecode

Public: Represents an SMPTE timecode: en.wikipedia.org/wiki/SMPTE_timecode

If a *.wav file has a "smpl" chunk, then Reader.sampler_info.smpte_offset
will return an instance of this class.

Attributes

frames[R]
hours[R]
minutes[R]
seconds[R]

Public Class Methods

new(hours: required("hours"), minutes: required("minutes"), seconds: required("seconds"), frames: required("frames")) click to toggle source

Public: Constructs a new SMPTETimecode instance.

Raises InvalidSMPTETimecodeError if the given arguments can't be written to a *.wav file.

# File lib/wavefile/smpte_timecode.rb, line 21
def initialize(hours: required("hours"),
               minutes: required("minutes"),
               seconds: required("seconds"),
               frames: required("frames"))
  validate_8_bit_signed_integer_field(hours, "hours")
  validate_8_bit_unsigned_integer_field(minutes, "minutes")
  validate_8_bit_unsigned_integer_field(seconds, "seconds")
  validate_8_bit_unsigned_integer_field(frames, "frames")

  @hours = hours
  @minutes = minutes
  @seconds = seconds
  @frames = frames
end

Private Instance Methods

required(keyword) click to toggle source
# File lib/wavefile/smpte_timecode.rb, line 43
def required(keyword)
  raise ArgumentError.new("missing keyword: #{keyword}")
end
validate_8_bit_signed_integer_field(candidate, field_name) click to toggle source
# File lib/wavefile/smpte_timecode.rb, line 54
def validate_8_bit_signed_integer_field(candidate, field_name)
  unless candidate.is_a?(Integer) && VALID_8_BIT_SIGNED_INTEGER_RANGE === candidate
    raise InvalidSMPTETimecodeError,
          "Invalid `#{field_name}` value: `#{candidate}`. Must be an Integer between #{VALID_8_BIT_SIGNED_INTEGER_RANGE.min} and #{VALID_8_BIT_SIGNED_INTEGER_RANGE.max}"
  end
end
validate_8_bit_unsigned_integer_field(candidate, field_name) click to toggle source
# File lib/wavefile/smpte_timecode.rb, line 47
def validate_8_bit_unsigned_integer_field(candidate, field_name)
  unless candidate.is_a?(Integer) && VALID_8_BIT_UNSIGNED_INTEGER_RANGE === candidate
    raise InvalidSMPTETimecodeError,
          "Invalid `#{field_name}` value: `#{candidate}`. Must be an Integer between #{VALID_8_BIT_UNSIGNED_INTEGER_RANGE.min} and #{VALID_8_BIT_UNSIGNED_INTEGER_RANGE.max}"
  end
end