Class: Diatone::Note

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

Class Method Summary collapse

Class Method Details

.fix(i) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/diatone.rb', line 74

def self.fix(i)
  if i.is_a? Numeric
    return i
  end
  unless i.to_s[0] == i[0].to_i.to_s
    i = tone2ord(i)
  end
  return i
end

.get(s) ⇒ Object



93
94
95
# File 'lib/diatone.rb', line 93

def self.get (s)
  return [key(s,false)]
end

.getFreq(i) ⇒ Object



101
102
103
104
# File 'lib/diatone.rb', line 101

def self.getFreq (i)
  i = fix(i)
  return 440.0 * ( STEP ** (i-9) )
end

.key(s, ord = true) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/diatone.rb', line 84

def self.key(s, ord=true)
  s = fix(s)
  s = ord2tone(s, true)
  unless ord
    return s
  end
  return TONES.rindex {|a| a == s }
end

.name(s) ⇒ Object



97
98
99
# File 'lib/diatone.rb', line 97

def self.name (s)
  return key(s,false)
end

.ord2tone(i, key = false) ⇒ Object



54
55
56
57
58
59
# File 'lib/diatone.rb', line 54

def self.ord2tone ( i, key = false )
  i += 48
  s = TONES[i% CHR]
  s = s + (i/ CHR).floor.to_s unless key
  return s
end

.tone2ord(s) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/diatone.rb', line 61

def self.tone2ord (s)
  if s[-2] == s[-2].to_i.to_s
    i = s[-2..-1].to_i * CHR
  elsif s[-1] == s[-1].to_i.to_s
    i = s[-1].to_i * CHR
  else
    i = 48
  end

  if s[1] == 'b' then i -= 1 elsif s[1] == '' then i += 1 end
  return i + TONES.rindex { |a| a == s[0].upcase } - 48
end