Class: HeadMusic::Content::Voice::Continuity
- Inherits:
-
Object
- Object
- HeadMusic::Content::Voice::Continuity
- Defined in:
- lib/head_music/content/voice/continuity.rb
Overview
Examines a voice’s placements for the first break in its coverage of time. A voice is continuous when its first placement starts a bar and every later placement begins where the one before it ends.
Instance Attribute Summary collapse
-
#composition ⇒ Object
readonly
Returns the value of attribute composition.
-
#placements ⇒ Object
readonly
Returns the value of attribute placements.
Instance Method Summary collapse
-
#bar_start_position(placement) ⇒ Object
private
-
#first_gap ⇒ Object
Returns nil when the placements are contiguous, or [expected_position, found_placement] for the first gap.
-
#initialize(composition, placements) ⇒ Continuity
constructor
A new instance of Continuity.
-
#interior_gap ⇒ Object
private
-
#leading_gap ⇒ Object
private
-
#starts_its_bar?(placement) ⇒ Boolean
private
Constructor Details
#initialize(composition, placements) ⇒ Continuity
Returns a new instance of Continuity.
8 9 10 11 |
# File 'lib/head_music/content/voice/continuity.rb', line 8 def initialize(composition, placements) @composition = composition @placements = placements end |
Instance Attribute Details
#composition ⇒ Object (readonly)
Returns the value of attribute composition.
6 7 8 |
# File 'lib/head_music/content/voice/continuity.rb', line 6 def composition @composition end |
#placements ⇒ Object (readonly)
Returns the value of attribute placements.
6 7 8 |
# File 'lib/head_music/content/voice/continuity.rb', line 6 def placements @placements end |
Instance Method Details
#bar_start_position(placement) ⇒ Object (private)
43 44 45 |
# File 'lib/head_music/content/voice/continuity.rb', line 43 def (placement) HeadMusic::Content::Position.new(composition, placement.position., 1, 0) end |
#first_gap ⇒ Object
Returns nil when the placements are contiguous, or [expected_position, found_placement] for the first gap.
15 16 17 18 19 |
# File 'lib/head_music/content/voice/continuity.rb', line 15 def first_gap return if placements.empty? leading_gap || interior_gap end |
#interior_gap ⇒ Object (private)
30 31 32 33 34 35 36 |
# File 'lib/head_music/content/voice/continuity.rb', line 30 def interior_gap placements.each_cons(2) do |previous, current| expected_position = previous.next_position return [expected_position, current] unless current.position == expected_position end nil end |
#leading_gap ⇒ Object (private)
23 24 25 26 27 28 |
# File 'lib/head_music/content/voice/continuity.rb', line 23 def leading_gap first = placements.first return if (first) [(first), first] end |
#starts_its_bar?(placement) ⇒ Boolean (private)
38 39 40 41 |
# File 'lib/head_music/content/voice/continuity.rb', line 38 def (placement) position = placement.position position.count == 1 && position.tick.zero? end |