| Module | ChordCollection |
| In: |
app/models/chord_collection.rb
|
WARNING: This is basically duplicated from Chord Try to make this DRY!
Resolves a chord symbol into a chord. Implementation is somewhat flakey due to the potential ambiguities arising from specifying key and symbols together.
# File app/models/chord_collection.rb, line 36
36: def resolve(symbol)
37: in_key = nil
38:
39: return nil if symbol.nil?
40:
41: Key.cache.each do |k|
42: if symbol.starts_with?(k.name)
43: in_key = k
44: symbol.sub!(k.name, '').strip
45: break
46: end
47: end
48:
49: chord_symbol = self.map {|c| c.symbols.to_a}.flatten.detect {|cs| cs.name == symbol}
50:
51: # Perhaps the matched key was really part of the name of the chord, try that:
52: if chord_symbol.nil? && !in_key.nil?
53: symbol = in_key.name + symbol
54: chord_symbol = self.symbols[symbol]
55: end
56:
57: # If still not found, must be invalid:
58: return nil if chord_symbol.nil?
59:
60: chord = chord_symbol.chord
61: chord.key = in_key unless in_key.nil?
62: chord
63: end