Sha256: 28a2cc4001a39c8ae8dbf3bfa91cf7062ca9c0f35c5c747d3993263ef2730023

Contents?: true

Size: 959 Bytes

Versions: 8

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

module Coltrane
  module Theory
    # 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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
coltrane-3.2.0 lib/coltrane/theory/voicing.rb
coltrane-3.1.3 lib/coltrane/theory/voicing.rb
coltrane-3.1.2 lib/coltrane/theory/voicing.rb
coltrane-3.1.1 lib/coltrane/theory/voicing.rb
coltrane-3.1.0 lib/coltrane/theory/voicing.rb
coltrane-3.0.0 lib/coltrane/theory/voicing.rb
coltrane-3.0.0.rc1 lib/coltrane/theory/voicing.rb
coltrane-3.0.0.pre lib/coltrane/theory/voicing.rb