Class: HeadMusic::Notation::LilyPond::Preflight
- Inherits:
-
Object
- Object
- HeadMusic::Notation::LilyPond::Preflight
- Includes:
- PlacementValidation, PreflightChecks
- Defined in:
- lib/head_music/notation/lily_pond/preflight.rb
Overview
Rejects compositions that cannot be expressed in the supported LilyPond subset.
Whole-composition problems (no voices, positional gaps, underfilled final bars, barline-crossing notes, unpitched sounds) raise RenderError here, before the Writer assembles any output — so a successful check! is the Writer’s guarantee that assembly cannot fail on these grounds.
Instance Attribute Summary collapse
-
#composition ⇒ Object
readonly
private
Returns the value of attribute composition.
Class Method Summary collapse
Instance Method Summary collapse
-
#check! ⇒ Object
-
#ensure_contiguous_voices(composition) ⇒ Object
included
from PreflightChecks
private
-
#ensure_filled_final_bars ⇒ Object
private
A bar with some placements that do not fill it would render short of its bar check, which LilyPond rejects at compile time — unlike a bar with none, which the Writer fills with a whole-bar rest.
-
#ensure_notes_within_barlines(composition) ⇒ Object
included
from PreflightChecks
private
-
#ensure_pitched_placements ⇒ Object
private
-
#ensure_pitched_sounds(placement) ⇒ Object
included
from PlacementValidation
private
-
#ensure_voices ⇒ Object
private
-
#initialize(composition) ⇒ Preflight
constructor
A new instance of Preflight.
-
#raise_gap_error(voice, expected_position, found_placement) ⇒ Object
included
from PreflightChecks
private
-
#render_error_class ⇒ Object
private
Constructor Details
#initialize(composition) ⇒ Preflight
Returns a new instance of Preflight.
18 19 20 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 18 def initialize(composition) @composition = composition end |
Instance Attribute Details
#composition ⇒ Object (readonly, private)
Returns the value of attribute composition.
32 33 34 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 32 def composition @composition end |
Class Method Details
.check!(composition) ⇒ Object
14 15 16 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 14 def self.check!(composition) new(composition).check! end |
Instance Method Details
#check! ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 22 def check! ensure_voices ensure_contiguous_voices(composition) (composition) ensure_pitched_placements end |
#ensure_contiguous_voices(composition) ⇒ Object (private) Originally defined in module PreflightChecks
#ensure_filled_final_bars ⇒ Object (private)
A bar with some placements that do not fill it would render short of its bar check, which LilyPond rejects at compile time — unlike a bar with none, which the Writer fills with a whole-bar rest.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 49 def composition.voices.each do |voice| placement = voice.last_placement next unless placement next if placement.next_position == placement.position. raise RenderError, "the voice ends mid-bar at #{placement.next_position}; " \ "insert explicit rests to fill the final bar" end end |
#ensure_notes_within_barlines(composition) ⇒ Object (private) Originally defined in module PreflightChecks
#ensure_pitched_placements ⇒ Object (private)
40 41 42 43 44 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 40 def ensure_pitched_placements composition.voices.each do |voice| voice.placements.each { |placement| ensure_pitched_sounds(placement) } end end |
#ensure_pitched_sounds(placement) ⇒ Object (private) Originally defined in module PlacementValidation
#ensure_voices ⇒ Object (private)
34 35 36 37 38 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 34 def ensure_voices return unless composition.voices.empty? raise RenderError, "cannot render a composition with no voices as LilyPond" end |
#raise_gap_error(voice, expected_position, found_placement) ⇒ Object (private) Originally defined in module PreflightChecks
#render_error_class ⇒ Object (private)
60 61 62 |
# File 'lib/head_music/notation/lily_pond/preflight.rb', line 60 def render_error_class RenderError end |