Class: Vizcore::DSL::TimelineBuilder
- Inherits:
-
Object
- Object
- Vizcore::DSL::TimelineBuilder
- Defined in:
- lib/vizcore/dsl/timeline_builder.rb
Overview
Collects ordered timeline scene markers and converts them to transitions.
Defined Under Namespace
Classes: Point
Constant Summary collapse
- DEFAULT_BEATS_PER_BAR =
4
Instance Method Summary collapse
-
#at(position, scene:) ⇒ Hash
Add a scene marker at a timeline position.
- #bars(value, beats_per_bar: nil) ⇒ Point
- #beats(value) ⇒ Point
-
#evaluate { ... } ⇒ Vizcore::DSL::TimelineBuilder
Evaluate a timeline block.
-
#initialize(beats_per_bar: DEFAULT_BEATS_PER_BAR) ⇒ TimelineBuilder
constructor
A new instance of TimelineBuilder.
- #seconds(value) ⇒ Point
-
#to_h ⇒ Array<Hash>
Serialized marker definitions.
-
#transitions ⇒ Array<Hash>
Generated scene transitions.
Constructor Details
#initialize(beats_per_bar: DEFAULT_BEATS_PER_BAR) ⇒ TimelineBuilder
Returns a new instance of TimelineBuilder.
11 12 13 14 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 11 def initialize(beats_per_bar: DEFAULT_BEATS_PER_BAR) @beats_per_bar = positive_integer(, "beats_per_bar") @entries = [] end |
Instance Method Details
#at(position, scene:) ⇒ Hash
Add a scene marker at a timeline position.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 31 def at(position, scene:) point = normalize_position(position) entry = { at: point.value, unit: point.unit, scene: scene.to_sym } @entries << entry entry end |
#bars(value, beats_per_bar: nil) ⇒ Point
57 58 59 60 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 57 def (value, beats_per_bar: nil) beats_per_measure = .nil? ? @beats_per_bar : positive_integer(, "beats_per_bar") beats(non_negative_float(value, "timeline bars") * beats_per_measure) end |
#beats(value) ⇒ Point
50 51 52 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 50 def beats(value) Point.new(value: non_negative_float(value, "timeline beats"), unit: :beats) end |
#evaluate { ... } ⇒ Vizcore::DSL::TimelineBuilder
Evaluate a timeline block.
20 21 22 23 24 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 20 def evaluate(&block) instance_eval(&block) if block validate_entries! self end |
#seconds(value) ⇒ Point
44 45 46 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 44 def seconds(value) Point.new(value: non_negative_float(value, "timeline seconds"), unit: :seconds) end |
#to_h ⇒ Array<Hash>
Returns serialized marker definitions.
63 64 65 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 63 def to_h @entries.map(&:dup) end |
#transitions ⇒ Array<Hash>
Returns generated scene transitions.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vizcore/dsl/timeline_builder.rb', line 68 def transitions @entries.each_cons(2).map do |from_entry, to_entry| delta = to_entry.fetch(:at) - from_entry.fetch(:at) { from: from_entry.fetch(:scene), to: to_entry.fetch(:scene), trigger: trigger_for(delta, from_entry.fetch(:unit)) } end end |