Sha256: 45ba25f0a97bc9c604f9187e07def57e9e118605f559a4c10b1da67b5761400d

Contents?: true

Size: 879 Bytes

Versions: 1

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module Coltrane
  # This class describes an actual implementation of a Chord, being aware
  # of exact octaves of each pitch and even repeating pitches across octaves.
  class Voicing
    attr_reader :pitches

    def initialize(*pitch_strings, pitches: nil)
      @pitches = if pitch_strings.any?
                   pitch_strings.map { |s| Pitch[s] }
                 elsif pitches
                   pitches
                 else
                   raise WrongArgumentsError
                 end
    end

    def self.[](*args)
      new(*args)
    end

    def pitch_classes
      NoteSet[*pitches.map(&:pitch_class).uniq]
    end

    alias notes pitch_classes

    def chord
      @chord ||= Chord.new(notes: notes)
    rescue ChordNotFoundError
      return false
    end

    def frequencies
      pitches.map(&:frequency)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coltrane-2.2.1 lib/coltrane/voicing.rb