Class: HeadMusic::Placement

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(voice, position, rhythmic_value, pitch = nil) ⇒ Placement

Returns a new instance of Placement.



12
13
14
# 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

Instance Attribute Details

#pitchObject (readonly)

Returns the value of attribute pitch.



7
8
9
# File 'lib/head_music/content/placement.rb', line 7

def pitch
  @pitch
end

#positionObject (readonly)

Returns the value of attribute position.



7
8
9
# File 'lib/head_music/content/placement.rb', line 7

def position
  @position
end

#rhythmic_valueObject (readonly)

Returns the value of attribute rhythmic_value.



7
8
9
# File 'lib/head_music/content/placement.rb', line 7

def rhythmic_value
  @rhythmic_value
end

#voiceObject (readonly)

Returns the value of attribute voice.



7
8
9
# File 'lib/head_music/content/placement.rb', line 7

def voice
  @voice
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/head_music/content/placement.rb', line 28

def <=>(other)
  position <=> other.position
end

#during?(other_placement) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# 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_positionObject



24
25
26
# File 'lib/head_music/content/placement.rb', line 24

def next_position
  @next_position ||= position + rhythmic_value
end

#note?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/head_music/content/placement.rb', line 16

def note?
  pitch
end

#rest?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/head_music/content/placement.rb', line 20

def rest?
  !note?
end

#to_sObject



36
37
38
# File 'lib/head_music/content/placement.rb', line 36

def to_s
  "#{rhythmic_value} #{pitch || "rest"} at #{position}"
end