Skip to content

Commit

Permalink
Fixes #9 and adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
donmai-me committed Dec 17, 2021
1 parent 622ed9d commit b56ae69
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
25 changes: 17 additions & 8 deletions maiconverter/simai/simainote.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,28 @@ def pattern_from_int(
dict_result = inv_slide_dict.get(pattern)
if dict_result is not None:
return dict_result, None
elif pattern in [2, 3]:
if pattern in [2, 3]:
# Have I told you how much I hate the simai format?
is_cw = pattern == 3
distance = slide_distance(start_position, end_position, is_cw)
if distance <= 3:
if 0 < distance <= 3:
return "^", None
elif (start_position in top_list and is_cw) or not (
if distance == 0:
if start_position in top_list and is_cw:
return ">", None
if start_position in top_list and not is_cw:
return "<", None
if start_position not in top_list and is_cw:
return "<", None

return ">", None
if (start_position in top_list and is_cw) or not (
start_position in top_list or is_cw
):
return ">", None
else:
return "<", None
elif pattern in [11, 12]:

return "<", None
if pattern in [11, 12]:
if pattern == 11:
reflect_position = start_position - 2
if reflect_position < 0:
Expand All @@ -211,8 +220,8 @@ def pattern_from_int(
reflect_position -= 8

return "V", reflect_position
else:
raise ValueError("Unknown pattern: " + str(pattern))

raise ValueError(f"Unknown pattern: {pattern}")


def pattern_to_int(slide_note: SlideNote) -> int:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_ma2tosimai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from maiconverter.maima2 import MaiMa2
from maiconverter.converter import ma2_to_simai


def test_slide360_conversion():
"""Tests whether a ma2 360 degree slide is properly converted in Simai.
Addresses https://github.com/donmai-me/MaiConverter/issues/9"""
ma2_cw_360_1 = MaiMa2()
ma2_cw_360_1.set_bpm(0.0, 120)
ma2_cw_360_1.add_slide(1.0, 1, 1, 1.0, 3) # Pattern 3 is CW

ma2_cw_360_2 = MaiMa2()
ma2_cw_360_2.set_bpm(0.0, 120)
ma2_cw_360_2.add_slide(1.0, 4, 4, 1.0, 3) # Pattern 3 is CW

ma2_ccw_360_1 = MaiMa2()
ma2_ccw_360_1.set_bpm(0.0, 120)
ma2_ccw_360_1.add_slide(1.0, 1, 1, 1.0, 2) # Pattern 2 is CCW

ma2_ccw_360_2 = MaiMa2()
ma2_ccw_360_2.set_bpm(0.0, 120)
ma2_ccw_360_2.add_slide(1.0, 4, 4, 1.0, 2) # Pattern 2 is CCW

simai_cw_360_1 = ma2_to_simai(ma2_cw_360_1)
assert len(simai_cw_360_1.notes) == 1
simai_cw_360_slide = simai_cw_360_1.notes[0]
assert simai_cw_360_slide.position == simai_cw_360_slide.end_position
assert simai_cw_360_slide.pattern == ">"

simai_cw_360_2 = ma2_to_simai(ma2_cw_360_2)
assert len(simai_cw_360_2.notes) == 1
simai_cw_360_slide = simai_cw_360_2.notes[0]
assert simai_cw_360_slide.position == simai_cw_360_slide.end_position
assert simai_cw_360_slide.pattern == "<"

simai_ccw_360_1 = ma2_to_simai(ma2_ccw_360_1)
assert len(simai_ccw_360_1.notes) == 1
simai_ccw_360_slide = simai_ccw_360_1.notes[0]
assert simai_ccw_360_slide.position == simai_ccw_360_slide.end_position
assert simai_ccw_360_slide.pattern == "<"

simai_ccw_360_2 = ma2_to_simai(ma2_ccw_360_2)
assert len(simai_ccw_360_2.notes) == 1
simai_ccw_360_slide = simai_ccw_360_2.notes[0]
assert simai_ccw_360_slide.position == simai_ccw_360_slide.end_position
assert simai_ccw_360_slide.pattern == ">"

0 comments on commit b56ae69

Please sign in to comment.