Sha256: 2642022ecc66248abe72c72d927eb3492e73c99e4798ca09a27c7c5438770908
Contents?: true
Size: 1.24 KB
Versions: 3
Compression:
Stored size: 1.24 KB
Contents
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_method :root, :first alias_method :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] } else raise InvalidNotes.new(arg) end end def &(another) NoteSet[*(notes & another.notes)] end def degree(note) index(note)+1 end def +(other_noteset) NoteSet[*(notes + other_noteset.notes)] end def pretty_names map(&:pretty_name) end def names map(&:name) 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 guitar_notes GuitarNoteSet.new(notes.map(&:guitar_notes).flatten) 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.0.11 | lib/coltrane/note_set.rb |
coltrane-1.0.1 | lib/coltrane/note_set.rb |
coltrane-1.0.0 | lib/coltrane/note_set.rb |