Module: HeadMusic::Notation::PreflightChecks
- Included in:
- ABC::Writer, LilyPond::Preflight, MusicXML::Preflight
- Defined in:
- lib/head_music/notation/preflight_checks.rb
Overview
Whole-composition checks shared by the notation writers’ preflights. Each check raises before any output is assembled, so a caller that passes them all can serialize without failing on these grounds; each includer supplies its own format-specific RenderError subclass through #render_error_class.
Instance Method Summary collapse
-
#ensure_contiguous_voices(composition) ⇒ Object
private
-
#ensure_notes_within_barlines(composition) ⇒ Object
private
-
#raise_gap_error(voice, expected_position, found_placement) ⇒ Object
private
Instance Method Details
#ensure_contiguous_voices(composition) ⇒ Object (private)
11 12 13 14 15 16 |
# File 'lib/head_music/notation/preflight_checks.rb', line 11 def ensure_contiguous_voices(composition) composition.voices.each do |voice| gap = voice.first_gap raise_gap_error(voice, *gap) if gap end end |
#ensure_notes_within_barlines(composition) ⇒ Object (private)
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/head_music/notation/preflight_checks.rb', line 18 def (composition) composition.voices.each do |voice| voice.placements.each do |placement| next unless placement.next_position > placement.position. raise render_error_class, "the note at #{placement.position} crosses its barline; " \ "splitting notes across barlines is not supported" end end end |
#raise_gap_error(voice, expected_position, found_placement) ⇒ Object (private)
29 30 31 32 33 34 35 36 37 |
# File 'lib/head_music/notation/preflight_checks.rb', line 29 def raise_gap_error(voice, expected_position, found_placement) if found_placement.equal?(voice.placements.first) raise render_error_class, "the first placement must start its bar " \ "(found #{found_placement.position}); insert explicit rests to fill the gap" end raise render_error_class, "expected a placement at #{expected_position}, " \ "found one at #{found_placement.position}; insert explicit rests to fill gaps" end |