Class: Stave::Theory::Interval::Number

Inherits:
Core::Lookup show all
Defined in:
lib/stave/theory/interval.rb

Instance Attribute Summary

Attributes inherited from Core::Lookup

#variant

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Lookup

#==, each_key, find_by, #initialize, keys, string_keys, variant, variant?, variant_lookup, variants, where, with_options

Constructor Details

This class inherits a constructor from Stave::Core::Lookup

Class Method Details

.between(note, other_note) ⇒ Object



78
79
80
81
82
83
# File 'lib/stave/theory/interval.rb', line 78

def self.between(note, other_note)
  target = other_note.pitch_class.index - note.pitch_class.index + 1
  target += 7 unless target.positive?

  find_by(to_i: target)
end

Instance Method Details

#+(other) ⇒ Object



58
59
60
61
62
63
# File 'lib/stave/theory/interval.rb', line 58

def +(other)
  target_i = to_i + other.relative.offset
  target_i -= 7 while target_i >= 8

  Number.find_by(to_i: target_i)
end

#compound?Boolean

Returns:

  • (Boolean)


50
# File 'lib/stave/theory/interval.rb', line 50

def compound? = size >= 12

#degreeObject



54
# File 'lib/stave/theory/interval.rb', line 54

def degree = compound? ? to_i - 7 : to_i

#invert!Object



72
73
74
75
76
# File 'lib/stave/theory/interval.rb', line 72

def invert!
  return self if octave?

  Number.find_by(degree: 9 - degree)
end

#octave?Boolean

Returns:

  • (Boolean)


52
# File 'lib/stave/theory/interval.rb', line 52

def octave? = (size % 12).zero?

#offsetObject



56
# File 'lib/stave/theory/interval.rb', line 56

def offset = to_i - 1

#relativeObject



65
66
67
68
69
70
# File 'lib/stave/theory/interval.rb', line 65

def relative
  target_i = to_i
  target_i -= 7 while target_i >= 8

  Number.find_by(to_i: target_i)
end

#symbolObject



48
# File 'lib/stave/theory/interval.rb', line 48

def symbol = to_i.to_s