module MusicUtils::Scales

Scales module

Constants

AUG
AUGP
CROMATIC_SCALE
DFLAT
DIATONIC_SCALE
DIATONIC_SCALE_AUX
DIM
DIMP
DO

Notes

DOF

Altered notes

DOFF
DOS
DOSS
DSHARP
FA
FAF
FAFF
FAS
FASS
FLAT

Alterations:

LA
LAF
LAFF
LAS
LASS
MAJ
MAJ_SCALE
MELODIC_MIN_SCALE
MI
MIF
MIFF
MIN
MIS
MISS
NATURAL_MIN_SCALE
PENTATONIC_MAJ
PERF

Qualities

QUALITIES

Qualities hash

RE
REF
REFF
RES
RESS
SHARP
SI
SIF
SIFF
SIS
SISS
SOL
SOLF
SOLFF
SOLS
SOLSS

Public Class Methods

cromatic_index(from) click to toggle source

Returns index of the note in the cromatic scale

# File lib/music-utils/scales/scales.rb, line 142
def Scales.cromatic_index(from)
  i = 0
  find_it = false
  CROMATIC_SCALE.each do |e|
    if e.is_a?(Array)
      e.each do |ee|
        find_it = true if from == ee
      end
    else
      find_it = true if from == e
    end
    break if find_it
    i += 1
  end
  i
end
diatonic_aux_scale_from(from) click to toggle source

Create a diatonic scale starting with the “from” note with notes dups

# File lib/music-utils/scales/scales.rb, line 161
def Scales.diatonic_aux_scale_from(from)
  diatonic_scale = []
  length = DIATONIC_SCALE_AUX.length
  i = DIATONIC_SCALE_AUX.index(from)
  c = 0
  while c < length
    diatonic_scale << DIATONIC_SCALE_AUX[i]
    i += 1
    c += 1
    if i > length - 1
      i = 0
    end 
  end
  diatonic_scale
end
diatonic_scale_from(from) click to toggle source

Create a diatonic scale starting with the “from” note

# File lib/music-utils/scales/scales.rb, line 137
def Scales.diatonic_scale_from(from)
  diatonic_aux_scale_from(from).uniq
end
scale(from, scale_struct) click to toggle source

Create scale from a note and scale structure

# File lib/music-utils/scales/scales.rb, line 99
def Scales.scale(from, scale_struct)
  from = from.to_sym
  
  i = cromatic_index(from)
  
  scale = []
  scale << from

  from_note, from_alter = MusicUtils::Note.parse(from)
  
  #diatonic_scale = diatonic_scale_from(from_note)
  diatonic_scale = scale_from(from_note, scale_struct)
  diatonic_scale.delete(from_note)

  length = CROMATIC_SCALE.length

  scale_struct.each do |shift|
    if i + shift > length - 1
      i = (i + shift) - (length)
      shift = 0
    end

    CROMATIC_SCALE[i + shift].each do |e|
      e_note, e_alter = MusicUtils::Note.parse(e)
        
      if diatonic_scale.first == e_note
        scale << e
        diatonic_scale.delete(diatonic_scale.first)
        break
      end 
    end
    i += shift
  end

  scale
end
scale_from(from_note, scale_struct) click to toggle source
# File lib/music-utils/scales/scales.rb, line 177
def Scales.scale_from(from_note, scale_struct)
  i = 0
  c = 0
  scale = []
  scale << from_note
  
  ds = diatonic_aux_scale_from(from_note)
  
  while c < scale_struct.size
    i += scale_struct[c]
    if scale.last != ds[i]
      scale << ds[i]  
    else
      scale << ds[i + 1]
    end
      c += 1
  end
  scale
end