diff --git a/lib/sscharter.rb b/lib/sscharter.rb index dc48979..495918b 100644 --- a/lib/sscharter.rb +++ b/lib/sscharter.rb @@ -343,6 +343,7 @@ def init_state @bpm_changes = nil @tip_point_mode_stack = [:none] @current_tip_point_stack = [] + @current_tip_point_group_stack = [] @tip_point_peak = 0 @current_duplicate = 0 @tip_point_start_to_add_stack = [nil] @@ -476,13 +477,13 @@ def tip_point mode, *args, preserve_beat: true, **opts, &block @tip_point_peak += 1 end result = group preserve_beat: do - @current_tip_point_group = @groups.last + @current_tip_point_group_stack.push @groups.last instance_eval &block end @tip_point_start_to_add_stack.pop @tip_point_mode_stack.pop @current_tip_point_stack.pop - @current_tip_point_group = nil + @current_tip_point_group_stack.pop result end @@ -515,7 +516,7 @@ def push_tip_point_start start_event return unless tip_point_start @groups.each do |group| group.push tip_point_start - break if group.equal?(@current_tip_point_group) && @tip_point_mode_stack.last != :drop + break if group.equal?(@current_tip_point_group_stack.last) && @tip_point_mode_stack.last != :drop end end diff --git a/test/test_sscharter.rb b/test/test_sscharter.rb index 6864f92..c089a98 100644 --- a/test/test_sscharter.rb +++ b/test/test_sscharter.rb @@ -553,4 +553,29 @@ def test_group_nested_in_tip_point_drop assert_equal group1.first(2), group2 end + def test_group_nested_in_tip_point_chain_twice + chart = Charter.open __method__ + chart.offset offset = rand + chart.bpm bpm = rand * 300 + + group1 = group2 = group3 = note1 = note2 = note3 = nil + chart.tip_point_chain rand, rand, rand do + group2 = tp_chain rand, rand, rand do + group3 = group do + note3 = t rand(100), rand(100) + end + note2 = t rand(100), rand(100) + end + group1 = group do + note1 = t rand(100), rand(100) + end + end + assert_equal chart.events.length, 5 + assert_equal note1[:tip_point], chart.events[4][:tip_point] + assert_equal note2[:tip_point], note3[:tip_point] + assert_equal note3[:tip_point], group2[1][:tip_point] + assert_equal group3, [note3] + assert_equal group1, [note1] + end + end