Class: Clef::Layout::Spacing
- Inherits:
-
Object
- Object
- Clef::Layout::Spacing
- Defined in:
- lib/clef/layout/spacing.rb
Instance Attribute Summary collapse
-
#extra_moments ⇒ Object
readonly
Returns the value of attribute extra_moments.
-
#stretch_factor ⇒ Object
readonly
Returns the value of attribute stretch_factor.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#timeline ⇒ Object
readonly
Returns the value of attribute timeline.
Instance Method Summary collapse
- #compute ⇒ Hash{Clef::Ir::Moment=>Float}
-
#initialize(timeline, style, extra_moments: []) ⇒ Spacing
constructor
A new instance of Spacing.
- #stretch_to_fit(target_width) ⇒ Float
Constructor Details
#initialize(timeline, style, extra_moments: []) ⇒ Spacing
Returns a new instance of Spacing.
11 12 13 14 15 16 |
# File 'lib/clef/layout/spacing.rb', line 11 def initialize(timeline, style, extra_moments: []) @timeline = timeline @style = style @extra_moments = extra_moments @stretch_factor = 1.0 end |
Instance Attribute Details
#extra_moments ⇒ Object (readonly)
Returns the value of attribute extra_moments.
6 7 8 |
# File 'lib/clef/layout/spacing.rb', line 6 def extra_moments @extra_moments end |
#stretch_factor ⇒ Object (readonly)
Returns the value of attribute stretch_factor.
6 7 8 |
# File 'lib/clef/layout/spacing.rb', line 6 def stretch_factor @stretch_factor end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
6 7 8 |
# File 'lib/clef/layout/spacing.rb', line 6 def style @style end |
#timeline ⇒ Object (readonly)
Returns the value of attribute timeline.
6 7 8 |
# File 'lib/clef/layout/spacing.rb', line 6 def timeline @timeline end |
Instance Method Details
#compute ⇒ Hash{Clef::Ir::Moment=>Float}
19 20 21 22 23 24 |
# File 'lib/clef/layout/spacing.rb', line 19 def compute moments = (timeline.each_moment.to_a + extra_moments).uniq.sort return {} if moments.empty? build_positions(moments) end |
#stretch_to_fit(target_width) ⇒ Float
28 29 30 31 32 33 34 35 36 |
# File 'lib/clef/layout/spacing.rb', line 28 def stretch_to_fit(target_width) positions = compute return stretch_factor if positions.empty? current_width = positions.values.max return stretch_factor unless current_width.positive? @stretch_factor *= target_width.to_f / current_width end |