Sha256: 4b5252076c61cc969aadcc7eaa42a08d693c228863c5376c6db4d94af73ea578
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true module Coltrane # It describes a set of notes class NoteSet extend Forwardable def_delegators :@notes, :first, :each, :size, :map, :reduce, :index, :[], :index, :empty?, :permutation, :include? attr_reader :notes alias root first alias all notes def self.[](*notes) new(notes) end def initialize(arg) @notes = case arg when NoteSet then arg.notes when Array then arg.map { |n| n.is_a?(Note) ? n : Note[n] }.uniq else raise InvalidNotesError, arg end end def &(other) NoteSet[*(notes & other.notes)] end def degree(note) index(note) + 1 end def +(other) NoteSet[*(notes + other.notes)] end def pretty_names map(&:pretty_name) end def names map(&:name) end def numbers map(&:number) end def transpose_to(note_name) transpose_by(root_note.interval_to(note_name).number) end def transpose_by(interval) notes.map do |note| note.transpose_by(interval) end end def interval_sequence IntervalSequence.new(notes: self) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
coltrane-1.1.2 | lib/coltrane/note_set.rb |
coltrane-1.1.1 | lib/coltrane/note_set.rb |
coltrane-1.1.0 | lib/coltrane/note_set.rb |