| Class | Key |
| In: |
app/models/key.rb
|
| Parent: | ActiveRecord::Base |
A key represents a specific theoretic tone mapped to a pitch and a letter index. Keys are defined for all letters A-G and all sharp/flat values within two semitons (e.g. Dbb, D Double-Flat enharmonic with C).
Each key is associated an index between 0-11 to represent the actual pitch within the chromatic scale. Each key is also assigned a "letter index" which represents a relative letter value. This index is crucial as it disambiguates theoretical tone differences such as Eb and D#. Doing so also supports correct double-sharp and double-flat interpretations which are rare but theoretically different from their enharmonic counterparts.
| Letters | = | ['C' => 0, 'D' => 1, 'E' => 2, 'F' => 3, 'G' => 4, 'A' => 5, 'B' => 6] |
| DEFAULT | = | self['C'] |
Retreives Fully-Cached Array
# File app/models/key.rb, line 17
17: def self.cache(conditions = [])
18: self.find(:all, :conditions => []) # Rails 2.0 Already Caches!
19: end
Finds a key given a tonal index 0-11 and a letter index (to disambiguate enharmonic keys)
# File app/models/key.rb, line 22
22: def self.from_index(value, preferred_letter = nil)
23: self.cache.find {|k| k.index == value && (preferred_letter.nil? || k.letter_index == preferred_letter)}
24: end
Finds a key object given the name (such as Eb)
# File app/models/key.rb, line 27
27: def self.from_name(value)
28: self.cache.find {|k| k.name == value}
29: end
Returns an array of the 12 primary keys (definitions around the cycle of fourths)
# File app/models/key.rb, line 39
39: def self.primaries
40: self.find_all_by_primary(true)
41: end