Method: Coltrane::Theory::Note#initialize
- Defined in:
- lib/coltrane/theory/note.rb
#initialize(arg) ⇒ Note
Returns a new instance of Note.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/coltrane/theory/note.rb', line 24 def initialize(arg) note_name = case arg when String then arg when PitchClass then arg.true_notation when Numeric, Frequency then PitchClass.new(arg).true_notation else raise(WrongArgumentsError, arg) end chars = note_name.chars letter = chars.shift raise InvalidNoteLetterError, arg unless ('A'..'G').cover?(letter) @alteration = chars.reduce(0) do |alt, symbol| raise InvalidNoteLetterError, arg unless ALTERATIONS.include?(symbol) alt + ALTERATIONS[symbol] end super((PitchClass[letter].integer + @alteration) % PitchClass.size) end |