Skip to content

Commit 5f16c54

Browse files
committed
add Charter#remove to remove an event
1 parent 54b68da commit 5f16c54

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib/sscharter.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def initialize type, beat, duration_beats = nil, bpm_changes, **properties
8282
@bpm_changes = bpm_changes
8383
@properties = properties
8484
@offset = 0.0
85-
process_backtrace
85+
@backtrace = caller.filter { _1.sub! /^#{PROJECT_DIR}\//, '' }
8686
end
8787

8888
def time_at_relative_beat delta_beat
@@ -126,10 +126,6 @@ def inspect
126126
"#<#@type at #@beat#{@duration_beats && " for #@duration_beats"} offset #@offset: " +
127127
@properties.map { |k, v| "#{k}=#{v.inspect}" }.join(', ') + '>'
128128
end
129-
130-
def process_backtrace
131-
@backtrace = caller.filter { _1.sub! /^#{PROJECT_DIR}\//, '' }
132-
end
133129
end
134130

135131
# Implements homography
@@ -500,6 +496,10 @@ def tip_point mode, *args, **opts, &block
500496
result
501497
end
502498

499+
def remove *events
500+
events.each { @events.delete _1 }
501+
end
502+
503503
def event type, duration_beats = nil, **properties
504504
raise OffsetError.new __method__ unless @bpm_changes
505505
event = Event.new type, @current_beat, duration_beats, @bpm_changes, **properties

test/test_sscharter.rb

+23
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,27 @@ def test_bg_note
494494
assert_equal event4.duration_beats, 0
495495
end
496496

497+
def test_remove
498+
chart = Charter.open __method__
499+
chart.offset offset = rand
500+
chart.bpm bpm = rand * 300
501+
502+
group1 = chart.group do
503+
t rand(100), rand(100)
504+
b 1
505+
f rand(100), rand(100), rand*PI*2
506+
b 2
507+
end
508+
group2 = chart.group do
509+
t rand(100), rand(100)
510+
b 1
511+
f rand(100), rand(100), rand*PI*2
512+
b 2
513+
end
514+
assert_equal chart.events.length, 4
515+
chart.remove *group1
516+
assert_equal chart.events.length, 2
517+
assert_equal chart.events, group2
518+
end
519+
497520
end

0 commit comments

Comments
 (0)