class Diatone::Scale

Public Class Methods

abbr(t) click to toggle source
# File lib/diatone.rb, line 110
def self.abbr (t)
  t.gsub!(' major','')
  t.gsub!('major','')
  t.gsub!('maj','')
  t.gsub!(' minor','m')
  t.gsub!('minor','m')
  t.gsub!('min','m')
  return t
end
get(s) click to toggle source
# File lib/diatone.rb, line 120
def self.get (s)
  if s.length > 1
    if s[1] == '♯' or s[1] == 'b'
      tonic = Note.key s[0..1]
      type = abbr(s[2..-1])
    else
      tonic = Note.key s[0]
      type = abbr(s[1..-1])
    end
  else
    tonic = Note.key s
    type = ''
  end
  i = Note.key(tonic)
  scale = [ TONES[i] ]
  if SCALES.include? type
    SCALES[type].split('').each do |interval|
      i += interval.to_i
      scale.push  TONES[i% CHR]
    end
  else
    return [false,type]
  end
  return scale
end
name(s) click to toggle source
# File lib/diatone.rb, line 146
def self.name (s)
  if s[1] == '♯' or s[1] == 'b'
    note = Note.key s[0..1], false
    type = abbr(s[2..-1])
  else
    note = Note.key s[0], false
    type = abbr(s[1..-1])
  end
  return note+type
end