Class: Coltrane::NoteSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/coltrane/note_set.rb

Overview

It describes a set of notes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ NoteSet



20
21
22
23
24
25
26
27
# File 'lib/coltrane/note_set.rb', line 20

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

Instance Attribute Details

#notesObject (readonly) Also known as: all

Returns the value of attribute notes.



11
12
13
# File 'lib/coltrane/note_set.rb', line 11

def notes
  @notes
end

Class Method Details

.[](*notes) ⇒ Object



16
17
18
# File 'lib/coltrane/note_set.rb', line 16

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

Instance Method Details

#&(other) ⇒ Object



29
30
31
# File 'lib/coltrane/note_set.rb', line 29

def &(other)
  NoteSet[*(notes & other.notes)]
end

#+(other) ⇒ Object



37
38
39
# File 'lib/coltrane/note_set.rb', line 37

def +(other)
  NoteSet[*(notes + other.notes)]
end

#degree(note) ⇒ Object



33
34
35
# File 'lib/coltrane/note_set.rb', line 33

def degree(note)
  index(note) + 1
end

#interval_sequenceObject



63
64
65
# File 'lib/coltrane/note_set.rb', line 63

def interval_sequence
  IntervalSequence.new(notes: self)
end

#namesObject



45
46
47
# File 'lib/coltrane/note_set.rb', line 45

def names
  map(&:name)
end

#numbersObject



49
50
51
# File 'lib/coltrane/note_set.rb', line 49

def numbers
  map(&:number)
end

#pretty_namesObject



41
42
43
# File 'lib/coltrane/note_set.rb', line 41

def pretty_names
  map(&:pretty_name)
end

#transpose_by(interval) ⇒ Object



57
58
59
60
61
# File 'lib/coltrane/note_set.rb', line 57

def transpose_by(interval)
  notes.map do |note|
    note.transpose_by(interval)
  end
end

#transpose_to(note_name) ⇒ Object



53
54
55
# File 'lib/coltrane/note_set.rb', line 53

def transpose_to(note_name)
  transpose_by(root_note.interval_to(note_name).number)
end