Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def make_tap_note(ticks: int, value: int, time_map: TimeMap,
                  beat_snap: int) -> song.TapNote:
    seconds = ticks_to_seconds(ticks)
    raw_beats = time_map.beats_at(seconds)
    beats = round_beats(raw_beats, beat_snap)
    position = song.NotePosition.from_index(value)
    return song.TapNote(time=beats, position=position)
Ejemplo n.º 3
0
def make_long_note(ticks: int, value: int, time_map: TimeMap,
                   beat_snap: int) -> song.LongNote:
    seconds = ticks_to_seconds(ticks)
    raw_beats = time_map.beats_at(seconds)
    beats = round_beats(raw_beats, beat_snap)
    eve_long = EveLong.from_value(value)
    seconds_duration = ticks_to_seconds(eve_long.duration)
    raw_beats_duration = time_map.beats_at(seconds +
                                           seconds_duration) - raw_beats
    beats_duration = round_beats(raw_beats_duration, beat_snap)
    position = song.NotePosition.from_index(eve_long.position)
    direction = VALUE_TO_DIRECTION[eve_long.direction]
    step_vector = song.TAIL_DIRECTION_TO_OUTWARDS_VECTOR[direction]
    raw_tail_pos = position + (eve_long.length * step_vector)
    tail_pos = song.NotePosition.from_raw_position(raw_tail_pos)
    return song.LongNote(time=beats,
                         position=position,
                         duration=beats_duration,
                         tail_tip=tail_pos)
Ejemplo n.º 4
0
def make_chart_from_events(events: Iterable[Event],
                           beat_snap: int = 240) -> song.Chart:
    events_by_command = group_by(events, lambda e: e.command)
    bpms = [
        BPMAtSecond(seconds=ticks_to_seconds(e.time),
                    BPM=value_to_truncated_bpm(e.value))
        for e in sorted(events_by_command[Command.TEMPO])
    ]
    time_map = TimeMap.from_seconds(bpms)
    tap_notes: List[AnyNote] = [
        make_tap_note(e.time, e.value, time_map, beat_snap)
        for e in events_by_command[Command.PLAY]
    ]
    long_notes: List[AnyNote] = [
        make_long_note(e.time, e.value, time_map, beat_snap)
        for e in events_by_command[Command.LONG]
    ]
    all_notes = sorted(tap_notes + long_notes,
                       key=lambda n: (n.time, n.position))
    timing = time_map.convert_to_timing_info(beat_snap=beat_snap)
    return song.Chart(level=Decimal(0), timing=timing, notes=all_notes)
Ejemplo n.º 5
0
def make_events_from_chart(notes: List[AnyNote],
                           timing: song.Timing) -> List[Event]:
    time_map = TimeMap.from_timing(timing)
    note_events = make_note_events(notes, time_map)
    timing_events = make_timing_events(notes, timing, time_map)
    return sorted(note_events + timing_events)
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def duration_in_ticks(long: song.LongNote, time_map: TimeMap) -> int:
    press_time = time_map.fractional_seconds_at(long.time)
    release_time = time_map.fractional_seconds_at(long.time + long.duration)
    length_in_seconds = release_time - press_time
    return seconds_to_ticks(length_in_seconds)
Ejemplo n.º 8
0
def ticks_at_beat(time: song.BeatsTime, time_map: TimeMap) -> int:
    seconds_time = time_map.fractional_seconds_at(time)
    return seconds_to_ticks(seconds_time)