Class: Musicality::Parsing::NoteNode

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

Instance Method Summary collapse

Instance Method Details

#to_noteObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/musicality/notation/parsing/note_node.rb', line 4

def to_note
  dur = duration.to_r
  pitches = []
  links = {}
  articulation = Articulations::NORMAL

  unless more.empty?
    first_pl = more.first_pl
    more_pl = more.more_pl

    pitches.push first_pl.pitch.to_pitch
    unless first_pl.the_link.empty?
      links[pitches[-1]] = first_pl.the_link.to_link
    end

    more_pl.elements.each do |x|
      pitches.push x.pl.pitch.to_pitch
      unless x.pl.the_link.empty?
        links[pitches[-1]] = x.pl.the_link.to_link
      end
    end

    unless more.art.empty?
      articulation = more.art.to_articulation
    end
  end

  marks = []
  unless begin_slur.empty?
    marks.push Musicality::Marks::BEGIN_SLUR
  end

  unless end_slur.empty?
    marks.push Musicality::Marks::END_SLUR
  end

  Musicality::Note.new(dur, pitches, links: links, marks: marks, articulation: articulation)
end