class HeadMusic::Placement
A placement is a note or rest at a position within a voice in a composition
Attributes
pitch[R]
position[R]
rhythmic_value[R]
voice[R]
Public Class Methods
new(voice, position, rhythmic_value, pitch = nil)
click to toggle source
# File lib/head_music/content/placement.rb, line 12 def initialize(voice, position, rhythmic_value, pitch = nil) ensure_attributes(voice, position, rhythmic_value, pitch) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/head_music/content/placement.rb, line 28 def <=>(other) position <=> other.position end
during?(other_placement)
click to toggle source
# File lib/head_music/content/placement.rb, line 32 def during?(other_placement) starts_during?(other_placement) || ends_during?(other_placement) || wraps?(other_placement) end
next_position()
click to toggle source
# File lib/head_music/content/placement.rb, line 24 def next_position @next_position ||= position + rhythmic_value end
note?()
click to toggle source
# File lib/head_music/content/placement.rb, line 16 def note? pitch end
rest?()
click to toggle source
# File lib/head_music/content/placement.rb, line 20 def rest? !note? end
to_s()
click to toggle source
# File lib/head_music/content/placement.rb, line 36 def to_s "#{rhythmic_value} #{pitch || 'rest'} at #{position}" end
Private Instance Methods
ends_during?(other_placement)
click to toggle source
# File lib/head_music/content/placement.rb, line 46 def ends_during?(other_placement) next_position > other_placement.position && next_position <= other_placement.next_position end
ensure_attributes(voice, position, rhythmic_value, pitch)
click to toggle source
# File lib/head_music/content/placement.rb, line 54 def ensure_attributes(voice, position, rhythmic_value, pitch) @voice = voice ensure_position(position) @rhythmic_value = HeadMusic::RhythmicValue.get(rhythmic_value) @pitch = HeadMusic::Pitch.get(pitch) end
ensure_position(position)
click to toggle source
# File lib/head_music/content/placement.rb, line 61 def ensure_position(position) @position = if position.is_a?(HeadMusic::Position) position else HeadMusic::Position.new(composition, position) end end
starts_during?(other_placement)
click to toggle source
# File lib/head_music/content/placement.rb, line 42 def starts_during?(other_placement) position >= other_placement.position && position < other_placement.next_position end
wraps?(other_placement)
click to toggle source
# File lib/head_music/content/placement.rb, line 50 def wraps?(other_placement) position <= other_placement.position && next_position >= other_placement.next_position end