def memon_0_2_0_compatible_song(draw: DrawFunc) -> song.Song: """Memon v0.2.0 does not support preview_file""" random_song: song.Song = draw( jbst.song( diffs_strat=memon_diffs(), chart_strat=jbst.chart(timing_strat=st.none()), common_timing_strat=jbst.timing_info(with_bpm_changes=False), )) random_song.metadata.preview_file = None return random_song
def memo_compatible_song(draw: DrawFunc) -> song.Song: """Memo only supports one difficulty per file""" diff = draw(st.sampled_from(list(d.value for d in song.Difficulty))) chart = draw( jbst.chart( timing_strat=jbst.timing_info(with_bpm_changes=True), notes_strat=jbst.notes(), )) metadata: song.Metadata = draw(memo_compatible_metadata()) return song.Song( metadata=metadata, charts={diff: chart}, )
def eve_compatible_song(draw: DrawFunc) -> song.Song: """eve only keeps notes, timing info and difficulty, the precision you can get out of it is also severly limited""" diff = draw(st.sampled_from(list(song.Difficulty))) chart = draw( jbst.chart( timing_strat=jbst.timing_info( with_bpm_changes=True, bpm_strat=st.decimals(min_value=50, max_value=300, places=2), beat_zero_offset_strat=st.decimals(min_value=0, max_value=20, places=2), time_strat=jbst.beat_time( min_section=1, max_section=10, denominator_strat=st.sampled_from([4, 3]), ), ), notes_strat=jbst.notes( note_strat=st.one_of( jbst.tap_note(time_strat=simple_beat_strat), jbst.long_note( time_strat=simple_beat_strat, duration_strat=jbst.beat_time( min_numerator=1, max_section=3, denominator_strat=st.sampled_from([4, 3]), ), ), ), beat_time_strat=simple_beat_strat, ), level_strat=st.just(Decimal(0)), )) return song.Song( metadata=song.Metadata(), charts={diff: chart}, )
from hypothesis import given from hypothesis import strategies as st from jubeatools import song from jubeatools.formats.konami.commons import EveLong from jubeatools.formats.timemap import TimeMap from jubeatools.testutils import strategies as jbst @given( jbst.long_note(), jbst.timing_info( with_bpm_changes=True, bpm_strat=st.decimals(min_value=1, max_value=1000, places=2), beat_zero_offset_strat=st.decimals(min_value=0, max_value=20, places=2), ), ) def test_that_long_note_roundtrips( long_note: song.LongNote, timing: song.Timing ) -> None: time_map = TimeMap.from_timing(timing) original = EveLong.from_jubeatools(long_note, time_map) recovered = EveLong.from_value(original.value) assert recovered == original
from fractions import Fraction from hypothesis import given from jubeatools import song from jubeatools.formats.timemap import TimeMap from jubeatools.testutils import strategies as jbst from jubeatools.utils import group_by @given(jbst.timing_info(with_bpm_changes=True), jbst.beat_time()) def test_that_seconds_at_beat_works_like_the_naive_approach( timing: song.Timing, beat: song.BeatsTime) -> None: time_map = TimeMap.from_timing(timing) expected = naive_approach(timing, beat) actual = time_map.fractional_seconds_at(beat) assert actual == expected def naive_approach(beats: song.Timing, beat: song.BeatsTime) -> Fraction: if beat < 0: raise ValueError("Can't compute seconds at negative beat") if not beats.events: raise ValueError("No BPM defined") grouped_by_time = group_by(beats.events, key=lambda e: e.time) for time, events in grouped_by_time.items(): if len(events) > 1: raise ValueError( f"Multiple BPMs defined on beat {time} : {events}")