Class: Juicy::Scale

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/juicy/scale.rb

Overview

0 1 2 3 4 5 6 7 8 9 10 11 12

 |- |- |- |- |- |- |- |- |- |- |- |- |
do di re ri mi fa fi so si la li ti do

chromatic |- |- |- |- |- |- |- |- |- |- |- |- |

do    re    mi fa    so    la    ti do

diatonic |- - |- - |- |- - |- - |- - |- |

do    re    mi       so    la       do

pentatonic |- - |- - |- - - |- - |- - - |

do    re    mi    fi    si    li    do

whole note |- - |- - |- - |- - |- - |- - |

do    re ri    fa fi    si la    ti do

octotonic |- - |- |- - |- |- - |- |- - |- |

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {mode: :major, root: Note.new}) ⇒ Scale

Returns a new instance of Scale.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/juicy/scale.rb', line 30

def initialize(options = {mode: :major, root: Note.new})
  options[:mode] ||= :major
  options[:root] ||= Note.new
  case options[:mode]
  when :major
  @type = :diatonic
  when :minor
  @type = :diatonic
  else
  @type = type
  end
  @mode = Mode.new(options[:mode])
  @root = options[:root]
  generate_notes

end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



28
29
30
# File 'lib/juicy/scale.rb', line 28

def mode
  @mode
end

#rootObject

Returns the value of attribute root.



28
29
30
# File 'lib/juicy/scale.rb', line 28

def root
  @root
end

Instance Method Details

#[](element) ⇒ Object



51
52
53
# File 'lib/juicy/scale.rb', line 51

def[](element)
  
end

#doObject



109
110
111
112
113
# File 'lib/juicy/scale.rb', line 109

def do
  if @mode == :major
    @root
  end
end

#eachObject

def each

yield SCALE_TYPES[@type]

end



73
74
75
76
77
# File 'lib/juicy/scale.rb', line 73

def each
  (SCALE_TYPES[@type].size+1).times do
    yield @notes.next.name
  end
end

#each_note(&block) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/juicy/scale.rb', line 79

def each_note &block
  if block_given?
    (SCALE_TYPES[@type].size+1).times do
      yield @notes.next
    end
  else
    @notes
  end
end

#faObject



127
128
129
130
131
# File 'lib/juicy/scale.rb', line 127

def fa
  if @mode == :major
    @root + 5
  end
end

#interval_between(note1, note2) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/juicy/scale.rb', line 89

def interval_between(note1, note2)
  half_steps = 0
  direction = (note1 <=> note2)
  if direction == 0
  elsif direction == -1
    note = note1.dup
    until (note <=> note2) == 0
      note += 1
      half_steps += 1
    end
  elsif direction == 1
    note = note1.dup
    until (note <=> note2) == 0
      note -= 1
      half_steps -= 1
    end
  end
  half_steps
end

#laObject



139
140
141
142
143
# File 'lib/juicy/scale.rb', line 139

def la
  if @mode == :major
    @root + 9
  end
end

#miObject



121
122
123
124
125
# File 'lib/juicy/scale.rb', line 121

def mi
  if @mode == :major
    @root + 4
  end
end

#playObject



55
56
57
# File 'lib/juicy/scale.rb', line 55

def play
  each_note &:play
end

#reObject



115
116
117
118
119
# File 'lib/juicy/scale.rb', line 115

def re
  if @mode == :major
    @root + 2
  end
end

#soObject



133
134
135
136
137
# File 'lib/juicy/scale.rb', line 133

def so
  if @mode == :major
    @root + 7
  end
end

#tiObject



145
146
147
148
149
# File 'lib/juicy/scale.rb', line 145

def ti
  if @mode == :major
    @root + 11
  end
end

#to_sObject



47
48
49
# File 'lib/juicy/scale.rb', line 47

def to_s
  "scale type: #{@type}, mode: #{@mode}, root: #{@root}"
end