Class: Musicality::Parsing::PitchNode

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/musicality/notation/parsing/pitch_node.rb

Instance Method Summary collapse

Instance Method Details

#to_pitchObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/musicality/notation/parsing/pitch_node.rb', line 4

def to_pitch
  
  modval = 0
  unless mod.empty?
    modval = case mod.text_value
    when "#" then 1
    when "b" then -1
    end
  end
  sem = (pitch_letter.to_semitone + modval) % Musicality::Pitch::SEMITONES_PER_OCTAVE

  oct = octave.to_i
  ncents = 0
  unless cents.empty?
    ncents = cents.to_i
  end
  
  Musicality::Pitch.new(semitone: sem, octave: oct, cent: ncents)
end