Class: HeadMusic::Notation::LilyPond::RenderPlan

Inherits:
RenderPlan
  • Object
show all
Defined in:
lib/head_music/notation/lily_pond/render_plan.rb

Overview

The computed musical facts a Writer needs to serialize a flow: the token for every placement, on top of the measure signatures the base plan tracks. Construction eagerly computes everything that can raise on unmappable keys, durations, or alterations, so a RenderPlan that builds successfully cannot fail assembly on those grounds.

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from HeadMusic::Notation::RenderPlan

Instance Method Details

#chord_token(placement) ⇒ Object (private)



47
48
49
50
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 47

def chord_token(placement)
  body = "<#{placement.pitches.sort.map { |pitch| PitchWriter.token(pitch) }.join(" ")}>"
  placement.rhythmic_value.tied_chain.map { |link| "#{body}#{DurationWriter.token(link)}" }.join("~ ")
end

#key_value(event) ⇒ Object (private)

LilyPond has no way to say "three flats read as dorian", so it renders what is printed at the clef.



24
25
26
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 24

def key_value(event)
  KeyMapper.token(event.printed_key_signature)
end

#note_token(placement) ⇒ Object (private)



42
43
44
45
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 42

def note_token(placement)
  pitch_token = PitchWriter.token(placement.pitch)
  placement.rhythmic_value.tied_chain.map { |link| "#{pitch_token}#{DurationWriter.token(link)}" }.join("~ ")
end

#precompute_eager_data ⇒ Object (private)



17
18
19
20
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 17

def precompute_eager_data
  super
  tokens_by_placement
end

#rest_token(placement) ⇒ Object (private)



38
39
40
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 38

def rest_token(placement)
  placement.rhythmic_value.tied_chain.map { |link| "r#{DurationWriter.token(link)}" }.join(" ")
end

#token(placement) ⇒ Object (private)

A tied chain within a placement joins its links with the tie mark; a chain of rests emits consecutive untied rests, and a tied chord repeats the whole chord.



31
32
33
34
35
36
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 31

def token(placement)
  return rest_token(placement) if placement.rest?
  return chord_token(placement) if placement.chord?

  note_token(placement)
end

#tokens_by_placement ⇒ Object



9
10
11
12
13
# File 'lib/head_music/notation/lily_pond/render_plan.rb', line 9

def tokens_by_placement
  @tokens_by_placement ||= flow.voices.flat_map(&:placements).to_h do |placement|
    [placement, token(placement)]
  end
end