Beispiel #1
0
def _load_memo1_file(lines: List[str]) -> Song:
    parser = Memo1Parser()
    for i, raw_line in enumerate(lines, start=1):
        try:
            parser.load_line(raw_line)
        except Exception as e:
            raise SyntaxError(f"On line {i}\n{e}")

    parser.finish_last_few_notes()
    metadata = Metadata(
        title=parser.title,
        artist=parser.artist,
        audio=none_or(Path, parser.music),
        cover=none_or(Path, parser.jacket),
    )
    if parser.preview_start is not None:
        metadata.preview = Preview(start=SecondsTime(parser.preview_start) /
                                   1000,
                                   length=SecondsTime(10))

    timing = Timing(events=parser.timing_events,
                    beat_zero_offset=SecondsTime(parser.offset) / 1000)
    charts = {
        parser.difficulty or "EXT":
        Chart(
            level=Decimal(parser.level),
            timing=timing,
            notes=sorted(parser.notes(), key=lambda n: (n.time, n.position)),
        )
    }
    return Song(metadata=metadata, charts=charts)
Beispiel #2
0
def test_that_a_single_long_note_roundtrips(note: LongNote) -> None:
    timing = Timing(
        events=[BPMEvent(BeatsTime(0), Decimal(120))], beat_zero_offset=SecondsTime(0)
    )
    chart = Chart(level=Decimal(0), timing=timing, notes=[note])
    metadata = Metadata("", "", Path(""), Path(""))
    string_io = _dump_mono_column_chart("", chart, metadata, timing)
    chart_text = string_io.getvalue()
    parser = MonoColumnParser()
    for line in chart_text.split("\n"):
        parser.load_line(line)
    actual = set(parser.notes())
    assert set([note]) == actual
Beispiel #3
0
def chart(
        draw: DrawFunc,
        timing_strat: st.SearchStrategy[Timing] = timing_info(),
        notes_strat: st.SearchStrategy[Iterable[Union[TapNote,
                                                      LongNote]]] = notes(),
        level_strat: st.SearchStrategy[Union[int, Decimal]] = level(),
) -> Chart:
    level = Decimal(draw(level_strat))
    timing = draw(timing_strat)
    notes = draw(notes_strat)
    return Chart(
        level=level,
        timing=timing,
        notes=sorted(notes, key=lambda n: (n.time, n.position)),
    )
Beispiel #4
0
def test_that_notes_roundtrip(notes: List[Union[TapNote, LongNote]]) -> None:
    timing = Timing(events=[BPMEvent(BeatsTime(0), Decimal(120))],
                    beat_zero_offset=SecondsTime(0))
    chart = Chart(
        level=Decimal(0),
        timing=timing,
        notes=sorted(notes, key=lambda n: (n.time, n.position)),
    )
    metadata = Metadata("", "", Path(""), Path(""))
    string_io = _dump_memo2_chart("", chart, metadata, timing)
    chart_text = string_io.getvalue()
    parser = Memo2Parser()
    for line in chart_text.split("\n"):
        parser.load_line(line)
    parser.finish_last_few_notes()
    actual = set(parser.notes())
    assert notes == actual
Beispiel #5
0
def test_that_a_set_of_tap_notes_roundtrip(notes: Set[TapNote]) -> None:
    timing = Timing(
        events=[BPMEvent(BeatsTime(0), Decimal(120))], beat_zero_offset=SecondsTime(0)
    )
    chart = Chart(
        level=Decimal(0),
        timing=timing,
        notes=sorted(notes, key=lambda n: (n.time, n.position)),
    )
    metadata = Metadata("", "", Path(""), Path(""))
    string_io = _dump_mono_column_chart("", chart, metadata, timing)
    chart_text = string_io.getvalue()
    parser = MonoColumnParser()
    for line in chart_text.split("\n"):
        parser.load_line(line)
    actual = set(parser.notes())
    assert notes == actual