Class: Sunniesnow::Charter::Event
- Inherits:
-
Object
- Object
- Sunniesnow::Charter::Event
- Defined in:
- lib/sscharter.rb
Constant Summary collapse
- TIP_POINTABLE_TYPES =
i[tap hold flick drag]
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#beat ⇒ Object
Returns the value of attribute beat.
-
#bpm_changes ⇒ Object
readonly
Returns the value of attribute bpm_changes.
-
#duration_beats ⇒ Object
Returns the value of attribute duration_beats.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #dup ⇒ Object
- #end_time ⇒ Object
-
#initialize(type, beat, duration_beats = nil, bpm_changes, **properties) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
- #time ⇒ Object
- #time_at_relative_beat(delta_beat) ⇒ Object
- #tip_pointable? ⇒ Boolean
- #to_sunniesnow ⇒ Object
Constructor Details
#initialize(type, beat, duration_beats = nil, bpm_changes, **properties) ⇒ Event
82 83 84 85 86 87 88 89 90 |
# File 'lib/sscharter.rb', line 82 def initialize type, beat, duration_beats = nil, bpm_changes, **properties @beat = beat @duration_beats = duration_beats @type = type @bpm_changes = bpm_changes @properties = properties @offset = 0.0 @backtrace = caller.filter { _1.sub! /^#{PROJECT_DIR}\//, '' } end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
80 81 82 |
# File 'lib/sscharter.rb', line 80 def backtrace @backtrace end |
#beat ⇒ Object
Returns the value of attribute beat.
79 80 81 |
# File 'lib/sscharter.rb', line 79 def beat @beat end |
#bpm_changes ⇒ Object (readonly)
Returns the value of attribute bpm_changes.
80 81 82 |
# File 'lib/sscharter.rb', line 80 def bpm_changes @bpm_changes end |
#duration_beats ⇒ Object
Returns the value of attribute duration_beats.
79 80 81 |
# File 'lib/sscharter.rb', line 79 def duration_beats @duration_beats end |
#offset ⇒ Object
Returns the value of attribute offset.
79 80 81 |
# File 'lib/sscharter.rb', line 79 def offset @offset end |
#properties ⇒ Object
Returns the value of attribute properties.
79 80 81 |
# File 'lib/sscharter.rb', line 79 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
80 81 82 |
# File 'lib/sscharter.rb', line 80 def type @type end |
Instance Method Details
#[](key) ⇒ Object
104 105 106 |
# File 'lib/sscharter.rb', line 104 def [] key @properties[key] end |
#[]=(key, value) ⇒ Object
108 109 110 |
# File 'lib/sscharter.rb', line 108 def []= key, value @properties[key] = value end |
#dup ⇒ Object
119 120 121 122 123 |
# File 'lib/sscharter.rb', line 119 def dup result = super result.properties = @properties.dup result end |
#end_time ⇒ Object
100 101 102 |
# File 'lib/sscharter.rb', line 100 def end_time time_at_relative_beat @duration_beats || 0 end |
#inspect ⇒ Object
129 130 131 132 |
# File 'lib/sscharter.rb', line 129 def inspect "#<#@type at #@beat#{@duration_beats && " for #@duration_beats"} offset #@offset: " + @properties.map { |k, v| "#{k}=#{v.inspect}" }.join(', ') + '>' end |
#time ⇒ Object
96 97 98 |
# File 'lib/sscharter.rb', line 96 def time time_at_relative_beat 0 end |
#time_at_relative_beat(delta_beat) ⇒ Object
92 93 94 |
# File 'lib/sscharter.rb', line 92 def time_at_relative_beat delta_beat @offset + @bpm_changes.time_at(@beat + delta_beat) end |
#tip_pointable? ⇒ Boolean
125 126 127 |
# File 'lib/sscharter.rb', line 125 def tip_pointable? TIP_POINTABLE_TYPES.include? @type end |
#to_sunniesnow ⇒ Object
112 113 114 115 116 117 |
# File 'lib/sscharter.rb', line 112 def to_sunniesnow t = time properties = @properties.transform_keys &:snake_to_camel properties[:duration] = end_time - t if @duration_beats Sunniesnow::Event.new t, @type.snake_to_camel, **properties end |