Sha256: ad6d36c7cfa969f04c3761e05bad9c3b1ac2caa6376195e412d7b2ce13f39543
Contents?: true
Size: 762 Bytes
Versions: 12
Compression:
Stored size: 762 Bytes
Contents
class HeadMusic::Chord attr_reader :pitches def initialize(pitches) raise ArgumentError if pitches.length < 3 @pitches = pitches.map { |pitch| HeadMusic::Pitch.get(pitch) }.sort end def consonant_triad? pitches.length == 3 && ( intervals.map(&:shorthand).sort == %w[M3 m3] || invert.intervals.map(&:shorthand).sort == %w[M3 m3] || invert.invert.intervals.map(&:shorthand).sort == %w[M3 m3] ) end def intervals pitches.drop(1).map.with_index do |pitch, i| HeadMusic::FunctionalInterval.new(pitches[i], pitch) end end def invert inverted_pitch = pitches[0] + HeadMusic::Interval.get(12) new_pitches = pitches.drop(1) + [inverted_pitch] HeadMusic::Chord.new(new_pitches) end end
Version data entries
12 entries across 12 versions & 1 rubygems