Class: HeadMusic::Content::Placement
- Inherits:
-
Object
- Object
- HeadMusic::Content::Placement
- Includes:
- Comparable
- Defined in:
- lib/head_music/content/placement.rb
Overview
A placement is a note or rest at a position within a voice in a composition
Instance Attribute Summary collapse
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#rhythmic_value ⇒ Object
readonly
Returns the value of attribute rhythmic_value.
-
#voice ⇒ Object
readonly
Returns the value of attribute voice.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #during?(other_placement) ⇒ Boolean
-
#initialize(voice, position, rhythmic_value, pitch = nil) ⇒ Placement
constructor
A new instance of Placement.
- #next_position ⇒ Object
- #note? ⇒ Boolean
- #rest? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(voice, position, rhythmic_value, pitch = nil) ⇒ Placement
Returns a new instance of Placement.
15 16 17 |
# File 'lib/head_music/content/placement.rb', line 15 def initialize(voice, position, rhythmic_value, pitch = nil) ensure_attributes(voice, position, rhythmic_value, pitch) end |
Instance Attribute Details
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
10 11 12 |
# File 'lib/head_music/content/placement.rb', line 10 def pitch @pitch end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
10 11 12 |
# File 'lib/head_music/content/placement.rb', line 10 def position @position end |
#rhythmic_value ⇒ Object (readonly)
Returns the value of attribute rhythmic_value.
10 11 12 |
# File 'lib/head_music/content/placement.rb', line 10 def rhythmic_value @rhythmic_value end |
#voice ⇒ Object (readonly)
Returns the value of attribute voice.
10 11 12 |
# File 'lib/head_music/content/placement.rb', line 10 def voice @voice end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 |
# File 'lib/head_music/content/placement.rb', line 31 def <=>(other) position <=> other.position end |
#during?(other_placement) ⇒ Boolean
35 36 37 |
# File 'lib/head_music/content/placement.rb', line 35 def during?(other_placement) starts_during?(other_placement) || ends_during?(other_placement) || wraps?(other_placement) end |
#next_position ⇒ Object
27 28 29 |
# File 'lib/head_music/content/placement.rb', line 27 def next_position @next_position ||= position + rhythmic_value end |
#note? ⇒ Boolean
19 20 21 |
# File 'lib/head_music/content/placement.rb', line 19 def note? pitch end |
#rest? ⇒ Boolean
23 24 25 |
# File 'lib/head_music/content/placement.rb', line 23 def rest? !note? end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/head_music/content/placement.rb', line 39 def to_s "#{rhythmic_value} #{pitch || "rest"} at #{position}" end |