Skip to content

Commit

Permalink
add Charter#remove to remove an event
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesZh committed Jul 31, 2024
1 parent 54b68da commit 5f16c54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/sscharter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def initialize type, beat, duration_beats = nil, bpm_changes, **properties
@bpm_changes = bpm_changes
@properties = properties
@offset = 0.0
process_backtrace
@backtrace = caller.filter { _1.sub! /^#{PROJECT_DIR}\//, '' }
end

def time_at_relative_beat delta_beat
Expand Down Expand Up @@ -126,10 +126,6 @@ def inspect
"#<#@type at #@beat#{@duration_beats && " for #@duration_beats"} offset #@offset: " +
@properties.map { |k, v| "#{k}=#{v.inspect}" }.join(', ') + '>'
end

def process_backtrace
@backtrace = caller.filter { _1.sub! /^#{PROJECT_DIR}\//, '' }
end
end

# Implements homography
Expand Down Expand Up @@ -500,6 +496,10 @@ def tip_point mode, *args, **opts, &block
result
end

def remove *events
events.each { @events.delete _1 }
end

def event type, duration_beats = nil, **properties
raise OffsetError.new __method__ unless @bpm_changes
event = Event.new type, @current_beat, duration_beats, @bpm_changes, **properties
Expand Down
23 changes: 23 additions & 0 deletions test/test_sscharter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,27 @@ def test_bg_note
assert_equal event4.duration_beats, 0
end

def test_remove
chart = Charter.open __method__
chart.offset offset = rand
chart.bpm bpm = rand * 300

group1 = chart.group do
t rand(100), rand(100)
b 1
f rand(100), rand(100), rand*PI*2
b 2
end
group2 = chart.group do
t rand(100), rand(100)
b 1
f rand(100), rand(100), rand*PI*2
b 2
end
assert_equal chart.events.length, 4
chart.remove *group1
assert_equal chart.events.length, 2
assert_equal chart.events, group2
end

end

0 comments on commit 5f16c54

Please sign in to comment.