Class: Diatone::Scale

Inherits:
Object
  • Object
show all
Defined in:
lib/diatone.rb

Class Method Summary collapse

Class Method Details

.abbr(t) ⇒ Object



110
111
112
113
114
115
116
117
118
# 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) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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) ⇒ Object



146
147
148
149
150
151
152
153
154
155
# 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