Class: HeadMusic::Content::Position
- Inherits:
-
Object
- Object
- HeadMusic::Content::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.
14 15 16 17 18 19 20 21 |
# File 'lib/head_music/content/position.rb', line 14 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.
10 11 12 |
# File 'lib/head_music/content/position.rb', line 10 def @bar_number end |
#composition ⇒ Object (readonly)
Returns the value of attribute composition.
10 11 12 |
# File 'lib/head_music/content/position.rb', line 10 def composition @composition end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
10 11 12 |
# File 'lib/head_music/content/position.rb', line 10 def count @count end |
#tick ⇒ Object (readonly)
Returns the value of attribute tick.
10 11 12 |
# File 'lib/head_music/content/position.rb', line 10 def tick @tick end |
Instance Method Details
#+(other) ⇒ Object
61 62 63 64 |
# File 'lib/head_music/content/position.rb', line 61 def +(other) other = HeadMusic::Content::RhythmicValue.new(other) if [HeadMusic::RhythmicUnit, Symbol, String].include?(other.class) self.class.new(composition, , count, tick + other.ticks) end |
#<=>(other) ⇒ Object
44 45 46 47 |
# File 'lib/head_music/content/position.rb', line 44 def <=>(other) other = self.class.new(composition, other) if other.is_a?(String) && other =~ /\D/ values <=> other.values end |
#code ⇒ Object
27 28 29 30 |
# File 'lib/head_music/content/position.rb', line 27 def code tick_string = tick.to_s.rjust(3, "0") [, count, tick_string].join(":") end |
#meter ⇒ Object
23 24 25 |
# File 'lib/head_music/content/position.rb', line 23 def meter composition.meter_at() end |
#start_of_next_bar ⇒ Object
66 67 68 |
# File 'lib/head_music/content/position.rb', line 66 def self.class.new(composition, + 1, 1, 0) end |
#state ⇒ Object
32 33 34 |
# File 'lib/head_music/content/position.rb', line 32 def state [composition.name, code].join(" ") end |
#strength ⇒ Object
49 50 51 |
# File 'lib/head_music/content/position.rb', line 49 def strength meter.beat_strength(count, tick: tick) end |
#strong? ⇒ Boolean
53 54 55 |
# File 'lib/head_music/content/position.rb', line 53 def strong? strength >= 80 end |
#values ⇒ Object
36 37 38 |
# File 'lib/head_music/content/position.rb', line 36 def values [, count, tick] end |
#weak? ⇒ Boolean
57 58 59 |
# File 'lib/head_music/content/position.rb', line 57 def weak? !strong? end |
#within_placement?(placement) ⇒ Boolean
40 41 42 |
# File 'lib/head_music/content/position.rb', line 40 def within_placement?(placement) placement.position <= self && placement.next_position > self end |