Class: MusicTheory::Third

Inherits:
Object
  • Object
show all
Includes:
Output
Defined in:
lib/music_theory/third.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Output

#buffer_format, #format, #output_track, #play, #sample_rate

Constructor Details

#initialize(scale) ⇒ Third

Returns a new instance of Third.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/music_theory/third.rb', line 8

def initialize(scale)
  @scale             = scale
  @all_notes         = [scale.scale_notes.first]
  current            = 0
  double_scale_notes = scale.scale_notes * 2
  scale.mode.in_groups_of(2, false) do |group|
    current += group.sum
    all_notes << double_scale_notes[current]
  end
  all_notes.compact.uniq {|note| note.frequency}.sort_by! {|note| note.frequency}
end

Instance Attribute Details

#all_notesObject

Returns the value of attribute all_notes.



6
7
8
# File 'lib/music_theory/third.rb', line 6

def all_notes
  @all_notes
end

#scaleObject

Returns the value of attribute scale.



6
7
8
# File 'lib/music_theory/third.rb', line 6

def scale
  @scale
end

Instance Method Details

#arpeggioObject



28
29
30
# File 'lib/music_theory/third.rb', line 28

def arpeggio
  arpeggio ||= MusicTheory::Arpeggio.new self.dup
end

#chordObject



24
25
26
# File 'lib/music_theory/third.rb', line 24

def chord
  chord ||= MusicTheory::Chord.new self.dup
end

#output_file_nameObject



32
33
34
# File 'lib/music_theory/third.rb', line 32

def output_file_name
  scale.output_file_name || 'thirds'
end

#samplesObject



20
21
22
# File 'lib/music_theory/third.rb', line 20

def samples
  all_notes.map(&:samples).flatten
end