Class: Sunniesnow::Charter::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/sscharter.rb

Constant Summary collapse

TIP_POINTABLE_TYPES =
i[tap hold flick drag]

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backtraceObject (readonly)

Returns the value of attribute backtrace.



80
81
82
# File 'lib/sscharter.rb', line 80

def backtrace
  @backtrace
end

#beatObject

Returns the value of attribute beat.



79
80
81
# File 'lib/sscharter.rb', line 79

def beat
  @beat
end

#bpm_changesObject (readonly)

Returns the value of attribute bpm_changes.



80
81
82
# File 'lib/sscharter.rb', line 80

def bpm_changes
  @bpm_changes
end

#duration_beatsObject

Returns the value of attribute duration_beats.



79
80
81
# File 'lib/sscharter.rb', line 79

def duration_beats
  @duration_beats
end

#offsetObject

Returns the value of attribute offset.



79
80
81
# File 'lib/sscharter.rb', line 79

def offset
  @offset
end

#propertiesObject

Returns the value of attribute properties.



79
80
81
# File 'lib/sscharter.rb', line 79

def properties
  @properties
end

#typeObject (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

#dupObject



119
120
121
122
123
# File 'lib/sscharter.rb', line 119

def dup
  result = super
  result.properties = @properties.dup
  result
end

#end_timeObject



100
101
102
# File 'lib/sscharter.rb', line 100

def end_time
  time_at_relative_beat @duration_beats || 0
end

#inspectObject



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

#timeObject



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_sunniesnowObject



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