Class: HeadMusic::Position
- Inherits:
-
Object
- Object
- HeadMusic::Position
- Includes:
- Comparable
- Defined in:
- lib/head_music/content/position.rb
Overview
A position is a moment in time within the rhythmic framework of a composition.
Instance Attribute Summary collapse
-
#bar_number ⇒ Object
readonly
Returns the value of attribute bar_number.
-
#composition ⇒ Object
readonly
Returns the value of attribute composition.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#tick ⇒ Object
readonly
Returns the value of attribute tick.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<=>(other) ⇒ Object
- #code ⇒ Object
-
#initialize(composition, code_or_bar, count = nil, tick = nil) ⇒ Position
constructor
A new instance of Position.
- #meter ⇒ Object
- #start_of_next_bar ⇒ Object
- #state ⇒ Object
- #strength ⇒ Object
- #strong? ⇒ Boolean
- #values ⇒ Object
- #weak? ⇒ Boolean
- #within_placement?(placement) ⇒ Boolean
Constructor Details
#initialize(composition, code_or_bar, count = nil, tick = nil) ⇒ Position
Returns a new instance of Position.
11 12 13 14 15 16 17 18 |
# File 'lib/head_music/content/position.rb', line 11 def initialize(composition, , count = nil, tick = nil) if .is_a?(String) && =~ /\D/ , count, tick = .split(/\D+/) ensure_state(composition, , count, tick) else ensure_state(composition, , count, tick) end end |
Instance Attribute Details
#bar_number ⇒ Object (readonly)
Returns the value of attribute bar_number.
7 8 9 |
# File 'lib/head_music/content/position.rb', line 7 def @bar_number end |
#composition ⇒ Object (readonly)
Returns the value of attribute composition.
7 8 9 |
# File 'lib/head_music/content/position.rb', line 7 def composition @composition end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
7 8 9 |
# File 'lib/head_music/content/position.rb', line 7 def count @count end |
#tick ⇒ Object (readonly)
Returns the value of attribute tick.
7 8 9 |
# File 'lib/head_music/content/position.rb', line 7 def tick @tick end |
Instance Method Details
#+(other) ⇒ Object
58 59 60 61 |
# File 'lib/head_music/content/position.rb', line 58 def +(other) other = HeadMusic::RhythmicValue.new(other) if [HeadMusic::RhythmicUnit, Symbol, String].include?(other.class) self.class.new(composition, , count, tick + other.ticks) end |
#<=>(other) ⇒ Object
41 42 43 44 |
# File 'lib/head_music/content/position.rb', line 41 def <=>(other) other = self.class.new(composition, other) if other.is_a?(String) && other =~ /\D/ values <=> other.values end |
#code ⇒ Object
24 25 26 27 |
# File 'lib/head_music/content/position.rb', line 24 def code tick_string = tick.to_s.rjust(3, "0") [, count, tick_string].join(":") end |
#meter ⇒ Object
20 21 22 |
# File 'lib/head_music/content/position.rb', line 20 def meter composition.meter_at() end |
#start_of_next_bar ⇒ Object
63 64 65 |
# File 'lib/head_music/content/position.rb', line 63 def self.class.new(composition, + 1, 1, 0) end |
#state ⇒ Object
29 30 31 |
# File 'lib/head_music/content/position.rb', line 29 def state [composition.name, code].join(" ") end |
#strength ⇒ Object
46 47 48 |
# File 'lib/head_music/content/position.rb', line 46 def strength meter.beat_strength(count, tick: tick) end |
#strong? ⇒ Boolean
50 51 52 |
# File 'lib/head_music/content/position.rb', line 50 def strong? strength >= 80 end |
#values ⇒ Object
33 34 35 |
# File 'lib/head_music/content/position.rb', line 33 def values [, count, tick] end |
#weak? ⇒ Boolean
54 55 56 |
# File 'lib/head_music/content/position.rb', line 54 def weak? !strong? end |
#within_placement?(placement) ⇒ Boolean
37 38 39 |
# File 'lib/head_music/content/position.rb', line 37 def within_placement?(placement) placement.position <= self && placement.next_position > self end |