class Juicy::Scale
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 |- - |- |- - |- |- - |- |- - |- |
Attributes
mode[R]
root[R]
Public Class Methods
new(options = {mode: :major, root: Note.new})
click to toggle source
# 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
Public Instance Methods
[](element)
click to toggle source
# File lib/juicy/scale.rb, line 51 def[](element) end
do()
click to toggle source
# File lib/juicy/scale.rb, line 109 def do if @mode == :major @root end end
each() { |next.name| ... }
click to toggle source
def each
yield SCALE_TYPES[@type]
end
# File lib/juicy/scale.rb, line 73 def each (SCALE_TYPES[@type].size+1).times do yield @notes.next.name end end
each_note() { |next| ... }
click to toggle source
# 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
fa()
click to toggle source
# File lib/juicy/scale.rb, line 127 def fa if @mode == :major @root + 5 end end
interval_between(note1, note2)
click to toggle source
# 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
la()
click to toggle source
# File lib/juicy/scale.rb, line 139 def la if @mode == :major @root + 9 end end
mi()
click to toggle source
# File lib/juicy/scale.rb, line 121 def mi if @mode == :major @root + 4 end end
mode=(type)
click to toggle source
# File lib/juicy/scale.rb, line 59 def mode=(type) @mode = Mode.new(type) generate_notes end
play()
click to toggle source
# File lib/juicy/scale.rb, line 55 def play each_note &:play end
re()
click to toggle source
# File lib/juicy/scale.rb, line 115 def re if @mode == :major @root + 2 end end
root=(root)
click to toggle source
# File lib/juicy/scale.rb, line 64 def root=(root) @root = root generate_notes end
so()
click to toggle source
# File lib/juicy/scale.rb, line 133 def so if @mode == :major @root + 7 end end
ti()
click to toggle source
# File lib/juicy/scale.rb, line 145 def ti if @mode == :major @root + 11 end end
to_s()
click to toggle source
# File lib/juicy/scale.rb, line 47 def to_s "scale type: #{@type}, mode: #{@mode}, root: #{@root}" end
Private Instance Methods
generate_notes()
click to toggle source
# File lib/juicy/scale.rb, line 153 def generate_notes @notes = [] @notes << @root SCALE_TYPES[@type].rotate(@mode.rotate).each do |step| @notes << @notes[-1]+step end @notes = @notes.cycle end