Class: Sunniesnow::Charter::Event

Inherits:
Object
  • Object
show all
Includes:
Metronomic
Defined in:
lib/sscharter/charter/event.rb

Constant Summary collapse

TIP_POINTABLE_TYPES =

The types (#type) of events that should be considered possibly visited by a tip point from the charting perspective. They affect #tip_pointable? and suggests whether this event should be visited by a tip point if it is created inside blocks in Sunniesnow::Charter#tip_point_chain and Sunniesnow::Charter#tip_point_drop. For this reason, although placeholder events can be visited by a tip point from a technical perspective, it is not included in this list.

%i[tap hold flick drag drag_flick].freeze
TIP_POINTABLE_TYPES_SET =
TIP_POINTABLE_TYPES.to_set.freeze

Instance Attribute Summary collapse

Attributes included from Metronomic

#beat, #bpm_changes, #duration_beats, #offset

Instance Method Summary collapse

Methods included from Metronomic

#<=>, #beat_state, #end_time, #time, #time_at_relative_beat

Constructor Details

#initialize(type, beat, duration_beats = nil, bpm_changes, **properties) ⇒ Event

Returns a new instance of Event.

Parameters:

  • type (Symbol)
  • beat (Rational)
  • duration_beats (Rational?) (defaults to: nil)
  • bpm_changes (BpmChangeList)
  • properties (Hash{Symbol => Numeric, String})


39
40
41
42
43
44
45
46
47
48
# File 'lib/sscharter/charter/event.rb', line 39

def initialize type, beat, duration_beats = nil, bpm_changes, **properties
	@beat = beat
	@duration_beats = duration_beats
	@type = type
	@bpm_changes = bpm_changes
	@properties = properties
	@time_dependent = TimeDependent.new beat, bpm_changes
	@offset = 0.0
	@backtrace = caller.filter { _1.sub! /^#{PROJECT_DIR}\//, '' }
end

Instance Attribute Details

#backtraceArray<String> (readonly)

Returns:

  • (Array<String>)


32
33
34
# File 'lib/sscharter/charter/event.rb', line 32

def backtrace
  @backtrace
end

#propertiesHash{Symbol => Numeric, String}

Returns:

  • (Hash{Symbol => Numeric, String})


26
27
28
# File 'lib/sscharter/charter/event.rb', line 26

def properties
  @properties
end

#time_dependentTimeDependent

Returns:



29
30
31
# File 'lib/sscharter/charter/event.rb', line 29

def time_dependent
  @time_dependent
end

#typeSymbol

Returns:

  • (Symbol)


23
24
25
# File 'lib/sscharter/charter/event.rb', line 23

def type
  @type
end

Instance Method Details

#[](key) ⇒ Numeric, String

Parameters:

  • key (Symbol)

Returns:

  • (Numeric, String)


52
53
54
# File 'lib/sscharter/charter/event.rb', line 52

def [] key
	@properties[key]
end

#[]=(key, value) ⇒ Numeric, String

Parameters:

  • key (Symbol)
  • value (Numeric, String)

Returns:

  • (Numeric, String)


59
60
61
# File 'lib/sscharter/charter/event.rb', line 59

def []= key, value
	@properties[key] = value
end

#dupEvent

TODO: use initialize_copy.

Returns:



75
76
77
78
79
80
# File 'lib/sscharter/charter/event.rb', line 75

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

#inspectString

Returns:

  • (String)


90
91
92
93
# File 'lib/sscharter/charter/event.rb', line 90

def inspect
	"#<#@type at #@beat#{@duration_beats && " for #@duration_beats"} offset #@offset: " +
	@properties.map { |k, v| "#{k}=#{v.inspect}" }.join(', ') + '>'
end

#tip_pointable?Boolean

Suggests whether this event should be visited by a tip point if it is created inside blocks in Sunniesnow::Charter#tip_point_chain and Sunniesnow::Charter#tip_point_drop.

Returns:

  • (Boolean)


85
86
87
# File 'lib/sscharter/charter/event.rb', line 85

def tip_pointable?
	TIP_POINTABLE_TYPES_SET.include? @type
end

#to_sunniesnowSunniesnow::Event

Returns:



64
65
66
67
68
69
70
71
# File 'lib/sscharter/charter/event.rb', line 64

def to_sunniesnow
	t = time
	properties = @properties.transform_keys &:snake_to_camel
	properties[:duration] = end_time - t if @duration_beats
	result = Sunniesnow::Event.new t, @type.snake_to_camel, **properties
	result.time_dependent = @time_dependent.to_sunniesnow unless @time_dependent.empty?
	result
end